World Save Back and Restore Changes

1. added the SaveGames folder to the to the backup zip file.
2. now restores the SaveGames folder.
This commit is contained in:
Brett Hewitson 2022-05-02 11:32:06 +10:00
parent aa5c135be7
commit a5e749963a
19 changed files with 408 additions and 96 deletions

View file

@ -87,7 +87,7 @@
<value>ConanSandbox\Mods</value>
</setting>
<setting name="SavedRelativePath" serializeAs="String">
<value>Saved</value>
<value>ConanSandbox\Saved</value>
</setting>
<setting name="WorkshopCacheFile" serializeAs="String">
<value>workshopcache_440900.json</value>
@ -272,6 +272,9 @@
<setting name="ServerCallUrlDelay" serializeAs="String">
<value>12</value>
</setting>
<setting name="SaveGamesRelativePath" serializeAs="String">
<value>SaveGames</value>
</setting>
</ServerManagerTool.Config>
<ServerManagerTool.Common.CommonConfig>
<setting name="DefaultSteamAPIKey" serializeAs="String">

View file

@ -487,7 +487,7 @@ namespace ServerManagerTool {
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("Saved")]
[global::System.Configuration.DefaultSettingValueAttribute("ConanSandbox\\Saved")]
public string SavedRelativePath {
get {
return ((string)(this["SavedRelativePath"]));
@ -2333,5 +2333,14 @@ namespace ServerManagerTool {
this["DiscordBotAllServersKeyword"] = value;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("SaveGames")]
public string SaveGamesRelativePath {
get {
return ((string)(this["SaveGamesRelativePath"]));
}
}
}
}

View file

@ -135,7 +135,7 @@
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="SavedRelativePath" Type="System.String" Scope="Application">
<Value Profile="(Default)">Saved</Value>
<Value Profile="(Default)">ConanSandbox\Saved</Value>
</Setting>
<Setting Name="SteamCmdRedirectOutput" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
@ -641,5 +641,8 @@
<Setting Name="DiscordBotAllServersKeyword" Type="System.String" Scope="User">
<Value Profile="(Default)">all</Value>
</Setting>
<Setting Name="SaveGamesRelativePath" Type="System.String" Scope="Application">
<Value Profile="(Default)">SaveGames</Value>
</Setting>
</Settings>
</SettingsFile>

View file

