Skip to content

Commit

Permalink
add exception handling to jsonmanager save
Browse files Browse the repository at this point in the history
  • Loading branch information
bluepilledgreat committed Sep 21, 2024
1 parent c58a8ab commit 3f438e9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Bloxstrap/JsonManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand Down
9 changes: 9 additions & 0 deletions Bloxstrap/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Bloxstrap/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 3f438e9

Please sign in to comment.