This commit is contained in:
WeeXnes 2025-04-22 00:27:17 +02:00
parent 0f8c65c61c
commit e6e356a9da
9 changed files with 114 additions and 5 deletions

View file

@ -28,6 +28,7 @@ public partial class AddGameWindow : Window
{ {
IsoPathBox.Text = this.newGame.GamePath; IsoPathBox.Text = this.newGame.GamePath;
SerialBox.Text = this.newGame.GameID; SerialBox.Text = this.newGame.GameID;
GameNameBox.Text = this.newGame.Name;
CoverImage.Source = this.newGame.ArtworkFront; CoverImage.Source = this.newGame.ArtworkFront;
} }

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Text.Json;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;

View file

@ -3,6 +3,7 @@ using System.ComponentModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
@ -29,7 +30,10 @@ public class Game
this.GameID = ISO.GetSerial(isoPath); this.GameID = ISO.GetSerial(isoPath);
if (!installed) 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 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<GameInfoApi>(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() public void GetChecksum()
{ {
string filePath = this.GamePath; string filePath = this.GamePath;
@ -77,11 +108,23 @@ public class Game
await this.CopyIsoWithProgressAsync(); await this.CopyIsoWithProgressAsync();
} }
private Bitmap GetCover() private Bitmap DownloadCover(Artwork.Type type)
{ {
Bitmap cover = null; 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 try
{ {
@ -101,6 +144,11 @@ public class Game
return cover; return cover;
} }
public void Uninstall()
{
File.Delete(this.GamePath);
}
public async Task CopyIsoWithProgressAsync() public async Task CopyIsoWithProgressAsync()
{ {
string targetDirectory = settings.library_path.GetValue<string>(); string targetDirectory = settings.library_path.GetValue<string>();
@ -129,6 +177,9 @@ public class Game
} }
//this.InstallCover(); //this.InstallCover();
this.SaveCover(Artwork.Type.Front);
this.SaveCover(Artwork.Type.Back);
this.SaveCover(Artwork.Type.Disc);
this.InstallationFinished?.Invoke(this, EventArgs.Empty); this.InstallationFinished?.Invoke(this, EventArgs.Empty);
MainWindow.RefreshGamesListTrigger?.Invoke(this, EventArgs.Empty); MainWindow.RefreshGamesListTrigger?.Invoke(this, EventArgs.Empty);

View file

@ -56,3 +56,9 @@ public class UpdateVar<T>
protected virtual void OnValueChanged() => ValueChanged?.Invoke(); protected virtual void OnValueChanged() => ValueChanged?.Invoke();
} }
public class GameInfoApi
{
public string id { get; set; }
public string title { get; set; }
}

View file

@ -99,6 +99,7 @@ public partial class GameInfo : UserControl
this.game.ArtworkDVD = new Bitmap(files[0].Path.LocalPath); this.game.ArtworkDVD = new Bitmap(files[0].Path.LocalPath);
break; break;
} }
this.game.SaveCover(ArtworkType.Value); this.game.SaveCover(ArtworkType.Value);
UpdateArtworks(); UpdateArtworks();
MainWindow.RefreshGamesListTrigger?.Invoke(null, EventArgs.Empty); MainWindow.RefreshGamesListTrigger?.Invoke(null, EventArgs.Empty);

View file

@ -37,7 +37,7 @@
<Border Background="Transparent" Padding="10"> <Border Background="Transparent" Padding="10">
<Border.ContextMenu> <Border.ContextMenu>
<ContextMenu> <ContextMenu>
<MenuItem Header="Remove Game"/> <MenuItem Header="Remove Game" Click="DeleteButton"/>
<MenuItem Header="Show Details"/> <MenuItem Header="Show Details"/>
</ContextMenu> </ContextMenu>
</Border.ContextMenu> </Border.ContextMenu>

View file

@ -64,6 +64,7 @@ public partial class MainWindow : Window
private async void Control_OnLoaded(object? sender, RoutedEventArgs e) private async void Control_OnLoaded(object? sender, RoutedEventArgs e)
{ {
WindowTitle.Text = "PS2 Games Manager"; WindowTitle.Text = "PS2 Games Manager";
GameEdit.Child = new Welcome();
FetchGamesFromLibrary(); FetchGamesFromLibrary();
} }
@ -71,6 +72,7 @@ public partial class MainWindow : Window
{ {
List<Game> Games = new List<Game>(); List<Game> Games = new List<Game>();
Console.WriteLine("Loading library..."); Console.WriteLine("Loading library...");
Util.CheckDir(Path.Combine(settings.library_path.GetValue<string>(), "DVD"));
string[] files = Directory.GetFiles(Path.Combine(settings.library_path.GetValue<string>(), "DVD")); string[] files = Directory.GetFiles(Path.Combine(settings.library_path.GetValue<string>(), "DVD"));
foreach (var file in files) foreach (var file in files)
{ {
@ -86,13 +88,21 @@ public partial class MainWindow : Window
{ {
if (GamesList.SelectedItem is Game selectedGame) if (GamesList.SelectedItem is Game selectedGame)
{ {
Console.WriteLine($"Clicked on game: {selectedGame.Name}, ID: {selectedGame.GameID}");
this.ShowcaseGame(selectedGame); 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) private void Context_RefreshGames(object? sender, RoutedEventArgs e)
{ {
FetchGamesFromLibrary(); FetchGamesFromLibrary();
} }
} }

15
PS2_Manager/Welcome.axaml Normal file
View file

@ -0,0 +1,15 @@
<UserControl xmlns="https://github.com/avaloniaui"
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"
mc:Ignorable="d"
x:Class="PS2_Manager.Welcome">
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Center" Spacing="10">
<TextBlock Text="Welcome to the PS2 Games Manager" HorizontalAlignment="Center" FontSize="18" FontWeight="Bold"/>
<Separator HorizontalAlignment="Center"/>
<TextBlock Text="by WeeXnes" HorizontalAlignment="Center" FontStyle="Italic"/>
<Separator HorizontalAlignment="Center"/>
<TextBlock Text="Check out the source code and contribute at:" HorizontalAlignment="Center" Margin="10"/>
<Button Content="PS2 Manager Repository" HorizontalAlignment="Center" Click="OnRepositoryLinkClicked"/>
</StackPanel>
</UserControl>

View file

@ -0,0 +1,24 @@
using System.Diagnostics;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
namespace PS2_Manager;
public partial class Welcome : UserControl
{
public Welcome()
{
InitializeComponent();
}
private void OnRepositoryLinkClicked(object sender, RoutedEventArgs e)
{
// Open the link in the default web browser
Process.Start(new ProcessStartInfo
{
FileName = "https://git.weexnes.dev/WeeXnes/ps2_manager",
UseShellExecute = true
});
}
}