Пример #1
0
        /// <summary>
        /// Adds a new section to the inifile.
        /// </summary>
        /// <param name="sectionName">The section name.</param>
        /// <returns>The newly created section.</returns>
        public IniFile.IniFileSection AddSection(string sectionName)
        {
            var section = new IniFile.IniFileSection(sectionName);

            sections.Add(section.Name, section);

            return(section);
        }
Пример #2
0
        /// <summary>
        /// Opens the ini file.
        /// </summary>
        public void Open()
        {
            var lines = File.ReadAllLines(FileName);

            GlobalSection = new IniFile.IniFileSection(string.Empty);
            IniFileSection CurrentSection = GlobalSection;

            foreach (var line in lines)
            {
                if (!string.IsNullOrWhiteSpace(line))
                {
                    if (line.Contains("="))
                    {
                        var split = line.IndexOf('=');
                        var key   = line.Substring(0, split);
                        var value = line.Substring(split + 1);

                        CurrentSection.SetValue <string>(key, value);
                    }
                    else if (line.StartsWith("[") && line.EndsWith("]"))
                    {
                        var name = line.Substring(1, line.Length - 2);

                        if (string.IsNullOrWhiteSpace(name))
                        {
                            continue;
                        }

                        CurrentSection = new IniFile.IniFileSection(name);
                        sections.Add(CurrentSection.Name, CurrentSection);
                    }
                }
            }

            foreach (var section in Sections)
            {
                section.UpdateFormats(GlobalSection);
            }

            GlobalSection.UpdateFormats(null);
        }