From 67e3a9c10f7e49baa7b94ddc386d8c26255da65a Mon Sep 17 00:00:00 2001 From: slxdy Date: Fri, 15 Nov 2024 17:25:42 +0100 Subject: [PATCH] Added faster startup and install confirmation --- Directory.Build.props | 2 +- MelonLoader.Installer/MLManager.cs | 1 - .../MelonLoader.Installer.csproj | 12 ++++---- MelonLoader.Installer/Program.cs | 7 ++--- .../ViewModels/DetailsViewModel.cs | 29 +++++++++++++++++++ .../ViewModels/MainViewModel.cs | 12 ++++++++ MelonLoader.Installer/Views/DetailsView.axaml | 12 ++++---- .../Views/DetailsView.axaml.cs | 22 +++++++------- MelonLoader.Installer/Views/MainView.axaml | 11 ++++--- MelonLoader.Installer/Views/MainView.axaml.cs | 27 +++++++++++++++++ .../Views/MainWindow.axaml.cs | 5 ---- 11 files changed, 101 insertions(+), 39 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index e3a22c9..ee4489e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ enable - 11.1.4 + 11.2.1 diff --git a/MelonLoader.Installer/MLManager.cs b/MelonLoader.Installer/MLManager.cs index 3bc1c74..b9a7a4c 100644 --- a/MelonLoader.Installer/MLManager.cs +++ b/MelonLoader.Installer/MLManager.cs @@ -13,7 +13,6 @@ internal static class MLManager private static MLVersion? localBuild; public static List Versions { get; private set; } = []; - public static bool Initialized { get; private set; } static MLManager() { diff --git a/MelonLoader.Installer/MelonLoader.Installer.csproj b/MelonLoader.Installer/MelonLoader.Installer.csproj index 33df5ca..e7adc02 100644 --- a/MelonLoader.Installer/MelonLoader.Installer.csproj +++ b/MelonLoader.Installer/MelonLoader.Installer.csproj @@ -1,7 +1,7 @@  WinExe - net8.0-windows + net9.0-windows win-x64 enable enable @@ -33,12 +33,12 @@ - - - - + + + + - + diff --git a/MelonLoader.Installer/Program.cs b/MelonLoader.Installer/Program.cs index 81b0a41..9984a52 100644 --- a/MelonLoader.Installer/Program.cs +++ b/MelonLoader.Installer/Program.cs @@ -43,9 +43,6 @@ private static void Main(string[] args) if (!CheckProcessLock()) return; - if (!Updater.UpdateIfPossible()) - MLManager.Init(); - BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); Exiting?.Invoke(); @@ -95,11 +92,13 @@ private static bool CheckProcessLock() internal static void GrabAttention() => GrabAttention(Process.GetCurrentProcess()); + private static void GrabAttention(Process process) { - nint processHandle = process.MainWindowHandle; + var processHandle = process.MainWindowHandle; if (WindowsUtils.IsIconic(processHandle)) WindowsUtils.ShowWindow(processHandle, 9); + WindowsUtils.SetForegroundWindow(processHandle); WindowsUtils.BringWindowToTop(processHandle); } diff --git a/MelonLoader.Installer/ViewModels/DetailsViewModel.cs b/MelonLoader.Installer/ViewModels/DetailsViewModel.cs index 7b53b73..be2cc71 100644 --- a/MelonLoader.Installer/ViewModels/DetailsViewModel.cs +++ b/MelonLoader.Installer/ViewModels/DetailsViewModel.cs @@ -3,6 +3,8 @@ public class DetailsViewModel(GameModel game) : ViewModelBase { private bool _installing; + private bool _confirmation; + private bool _offline; public GameModel Game => game; @@ -13,6 +15,33 @@ public bool Installing { _installing = value; OnPropertyChanged(nameof(Installing)); + OnPropertyChanged(nameof(CanInstall)); + OnPropertyChanged(nameof(EnableSettings)); } } + + public bool Confirmation + { + get => _confirmation; + set + { + _confirmation = value; + OnPropertyChanged(nameof(Confirmation)); + OnPropertyChanged(nameof(CanInstall)); + } + } + + public bool Offline + { + get => _offline; + set + { + _offline = value; + OnPropertyChanged(nameof(Confirmation)); + OnPropertyChanged(nameof(EnableSettings)); + } + } + + public bool CanInstall => !Installing && !Confirmation; + public bool EnableSettings => !Offline && !Installing; } diff --git a/MelonLoader.Installer/ViewModels/MainViewModel.cs b/MelonLoader.Installer/ViewModels/MainViewModel.cs index 125bd38..8859821 100644 --- a/MelonLoader.Installer/ViewModels/MainViewModel.cs +++ b/MelonLoader.Installer/ViewModels/MainViewModel.cs @@ -4,6 +4,18 @@ namespace MelonLoader.Installer.ViewModels; public partial class MainViewModel : ViewModelBase { + private static bool _ready; + + public bool Ready + { + get => _ready; + set + { + _ready = value; + OnPropertyChanged(nameof(Ready)); + } + } + public ObservableCollection Games => GameManager.Games; public string Version => 'v' + Program.Version.ToString(3); diff --git a/MelonLoader.Installer/Views/DetailsView.axaml b/MelonLoader.Installer/Views/DetailsView.axaml index 4507cc5..bfe2440 100644 --- a/MelonLoader.Installer/Views/DetailsView.axaml +++ b/MelonLoader.Installer/Views/DetailsView.axaml @@ -26,14 +26,14 @@ Select a version - - Or select a zipped version - Enable Nightly builds Keep mods and settings - - @@ -52,7 +52,7 @@ Background="#833" Height="40" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="18">Uninstall - + diff --git a/MelonLoader.Installer/Views/DetailsView.axaml.cs b/MelonLoader.Installer/Views/DetailsView.axaml.cs index 26c629c..670a249 100644 --- a/MelonLoader.Installer/Views/DetailsView.axaml.cs +++ b/MelonLoader.Installer/Views/DetailsView.axaml.cs @@ -48,9 +48,7 @@ protected override void OnDataContextChanged(EventArgs e) if (!MLManager.Init()) { - InstallButton.IsEnabled = false; - NightlyCheck.IsEnabled = false; - VersionCombobox.IsEnabled = false; + Model.Offline = true; ErrorBox.Open("Failed to fetch MelonLoader releases. Ensure you're online."); } } @@ -91,6 +89,8 @@ public void UpdateVersionInfo() if (Model == null || VersionCombobox.SelectedItem == null) return; + Model.Confirmation = false; + MelonIcon.Opacity = Model.Game.MLInstalled ? 1 : 0.3; if (Model.Game.MLVersion == null) @@ -99,7 +99,7 @@ public void UpdateVersionInfo() return; } - var comp = ((MLVersion)VersionCombobox.SelectedItem).Version.ComparePrecedenceTo(Model.Game.MLVersion); + var comp = ((MLVersion)VersionCombobox.SelectedItem).Version.CompareSortOrderTo(Model.Game.MLVersion); InstallButton.Content = comp switch { @@ -118,8 +118,6 @@ private void InstallHandler(object sender, RoutedEventArgs args) } Model.Installing = true; - NightlyCheck.IsEnabled = false; - VersionCombobox.IsEnabled = false; _ = MLManager.InstallAsync(Path.GetDirectoryName(Model.Game.Path)!, Model.Game.MLInstalled && !KeepFilesCheck.IsChecked!.Value, (MLVersion)VersionCombobox.SelectedItem!, Model.Game.Is32Bit, @@ -141,16 +139,18 @@ private void OnInstallFinished(string? errorMessage) if (Model == null) return; - Model.Installing = false; - NightlyCheck.IsEnabled = true; - VersionCombobox.IsEnabled = true; - Model.Game.ValidateGame(); + Model.Installing = false; + if (errorMessage != null) { ErrorBox.Open(errorMessage); + return; } + + InstallStatus.Text = "Done!"; + Model.Confirmation = true; } private void OpenDirHandler(object sender, RoutedEventArgs args) @@ -205,8 +205,6 @@ private async void SelectZipHandler(object sender, TappedEventArgs args) var path = files[0].Path.LocalPath; Model.Installing = true; - NightlyCheck.IsEnabled = false; - VersionCombobox.IsEnabled = false; _ = Task.Run(() => MLManager.SetLocalZip(path, (progress, newStatus) => Dispatcher.UIThread.Post(() => OnInstallProgress(progress, newStatus)), diff --git a/MelonLoader.Installer/Views/MainView.axaml b/MelonLoader.Installer/Views/MainView.axaml index c1b64d6..3fabd96 100644 --- a/MelonLoader.Installer/Views/MainView.axaml +++ b/MelonLoader.Installer/Views/MainView.axaml @@ -28,7 +28,7 @@ If you can't find your game on the list, add it manually. - + @@ -36,15 +36,18 @@ If you can't find your game on the list, add it manually. - No Unity games have been found on your device. Please add one manually using the button below. + + Loading... + - +