fixes
This commit is contained in:
parent
aabe596064
commit
2ee895494c
6 changed files with 80 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
@ -7,6 +8,7 @@ using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Media.Imaging;
|
using Avalonia.Media.Imaging;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
|
using Microsoft.VisualBasic.CompilerServices;
|
||||||
|
|
||||||
namespace PS2_Manager.Core;
|
namespace PS2_Manager.Core;
|
||||||
|
|
||||||
|
@ -34,6 +36,30 @@ 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)
|
private string ParseFormattedFilename(string filename)
|
||||||
{
|
{
|
||||||
|
@ -74,8 +100,7 @@ public class Game
|
||||||
public async Task CopyIsoWithProgressAsync()
|
public async Task CopyIsoWithProgressAsync()
|
||||||
{
|
{
|
||||||
string targetDirectory = settings.library_path.GetValue<string>();
|
string targetDirectory = settings.library_path.GetValue<string>();
|
||||||
if(!Directory.Exists(Path.Combine(targetDirectory, "DVD")))
|
Util.CheckDir(Path.Combine(targetDirectory, "DVD"));
|
||||||
Directory.CreateDirectory(Path.Combine(targetDirectory, "DVD"));
|
|
||||||
|
|
||||||
string newFileName = $"{this.GameID}.{this.Name}.iso";
|
string newFileName = $"{this.GameID}.{this.Name}.iso";
|
||||||
string destPath = Path.Combine(Path.Combine(targetDirectory, "DVD"), newFileName);
|
string destPath = Path.Combine(Path.Combine(targetDirectory, "DVD"), newFileName);
|
||||||
|
@ -113,9 +138,7 @@ public class Game
|
||||||
public void InstallCover()
|
public void InstallCover()
|
||||||
{
|
{
|
||||||
string targetDirectory = settings.library_path.GetValue<string>();
|
string targetDirectory = settings.library_path.GetValue<string>();
|
||||||
if(!Directory.Exists(Path.Combine(targetDirectory, "ART")))
|
Util.CheckDir(Path.Combine(targetDirectory, "ART"));
|
||||||
Directory.CreateDirectory(Path.Combine(targetDirectory, "ART"));
|
|
||||||
//this.Cover.Save(Path.Combine(Path.Combine(targetDirectory, "ART"), this.GameID + "_COV.png"));
|
|
||||||
this.Cover.CreateScaledBitmap(
|
this.Cover.CreateScaledBitmap(
|
||||||
new PixelSize(353, 500),
|
new PixelSize(353, 500),
|
||||||
BitmapInterpolationMode.HighQuality
|
BitmapInterpolationMode.HighQuality
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.Shapes;
|
||||||
using Avalonia.Media.Imaging;
|
using Avalonia.Media.Imaging;
|
||||||
|
|
||||||
namespace PS2_Manager.Core;
|
namespace PS2_Manager.Core;
|
||||||
|
@ -24,6 +28,12 @@ public static class Util
|
||||||
var result = dialog.ShowAsync(parent).GetAwaiter().GetResult();
|
var result = dialog.ShowAsync(parent).GetAwaiter().GetResult();
|
||||||
return result?.FirstOrDefault();
|
return result?.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CheckDir(string path)
|
||||||
|
{
|
||||||
|
if(!Directory.Exists(path))
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
}
|
||||||
public static string FormatFileSize(long bytes)
|
public static string FormatFileSize(long bytes)
|
||||||
{
|
{
|
||||||
string[] sizes = { "B", "KB", "MB", "GB", "TB" };
|
string[] sizes = { "B", "KB", "MB", "GB", "TB" };
|
||||||
|
@ -40,3 +50,28 @@ public static class Util
|
||||||
return string.Format("{0:0.0} {1}", len, sizes[order]);
|
return string.Format("{0:0.0} {1}", len, sizes[order]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class Checksum
|
||||||
|
{
|
||||||
|
public static string GetMD5Hash(string filePath)
|
||||||
|
{
|
||||||
|
using (var md5 = MD5.Create())
|
||||||
|
using (var stream = File.OpenRead(filePath))
|
||||||
|
{
|
||||||
|
var hash = md5.ComputeHash(stream);
|
||||||
|
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetSHA1Hash(string filePath)
|
||||||
|
{
|
||||||
|
using (var sha1 = SHA1.Create())
|
||||||
|
using (var stream = File.OpenRead(filePath))
|
||||||
|
{
|
||||||
|
var hash = sha1.ComputeHash(stream);
|
||||||
|
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -8,5 +8,6 @@
|
||||||
<StackPanel Orientation="Vertical" Margin="10">
|
<StackPanel Orientation="Vertical" Margin="10">
|
||||||
<TextBlock Text="Display Name:" HorizontalAlignment="Center" Padding="0,10"/>
|
<TextBlock Text="Display Name:" HorizontalAlignment="Center" Padding="0,10"/>
|
||||||
<TextBox Name="DisplayNameBox" TextChanged="DisplayNameBox_OnTextChanged"/>
|
<TextBox Name="DisplayNameBox" TextChanged="DisplayNameBox_OnTextChanged"/>
|
||||||
|
<Button Click="Button_OnClick"></Button>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
using PS2_Manager.Core;
|
using PS2_Manager.Core;
|
||||||
|
|
||||||
|
@ -20,4 +21,9 @@ public partial class EditGame : UserControl
|
||||||
this.game.Name = DisplayNameBox.Text;
|
this.game.Name = DisplayNameBox.Text;
|
||||||
MainWindow.RefreshGamesListTrigger.Invoke(null, EventArgs.Empty);
|
MainWindow.RefreshGamesListTrigger.Invoke(null, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Button_OnClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
this.game.GetChecksum();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,7 +9,8 @@
|
||||||
Title="Setup"
|
Title="Setup"
|
||||||
Height="349"
|
Height="349"
|
||||||
Width="598"
|
Width="598"
|
||||||
Background="#201c29">
|
Background="#201c29"
|
||||||
|
Closing="Window_OnClosing">
|
||||||
<Grid RowDefinitions="20, *">
|
<Grid RowDefinitions="20, *">
|
||||||
<Grid Grid.Row="0">
|
<Grid Grid.Row="0">
|
||||||
<Border Background="#35313d"
|
<Border Background="#35313d"
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace PS2_Manager;
|
||||||
|
|
||||||
public partial class Setup : Window
|
public partial class Setup : Window
|
||||||
{
|
{
|
||||||
|
private bool SetupFinished { get; set; } = false;
|
||||||
public Setup()
|
public Setup()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
@ -30,6 +31,7 @@ public partial class Setup : Window
|
||||||
InfoText2.Text = "You can now exit to the Main Application";
|
InfoText2.Text = "You can now exit to the Main Application";
|
||||||
OpenLibraryButton.Content = "Exit";
|
OpenLibraryButton.Content = "Exit";
|
||||||
OpenLibraryButton.Click -= OpenLibraryButton_OnClick;
|
OpenLibraryButton.Click -= OpenLibraryButton_OnClick;
|
||||||
|
this.SetupFinished = true;
|
||||||
OpenLibraryButton.Click += (sender, args) =>
|
OpenLibraryButton.Click += (sender, args) =>
|
||||||
{
|
{
|
||||||
this.Close();
|
this.Close();
|
||||||
|
@ -59,4 +61,9 @@ public partial class Setup : Window
|
||||||
}
|
}
|
||||||
FinishSetup();
|
FinishSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Window_OnClosing(object? sender, WindowClosingEventArgs e)
|
||||||
|
{
|
||||||
|
if(!this.SetupFinished) e.Cancel = true;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue