public CtfEditorGamePage(System.IO.Stream fileStream, CtfEditorMainTabs _parentTab)
        {
            using (fileStream)
            {
                XmlDocument ctfSchema = new XmlDocument();
                ctfSchema.Load(fileStream);

                if (ctfSchema.DocumentElement is null)
                {
                    throw new InvalidDataException("The ctf schema does not have a root element.");
                }

                filterIndex = GetFilterIndex(ctfSchema.DocumentElement.GetAttribute("extension"));
                Int32.TryParse(ctfSchema.DocumentElement.GetAttribute("line"), out lineIndex);
                parentTab = _parentTab;

                ctfEntryInfo = new CtfEntryInfo[ctfSchema.DocumentElement.ChildNodes.Count];
                int i = 0;
                foreach (XmlElement entry in ctfSchema.DocumentElement.ChildNodes)
                {
                    ctfEntryInfo[i] = new CtfEntryInfo(i, entry);
                    i++;
                }

                files = new List <PerformanceFile>();
            }
        }
Example #2
0
        public CtfFile(string _fileName, System.IO.Stream fileStream, CtfEditorGamePage _page)
            : base(_fileName, fileStream, _page)
        {
            int flag = -1;

            using (CtfBinaryReader reader = new CtfBinaryReader(EndianBitConverter.Little, fileStream))
            {
                foreach (CtfEntryInfo entryInfo in parentPage.ctfEntryInfo)
                {
                    try
                    {
                        if (entryInfo.name == "magic")
                        {
                            entry.Add(entryInfo.id, reader.ReadInt32());
                        }
                        else if (entryInfo.name == "flag")
                        {
                            entry.Add(entryInfo.id, reader.ReadInt32());
                            flag = (int)entry[entryInfo.id];
                        }
                        else if (entryInfo.IsUsed(flag))
                        {
                            if (entryInfo.linkID != -1)
                            {
                                CtfEntryInfo linkedEntryInfo = parentPage.ctfEntryInfo.First(x => x.refID == entryInfo.linkID);
                                if (Convert.ToBoolean(entry[linkedEntryInfo.id]))
                                {
                                    entry.Add(entryInfo.id, reader.ReadEntryData(entryInfo.type));
                                }
                            }
                            else
                            {
                                entry.Add(entryInfo.id, reader.ReadEntryData(entryInfo.type));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message + Environment.NewLine + entryInfo.id + " " + entryInfo.name);
                    }
                }
                CtfEntryInfo last = parentPage.ctfEntryInfo.Last(x => x.minFlag == 0);
                if (!entry.ContainsKey(last.id))
                {
                    throw new Exception("Reader did not read last required value");
                }
                // Use -1 For Dirt 3, hopefully won't cause problems with other games
                //System.Windows.Forms.MessageBox.Show(reader.BaseStream.Position + " " + reader.BaseStream.Length);
                if (reader.BaseStream.Position < reader.BaseStream.Length - 1)
                {
                    throw new Exception("Reader did not reach end of file!");
                }

                parentPage.files.Add(this);
            }
        }
        public CtfEditorGamePage(System.IO.Stream fileStream, CtfEditorMainTabs _parentTab)
        {
            using (fileStream)
            {
                XmlDocument ctfSchema = new XmlDocument();
                ctfSchema.Load(fileStream);
                filterIndex = GetFilterIndex(ctfSchema.DocumentElement.GetAttribute("extension"));
                Int32.TryParse(ctfSchema.DocumentElement.GetAttribute("line"), out lineIndex);
                parentTab = _parentTab;

                ctfEntryInfo = new CtfEntryInfo[ctfSchema.DocumentElement.ChildNodes.Count];
                int i = 0;
                foreach (XmlElement entry in ctfSchema.DocumentElement.ChildNodes)
                {
                    ctfEntryInfo[i] = new CtfEntryInfo(i, entry);
                    i++;
                }

                files = new List<PerformanceFile>();
            }
        }