public static List <ConfigRow> ParseConfig(string FileName) { string Text = File.ReadAllText(FileName, Encoding.Default); if (Text == null) { return(null); } List <ConfigRow> Rows = new List <ConfigRow>(); string[] Lines = StrHelper.Explode("\n", Text); for (int i = 0; i < Lines.Length; i++) { ConfigRow CurrentRow = ParseConfigRow(Lines[i]); if (CurrentRow != null) { if (CurrentRow.Key == "+include") { string IncludeFile = FileName; IncludeFile = IncludeFile.Substring(0, IncludeFile.LastIndexOf(@"\")) + @"\" + CurrentRow.Fields[0]; List <ConfigRow> Include = ParseConfig(IncludeFile); if (Include != null) { Rows.AddRange(Include); } } else { Rows.Add(CurrentRow); } } } return(Rows); }
public void ParseConfigRow(ConfigRow Row) { if (Row.Fields.Count == 2) { Row.Fields.Add(""); } SettingType SType = SettingType.SETTING_RESERVED; object SValue = null; switch (Row.Fields[1]) { case "INT": SType = SettingType.SETTING_INT; SValue = int.Parse(Row.Fields[2]); break; case "FLOAT": SType = SettingType.SETTING_FLOAT; SValue = double.Parse(Row.Fields[2]); break; case "BOOLEAN": SType = SettingType.SETTING_BOOLEAN; SValue = bool.Parse(Row.Fields[2].ToLower()); break; case "STRING": SType = SettingType.SETTING_STRING; SValue = Row.Fields[2]; break; case "FILEPATH": SType = SettingType.SETTING_FILEPATH; SValue = Row.Fields[2]; break; } Register(Row.Key, Row.Fields[0], SType, SValue, bool.Parse(Row.Fields[3])); }