Added VDF Generator

This commit is contained in:
2026-05-31 11:06:50 +02:00
parent ec7031d9fd
commit ab391186f2
13 changed files with 720 additions and 17 deletions

View File

@@ -1,6 +1,9 @@
using EonaCat.FirstLight.SaveTransfer.VdfGenerator.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
@@ -31,6 +34,7 @@ public partial class MainWindow : Window
PanelResign.Visibility = Visibility.Collapsed;
PanelDecrypt.Visibility = Visibility.Collapsed;
PanelVdf.Visibility = Visibility.Collapsed;
PanelLog.Visibility = Visibility.Collapsed;
if (tab == TabResign)
@@ -43,6 +47,11 @@ public partial class MainWindow : Window
PanelDecrypt.Visibility = Visibility.Visible;
}
if (tab == TabVdf)
{
PanelVdf.Visibility = Visibility.Visible;
}
if (tab == TabLog)
{
PanelLog.Visibility = Visibility.Visible;
@@ -73,6 +82,18 @@ public partial class MainWindow : Window
TxtDecryptFolder.Foreground = (Brush)FindResource("TextPrimaryBrush");
}
private void BrowseVdfRemoteFolder_Click(object sender, RoutedEventArgs e)
{
string? path = BrowseForFolder();
if (path is null)
{
return;
}
TxtVdfRemoteFolder.Text = path;
TxtVdfRemoteFolder.Foreground = (Brush)FindResource("TextPrimaryBrush");
}
private static string? BrowseForFolder()
{
var dlg = new Microsoft.Win32.OpenFolderDialog
@@ -341,6 +362,86 @@ public partial class MainWindow : Window
return (processedCount, summary);
}
private async void BtnGenerateVdf_Click(object sender, RoutedEventArgs e)
{
string folder = TxtVdfRemoteFolder.Text.Trim();
if (string.IsNullOrEmpty(folder) || folder.StartsWith("Click"))
{ ShowBanner(VdfResultBanner, VdfResultText, "Please select a remote folder first.", BannerKind.Error); return; }
if (!Directory.Exists(folder))
{ ShowBanner(VdfResultBanner, VdfResultText, "The selected folder does not exist.", BannerKind.Error); return; }
SetBusy(true, BtnGenerateVdf, VdfProgress);
HideBanner(VdfResultBanner);
var log = new List<string>();
string summary;
try
{
summary = await Task.Run(() => RunGenerateVdf(folder, log));
}
catch (Exception ex)
{
summary = $"Error generating VDF: {ex.Message}";
log.Add($"[ERROR] {ex.Message}");
}
finally
{
SetBusy(false, BtnGenerateVdf, VdfProgress);
}
AppendLog(log);
UpdateStatusBar("VDF generation completed.");
bool success = !summary.StartsWith("Error");
ShowBanner(VdfResultBanner, VdfResultText, summary,
success ? BannerKind.Success : BannerKind.Error);
}
private static string RunGenerateVdf(string remoteFolderPath, List<string> log)
{
try
{
log.Add("[INFO] Generating VDF from remote folder...");
var remoteCacheVdfFile = new RemoteCacheVdfFile(remoteFolderPath);
log.Add($"[INFO] Found {remoteCacheVdfFile.CachedFiles.Count} files in remote folder.");
var outputDirectory = remoteFolderPath;
if (string.IsNullOrEmpty(outputDirectory))
{
outputDirectory = AppDomain.CurrentDomain.BaseDirectory;
}
// Check if we already have a remotecache.vdf in the target location
string outputPath = Path.Combine(outputDirectory, $"{RemoteCacheVdfFile.FileName}{RemoteCacheVdfFile.FileExtension}");
if (File.Exists(outputPath))
{
log.Add($"[WARNING] A file named {RemoteCacheVdfFile.FileName}{RemoteCacheVdfFile.FileExtension} already exists in the target location.");
// Create a backup of the existing file
string backupPath = Path.Combine(outputDirectory, $"{RemoteCacheVdfFile.FileName}_backup_{DateTime.Now:yyyyMMddHHmmss}{RemoteCacheVdfFile.FileExtension}");
if (File.Exists(backupPath))
{
log.Add($"[WARNING] Backup file {backupPath} already exists. Overwriting backup.");
File.Delete(backupPath);
}
File.Move(outputPath, backupPath);
}
remoteCacheVdfFile.ExportAsFile(outputDirectory);
log.Add($"[SUCCESS] VDF file generated successfully.");
log.Add($"[INFO] Output: {Path.Combine(outputDirectory, "remotecache.vdf")}");
return $"✓ VDF generated successfully with {remoteCacheVdfFile.CachedFiles.Count} files.";
}
catch (Exception ex)
{
log.Add($"[ERROR] {ex.Message}");
return $"Error: {ex.Message}";
}
}
private void AppendLog(IEnumerable<string> lines)
{
Dispatcher.Invoke(() =>