Skip to content

Re-enable SaveGameFixer and improve it to also run on canned stock craft dirs #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions SaveGameFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ internal void Awake()

// So at this point we know we have won the election, and will be using the class versions as in this assembly.

// Disabled for now since .24 fix the module loading order.
// UpdateSaves();
UpdateSaves();

char ds = Path.DirectorySeparatorChar;

UpdateCraftDir(Path.Combine(KSPUtil.ApplicationRootPath, string.Format("Ships{0}VAB", ds)), KSPUtil.ApplicationRootPath);
UpdateCraftDir(Path.Combine(KSPUtil.ApplicationRootPath, string.Format("Ships{0}VAB", ds)), KSPUtil.ApplicationRootPath);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -145,7 +149,7 @@ private void UpdateSaveDir(string saveDir)
}
}

private void UpdateCraftDir(string dir)
private void UpdateCraftDir(string dir, string rootDir)
{
string[] files;
try
Expand All @@ -158,14 +162,19 @@ private void UpdateCraftDir(string dir)
}
foreach (string vabCraft in files)
if (vabCraft.EndsWith(".craft"))
UpdateCraft(vabCraft);
UpdateCraft(vabCraft, rootDir);
}

private void UpdateCraft(string vabCraft)
private void UpdateCraftDir(string dir)
{
UpdateCraftDir(dir, savesRoot);
}

private void UpdateCraft(string vabCraft, string rootDir)
{
try
{
PushLogContext("Craft file: " + vabCraft.Substring(savesRoot.Length, vabCraft.Length-savesRoot.Length));
PushLogContext("Craft file: " + vabCraft.Substring(rootDir.Length, vabCraft.Length-rootDir.Length));
ConfigNode craft = ConfigNode.Load(vabCraft);

needsBackup = false; needsSave = false; partMissing = false;
Expand All @@ -180,7 +189,7 @@ private void UpdateCraft(string vabCraft)
WriteDebugMessage("Delete the craft to get rid of this message.");
}

BackupAndReplace(vabCraft, craft);
BackupAndReplace(vabCraft, rootDir, craft);


}
Expand All @@ -190,6 +199,11 @@ private void UpdateCraft(string vabCraft)
}
}

private void UpdateCraft(string vabCraft)
{
UpdateCraft(vabCraft, savesRoot);
}

private void UpdateSFS(string sfsFile)
{
ConfigNode sfs = ConfigNode.Load(sfsFile);
Expand Down Expand Up @@ -471,14 +485,14 @@ private void CreateBackupDir()
}
}

private void BackupAndReplace(string file, ConfigNode config)
private void BackupAndReplace(string file, string rootDir, ConfigNode config)
{

if (needsBackup)
{
CreateBackupDir();

string relPath = file.Substring(savesRoot.Length, file.Length - savesRoot.Length);
string relPath = file.Substring(rootDir.Length, file.Length - rootDir.Length);

string backupTo = Path.Combine(backupDir, relPath);
// ReSharper disable once AssignNullToNotNullAttribute
Expand All @@ -493,6 +507,11 @@ private void BackupAndReplace(string file, ConfigNode config)
config.Save(file);
}

private void BackupAndReplace(string File, ConfigNode config)
{
BackupAndReplace(File, savesRoot, config);
}

#endregion
}

Expand Down