public static Settings LoadPreset(Settings previousSettings, string presetCfgUrl)
{
var newPreSetSettings = new Settings();
var successLoadPreSet = false;
// Exploit KSP's GameDatabase to find third-party mods' RemoteTechSetting node (from GameData/ExampleMod/RemoteTechSettings.cfg)
var rtSettingCfGs = GameDatabase.Instance.GetConfigs("RemoteTechSettings");
for(var i = 0; i < rtSettingCfGs.Length; i++)
{
var rtSettingCfg = rtSettingCfGs[i];
if (!rtSettingCfg.url.Equals(presetCfgUrl))
continue;
// Preserve important information of RT, such as the single ID
var importantInfoNode = new ConfigNode();
importantInfoNode.AddValue("MapFilter", previousSettings.MapFilter);
importantInfoNode.AddValue("ActiveVesselGuid", previousSettings.ActiveVesselGuid);
importantInfoNode.AddValue("NoTargetGuid", previousSettings.NoTargetGuid);
successLoadPreSet = ConfigNode.LoadObjectFromConfig(newPreSetSettings, rtSettingCfg.config);
RTLog.Notify("Load the preset cfg into object with {0}: LOADED {1}", newPreSetSettings, successLoadPreSet ? "OK" : "FAIL");
// Restore backups
ConfigNode.LoadObjectFromConfig(newPreSetSettings, importantInfoNode);
break;
}
return successLoadPreSet?newPreSetSettings: previousSettings;
}