From 3f438e99b1adcab35e615b483ccdc4b27cd12bee Mon Sep 17 00:00:00 2001 From: bluepilledgreat <97983689+bluepilledgreat@users.noreply.github.com> Date: Sat, 21 Sep 2024 14:18:14 +0100 Subject: [PATCH] add exception handling to jsonmanager save --- Bloxstrap/JsonManager.cs | 16 +++++++++++++++- Bloxstrap/Resources/Strings.Designer.cs | 9 +++++++++ Bloxstrap/Resources/Strings.resx | 3 +++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Bloxstrap/JsonManager.cs b/Bloxstrap/JsonManager.cs index 8e786bee..58a1e257 100644 --- a/Bloxstrap/JsonManager.cs +++ b/Bloxstrap/JsonManager.cs @@ -60,7 +60,21 @@ public virtual void Save() App.Logger.WriteLine(LOG_IDENT, $"Saving to {FileLocation}..."); Directory.CreateDirectory(Path.GetDirectoryName(FileLocation)!); - File.WriteAllText(FileLocation, JsonSerializer.Serialize(Prop, new JsonSerializerOptions { WriteIndented = true })); + + try + { + File.WriteAllText(FileLocation, JsonSerializer.Serialize(Prop, new JsonSerializerOptions { WriteIndented = true })); + } + catch (IOException ex) + { + App.Logger.WriteLine(LOG_IDENT, "Failed to save"); + App.Logger.WriteException(LOG_IDENT, ex); + + string errorMessage = string.Format(Resources.Strings.Bootstrapper_JsonManagerSaveFailed, ClassName, ex.Message); + Frontend.ShowMessageBox(errorMessage, System.Windows.MessageBoxImage.Warning); + + return; + } App.Logger.WriteLine(LOG_IDENT, "Save complete!"); } diff --git a/Bloxstrap/Resources/Strings.Designer.cs b/Bloxstrap/Resources/Strings.Designer.cs index 7911c5ba..e78fd909 100644 --- a/Bloxstrap/Resources/Strings.Designer.cs +++ b/Bloxstrap/Resources/Strings.Designer.cs @@ -170,6 +170,15 @@ public static string Bootstrapper_HyperionUpdateInfo { } } + /// + /// Looks up a localized string similar to Failed to save {0}: {1}. + /// + public static string Bootstrapper_JsonManagerSaveFailed { + get { + return ResourceManager.GetString("Bootstrapper.JsonManagerSaveFailed", resourceCulture); + } + } + /// /// Looks up a localized string similar to Bloxstrap does not have enough disk space to download and install Roblox. Please free up some disk space and try again.. /// diff --git a/Bloxstrap/Resources/Strings.resx b/Bloxstrap/Resources/Strings.resx index 0a04ef21..942a9323 100644 --- a/Bloxstrap/Resources/Strings.resx +++ b/Bloxstrap/Resources/Strings.resx @@ -1192,4 +1192,7 @@ Please manually delete Bloxstrap.exe from the install location or try restarting Roblox has not yet been installed. Please launch Roblox using Bloxstrap at least once before trying to use this option. + + Failed to save {0}: {1} + \ No newline at end of file