From e6e356a9da2851379538c9bb16fb026babbd7ac8 Mon Sep 17 00:00:00 2001 From: WeeXnes Date: Tue, 22 Apr 2025 00:27:17 +0200 Subject: [PATCH] update --- PS2_Manager/AddGameWindow.axaml.cs | 1 + PS2_Manager/App.axaml.cs | 1 + PS2_Manager/Core/Game.cs | 57 ++++++++++++++++++++++++++++-- PS2_Manager/Core/Globals.cs | 6 ++++ PS2_Manager/GameInfo.axaml.cs | 1 + PS2_Manager/MainWindow.axaml | 2 +- PS2_Manager/MainWindow.axaml.cs | 12 ++++++- PS2_Manager/Welcome.axaml | 15 ++++++++ PS2_Manager/Welcome.axaml.cs | 24 +++++++++++++ 9 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 PS2_Manager/Welcome.axaml create mode 100644 PS2_Manager/Welcome.axaml.cs diff --git a/PS2_Manager/AddGameWindow.axaml.cs b/PS2_Manager/AddGameWindow.axaml.cs index c769bb1..17c9eb0 100644 --- a/PS2_Manager/AddGameWindow.axaml.cs +++ b/PS2_Manager/AddGameWindow.axaml.cs @@ -28,6 +28,7 @@ public partial class AddGameWindow : Window { IsoPathBox.Text = this.newGame.GamePath; SerialBox.Text = this.newGame.GameID; + GameNameBox.Text = this.newGame.Name; CoverImage.Source = this.newGame.ArtworkFront; } diff --git a/PS2_Manager/App.axaml.cs b/PS2_Manager/App.axaml.cs index 95221a1..a4cfdcc 100644 --- a/PS2_Manager/App.axaml.cs +++ b/PS2_Manager/App.axaml.cs @@ -1,4 +1,5 @@ using System; +using System.Text.Json; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; diff --git a/PS2_Manager/Core/Game.cs b/PS2_Manager/Core/Game.cs index fadd2ec..69994c9 100644 --- a/PS2_Manager/Core/Game.cs +++ b/PS2_Manager/Core/Game.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.IO; using System.Linq; using System.Net.Http; +using System.Text.Json; using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; @@ -29,7 +30,10 @@ public class Game this.GameID = ISO.GetSerial(isoPath); if (!installed) { - this.ArtworkFront = this.GetCover(); + this.Name = this.GetGameTitle(); + this.ArtworkFront = this.DownloadCover(Artwork.Type.Front); + this.ArtworkBack = this.DownloadCover(Artwork.Type.Back); + this.ArtworkDVD = this.DownloadCover(Artwork.Type.Disc); } else { @@ -40,6 +44,33 @@ public class Game } } + public string GetGameTitle() + { + string url = $"http://localhost:3000/search/{this.GameID}"; + + try + { + using HttpClient client = new(); + string json = client.GetStringAsync(url).GetAwaiter().GetResult(); + Console.WriteLine(json); + + GameInfoApi? game = JsonSerializer.Deserialize(json); + string title = game?.title ?? "Title not found"; + + if (title.Length > 32) + { + title = title.Substring(0, 32); + } + + return title; + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + return ""; + } + } + public void GetChecksum() { string filePath = this.GamePath; @@ -77,11 +108,23 @@ public class Game await this.CopyIsoWithProgressAsync(); } - private Bitmap GetCover() + private Bitmap DownloadCover(Artwork.Type type) { Bitmap cover = null; - string url = $"https://github.com/xlenore/ps2-covers/blob/main/covers/default/{this.GameID.Replace(".", "").Replace("_", "-")}.jpg?raw=true"; + string url = ""; + switch (type) + { + case Artwork.Type.Front: + url = $"http://localhost:3000/art/{this.GameID}/{this.GameID}_COV.png"; + break; + case Artwork.Type.Back: + url = $"http://localhost:3000/art/{this.GameID}/{this.GameID}_COV2.png"; + break; + case Artwork.Type.Disc: + url = $"http://localhost:3000/art/{this.GameID}/{this.GameID}_ICO.png"; + break; + } try { @@ -100,6 +143,11 @@ public class Game return cover; } + + public void Uninstall() + { + File.Delete(this.GamePath); + } public async Task CopyIsoWithProgressAsync() { @@ -129,6 +177,9 @@ public class Game } //this.InstallCover(); + this.SaveCover(Artwork.Type.Front); + this.SaveCover(Artwork.Type.Back); + this.SaveCover(Artwork.Type.Disc); this.InstallationFinished?.Invoke(this, EventArgs.Empty); MainWindow.RefreshGamesListTrigger?.Invoke(this, EventArgs.Empty); diff --git a/PS2_Manager/Core/Globals.cs b/PS2_Manager/Core/Globals.cs index 2b76533..1e6d22a 100644 --- a/PS2_Manager/Core/Globals.cs +++ b/PS2_Manager/Core/Globals.cs @@ -55,4 +55,10 @@ public class UpdateVar } protected virtual void OnValueChanged() => ValueChanged?.Invoke(); +} + +public class GameInfoApi +{ + public string id { get; set; } + public string title { get; set; } } \ No newline at end of file diff --git a/PS2_Manager/GameInfo.axaml.cs b/PS2_Manager/GameInfo.axaml.cs index 5388cbb..bce5e0f 100644 --- a/PS2_Manager/GameInfo.axaml.cs +++ b/PS2_Manager/GameInfo.axaml.cs @@ -99,6 +99,7 @@ public partial class GameInfo : UserControl this.game.ArtworkDVD = new Bitmap(files[0].Path.LocalPath); break; } + this.game.SaveCover(ArtworkType.Value); UpdateArtworks(); MainWindow.RefreshGamesListTrigger?.Invoke(null, EventArgs.Empty); diff --git a/PS2_Manager/MainWindow.axaml b/PS2_Manager/MainWindow.axaml index 6600ac9..9540fd6 100644 --- a/PS2_Manager/MainWindow.axaml +++ b/PS2_Manager/MainWindow.axaml @@ -37,7 +37,7 @@ - + diff --git a/PS2_Manager/MainWindow.axaml.cs b/PS2_Manager/MainWindow.axaml.cs index 05edbb4..bf22296 100644 --- a/PS2_Manager/MainWindow.axaml.cs +++ b/PS2_Manager/MainWindow.axaml.cs @@ -64,6 +64,7 @@ public partial class MainWindow : Window private async void Control_OnLoaded(object? sender, RoutedEventArgs e) { WindowTitle.Text = "PS2 Games Manager"; + GameEdit.Child = new Welcome(); FetchGamesFromLibrary(); } @@ -71,6 +72,7 @@ public partial class MainWindow : Window { List Games = new List(); Console.WriteLine("Loading library..."); + Util.CheckDir(Path.Combine(settings.library_path.GetValue(), "DVD")); string[] files = Directory.GetFiles(Path.Combine(settings.library_path.GetValue(), "DVD")); foreach (var file in files) { @@ -86,13 +88,21 @@ public partial class MainWindow : Window { if (GamesList.SelectedItem is Game selectedGame) { - Console.WriteLine($"Clicked on game: {selectedGame.Name}, ID: {selectedGame.GameID}"); this.ShowcaseGame(selectedGame); } } + private void DeleteButton(object? sender, RoutedEventArgs e) + { + if (GamesList.SelectedItem is Game selectedGame) + { + selectedGame.Uninstall(); + RefreshGamesListTrigger?.Invoke(sender, e); + } + } private void Context_RefreshGames(object? sender, RoutedEventArgs e) { FetchGamesFromLibrary(); } + } \ No newline at end of file diff --git a/PS2_Manager/Welcome.axaml b/PS2_Manager/Welcome.axaml new file mode 100644 index 0000000..413b318 --- /dev/null +++ b/PS2_Manager/Welcome.axaml @@ -0,0 +1,15 @@ + + + + + + + +