/// <summary> /// Loads all the contact configuration group nodes. /// </summary> private IEnumerator <YieldInstruction> LoadGroupConfig() { // Load all the contract groups LoggingUtil.LogDebug(this, "Loading CONTRACT_GROUP nodes."); ConfigNode[] contractGroups = GameDatabase.Instance.GetConfigNodes("CONTRACT_GROUP"); foreach (ConfigNode groupConfig in contractGroups) { // Create the group string name = groupConfig.GetValue("name"); LoggingUtil.LogInfo(this, "Loading CONTRACT_GROUP: '" + name + "'"); ContractGroup contractGroup = null; try { contractGroup = new ContractGroup(name); } catch (ArgumentException) { LoggingUtil.LogError(this, "Couldn't load CONTRACT_GROUP '" + name + "' due to a duplicate name."); } // Peform the actual load if (contractGroup != null) { bool success = false; try { ConfigNodeUtil.ClearCache(true); success = contractGroup.Load(groupConfig); } catch (Exception e) { Exception wrapper = new Exception("Error loading CONTRACT_GROUP '" + name + "'", e); LoggingUtil.LogException(wrapper); } finally { if (!success) { ContractGroup.contractGroups.Remove(name); } } } } if (!reloading) { yield return(new WaitForEndOfFrame()); } // Emit settings for the menu SettingsBuilder.EmitSettings(); yield break; }
/// <summary> /// Loads the contract group details from the given config node. /// </summary> /// <param name="configNode">The config node to load from</param> /// <returns>Whether we were successful.</returns> public bool Load(ConfigNode configNode) { try { dataNode = new DataNode(configNode.GetValue("name"), this); LoggingUtil.CaptureLog = true; ConfigNodeUtil.SetCurrentDataNode(dataNode); bool valid = true; valid &= ConfigNodeUtil.ParseValue <string>(configNode, "name", x => name = x, this); valid &= ConfigNodeUtil.ParseValue <string>(configNode, "displayName", x => displayName = x, this, name); valid &= ConfigNodeUtil.ParseValue <string>(configNode, "minVersion", x => minVersionStr = x, this, ""); valid &= ConfigNodeUtil.ParseValue <int>(configNode, "maxCompletions", x => maxCompletions = x, this, 0, x => Validation.GE(x, 0)); valid &= ConfigNodeUtil.ParseValue <int>(configNode, "maxSimultaneous", x => maxSimultaneous = x, this, 0, x => Validation.GE(x, 0)); valid &= ConfigNodeUtil.ParseValue <List <string> >(configNode, "disabledContractType", x => disabledContractType = x, this, new List <string>()); valid &= ConfigNodeUtil.ParseValue <Agent>(configNode, "agent", x => agent = x, this, (Agent)null); valid &= ConfigNodeUtil.ParseValue <string>(configNode, "sortKey", x => sortKey = x, this, displayName); valid &= ConfigNodeUtil.ParseValue <string>(configNode, "tip", x => {}, this, ""); if (configNode.HasValue("sortKey") && parent == null) { sortKey = displayName; LoggingUtil.LogWarning(this, ErrorPrefix() + ": Using the sortKey field is only applicable on child CONTRACT_GROUP elements"); } if (!string.IsNullOrEmpty(minVersionStr)) { if (Util.Version.VerifyAssemblyVersion("ContractConfigurator", minVersionStr) == null) { valid = false; var ainfoV = Attribute.GetCustomAttribute(typeof(ExceptionLogWindow).Assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute; string title = "Contract Configurator " + ainfoV.InformationalVersion + " Message"; string message = "The contract group '" + name + "' requires at least Contract Configurator " + minVersionStr + " to work, and you are running version " + ainfoV.InformationalVersion + ". Please upgrade Contract Configurator to use the contracts in this group."; DialogGUIButton dialogOption = new DialogGUIButton("Okay", new Callback(DoNothing), true); PopupDialog.SpawnPopupDialog(new MultiOptionDialog(message, title, UISkinManager.GetSkin("default"), dialogOption), false, UISkinManager.GetSkin("default")); } } // Load DATA nodes valid &= dataNode.ParseDataNodes(configNode, this, dataValues, uniquenessChecks); // Do the deferred loads valid &= ConfigNodeUtil.ExecuteDeferredLoads(); // Do post-deferred load warnings if (agent == null) { LoggingUtil.LogWarning(this, ErrorPrefix() + ": Providing the agent field for all CONTRACT_GROUP nodes is highly recommended, as the agent is used to group contracts in Mission Control."); } if (string.IsNullOrEmpty(minVersionStr) || minVersion < ContractConfigurator.ENHANCED_UI_VERSION) { LoggingUtil.LogWarning(this, ErrorPrefix() + ": No minVersion or older minVersion provided. It is recommended that the minVersion is set to at least 1.15.0 to turn important warnings for deprecated functionality into errors."); } if (!configNode.HasValue("displayName")) { LoggingUtil.LogWarning(this, ErrorPrefix() + ": No display name provided. A display name is recommended, as it is used in the Mission Control UI."); } config = configNode.ToString(); log += LoggingUtil.capturedLog; LoggingUtil.CaptureLog = false; // Load child groups foreach (ConfigNode childNode in ConfigNodeUtil.GetChildNodes(configNode, "CONTRACT_GROUP")) { ContractGroup child = null; string childName = childNode.GetValue("name"); try { child = new ContractGroup(childName); } catch (ArgumentException) { LoggingUtil.LogError(this, "Couldn't load CONTRACT_GROUP '" + childName + "' due to a duplicate name."); valid = false; continue; } child.parent = this; valid &= child.Load(childNode); child.dataNode.Parent = dataNode; if (child.hasWarnings) { hasWarnings = true; } } // Check for unexpected values - always do this last valid &= ConfigNodeUtil.ValidateUnexpectedValues(configNode, this); // Invalidate children if (!valid) { Invalidate(); } enabled = valid; return(valid); } catch { enabled = false; throw; } }
/// <summary> /// Loads the contract group details from the given config node. /// </summary> /// <param name="configNode">The config node to load from</param> /// <returns>Whether we were successful.</returns> public bool Load(ConfigNode configNode) { try { dataNode = new DataNode(configNode.GetValue("name"), this); LoggingUtil.CaptureLog = true; ConfigNodeUtil.SetCurrentDataNode(dataNode); bool valid = true; string unused; valid &= ConfigNodeUtil.ParseValue<string>(configNode, "name", x => name = x, this); valid &= ConfigNodeUtil.ParseValue<string>(configNode, "displayName", x => displayName = x, this, name); valid &= ConfigNodeUtil.ParseValue<string>(configNode, "minVersion", x => minVersionStr = x, this, ""); valid &= ConfigNodeUtil.ParseValue<int>(configNode, "maxCompletions", x => maxCompletions = x, this, 0, x => Validation.GE(x, 0)); valid &= ConfigNodeUtil.ParseValue<int>(configNode, "maxSimultaneous", x => maxSimultaneous = x, this, 0, x => Validation.GE(x, 0)); valid &= ConfigNodeUtil.ParseValue<List<string>>(configNode, "disabledContractType", x => disabledContractType = x, this, new List<string>()); valid &= ConfigNodeUtil.ParseValue<Agent>(configNode, "agent", x => agent = x, this, (Agent)null); valid &= ConfigNodeUtil.ParseValue<string>(configNode, "sortKey", x => sortKey = x, this, displayName); valid &= ConfigNodeUtil.ParseValue<string>(configNode, "tip", x => unused = x, this, ""); if (configNode.HasValue("sortKey") && parent == null) { sortKey = displayName; LoggingUtil.LogWarning(this, ErrorPrefix() + ": Using the sortKey field is only applicable on child CONTRACT_GROUP elements"); } if (!string.IsNullOrEmpty(minVersionStr)) { if (Util.Version.VerifyAssemblyVersion("ContractConfigurator", minVersionStr) == null) { valid = false; var ainfoV = Attribute.GetCustomAttribute(typeof(ExceptionLogWindow).Assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute; string title = "Contract Configurator " + ainfoV.InformationalVersion + " Message"; string message = "The contract group '" + name + "' requires at least Contract Configurator " + minVersionStr + " to work, and you are running version " + ainfoV.InformationalVersion + ". Please upgrade Contract Configurator to use the contracts in this group."; DialogGUIButton dialogOption = new DialogGUIButton("Okay", new Callback(DoNothing), true); PopupDialog.SpawnPopupDialog(new MultiOptionDialog(message, title, UISkinManager.GetSkin("default"), dialogOption), false, UISkinManager.GetSkin("default")); } } // Load DATA nodes valid &= dataNode.ParseDataNodes(configNode, this, dataValues, uniquenessChecks); // Do the deferred loads valid &= ConfigNodeUtil.ExecuteDeferredLoads(); // Do post-deferred load warnings if (agent == null) { LoggingUtil.LogWarning(this, ErrorPrefix() + ": Providing the agent field for all CONTRACT_GROUP nodes is highly recommended, as the agent is used to group contracts in Mission Control."); } if (string.IsNullOrEmpty(minVersionStr) || minVersion < ContractConfigurator.ENHANCED_UI_VERSION) { LoggingUtil.LogWarning(this, ErrorPrefix() + ": No minVersion or older minVersion provided. It is recommended that the minVersion is set to at least 1.15.0 to turn important warnings for deprecated functionality into errors."); } if (!configNode.HasValue("displayName")) { LoggingUtil.LogWarning(this, ErrorPrefix() + ": No display name provided. A display name is recommended, as it is used in the Mission Control UI."); } config = configNode.ToString(); log += LoggingUtil.capturedLog; LoggingUtil.CaptureLog = false; // Load child groups foreach (ConfigNode childNode in ConfigNodeUtil.GetChildNodes(configNode, "CONTRACT_GROUP")) { ContractGroup child = null; string childName = childNode.GetValue("name"); try { child = new ContractGroup(childName); } catch (ArgumentException) { LoggingUtil.LogError(this, "Couldn't load CONTRACT_GROUP '" + childName + "' due to a duplicate name."); valid = false; continue; } child.parent = this; valid &= child.Load(childNode); child.dataNode.Parent = dataNode; if (child.hasWarnings) { hasWarnings = true; } } // Check for unexpected values - always do this last valid &= ConfigNodeUtil.ValidateUnexpectedValues(configNode, this); // Invalidate children if (!valid) { Invalidate(); } enabled = valid; return valid; } catch { enabled = false; throw; } }
/// <summary> /// Loads the contract group details from the given config node. /// </summary> /// <param name="configNode">The config node to load from</param> /// <returns>Whether we were successful.</returns> public bool Load(ConfigNode configNode) { try { dataNode = new DataNode(configNode.GetValue("name"), this); LoggingUtil.CaptureLog = true; ConfigNodeUtil.SetCurrentDataNode(dataNode); bool valid = true; valid &= ConfigNodeUtil.ParseValue<string>(configNode, "name", x => name = x, this); valid &= ConfigNodeUtil.ParseValue<string>(configNode, "displayName", x => displayName = x, this, name); valid &= ConfigNodeUtil.ParseValue<string>(configNode, "minVersion", x => minVersion = x, this, ""); valid &= ConfigNodeUtil.ParseValue<int>(configNode, "maxCompletions", x => maxCompletions = x, this, 0, x => Validation.GE(x, 0)); valid &= ConfigNodeUtil.ParseValue<int>(configNode, "maxSimultaneous", x => maxSimultaneous = x, this, 0, x => Validation.GE(x, 0)); valid &= ConfigNodeUtil.ParseValue<List<string>>(configNode, "disabledContractType", x => disabledContractType = x, this, new List<string>()); if (!string.IsNullOrEmpty(minVersion)) { if (Util.Version.VerifyAssemblyVersion("ContractConfigurator", minVersion) == null) { valid = false; var ainfoV = Attribute.GetCustomAttribute(typeof(ExceptionLogWindow).Assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute; string title = "Contract Configurator " + ainfoV.InformationalVersion + " Message"; string message = "The contract group '" + name + "' requires at least Contract Configurator " + minVersion + " to work, and you are running version " + ainfoV.InformationalVersion + ". Please upgrade Contract Configurator to use the contracts in this group."; DialogOption dialogOption = new DialogOption("Okay", new Callback(DoNothing), true); PopupDialog.SpawnPopupDialog(new MultiOptionDialog(message, title, HighLogic.Skin, dialogOption), false, HighLogic.Skin); } } // Load DATA nodes valid &= dataNode.ParseDataNodes(configNode, this, dataValues, uniquenessChecks); // Do the deferred loads valid &= ConfigNodeUtil.ExecuteDeferredLoads(); config = configNode.ToString(); log += LoggingUtil.capturedLog; LoggingUtil.CaptureLog = false; // Load child groups foreach (ConfigNode childNode in ConfigNodeUtil.GetChildNodes(configNode, "CONTRACT_GROUP")) { ContractGroup child = null; string childName = childNode.GetValue("name"); try { child = new ContractGroup(childName); } catch (ArgumentException) { LoggingUtil.LogError(this, "Couldn't load CONTRACT_GROUP '" + childName + "' due to a duplicate name."); valid = false; continue; } valid &= child.Load(childNode); child.parent = this; child.dataNode.Parent = dataNode; if (child.hasWarnings) { hasWarnings = true; } } // Check for unexpected values - always do this last valid &= ConfigNodeUtil.ValidateUnexpectedValues(configNode, this); // Invalidate children if (!valid) { Invalidate(); } enabled = valid; return valid; } catch { enabled = false; throw; } }
/// <summary> /// Loads all the contact configuration nodes and creates ContractType objects. /// </summary> private IEnumerator <YieldInstruction> LoadContractConfig() { // Load all the contract groups LoggingUtil.LogDebug(this.GetType(), "Loading CONTRACT_GROUP nodes."); ConfigNode[] contractGroups = GameDatabase.Instance.GetConfigNodes("CONTRACT_GROUP"); foreach (ConfigNode groupConfig in contractGroups) { // Create the group string name = groupConfig.GetValue("name"); LoggingUtil.LogInfo(this.GetType(), "Loading CONTRACT_GROUP: '" + name + "'"); ContractGroup contractGroup = null; try { contractGroup = new ContractGroup(name); } catch (ArgumentException) { LoggingUtil.LogError(this.GetType(), "Couldn't load CONTRACT_GROUP '" + name + "' due to a duplicate name."); } // Peform the actual load if (contractGroup != null) { bool success = false; try { success = contractGroup.Load(groupConfig); } catch (Exception e) { Exception wrapper = new Exception("Error loading CONTRACT_GROUP '" + name + "'", e); LoggingUtil.LogException(wrapper); } finally { if (!success) { ContractGroup.contractGroups.Remove(name); } } } } LoggingUtil.LogDebug(this.GetType(), "Loading CONTRACT_TYPE nodes."); ConfigNode[] contractConfigs = GameDatabase.Instance.GetConfigNodes("CONTRACT_TYPE"); totalContracts = contractConfigs.Count(); // First pass - create all the ContractType objects foreach (ConfigNode contractConfig in contractConfigs) { // Create the initial contract type LoggingUtil.LogVerbose(this.GetType(), "Pre-load for node: '" + contractConfig.GetValue("name") + "'"); try { ContractType contractType = new ContractType(contractConfig.GetValue("name")); } catch (ArgumentException) { LoggingUtil.LogError(this.GetType(), "Couldn't load CONTRACT_TYPE '" + contractConfig.GetValue("name") + "' due to a duplicate name."); } } // Second pass - do the actual loading of details foreach (ConfigNode contractConfig in contractConfigs) { attemptedContracts++; yield return(new WaitForEndOfFrame()); // Fetch the contractType string name = contractConfig.GetValue("name"); ContractType contractType = ContractType.GetContractType(name); if (contractType != null) { LoggingUtil.LogDebug(this.GetType(), "Loading CONTRACT_TYPE: '" + name + "'"); // Perform the load try { contractType.Load(contractConfig); if (contractType.enabled) { successContracts++; } } catch (Exception e) { Exception wrapper = new Exception("Error loading CONTRACT_TYPE '" + name + "'", e); LoggingUtil.LogException(wrapper); } } } LoggingUtil.LogInfo(this.GetType(), "Loaded " + successContracts + " out of " + totalContracts + " CONTRACT_TYPE nodes."); if (!reloading && LoggingUtil.logLevel == LoggingUtil.LogLevel.DEBUG || LoggingUtil.logLevel == LoggingUtil.LogLevel.VERBOSE) { ScreenMessages.PostScreenMessage("Contract Configurator: Loaded " + successContracts + " out of " + totalContracts + " contracts successfully.", 5, ScreenMessageStyle.UPPER_CENTER); } }
/// <summary> /// Loads the contract group details from the given config node. /// </summary> /// <param name="configNode">The config node to load from</param> /// <returns>Whether we were successful.</returns> public bool Load(ConfigNode configNode) { try { dataNode = new DataNode(configNode.GetValue("name"), this); LoggingUtil.CaptureLog = true; ConfigNodeUtil.ClearCache(true); ConfigNodeUtil.SetCurrentDataNode(dataNode); bool valid = true; valid &= ConfigNodeUtil.ParseValue <string>(configNode, "name", x => name = x, this); valid &= ConfigNodeUtil.ParseValue <string>(configNode, "minVersion", x => minVersion = x, this, ""); valid &= ConfigNodeUtil.ParseValue <int>(configNode, "maxCompletions", x => maxCompletions = x, this, 0, x => Validation.GE(x, 0)); valid &= ConfigNodeUtil.ParseValue <int>(configNode, "maxSimultaneous", x => maxSimultaneous = x, this, 0, x => Validation.GE(x, 0)); if (!string.IsNullOrEmpty(minVersion)) { if (Util.Version.VerifyAssemblyVersion("ContractConfigurator", minVersion) == null) { valid = false; var ainfoV = Attribute.GetCustomAttribute(typeof(ExceptionLogWindow).Assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute; string title = "Contract Configurator " + ainfoV.InformationalVersion + " Message"; string message = "The contract group '" + name + "' requires at least Contract Configurator " + minVersion + " to work, and you are running version " + ainfoV.InformationalVersion + ". Please upgrade Contract Configurator to use the contracts in this group."; DialogOption dialogOption = new DialogOption("Okay", new Callback(DoNothing), true); PopupDialog.SpawnPopupDialog(new MultiOptionDialog(message, title, HighLogic.Skin, dialogOption), false, HighLogic.Skin); } } // Check for unexpected values - always do this last valid &= ConfigNodeUtil.ValidateUnexpectedValues(configNode, this); // Do the deferred loads valid &= ConfigNodeUtil.ExecuteDeferredLoads(); config = configNode.ToString(); log += LoggingUtil.capturedLog; LoggingUtil.CaptureLog = false; // Load child groups foreach (ConfigNode childNode in ConfigNodeUtil.GetChildNodes(configNode, "CONTRACT_GROUP")) { ContractGroup child = null; string name = childNode.GetValue("name"); try { child = new ContractGroup(name); } catch (ArgumentException) { LoggingUtil.LogError(this, "Couldn't load CONTRACT_GROUP '" + name + "' due to a duplicate name."); valid = false; continue; } valid &= child.Load(childNode); child.parent = this; if (child.hasWarnings) { hasWarnings = true; } } // Invalidate children if (!valid) { Invalidate(); } enabled = valid; return(valid); } catch { enabled = false; throw; } }