Skip to content

Commit 0c73b09

Browse files
committed
Quick Loading DataBase from Config Cache (when available)
1 parent 00ee1d7 commit 0c73b09

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

Source/ModuleManager/GUI/Menu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private void Show()
7171
new DialogGUIButton("Quick Reload Database",
7272
delegate
7373
{
74-
this.parent.StartCoroutine(this.parent.DataBaseReloadWithMM(true));
74+
this.parent.StartCoroutine(this.parent.QuickDataBaseReloadWithMM());
7575
this.Dismiss();
7676
}, 140.0f, 30.0f, false),
7777
new DialogGUIButton("Dump Database to Files",

Source/ModuleManager/ModuleManager.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,45 @@ internal IEnumerator DataBaseReloadWithMM(bool keepPartDB)
375375
}
376376
}
377377

378+
internal IEnumerator QuickDataBaseReloadWithMM()
379+
{
380+
ModLogger.LOG.info("Quick loading DataBase from Config Cache...");
381+
if (!FilePathRepository.CACHE_CONFIG.IsLoadable)
382+
{
383+
ModLogger.LOG.warn("Config Cache file not found. Aborting Quick Reload.");
384+
yield break;
385+
}
386+
387+
ConfigNode cache = FilePathRepository.CACHE_CONFIG.Load().Node;
388+
389+
UrlDir gameDataDir = GameDatabase.Instance.root.AllDirectories.First(d => d.path.EndsWith("GameData") && d.name == "" && d.url == "");
390+
UrlDir.UrlFile physicsUrlFile = new UrlDir.UrlFile(gameDataDir, new FileInfo(FilePathRepository.PHYSICS_CONFIG.KspPath));
391+
gameDataDir.files.Add(physicsUrlFile);
392+
393+
List<IProtoUrlConfig> databaseConfigs = new List<IProtoUrlConfig>(cache.nodes.Count);
394+
395+
foreach (ConfigNode node in cache.nodes)
396+
{
397+
string parentUrl = node.GetValue("parentUrl");
398+
399+
UrlDir.UrlFile parent = gameDataDir.Find(parentUrl);
400+
if (parent != null)
401+
{
402+
node.nodes[0].UnescapeValuesRecursive();
403+
databaseConfigs.Add(new ProtoUrlConfig(parent, node.nodes[0]));
404+
}
405+
}
406+
407+
foreach (UrlDir.UrlFile file in GameDatabase.Instance.root.AllConfigFiles)
408+
file.configs.Clear();
409+
410+
foreach (IProtoUrlConfig protoConfig in databaseConfigs)
411+
protoConfig.UrlFile.AddConfig(protoConfig.Node);
412+
413+
ModLogger.LOG.info("Quick loading DataBase finished.");
414+
yield return null;
415+
}
416+
378417
internal IEnumerator DumpDataBaseToFiles()
379418
{
380419
ModLogger.LOG.info("Dumping DataBase to files.");

0 commit comments

Comments
 (0)