示例#1
0
        private bool ReadCentralDirectoryStructure( BinaryReader br )
        {
            string fileName = "";
            XUnzipFileInfo pFileInfo = new XUnzipFileInfo ();
            SCentralDirectoryStructureHead head = new SCentralDirectoryStructureHead ();

            head.versionMadeBy = br.ReadInt16 ();
            head.versionNeededToExtract = br.ReadInt16 ();
            head.generalPurposeBitFlag = new _UGeneralPurposeBitFlag ( br.ReadInt16 () );
            head.compressionMethod = ( XUNZIP_COMPRESSION_METHOD ) br.ReadInt16 ();
            head.dostime = br.ReadUInt32 ();
            head.crc32 = br.ReadUInt32 ();
            head.compressedSize = br.ReadUInt32 ();
            head.uncompressedSize = br.ReadUInt32 ();
            head.fileNameLength = br.ReadInt16 ();
            head.extraFieldLength = br.ReadInt16 ();
            head.fileCommentLength = br.ReadInt16 ();
            head.diskNumberStart = br.ReadInt16 ();
            head.internalFileAttributes = br.ReadInt16 ();
            head.externalFileAttributes = br.ReadUInt32 ();
            head.relativeOffsetOfLocalHeader = br.ReadUInt32 ();

            if ( head.compressionMethod != XUNZIP_COMPRESSION_METHOD.METHOD_STORE &&
                head.compressionMethod != XUNZIP_COMPRESSION_METHOD.METHOD_DEFLATE )
                return false;

            if ( head.generalPurposeBitFlag.bit0 != 0 )
                return false;

            if ( head.fileNameLength != 0 )
            {
                byte [] tmp = br.ReadBytes ( head.fileNameLength );
                fileName = Encoding.UTF8.GetString ( tmp, 0, tmp.Length );
            }

            inputStream.Seek ( head.extraFieldLength, SeekOrigin.Current );

            //inputStream.Seek ( head.extraFieldLength, SeekOrigin.Current );

            inputStream.Seek ( head.fileCommentLength, SeekOrigin.Current );

            if ( ( head.externalFileAttributes & 16 ) != 0 )
                return true;

            pFileInfo.fileName = fileName;
            pFileInfo.compressedSize = ( int ) head.compressedSize;
            pFileInfo.uncompressedSize = ( int ) head.uncompressedSize;
            pFileInfo.crc32 = head.crc32;
            pFileInfo.method = head.compressionMethod;
            pFileInfo.encrypted = ( head.generalPurposeBitFlag.bit0 != 0 ) ? true : false;
            pFileInfo.offsetLocalHeader = ( int ) head.relativeOffsetOfLocalHeader;
            pFileInfo.offsetData = -1;

            FileAddList ( pFileInfo );

            return true;
        }
示例#2
0
        private bool ReadLocalHeader( ref XUnzipFileInfo pFileInfo, BinaryReader br )
        {
            if ( ( ( SIGNATURE ) br.ReadUInt32 () ) != SIGNATURE.LOCAL_FILE_HEADER )
                return false;

            SLocalFileHeader head = new SLocalFileHeader ();

            head.versionNeededToExtract = br.ReadInt16 ();
            head.generalPurposeBitFlag = new _UGeneralPurposeBitFlag ( br.ReadInt16 () );
            head.compressionMethod = ( XUNZIP_COMPRESSION_METHOD ) br.ReadInt16 ();
            head.dostime = br.ReadUInt32 ();
            head.crc32 = br.ReadUInt32 ();
            head.compressedSize = br.ReadUInt32 ();
            head.uncompressedSize = br.ReadUInt32 ();
            head.fileNameLength = br.ReadInt16 ();
            head.extraFieldLength = br.ReadInt16 ();

            inputStream.Seek ( head.fileNameLength, SeekOrigin.Current );

            inputStream.Seek ( head.extraFieldLength, SeekOrigin.Current );

            pFileInfo.offsetData = ( int ) inputStream.Position;

            return true;
        }
示例#3
0
 private bool FileAddList( XUnzipFileInfo pFileInfo )
 {
     fileInfoList.Add ( pFileInfo );
     return true;
 }