Merge branch 'experimental'

This commit is contained in:
WeeXnes 2025-04-26 18:16:55 +02:00
commit d7479b9fec
10 changed files with 379 additions and 388 deletions

View file

@ -1,30 +0,0 @@
<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" 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"/>
<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"
Click="Edit_OnClick"/>
<Button Content="Save" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"
Click="Save_OnClick"/>
</Grid>
</Grid>
</UserControl>

View file

@ -1,82 +0,0 @@
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;
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.Info("MD5 Hash calculated");
MD5TextBlock.Text = "MD5: " + MD5Hash.Value;
});
};
SHA1Hash.ValueChanged += () =>
{
Dispatcher.UIThread.Invoke(() =>
{
Console.Info("SHA1 Hash calculated");
SHATextBlock.Text = "SHA1: " + SHA1Hash.Value;
});
};
}
private void ChecksumButtonOnClick(object? sender, RoutedEventArgs e)
{
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();
Console.Info("MD5 Hashing started...");
sha1Worker.RunWorkerAsync();
Console.Info("SHA1 Hashing started...");
}
private void Save_OnClick(object? sender, RoutedEventArgs e)
{
this.game.ChangeName(DisplayNameBox.Text);
MainWindow.RefreshGamesListTrigger?.Invoke(null, EventArgs.Empty);
}
private void Edit_OnClick(object? sender, RoutedEventArgs e)
{
DisplayNameBox.Text = game.Name;
}
}

View file

@ -4,27 +4,5 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" mc:Ignorable="d"
x:Class="PS2_Manager.GameInfo"> x:Class="PS2_Manager.GameInfo">
<Grid RowDefinitions="350, *, *, *, *">
<Grid Grid.Row="0" ColumnDefinitions="*, 205, *">
<Button Grid.Column="0" Content="←" HorizontalAlignment="Center" VerticalAlignment="Center" Click="PrevButton"/>
<Button Grid.Column="2" Content="→" HorizontalAlignment="Center" VerticalAlignment="Center" Click="NextButton"/>
<Border Grid.Column="1" Width="205" Height="292" Background="Transparent" CornerRadius="5" HorizontalAlignment="Center" VerticalAlignment="Center"
PointerPressed="CoverImage_OnPointerPressed" Name="CoverContainer">
<Grid>
<Image Name="CoverImage" Source="Images/missing.png" Stretch="UniformToFill"/>
<TextBlock Name="CoverTextHint" HorizontalAlignment="Center" VerticalAlignment="Center" IsVisible="False"/>
</Grid>
</Border>
</Grid>
<TextBlock Grid.Row="1" Text="" HorizontalAlignment="Center"
Name="GameNameTextBlock"/>
<TextBlock Grid.Row="2" Text="" HorizontalAlignment="Center"
Name="GameIdTextBlock"/>
<TextBlock Grid.Row="3" Text="" HorizontalAlignment="Center"
Name="IsoSizeTextBlock"/>
<TextBlock Grid.Row="4" Text="" HorizontalAlignment="Center"
Name="GameDateTextBlock"/>
</Grid>
</UserControl> </UserControl>

View file

