Esempio n. 1
0
        /// <summary>
        /// Parses the text.
        /// </summary>
        /// <param name="sr">stream to read</param>
        /// <returns></returns>
        public static IniData Deserialize(StreamReader sr)
        {
            var ini = new IniData();

            // 0 readsectionheader
            // 1 readsectiondata
            int    state = 0;
            string line;
            string sectionHeader             = null;
            Dictionary <string, string> data = new Dictionary <string, string>();

            for (int linecount = 1; (line = sr.ReadLine()) != null; linecount++)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }
                switch (state)
                {
                case 0:
                    sectionHeader = ReadSectionHeader(line);
                    state         = 1;
                    break;

                case 1:
                    if (line[0] == '[')
                    {
                        ini.AddSection(sectionHeader, data);
                        data          = new Dictionary <string, string>();
                        sectionHeader = ReadSectionHeader(line);
                    }
                    else
                    {
                        var valuePair = ReadValue(line);
                        data.Add(valuePair.Key, valuePair.Value);
                    }
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }
            ini.AddSection(sectionHeader, data);
            return(ini);
        }
Esempio n. 2
0
        /// <summary>
        /// Writes the settings into a file.
        /// </summary>
        /// <param name="filePath">Filepath of the settings file</param>
        public void Save(string filePath)
        {
            IniData ini = new IniData();

            foreach (var mapper in mappers)
            {
                ini.AddSection(mapper.Key, mapper.Value.ToDictionary());
            }
            Dictionary <string, string> generalSettings = new Dictionary <string, string>();

            generalSettings[LanguageKey]    = LanguageManager.Instance.Language;
            generalSettings[CloseToTrayKey] = CloseToTray ? "true" : "false";
            ini.AddSection(General, generalSettings);
            File.WriteAllText(filePath, ini.Serialize());
        }