public override async Task<bool> Validate()
{
var valid = false;
var retry = false;
SFile file = null;
try
{
// Test if the file is a valid mp3
file = SFile.Create(MainResource.AbsolutePath);
}
catch (CorruptFileException) // File isn't mp3
{
try
{
// Check if the file is wma
var old = MainResource.AbsolutePath;
MainResource.AbsolutePath = MainResource.AbsolutePath.Substring(0,
MainResource.AbsolutePath.Length - 3) + "wma";
File.Move(old, MainResource.AbsolutePath);
file = SFile.Create(MainResource.AbsolutePath);
}
catch (CorruptFileException e) // File isn't any supported type
{
File.Delete(MainResource.AbsolutePath);
// If manual has already been attempted, this isn't possible
retry = !_forceManual;
if (!retry)
{
View.Report("Error!", true);
CrashHandler.Throw("Unable to download a valid song format for editing!", e);
}
}
}
finally
{
if (file != null)
{
valid = true;
file.Dispose();
}
}
// Retry the download if necessary
if (retry)
valid = await RetryDownload();
return valid;
}