예제 #1
0
        /// <summary>Reads a INI file from a file or creates one.</summary>
        public static IniFileEx FromFile(string path)
        {
            if (!File.Exists(path))
            {
                File.Create(path).Close();
                return(new IniFileEx());
            }

            using (StreamReader reader = new StreamReader(path)) {
                IniFileEx ret = FromStream(reader);
                return(ret);
            }
        }
예제 #2
0
        /// <summary>Reads a INI file from a stream.</summary>
        public static IniFileEx FromStream(StreamReader reader)
        {
            IEnumerable <IniFileElement> elemes = ParseText(reader);

            IniFileEx ret = new IniFileEx();

            ret.elements.AddRange(elemes);
            if (ret.elements.Count > 0)
            {
                IniFileSection section = null;

                if (ret.elements[ret.elements.Count - 1] is IniFileBlankLine)
                {
                    ret.elements.RemoveAt(ret.elements.Count - 1);
                }

                for (int i = 0; i < ret.elements.Count; i++)
                {
                    IniFileElement el = ret.elements[i];
                    if (el is IniFileSectionStart)
                    {
                        section = new IniFileSection(ret, (IniFileSectionStart)el);
                        ret.sections.Add(section);
                    }
                    else if (section != null)
                    {
                        section.elements.Add(el);
                    }
                    else if (ret.sections.Exists(delegate(IniFileSection a) { return(a.Name == ""); }))
                    {
                        ret.sections[0].elements.Add(el);
                    }
                    else if (el is IniFileValue)
                    {
                        section = new IniFileSection(ret, IniFileSectionStart.FromName(""));
                        section.elements.Add(el);
                        ret.sections.Add(section);
                    }
                }
            }
            return(ret);
        }
예제 #3
0
 internal IniFileSection(IniFileEx _parent, IniFileSectionStart sect)
 {
     sectionStart = sect;
     parent       = _parent;
 }