/// <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); }
internal bool Read(WzFileStream zs) { this.Items.Clear(); zs.Seek(this.Offset); int count = zs.Read4(true); for (int i = 0; i < count; i++) { WzArchiveItem item = null; WzArchiveItemType itemtype; string itemname = zs.StringPool.DirectoryRead(out itemtype, WzArchiveItemType.Reference); if (itemtype == WzArchiveItemType.Directory) { item = new WzDirectory(itemname); } else if (itemtype == WzArchiveItemType.File) { item = new WzFile(itemname, zs.KeyType) { Stream = zs.BaseStream }; } else { throw new InvalidDataException("Undefined item type : " + (int)itemtype); } item.Size = zs.Read4(true); item.Checksum = zs.Read4(true); uint offKey = HashTools.GenerateOffsetKey((uint)zs.Tell(), this.Archive.DataOffset, this.Archive.Hash); item.Offset = HashTools.DecryptOffsetHash(zs.Read4u(), offKey, this.Archive.DataOffset); if ((item.Offset + item.Size) > zs.Length) { return(false); } this.Add(item); } for (int i = 0; i < this.Items.Count; i++) { if (this.Items[i].Type == WzArchiveItemType.Directory) { (this.Items[i] as WzDirectory).Read(zs); } } return(true); }