Better backup (#315)

Now it actually backups the previous file instead of new file
This commit is contained in:
Noah 2022-08-28 15:11:13 -04:00 committed by GitHub
commit c73a53514b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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}");
}
}
}