public static void AddOverrideVersion(string oldVersion, string newVersion) { string tempOldVersion = oldVersion.Replace("*", "-1"); //check if there is already an dictionary key which contains the oldversion var dictKeys = CompatibleVersions.Keys; if (dictKeys.Contains(tempOldVersion)) { //add an additional new version to the list of compatible versions CompatibleVersions[tempOldVersion].AddCompatibleWithVersion(newVersion); CfgUpdated = true; return; } //If the key doesn't match, we have to create a whole new dictionary entry //Basically the same code which is used to load the config CompatVersions cv = new CompatVersions(); cv.currentVersion = tempOldVersion; cv.curVersion = new VersionInfo(cv.currentVersion); cv.compatibleWithVersion = new List <string>(); cv.compatWithVersion = new List <VersionInfo>(); cv.compatibleWithVersion.Add(newVersion); cv.compatWithVersion.Add(new VersionInfo(newVersion)); CompatibleVersions.Add(cv.currentVersion, cv); CfgUpdated = true; }
///////// public static void LoadCfg() { Logger.Log("LoadCfg"); OverridePriority = LocalRemotePriority.none; SimplePriority = LocalRemotePriority.none; Logger.Log("KSP-AVC node count: " + GameDatabase.Instance.GetConfigNodes("KSP-AVC").Length); foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("KSP-AVC")) { if (node.HasValue("OVERRIDE_PRIORITY")) { try { OverridePriority = (LocalRemotePriority)Enum.Parse(typeof(LocalRemotePriority), node.GetValue("OVERRIDE_PRIORITY")); Logger.Log("OverridePriority: " + OverridePriority); } catch { } } if (node.HasValue("SIMPLE_PRIORITY")) { try { SimplePriority = (LocalRemotePriority)Enum.Parse(typeof(LocalRemotePriority), node.GetValue("SIMPLE_PRIORITY")); Logger.Log("SimplePriority: " + SimplePriority); } catch { } } var compatVerList = node.GetValuesList("COMPATIBLE_VERSION_OVERRIDE"); foreach (var a in compatVerList) { CompatVersions cv = new CompatVersions(); var ar = a.Split(','); cv.currentVersion = ar[0]; cv.curVersion = new VersionInfo(cv.currentVersion); cv.compatibleWithVersion = new List <string>(); for (int i = 1; i < ar.Length; i++) { cv.compatibleWithVersion.Add(ar[i]); cv.compatWithVersion.Add(new VersionInfo(ar[i])); Logger.Log("COMPATIBLE_VERSION_OVERRIDE, currentVersion: " + ar[0] + ", compatibleWithVersion: " + ar[i]); } CompatibleVersions.Add(cv.currentVersion, cv); } } CfgLoaded = true; Logger.Flush(); }
public static void LoadCfg() { Logger.Log("LoadCfg"); OverridePriority = LocalRemotePriority.none; SimplePriority = LocalRemotePriority.none; CfgUpdated = false; //Logger.Log("KSP-AVC node count: " + GameDatabase.Instance.GetConfigNodes("KSP-AVC").Length); //foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("KSP-AVC")) if (!File.Exists(AvcConfigFile)) { SaveCfg(); return; } ConfigNode LoadNodeFromFile = ConfigNode.Load(AvcConfigFile); ConfigNode node = LoadNodeFromFile.GetNode("KSP-AVC"); //if (node.HasValue("KSP_SKIN")) //{ // try // { // if (node.GetValue("KSP_SKIN").ToLower() == "false") // UseKspSkin = false; // else // UseKspSkin = true; // //Logger.Log($"UseKspSkin: {UseKspSkin}"); // } // catch { } //} if (node.HasValue("OVERRIDE_PRIORITY")) { try { OverridePriority = (LocalRemotePriority)Enum.Parse(typeof(LocalRemotePriority), node.GetValue("OVERRIDE_PRIORITY")); //Logger.Log("OverridePriority: " + OverridePriority); } catch { } } if (node.HasValue("SIMPLE_PRIORITY")) { try { SimplePriority = (LocalRemotePriority)Enum.Parse(typeof(LocalRemotePriority), node.GetValue("SIMPLE_PRIORITY")); //Logger.Log("SimplePriority: " + SimplePriority); } catch { } } if (node.HasValue("DISABLE_COMPATIBLE_VERSION_OVERRIDE")) { try { if (node.GetValue("DISABLE_COMPATIBLE_VERSION_OVERRIDE").ToLower() == "false") { OverrideIsDisabledGlobal = false; } else { OverrideIsDisabledGlobal = true; } //Logger.Log($"OverrideIsDisabled: {OverrideIsDisabledGlobal}"); } catch { } } if (node.HasValue("SHOW_DEFAULT_VALUES")) { try { if (node.GetValue("SHOW_DEFAULT_VALUES").ToLower() == "false") { ShowDefaultValues = false; } else { ShowDefaultValues = true; } //Logger.Log($"OverrideIsDisabled: {OverrideIsDisabledGlobal}"); } catch { } } #if STRICT if (node.HasValue("STRICT_VERSION")) { try { if (node.GetValue("STRICT_VERSION").ToLower() == "false") { StrictVersion = false; } else { StrictVersion = true; } //Logger.Log($"OverrideIsDisabled: {OverrideIsDisabledGlobal}"); } catch { } } else { StrictVersion = false; } #endif if (node.HasNode("OVERRIDE_NAME")) { try { ConfigNode _temp = new ConfigNode(); _temp = node.GetNode("OVERRIDE_NAME"); OverrideCompatibilityByName = _temp.GetValuesList("OverrideEnabled"); } catch { } } if (node.HasNode("OVERRIDE_VERSION")) { try { ConfigNode _temp = new ConfigNode(); _temp = node.GetNode("OVERRIDE_VERSION"); var compatVerList = _temp.GetValuesList("OverrideEnabled"); foreach (var a in compatVerList) { CompatVersions cv = new CompatVersions(); var ar = a.Split(',').Select(x => x.Trim()).ToArray(); cv.currentVersion = ar[0].Replace("*", "-1"); cv.curVersion = new VersionInfo(cv.currentVersion); cv.compatibleWithVersion = new List <string>(); cv.compatWithVersion = new List <VersionInfo>(); //initializing the list before adding stuff to it helps to prevent a NRE :) for (int i = 1; i < ar.Length; i++) { cv.compatibleWithVersion.Add(ar[i]); cv.compatWithVersion.Add(new VersionInfo(ar[i])); Logger.Log("OVERRIDE_VERSION, currentVersion: " + ar[0].Replace("-1", "*") + ", compatibleWithVersion: " + ar[i]); } CompatibleVersions.Add(cv.currentVersion, cv); } } catch { } } if (node.HasNode("OVERRIDE_IGNORE")) { try { ConfigNode _temp = new ConfigNode(); _temp = node.GetNode("OVERRIDE_IGNORE"); List <string> ignoredMods = _temp.GetValuesList("IgnoreOverride"); foreach (string modName in ignoredMods) { modsIgnoreOverride.Add(modName); //Logger.Log($"IGNORE_OVERRIDE: {modName}"); } } catch { } } if (node.HasNode("INTERVAL")) { try { ConfigNode _temp = new ConfigNode(); _temp = node.GetNode("INTERVAL"); AvcInterval = Int32.Parse(_temp.GetValue("MinTimeBetweenAvcRuns")); if (!_temp.HasValue("AvcRunsNext")) { CfgUpdated = true; } NextRun = DateTime.Parse(_temp.GetValue("AvcRunsNext")); Logger.Log($"INTERVAL: {AvcInterval}"); Logger.Log($"NextRun: {NextRun}"); } catch { } } if (DateTime.Compare(DateTime.Now, NextRun) >= 0 && AvcInterval > 0) { CfgUpdated = true; } CfgLoaded = true; Logger.Flush(); }