예제 #1
0
 public DwPackFileEntry(Stream baseStream, long dataStartOffset, ref DwPackEntry entry)
 {
     mBaseStream      = baseStream;
     mDataOffset      = dataStartOffset + entry.DataOffset;
     Field00          = entry.Field00;
     Path             = entry.Path;
     Field104         = entry.Field104;
     CompressedSize   = entry.CompressedSize;
     UncompressedSize = entry.UncompressedSize;
     IsCompressed     = entry.Flags > 0;
 }
예제 #2
0
        public void Write(Stream stream, bool compress, Action <DwPackFileEntry> callback)
        {
            using var writer = new BinaryValueWriter(stream, StreamOwnership.Retain, Endianness.Little);

            DwPackHeader header;

            header.Signature = DwPackHeader.SIGNATURE;
            header.Field08   = Field08;
            header.FileCount = Entries.Count;
            header.Index     = Index;
            writer.Write(header);

            var dataOffset = 0;

            for (int i = 0; i < Entries.Count; i++)
            {
                var e = Entries[i];
                if (compress)
                {
                    e.Compress();
                }

                var entry = new DwPackEntry();
                entry.Field00          = e.Field00;
                entry.Index            = (short)i;
                entry.PackIndex        = (short)header.Index;
                entry.Path             = e.Path;
                entry.Field104         = e.Field104;
                entry.CompressedSize   = e.CompressedSize;
                entry.UncompressedSize = e.UncompressedSize;
                entry.Flags            = e.IsCompressed ? 1 : 0;
                entry.DataOffset       = dataOffset;
                writer.Write(entry);
                dataOffset += entry.CompressedSize;
            }

            for (int i = 0; i < Entries.Count; i++)
            {
                callback?.Invoke(Entries[i]);
                Entries[i].CopyTo(writer.GetBaseStream(), decompress: false);
            }
        }