mirror of
https://github.com/ApfelTeeSaft/ChunkDBExtractor.git
synced 2026-08-26 19:23:30 +00:00
fix a few things
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
<Window x:Class="ChunkDBExtractor.ProgressWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Processing..." Height="150" Width="400" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
|
||||
Title="Processing..." Height="120" Width="400" WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow">
|
||||
<Grid>
|
||||
<StackPanel Margin="20">
|
||||
<TextBlock Name="FileNameTextBlock" FontSize="16" TextAlignment="Center" Margin="0,0,0,10"/>
|
||||
<ProgressBar Name="ProgressBar" Height="30" Minimum="0" Maximum="100" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user