From ae11eb1999a32ea3d9af6427e38576be320d5670 Mon Sep 17 00:00:00 2001 From: hsayed21 Date: Fri, 8 Dec 2023 14:53:21 +0200 Subject: [PATCH] Copy All Selected Files --- .../ConversionJobs/ConversionJob.cs | 22 ------------ .../Properties/Resources.Designer.cs | 6 ++-- .../FileConverter/Properties/Resources.resx | 4 +-- .../Services/ConversionService.cs | 34 +++++++++++++++++++ Application/FileConverter/Settings.cs | 2 +- .../FileConverter/Views/SettingsWindow.xaml | 4 +-- 6 files changed, 42 insertions(+), 30 deletions(-) diff --git a/Application/FileConverter/ConversionJobs/ConversionJob.cs b/Application/FileConverter/ConversionJobs/ConversionJob.cs index 4cd92cc..aea69e4 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob.cs @@ -449,14 +449,6 @@ namespace FileConverter.ConversionJobs this.UserState = Properties.Resources.ConversionStateDone; Debug.Log("Conversion Done!"); - ISettingsService settingsService = SimpleIoc.Default.GetInstance(); - // Copy the output file to the clipboard using Task - if (settingsService.Settings.CheckCopyFileAfterConverting) - { - Thread clipboardThread = new Thread(CopyFileToClipboard); - clipboardThread.SetApartmentState(ApartmentState.STA); - clipboardThread.Start(); - } } protected void ConversionFailed(string exitingMessage) @@ -538,19 +530,5 @@ namespace FileConverter.ConversionJobs return false; } - - private void CopyFileToClipboard() - { - try - { - System.Windows.Forms.Clipboard.SetFileDropList(new System.Collections.Specialized.StringCollection { OutputFilePath }); - Debug.Log("Output file copied to the clipboard: '{0}'", OutputFilePath); - } - catch (Exception exception) - { - Debug.Log("Can't copy file '{0}' to the clipboard.", OutputFilePath); - Debug.Log("An exception has been thrown: {0}.", exception.ToString()); - } - } } } diff --git a/Application/FileConverter/Properties/Resources.Designer.cs b/Application/FileConverter/Properties/Resources.Designer.cs index aae88f9..9cf1b66 100644 --- a/Application/FileConverter/Properties/Resources.Designer.cs +++ b/Application/FileConverter/Properties/Resources.Designer.cs @@ -322,11 +322,11 @@ namespace FileConverter.Properties { } /// - /// Looks up a localized string similar to Copy File After Converting. + /// Looks up a localized string similar to Copy Files After Converting. /// - public static string CopyFileAfterConverting { + public static string CopyFilesAfterConverting { get { - return ResourceManager.GetString("CopyFileAfterConverting", resourceCulture); + return ResourceManager.GetString("CopyFilesAfterConverting", resourceCulture); } } diff --git a/Application/FileConverter/Properties/Resources.resx b/Application/FileConverter/Properties/Resources.resx index 935da49..19f566c 100644 --- a/Application/FileConverter/Properties/Resources.resx +++ b/Application/FileConverter/Properties/Resources.resx @@ -592,7 +592,7 @@ use maj for uppercase version Can't load file converter user settings. Do you want to fall back to default settings ? - - Copy File After Converting + + Copy Files After Converting \ No newline at end of file diff --git a/Application/FileConverter/Services/ConversionService.cs b/Application/FileConverter/Services/ConversionService.cs index 49812bd..94488a1 100644 --- a/Application/FileConverter/Services/ConversionService.cs +++ b/Application/FileConverter/Services/ConversionService.cs @@ -65,6 +65,7 @@ namespace FileConverter.Services this.ConversionJobs[index].PrepareConversion(); } + System.Collections.Specialized.StringCollection files = new System.Collections.Specialized.StringCollection(); // Convert! Thread[] jobThreads = new Thread[this.numberOfConversionThread]; while (true) @@ -118,6 +119,11 @@ namespace FileConverter.Services } } + if (!files.Contains(conversionJob.OutputFilePath)) + { + files.Add(conversionJob.OutputFilePath); + } + break; } } @@ -125,6 +131,15 @@ namespace FileConverter.Services Thread.Sleep(50); } + ISettingsService settingsService = SimpleIoc.Default.GetInstance(); + // Copy the output files to the clipboard + if (settingsService.Settings.CheckCopyFilesAfterConverting && files.Count > 0) + { + Thread clipboardThread = Helpers.InstantiateThread("CopyFilesToClipboardThread", this.CopyFilesToClipboard); + clipboardThread.SetApartmentState(ApartmentState.STA); + clipboardThread.Start(files); + } + bool allConversionsSucceed = true; for (int index = 0; index < this.conversionJobs.Count; index++) { @@ -160,5 +175,24 @@ namespace FileConverter.Services Debug.LogError("Failure during conversion: {0}", exception.ToString()); } } + + private void CopyFilesToClipboard(object _filePaths) + { + try + { + System.Collections.Specialized.StringCollection FilePaths = _filePaths as System.Collections.Specialized.StringCollection; + System.Windows.Forms.Clipboard.SetFileDropList(FilePaths); + Debug.Log("Output files copied to the clipboard:"); + for (int index = 0; index < FilePaths.Count; index++) + { + Debug.Log(" {0}", FilePaths[index]); + } + } + catch (Exception exception) + { + Debug.Log("Can't copy files to the clipboard."); + Debug.Log("An exception has been thrown: {0}.", exception.ToString()); + } + } } } diff --git a/Application/FileConverter/Settings.cs b/Application/FileConverter/Settings.cs index 87dc071..96b00ec 100644 --- a/Application/FileConverter/Settings.cs +++ b/Application/FileConverter/Settings.cs @@ -209,7 +209,7 @@ namespace FileConverter } [XmlElement] - public bool CheckCopyFileAfterConverting + public bool CheckCopyFilesAfterConverting { get { diff --git a/Application/FileConverter/Views/SettingsWindow.xaml b/Application/FileConverter/Views/SettingsWindow.xaml index 2a4dc92..976429e 100644 --- a/Application/FileConverter/Views/SettingsWindow.xaml +++ b/Application/FileConverter/Views/SettingsWindow.xaml @@ -400,8 +400,8 @@