Restore files from save archive based on entries in manifest

save-path-regex
Pat Hartl 2023-11-30 18:37:23 -06:00
parent 7b625b2f60
commit 82779bcc72
1 changed files with 30 additions and 28 deletions

View File

@ -67,43 +67,45 @@ namespace LANCommander.SDK
bool inInstallDir = savePath.Path.StartsWith("{InstallDir}"); bool inInstallDir = savePath.Path.StartsWith("{InstallDir}");
string tempSavePath = Path.Combine(tempLocation, savePath.Id.ToString()); string tempSavePath = Path.Combine(tempLocation, savePath.Id.ToString());
var tempSavePathFile = Path.Combine(tempSavePath, savePath.Path.Replace('/', Path.DirectorySeparatorChar).Replace("{InstallDir}" + Path.DirectorySeparatorChar, "")); foreach (var entry in savePath.Entries)
destination = Environment.ExpandEnvironmentVariables(savePath.Path.Replace('/', Path.DirectorySeparatorChar).Replace("{InstallDir}", installDirectory));
if (File.Exists(tempSavePathFile))
{ {
// Is file, move file var tempSavePathFile = Path.Combine(tempSavePath, entry.ArchivePath);
if (File.Exists(destination))
File.Delete(destination);
File.Move(tempSavePathFile, destination); destination = Environment.ExpandEnvironmentVariables(entry.ActualPath).Replace("{InstallDir}", installDirectory);
}
else if (Directory.Exists(tempSavePath))
{
var files = Directory.GetFiles(tempSavePath, "*", SearchOption.AllDirectories);
foreach (var file in files) if (File.Exists(tempSavePathFile))
{ {
if (inInstallDir) if (File.Exists(destination))
File.Delete(destination);
File.Move(tempSavePathFile, destination);
}
else if (Directory.Exists(tempSavePath))
{
var files = Directory.GetFiles(tempSavePath, "*", SearchOption.AllDirectories);
foreach (var file in files)
{ {
// Files are in the game's install directory. Move them there from the save path. if (inInstallDir)
destination = file.Replace(tempSavePath, savePath.Path.Replace('/', Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar).Replace("{InstallDir}", installDirectory)); {
// Files are in the game's install directory. Move them there from the save path.
destination = file.Replace(tempSavePath, savePath.Path.Replace('/', Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar).Replace("{InstallDir}", installDirectory));
if (File.Exists(destination)) if (File.Exists(destination))
File.Delete(destination); File.Delete(destination);
File.Move(file, destination); File.Move(file, destination);
} }
else else
{ {
// Specified path is probably an absolute path, maybe with environment variables. // Specified path is probably an absolute path, maybe with environment variables.
destination = Environment.ExpandEnvironmentVariables(file.Replace(tempSavePathFile, savePath.Path.Replace('/', Path.DirectorySeparatorChar))); destination = Environment.ExpandEnvironmentVariables(file.Replace(tempSavePathFile, savePath.Path.Replace('/', Path.DirectorySeparatorChar)));
if (File.Exists(destination)) if (File.Exists(destination))
File.Delete(destination); File.Delete(destination);
File.Move(file, destination); File.Move(file, destination);
}
} }
} }
} }