@ -1925,8 +1925,8 @@ namespace ServerManagerTool.Lib
if (Directory.Exists(saveFolder))
{
// make a backup of the current world file.
var worldBackupFile = GetServerWorldBackupFile();
if (File.Exists(worldBackupFile))
var worldFile = GetServerWorldBackupFile();
if (File.Exists(worldFile))
{
try
{
@ -1944,8 +1944,6 @@ namespace ServerManagerTool.Lib
if (File.Exists(backupFile))
File.Delete(backupFile);
var files = new List<string>();
var comment = new StringBuilder();
comment.AppendLine($"Windows Platform: {Environment.OSVersion.Platform}");
comment.AppendLine($"Windows Version: {Environment.OSVersion.VersionString}");
@ -1956,9 +1954,24 @@ namespace ServerManagerTool.Lib
comment.AppendLine($"Profile Name: {_profile.ProfileName}");
comment.AppendLine($"Process: {ServerProcess}");
ZipUtils.ZipAFile(backupFile, worldFileName, worldBackupFile, comment.ToString());
if (files.Count > 0)
ZipUtils.UpdateFiles(backupFile, files, null, false, "");
var saveFolderInfo = new DirectoryInfo(saveFolder);
// backup the world save file
ZipUtils.ZipAFile(backupFile, worldFileName, worldFile, comment.ToString());
// backup the save games files
var saveGamesFolder = GetServerSaveGamesFolder();
if (Directory.Exists(saveGamesFolder))
{
var saveGamesFolderInfo = new DirectoryInfo(saveGamesFolder);
var saveGamesFileFilter = $"*";
var saveGamesFiles = saveGamesFolderInfo.GetFiles(saveGamesFileFilter, SearchOption.AllDirectories);
foreach (var file in saveGamesFiles)
{
ZipUtils.ZipAFile(backupFile, file.FullName.Replace(saveGamesFolder, Config.Default.SaveGamesRelativePath), file.FullName);
}
}
LogProfileMessage($"Backed up world files - {saveFolder}");
LogProfileMessage($"Backup file created - {backupFile}");
@ -1986,12 +1999,12 @@ namespace ServerManagerTool.Lib
}
else
{
LogProfileMessage($"Server save file does not exist or could not be found '{worldBackupFile}'.");
LogProfileMessage($"Server save file does not exist or could not be found '{worldFile}'.");
LogProfileMessage($"Backup not performed.");
emailMessage?.AppendLine();
emailMessage?.AppendLine($"Server save file does not exist or could not be found.");
emailMessage?.AppendLine(worldBackupFile);
emailMessage?.AppendLine(worldFile);
emailMessage?.AppendLine();
emailMessage?.AppendLine("Backup not performed.");
@ -2289,6 +2302,8 @@ namespace ServerManagerTool.Lib
private string GetServerSaveFolder() => IOUtils.NormalizePath(Path.Combine(_profile.InstallDirectory, Config.Default.SavedFilesRelativePath));
private string GetServerSaveGamesFolder() => IOUtils.NormalizePath(ServerProfile.GetProfileSaveGamesPath(_profile.InstallDirectory));
private string GetServerVersionFile() => IOUtils.NormalizePath(Path.Combine(_profile.InstallDirectory, Config.Default.ServerBinaryRelativePath, Config.Default.ServerExeFile));
public static Version GetServerVersion(string versionFile)

View file

@ -1320,7 +1320,7 @@ namespace ServerManagerTool.Lib
return JsonUtils.Serialize<ServerProfile>(this);
}
public int RestoreSaveFiles(string restoreFile, bool isArchiveFile)
public int RestoreSaveFiles(string restoreFile, bool isArchiveFile, bool restoreAll)
{
if (string.IsNullOrWhiteSpace(restoreFile) || !File.Exists(restoreFile))
{
@ -1336,6 +1336,7 @@ namespace ServerManagerTool.Lib
}
var worldFileName = ServerMapSaveFileName;
var saveGamesFolder = GetProfileSaveGamesPath(this);
// check if the archive file contains the world save file at minimum
if (isArchiveFile)
@ -1365,12 +1366,23 @@ namespace ServerManagerTool.Lib
if (isArchiveFile)
{
// create a list of files to be deleted
var files = new List<string>();
// add the current world save file
files.Add(worldFile);
var directories = new List<string>();
var files = new List<string>
{
worldFile,
};
// add the world save support files
files.AddRange(Directory.GetFiles(saveFolder, $"{worldFileName}-*"));
if (restoreAll)
{
if (Directory.Exists(saveGamesFolder) && ZipUtils.DoesFolderExist(restoreFile, Config.Default.SaveGamesRelativePath))
{
directories.Add(saveGamesFolder);
}
}
// delete the selected files
foreach (var file in files)
{
@ -1384,8 +1396,33 @@ namespace ServerManagerTool.Lib
}
}
// restore the files from the backup
restoredFileCount = ZipUtils.ExtractAFile(restoreFile, worldFileName, saveFolder);
foreach (var directory in directories)
{
try
{
Directory.Delete(directory, true);
}
catch
{
// if unable to delete, do not bother
}
}
if (restoreAll)
{
// restore the files from the backup
restoredFileCount += ZipUtils.ExtractFiles(restoreFile, saveFolder, sourceFolder: "", recurseFolders: false);
if (ZipUtils.DoesFolderExist(restoreFile, Config.Default.SaveGamesRelativePath))
{
var rootSaveFolder = Path.GetDirectoryName(saveGamesFolder);
restoredFileCount += ZipUtils.ExtractFiles(restoreFile, rootSaveFolder, Config.Default.SaveGamesRelativePath, recurseFolders: true);
}
}
else
{
restoredFileCount += ZipUtils.ExtractAFile(restoreFile, worldFileName, saveFolder);
}
}
else
{
@ -1768,6 +1805,16 @@ namespace ServerManagerTool.Lib
return ModUtils.GetMapName(serverMap);
}
public static string GetProfileSaveGamesPath(ServerProfile profile)
{
return GetProfileSaveGamesPath(profile?.InstallDirectory);
}
public static string GetProfileSaveGamesPath(string installDirectory)
{
return Path.Combine(installDirectory ?? string.Empty, Config.Default.SavedRelativePath, Config.Default.SaveGamesRelativePath);
}
public static string GetProfileSavePath(ServerProfile profile)
{
return GetProfileSavePath(profile?.InstallDirectory);

View file

@ -5,7 +5,31 @@
<title>Conan Server Manager Version Feed</title>
<subtitle>This is the Conan Server Manager release version feed.</subtitle>
<link href="http://servermanagers.freeforums.net/" />
<updated>2022-04-23T00:00:00Z</updated>
<updated>2022-05-02T00:00:00Z</updated>
<entry>
<id>urn:uuid:FF2C83B2-6D10-4217-A021-5B5F090FC480</id>
<title>1.1.68 (1.1.68.1)</title>
<summary>1.1.68.1</summary>
<link href="" />
<updated>2022-05-02T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>World Save Backup - added the SaveGames folder to the to the backup zip file.</li>
<li>World Save Restore - now restores the SaveGames folder.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:E482A8A4-88C3-4517-A4DD-B954811F4F13</id>

View file

@ -5,26 +5,22 @@
<title>Conan Server Manager Version Feed</title>
<subtitle>This is the Conan Server Manager beta version feed.</subtitle>
<link href="http://servermanagers.freeforums.net/" />
<updated>2022-04-23T00:00:00Z</updated>
<updated>2022-05-02T00:00:00Z</updated>
<entry>
<id>urn:uuid:E482A8A4-88C3-4517-A4DD-B954811F4F13</id>
<title>1.1.67 (1.1.67.1)</title>
<summary>1.1.67.1</summary>
<id>urn:uuid:FF2C83B2-6D10-4217-A021-5B5F090FC480</id>
<title>1.1.68 (1.1.68.1)</title>
<summary>1.1.68.1</summary>
<link href="" />
<updated>2022-04-23T00:00:00Z</updated>
<updated>2022-05-02T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">BUGFIX</u>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>Fixed the discord bot Info command, to release the profile once the command has finished running.</li>
</ul>
<u style="font-size: .9em;">NEW</u>
<br/>
<ul>
<li>ru-RU Translation file added.</li>
<li>World Save Backup - added the SaveGames folder to the to the backup zip file.</li>
<li>World Save Restore - now restores the SaveGames folder.</li>
</ul>
</p>
</div>

View file

@ -220,7 +220,7 @@ namespace ServerManagerTool
Application.Current.Dispatcher.Invoke(() => this.Cursor = System.Windows.Input.Cursors.Wait);
await Task.Delay(500);
var restoredFileCount = _profile.RestoreSaveFiles(item.File, item.IsArchiveFile);
var restoredFileCount = _profile.RestoreSaveFiles(item.File, item.IsArchiveFile, true);
var successMessage = _globalizer.GetResourceString("WorldSaveRestore_RestoreSuccessLabel");
successMessage = successMessage.Replace("{fileCount}", restoredFileCount.ToString());