2 Commits
Author SHA1 Message Date
ApfelTeeSaft 4b1b9f3e1f fix a few things 2024-09-16 13:52:09 +02:00
ApfelTeeSaft 106a322e4a add ProgressBar per chunkdb 2024-09-16 13:29:33 +02:00
4 changed files with 117 additions and 27 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>
+47 -27
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;
@@ -62,15 +63,25 @@ namespace ChunkDBExtractor
return;
}
try
ProgressWindow progressWindow = new ProgressWindow();
progressWindow.Owner = this;
progressWindow.ShowInTaskbar = false;
Task.Run(async () =>
{
ExtractChunkDBFiles(sourceFolder, destinationFolder);
progressWindow.Dispatcher.Invoke(() => progressWindow.StartAnimation());
await ExtractChunkDBFilesAsync(sourceFolder, destinationFolder, progressWindow);
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()
@@ -78,31 +89,17 @@ 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");
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(Path.GetFileName(file));
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);
}
}
await Task.Run(() => ExtractChunkDBFile(file, destination));
}
catch (Exception ex)
{
@@ -111,6 +108,29 @@ namespace ChunkDBExtractor
}
}
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
private class FChunkDatabase
{
+10
View File
@@ -0,0 +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="120" Width="400" WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow">
<Grid>
<StackPanel Margin="20">
<TextBlock Name="FileNameTextBlock" FontSize="16" TextAlignment="Center" Margin="0,0,0,10"/>
</StackPanel>
</Grid>
</Window>
+52
View File
@@ -0,0 +1,52 @@
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;
}
private void UpdateAnimation(object sender, EventArgs e)
{
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
});
}
}
}