コード例 #1
0
        /// <summary>
        /// Initializes the Structure from a BinaryReader
        /// </summary>
        /// <param name="reader">The Reader representing the Package File</param>
        /// <remarks>Reader must be on the correct Position since no Positioning is performed</remarks>
        internal void Load(BinaryReader reader)
        {
            //this.id = new char[4];
            for (uint i = 0; i < this.id.Length; i++)
            {
                this.id[i] = reader.ReadChar();
            }
            if (!Helper.AnyPackage && Identifier != "DBPF")
            {
                throw new InvalidOperationException("SimPe does not support this type of file." + spore);
            }

            this.majorversion = reader.ReadInt32();
            if (!Helper.AnyPackage && this.majorversion > 1)
            {
                throw new InvalidOperationException("SimPe does not support this version of DBPF file." + spore);
            }

            this.minorversion = reader.ReadInt32();

            //this.reserved_00 = new Int32[3];
            for (uint i = 0; i < this.reserved_00.Length; i++)
            {
                this.reserved_00[i] = reader.ReadInt32();
            }

            this.created  = reader.ReadUInt32();
            this.modified = reader.ReadInt32();


            this.index.type = reader.ReadInt32();
            if (!lidl)
            {
                this.index.count  = reader.ReadInt32();
                this.index.offset = reader.ReadUInt32();
                this.index.size   = reader.ReadInt32();
            }
            else
            {
                reader.ReadInt32(); reader.ReadInt32(); reader.ReadInt32();                 //count, offset, size
            }

            this.hole.count  = reader.ReadInt32();
            this.hole.offset = reader.ReadUInt32();
            this.hole.size   = reader.ReadInt32();

            if (IsVersion0101)
            {
                this.indextype = (Data.MetaData.IndexTypes)reader.ReadUInt32();
            }

            //this.reserved_02 = new Int32[8];
            for (uint i = 0; i < this.reserved_02.Length; i++)
            {
                this.reserved_02[i] = reader.ReadInt32();
            }
        }
コード例 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 public ClstItem(SimPe.Interfaces.Files.IPackedFileDescriptor pfd, Data.MetaData.IndexTypes format)
 {
     this.format = format;
     if (pfd != null)
     {
         this.Type     = pfd.Type;
         this.Instance = pfd.Instance;
         this.SubType  = pfd.SubType;
         this.Group    = pfd.Group;
     }
 }
コード例 #3
0
        /// <summary>
        /// Unserializes a BinaryStream into the Attributes of this Instance
        /// </summary>
        /// <param name="reader">The Stream that contains the FileData</param>
        internal void Serialize(System.IO.BinaryWriter writer, Data.MetaData.IndexTypes format)
        {
            this.format = format;

            writer.Write(type);
            writer.Write(group);
            writer.Write(instance);
            if (format == Data.MetaData.IndexTypes.ptLongFileIndex)
            {
                writer.Write(subtype);
            }
            writer.Write(uncsize);
        }
コード例 #4
0
        /// <summary>
        /// Unserializes a BinaryStream into the Attributes of this Instance
        /// </summary>
        /// <param name="reader">The Stream that contains the FileData</param>
        protected override void Unserialize(System.IO.BinaryReader reader)
        {
            this.IndexType = package.Header.IndexType;
            long count = 0;

            if (iformat == Data.MetaData.IndexTypes.ptLongFileIndex)
            {
                count = reader.BaseStream.Length / 0x14;
            }
            else
            {
                count = reader.BaseStream.Length / 0x10;
            }
            items = new ClstItem[count];

            long pos      = reader.BaseStream.Position;
            bool switch_t = false;

            for (int i = 0; i < count; i++)
            {
                ClstItem item = new ClstItem(this.IndexType);
                item.Unserialize(reader);


                if ((i == 2) && (!switch_t))
                {
                    switch_t = true;
                    if (Package.FindFile(item.Type, item.SubType, item.Group, item.Instance) == null)
                    {
                        i = 0;
                        if (iformat == Data.MetaData.IndexTypes.ptLongFileIndex)
                        {
                            iformat = Data.MetaData.IndexTypes.ptShortFileIndex;
                        }
                        else
                        {
                            iformat = Data.MetaData.IndexTypes.ptLongFileIndex;
                        }

                        reader.BaseStream.Seek(pos, System.IO.SeekOrigin.Begin);
                        item = new ClstItem(this.IndexType);
                        item.Unserialize(reader);
                    }
                }

                items[i] = item;
            }
        }
