diff --git a/ChunkDBExtractor/ChunkDBExtractor.csproj.user b/ChunkDBExtractor/ChunkDBExtractor.csproj.user index 644b0a6..676e629 100644 --- a/ChunkDBExtractor/ChunkDBExtractor.csproj.user +++ b/ChunkDBExtractor/ChunkDBExtractor.csproj.user @@ -6,9 +6,17 @@ Designer + + + Code + + Designer + + Designer + \ No newline at end of file diff --git a/ChunkDBExtractor/MainWindow.xaml.cs b/ChunkDBExtractor/MainWindow.xaml.cs index 05d4da9..9e9b519 100644 --- a/ChunkDBExtractor/MainWindow.xaml.cs +++ b/ChunkDBExtractor/MainWindow.xaml.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Windows; +using System.Threading.Tasks; using Microsoft.Win32; using System.Collections.Generic; using ICSharpCode.SharpZipLib.Zip.Compression; @@ -54,7 +55,7 @@ namespace ChunkDBExtractor } } - private void ExtractButton_Click(object sender, RoutedEventArgs e) + private async void ExtractButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(sourceFolder) || string.IsNullOrEmpty(destinationFolder)) { @@ -64,7 +65,12 @@ namespace ChunkDBExtractor try { - ExtractChunkDBFiles(sourceFolder, destinationFolder); + ProgressWindow progressWindow = new ProgressWindow(); + progressWindow.Show(); + + await ExtractChunkDBFilesAsync(sourceFolder, destinationFolder, progressWindow); + + progressWindow.Close(); MessageBox.Show("Files extracted successfully!"); } catch (Exception ex) @@ -78,37 +84,52 @@ namespace ChunkDBExtractor ExtractButton.IsEnabled = !string.IsNullOrEmpty(sourceFolder) && !string.IsNullOrEmpty(destinationFolder); } - private void ExtractChunkDBFiles(string source, string destination) + private async Task ExtractChunkDBFilesAsync(string source, string destination, ProgressWindow progressWindow) { - foreach (var file in Directory.GetFiles(source, "*.chunkdb")) + var chunkdbFiles = Directory.GetFiles(source, "*.chunkdb"); + double progressPerFile = 100.0 / chunkdbFiles.Length; + double currentProgress = 0; + + foreach (var file in chunkdbFiles) { try { - using (var stream = File.OpenRead(file)) - using (var reader = new BinaryReader(stream)) - { - var chunkDatabase = new FChunkDatabase(reader); + progressWindow.UpdateProgress(currentProgress, Path.GetFileName(file)); - foreach (var location in chunkDatabase.Locations) - { - stream.Seek((long)location.ByteStart, SeekOrigin.Begin); - var chunkHeader = new FChunkHeader(reader); + await Task.Run(() => ExtractChunkDBFile(file, destination)); - var guidString = $"{chunkHeader.Guid.A:X8}{chunkHeader.Guid.B:X8}{chunkHeader.Guid.C:X8}{chunkHeader.Guid.D:X8}"; - var chunkFilePath = Path.Combine(destination, guidString); - - var chunkData = reader.ReadBytes((int)chunkHeader.DataSizeCompressed); - var decompressedData = chunkHeader.StoredAs == EChunkStorageFlags.None ? chunkData : FChunkHeader.Decompress(chunkData); - - File.WriteAllBytes(chunkFilePath, decompressedData); - } - } + 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) + { + using (var stream = File.OpenRead(file)) + using (var reader = new BinaryReader(stream)) + { + var chunkDatabase = new FChunkDatabase(reader); + + foreach (var location in chunkDatabase.Locations) + { + stream.Seek((long)location.ByteStart, SeekOrigin.Begin); + var chunkHeader = new FChunkHeader(reader); + + var guidString = $"{chunkHeader.Guid.A:X8}{chunkHeader.Guid.B:X8}{chunkHeader.Guid.C:X8}{chunkHeader.Guid.D:X8}"; + var chunkFilePath = Path.Combine(destination, guidString); + + var chunkData = reader.ReadBytes((int)chunkHeader.DataSizeCompressed); + var decompressedData = chunkHeader.StoredAs == EChunkStorageFlags.None ? chunkData : FChunkHeader.Decompress(chunkData); + + File.WriteAllBytes(chunkFilePath, decompressedData); + } + } } // ChunkDBTool diff --git a/ChunkDBExtractor/ProgressWindow.xaml b/ChunkDBExtractor/ProgressWindow.xaml new file mode 100644 index 0000000..72db85d --- /dev/null +++ b/ChunkDBExtractor/ProgressWindow.xaml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/ChunkDBExtractor/ProgressWindow.xaml.cs b/ChunkDBExtractor/ProgressWindow.xaml.cs new file mode 100644 index 0000000..9bb01a4 --- /dev/null +++ b/ChunkDBExtractor/ProgressWindow.xaml.cs @@ -0,0 +1,18 @@ +using System.Windows; + +namespace ChunkDBExtractor +{ + public partial class ProgressWindow : Window + { + public ProgressWindow() + { + InitializeComponent(); + } + + public void UpdateProgress(double value, string fileName) + { + FileNameTextBlock.Text = $"Processing: {fileName}"; + ProgressBar.Value = value; + } + } +} \ No newline at end of file