diff --git a/ChunkDBExtractor/MainWindow.xaml.cs b/ChunkDBExtractor/MainWindow.xaml.cs index 9e9b519..fa3feff 100644 --- a/ChunkDBExtractor/MainWindow.xaml.cs +++ b/ChunkDBExtractor/MainWindow.xaml.cs @@ -55,7 +55,7 @@ namespace ChunkDBExtractor } } - private async void ExtractButton_Click(object sender, RoutedEventArgs e) + private void ExtractButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(sourceFolder) || string.IsNullOrEmpty(destinationFolder)) { @@ -63,20 +63,25 @@ namespace ChunkDBExtractor return; } - try - { - ProgressWindow progressWindow = new ProgressWindow(); - progressWindow.Show(); + ProgressWindow progressWindow = new ProgressWindow(); + progressWindow.Owner = this; + progressWindow.ShowInTaskbar = false; + Task.Run(async () => + { + progressWindow.Dispatcher.Invoke(() => progressWindow.StartAnimation()); await ExtractChunkDBFilesAsync(sourceFolder, destinationFolder, progressWindow); - progressWindow.Close(); + progressWindow.Dispatcher.Invoke(() => + { + progressWindow.StopAnimation(); + progressWindow.Close(); + }); + MessageBox.Show("Files extracted successfully!"); - } - catch (Exception ex) - { - MessageBox.Show($"An error occurred: {ex.Message}"); - } + }); + + progressWindow.ShowDialog(); } private void CheckIfReadyToExtract() @@ -87,26 +92,20 @@ namespace ChunkDBExtractor private async Task ExtractChunkDBFilesAsync(string source, string destination, ProgressWindow progressWindow) { var chunkdbFiles = Directory.GetFiles(source, "*.chunkdb"); - double progressPerFile = 100.0 / chunkdbFiles.Length; - double currentProgress = 0; foreach (var file in chunkdbFiles) { try { - progressWindow.UpdateProgress(currentProgress, Path.GetFileName(file)); + progressWindow.UpdateProgress(Path.GetFileName(file)); await Task.Run(() => ExtractChunkDBFile(file, destination)); - - currentProgress += progressPerFile; } catch (Exception ex) { MessageBox.Show($"An error occurred while extracting {file}: {ex.Message}"); } } - - progressWindow.UpdateProgress(100, "Extraction Complete"); } private void ExtractChunkDBFile(string file, string destination) diff --git a/ChunkDBExtractor/ProgressWindow.xaml b/ChunkDBExtractor/ProgressWindow.xaml index 72db85d..24e7d1c 100644 --- a/ChunkDBExtractor/ProgressWindow.xaml +++ b/ChunkDBExtractor/ProgressWindow.xaml @@ -1,11 +1,10 @@  + Title="Processing..." Height="120" Width="400" WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow"> - \ No newline at end of file diff --git a/ChunkDBExtractor/ProgressWindow.xaml.cs b/ChunkDBExtractor/ProgressWindow.xaml.cs index 9bb01a4..2799e82 100644 --- a/ChunkDBExtractor/ProgressWindow.xaml.cs +++ b/ChunkDBExtractor/ProgressWindow.xaml.cs @@ -1,18 +1,52 @@ -using System.Windows; +using System; +using System.Windows; +using System.Windows.Threading; namespace ChunkDBExtractor { public partial class ProgressWindow : Window { + private DispatcherTimer animationTimer; + private int dotCount = 0; + private string baseText = "Processing"; + public ProgressWindow() { InitializeComponent(); + + // Initialize the animation timer + animationTimer = new DispatcherTimer(); + animationTimer.Interval = TimeSpan.FromMilliseconds(500); // Update every 500ms + animationTimer.Tick += UpdateAnimation; } - public void UpdateProgress(double value, string fileName) + private void UpdateAnimation(object sender, EventArgs e) { - FileNameTextBlock.Text = $"Processing: {fileName}"; - ProgressBar.Value = value; + dotCount = (dotCount + 1) % 4; // Cycle between 0, 1, 2, 3 + string dots = new string('.', dotCount); + FileNameTextBlock.Text = $"{baseText}{dots}"; + } + + public void StartAnimation() + { + animationTimer.Start(); + } + + public void StopAnimation() + { + Dispatcher.Invoke(() => + { + animationTimer.Stop(); + FileNameTextBlock.Text = "Extraction Complete"; + }); + } + + public void UpdateProgress(string fileName) + { + Dispatcher.Invoke(() => + { + baseText = $"Processing: {fileName}"; // Update the base text with the current filename + }); } } } \ No newline at end of file