コード例 #5
0
        /// <summary>
        /// Unserializes a BinaryStream into the Attributes of this Instance
        /// </summary>
        /// <param name="reader">The Stream that contains the FileData</param>
        protected override void Unserialize(System.IO.BinaryReader reader)
        {
            id   = reader.ReadUInt32();
            type = (Data.MetaData.IndexTypes)reader.ReadUInt32();

            items = new Interfaces.Files.IPackedFileDescriptor[reader.ReadUInt32()];

            for (int i = 0; i < items.Length; i++)
            {
                RefFileItem pfd = new RefFileItem(this);

                pfd.Type     = reader.ReadUInt32();
                pfd.Group    = reader.ReadUInt32();
                pfd.Instance = reader.ReadUInt32();
                if (type == Data.MetaData.IndexTypes.ptLongFileIndex)
                {
                    pfd.SubType = reader.ReadUInt32();
                }

                /*Interfaces.Files.IPackedFileDescriptor ppfd = Package.FindFile(pfd.Type, pfd.SubType, pfd.Group, pfd.Instance);
                 * if (ppfd!=null) items[i]=ppfd;
                 * else*/items[i] = pfd;
            }
        }
コード例 #6
0
        /// <summary>
        /// Creates a Package File from a previously extracted Package
        /// </summary>
        /// <param name="filename">Filename of package.xml File describing the Package</param>
        /// <param name="pb">A Progressbar indicating the progress</param>
        /// <returns>Binary Reader representing the Package File</returns>
        public static System.IO.BinaryReader OpenExtractedPackage(ProgressBar pb, string filename)
        {
            string path = System.IO.Path.GetDirectoryName(filename);

            System.Xml.XmlDocument xmlfile = new XmlDocument();
            xmlfile.Load(filename);

            //Root Node suchen
            XmlNodeList XMLData = xmlfile.GetElementsByTagName("package");

            ArrayList list = new ArrayList();

            //Alle Eintr&auml;ge im Root Node verarbeiten
            Data.MetaData.IndexTypes type = Data.MetaData.IndexTypes.ptShortFileIndex;
            for (int i = 0; i < XMLData.Count; i++)
            {
                XmlNode node = XMLData.Item(i);

                object o = node.Attributes["type"].Value; if (o == null)
                {
                    o = "1";
                }
                type = (Data.MetaData.IndexTypes) uint.Parse(o.ToString());

                if (pb != null)
                {
                    pb.Maximum = node.ChildNodes.Count;
                }
                int count = 0;
                foreach (XmlNode subnode in node)
                {
                    if (pb != null)
                    {
                        pb.Value = count++;
                        System.Windows.Forms.Application.DoEvents();
                    }
                    ///a New FileItem
                    if (subnode.LocalName == "packedfile")
                    {
                        list.Add(CreateDescriptor(path, subnode));
                    }
                }
            }

            SimPe.Packages.GeneratableFile file = SimPe.Packages.GeneratableFile.CreateNew();
            file.BeginUpdate();
            file.Header.IndexType = type;

            foreach (SimPe.Packages.PackedFileDescriptor pfd in list)
            {
                file.Add(pfd);
                if (pfd.Type == Packages.File.FILELIST_TYPE)
                {
                    file.FileList = pfd;
                }
            }

            System.IO.MemoryStream ms = file.Build();
            file.EndUpdate();
            if (pb != null)
            {
                pb.Value = pb.Maximum;
            }
            return(new System.IO.BinaryReader(ms));
        }
コード例 #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 public RefFile() : base()
 {
     items = new Interfaces.Files.IPackedFileDescriptor[0];
     id    = 0xDEADBEEF;
     type  = Data.MetaData.IndexTypes.ptLongFileIndex;
 }
コード例 #8
0
 /// <summary>
 /// Constructor, Initializes the Object with Data from the File
 /// </summary>
 /// <param name="type">ize of the Package Index</param>
 /// <param name="pfd"></param>
 /// <param name="package"></param>
 public CompressedFileList(IPackedFileDescriptor pfd, IPackageFile package) : base()
 {
     iformat = package.Header.IndexType;
     items   = new ClstItem[0];
     this.ProcessData(pfd, package);
 }
コード例 #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="type">ize of the Package Index</param>
 public CompressedFileList(Data.MetaData.IndexTypes type) : base()
 {
     iformat = type;
     items   = new ClstItem[0];
 }
コード例 #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 internal CompressedFileList() : base()
 {
     iformat = Data.MetaData.IndexTypes.ptShortFileIndex;
     items   = new ClstItem[0];
 }
コード例 #11
0
 /// <summary>
 /// Constructor
 /// </summary>
 public ClstItem(Data.MetaData.IndexTypes format) : this(null, format)
 {
 }