working prototype

This commit is contained in:
WeeXnes 2025-04-22 01:09:48 +02:00
parent e6e356a9da
commit 62595f612e
4 changed files with 72 additions and 32 deletions

View file

@ -71,30 +71,7 @@ public class Game
}
}
public void GetChecksum()
{
string filePath = this.GamePath;
BackgroundWorker md5Worker = new BackgroundWorker();
BackgroundWorker sha1Worker = new BackgroundWorker();
md5Worker.DoWork += (s, e) =>
{
string md5 = Checksum.GetMD5Hash(filePath);
Console.WriteLine("MD5: " + md5);
};
sha1Worker.DoWork += (s, e) =>
{
string sha1 = Checksum.GetSHA1Hash(filePath);
Console.WriteLine("SHA1: " + sha1);
};
md5Worker.RunWorkerAsync();
sha1Worker.RunWorkerAsync();
Console.WriteLine("Hashing started...");
}
private string ParseFormattedFilename(string filename)
{

View file

@ -5,9 +5,24 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="PS2_Manager.EditGame">
<Grid RowDefinitions="*, 40">
<ScrollViewer Grid.Row="0">
<StackPanel Orientation="Vertical" Margin="10">
<TextBlock Text="Display Name:" HorizontalAlignment="Center" Padding="0,10"/>
<TextBox Name="DisplayNameBox" TextChanged="DisplayNameBox_OnTextChanged"/>
<Button Click="Button_OnClick"></Button>
<Separator/>
<Button Content="Calculate Checksums" Click="ChecksumButtonOnClick" HorizontalAlignment="Stretch"></Button>
<Border Background="#35313d" CornerRadius="5" Padding="10" Margin="0,5" IsVisible="False" Name="ChecksumArea">
<StackPanel>
<TextBlock FontSize="10" Name="MD5TextBlock"/>
<TextBlock FontSize="10" Name="SHATextBlock"/>
</StackPanel>
</Border>
</StackPanel>
</ScrollViewer>
<Grid Grid.Row="1" ColumnDefinitions="*,*">
<Button Content="Undo" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Button Content="Save" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Grid>
</UserControl>

View file

@ -1,8 +1,10 @@
using System;
using System.ComponentModel;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;
using PS2_Manager.Core;
namespace PS2_Manager;
@ -10,10 +12,29 @@ namespace PS2_Manager;
public partial class EditGame : UserControl
{
public Game game { get; set; }
public UpdateVar<string> MD5Hash { get; set; } = new UpdateVar<string>();
public UpdateVar<string> SHA1Hash { get; set; } = new UpdateVar<string>();
public EditGame(Game _game)
{
this.game = _game;
InitializeComponent();
DisplayNameBox.Text = this.game.Name;
MD5Hash.ValueChanged += () =>
{
Dispatcher.UIThread.Invoke(() =>
{
Console.WriteLine("MD5Hash.ValueChanged");
MD5TextBlock.Text = "MD5: " + MD5Hash.Value;
});
};
SHA1Hash.ValueChanged += () =>
{
Dispatcher.UIThread.Invoke(() =>
{
Console.WriteLine("SHA1Hash.ValueChanged");
SHATextBlock.Text = "SHA1: " + SHA1Hash.Value;
});
};
}
private void DisplayNameBox_OnTextChanged(object? sender, TextChangedEventArgs e)
@ -22,8 +43,35 @@ public partial class EditGame : UserControl
MainWindow.RefreshGamesListTrigger.Invoke(null, EventArgs.Empty);
}
private void Button_OnClick(object? sender, RoutedEventArgs e)
private void ChecksumButtonOnClick(object? sender, RoutedEventArgs e)
{
this.game.GetChecksum();
this.GetChecksum();
}
public void GetChecksum()
{
string filePath = this.game.GamePath;
MD5TextBlock.Text = "MD5: Loading...";
SHATextBlock.Text = "SHA1: Loading...";
ChecksumArea.IsVisible = true;
BackgroundWorker md5Worker = new BackgroundWorker();
BackgroundWorker sha1Worker = new BackgroundWorker();
md5Worker.DoWork += (s, e) =>
{
this.MD5Hash.Value = Checksum.GetMD5Hash(filePath);
};
sha1Worker.DoWork += (s, e) =>
{
this.SHA1Hash.Value = Checksum.GetSHA1Hash(filePath);
};
md5Worker.RunWorkerAsync();
sha1Worker.RunWorkerAsync();
Console.WriteLine("Hashing started...");
}
}