Ejemplo n.º 1
0
        //public byte[] extraField;
        //public byte[] comment;

        public static PakCentralDirFile Read(BinaryReader br)
        {
            var result = new PakCentralDirFile();

            result.signature1        = br.ReadUInt16();
            result.signature2        = br.ReadUInt16();
            result.createVersion     = br.ReadUInt16();
            result.extractVersion    = br.ReadUInt16();
            result.flags             = br.ReadUInt16();
            result.compressionMethod = br.ReadUInt16();
            result.time              = br.ReadUInt16();
            result.date              = br.ReadUInt16();
            result.crc               = br.ReadUInt32();
            result.compressedSize    = br.ReadUInt32();
            result.uncompressedSize  = br.ReadUInt32();
            result.filenameLength    = br.ReadUInt16();
            result.extraFieldLength  = br.ReadUInt16();
            result.fileCommentLength = br.ReadUInt16();
            result.diskNumStart      = br.ReadUInt16();
            result.internalFileAttr  = br.ReadUInt16();
            result.externalFileAttr  = br.ReadUInt32();
            result.localHeaderOffset = br.ReadUInt32();

            result.filename = PakUtil.ReadFilename(br, result.filenameLength);

            if (result.signature1 == PakConstants.PAK_SIGNATURE1 &&
                result.signature2 == PakConstants.PAK_SIGNATURE2_DIR)
            {
                result.isAionFormat = true;
            }
            else
            {
                if (result.signature1 != PakConstants.ZIP_SIGNATURE1 ||
                    result.signature2 != PakConstants.ZIP_SIGNATURE2_DIR)
                {
                    throw new InvalidOperationException("bad central dir signature");
                }

                // zipformat = true
            }

            if (result.extraFieldLength != 0)
            {
                var b = br.ReadBytes(result.extraFieldLength);
                //    throw new InvalidOperationException("extra field not supported");
            }

            if (result.fileCommentLength != 0)
            {
                throw new InvalidOperationException("file comment not supported");
            }

            if (result.diskNumStart != 0)
            {
                throw new InvalidOperationException("disk num not supported");
            }

            return(result);
        }
Ejemplo n.º 2
0
        // after Read(), stream points to the start of the compressed data.
        public static PakFileEntry Read(BinaryReader br)
        {
            var result = new PakFileEntry();

            result.signature1        = br.ReadUInt16();
            result.signature2        = br.ReadUInt16();
            result.extractVersion    = br.ReadUInt16();
            result.flags             = br.ReadUInt16();
            result.compressionMethod = br.ReadUInt16();
            result.time             = br.ReadUInt16();
            result.date             = br.ReadUInt16();
            result.crc              = br.ReadUInt32();
            result.compressedSize   = br.ReadUInt32();
            result.uncompressedSize = br.ReadUInt32();
            result.filenameLength   = br.ReadUInt16();
            result.extraFieldLength = br.ReadUInt16();

            result.filename = PakUtil.ReadFilename(br, result.filenameLength);

            if (result.signature1 != PakConstants.PAK_SIGNATURE1 ||
                result.signature2 != PakConstants.PAK_SIGNATURE2_FILE)
            {
                if (result.signature1 != PakConstants.ZIP_SIGNATURE1 ||
                    result.signature2 != PakConstants.ZIP_SIGNATURE2_FILE)
                {
                    throw new InvalidOperationException("bad file signature");
                }

                // zipformat = true
            }

            if (result.extraFieldLength != 0)
            {
                throw new InvalidOperationException("extra field not supported");
            }

            return(result);
        }
Ejemplo n.º 3
0
 public byte[] GetFile(string filename)
 {
     return(m_pr.ReadFileBytes(Files[PakUtil.NormalizeFilename(filename)]));
 }