@ -14,112 +14,16 @@ namespace PS2_Manager;
public partial class GameInfo : UserControl public partial class GameInfo : UserControl
{ {
public UpdateVar<Artwork.Type> ArtworkType { get; set; } = new UpdateVar<Artwork.Type>();
public Game game { get; set; } public Game game { get; set; }
public GameInfo(Game _game) public GameInfo(Game _game)
{ {
InitializeComponent(); InitializeComponent();
this.game = _game; this.game = _game;
ArtworkType.ValueChanged += UpdateArtworks;
ArtworkType.Value = Artwork.Type.Front;
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;
} }
private void UpdateArtworks()
{
Console.Info("Showing: " + ArtworkType.Value.ToString());
Bitmap? tempBitmap = null;
switch (ArtworkType.Value)
{
case Artwork.Type.Front:
CoverContainer.Height = 292;
tempBitmap = game.ArtworkFront;
break;
case Artwork.Type.Back:
CoverContainer.Height = 292;
tempBitmap = game.ArtworkBack;
break;
case Artwork.Type.Disc:
CoverContainer.Height = CoverContainer.Width;
tempBitmap = game.ArtworkDVD;
break;
}
if (Util.IsBitmapEmpty(tempBitmap))
{
CoverContainer.Background = new SolidColorBrush(Color.Parse("#201c29"));
CoverTextHint.IsVisible = true;
}
else
{
CoverContainer.Background = Brushes.Transparent;
CoverTextHint.IsVisible = false;
}
CoverTextHint.Text = ArtworkType.Value.ToString();
CoverImage.Source = tempBitmap;
}
private async void CoverImage_OnPointerPressed(object? sender, PointerPressedEventArgs e)
{
var topLevel = TopLevel.GetTopLevel(this);
var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
{
Title = "Select a Cover for the PS2 Game",
AllowMultiple = false,
FileTypeFilter = new []
{
Globals.FileDialogTypes.PS2Cover
}
});
if (files.Count >= 1)
{
switch (ArtworkType.Value)
{
case Artwork.Type.Front:
this.game.ArtworkFront = new Bitmap(files[0].Path.LocalPath);
break;
case Artwork.Type.Back:
this.game.ArtworkBack = new Bitmap(files[0].Path.LocalPath);
break;
case Artwork.Type.Disc:
this.game.ArtworkDVD = new Bitmap(files[0].Path.LocalPath);
break;
}
Console.Info("Updating " + ArtworkType.Value + " Artwork for " + this.game.GameID);
this.game.SaveCover(ArtworkType.Value);
UpdateArtworks();
MainWindow.RefreshGamesListTrigger?.Invoke(null, EventArgs.Empty);
}
else
{
Console.Error("OpenFilePicker was called but Canceled or no Files selected");
}
}
private void NextButton(object? sender, RoutedEventArgs e)
{
this.ArtworkType.Value = Artwork.NextType(this.ArtworkType.Value);
}
private void PrevButton(object? sender, RoutedEventArgs e)
{
this.ArtworkType.Value = Artwork.PrevType(this.ArtworkType.Value);
}
} }

View file

