From a0d54602fa5ac6b551fd0e0620994679081f3c4e Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 22 Jul 2014 20:53:40 -0700 Subject: [PATCH 1/3] Revert "Disable the SaveGameFixer for a 0.24 build" because 0.24's save game fixer makes everything so much worse than it was before. This reverts commit ab2db2c16c8b11bea6e78fbde6ad8e4a91889092. --- SaveGameFixer.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SaveGameFixer.cs b/SaveGameFixer.cs index 42d22d83..3c0e0d25 100644 --- a/SaveGameFixer.cs +++ b/SaveGameFixer.cs @@ -65,8 +65,7 @@ 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(); } catch (Exception ex) { From 8120135072c3fae2a2e72b94911f22151a596f26 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 22 Jul 2014 20:56:14 -0700 Subject: [PATCH 2/3] SaveGameFixer: Also update stock Ships folders. --- SaveGameFixer.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SaveGameFixer.cs b/SaveGameFixer.cs index 3c0e0d25..bccb6a70 100644 --- a/SaveGameFixer.cs +++ b/SaveGameFixer.cs @@ -66,6 +66,11 @@ 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. UpdateSaves(); + + char ds = Path.DirectorySeparatorChar; + + UpdateCraftDir(string.Format("{0}{1}Ships{1}VAB", KSPUtil.ApplicationRootPath, ds)); + UpdateCraftDir(string.Format("{0}{1}Ships{1}SPH", KSPUtil.ApplicationRootPath, ds)); } catch (Exception ex) { From 40ab23b71d23af629bc9b277111da6339805c302 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 22 Jul 2014 22:32:15 -0700 Subject: [PATCH 3/3] Fixes to make updates to stock craft backup correctly. --- SaveGameFixer.cs | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/SaveGameFixer.cs b/SaveGameFixer.cs index bccb6a70..62f7b7af 100644 --- a/SaveGameFixer.cs +++ b/SaveGameFixer.cs @@ -67,10 +67,10 @@ internal void Awake() UpdateSaves(); - char ds = Path.DirectorySeparatorChar; + char ds = Path.DirectorySeparatorChar; - UpdateCraftDir(string.Format("{0}{1}Ships{1}VAB", KSPUtil.ApplicationRootPath, ds)); - UpdateCraftDir(string.Format("{0}{1}Ships{1}SPH", KSPUtil.ApplicationRootPath, ds)); + 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) { @@ -149,7 +149,7 @@ private void UpdateSaveDir(string saveDir) } } - private void UpdateCraftDir(string dir) + private void UpdateCraftDir(string dir, string rootDir) { string[] files; try @@ -162,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; @@ -184,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); } @@ -194,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); @@ -475,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 @@ -497,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 }