add exception handling to jsonmanager save

This commit is contained in:
bluepilledgreat 2024-09-21 14:18:14 +01:00
parent c58a8ab739
commit 3f438e99b1
3 changed files with 27 additions and 1 deletions

View File

@ -60,7 +60,21 @@ namespace Bloxstrap
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!");
}

View File

@ -170,6 +170,15 @@ namespace Bloxstrap.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Failed to save {0}: {1}.
/// </summary>
public static string Bootstrapper_JsonManagerSaveFailed {
get {
return ResourceManager.GetString("Bootstrapper.JsonManagerSaveFailed", resourceCulture);
}
}
/// <summary>
/// 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..
/// </summary>

View File

@ -1192,4 +1192,7 @@ Please manually delete Bloxstrap.exe from the install location or try restarting
<data name="Common.RobloxNotInstalled" xml:space="preserve">
<value>Roblox has not yet been installed. Please launch Roblox using Bloxstrap at least once before trying to use this option.</value>
</data>
<data name="Bootstrapper.JsonManagerSaveFailed" xml:space="preserve">
<value>Failed to save {0}: {1}</value>
</data>
</root>