Alert user on failure to load settings/flags

This commit is contained in:
pizzaboxer 2024-09-02 11:04:39 +01:00
parent cab047d7a9
commit f1246e1a2d
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
7 changed files with 67 additions and 24 deletions

View File

@ -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");

View File

@ -4,6 +4,10 @@ namespace Bloxstrap
{
public class FastFlagManager : JsonManager<Dictionary<string, object>>
{
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);

View File

@ -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()

View File

@ -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();
}
}

View File

@ -1495,6 +1495,24 @@ namespace Bloxstrap.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Your Fast Flags could not be loaded. They have been reset to the default configuration..
/// </summary>
public static string JsonManager_FastFlagsLoadFailed {
get {
return ResourceManager.GetString("JsonManager.FastFlagsLoadFailed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Your Settings could not be loaded. They have been reset to the default configuration..
/// </summary>
public static string JsonManager_SettingsLoadFailed {
get {
return ResourceManager.GetString("JsonManager.SettingsLoadFailed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Configure settings.
/// </summary>

View File

@ -1162,4 +1162,10 @@ Are you sure you want to continue?</value>
<data name="About.Supporters.Description" xml:space="preserve">
<value>These are the people currently supporting Bloxstrap through [Ko-fi]({0}). A massive thank you to everyone here!</value>
</data>
<data name="JsonManager.SettingsLoadFailed" xml:space="preserve">
<value>Your Settings could not be loaded. They have been reset to the default configuration.</value>
</data>
<data name="JsonManager.FastFlagsLoadFailed" xml:space="preserve">
<value>Your Fast Flags could not be loaded. They have been reset to the default configuration.</value>
</data>
</root>

View File

@ -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();