@ -5,33 +5,21 @@
xmlns:local="clr-namespace:PS2_Manager.Core" xmlns:local="clr-namespace:PS2_Manager.Core"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="PS2_Manager.MainWindow" x:Class="PS2_Manager.MainWindow"
Title="PS2_Manager" Title="PS2 Games Manager"
Background="Transparent" Background="#201c29"
SystemDecorations="None"
Width="990" Width="990"
Height="520" Height="520"
MinHeight="490"
MinWidth="600"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
Loaded="Control_OnLoaded"> Loaded="Control_OnLoaded"
<Grid ColumnDefinitions="680, 10, 300" Background="Transparent"> Foreground="White">
<Grid Grid.Column="0" RowDefinitions="20, *"> <Grid ColumnDefinitions="*, 10, *, 10, 320" Background="Transparent">
<Grid Grid.Row="0"> <Grid Grid.Column="0">
<Border Background="#35313d" <Border CornerRadius="0,0,10,10">
PointerPressed="WindowDrag">
<Grid ColumnDefinitions="*, 20">
<TextBlock Name="WindowTitle" FontSize="12" Padding="8,0,0,0" VerticalAlignment="Center"/>
<Border Grid.Column="1" Background="#625f69" PointerPressed="WindowClose">
<TextBlock FontSize="12" Text="×" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</Grid>
</Border>
</Grid>
<Grid Grid.Row="1">
<Border Background="#201c29" CornerRadius="0,0,10,10">
<Grid ColumnDefinitions="300, 1, *">
<Border CornerRadius="10" Margin="5"> <Border CornerRadius="10" Margin="5">
<ListBox Name="GamesList" Background="Transparent" <ListBox Name="GamesList" Background="Transparent"
SelectionChanged="GamesList_OnSelectionChanged" SelectionChanged="GamesList_OnSelectionChanged">
>
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate x:DataType="local:Game"> <DataTemplate x:DataType="local:Game">
<Border Background="Transparent" Padding="10"> <Border Background="Transparent" Padding="10">
@ -41,7 +29,7 @@
<MenuItem Header="Show Details"/> <MenuItem Header="Show Details"/>
</ContextMenu> </ContextMenu>
</Border.ContextMenu> </Border.ContextMenu>
<TextBlock Text="{Binding Name}"/> <TextBlock Foreground="White" Text="{Binding Name}"/>
</Border> </Border>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
@ -62,24 +50,98 @@
</ListBox.Styles> </ListBox.Styles>
</ListBox> </ListBox>
</Border> </Border>
</Border>
</Grid>
<Border Grid.Column="1"> <Border Grid.Column="1">
<Border Width="1" Background="#35313d" Margin="2,10"/> <Border Width="1" Background="#35313d" Margin="2,10"/>
</Border> </Border>
<Border Grid.Column="2"> <Border Grid.Column="2">
<Border Margin="2,0,0,0" Name="GameEdit"> <Border Margin="2,0,0,0">
<Grid>
<StackPanel Name="WelcomePanel"
Orientation="Vertical"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Spacing="10">
<TextBlock Text="Welcome to the PS2 Games Manager"
HorizontalAlignment="Center"
TextAlignment="Center"
FontSize="18"
FontWeight="Bold"
TextWrapping="Wrap"/>
<Separator HorizontalAlignment="Center"/>
<TextBlock Text="by WeeXnes"
HorizontalAlignment="Center"
TextAlignment="Center"
FontStyle="Italic"
TextWrapping="Wrap"/>
<Separator HorizontalAlignment="Center"/>
<TextBlock Text="Check out the source code and contribute at:"
HorizontalAlignment="Center"
TextAlignment="Center"
Margin="10"
TextWrapping="Wrap"/>
<Button Content="PS2 Manager Repository"
HorizontalAlignment="Center"
Click="OnRepositoryLinkClicked"/>
</StackPanel>
<Grid RowDefinitions="*, 40, 10" Name="GameEdit" IsVisible="False">
<ScrollViewer Grid.Row="0">
<StackPanel Orientation="Vertical" Margin="10">
<TextBlock Foreground="White" Text="Display Name:" HorizontalAlignment="Center" Padding="0,10"/>
<TextBox Foreground="White" Name="NameTextBox_Edit"/>
<Separator/>
<Button Foreground="White" Content="Calculate Checksums" Click="ChecksumButtonOnClick" HorizontalAlignment="Stretch"></Button>
<Border Background="#35313d" CornerRadius="5" Padding="10" Margin="0,5" IsVisible="False" Name="ChecksumArea">
<StackPanel>
<TextBlock Foreground="White" FontSize="10" Name="MD5TextBlock"/>
<TextBlock Foreground="White" FontSize="10" Name="SHATextBlock"/>
</StackPanel>
</Border> </Border>
</Border> </StackPanel>
</Grid> </ScrollViewer>
</Border> <Grid Grid.Row="1" ColumnDefinitions="*,*">
<Button Foreground="White" Content="Undo" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"
Click="Undo_OnClick"/>
<Button Foreground="White" Content="Save" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"
Click="Save_OnClick"/>
</Grid> </Grid>
</Grid> </Grid>
</Grid>
</Border>
</Border>
<Grid Grid.Column="2" RowDefinitions="20, *" IsVisible="False" Name="GameShowcaseGrid"> <Border Grid.Column="4" Background="#35313d" CornerRadius="10" Name="InfoWindow" Margin="10">
<Border Grid.Row="1" Background="#35313d" CornerRadius="10" Name="InfoWindow" > <Grid>
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center" Name="GameInfoPlaceholder">
<TextBlock Text="Select a Game"/>
</StackPanel>
<Grid RowDefinitions="*, 350, 20, 20, 20, 20, *" Name="GameInfo" IsVisible="False">
<Grid Grid.Row="1" ColumnDefinitions="*, 205, *">
<Button Foreground="White" Grid.Column="0" Content="←" HorizontalAlignment="Center" VerticalAlignment="Center" Click="PrevButton"/>
<Button Foreground="White" Grid.Column="2" Content="→" HorizontalAlignment="Center" VerticalAlignment="Center" Click="NextButton"/>
<Border Grid.Column="1" Width="205" Height="292" Background="Transparent" CornerRadius="5" HorizontalAlignment="Center" VerticalAlignment="Center"
PointerPressed="CoverImage_OnPointerPressed" Name="CoverContainer">
<Grid>
<Image Name="CoverImage" Source="Images/missing.png" Stretch="UniformToFill"/>
<TextBlock Name="CoverTextHint" HorizontalAlignment="Center" VerticalAlignment="Center" IsVisible="False"/>
</Grid>
</Border> </Border>
</Grid> </Grid>
<TextBlock Foreground="White" Grid.Row="2" Text="" HorizontalAlignment="Center"
Name="GameNameTextBlock"/>
<TextBlock Foreground="White" Grid.Row="3" Text="" HorizontalAlignment="Center"
Name="GameIdTextBlock"/>
<TextBlock Foreground="White" Grid.Row="4" Text="" HorizontalAlignment="Center"
Name="IsoSizeTextBlock"/>
<TextBlock Foreground="White" Grid.Row="5" Text="" HorizontalAlignment="Center"
Name="GameDateTextBlock"/>
</Grid>
</Grid>
</Border>
</Grid> </Grid>
</Window> </Window>

