add ProgressBar per chunkdb

This commit is contained in:
ApfelTeeSaft
2024-09-16 13:29:33 +02:00
parent 5410bfaecf
commit 106a322e4a
4 changed files with 79 additions and 21 deletions
@@ -6,9 +6,17 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
</ItemGroup>
<ItemGroup>
<Compile Update="ProgressWindow.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Update="MainWindow.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="ProgressWindow.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
</Project>
+42 -21
View File
@@ -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
+11
View File
@@ -0,0 +1,11 @@
<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">
<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>
+18
View File
@@ -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;
}
}
}