From f1246e1a2d18e6cc60ba71842672d1bfb3bd636e Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Mon, 2 Sep 2024 11:04:39 +0100 Subject: [PATCH] Alert user on failure to load settings/flags --- Bloxstrap/Bootstrapper.cs | 4 +-- Bloxstrap/FastFlagManager.cs | 9 +++++-- Bloxstrap/Installer.cs | 14 ++++++++--- Bloxstrap/JsonManager.cs | 25 ++++++++++++++++--- Bloxstrap/Resources/Strings.Designer.cs | 18 +++++++++++++ Bloxstrap/Resources/Strings.resx | 6 +++++ .../ViewModels/Installer/InstallViewModel.cs | 15 ++--------- 7 files changed, 67 insertions(+), 24 deletions(-) diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index fa526ad..408f206 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -214,7 +214,6 @@ namespace Bloxstrap if (_installWebView2) await InstallWebView2(); - App.FastFlags.Save(); await ApplyModifications(); // TODO: move this to install/upgrade flow @@ -224,7 +223,6 @@ namespace Bloxstrap CheckInstall(); // at this point we've finished updating our configs - App.Settings.Save(); App.State.Save(); await mutex.ReleaseAsync(); @@ -777,6 +775,8 @@ namespace Bloxstrap public static void MigrateIntegrations() { + // TODO: move this to the installer logic + // v2.2.0 - remove rbxfpsunlocker string rbxfpsunlocker = Path.Combine(Paths.Integrations, "rbxfpsunlocker"); diff --git a/Bloxstrap/FastFlagManager.cs b/Bloxstrap/FastFlagManager.cs index f211752..8c7760f 100644 --- a/Bloxstrap/FastFlagManager.cs +++ b/Bloxstrap/FastFlagManager.cs @@ -4,6 +4,10 @@ namespace Bloxstrap { public class FastFlagManager : JsonManager> { + public override string ClassName => nameof(FastFlagManager); + + public override string LOG_IDENT_CLASS => ClassName; + public override string FileLocation => Path.Combine(Paths.Modifications, "ClientSettings\\ClientAppSettings.json"); public bool Changed => !OriginalProp.SequenceEqual(Prop); @@ -238,9 +242,9 @@ namespace Bloxstrap OriginalProp = new(Prop); } - public override void Load() + public override void Load(bool alertFailure = true) { - base.Load(); + base.Load(alertFailure); // clone the dictionary OriginalProp = new(Prop); @@ -249,6 +253,7 @@ namespace Bloxstrap if (GetPreset("Network.Log") != "7") SetPreset("Network.Log", "7"); + // TODO - this should be moved to the installer update logic string? val = GetPreset("UI.Menu.Style.EnableV4.1"); if (GetPreset("UI.Menu.Style.EnableV4.2") != val) SetPreset("UI.Menu.Style.EnableV4.2", val); diff --git a/Bloxstrap/Installer.cs b/Bloxstrap/Installer.cs index 2e841fd..08fc778 100644 --- a/Bloxstrap/Installer.cs +++ b/Bloxstrap/Installer.cs @@ -11,6 +11,8 @@ namespace Bloxstrap public string InstallLocation = Path.Combine(Paths.LocalAppData, "Bloxstrap"); + public bool ExistingDataPresent => File.Exists(Path.Combine(InstallLocation, "Settings.json")); + public bool CreateDesktopShortcuts = true; public bool CreateStartMenuShortcuts = true; @@ -21,6 +23,10 @@ namespace Bloxstrap public void DoInstall() { + const string LOG_IDENT = "Installer::DoInstall"; + + App.Logger.WriteLine(LOG_IDENT, "Beginning installation"); + // should've been created earlier from the write test anyway Directory.CreateDirectory(InstallLocation); @@ -69,9 +75,11 @@ namespace Bloxstrap Shortcut.Create(Paths.Application, "", StartMenuShortcut); // existing configuration persisting from an earlier install - App.Settings.Load(); - App.State.Load(); - App.FastFlags.Load(); + App.Settings.Load(false); + App.State.Load(false); + App.FastFlags.Load(false); + + App.Logger.WriteLine(LOG_IDENT, "Installation finished"); } private bool ValidateLocation() diff --git a/Bloxstrap/JsonManager.cs b/Bloxstrap/JsonManager.cs index a8e8c3e..cf4d66a 100644 --- a/Bloxstrap/JsonManager.cs +++ b/Bloxstrap/JsonManager.cs @@ -8,11 +8,13 @@ namespace Bloxstrap public T Prop { get; set; } = new(); - public virtual string FileLocation => Path.Combine(Paths.Base, $"{typeof(T).Name}.json"); + public virtual string ClassName => typeof(T).Name; - private string LOG_IDENT_CLASS => $"JsonManager<{typeof(T).Name}>"; + public virtual string FileLocation => Path.Combine(Paths.Base, $"{ClassName}.json"); - public virtual void Load() + public virtual string LOG_IDENT_CLASS => $"JsonManager<{ClassName}>"; + + public virtual void Load(bool alertFailure = true) { string LOG_IDENT = $"{LOG_IDENT_CLASS}::Load"; @@ -32,7 +34,22 @@ namespace Bloxstrap catch (Exception ex) { App.Logger.WriteLine(LOG_IDENT, "Failed to load!"); - App.Logger.WriteLine(LOG_IDENT, $"{ex.Message}"); + App.Logger.WriteException(LOG_IDENT, ex); + + if (alertFailure) + { + string message = ""; + + if (ClassName == nameof(Settings)) + message = Strings.JsonManager_SettingsLoadFailed; + else if (ClassName == nameof(FastFlagManager)) + message = Strings.JsonManager_FastFlagsLoadFailed; + + if (!String.IsNullOrEmpty(message)) + Frontend.ShowMessageBox($"{message}\n\n{ex.GetType()}: {ex.Message}", System.Windows.MessageBoxImage.Warning); + } + + Save(); } } diff --git a/Bloxstrap/Resources/Strings.Designer.cs b/Bloxstrap/Resources/Strings.Designer.cs index c6473c1..3d93915 100644 --- a/Bloxstrap/Resources/Strings.Designer.cs +++ b/Bloxstrap/Resources/Strings.Designer.cs @@ -1495,6 +1495,24 @@ namespace Bloxstrap.Resources { } } + /// + /// Looks up a localized string similar to Your Fast Flags could not be loaded. They have been reset to the default configuration.. + /// + public static string JsonManager_FastFlagsLoadFailed { + get { + return ResourceManager.GetString("JsonManager.FastFlagsLoadFailed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Your Settings could not be loaded. They have been reset to the default configuration.. + /// + public static string JsonManager_SettingsLoadFailed { + get { + return ResourceManager.GetString("JsonManager.SettingsLoadFailed", resourceCulture); + } + } + /// /// Looks up a localized string similar to Configure settings. /// diff --git a/Bloxstrap/Resources/Strings.resx b/Bloxstrap/Resources/Strings.resx index 686331e..3c813c6 100644 --- a/Bloxstrap/Resources/Strings.resx +++ b/Bloxstrap/Resources/Strings.resx @@ -1162,4 +1162,10 @@ Are you sure you want to continue? These are the people currently supporting Bloxstrap through [Ko-fi]({0}). A massive thank you to everyone here! + + Your Settings could not be loaded. They have been reset to the default configuration. + + + Your Fast Flags could not be loaded. They have been reset to the default configuration. + \ No newline at end of file diff --git a/Bloxstrap/UI/ViewModels/Installer/InstallViewModel.cs b/Bloxstrap/UI/ViewModels/Installer/InstallViewModel.cs index 4f099a7..6098861 100644 --- a/Bloxstrap/UI/ViewModels/Installer/InstallViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Installer/InstallViewModel.cs @@ -32,11 +32,11 @@ namespace Bloxstrap.UI.ViewModels.Installer } installer.InstallLocation = value; - CheckExistingData(); + OnPropertyChanged(nameof(DataFoundMessageVisibility)); } } - public Visibility DataFoundMessageVisibility { get; set; } = Visibility.Collapsed; + public Visibility DataFoundMessageVisibility => installer.ExistingDataPresent ? Visibility.Visible : Visibility.Collapsed; public string ErrorMessage => installer.InstallLocationError; @@ -61,7 +61,6 @@ namespace Bloxstrap.UI.ViewModels.Installer public InstallViewModel() { _originalInstallLocation = installer.InstallLocation; - CheckExistingData(); } public bool DoInstall() @@ -79,16 +78,6 @@ namespace Bloxstrap.UI.ViewModels.Installer return true; } - public void CheckExistingData() - { - if (File.Exists(Path.Combine(InstallLocation, "Settings.json"))) - DataFoundMessageVisibility = Visibility.Visible; - else - DataFoundMessageVisibility = Visibility.Collapsed; - - OnPropertyChanged(nameof(DataFoundMessageVisibility)); - } - private void BrowseInstallLocation() { using var dialog = new System.Windows.Forms.FolderBrowserDialog();