Skip to content

Commit

Permalink
Look for and copy older save files
Browse files Browse the repository at this point in the history
  • Loading branch information
AuriRex committed Apr 26, 2023
1 parent 4d8482d commit d82cd50
Showing 1 changed file with 48 additions and 28 deletions.
76 changes: 48 additions & 28 deletions TheArchive.Core/Utilities/LocalFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,39 +139,15 @@ public static string VersionSpecificSaveDirectoryPath
{
_versionSpecificSavePath = GetVersionSpecificSaveDirectoryPath(ArchiveMod.CurrentRundown);
}

if (!Directory.Exists(_versionSpecificSavePath))
{
Directory.CreateDirectory(_versionSpecificSavePath);
try
{
var olderSettingsFile = GetSettingsPath(ArchiveMod.CurrentRundown - 1);

if (File.Exists(olderSettingsFile))
if(!CopyMostRecentSaveFiles(ArchiveMod.CurrentRundown - 1, ArchiveMod.CurrentRundown))
{
var newSettingsFile = Path.Combine(_versionSpecificSavePath, GTFO_SETTINGS_JSON);
ArchiveLogger.Debug($"Copying most recent settings file! (\"{olderSettingsFile}\" -> \"{newSettingsFile}\")");
File.Copy(olderSettingsFile, newSettingsFile);
}

if (!ArchiveMod.IsPlayingModded)
{
var newFavs = GetFavoritesPath(ArchiveMod.CurrentRundown);
var oldFavs = GetFavoritesPath(ArchiveMod.CurrentRundown - 1);

if (File.Exists(oldFavs))
{
ArchiveLogger.Debug($"Copying most recent favorites file! (\"{newFavs}\" -> \"{oldFavs}\")");
File.Copy(oldFavs, newFavs);
}

var newBotFavs = GetBotFavoritesPath(ArchiveMod.CurrentRundown);
var oldBotFavs = GetBotFavoritesPath(ArchiveMod.CurrentRundown - 1);

if (File.Exists(oldBotFavs))
{
ArchiveLogger.Debug($"Copying most recent bot favorites file! (\"{newBotFavs}\" -> \"{oldBotFavs}\")");
File.Copy(oldBotFavs, newBotFavs);
}
ArchiveLogger.Notice("Creating new game settings file(s)!");
}
}
catch(Exception ex)
Expand All @@ -180,13 +156,57 @@ public static string VersionSpecificSaveDirectoryPath
ArchiveLogger.Debug(ex.StackTrace);
}
}

}

return _versionSpecificSavePath;
}
}

internal static bool CopyMostRecentSaveFiles(RundownID copyFrom, RundownID copyTo, int maxStep = 3)
{
if (copyFrom < RundownID.RundownOne)
return false;

var olderSettingsFile = GetSettingsPath(copyFrom);

if (!File.Exists(olderSettingsFile))
{
if (maxStep <= 1)
{
return false;
}

return CopyMostRecentSaveFiles(copyFrom - 1, copyTo, maxStep - 1);
}

var newSettingsFile = GetSettingsPath(copyTo);
ArchiveLogger.Debug($"Copying most recent settings file! (\"{olderSettingsFile}\" -> \"{newSettingsFile}\")");
File.Copy(olderSettingsFile, newSettingsFile);

if (!ArchiveMod.IsPlayingModded)
{
var newFavs = GetFavoritesPath(copyTo);
var oldFavs = GetFavoritesPath(copyFrom);

if (File.Exists(oldFavs))
{
ArchiveLogger.Debug($"Copying most recent favorites file! (\"{oldFavs}\" -> \"{newFavs}\")");
File.Copy(oldFavs, newFavs);
}

var newBotFavs = GetBotFavoritesPath(copyTo);
var oldBotFavs = GetBotFavoritesPath(copyFrom);

if (File.Exists(oldBotFavs))
{
ArchiveLogger.Debug($"Copying most recent bot favorites file! (\"{oldBotFavs}\" -> \"{newBotFavs}\")");
File.Copy(oldBotFavs, newBotFavs);
}
}

return true;
}

public static string GetVersionSpecificSaveDirectoryPath(RundownID rundown)
{
return Path.Combine(SaveDirectoryPath, $"{((int)rundown).ToString().PadLeft(2, '0')}_{rundown}_Data");
Expand Down

0 comments on commit d82cd50

Please sign in to comment.