public string GenerateText() { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < this.m_lines.Count; i++) { ConfigFile.Line line = this.m_lines[i]; ConfigFile.LineType type = line.m_type; if (type != ConfigFile.LineType.SECTION) { if (type != ConfigFile.LineType.ENTRY) { stringBuilder.Append(line.m_raw); } else if (line.m_quoteValue) { stringBuilder.AppendFormat("{0} = \"{1}\"", line.m_lineKey, line.m_value); } else { stringBuilder.AppendFormat("{0} = {1}", line.m_lineKey, line.m_value); } } else { stringBuilder.AppendFormat("[{0}]", line.m_sectionName); } stringBuilder.AppendLine(); } return(stringBuilder.ToString()); }
public float Get(string key, float defaultVal = 0f) { ConfigFile.Line line = this.FindEntry(key); if (line == null) { return(defaultVal); } return(GeneralUtils.ForceFloat(line.m_value)); }
public string Get(string key, string defaultVal = "") { ConfigFile.Line line = this.FindEntry(key); if (line == null) { return(defaultVal); } return(line.m_value); }
public bool Get(string key, bool defaultVal = false) { ConfigFile.Line line = this.FindEntry(key); if (line == null) { return(defaultVal); } return(GeneralUtils.ForceBool(line.m_value)); }
public bool Set(string key, string val) { ConfigFile.Line line = this.RegisterEntry(key); if (line == null) { return(false); } line.m_value = val; return(true); }
public bool Delete(string key, bool removeEmptySections = true) { int num = this.FindEntryIndex(key); if (num < 0) { return(false); } this.m_lines.RemoveAt(num); if (removeEmptySections) { int num1 = num - 1; while (num1 >= 0) { ConfigFile.Line item = this.m_lines[num1]; if (item.m_type != ConfigFile.LineType.SECTION) { if (!string.IsNullOrEmpty(item.m_raw.Trim())) { return(true); } num1--; } else { break; } } int num2 = num; while (num2 < this.m_lines.Count) { ConfigFile.Line line = this.m_lines[num2]; if (line.m_type != ConfigFile.LineType.SECTION) { if (!string.IsNullOrEmpty(line.m_raw.Trim())) { return(true); } num2++; } else { break; } } this.m_lines.RemoveRange(num1, num2 - num1); } return(true); }
private int FindSectionIndex(string sectionName) { for (int i = 0; i < this.m_lines.Count; i++) { ConfigFile.Line line = this.m_lines[i]; if (line.m_type == ConfigFile.LineType.SECTION) { if (line.m_sectionName.Equals(sectionName, StringComparison.OrdinalIgnoreCase)) { return(i); } } } return(-1); }
private int FindEntryIndex(string fullKey) { for (int i = 0; i < this.m_lines.Count; i++) { ConfigFile.Line line = this.m_lines[i]; if (line.m_type == ConfigFile.LineType.ENTRY) { if (line.m_fullKey.Equals(fullKey, StringComparison.OrdinalIgnoreCase)) { return(i); } } } return(-1); }
private int FindEntryIndex(string fullKey) { for (int i = 0; i < this.m_lines.get_Count(); i++) { ConfigFile.Line line = this.m_lines.get_Item(i); if (line.m_type == ConfigFile.LineType.ENTRY) { if (line.m_fullKey.Equals(fullKey, 5)) { return(i); } } } return(-1); }
private int FindSectionIndex(string sectionName) { for (int i = 0; i < this.m_lines.get_Count(); i++) { ConfigFile.Line line = this.m_lines.get_Item(i); if (line.m_type == ConfigFile.LineType.SECTION) { if (line.m_sectionName.Equals(sectionName, 5)) { return(i); } } } return(-1); }
private bool LoadConfig(string path) { ConfigFile configFile = new ConfigFile(); if (!configFile.LightLoad(path)) { return(false); } using (List <ConfigFile.Line> .Enumerator enumerator = configFile.GetLines().GetEnumerator()) { while (enumerator.MoveNext()) { ConfigFile.Line current = enumerator.get_Current(); this.m_vars.set_Item(current.m_fullKey, current.m_value); } } return(true); }
public bool Delete(string key, bool removeEmptySections = true) { int num = this.FindEntryIndex(key); if (num < 0) { return(false); } this.m_lines.RemoveAt(num); if (removeEmptySections) { int i; for (i = num - 1; i >= 0; i--) { ConfigFile.Line line = this.m_lines.get_Item(i); if (line.m_type == ConfigFile.LineType.SECTION) { break; } string text = line.m_raw.Trim(); if (!string.IsNullOrEmpty(text)) { return(true); } } int j; for (j = num; j < this.m_lines.get_Count(); j++) { ConfigFile.Line line2 = this.m_lines.get_Item(j); if (line2.m_type == ConfigFile.LineType.SECTION) { break; } string text2 = line2.m_raw.Trim(); if (!string.IsNullOrEmpty(text2)) { return(true); } } int num2 = j - i; this.m_lines.RemoveRange(i, num2); } return(true); }
public bool Delete(string key, bool removeEmptySections = true) { int num = this.FindEntryIndex(key); if (num < 0) { return(false); } this.m_lines.RemoveAt(num); if (removeEmptySections) { int i; for (i = num - 1; i >= 0; i--) { ConfigFile.Line line = this.m_lines[i]; if (line.m_type == ConfigFile.LineType.SECTION) { break; } string value = line.m_raw.Trim(); if (!string.IsNullOrEmpty(value)) { return(true); } } int j; for (j = num; j < this.m_lines.Count; j++) { ConfigFile.Line line2 = this.m_lines[j]; if (line2.m_type == ConfigFile.LineType.SECTION) { break; } string value2 = line2.m_raw.Trim(); if (!string.IsNullOrEmpty(value2)) { return(true); } } int count = j - i; this.m_lines.RemoveRange(i, count); } return(true); }
public bool Has(string key) { ConfigFile.Line line = this.FindEntry(key); return(line != null); }
private bool Load(string path, bool ignoreUselessLines) { this.m_path = null; this.m_lines.Clear(); if (!File.Exists(path)) { Debug.LogError("Error loading config file " + path); return false; } int num = 1; using (StreamReader streamReader = File.OpenText(path)) { string text = string.Empty; while (streamReader.Peek() != -1) { string text2 = streamReader.ReadLine(); string text3 = text2.Trim(); if (!ignoreUselessLines || text3.Length > 0) { bool flag = text3.Length > 0 && text3[0] == ';'; if (!ignoreUselessLines || !flag) { ConfigFile.Line line = new ConfigFile.Line(); line.m_raw = text2; line.m_sectionName = text; if (flag) { line.m_type = ConfigFile.LineType.COMMENT; } else if (text3.Length > 0) { if (text3[0] == '[') { if (text3.Length < 2 || text3[text3.Length - 1] != ']') { Debug.LogWarning(string.Format("ConfigFile.Load() - invalid section \"{0}\" on line {1} in file {2}", text2, num, path)); if (!ignoreUselessLines) { this.m_lines.Add(line); } continue; } line.m_type = ConfigFile.LineType.SECTION; text = (line.m_sectionName = text3.Substring(1, text3.Length - 2)); this.m_lines.Add(line); continue; } else { int num2 = text3.IndexOf('='); if (num2 < 0) { Debug.LogWarning(string.Format("ConfigFile.Load() - invalid entry \"{0}\" on line {1} in file {2}", text2, num, path)); if (!ignoreUselessLines) { this.m_lines.Add(line); } continue; } string text4 = text3.Substring(0, num2).Trim(); string text5 = text3.Substring(num2 + 1, text3.Length - num2 - 1).Trim(); if (text5.Length > 2) { int index = text5.Length - 1; if ((text5[0] == '"' || text5[0] == '“' || text5[0] == '”') && (text5[index] == '"' || text5[index] == '“' || text5[index] == '”')) { text5 = text5.Substring(1, text5.Length - 2); line.m_quoteValue = true; } } line.m_type = ConfigFile.LineType.ENTRY; line.m_fullKey = string.Format("{0}.{1}", text, text4); line.m_lineKey = text4; line.m_value = text5; } } this.m_lines.Add(line); } } } } this.m_path = path; return true; }
private ConfigFile.Line RegisterEntry(string fullKey) { if (string.IsNullOrEmpty(fullKey)) { return(null); } int num = fullKey.IndexOf('.'); if (num < 0) { return(null); } string sectionName = fullKey.Substring(0, num); string text = string.Empty; if (fullKey.Length > num + 1) { text = fullKey.Substring(num + 1, fullKey.Length - num - 1); } ConfigFile.Line line = null; int num2 = this.FindSectionIndex(sectionName); if (num2 < 0) { ConfigFile.Line line2 = new ConfigFile.Line(); if (this.m_lines.Count > 0) { line2.m_sectionName = this.m_lines[this.m_lines.Count - 1].m_sectionName; } this.m_lines.Add(line2); ConfigFile.Line line3 = new ConfigFile.Line(); line3.m_type = ConfigFile.LineType.SECTION; line3.m_sectionName = sectionName; this.m_lines.Add(line3); line = new ConfigFile.Line(); line.m_type = ConfigFile.LineType.ENTRY; line.m_sectionName = sectionName; line.m_lineKey = text; line.m_fullKey = fullKey; this.m_lines.Add(line); } else { int i; for (i = num2 + 1; i < this.m_lines.Count; i++) { ConfigFile.Line line4 = this.m_lines[i]; if (line4.m_type == ConfigFile.LineType.SECTION) { break; } if (line4.m_type == ConfigFile.LineType.ENTRY) { if (line4.m_lineKey.Equals(text, StringComparison.OrdinalIgnoreCase)) { line = line4; break; } } } if (line == null) { line = new ConfigFile.Line(); line.m_type = ConfigFile.LineType.ENTRY; line.m_sectionName = sectionName; line.m_lineKey = text; line.m_fullKey = fullKey; this.m_lines.Insert(i, line); } } return(line); }
private bool Load(string path, bool ignoreUselessLines) { this.m_path = null; this.m_lines.Clear(); if (!File.Exists(path)) { Console.WriteLine(string.Concat("Error loading config file ", path)); return(false); } int num = 1; using (StreamReader streamReader = File.OpenText(path)) { string empty = string.Empty; while (streamReader.Peek() != -1) { string str = streamReader.ReadLine(); string str1 = str.Trim(); if (!ignoreUselessLines || str1.Length > 0) { bool flag = (str1.Length <= 0 ? false : str1[0] == ';'); if (!ignoreUselessLines || !flag) { ConfigFile.Line line = new ConfigFile.Line() { m_raw = str, m_sectionName = empty }; if (flag) { line.m_type = ConfigFile.LineType.COMMENT; } else if (str1.Length > 0) { if (str1[0] != '[') { int num1 = str1.IndexOf('='); if (num1 >= 0) { string str2 = str1.Substring(0, num1).Trim(); string str3 = str1.Substring(num1 + 1, str1.Length - num1 - 1).Trim(); if (str3.Length > 2) { int length = str3.Length - 1; if ((str3[0] == '\"' || str3[0] == '“' || str3[0] == '”') && (str3[length] == '\"' || str3[length] == '“' || str3[length] == '”')) { str3 = str3.Substring(1, str3.Length - 2); line.m_quoteValue = true; } } line.m_type = ConfigFile.LineType.ENTRY; line.m_fullKey = string.Format("{0}.{1}", empty, str2); line.m_lineKey = str2; line.m_value = str3; } else { Console.WriteLine(string.Format("ConfigFile.Load() - invalid entry \"{0}\" on line {1} in file {2}", str, num, path)); if (!ignoreUselessLines) { this.m_lines.Add(line); } continue; } } else if (str1.Length < 2 || str1[str1.Length - 1] != ']') { Console.WriteLine(string.Format("ConfigFile.Load() - invalid section \"{0}\" on line {1} in file {2}", str, num, path)); if (!ignoreUselessLines) { this.m_lines.Add(line); } continue; } else { line.m_type = ConfigFile.LineType.SECTION; string str4 = str1.Substring(1, str1.Length - 2); empty = str4; line.m_sectionName = str4; this.m_lines.Add(line); continue; } } this.m_lines.Add(line); } } } } this.m_path = path; return(true); }
private ConfigFile.Line RegisterEntry(string fullKey) { if (string.IsNullOrEmpty(fullKey)) { return(null); } int num = fullKey.IndexOf('.'); if (num < 0) { return(null); } string str = fullKey.Substring(0, num); string empty = string.Empty; if (fullKey.Length > num + 1) { empty = fullKey.Substring(num + 1, fullKey.Length - num - 1); } ConfigFile.Line line = null; int num1 = this.FindSectionIndex(str); if (num1 >= 0) { int num2 = num1 + 1; while (num2 < this.m_lines.Count) { ConfigFile.Line item = this.m_lines[num2]; if (item.m_type != ConfigFile.LineType.SECTION) { if (item.m_type == ConfigFile.LineType.ENTRY) { if (item.m_lineKey.Equals(empty, StringComparison.OrdinalIgnoreCase)) { line = item; break; } } num2++; } else { break; } } if (line == null) { line = new ConfigFile.Line() { m_type = ConfigFile.LineType.ENTRY, m_sectionName = str, m_lineKey = empty, m_fullKey = fullKey }; this.m_lines.Insert(num2, line); } } else { ConfigFile.Line mSectionName = new ConfigFile.Line(); if (this.m_lines.Count > 0) { mSectionName.m_sectionName = this.m_lines[this.m_lines.Count - 1].m_sectionName; } this.m_lines.Add(mSectionName); ConfigFile.Line line1 = new ConfigFile.Line() { m_type = ConfigFile.LineType.SECTION, m_sectionName = str }; this.m_lines.Add(line1); line = new ConfigFile.Line() { m_type = ConfigFile.LineType.ENTRY, m_sectionName = str, m_lineKey = empty, m_fullKey = fullKey }; this.m_lines.Add(line); } return(line); }
private bool Load(string path, bool ignoreUselessLines) { this.m_path = null; this.m_lines.Clear(); if (!File.Exists(path)) { Console.WriteLine("Error loading config file " + path); return(false); } int num = 1; using (StreamReader streamReader = File.OpenText(path)) { string text = string.Empty; while (streamReader.Peek() != -1) { string text2 = streamReader.ReadLine(); string text3 = text2.Trim(); if (!ignoreUselessLines || text3.Length > 0) { bool flag = text3.Length > 0 && text3[0] == ';'; if (!ignoreUselessLines || !flag) { ConfigFile.Line line = new ConfigFile.Line(); line.m_raw = text2; line.m_sectionName = text; if (flag) { line.m_type = ConfigFile.LineType.COMMENT; } else if (text3.Length > 0) { if (text3[0] == '[') { if (text3.Length < 2 || text3[text3.Length - 1] != ']') { Console.WriteLine(string.Format("ConfigFile.Load() - invalid section \"{0}\" on line {1} in file {2}", text2, num, path)); if (!ignoreUselessLines) { this.m_lines.Add(line); } continue; } line.m_type = ConfigFile.LineType.SECTION; text = (line.m_sectionName = text3.Substring(1, text3.Length - 2)); this.m_lines.Add(line); continue; } else { int num2 = text3.IndexOf('='); if (num2 < 0) { Console.WriteLine(string.Format("ConfigFile.Load() - invalid entry \"{0}\" on line {1} in file {2}", text2, num, path)); if (!ignoreUselessLines) { this.m_lines.Add(line); } continue; } string text4 = text3.Substring(0, num2).Trim(); string text5 = text3.Substring(num2 + 1, text3.Length - num2 - 1).Trim(); if (text5.Length > 2) { int index = text5.Length - 1; if ((text5[0] == '"' || text5[0] == '“' || text5[0] == '”') && (text5[index] == '"' || text5[index] == '“' || text5[index] == '”')) { text5 = text5.Substring(1, text5.Length - 2); line.m_quoteValue = true; } } line.m_type = ConfigFile.LineType.ENTRY; line.m_fullKey = string.Format("{0}.{1}", text, text4); line.m_lineKey = text4; line.m_value = text5; } } this.m_lines.Add(line); } } } } this.m_path = path; return(true); }
private ConfigFile.Line RegisterEntry(string fullKey) { if (string.IsNullOrEmpty(fullKey)) return (ConfigFile.Line) null; int length = fullKey.IndexOf('.'); if (length < 0) return (ConfigFile.Line) null; string sectionName = fullKey.Substring(0, length); string str = string.Empty; if (fullKey.Length > length + 1) str = fullKey.Substring(length + 1, fullKey.Length - length - 1); ConfigFile.Line line1 = (ConfigFile.Line) null; int sectionIndex = this.FindSectionIndex(sectionName); if (sectionIndex < 0) { ConfigFile.Line line2 = new ConfigFile.Line(); if (this.m_lines.Count > 0) line2.m_sectionName = this.m_lines[this.m_lines.Count - 1].m_sectionName; this.m_lines.Add(line2); this.m_lines.Add(new ConfigFile.Line() { m_type = ConfigFile.LineType.SECTION, m_sectionName = sectionName }); line1 = new ConfigFile.Line(); line1.m_type = ConfigFile.LineType.ENTRY; line1.m_sectionName = sectionName; line1.m_lineKey = str; line1.m_fullKey = fullKey; this.m_lines.Add(line1); } else { int index; for (index = sectionIndex + 1; index < this.m_lines.Count; ++index) { ConfigFile.Line line2 = this.m_lines[index]; if (line2.m_type != ConfigFile.LineType.SECTION) { if (line2.m_type == ConfigFile.LineType.ENTRY && line2.m_lineKey.Equals(str, StringComparison.OrdinalIgnoreCase)) { line1 = line2; break; } } else break; } if (line1 == null) { line1 = new ConfigFile.Line(); line1.m_type = ConfigFile.LineType.ENTRY; line1.m_sectionName = sectionName; line1.m_lineKey = str; line1.m_fullKey = fullKey; this.m_lines.Insert(index, line1); } } return line1; }