View file

@ -1,11 +1,16 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Platform.Storage; using Avalonia.Platform.Storage;
using Avalonia.Threading;
using PS2_Manager.Core; using PS2_Manager.Core;
namespace PS2_Manager; namespace PS2_Manager;
@ -13,22 +18,78 @@ namespace PS2_Manager;
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
public static EventHandler? RefreshGamesListTrigger { get; set; } public static EventHandler? RefreshGamesListTrigger { get; set; }
public UpdateVar<Artwork.Type> ArtworkType { get; set; } = new UpdateVar<Artwork.Type>();
public UpdateVar<string> MD5Hash { get; set; } = new UpdateVar<string>();
public UpdateVar<string> SHA1Hash { get; set; } = new UpdateVar<string>();
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
RefreshGamesListTrigger += FetchGamesFromLibrary; RefreshGamesListTrigger += FetchGamesFromLibrary;
} ArtworkType.ValueChanged += UpdateArtworks;
MD5Hash.ValueChanged += () =>
private void ShowcaseGame(Game game)
{ {
GameShowcaseGrid.IsVisible = true; Dispatcher.UIThread.Invoke(() =>
InfoWindow.Child = new GameInfo(game); {
GameEdit.Child = new EditGame(game); Console.Info("MD5 Hash calculated");
Console.Info(game + " set as Showcase"); MD5TextBlock.Text = "MD5: " + MD5Hash.Value;
});
};
SHA1Hash.ValueChanged += () =>
{
Dispatcher.UIThread.Invoke(() =>
{
Console.Info("SHA1 Hash calculated");
SHATextBlock.Text = "SHA1: " + SHA1Hash.Value;
});
};
} }
private void GamesList_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (GamesList.SelectedItem is Game selectedGame)
{
Console.Info("Selected " + selectedGame + " from ListView");
SetEditArea();
SetShowcaseArea();
SwitchView(false);
}
}
private void SwitchView(bool placeholder)
{
GameEdit.IsVisible = !placeholder;
WelcomePanel.IsVisible = placeholder;
GameInfo.IsVisible = !placeholder;
GameInfoPlaceholder.IsVisible = placeholder;
}
private void SetShowcaseArea()
{
if (GamesList.SelectedItem is Game selectedGame)
{
ArtworkType.Value = Artwork.Type.Front;
GameNameTextBlock.Text = selectedGame.Name;
GameIdTextBlock.Text = selectedGame.GameID;
FileInfo fileInfo = new FileInfo(selectedGame.GamePath);
IsoSizeTextBlock.Text = Util.FormatFileSize(fileInfo.Length);
DateTime lastModified = fileInfo.LastWriteTime;
string formattedDate = lastModified.ToString("dd.MM.yyyy HH:mm");
GameDateTextBlock.Text = formattedDate;
}
}
private void SetEditArea()
{
if (GamesList.SelectedItem is Game selectedGame)
{
ChecksumArea.IsVisible = false;
NameTextBox_Edit.Text = selectedGame.Name;
}
}
private void WindowDrag(object? sender, PointerPressedEventArgs e) private void WindowDrag(object? sender, PointerPressedEventArgs e)
{ {
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
@ -70,13 +131,12 @@ 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";
GameEdit.Child = new Welcome();
FetchGamesFromLibrary(); FetchGamesFromLibrary();
} }
public void FetchGamesFromLibrary(object? sender = null, EventArgs? e = null) public void FetchGamesFromLibrary(object? sender = null, EventArgs? e = null)
{ {
SwitchView(true);
Console.Info("Fetching games from library..."); Console.Info("Fetching games from library...");
List<Game> Games = new List<Game>(); List<Game> Games = new List<Game>();
Util.CheckDir(Path.Combine(settings.library_path.GetValue<string>(), "DVD")); Util.CheckDir(Path.Combine(settings.library_path.GetValue<string>(), "DVD"));
@ -92,14 +152,7 @@ public partial class MainWindow : Window
GamesList.ItemsSource = Games; GamesList.ItemsSource = Games;
} }
private void GamesList_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (GamesList.SelectedItem is Game selectedGame)
{
Console.Info("Selected " + selectedGame + " from ListView");
this.ShowcaseGame(selectedGame);
}
}
private void DeleteButton(object? sender, RoutedEventArgs e) private void DeleteButton(object? sender, RoutedEventArgs e)
{ {
if (GamesList.SelectedItem is Game selectedGame) if (GamesList.SelectedItem is Game selectedGame)
@ -115,4 +168,176 @@ public partial class MainWindow : Window
FetchGamesFromLibrary(); FetchGamesFromLibrary();
} }
//Game Edit Area/////////////////////////////////////////////////////////////
private void OnRepositoryLinkClicked(object sender, RoutedEventArgs e)
{
Console.Info("Repository Link Clicked");
Process.Start(new ProcessStartInfo
{
FileName = "https://git.weexnes.dev/WeeXnes/ps2_manager",
UseShellExecute = true
});
}
private void Save_OnClick(object? sender, RoutedEventArgs e)
{
if (GamesList.SelectedItem is Game selectedGame)
{
selectedGame.ChangeName(NameTextBox_Edit.Text ?? "Error");
MainWindow.RefreshGamesListTrigger?.Invoke(null, EventArgs.Empty);
}
}
private void Undo_OnClick(object? sender, RoutedEventArgs e)
{
if (GamesList.SelectedItem is Game selectedGame)
{
NameTextBox_Edit.Text = selectedGame.Name;
}
}
private void ChecksumButtonOnClick(object? sender, RoutedEventArgs e)
{
this.GetChecksum();
}
public void GetChecksum()
{
if (GamesList.SelectedItem is Game selectedGame)
{
string filePath = selectedGame.GamePath;
this.MD5Hash.Value = "Loading...";
this.SHA1Hash.Value = "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();
Console.Info("MD5 Hashing started...");
sha1Worker.RunWorkerAsync();
Console.Info("SHA1 Hashing started...");
}
}
//Game Showcase Area/////////////////////////////////////////////////////////////
private void UpdateArtworks()
{
if (GamesList.SelectedItem is Game selectedGame)
{
Console.Info("Showing: " + ArtworkType.Value.ToString());
Bitmap? tempBitmap = null;
switch (ArtworkType.Value)
{
case Artwork.Type.Front:
CoverContainer.Height = 292;
tempBitmap = selectedGame.ArtworkFront;
break;
case Artwork.Type.Back:
CoverContainer.Height = 292;
tempBitmap = selectedGame.ArtworkBack;
break;
case Artwork.Type.Disc:
CoverContainer.Height = CoverContainer.Width;
tempBitmap = selectedGame.ArtworkDVD;
break;
}
if (Util.IsBitmapEmpty(tempBitmap))
{
CoverContainer.Background = new SolidColorBrush(Color.Parse("#201c29"));
CoverTextHint.IsVisible = true;
}
else
{
CoverContainer.Background = Brushes.Transparent;
CoverTextHint.IsVisible = false;
}
CoverTextHint.Text = ArtworkType.Value.ToString();
CoverImage.Source = tempBitmap;
}
}
private async void CoverImage_OnPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (GamesList.SelectedItem is Game selectedGame)
{
var topLevel = TopLevel.GetTopLevel(this);
var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
{
Title = "Select a Cover for the PS2 Game",
AllowMultiple = false,
FileTypeFilter = new []
{
Globals.FileDialogTypes.PS2Cover
}
});
if (files.Count >= 1)
{
switch (ArtworkType.Value)
{
case Artwork.Type.Front:
selectedGame.ArtworkFront = new Bitmap(files[0].Path.LocalPath);
break;
case Artwork.Type.Back:
selectedGame.ArtworkBack = new Bitmap(files[0].Path.LocalPath);
break;
case Artwork.Type.Disc:
selectedGame.ArtworkDVD = new Bitmap(files[0].Path.LocalPath);
break;
}
Console.Info("Updating " + ArtworkType.Value + " Artwork for " + selectedGame.GameID);
selectedGame.SaveCover(ArtworkType.Value);
UpdateArtworks();
MainWindow.RefreshGamesListTrigger?.Invoke(null, EventArgs.Empty);
}
else
{
Console.Error("OpenFilePicker was called but Canceled or no Files selected");
}
}
}
private void NextButton(object? sender, RoutedEventArgs e)
{
this.ArtworkType.Value = Artwork.NextType(this.ArtworkType.Value);
}
private void PrevButton(object? sender, RoutedEventArgs e)
{
this.ArtworkType.Value = Artwork.PrevType(this.ArtworkType.Value);
}
} }

