From aabe596064d155393c294940f91618b6b1733b9e Mon Sep 17 00:00:00 2001 From: WeeXnes Date: Mon, 21 Apr 2025 03:49:47 +0200 Subject: [PATCH] updates --- PS2_Manager/AddGameWindow.axaml | 1 + PS2_Manager/App.axaml.cs | 25 ++++++++- PS2_Manager/Core/Game.cs | 20 ++++++- PS2_Manager/Core/Util.cs | 15 ++++++ PS2_Manager/EditGame.axaml | 12 +++++ PS2_Manager/EditGame.axaml.cs | 23 +++++++++ PS2_Manager/GameInfo.axaml | 20 +++++++ PS2_Manager/GameInfo.axaml.cs | 27 ++++++++++ PS2_Manager/MainWindow.axaml | 92 ++++++++++++++++++++++++--------- PS2_Manager/MainWindow.axaml.cs | 55 +++++++++++++++----- PS2_Manager/Setup.axaml | 32 ++++++++++++ PS2_Manager/Setup.axaml.cs | 62 ++++++++++++++++++++++ 12 files changed, 345 insertions(+), 39 deletions(-) create mode 100644 PS2_Manager/EditGame.axaml create mode 100644 PS2_Manager/EditGame.axaml.cs create mode 100644 PS2_Manager/GameInfo.axaml create mode 100644 PS2_Manager/GameInfo.axaml.cs create mode 100644 PS2_Manager/Setup.axaml create mode 100644 PS2_Manager/Setup.axaml.cs diff --git a/PS2_Manager/AddGameWindow.axaml b/PS2_Manager/AddGameWindow.axaml index 5ab76d7..cebadc7 100644 --- a/PS2_Manager/AddGameWindow.axaml +++ b/PS2_Manager/AddGameWindow.axaml @@ -8,6 +8,7 @@ CanResize="False" x:Class="PS2_Manager.AddGameWindow" Title="Install Game" + WindowStartupLocation="CenterScreen" Loaded="Control_OnLoaded" SizeChanged="Control_OnSizeChanged" Background="#201c29" diff --git a/PS2_Manager/App.axaml.cs b/PS2_Manager/App.axaml.cs index 828014b..95221a1 100644 --- a/PS2_Manager/App.axaml.cs +++ b/PS2_Manager/App.axaml.cs @@ -1,4 +1,6 @@ +using System; using Avalonia; +using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; using PS2_Manager.Core; @@ -17,7 +19,28 @@ public partial class App : Application Globals.LoadSettings(); if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - desktop.MainWindow = new MainWindow(); + if (String.IsNullOrEmpty(settings.library_path.GetValue())) + { + var setupWindow = new Setup(); + + setupWindow.Closed += (_, _) => + { + // Replace MainWindow after setup finishes + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + var mainWindow = new MainWindow(); + desktop.MainWindow = mainWindow; + mainWindow.Show(); + } + }; + + desktop.MainWindow = setupWindow; + } + else + { + desktop.MainWindow = new MainWindow(); + } + } base.OnFrameworkInitializationCompleted(); diff --git a/PS2_Manager/Core/Game.cs b/PS2_Manager/Core/Game.cs index 5be4e5d..dc7f0a2 100644 --- a/PS2_Manager/Core/Game.cs +++ b/PS2_Manager/Core/Game.cs @@ -19,11 +19,26 @@ public class Game public EventHandler? InstallationFinished { get; set; } public UpdateVar InstallProgress { get; private set; } - public Game(string isoPath) + public Game(string isoPath, bool installed = false) { this.GamePath = isoPath; this.GameID = ISO.GetSerial(isoPath); - this.Cover = this.GetCover(); + if (!installed) + { + this.Cover = this.GetCover(); + } + else + { + this.Name = ParseFormattedFilename(Path.GetFileName(isoPath)); + this.Cover = new Bitmap(Path.Combine(Path.Combine(settings.library_path.GetValue(), "ART"), this.GameID + "_COV.png")); + } + } + + + private string ParseFormattedFilename(string filename) + { + string[] parts = filename.Split('.'); + return parts[^2]; } public async void Install() @@ -86,6 +101,7 @@ public class Game this.InstallCover(); this.InstallationFinished?.Invoke(this, EventArgs.Empty); + MainWindow.RefreshGamesListTrigger?.Invoke(this, EventArgs.Empty); Console.WriteLine($"Copied ISO to: {destPath}"); } diff --git a/PS2_Manager/Core/Util.cs b/PS2_Manager/Core/Util.cs index 11d0d4d..82bd122 100644 --- a/PS2_Manager/Core/Util.cs +++ b/PS2_Manager/Core/Util.cs @@ -24,4 +24,19 @@ public static class Util var result = dialog.ShowAsync(parent).GetAwaiter().GetResult(); return result?.FirstOrDefault(); } + public static string FormatFileSize(long bytes) + { + string[] sizes = { "B", "KB", "MB", "GB", "TB" }; + double len = bytes; + int order = 0; + + while (len >= 1024 && order < sizes.Length - 1) + { + order++; + len /= 1024; + } + + // Format to 1 decimal place + return string.Format("{0:0.0} {1}", len, sizes[order]); + } } \ No newline at end of file diff --git a/PS2_Manager/EditGame.axaml b/PS2_Manager/EditGame.axaml new file mode 100644 index 0000000..1a22835 --- /dev/null +++ b/PS2_Manager/EditGame.axaml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/PS2_Manager/EditGame.axaml.cs b/PS2_Manager/EditGame.axaml.cs new file mode 100644 index 0000000..de668ba --- /dev/null +++ b/PS2_Manager/EditGame.axaml.cs @@ -0,0 +1,23 @@ +using System; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using PS2_Manager.Core; + +namespace PS2_Manager; + +public partial class EditGame : UserControl +{ + public Game game { get; set; } + public EditGame(Game _game) + { + this.game = _game; + InitializeComponent(); + } + + private void DisplayNameBox_OnTextChanged(object? sender, TextChangedEventArgs e) + { + this.game.Name = DisplayNameBox.Text; + MainWindow.RefreshGamesListTrigger.Invoke(null, EventArgs.Empty); + } +} \ No newline at end of file diff --git a/PS2_Manager/GameInfo.axaml b/PS2_Manager/GameInfo.axaml new file mode 100644 index 0000000..5c4964b --- /dev/null +++ b/PS2_Manager/GameInfo.axaml @@ -0,0 +1,20 @@ + + + + + + + + + + + diff --git a/PS2_Manager/GameInfo.axaml.cs b/PS2_Manager/GameInfo.axaml.cs new file mode 100644 index 0000000..3d82344 --- /dev/null +++ b/PS2_Manager/GameInfo.axaml.cs @@ -0,0 +1,27 @@ +using System; +using System.IO; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Interactivity; +using Avalonia.Markup.Xaml; +using PS2_Manager.Core; + +namespace PS2_Manager; + +public partial class GameInfo : UserControl +{ + public Game game { get; set; } + public GameInfo(Game _game) + { + InitializeComponent(); + this.game = _game; + CoverImage.Source = game.Cover; + GameNameTextBlock.Text = game.Name; + GameIdTextBlock.Text = game.GameID; + FileInfo fileInfo = new FileInfo(game.GamePath); + IsoSizeTextBlock.Text = Util.FormatFileSize(fileInfo.Length); + DateTime lastModified = fileInfo.LastWriteTime; + string formattedDate = lastModified.ToString("dd.MM.yyyy HH:mm"); + GameDateTextBlock.Text = formattedDate; + } +} \ No newline at end of file diff --git a/PS2_Manager/MainWindow.axaml b/PS2_Manager/MainWindow.axaml index 0cc0c81..6600ac9 100644 --- a/PS2_Manager/MainWindow.axaml +++ b/PS2_Manager/MainWindow.axaml @@ -2,38 +2,84 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:local="clr-namespace:PS2_Manager.Core" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="PS2_Manager.MainWindow" Title="PS2_Manager" - Background="#201c29" + Background="Transparent" SystemDecorations="None" - Width="880" + Width="990" Height="520" + WindowStartupLocation="CenterScreen" Loaded="Control_OnLoaded"> - - - - - - - - - + + + + + + + + - + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + diff --git a/PS2_Manager/MainWindow.axaml.cs b/PS2_Manager/MainWindow.axaml.cs index 4f3c9bc..05edbb4 100644 --- a/PS2_Manager/MainWindow.axaml.cs +++ b/PS2_Manager/MainWindow.axaml.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using Avalonia.Controls; using Avalonia.Input; @@ -10,9 +11,20 @@ namespace PS2_Manager; public partial class MainWindow : Window { + public static EventHandler? RefreshGamesListTrigger { get; set; } public MainWindow() { InitializeComponent(); + RefreshGamesListTrigger += FetchGamesFromLibrary; + } + + + + private void ShowcaseGame(Game game) + { + GameShowcaseGrid.IsVisible = true; + InfoWindow.Child = new GameInfo(game); + GameEdit.Child = new EditGame(game); } private void WindowDrag(object? sender, PointerPressedEventArgs e) @@ -34,7 +46,7 @@ public partial class MainWindow : Window var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions { - Title = "Open Text File", + Title = "Select PS2 Iso file to install", AllowMultiple = false, FileTypeFilter = new [] { @@ -52,18 +64,35 @@ public partial class MainWindow : Window private async void Control_OnLoaded(object? sender, RoutedEventArgs e) { WindowTitle.Text = "PS2 Games Manager"; - if (String.IsNullOrEmpty(settings.library_path.GetValue())) - { - var topLevel = TopLevel.GetTopLevel(this); - var path = await topLevel.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions - { - Title = "Open Game Library", - AllowMultiple = false - }); - Console.WriteLine(path[0].Path.LocalPath); - if(!String.IsNullOrEmpty(path[0].Path.LocalPath)) - settings.library_path.SetValue(path[0].Path.LocalPath); - } + FetchGamesFromLibrary(); } + public void FetchGamesFromLibrary(object? sender = null, EventArgs? e = null) + { + List Games = new List(); + Console.WriteLine("Loading library..."); + string[] files = Directory.GetFiles(Path.Combine(settings.library_path.GetValue(), "DVD")); + foreach (var file in files) + { + Console.WriteLine(file); + Game newGame = + new Game(file, true); + Games.Add(newGame); + } + GamesList.ItemsSource = Games; + } + + private void GamesList_OnSelectionChanged(object? sender, SelectionChangedEventArgs e) + { + if (GamesList.SelectedItem is Game selectedGame) + { + Console.WriteLine($"Clicked on game: {selectedGame.Name}, ID: {selectedGame.GameID}"); + this.ShowcaseGame(selectedGame); + } + } + + private void Context_RefreshGames(object? sender, RoutedEventArgs e) + { + FetchGamesFromLibrary(); + } } \ No newline at end of file diff --git a/PS2_Manager/Setup.axaml b/PS2_Manager/Setup.axaml new file mode 100644 index 0000000..237768b --- /dev/null +++ b/PS2_Manager/Setup.axaml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + +