From bf04a30272d8defc63f9c82d392ea3b7c13bcdc1 Mon Sep 17 00:00:00 2001 From: SuperSonic16 <25761885+thesupersonic16@users.noreply.github.com> Date: Thu, 28 Nov 2024 01:36:26 +1100 Subject: [PATCH] More GameBanana changes --- Source/HedgeModManager.UI/GameBanana.cs | 1 + Source/HedgeModManager.UI/Program.cs | 29 +++++++++++++++++++ .../ViewModels/ModDownloaderViewModel.cs | 2 ++ .../ViewModels/Mods/ModConfigViewModel.cs | 11 ++++--- .../Views/MainWindow.axaml.cs | 3 ++ 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/Source/HedgeModManager.UI/GameBanana.cs b/Source/HedgeModManager.UI/GameBanana.cs index a61ad1e..afd89b6 100644 --- a/Source/HedgeModManager.UI/GameBanana.cs +++ b/Source/HedgeModManager.UI/GameBanana.cs @@ -69,6 +69,7 @@ public static class GameBanana Images = profilePage.PreviewMedia.Images.Select(x => $"{x.BaseURL}/{x.FilePath}").ToList(), DownloadURL = downloadURL, }; + Logger.Information("Finished downloading item data"); return downloadInfo; } diff --git a/Source/HedgeModManager.UI/Program.cs b/Source/HedgeModManager.UI/Program.cs index eb3fb16..835dc23 100644 --- a/Source/HedgeModManager.UI/Program.cs +++ b/Source/HedgeModManager.UI/Program.cs @@ -1,5 +1,6 @@ using Avalonia; using HedgeModManager.UI.CLI; +using Microsoft.Win32; using System; using System.IO.Pipes; using System.IO; @@ -8,6 +9,7 @@ using System.Threading; using System.Text.Json; using System.Collections.Generic; +using System.Runtime.Versioning; namespace HedgeModManager.UI; @@ -70,6 +72,33 @@ public static void Main(string[] args) CurrentMutex?.Dispose(); } + public static void InstallURIHandler() + { + if (OperatingSystem.IsWindows()) + { + foreach (string schema in GameBanana.GameIDMapping.Keys) + installToRegistery(schema, "-gb \"%1\""); + } + + [SupportedOSPlatform("windows")] + static void installToRegistery(string schema, string args) + { + if (Environment.ProcessPath is not string processPath) + return; + + try + { + var reg = Registry.CurrentUser.CreateSubKey($"Software\\Classes\\{schema}"); + reg.SetValue("", $"URL:{ApplicationName}"); + reg.SetValue("URL Protocol", ""); + reg = reg.CreateSubKey("shell\\open\\command"); + reg.SetValue("", $"\"{processPath}\" {args}"); + reg.Close(); + } + catch { } + } + } + // Avalonia configuration, don't remove; also used by visual designer. public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() diff --git a/Source/HedgeModManager.UI/ViewModels/ModDownloaderViewModel.cs b/Source/HedgeModManager.UI/ViewModels/ModDownloaderViewModel.cs index 2369a6c..0109cf7 100644 --- a/Source/HedgeModManager.UI/ViewModels/ModDownloaderViewModel.cs +++ b/Source/HedgeModManager.UI/ViewModels/ModDownloaderViewModel.cs @@ -11,6 +11,7 @@ namespace HedgeModManager.UI.ViewModels; public partial class ModDownloaderViewModel : ViewModelBase { [ObservableProperty] private bool _ready = false; + [ObservableProperty] private bool _loading = true; [ObservableProperty] private string _title = "Common.Text.Loading"; [ObservableProperty] private string _description = ""; [ObservableProperty] private ModDownloadInfo? _downloadInfo; @@ -37,6 +38,7 @@ public async Task StartInfoDownload() if (DownloadInfo != null) { Ready = true; + Loading = false; Update(); } } diff --git a/Source/HedgeModManager.UI/ViewModels/Mods/ModConfigViewModel.cs b/Source/HedgeModManager.UI/ViewModels/Mods/ModConfigViewModel.cs index 5491a1c..428c35b 100644 --- a/Source/HedgeModManager.UI/ViewModels/Mods/ModConfigViewModel.cs +++ b/Source/HedgeModManager.UI/ViewModels/Mods/ModConfigViewModel.cs @@ -52,13 +52,11 @@ public ValidatableConfigElement(ModConfig.ConfigElement element) public IEnumerable GetErrors(string? propertyName) { - switch (propertyName) + return propertyName switch { - case nameof(Value): - return new[] { ErrorText }; - default: - return Array.Empty(); - } + nameof(Value) => [ErrorText], + _ => Array.Empty(), + }; } protected override void OnPropertyChanged(PropertyChangedEventArgs e) @@ -99,6 +97,7 @@ protected override void OnPropertyChanged(PropertyChangedEventArgs e) default: break; } + ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(e.PropertyName)); } base.OnPropertyChanged(e); } diff --git a/Source/HedgeModManager.UI/Views/MainWindow.axaml.cs b/Source/HedgeModManager.UI/Views/MainWindow.axaml.cs index 591d566..ca7a6b8 100644 --- a/Source/HedgeModManager.UI/Views/MainWindow.axaml.cs +++ b/Source/HedgeModManager.UI/Views/MainWindow.axaml.cs @@ -29,6 +29,9 @@ private async void Window_Loaded(object? sender, RoutedEventArgs e) Logger.Information($"Initialising codes..."); CodeProvider.TryLoadRoslyn(); + Logger.Information($"Loading URI handlers..."); + Program.InstallURIHandler(); + Logger.Information($"Locating games..."); ViewModel.Games = new(Games.GetUIGames(ModdableGameLocator.LocateGames())); //ViewModel.Games = new();