From 84822e29c67b1a99e73c73777d8229cfe978ba19 Mon Sep 17 00:00:00 2001 From: yesseruser <67008763+yesseruser@users.noreply.github.com> Date: Sat, 14 Dec 2024 15:27:51 +0100 Subject: [PATCH] Create .bak file when loading fails (#3984) * 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 --- Bloxstrap/JsonManager.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Bloxstrap/JsonManager.cs b/Bloxstrap/JsonManager.cs index a713d4f..bb1eb77 100644 --- a/Bloxstrap/JsonManager.cs +++ b/Bloxstrap/JsonManager.cs @@ -47,6 +47,17 @@ namespace Bloxstrap 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();