Beispiel #1
0
        /// <summary>
        /// This is used to enable SimPe to add compressed Resources
        /// </summary>
        void PrepareCompression()
        {
            if (fileindex == null)
            {
                return;
            }

            if (filelistfile != null)
            {
                return;
            }

            filelistfile          = new SimPe.PackedFiles.Wrapper.CompressedFileList(this.Header.IndexType);
            filelist              = new PackedFileDescriptor();
            filelist.Type         = Data.MetaData.DIRECTORY_FILE;
            filelist.LongInstance = 0x286B1F03;
            filelist.Group        = Data.MetaData.DIRECTORY_FILE;

            filelistfile.FileDescriptor = filelist;
            filelistfile.SynchronizeUserData();
            this.Add(filelist);
        }
Beispiel #2
0
        /// <summary>
        /// Writes the Index to the Package File
        /// </summary>
        /// <param name="writer">The BinaryWriter to use</param>
        /// <param name="tmpcmp">the index you want to write</param>
        /// <param name="tmpindex">listing of the compressin state for each packed File</param>
        protected void WriteFileList(BinaryWriter writer, ref PackedFileDescriptors tmpindex, ArrayList tmpcmp)
        {
            if (this.filelist == null)
            {
                filelist          = new PackedFileDescriptor();
                filelist.instance = 0x286B1F03;
                filelist.Group    = Data.MetaData.DIRECTORY_FILE;
                filelist.Type     = Data.MetaData.DIRECTORY_FILE;
            }

            //we use the fact, taht packed files that were altered by SimPe will not be compressed,
            //so we only need to delete entries in the Filelist that do not exist any longer. The Size
            //won't change!
            byte[] b = this.Read(filelist).UncompressedData;
            SimPe.PackedFiles.Wrapper.CompressedFileList fl = new SimPe.PackedFiles.Wrapper.CompressedFileList(filelist, this);
            if (filelist.MarkForDelete)
            {
                fl.Clear();
            }

            SimPe.PackedFiles.Wrapper.CompressedFileList newfl = new SimPe.PackedFiles.Wrapper.CompressedFileList(this.Header.IndexType);
            newfl.FileDescriptor = filelist;

            for (int i = 0; i < tmpcmp.Count; i++)
            {
                if ((bool)tmpcmp[i])
                {
                    int pos = fl.FindFile((IPackedFileDescriptor)tmpindex[i]);

                    if (pos != -1)                   //the file did already exist, so the size did not change!
                    {
                        SimPe.PackedFiles.Wrapper.ClstItem fi = fl.Items[pos];
                        newfl.Add(fi);
                    }
                    else                     //the file is new but compressed
                    {
                        //IPackedFile pf = this.Read((IPackedFileDescriptor)tmpindex[i]);
                        SimPe.PackedFiles.Wrapper.ClstItem fi = new SimPe.PackedFiles.Wrapper.ClstItem(newfl.IndexType);
                        PackedFileDescriptor pfd = (PackedFileDescriptor)tmpindex[i];
                        fi.Type             = pfd.Type;
                        fi.Group            = pfd.Group;
                        fi.Instance         = pfd.Instance;
                        fi.SubType          = pfd.SubType;
                        fi.UncompressedSize = (uint)pfd.fldata.UncompressedSize;
                        newfl.Add(fi);
                    }
                }
            }



            //no compressed Files, so remove the (empty) Filelist
            if (newfl.Items.Length != 0)
            {
                //tmpindex[tmpindex.Length-1] = filelist;
                tmpindex.Add(filelist);

                newfl.SynchronizeUserData();
                filelist.offset = (uint)writer.BaseStream.Position;
                filelist.size   = filelist.UserData.Length;
                writer.Write(filelist.UserData);
                filelist.Changed = false;
            }

            this.filelistfile = newfl;
        }