View file

@ -1,31 +0,0 @@
<Window 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" d:DesignWidth="800" d:DesignHeight="450"
x:Class="PS2_Manager.MessageBox"
Title="MessageBox"
SystemDecorations="None">
<Grid RowDefinitions="20, *">
<Grid Grid.Row="0">
<Border Background="#35313d"
PointerPressed="WindowDrag">
<Grid ColumnDefinitions="*, 20">
<TextBlock Name="WindowTitle" FontSize="12" Text="Install Game" Padding="8,0,0,0" VerticalAlignment="Center"/>
<Border Grid.Column="1" Background="#4b4753">
<TextBlock FontSize="12" Text="×" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</Grid>
</Border>
</Grid>
<Grid Grid.Row="1" ColumnDefinitions="Auto,Auto,*" Margin="20">
<Border Margin="0,0,0,0">
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<Label Content="Oh no! an error has occurred" Foreground="White" HorizontalAlignment="Center" FontSize="25"/>
<Label Content="full exception log has been dumped into error__log.txt" Foreground="White" HorizontalAlignment="Center" FontSize="12"/>
<Label Content="" Name="ErrorDump" Foreground="Gray" HorizontalAlignment="Center" FontSize="12" Padding="0,15,0,0"/>
</StackPanel>
</Border>
</Grid>
</Grid>
</Window>

View file

@ -1,22 +0,0 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
namespace PS2_Manager;
public partial class MessageBox : Window
{
public MessageBox(string messageContent)
{
InitializeComponent();
ErrorDump.Content = "Exception: " + messageContent;
}
private void WindowDrag(object? sender, PointerPressedEventArgs e)
{
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
{
BeginMoveDrag(e);
}
}
}

View file

@ -4,12 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" mc:Ignorable="d"
x:Class="PS2_Manager.Welcome"> x:Class="PS2_Manager.Welcome">
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Center" Spacing="10"> <StackPanel >
<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> </StackPanel>
</UserControl> </UserControl>

View file

@ -12,13 +12,5 @@ public partial class Welcome : UserControl
{ {
InitializeComponent(); InitializeComponent();
} }
private void OnRepositoryLinkClicked(object sender, RoutedEventArgs e)
{
Console.Info("Repository Link Clicked");
Process.Start(new ProcessStartInfo
{
FileName = "https://git.weexnes.dev/WeeXnes/ps2_manager",
UseShellExecute = true
});
}
} }