コード例 #1
0
ファイル: WzDirectory.cs プロジェクト: stu98832/libwz
        internal override void Write(WzFileStream zf)
        {
            // start write
            int count = this.Items.Count;

            long[] itemoff = new long[count];

            this.Offset = (uint)zf.Tell();

            zf.Write4(count, true);

            // write header
            for (int i = 0; i < count; i++)
            {
                WzArchiveItem item = this.Items[i];
                zf.StringPool.DirectoryWrite(item.Name, item.Type, WzArchiveItemType.Reference);
                zf.Write4(item.Size, true);
                zf.Write4(item.Checksum, true);

                itemoff[i] = zf.Tell();
                zf.Write4u(0u); // reserve
            }

            // package items
            for (int i = 0; i < count; i++)
            {
                this.Items[i].Write(zf);
            }

            long endoff = zf.Tell();

            // rewrite offset
            for (int i = 0; i < count; i++)
            {
                zf.Seek(itemoff[i]);
                uint offKey = HashTools.GenerateOffsetKey((uint)zf.Tell(), this.Archive.DataOffset, this.Archive.Hash);
                uint encoff = HashTools.EncryptOffsetHash(this.Items[i].Offset, offKey, this.Archive.DataOffset);
                zf.Write4u(encoff);
            }

            // end write
            zf.Seek(endoff);
        }