diff --git a/Application/FileConverter/Application.xaml.cs b/Application/FileConverter/Application.xaml.cs index 04318e5..aad57b6 100644 --- a/Application/FileConverter/Application.xaml.cs +++ b/Application/FileConverter/Application.xaml.cs @@ -341,8 +341,7 @@ namespace FileConverter { string inputFilePath = filePaths[index]; ConversionJob conversionJob = ConversionJobFactory.Create(conversionPreset, inputFilePath); - conversionJob.PrepareConversion(inputFilePath); - + this.conversionJobs.Add(conversionJob); } } @@ -358,8 +357,14 @@ namespace FileConverter private void ConvertFiles() { - Thread[] jobThreads = new Thread[this.numberOfConversionThread]; + // Prepare conversions. + for (int index = 0; index < this.ConvertionJobs.Count; index++) + { + this.ConvertionJobs[index].PrepareConversion(); + } + // Convert! + Thread[] jobThreads = new Thread[this.numberOfConversionThread]; while (true) { // Compute conversion flags. diff --git a/Application/FileConverter/ConversionJobs/ConversionJob.cs b/Application/FileConverter/ConversionJobs/ConversionJob.cs index 45374c3..463a8e0 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob.cs @@ -25,17 +25,26 @@ namespace FileConverter.ConversionJobs { this.State = ConversionState.Unknown; this.ConversionPreset = null; + this.initialInputPath = string.Empty; this.InputFilePath = string.Empty; } - public ConversionJob(ConversionPreset conversionPreset) : this() + public ConversionJob(ConversionPreset conversionPreset, string inputFilePath) : this() { if (conversionPreset == null) { - throw new ArgumentNullException("conversionPreset"); + throw new ArgumentNullException(nameof(conversionPreset)); } + if (string.IsNullOrEmpty(inputFilePath)) + { + throw new ArgumentNullException(nameof(inputFilePath)); + } + + this.initialInputPath = inputFilePath; + this.InputFilePath = inputFilePath; this.ConversionPreset = conversionPreset; + this.UserState = Properties.Resources.ConversionStatePrepareConversion; } public event PropertyChangedEventHandler PropertyChanged; @@ -66,7 +75,7 @@ namespace FileConverter.ConversionJobs { get { - if (this.OutputFilePaths == null) + if (this.OutputFilePaths == null || this.OutputFilePaths.Length == 0) { return string.Empty; } @@ -210,19 +219,16 @@ namespace FileConverter.ConversionJobs return (conversionFlags & ConversionFlags.CdDriveExtraction) == 0; } - public void PrepareConversion(string inputFilePath, params string[] outputFilePaths) + public void PrepareConversion(params string[] outputFilePaths) { - if (string.IsNullOrEmpty(inputFilePath)) - { - throw new ArgumentNullException(nameof(inputFilePath)); - } - if (this.ConversionPreset == null) { throw new Exception("The conversion preset must be valid."); } - string extension = System.IO.Path.GetExtension(inputFilePath); + this.InputFilePath = this.initialInputPath; + + string extension = System.IO.Path.GetExtension(this.initialInputPath); extension = extension.Substring(1, extension.Length - 1); string extensionCategory = Helpers.GetExtensionCategory(extension); if (!Helpers.IsOutputTypeCompatibleWithCategory(this.ConversionPreset.OutputType, extensionCategory)) @@ -231,9 +237,6 @@ namespace FileConverter.ConversionJobs return; } - this.initialInputPath = inputFilePath; - this.InputFilePath = inputFilePath; - this.OutputFilePaths = outputFilePaths; if (this.OutputFilePaths.Length == 0) { @@ -249,7 +252,7 @@ namespace FileConverter.ConversionJobs continue; } - string path = this.ConversionPreset.GenerateOutputFilePath(inputFilePath, index + 1, this.OutputFilePaths.Length); + string path = this.ConversionPreset.GenerateOutputFilePath(this.initialInputPath, index + 1, this.OutputFilePaths.Length); if (!PathHelpers.IsPathValid(path)) { @@ -267,7 +270,7 @@ namespace FileConverter.ConversionJobs string inputExtension = System.IO.Path.GetExtension(this.InputFilePath); string pathWithoutExtension = this.InputFilePath.Substring(0, this.InputFilePath.Length - inputExtension.Length); this.InputFilePath = PathHelpers.GenerateUniquePath(pathWithoutExtension + "_TEMP" + inputExtension); - System.IO.File.Move(inputFilePath, this.InputFilePath); + System.IO.File.Move(this.initialInputPath, this.InputFilePath); } } diff --git a/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs b/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs index de947d0..b6ffb91 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs @@ -10,36 +10,36 @@ namespace FileConverter.ConversionJobs inputFileExtension = inputFileExtension.ToLowerInvariant().Substring(1, inputFileExtension.Length - 1); if (inputFileExtension == "cda") { - return new ConversionJob_ExtractCDA(conversionPreset); + return new ConversionJob_ExtractCDA(conversionPreset, inputFilePath); } if (inputFileExtension == "doc" || inputFileExtension == "docx" || inputFileExtension == "odt") { - return new ConversionJob_Word(conversionPreset); + return new ConversionJob_Word(conversionPreset, inputFilePath); } if (conversionPreset.OutputType == OutputType.Ico) { - return new ConversionJob_Ico(conversionPreset); + return new ConversionJob_Ico(conversionPreset, inputFilePath); } if (conversionPreset.OutputType == OutputType.Gif) { - return new ConversionJob_Gif(conversionPreset); + return new ConversionJob_Gif(conversionPreset, inputFilePath); } if (conversionPreset.OutputType == OutputType.Pdf) { - return new ConversionJob_ImageMagick(conversionPreset); + return new ConversionJob_ImageMagick(conversionPreset, inputFilePath); } if (Helpers.GetExtensionCategory(inputFileExtension) == Helpers.InputCategoryNames.Image || Helpers.GetExtensionCategory(inputFileExtension) == Helpers.InputCategoryNames.Document) { - return new ConversionJob_ImageMagick(conversionPreset); + return new ConversionJob_ImageMagick(conversionPreset, inputFilePath); } - return new ConversionJob_FFMPEG(conversionPreset); + return new ConversionJob_FFMPEG(conversionPreset, inputFilePath); } } } diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_ExtractCDA.cs b/Application/FileConverter/ConversionJobs/ConversionJob_ExtractCDA.cs index 7163569..5adcc3c 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_ExtractCDA.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_ExtractCDA.cs @@ -25,7 +25,7 @@ namespace FileConverter.ConversionJobs this.IsCancelable = true; } - public ConversionJob_ExtractCDA(ConversionPreset conversionPreset) : base(conversionPreset) + public ConversionJob_ExtractCDA(ConversionPreset conversionPreset, string inputFilePath) : base(conversionPreset, inputFilePath) { this.IsCancelable = true; } @@ -105,7 +105,7 @@ namespace FileConverter.ConversionJobs // Sub conversion job (for compression). this.compressionConversionJob = ConversionJobFactory.Create(this.ConversionPreset, this.intermediateFilePath); - this.compressionConversionJob.PrepareConversion(this.intermediateFilePath, this.OutputFilePath); + this.compressionConversionJob.PrepareConversion(this.OutputFilePath); this.compressionThread = Helpers.InstantiateThread("CDACompressionThread", this.CompressAsync); } diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs index 6cb53ef..df6d991 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs @@ -28,7 +28,7 @@ namespace FileConverter.ConversionJobs this.IsCancelable = true; } - public ConversionJob_FFMPEG(ConversionPreset conversionPreset) : base(conversionPreset) + public ConversionJob_FFMPEG(ConversionPreset conversionPreset, string inputFilePath) : base(conversionPreset, inputFilePath) { this.IsCancelable = true; } diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_Gif.cs b/Application/FileConverter/ConversionJobs/ConversionJob_Gif.cs index b8dfe1f..8035b12 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_Gif.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_Gif.cs @@ -12,7 +12,7 @@ namespace FileConverter.ConversionJobs private ConversionJob pngConversionJob = null; private ConversionJob gifConversionJob = null; - public ConversionJob_Gif(ConversionPreset conversionPreset) : base(conversionPreset) + public ConversionJob_Gif(ConversionPreset conversionPreset, string inputFilePath) : base(conversionPreset, inputFilePath) { this.IsCancelable = true; } @@ -50,7 +50,7 @@ namespace FileConverter.ConversionJobs // Convert input in png file to send it to ffmpeg for the gif conversion. ConversionPreset intermediatePreset = new ConversionPreset("To compatible image", OutputType.Png, this.ConversionPreset.InputTypes.ToArray()); this.pngConversionJob = ConversionJobFactory.Create(intermediatePreset, this.InputFilePath); - this.pngConversionJob.PrepareConversion(this.InputFilePath, this.intermediateFilePath); + this.pngConversionJob.PrepareConversion(this.intermediateFilePath); inputFilePath = this.intermediateFilePath; } @@ -60,8 +60,8 @@ namespace FileConverter.ConversionJobs } // Convert png file into ico. - this.gifConversionJob = new ConversionJob_FFMPEG(this.ConversionPreset); - this.gifConversionJob.PrepareConversion(inputFilePath, this.OutputFilePath); + this.gifConversionJob = new ConversionJob_FFMPEG(this.ConversionPreset, inputFilePath); + this.gifConversionJob.PrepareConversion(this.OutputFilePath); } protected override void Convert() diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_Ico.cs b/Application/FileConverter/ConversionJobs/ConversionJob_Ico.cs index 5f38179..46f8b73 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_Ico.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_Ico.cs @@ -11,7 +11,7 @@ namespace FileConverter.ConversionJobs private ConversionJob pngConversionJob; private ConversionJob icoConversionJob; - public ConversionJob_Ico(ConversionPreset conversionPreset) : base(conversionPreset) + public ConversionJob_Ico(ConversionPreset conversionPreset, string inputFilePath) : base(conversionPreset, inputFilePath) { this.IsCancelable = true; } @@ -43,11 +43,11 @@ namespace FileConverter.ConversionJobs intermediatePreset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageClampSizePowerOf2, "True"); intermediatePreset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageMaximumSize, "256"); this.pngConversionJob = ConversionJobFactory.Create(intermediatePreset, this.InputFilePath); - this.pngConversionJob.PrepareConversion(this.InputFilePath, this.intermediateFilePath); + this.pngConversionJob.PrepareConversion(this.intermediateFilePath); // Convert png file into ico. - this.icoConversionJob = new ConversionJob_FFMPEG(this.ConversionPreset); - this.icoConversionJob.PrepareConversion(this.intermediateFilePath, this.OutputFilePath); + this.icoConversionJob = new ConversionJob_FFMPEG(this.ConversionPreset, this.intermediateFilePath); + this.icoConversionJob.PrepareConversion(this.OutputFilePath); } protected override void Convert() diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs b/Application/FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs index 06c3c77..8e2d7d7 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs @@ -17,7 +17,7 @@ namespace FileConverter.ConversionJobs this.IsCancelable = true; } - public ConversionJob_ImageMagick(ConversionPreset conversionPreset) : base(conversionPreset) + public ConversionJob_ImageMagick(ConversionPreset conversionPreset, string inputFilePath) : base(conversionPreset, inputFilePath) { this.IsCancelable = true; } diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_Word.cs b/Application/FileConverter/ConversionJobs/ConversionJob_Word.cs index 5ad1328..db0b8de 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_Word.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_Word.cs @@ -21,7 +21,7 @@ namespace FileConverter.ConversionJobs ConversionJob_Word.InitializeWordApplicationInstance(); } - public ConversionJob_Word(ConversionPreset conversionPreset) : base(conversionPreset) + public ConversionJob_Word(ConversionPreset conversionPreset, string inputFilePath) : base(conversionPreset, inputFilePath) { ConversionJob_Word.InitializeWordApplicationInstance(); } diff --git a/Application/FileConverter/Properties/Resources.Designer.cs b/Application/FileConverter/Properties/Resources.Designer.cs index d7722b9..521691d 100644 --- a/Application/FileConverter/Properties/Resources.Designer.cs +++ b/Application/FileConverter/Properties/Resources.Designer.cs @@ -267,6 +267,15 @@ namespace FileConverter.Properties { } } + /// + /// Looks up a localized string similar to Prepare conversion. + /// + public static string ConversionStatePrepareConversion { + get { + return ResourceManager.GetString("ConversionStatePrepareConversion", resourceCulture); + } + } + /// /// Looks up a localized string similar to Read document. /// diff --git a/Application/FileConverter/Properties/Resources.en.resx b/Application/FileConverter/Properties/Resources.en.resx index 3a2c44e..cfd3a0e 100644 --- a/Application/FileConverter/Properties/Resources.en.resx +++ b/Application/FileConverter/Properties/Resources.en.resx @@ -523,4 +523,7 @@ use maj for uppercase version The conversion job failed but there is an output file that does exists. + + Prepare conversion + \ No newline at end of file diff --git a/Application/FileConverter/Properties/Resources.fr.resx b/Application/FileConverter/Properties/Resources.fr.resx index 5da8888..1571b89 100644 --- a/Application/FileConverter/Properties/Resources.fr.resx +++ b/Application/FileConverter/Properties/Resources.fr.resx @@ -541,4 +541,7 @@ utilisez maj pour une version en majuscules Des fichiers sont présents malgré l'echec de la conversion. + + Préparation + \ No newline at end of file diff --git a/Application/FileConverter/Properties/Resources.resx b/Application/FileConverter/Properties/Resources.resx index 2c39276..37aa21b 100644 --- a/Application/FileConverter/Properties/Resources.resx +++ b/Application/FileConverter/Properties/Resources.resx @@ -523,4 +523,7 @@ use maj for uppercase version The conversion job failed but there is an output file that does exists. + + Prepare conversion + \ No newline at end of file