Exemple #1
0
        /// <summary>
        /// Read the header of a file in the PAK <see cref="BinaryReader"/>.
        /// After Read(), stream points to the start of the compressed data.
        /// </summary>
        /// <param name="br">PAK <see cref="BinaryReader"/></param>
        /// <returns></returns>
        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");
                }
            }
            if (result.extraFieldLength != 0)
            {
                throw new InvalidOperationException("extra field not supported");
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Read the file chunk from specified <see cref="BinaryReader"/>.
        /// </summary>
        /// <param name="br">PAK <see cref="BinaryReader"/></param>
        /// <returns></returns>
        public static PakCentralDirFile Read(BinaryReader br)
        {
            PakCentralDirFile result = new PakCentralDirFile
            {
                signature1        = br.ReadUInt16(),
                signature2        = br.ReadUInt16(),
                createVersion     = br.ReadUInt16(),
                extractVersion    = br.ReadUInt16(),
                flags             = br.ReadUInt16(),
                compressionMethod = br.ReadUInt16(),
                time              = br.ReadUInt16(),
                date              = br.ReadUInt16(),
                crc               = br.ReadUInt32(),
                compressedSize    = br.ReadUInt32(),
                uncompressedSize  = br.ReadUInt32(),
                filenameLength    = br.ReadUInt16(),
                extraFieldLength  = br.ReadUInt16(),
                fileCommentLength = br.ReadUInt16(),
                diskNumStart      = br.ReadUInt16(),
                internalFileAttr  = br.ReadUInt16(),
                externalFileAttr  = br.ReadUInt32(),
                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");
                }
            }
            if (result.extraFieldLength != 0)
            {
                br.ReadBytes(result.extraFieldLength);
            }

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

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

            return(result);
        }
 /// <summary>
 /// Get a specific file from the loaded PAK files.
 /// </summary>
 /// <param name="filename">File name</param>
 /// <returns></returns>
 public byte[] GetFile(string filename) =>
 PakReaderSlim.ReadFileBytes(Files[PakUtil.NormalizeFilename(filename)]);