Пример #1
0
        /// <summary> 使用外部的的<see cref="WzFileStream"/>儲存資料 </summary>
        public bool Write(WzFileStream zs)
        {
            this.Hash = HashTools.GenerateArchiveVersionHash(this.Version.ToString());

            // header
            zs.Write(new byte[] { (byte)'P', (byte)'K', (byte)'G', (byte)'1' }, 4);
            zs.Write8(0);  //Reserve
            zs.Write4u(0); //Reserve
            zs.WriteString(this.Description);

            // data
            long off = zs.Tell();

            this.DataOffset = (uint)off;
            zs.BaseOffset   = this.DataOffset;

            zs.Write2u((ushort)HashTools.EncryptArchiveVersionHash(this.Hash));
            this.RootDirectory.Update();
            this.RootDirectory.Write(zs);

            long endoff = zs.Tell();

            // rewrite size, offset
            zs.Seek(4);
            zs.Write8(endoff - off);
            zs.Write4u((uint)off);

            // end write
            zs.Flush();

            return(true);
        }
Пример #2
0
        /// <summary> 使用外部的<see cref="WzFileStream"/>讀取資料 </summary>
        public bool Read(WzFileStream zs)
        {
            string identifier = zs.ReadString(4);

            if (!identifier.Equals("PKG1"))
            {
                return(false);
            }

            this.DataSize    = zs.Read8();
            this.DataOffset  = zs.Read4u();
            this.Description = zs.ReadString((int)(this.DataOffset - zs.Tell()));

            zs.BaseOffset = this.DataOffset;

            ushort cryptedHash = zs.Read2u();

            this.RootDirectory.Offset = (uint)zs.Tell();
            for (int j = 0; j < 0xFFFF; j++)
            {
                this.Hash = HashTools.GenerateArchiveVersionHash(j.ToString());
                if (HashTools.EncryptArchiveVersionHash(this.Hash) == cryptedHash)
                {
                    zs.StringPool.Clear();
                    if (this.RootDirectory.Read(zs))
                    {
                        this.Version = j;
                        return(true);
                    }
                }
            }
            return(false);
        }