private void updateSettingsSection() { for (string prop : configs) { IniItem item = settings.getItem(prop); item.setValue(getProperty(prop)); } }
/// <summary> /// Read all lines from the given text reader, parse and generate INI objects such as /// section, properties, comments and blank lines. /// </summary> /// <param name="reader">The <see cref="TextReader"/> instance to read the INI lines from.</param> /// <returns></returns> private static IEnumerable <IniItem> ParseLines(TextReader reader) { // These variables track multiline values Property mlProperty = null; var mlValue = new StringBuilder(); string mlEot = null; for (string line = reader.ReadLine(); line != null; line = reader.ReadLine()) { // Are we in the middle of a multi-line property value? // If so, continue adding the line strings to the mlValue variable until the EOT // string is found. if (mlProperty != null) { // Have we reached the end of the multi-line value (end-of-text)? if (line.Trim() == mlEot) // EOT is case-sensitive { mlProperty.Value = mlValue.ToString(); mlProperty = null; } else { if (mlValue.Length > 0) { mlValue.AppendLine(); } mlValue.Append(line); } } else { IniItem iniItem = IniItemFactory.CreateItem(line); if (iniItem is Property property) { // If the property value matches the start of a multiline value, enable multiline // mode (mlProperty != null) and add all subsequent lines until the end-of-text // marker is found. Match match = MultilineStartPattern.Match(property.Value); if (match.Success) { // Start tracking the multiline value until we encounter an end-of-text (EOT) line mlProperty = property; #if NET35 mlValue = new StringBuilder(); #else mlValue.Clear(); #endif mlEot = match.Groups[1].Value; } } yield return(iniItem); } } }
/// <summary> /// Creates the correct <see cref="IniItem"/> object from the given line. If the line /// does not match any INI item object, an exception is thrown. /// </summary> /// <param name="line">A line from the INI file.</param> /// <returns>The <see cref="IniItem"/> object that matches the line format.</returns> internal static IniItem CreateItem(string line) { IniItem item = TryCreateProperty(line) ?? TryCreateSection(line) ?? TryCreateComment(line) ?? TryCreateBlankLine(line); if (item != null) { return(item); } throw new FormatException(string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnrecognizedLine, line)); }
private void initSettingsSection() { settings = ini.getSection("SETTINGS"); if (settings == null) { settings = ini.addSection("SETTINGS"); } autoSave = false; for (string prop : configs) { IniItem item = settings.getItem(prop); if (item != null) { changeProperty(prop, Float.parseFloat(item.getValue())); } else { settings.addItem(prop).setValue(getProperty(prop)); } } autoSave = true; }
/// <summary> /// Loads the configuration file. /// </summary> private void Load() { IniConfig config = null; IniSection section = null; IniItem item = null; for (int j = 0; j < iniDocument.Sections.Count; j++) { section = iniDocument.Sections[j]; config = new IniConfig(section.Name, this); for (int i = 0; i < section.ItemCount; i++) { item = section.GetItem(i); if (item.Type == IniType.Key) { config.Add(item.Name, item.Value); } } this.Configs.Add(config); } }