public static DuplicatingIni ParseIni(string iniText)
        {
            DuplicatingIni di             = new DuplicatingIni();
            var            splits         = iniText.Split('\n');
            Section        currentSection = null;

            foreach (var line in splits)
            {
                string trimmed = line.Trim();
                if (string.IsNullOrWhiteSpace(trimmed))
                {
                    continue;                                     //blank line
                }
                if (trimmed.StartsWith("[") && trimmed.EndsWith("]"))
                {
                    //New section
                    currentSection = new Section()
                    {
                        Header = trimmed.Trim('[', ']')
                    };
                    di.Sections.Add(currentSection);
                }
                else if (currentSection == null)
                {
                    continue; //this parser only supports section items
                }
                else
                {
                    currentSection.Entries.Add(new IniEntry(trimmed));
                }
            }
            return(di);
        }
Пример #2
0
        public ME2Coalesced(string file)
        {
            Inputfile           = file;
            using FileStream fs = new FileStream(file, FileMode.Open);
            int unknownInt = fs.ReadInt32();

            if (unknownInt != 0x1E)
            {
                throw new Exception("First 4 bytes were not 0x1E (was " + unknownInt.ToString("X8") + ").This does not appear to be a Coalesced file.");
            }

            while (fs.Position < fs.Length)
            {
                long   pos      = fs.Position;
                string filename = fs.ReadUnrealString();
                string contents = fs.ReadUnrealString();
                Inis[filename] = DuplicatingIni.ParseIni(contents);
            }
        }