public static Settings Load(string path) { Settings settings = new Settings(); SettingsFormat format = SettingsFormat.Load(path); format.DeserializeProps(settings); settings.settingsBinary = format; return(settings); }
public void Save(string path) { if (settingsBinary == null) { settingsBinary = new SettingsFormat(); } settingsBinary.SerializeProps(this); File.WriteAllText(path, settingsBinary.Write()); }
public static SettingsFormat Load(string path) { SettingsFormat format = new SettingsFormat(); int lineNum = 0; using (StringReader reader = new StringReader(File.ReadAllText(path))) { string line; while ((line = reader.ReadLine()) != null) { string[] split = line.Split(','); if (split.Length != 3 && split.Length != 0) { throw new InvalidDataException($"SettingsFormat.Load: invalid number of arguments on line {lineNum}"); } if (split.Length == 0) { lineNum++; continue; } SettingsFormatEntry.SettingsValueType type; if (!Enum.TryParse(split[1].Trim(), out type)) { type = SettingsFormatEntry.SettingsValueType.NotDefined; } if (type == SettingsFormatEntry.SettingsValueType.NotDefined) { SettingsFormatEntry entry = new SettingsFormatEntry(split[0].Trim(), split[1].Trim(), split[2].Trim()); format.Entries.Add(entry); } else { SettingsFormatEntry entry = new SettingsFormatEntry(split[0].Trim(), type, ParseValue(type, split[2].Trim())); format.Entries.Add(entry); } lineNum++; } } return(format); }