Add: handle path validity error check in conversion jobs.

This commit is contained in:
Tichau committed 2015-10-27 09:06:35 +01:00
1 parent 6f7b0386cd
commit 1d66f9fef0
3 files changed
+37 -17

No files matched your search

+6 -12
View File
@@ -102,20 +102,14 @@ namespace FileConverter
if (args.Length <= 1)
{
this.debugMode = true;
System.Array.Resize(ref args, 9);
System.Array.Resize(ref args, 5);
args[1] = "--conversion-preset";
args[2] = "To Mp3";
args[3] = @"D:\Projects\FileConverter\TestFiles\Herbie Hancock - Speak Like A Child [RVG Edition].flac";
args[3] = @"D:\Projects\FileConverter\TestFiles\01 - Le Bruit Du Bang.wma";
args[4] = @"D:\Projects\FileConverter\TestFiles\test\Toccata.wav";
args[5] = @"D:\Projects\FileConverter\TestFiles\test\Toccata - Copie (4).wav";
args[5] = "--verbose";
args[6] = @"D:\Projects\FileConverter\TestFiles\test\Toccata - Copie (3).wav";
args[7] = @"D:\Projects\FileConverter\TestFiles\test\Toccata - Copie (2).wav";
args[8] = @"D:\Projects\FileConverter\TestFiles\test\Toccata - Copie (5).wav";
args[3] = "--verbose";
args[4] = @"D:\Test\10 - Get around town (lp version).ogg";
System.Array.Resize(ref args, 2);
args[1] = "--settings";
//System.Array.Resize(ref args, 2);
//args[1] = "--settings";
}
#endif
@@ -227,7 +221,7 @@ namespace FileConverter
Diagnostics.Log("Delete file {0}.", conversionJob.OutputFilePath);
try
{
System.IO.File.Delete(conversionJob.OutputFilePath);
//System.IO.File.Delete(conversionJob.OutputFilePath);
}
catch
{
@@ -115,17 +115,39 @@ namespace FileConverter.ConversionJobs
this.InputFilePath = inputFilePath;
this.OutputFilePath = this.ConversionPreset.GenerateOutputFilePath(inputFilePath);
string presetError = this.ConversionPreset.Error;
if (!string.IsNullOrEmpty(presetError))
if (!PathHelpers.IsPathValid(this.OutputFilePath))
{
this.State = ConversionState.Failed;
this.ErrorMessage = presetError;
this.ConvertionFailed("Invalid output path generated by output file path template.");
Diagnostics.Log(string.Format("Invalid output path generated: {0} from input: {1}.", this.OutputFilePath, this.InputFilePath));
return;
}
// TODO: Check is all output folders exists.
try
{
string basePath = System.IO.Path.GetDirectoryName(this.OutputFilePath) + "\\" + System.IO.Path.GetFileNameWithoutExtension(this.OutputFilePath);
string baseExtension = System.IO.Path.GetExtension(this.OutputFilePath);
int index = 2;
while (System.IO.File.Exists(this.OutputFilePath))
{
this.OutputFilePath = string.Format("{0} ({1}){2}", basePath, index, baseExtension);
index++;
}
}
catch (Exception exception)
{
this.ConvertionFailed("Can't generate a valid output filename.");
Diagnostics.Log(exception.Message);
return;
}
this.Initialize();
this.State = ConversionState.Ready;
if (this.State == ConversionState.Unknown)
{
this.State = ConversionState.Ready;
}
}
public void StartConvertion()
@@ -166,6 +188,7 @@ namespace FileConverter.ConversionJobs
protected void ConvertionFailed(string exitingMessage)
{
this.State = ConversionState.Failed;
this.ErrorMessage = exitingMessage;
}
protected void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
@@ -27,6 +27,8 @@ namespace FileConverter.ConversionJobs
protected override void Initialize()
{
base.Initialize();
if (this.ConversionPreset == null)
{
throw new Exception("The conversion preset must be valid.");
@@ -38,6 +40,7 @@ namespace FileConverter.ConversionJobs
string ffmpegPath = string.Format("{0}\\ffmpeg.exe", applicationDirectory);
if (!System.IO.File.Exists(ffmpegPath))
{
this.ConvertionFailed("Can't find ffmpeg executable. You should try to reinstall the application.");
Diagnostics.Log("Can't find ffmpeg executable ({0}). Try to reinstall the application.", ffmpegPath);
return;
}