Better backup

This commit is contained in:
Noah Pilarski 2022-08-28 15:03:35 -04:00
parent bca0e2ffed
commit 313267427b

View File

@ -227,6 +227,24 @@ namespace NewHorizons.Utility.DebugMenu
var json = loadedConfigFiles[filePath].ToSerializedJson();
try
{
var path = loadedMod.ModHelper.Manifest.ModFolderPath + backupFolderName + relativePath;
Logger.LogVerbose($"Backing up... {relativePath} to {path}");
var oldPath = loadedMod.ModHelper.Manifest.ModFolderPath + relativePath;
var directoryName = Path.GetDirectoryName(path);
Directory.CreateDirectory(directoryName);
if (File.Exists(oldPath))
File.WriteAllBytes(path, File.ReadAllBytes(oldPath));
else
File.WriteAllText(path, json);
}
catch (Exception e)
{
Logger.LogError($"Failed to save backup file {backupFolderName}{relativePath}:\n{e}");
}
try
{
Logger.Log($"Saving... {relativePath} to {filePath}");
@ -240,19 +258,6 @@ namespace NewHorizons.Utility.DebugMenu
{
Logger.LogError($"Failed to save file {relativePath}:\n{e}");
}
try
{
var path = Main.Instance.ModHelper.Manifest.ModFolderPath + backupFolderName + relativePath;
var directoryName = Path.GetDirectoryName(path);
Directory.CreateDirectory(directoryName);
File.WriteAllText(path, json);
}
catch (Exception e)
{
Logger.LogError($"Failed to save backup file {backupFolderName}{relativePath}:\n{e}");
}
}
}