public static IniFile Read(Stream stream) { StreamReader reader = new StreamReader(stream); SectionDict sections = new SectionDict(); IniDict section = null; string key, val, line; int index; string sectionKey = ""; while ((line = reader.ReadLine()) != null) { // strip off comments if ((index = line.IndexOf(';')) != -1) { line = line.Substring(0, index); } // strip off white spaces line = line.Trim(); // skip empty lines if (line.Length == 0) { continue; } // start of section if (line[0] == '[') { if ((index = line.IndexOf(']')) == -1) { continue; } sectionKey = line.Substring(1, index - 1); section = new OrderedDictionary <string, string>(); if (!sections.ContainsKey(sectionKey)) { sections.Add(sectionKey, section); } } // key=value pair else if (section != null) { if ((index = line.IndexOf('=')) == -1) { continue; } key = line.Substring(0, index).Trim(); val = line.Substring(index + 1).Trim(); // the game always chooses the first duplicate key entry if (!section.Contains(key)) { section[key] = val; } } } return(new IniFile(sections)); }
private IniFile(SectionDict sections) { this.sections = sections; }