diff --git a/OfficeConverter.sln b/OfficeConverter.sln
index e4ff505..73c6695 100644
--- a/OfficeConverter.sln
+++ b/OfficeConverter.sln
@@ -8,13 +8,19 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
+ Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
+ Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6E77662E-82C3-4913-8964-5A452B229F78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6E77662E-82C3-4913-8964-5A452B229F78}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6E77662E-82C3-4913-8964-5A452B229F78}.Debug|x64.ActiveCfg = Debug|x64
+ {6E77662E-82C3-4913-8964-5A452B229F78}.Debug|x64.Build.0 = Debug|x64
{6E77662E-82C3-4913-8964-5A452B229F78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6E77662E-82C3-4913-8964-5A452B229F78}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6E77662E-82C3-4913-8964-5A452B229F78}.Release|x64.ActiveCfg = Release|x64
+ {6E77662E-82C3-4913-8964-5A452B229F78}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/OfficeConverter/FodyWeavers.xml b/OfficeConverter/FodyWeavers.xml
new file mode 100644
index 0000000..5029e70
--- /dev/null
+++ b/OfficeConverter/FodyWeavers.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/OfficeConverter/MainWindow.xaml b/OfficeConverter/MainWindow.xaml
index 0c76964..3f860cf 100644
--- a/OfficeConverter/MainWindow.xaml
+++ b/OfficeConverter/MainWindow.xaml
@@ -5,13 +5,16 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:OfficeConverter"
mc:Ignorable="d"
- Title="MainWindow" Height="866" Width="1099" Background="#FF1A1A1A">
+ Title="OfficeConverter 1.0" Height="715" Width="1045" Background="#FF1A1A1A">
+
+
+
-
+
@@ -24,37 +27,37 @@
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/OfficeConverter/MainWindow.xaml.cs b/OfficeConverter/MainWindow.xaml.cs
index 8b7696e..77085f1 100644
--- a/OfficeConverter/MainWindow.xaml.cs
+++ b/OfficeConverter/MainWindow.xaml.cs
@@ -1,20 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Diagnostics;
using System.IO;
-using System.Linq;
+using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
-using Word = Microsoft.Office.Interop.Word;
-using Forms = System.Windows.Forms;
-using System.Threading.Tasks;
using Excel = Microsoft.Office.Interop.Excel;
+using Forms = System.Windows.Forms;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
-using System.Threading;
-using System.Windows.Media.TextFormatting;
-using System.Windows.Forms;
-using System.Runtime.InteropServices;
-using System.Diagnostics;
+using Word = Microsoft.Office.Interop.Word;
namespace OfficeConverter
{
@@ -23,13 +20,15 @@ namespace OfficeConverter
///
public partial class MainWindow : Window
{
- //Definiere Background workder für die Konvertierung
+ //Definiere Background worker für die Konvertierung
private BackgroundWorker backgroundWorker;
+ private CancellationTokenSource cancellationTokenSource;
+ //Definiter listen für die Anzeige im GUI
List combinedFiles = new List();
List convertedFiles = new List();
-
+ //Globalvariables
bool doSubfolders = false;
bool doReplace = false;
bool doWord = false;
@@ -55,8 +54,11 @@ namespace OfficeConverter
backgroundWorker.ProgressChanged += BackgroundWorker_ProgressChanged;
backgroundWorker.RunWorkerCompleted += BackgroundWorker_RunWorkerCompleted;
lblState.Content = "Ready";
-
+ cancellationTokenSource = new CancellationTokenSource();
}
+
+
+ //Konvertier-Button
private void btnConvert_Click(object sender, RoutedEventArgs e)
{
string folderPath = txtSourceFolder.Text;
@@ -87,42 +89,73 @@ namespace OfficeConverter
System.Windows.MessageBox.Show("Conversion is already in progress. Please wait for the current operation to finish.");
}
}
+
+ //Background Worker
private async void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
-
// Clear the list of converted files at the beginning of each conversion
convertedFiles.Clear();
string folderPath = e.Argument as string;
- // Disable buttons during conversion
+
+ // Use Dispatcher.Invoke to access UI elements from the UI thread
System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
+ // Check if txtDestFolder is empty and doReplace is false
+ if (string.IsNullOrWhiteSpace(txtDestFolder.Text) && !doReplace)
+ {
+ // Show a warning message in a MessageBox
+ System.Windows.MessageBox.Show("Destination folder is required when 'Replace files' is not selected.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
+
+ // Cancel the task
+ e.Cancel = true;
+ cancellationTokenSource.Cancel();
+
+ return;
+ }
+
+ // Disable buttons during conversion
UpdateButtonStates(false);
+
+ // Initialize the CancellationTokenSource
+ cancellationTokenSource = new CancellationTokenSource();
});
- if (Directory.Exists(folderPath))
+ try
{
- try
- {
- await SearchAndConvertDocs(folderPath);
- }
- catch (Exception ex)
- {
- System.Windows.MessageBox.Show($"Error: {ex.Message}");
- }
+ // Pass the cancellation token to SearchAndConvertDocs
+ await SearchAndConvertDocs(folderPath, cancellationTokenSource.Token);
}
- else
+ catch (OperationCanceledException)
{
+ // Handle cancellation if needed
+ }
+ finally
+ {
+ // Use Dispatcher.Invoke to update UI elements from the UI thread
System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
- System.Windows.MessageBox.Show("Ungültiger Ordnerpfad.");
+ // Clear the UI-bound collection
+ combinedFiles.Clear();
+ // Add the contents of the combinedFiles list to the UI-bound collection
+ combinedFiles.ForEach(file => lstSourceFiles.Items.Add(file));
+ // Enable buttons after conversion completion
+ UpdateButtonStates(true);
});
}
+ }
+ private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
+ {
+ // Update the UI with the progress value
+ //progressBar.Value = e.ProgressPercentage;
+ }
+ private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
+ {
+ // Perform any additional tasks after the background work is completed
// Enable buttons after conversion completion
- UpdateButtonStates(true);
+
}
-
- private async Task SearchAndConvertDocs(string folderPath)
+ private async Task SearchAndConvertDocs(string folderPath, CancellationToken cancellationToken)
{
string[] docFiles = null;
string[] xlsFiles = null;
@@ -141,7 +174,6 @@ namespace OfficeConverter
pptFiles = Directory.GetFiles(folderPath, "*.ppt");
}
- //List currentFolderFiles = new List();
// Check for null before adding to combinedFiles
if (docFiles != null)
{
@@ -158,20 +190,27 @@ namespace OfficeConverter
Console.WriteLine($"Processing files in folder: {folderPath}");
-
- // Create a copy of the collection to avoid modification during iteration
+ /// Create a copy of the collection to avoid modification during iteration
List snapshot = new List(combinedFiles);
- // Iterate over currentFolderFiles and start the conversion asynchronously
- await Task.Run(async () =>
+ // Check for cancellation after creating the snapshot
+ cancellationToken.ThrowIfCancellationRequested();
+
+
+ try
{
+ // Iterate over currentFolderFiles and start the conversion asynchronously
foreach (var docFile in snapshot)
{
+ // Check for cancellation before each iteration
+ cancellationToken.ThrowIfCancellationRequested();
+
Console.WriteLine($"Converting file: {docFile}");
try
{
await ConvertFileToNewFormatAsync(docFile);
+
Console.WriteLine($"DisplayCombinedFiles called");
DisplayCombinedFiles();
}
@@ -183,7 +222,20 @@ namespace OfficeConverter
Console.WriteLine($"Task completed for file: {docFile}");
}
- });
+
+ // Check for cancellation before displaying the completion message
+ cancellationToken.ThrowIfCancellationRequested();
+
+ // Clear the list of combined files if the operation was cancelled
+ if (cancellationToken.IsCancellationRequested)
+ {
+ combinedFiles.Clear();
+ }
+ }
+ catch (OperationCanceledException)
+ {
+ // Handle cancellation if needed
+ }
// Recursively process subfolders
if (doSubfolders)
@@ -191,25 +243,25 @@ namespace OfficeConverter
string[] subfolders = Directory.GetDirectories(folderPath);
foreach (var subfolder in subfolders)
{
- // Await the completion of the recursive call
- await SearchAndConvertDocs(subfolder);
+ // Pass the cancellation token to the recursive call
+ await SearchAndConvertDocs(subfolder, cancellationToken);
+
+ // Check for cancellation after processing each subfolder
+ if (cancellationToken.IsCancellationRequested)
+ {
+ // Stop processing if cancellation is requested
+ break;
+ }
}
}
+
System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
lblState.Content = "Background work completed!";
});
+
DisplayCombinedFiles();
-
}
-
-
-
-
-
-
-
-
private async Task ConvertFileToNewFormatAsync(string filePath)
{
await Task.Run(() =>
@@ -293,8 +345,6 @@ namespace OfficeConverter
KillProcess("EXCEL");
}
}
-
-
private void ConvertPptToPptx(string pptFile, bool doSubfolders, bool doReplace)
{
PowerPoint.Application pptApp = new PowerPoint.Application();
@@ -335,7 +385,6 @@ namespace OfficeConverter
pptApp.Quit();
}
}
-
private void ConvertDocToDocx(string docFile, bool doSubfolders, bool doReplace)
{
Word.Application wordApp = new Word.Application();
@@ -374,7 +423,6 @@ namespace OfficeConverter
KillProcess("WINWORD");
}
}
-
private void KillProcess(string processName)
{
try
@@ -390,7 +438,6 @@ namespace OfficeConverter
}
}
-
// Helper method to determine the target folder path
private string GetTargetFolderPath(bool doReplace, bool doSubfolders, string docFilePath)
{
@@ -429,15 +476,6 @@ namespace OfficeConverter
return targetFolder;
}
-
-
-
-
-
-
-
-
-
private string GetRelativePath(string fullPath, string basePath)
{
Uri baseUri = new Uri(basePath + (basePath.EndsWith("\\") ? "" : "\\"));
@@ -455,26 +493,6 @@ namespace OfficeConverter
return relativePath;
}
-
-
-
-
-
-
- private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
- {
- // Update the UI with the progress value
- //progressBar.Value = e.ProgressPercentage;
- }
-
- private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
- {
- // Perform any additional tasks after the background work is completed
- // Enable buttons after conversion completion
-
- }
-
-
private void setLangEN()
{
grpFolders.Header = "Folders";
@@ -490,7 +508,6 @@ namespace OfficeConverter
btnConvert.Content = "Convert";
btnDelete.Content = "Delete Files";
btnExport.Content = "Export list";
-
}
private void setLangDE()
{
@@ -508,14 +525,6 @@ namespace OfficeConverter
btnDelete.Content = "Dateien löschen";
btnExport.Content = "Liste exportieren";
}
-
- private void txtDestFolder_TextChanged(object sender, TextChangedEventArgs e)
- {
-
- }
-
-
-
private void btnDestFolder_Click(object sender, RoutedEventArgs e)
{
using (var folderBrowserDialog = new Forms.FolderBrowserDialog())
@@ -529,7 +538,6 @@ namespace OfficeConverter
}
}
-
private void DisplayCombinedFiles()
{
if (combinedFiles != null)
@@ -543,10 +551,6 @@ namespace OfficeConverter
});
}
}
-
-
-
-
private void btnSourceFolder_Click(object sender, RoutedEventArgs e)
{
using (var folderBrowserDialog = new Forms.FolderBrowserDialog())
@@ -603,16 +607,6 @@ namespace OfficeConverter
else { doSubfolders = false; }
}
- private void chkSubfolders_Checked(object sender, RoutedEventArgs e)
- {
-
- }
-
- private void chkReplace_Checked(object sender, RoutedEventArgs e)
- {
-
- }
-
private void ExportConvertedFilesToFile(string filePath)
{
try
@@ -699,9 +693,5 @@ namespace OfficeConverter
btnDelete.IsEnabled = isEnabled;
});
}
-
-
-
-
}
}
diff --git a/OfficeConverter/OfficeConverter.csproj b/OfficeConverter/OfficeConverter.csproj
index 831b073..2c4b154 100644
--- a/OfficeConverter/OfficeConverter.csproj
+++ b/OfficeConverter/OfficeConverter.csproj
@@ -1,5 +1,6 @@
+
@@ -21,16 +22,15 @@
D:\OneDrive - wyniger\Design & Development\Code\Publish\DocConvert\
true
- Unc
- true
+ Disk
+ false
Foreground
7
Days
false
false
true
- \\localhost\d%24\testconvert\
- 3
+ 5
1.0.0.%2a
false
true
@@ -67,28 +67,210 @@
true
+
+ true
+ bin\x64\Debug\
+ DEBUG;TRACE
+ full
+ x64
+ 7.3
+ prompt
+ true
+
+
+ bin\x64\Release\
+ TRACE
+ true
+ pdbonly
+ x64
+ 7.3
+ prompt
+ true
+
-
-
+
+ ..\packages\Costura.Fody.5.7.0\lib\netstandard1.0\Costura.dll
+
+
+ ..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll
+ True
+ True
+
+
+ True
+
+
+ ..\packages\System.AppContext.4.3.0\lib\net463\System.AppContext.dll
+ True
+ True
+
+
+ True
+
+
+ ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll
+ True
+ True
+
+
+ True
+
+
+ ..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll
+
+
+ ..\packages\System.Diagnostics.Tracing.4.3.0\lib\net462\System.Diagnostics.Tracing.dll
+ True
+ True
+
+
+ ..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll
+ True
+ True
+
+
+ ..\packages\System.IO.4.3.0\lib\net462\System.IO.dll
+ True
+ True
+
+
+ ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll
+ True
+ True
+
+
+ True
+
+
+ ..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll
+ True
+ True
+
+
+ ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll
+ True
+ True
+
+
+ ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll
+ True
+ True
+
+
+ ..\packages\System.Linq.4.3.0\lib\net463\System.Linq.dll
+ True
+ True
+
+
+ ..\packages\System.Linq.Expressions.4.3.0\lib\net463\System.Linq.Expressions.dll
+ True
+ True
+
+
+ ..\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll
+ True
+ True
+
+
+ ..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll
+ True
+ True
+
+
+ True
+
+
+ ..\packages\System.Reflection.4.3.0\lib\net462\System.Reflection.dll
+ True
+ True
+
+
+ ..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll
+ True
+ True
+
+
+ ..\packages\System.Runtime.Extensions.4.3.0\lib\net462\System.Runtime.Extensions.dll
+ True
+ True
+
+
+ ..\packages\System.Runtime.InteropServices.4.3.0\lib\net463\System.Runtime.InteropServices.dll
+ True
+ True
+
+
+ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll
+ True
+ True
+
+
+ ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net463\System.Security.Cryptography.Algorithms.dll
+ True
+ True
+
+
+ ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll
+ True
+ True
+
+
+ ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll
+ True
+ True
+
+
+ ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll
+ True
+ True
+
+
+ ..\packages\System.Text.RegularExpressions.4.3.0\lib\net463\System.Text.RegularExpressions.dll
+ True
+ True
+
..\packages\Infragistics.Themes.MetroDark.Wpf.1.0.0\lib\net40\System.Windows.Controls.Input.Toolkit.dll
..\packages\Infragistics.Themes.MetroDark.Wpf.1.0.0\lib\net40\System.Windows.Controls.Layout.Toolkit.dll
-
-
-
-
-
-
-
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
4.0
+ True
+
+
+ ..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll
+ True
+ True
+
+
+ True
+
+
+ True
+
+
+ True
-
-
-
..\packages\Infragistics.Themes.MetroDark.Wpf.1.0.0\lib\net40\WPFToolkit.dll
@@ -109,6 +291,7 @@
MainWindow.xaml
Code
+ PreserveNewest
MSBuild:Compile
@@ -230,5 +413,10 @@
Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".
+
+
+
+
+
\ No newline at end of file
diff --git a/OfficeConverter/packages.config b/OfficeConverter/packages.config
index bc9acb7..e584a6a 100644
--- a/OfficeConverter/packages.config
+++ b/OfficeConverter/packages.config
@@ -1,5 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file