diff --git a/src/RomManager/AppLogger.cs b/src/RomManager/AppLogger.cs new file mode 100644 index 0000000..f2dd214 --- /dev/null +++ b/src/RomManager/AppLogger.cs @@ -0,0 +1,16 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; + +namespace RomManager; + +public static class AppLogger +{ + // Globally accessible static logger instance + public static ILogger Instance { get; private set; } = NullLogger.Instance; + + public static void Initialize(ILoggerFactory factory) + { + // Creates a named logger for your static context + Instance = factory.CreateLogger("GlobalApplication"); + } +} diff --git a/src/RomManager/Assets/Icons/Games/favourite.png b/src/RomManager/Assets/Icons/Games/favourite.png new file mode 100644 index 0000000..028f515 Binary files /dev/null and b/src/RomManager/Assets/Icons/Games/favourite.png differ diff --git a/src/RomManager/Assets/Icons/Games/unfavourite.png b/src/RomManager/Assets/Icons/Games/unfavourite.png new file mode 100644 index 0000000..3eade9a Binary files /dev/null and b/src/RomManager/Assets/Icons/Games/unfavourite.png differ diff --git a/src/RomManager/Converters/FavouriteToImageConverter.cs b/src/RomManager/Converters/FavouriteToImageConverter.cs new file mode 100644 index 0000000..afcd1f5 --- /dev/null +++ b/src/RomManager/Converters/FavouriteToImageConverter.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Globalization; +using Avalonia.Data.Converters; +using Avalonia.Media; +using Avalonia.Media.Imaging; +using Avalonia.Platform; +using RomManager.Core.RegionDetection; + +namespace RomManager.Converters; + +public sealed class FavouriteToImageConverter : IValueConverter +{ + + private IImage? _favourite; + private IImage? _unfavourite; + + + + + public FavouriteToImageConverter() + { + _favourite = LoadImage("favourite.png"); + _unfavourite = LoadImage("unfavourite.png"); + } + + private static IImage? LoadImage(string fileName) + { + try + { + var uri = new Uri($"avares://RomManager/Assets/Icons/Games/{fileName}"); + using var stream = AssetLoader.Open(uri); + return new Bitmap(stream); + } + catch (Exception) + { + return null; + } + } + public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) + { + if (value is not bool icon) + { + return null; + } + + return icon ? _favourite : _unfavourite; + } + + public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) + { + throw new NotSupportedException(); + } + + + + +} diff --git a/src/RomManager/Models/Game.cs b/src/RomManager/Models/Game.cs index 08f37d2..7c54f7c 100644 --- a/src/RomManager/Models/Game.cs +++ b/src/RomManager/Models/Game.cs @@ -1,9 +1,11 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using Avalonia.Media; using Avalonia.Media.Imaging; +using Avalonia.Platform; using CommunityToolkit.Mvvm.ComponentModel; using RomManager.Core.RegionDetection; using RomManager.Models.FileTypes; @@ -19,12 +21,13 @@ public partial class Game : ObservableObject private IEnumerable _files = []; [ObservableProperty] private IImage? _coverArt; - [ObservableProperty] private GameInfo? _info; + [ObservableProperty] private GameInfo? _info ; [ObservableProperty] private SystemInfo[] _systems; [ObservableProperty] private Region[] _regions = [Region.Unknown]; + public void Load() { var art = Files.OfType().FirstOrDefault(); @@ -33,6 +36,7 @@ public void Load() CoverArt = new Bitmap(art.Filename); } + Systems = Files.OfType().Select(f => f.SystemInfo).ToArray(); // Detect regions from the ROM file diff --git a/src/RomManager/Models/SystemInfo.cs b/src/RomManager/Models/SystemInfo.cs index cf7d5a6..930e7d9 100644 --- a/src/RomManager/Models/SystemInfo.cs +++ b/src/RomManager/Models/SystemInfo.cs @@ -73,6 +73,7 @@ private Game GetGame(PathsConfiguration pathsConfiguration, string file) GameInfo gameInfo; if (!GameList.GamesByFilename.TryGetValue(System.IO.Path.GetFileName(file), out gameInfo)) { + gameInfo = new GameInfo { Path = file, Name = System.IO.Path.GetFileNameWithoutExtension(file) }; } diff --git a/src/RomManager/Pages/LibraryPage.axaml b/src/RomManager/Pages/LibraryPage.axaml index babf43c..4f0553b 100644 --- a/src/RomManager/Pages/LibraryPage.axaml +++ b/src/RomManager/Pages/LibraryPage.axaml @@ -14,6 +14,7 @@ + @@ -149,11 +150,19 @@ Width="18" HorizontalAlignment="Center" VerticalAlignment="Center" Height="18" ToolTip.Tip="{Binding Name}" /> + + - + + AppBuilder .UsePlatformDetect() .WithInterFont() .LogToTrace(); + public static void InitialiseLoggerFactory() + { + using ILoggerFactory factory = LoggerFactory.Create(builder => + { + builder.AddConsole(); + builder.SetMinimumLevel(LogLevel.Debug); + }); + AppLogger.Initialize(factory); + AppLogger.Instance.LogInformation("Application started via static pipeline."); + } } + diff --git a/src/RomManager/ViewModels/LibraryPageViewModel.cs b/src/RomManager/ViewModels/LibraryPageViewModel.cs index 4723cb6..6473f26 100644 --- a/src/RomManager/ViewModels/LibraryPageViewModel.cs +++ b/src/RomManager/ViewModels/LibraryPageViewModel.cs @@ -28,6 +28,8 @@ public partial class LibraryPageViewModel : ObservableObject [ObservableProperty] private int _pageSize = 30; [ObservableProperty] private int _filteredGamesCount; + + public LibraryPageViewModel(Core.RomManager romManager, FilenameFilterBuilder filenameFilterBuilder, IOptions pathsConfiguration) { _filenameFilterBuilder = filenameFilterBuilder;