Skip to content

Commit

Permalink
Create .bak file when loading fails (#3984)
Browse files Browse the repository at this point in the history
* Create backup on file loading fail

When loading a file that has errors in it, Bloxstrap would previously overwrite the file with the defaults. This commit now copies the file to a .bak file with the same name so the user can choose to edit it and fix issues.

* Overwrite backup and handle exceptions
  • Loading branch information
yesseruser authored Dec 14, 2024
1 parent 1dc3186 commit 84822e2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Bloxstrap/JsonManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ public virtual void Load(bool alertFailure = true)

if (!String.IsNullOrEmpty(message))
Frontend.ShowMessageBox($"{message}\n\n{ex.Message}", System.Windows.MessageBoxImage.Warning);

try
{
// Create a backup of loaded file
File.Copy(FileLocation, FileLocation + ".bak", true);
}
catch (Exception copyEx)
{
App.Logger.WriteLine(LOG_IDENT, $"Failed to create backup file: {FileLocation}.bak");
App.Logger.WriteException(LOG_IDENT, copyEx);
}
}

Save();
Expand Down

1 comment on commit 84822e2

@sadianadeem7sasianadeem7

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

danow;d

Please sign in to comment.