Exemple #1
0
        public void ReadFromStream(TextReader sr)
        {
            Clear();
            PBXStream.ReadLinesWithConditionForLastLine(sr, m_Header, s => s.Trim() == "objects = {");

            string line = PBXStream.ReadSkippingEmptyLines(sr);

            string prevSectionName = null;

            while (PBXRegex.BeginSection.IsMatch(line))
            {
                string sectName = PBXRegex.BeginSection.Match(line).Groups[1].Value;

                // Duplicate sections (which should never appear) will be simply read again.
                if (m_Section.ContainsKey(sectName))
                {
                    m_Section[sectName].ReadSection(line, sr);
                }
                else
                {
                    SectionBase sect = new TextSection();
                    sect.ReadSection(line, sr);
                    m_Section.Add(sectName, sect);
                }

                // if the section is unknown, save its position relative to other sections
                if (!m_SectionOrder.Contains(sectName))
                {
                    int pos = 0;
                    if (prevSectionName != null)
                    {
                        pos  = m_SectionOrder.FindIndex(x => x == prevSectionName); // this never fails
                        pos += 1;
                    }

                    m_SectionOrder.Insert(pos, sectName);
                }
                line = PBXStream.ReadSkippingEmptyLines(sr);
            }

            m_Footer.Add(line);
            PBXStream.ReadLinesFromFile(sr, m_Footer);

            RefreshAuxMaps();
        }
        public override void ReadSection(string curLine, TextReader sr)
        {
            if (!PBXRegex.BeginSection.IsMatch(curLine))
            {
                throw new Exception("Can't read section");
            }
            if (PBXRegex.BeginSection.Match(curLine).Groups[1].Value != m_Name)
            {
                throw new Exception("Wrong section");
            }

            curLine = PBXStream.ReadSkippingEmptyLines(sr);
            while (!PBXRegex.EndSection.IsMatch(curLine))
            {
                T obj = new T();
                obj.ReadFromSection(curLine, sr);
                entry[obj.guid] = obj;

                curLine = sr.ReadLine();
            }
        }