public void Load(KeyDataCollection section) { if (section.ContainsKey("enabled") == false) { return; } string enablestring = section["enabled"].ToUpper(); this.Autoaccount = enablestring == "YES" || enablestring == "1" || enablestring == "TRUE"; if (section.ContainsKey("role") == false) { throw new Exception("With autoaccount enabled you MUST specify a default role"); } string rolestring = section["role"]; Roles role; if (Roles.TryParse(rolestring, out role) == false) { throw new Exception($"Unknown role value {rolestring}"); } this.Role = role; }
public void Load(KeyDataCollection section) { if (section.ContainsKey("loginMessageType") == false) { this.MessageType = AuthenticationMessageType.NoMessage; return; } string value = section["loginMessageType"].ToUpper(); switch (value) { case "MESSAGE": if (section.ContainsKey("loginMessage") == false) { throw new Exception( "Authentication service configuration must specify an HTML message" ); } this.Message = section["loginMessage"]; this.MessageType = AuthenticationMessageType.HTMLMessage; break; case "NONE": default: this.MessageType = AuthenticationMessageType.NoMessage; break; } }
void ReadGraphicsSettings(IniData data) { KeyDataCollection keys = data["Graphics"]; if (keys == null) { return; } if (keys.ContainsKey("ShadowRes")) { int val; if (Int32.TryParse(keys["ShadowRes"], out val)) { Graphics.ShadowRes = val; } } if (keys.ContainsKey("EnableShadow")) { int val; if (Int32.TryParse(keys["EnableShadow"], out val)) { Graphics.EnableShadow = (val == 1); } } }
public void LoadIniData(KeyDataCollection data) { IsEnabled = true; foreach (var prop in typeof(T).GetProperties()) { var keyName = prop.Name; // Set first char of keyName to lowercase if (keyName != string.Empty && char.IsUpper(keyName[0])) { keyName = char.ToLower(keyName[0]) + keyName.Substring(1); } if (data.ContainsKey(keyName)) { Debug.Log($" Loading key {keyName}"); } else { Debug.Log($" Key {keyName} not defined, using default value"); } if (!data.ContainsKey(keyName)) { continue; } var existingValue = prop.GetValue(this, null); if (prop.PropertyType == typeof(float)) { prop.SetValue(this, data.GetFloat(keyName, (float)existingValue), null); continue; } if (prop.PropertyType == typeof(int)) { prop.SetValue(this, data.GetInt(keyName, (int)existingValue), null); continue; } if (prop.PropertyType == typeof(bool)) { prop.SetValue(this, data.GetBool(keyName), null); continue; } if (prop.PropertyType == typeof(KeyCode)) { prop.SetValue(this, data.GetKeyCode(keyName, (KeyCode)existingValue), null); continue; } Debug.LogWarning($" Could not load data of type {prop.PropertyType} for key {keyName}"); } }
public void AddKey(string filename, string section, string key, string value) { if (!File.Exists(filename)) { File.WriteAllText(filename, string.Empty); } IniData iniData = IniParser.ReadFile(filename); if (!iniData.Sections.ContainsSection(section)) { iniData.Sections.AddSection(section); } KeyDataCollection autorunSection = iniData.Sections[section]; if (!autorunSection.ContainsKey(key)) { autorunSection.AddKey(key); } autorunSection.GetKeyData(key).Value = value; IniParser.WriteFile(filename, iniData); }
/// <summary> /// Adds a key to a concrete <see cref="KeyDataCollection"/> instance, checking /// if duplicate keys are allowed in the configuration /// </summary> /// <param name="key"> /// Key name /// </param> /// <param name="value"> /// Key's value /// </param> /// <param name="keyDataCollection"> /// <see cref="KeyData"/> collection where the key should be inserted /// </param> /// <param name="sectionName"> /// Name of the section where the <see cref="KeyDataCollection"/> is contained. /// Used only for logging purposes. /// </param> private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName) { // Check for duplicated keys if (keyDataCollection.ContainsKey(key)) { // We already have a key with the same name defined in the current section if (!Configuration.AllowDuplicateKeys) { throw new ParsingException(string.Format("Duplicated key '{0}' found in section '{1}", key, sectionName)); } else if (Configuration.OverrideDuplicateKeys) { keyDataCollection[key] = value; } } else { // Save the keys keyDataCollection.AddKey(key, value); } keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp; _currentCommentListTemp.Clear(); }
/// <summary> /// Deserialize a section of settings in a class. /// </summary> /// <typeparam name="T">Type of class.</typeparam> /// <param name="section">Name of section.</param> /// <param name="instance">Instance of class with keys as public fields.</param> public void Deserialize <T>(string section, ref T instance) where T : class { if (!userSettings.Sections.ContainsSection(section)) { Debug.LogErrorFormat("Failed to parse section {0} for mod {1}", section, mod.Title); return; } KeyDataCollection sectionData = userSettings[section]; foreach (var field in typeof(T).GetFields(BindingFlags.Instance | BindingFlags.Public)) { try { if (sectionData.ContainsKey(field.Name)) { var value = GetValue(section, field.Name, field.FieldType); if (value != null) { field.SetValue(instance, value); } } } catch (Exception e) { Debug.LogErrorFormat("Failed to parse section {0} for mod {1}\n{2}", section, mod.Title, e.ToString()); } } }
public void RemoveKey(string filename, string section, string key) { if (!File.Exists(filename)) { return; } IniData iniData = IniParser.ReadFile(filename); if (iniData.Sections.ContainsSection(section)) { KeyDataCollection autorunSection = iniData.Sections[section]; if (autorunSection.ContainsKey(key)) { autorunSection.RemoveKey(key); } if (autorunSection.Count == 0) { iniData.Sections.RemoveSection(section); } IniParser.WriteFile(filename, iniData); } if (File.ReadAllText(filename) == string.Empty) { File.Delete(filename); } }
private string TryGet(KeyDataCollection context, string key, string def = null) { if (context.ContainsKey(key)) { return(context[key].Trim('"')); } return(def?.Trim('"')); }
public static string GetString(this KeyDataCollection settings, string keyName, string defaultVal = "") { if (!settings.ContainsKey(keyName)) { settings.AddKey(CreateKeyData(keyName, defaultVal)); Write(); } return(settings[keyName]); }
public void Load(KeyDataCollection section) { if (section.ContainsKey("port") == false) { return; } Port = ushort.Parse(section["port"]); }
private int getDirWarp(KeyDataCollection data, string axis, string dir) { string key = string.Format("Warp{0}({1})", axis, dir); if (!data.ContainsKey(key)) { return(0); } return(int.TryParse(data[key], out var i) ? i : 0); }
public void Load(KeyDataCollection section) { if (section.ContainsKey("balance") == false) { this.Balance = 50000.0; return; } this.Balance = double.Parse(section["balance"]); }
private static bool ParametersContainKey(KeyDataCollection parameters, string key, out string paramOut) { if (parameters.ContainsKey(key)) { paramOut = parameters[key]; return(true); } paramOut = null; return(false); }
protected string getStringINIValue(KeyDataCollection data, string name) { char letter = "ABC"[(int)ID]; string key = $"{prefix}{name}({letter})"; if (!data.ContainsKey(key)) { return(null); } return(data[key]); }
/// <summary> /// Adds a key to a concrete <see cref="KeyDataCollection" instance, checking /// if duplicate keys are allowed in the configuration /// </summary> /// <param name="key"> /// Key name /// </param> /// <param name="value"> /// Key's value /// </param> /// <param name="keyDataCollection"> /// <see cref="KeyData" collection where the key should be inserted /// </param> /// <param name="sectionName"> /// Name of the section where the <see cref="KeyDataCollection" is contained. /// Used only for logging purposes. /// </param> private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName) { // Check for duplicated keys if (keyDataCollection.ContainsKey(key)) HandleDuplicatedKeyInCollection(key, value, keyDataCollection, sectionName); else keyDataCollection.AddKey(key, value); keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp; _currentCommentListTemp.Clear(); }
private void parseMultiCategory(KeyDataCollection world_data, string base_name, List <string> target, string[] sub) { foreach (string s in sub) { string entry = string.Format("{0} {1}", base_name, s); if (!world_data.ContainsKey(entry)) { continue; } target.Add(world_data[entry]); } }
public void Load(KeyDataCollection collection) { if (collection.ContainsKey("force") == false) { return; } // load suppressed channels from the line string[] channels = collection["force"].Split(','); this.EnableChannels.AddRange(channels); }
public void Load(KeyDataCollection section) { if (section.ContainsKey("enabled") == false) { return; } string enablestring = section["enabled"].ToUpper(); this.Autoaccount = enablestring == "YES" || enablestring == "1" || enablestring == "TRUE"; if (section.ContainsKey("role") == false) { throw new Exception("With autoaccount enabled you MUST specify a default role"); } string rolestring = section["role"]; string[] rolelist = rolestring.Split(","); foreach (string role in rolelist) { string trimedRole = role.Trim(); // ignore empty roles if (trimedRole == "") { continue; } Roles roleValue; if (Roles.TryParse(trimedRole, out roleValue) == false) { throw new Exception($"Unknown role value {role.Trim()}"); } this.Role |= (long)roleValue; } }
public static ParserConfiguration Parse(KeyDataCollection initSection) { var config = Default; if (initSection.ContainsKey(RelativePathKey)) { config.RelativePath = initSection[RelativePathKey]; } if (initSection.ContainsKey(ValuesKey)) { var valuesString = initSection[ValuesKey].Split(','); var valueArray = new MaterialType[valuesString.Length]; for (var i = 0; i < valuesString.Length; i++) { valueArray[i] = ParseMaterialTypeEnum(valuesString[i]); } config.Values = valueArray; } return(config); }
private void DeleteIconFile(KeyDataCollection section) { if (section.ContainsKey("IconResource")) { var oldIcon = section["IconResource"]; var imgPath = oldIcon.Split(',')[0]; if (Path.GetExtension(imgPath) == ".ico") { var folderPath = Path.GetDirectoryName(filePath); File.Delete(Path.Combine(folderPath, imgPath)); } section.RemoveKey("IconResource"); } }
private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName) { bool flag = keyDataCollection.ContainsKey(key); if (flag) { this.HandleDuplicatedKeyInCollection(key, value, keyDataCollection, sectionName); } else { keyDataCollection.AddKey(key, value); } keyDataCollection.GetKeyData(key).Comments = this._currentCommentListTemp; this._currentCommentListTemp.Clear(); }
public static bool GetBool(this KeyDataCollection settings, string keyName, bool defaultVal = false) { if (!settings.ContainsKey(keyName)) { settings.AddKey(CreateKeyData(keyName, defaultVal.ToString())); Write(); } bool successful = StrToBool(settings[keyName], out bool result, defaultVal); if (!successful) { Logger.Warning($"Unable to parse {keyName} with value {settings[keyName]} as a boolean, using default value of {defaultVal} instead."); } return(result); }
private string GetValue(string section, string key) { if (!_data.Sections.ContainsSection(section)) { throw new SectionNotFoundException(section); } KeyDataCollection keyMap = _data[section];; if (!keyMap.ContainsKey(key)) { throw new KeyNotFoundException(key); } return(keyMap[key]); }
/// <summary> /// Adds a key to a concrete <see cref="KeyDataCollection"/> instance, checking /// if duplicate keys are allowed in the configuration /// </summary> /// <param name="key"> /// Key name /// </param> /// <param name="value"> /// Key's value /// </param> /// <param name="keyDataCollection"> /// <see cref="KeyData"/> collection where the key should be inserted /// </param> /// <param name="sectionName"> /// Name of the section where the <see cref="KeyDataCollection"/> is contained. /// Used only for logging purposes. /// </param> private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName) { // Check for duplicated keys if (keyDataCollection.ContainsKey(key)) { // We already have a key with the same name defined in the current section HandleDuplicatedKeyInCollection(key, value, keyDataCollection, sectionName); } else { // Save the keys keyDataCollection.AddKey(key, value); } keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp; _currentCommentListTemp.Clear(); }
public static int GetInt(this KeyDataCollection settings, string keyName, int defaultVal = 0) { if (!settings.ContainsKey(keyName)) { settings.AddKey(CreateKeyData(keyName, defaultVal.ToString())); Write(); } int val = defaultVal; bool successful = int.TryParse(settings[keyName], out val); if (!successful) { Logger.Warning($"Unable to parse {keyName} with value {settings[keyName]} as an integer, using default value of {defaultVal} instead."); val = defaultVal; } return(val); }
/// <summary> /// Creates the configuration. /// </summary> /// <param name="serialNumber">The serial number.</param> /// <param name="data">The data.</param> /// <returns>A filled robot configuration instance</returns> private static RobotConfiguration ReadConfig(string serialNumber, KeyDataCollection data) { try { return(new RobotConfiguration() { SerialNumber = serialNumber, Guid = data[GuidKey], IPAddress = data.ContainsKey(IpKey) ? IPAddress.Parse(data[IpKey]) : null, RobotName = data[NameKey], Certificate = File.ReadAllText(data[CertKey]) }); } catch (Exception ex) { throw new VectorConfigurationException("Invalid robot configuration in file", ex); } }
/// <summary> /// Updates the configuration file data /// </summary> /// <param name="robot">The robot configuration.</param> /// <param name="ankiVectorPath">The anki_vector folder path.</param> /// <param name="data">The configuration file data.</param> private static void WriteConfig(IRobotConfiguration robot, string ankiVectorPath, KeyDataCollection data) { data[GuidKey] = robot.Guid; data[NameKey] = robot.RobotName; if (!data.ContainsKey(CertKey)) { data[CertKey] = Path.Combine(ankiVectorPath, robot.RobotName + "-" + robot.SerialNumber + ".cert"); } if (robot.IPAddress != null) { data[IpKey] = robot.IPAddress.ToString(); } if (!File.Exists(data[CertKey])) { File.WriteAllText(data[CertKey], robot.Certificate); } }
public static ProgramMapping BuildFromFile(string filename) { var parser = new FileIniDataParser(); IniData data = parser.ReadFile(filename); string name = data["ID"]["name"]; string program_regex_str = data["PROGRAM"]["regex"]; Dictionary <Types.ButtonFlags, Action> mappings = new Dictionary <Types.ButtonFlags, Action>(); KeyDataCollection mapping_section = data["MAPPINGS"]; KeyDataCollection labels_section = data["LABELS"]; if (mapping_section.ContainsKey("START")) { mappings.Add(Types.ButtonFlags.START, new Action(readMapping(mapping_section, "START"), labels_section["START"])); } if (mapping_section.ContainsKey("BACK")) { mappings.Add(Types.ButtonFlags.BACK, new Action(mapping_section["BACK"], labels_section["BACK"])); } if (mapping_section.ContainsKey("A")) { mappings.Add(Types.ButtonFlags.A, new Action(mapping_section["A"], labels_section["A"])); } if (mapping_section.ContainsKey("B")) { mappings.Add(Types.ButtonFlags.B, new Action(mapping_section["B"], labels_section["B"])); } if (mapping_section.ContainsKey("X")) { mappings.Add(Types.ButtonFlags.X, new Action(readMapping(mapping_section, "X"), labels_section["X"])); } if (mapping_section.ContainsKey("Y")) { mappings.Add(Types.ButtonFlags.Y, new Action(mapping_section["Y"], labels_section["Y"])); } if (mapping_section.ContainsKey("LEFT_SHOULDER")) { mappings.Add(Types.ButtonFlags.LEFT_SHOULDER, new Action(mapping_section["LEFT_SHOULDER"], labels_section["LEFT_SHOULDER"])); } if (mapping_section.ContainsKey("RIGHT_SHOULDER")) { mappings.Add(Types.ButtonFlags.RIGHT_SHOULDER, new Action(mapping_section["RIGHT_SHOULDER"], labels_section["RIGHT_SHOULDER"])); } if (mapping_section.ContainsKey("DPAD_DOWN")) { mappings.Add(Types.ButtonFlags.DPAD_DOWN, new Action(mapping_section["DPAD_DOWN"], labels_section["DPAD_DOWN"])); } if (mapping_section.ContainsKey("DPAD_LEFT")) { mappings.Add(Types.ButtonFlags.DPAD_LEFT, new Action(mapping_section["DPAD_LEFT"], labels_section["DPAD_LEFT"])); } if (mapping_section.ContainsKey("DPAD_UP")) { mappings.Add(Types.ButtonFlags.DPAD_UP, new Action(mapping_section["DPAD_UP"], labels_section["DPAD_UP"])); } if (mapping_section.ContainsKey("DPAD_RIGHT")) { mappings.Add(Types.ButtonFlags.DPAD_RIGHT, new Action(mapping_section["DPAD_RIGHT"], labels_section["DPAD_RIGHT"])); } return(ProgramMapping.Build(name, program_regex_str, mappings)); }
public string?GetSetting(string name) { return(_settings.ContainsKey(name) ?_settings[name] : null); }
/// <summary> /// Adds a key to a concrete <see cref="KeyDataCollection"/> instance, checking /// if duplicate keys are allowed in the configuration /// </summary> /// <param name="key"> /// Key name /// </param> /// <param name="value"> /// Key's value /// </param> /// <param name="keyDataCollection"> /// <see cref="KeyData"/> collection where the key should be inserted /// </param> /// <param name="sectionName"> /// Name of the section where the <see cref="KeyDataCollection"/> is contained. /// Used only for logging purposes. /// </param> private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName) { // Check for duplicated keys if (keyDataCollection.ContainsKey(key)) { // We already have a key with the same name defined in the current section if (!Configuration.AllowDuplicateKeys) { throw new ParsingException(string.Format("Duplicated key '{0}' found in section '{1}", key, sectionName)); } else if(Configuration.OverrideDuplicateKeys) { keyDataCollection[key] = value; } } else { // Save the keys keyDataCollection.AddKey(key, value); } keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp; _currentCommentListTemp.Clear(); }