Example #1
0
        public static Settings Load(string path)
        {
            Settings settings     = new Settings();
            SettingsFormat format = SettingsFormat.Load(path);

            format.DeserializeProps(settings);
            settings.settingsBinary = format;

            return(settings);
        }
Example #2
0
        public void Save(string path)
        {
            if (settingsBinary == null)
            {
                settingsBinary = new SettingsFormat();
            }

            settingsBinary.SerializeProps(this);
            File.WriteAllText(path, settingsBinary.Write());
        }
Example #3
0
        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);
        }