Beispiel #1
0
        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);
        }