public void UpdateEntry(PakEntry pakEntry)
        {
            if (updateSuspended)
            {
                return;
            }

            var index         = entries.FindIndex(x => x.HeaderOffset == pakEntry.HeaderOffset);
            var nextHeaderPos = index == entries.Count
                                    ? this.terminator.HeaderOffset
                                    : this.entries[index + 1].HeaderOffset;
            var oldLength = nextHeaderPos - pakEntry.HeaderOffset;

            if (oldLength != pakEntry.HeaderLength)
            {
                this.updateSuspended = true;
                moveEntriesAfter(index, (int)pakEntry.HeaderLength - (int)oldLength);
                this.updateSuspended = false;
            }

            this.pakStream.Position = pakEntry.HeaderOffset;

            using (var bw = new EndianBinaryWriter(EndianBitConverter.Big, new NonClosingStreamWrapper(this.pakStream)))
            {
                pakEntry.WriteHeaderTo(bw);
            }
        }
        private void ReadHeader()
        {
            using (EndianBinaryReader br = new EndianBinaryReader(
                       EndianBitConverter.Big,
                       new NonClosingStreamWrapper(pakStream)))
            {
                PakEntry entry;
                QbKey    lastKey = new QbKey(".last");

                do
                {
                    entry = PakEntry.ParseHeader(br, this);
                    this.entries.Add(entry);
                }while (!entry.FileType.Equals(lastKey));

                this.entries.RemoveAt(this.entries.Count - 1);
                this.terminator = entry;
            }
        }
        public PakEntry CreateEntry(string filePath, bool withEmbeddedFilename = false)
        {
            var      type      = Path.GetExtension(filePath);
            var      shortName = Path.GetFileNameWithoutExtension(filePath);
            PakEntry newEntry  = new PakEntry(this)
            {
                HeaderOffset       = this.terminator.HeaderOffset,
                FileOffsetRelative = this.terminator.FileOffsetRelative,
                FileType           = new QbKey(type),
                FileShortNameKey   = new QbKey(shortName)
            };

            if (withEmbeddedFilename)
            {
                newEntry.EmbeddedFilename = filePath;
            }
            else
            {
                newEntry.FileFullNameKey = new QbKey(filePath);
            }

            this.terminator.HeaderOffset       += newEntry.HeaderLength;
            this.terminator.FileOffsetRelative -= newEntry.HeaderLength;

            if (this.terminator.HeaderOffset + this.terminator.HeaderLength > this.Entries[0].FileOffset)
            {
                var delta = this.extendHeadersRegion();
                newEntry.FileOffsetRelative += delta;
            }

            this.entries.Add(newEntry);
            this.pakStream.Position = newEntry.HeaderOffset;

            using (var bw = new EndianBinaryWriter(EndianBitConverter.Big, new NonClosingStreamWrapper(this.pakStream)))
            {
                newEntry.WriteHeaderTo(bw);
                this.terminator.WriteHeaderTo(bw);
            }

            return(newEntry);
        }
예제 #4
0
        internal static PakEntry ParseHeader(EndianBinaryReader br, PakArchive sourceArchive)
        {
            var result = new PakEntry(sourceArchive);

            result.HeaderOffset        = (UInt32)br.BaseStream.Position;
            result.FileType            = new QbKey(br.ReadUInt32());
            result.FileOffsetRelative  = br.ReadUInt32();
            result.FileLength          = br.ReadUInt32();
            result.EmbeddedFilenameKey = new QbKey(br.ReadUInt32());
            result.FileFullNameKey     = new QbKey(br.ReadUInt32());
            result.FileShortNameKey    = new QbKey(br.ReadUInt32());
            result.Unknown             = br.ReadUInt32();
            result._flags = (PakEntryFlags)br.ReadUInt32();

            if (result.Flags.HasFlag(PakEntryFlags.HasEmbeddedFilename))
            {
                var embeddedFilenameBytes = br.ReadBytes(0xA0);
                result._embeddedFilename = Utility.Latin1Encoding.GetString(embeddedFilenameBytes).TrimEnd('\0');
            }

            return(result);
        }
        public PakEntry CreateEntry(string filePath, bool withEmbeddedFilename = false)
        {
            var type      = Path.GetExtension(filePath);
            var shortName = Path.GetFileNameWithoutExtension(filePath);

            this.updateSuspended = true;

            PakEntry newEntry = new PakEntry(this)
            {
                HeaderOffset       = this.terminator.HeaderOffset,
                FileOffsetRelative = this.terminator.FileOffsetRelative,
                FileType           = new QbKey(type),
                FileShortNameKey   = new QbKey(shortName)
            };

            if (withEmbeddedFilename)
            {
                newEntry.EmbeddedFilename = filePath;
            }
            else
            {
                newEntry.FileFullNameKey = new QbKey(filePath);
            }

            this.entries.Add(newEntry);
            moveEntriesAfter(this.entries.Count, (int)newEntry.HeaderLength);
            this.pakStream.Position = newEntry.HeaderOffset;

            using (var bw = new EndianBinaryWriter(EndianBitConverter.Big, new NonClosingStreamWrapper(this.pakStream)))
            {
                newEntry.WriteHeaderTo(bw);
                this.terminator.WriteHeaderTo(bw);
            }

            this.updateSuspended = false;

            return(newEntry);
        }