コード例 #1
0
ファイル: ZipArchiveEntry.cs プロジェクト: wise0704/SwcBuild
 internal ZipArchiveEntry(ZipArchive archive, ZipCentralDirectoryFileHeader cd)
 {
     _archive                      = archive;
     _originallyInArchive          = true;
     _diskNumberStart              = cd.DiskNumberStart;
     _versionToExtract             = (ZipVersionNeededValues)cd.VersionNeededToExtract;
     _generalPurposeBitFlag        = (BitFlagValues)cd.GeneralPurposeBitFlag;
     CompressionMethod             = (CompressionMethodValues)cd.CompressionMethod;
     _lastModified                 = new DateTimeOffset(ZipHelper.DosTimeToDateTime(cd.LastModified));
     _compressedSize               = cd.CompressedSize;
     _uncompressedSize             = cd.UncompressedSize;
     _offsetOfLocalHeader          = cd.RelativeOffsetOfLocalHeader;
     _storedOffsetOfCompressedData = null;
     _crc32                  = cd.Crc32;
     _compressedBytes        = null;
     _storedUncompressedData = null;
     _currentlyOpenForWrite  = false;
     _everOpenedForWrite     = false;
     _outstandingWriteStream = null;
     FullName                = DecodeEntryName(cd.Filename);
     _lhUnknownExtraFields   = null;
     _cdUnknownExtraFields   = cd.ExtraFields;
     _fileComment            = cd.FileComment;
     _compressionLevel       = null;
 }
コード例 #2
0
ファイル: ZipArchive.cs プロジェクト: wise0704/SwcBuild
 private void ReadCentralDirectory()
 {
     try
     {
         ZipCentralDirectoryFileHeader header;
         ArchiveStream1.Seek(_centralDirectoryStart, SeekOrigin.Begin);
         long num = 0L;
         bool saveExtraFieldsAndComments = Mode == ZipArchiveMode.Update;
         while (ZipCentralDirectoryFileHeader.TryReadBlock(_archiveReader, saveExtraFieldsAndComments, out header))
         {
             AddEntry(new ZipArchiveEntry(this, header));
             num += 1L;
         }
         if (num != _expectedNumberOfEntries)
         {
             throw new InvalidDataException(Messages.NumEntriesWrong);
         }
     }
     catch (EndOfStreamException exception)
     {
         throw new InvalidDataException(Messages.CentralDirectoryInvalid, exception);
     }
 }
コード例 #3
0
        public static bool TryReadBlock(BinaryReader reader, bool saveExtraFieldsAndComments, out ZipCentralDirectoryFileHeader header)
        {
            Zip64ExtraField field;

            header = new ZipCentralDirectoryFileHeader();
            if (reader.ReadUInt32() != 0x2014b50)
            {
                return(false);
            }
            header.VersionMadeBy          = reader.ReadUInt16();
            header.VersionNeededToExtract = reader.ReadUInt16();
            header.GeneralPurposeBitFlag  = reader.ReadUInt16();
            header.CompressionMethod      = reader.ReadUInt16();
            header.LastModified           = reader.ReadUInt32();
            header.Crc32 = reader.ReadUInt32();
            uint num  = reader.ReadUInt32();
            uint num2 = reader.ReadUInt32();

            header.FilenameLength    = reader.ReadUInt16();
            header.ExtraFieldLength  = reader.ReadUInt16();
            header.FileCommentLength = reader.ReadUInt16();
            ushort num3 = reader.ReadUInt16();

            header.InternalFileAttributes = reader.ReadUInt16();
            header.ExternalFileAttributes = reader.ReadUInt32();
            uint num4 = reader.ReadUInt32();

            header.Filename = reader.ReadBytes(header.FilenameLength);
            bool readUncompressedSize  = num2 == uint.MaxValue;
            bool readCompressedSize    = num == uint.MaxValue;
            bool readLocalHeaderOffset = num4 == uint.MaxValue;
            bool readStartDiskNumber   = num3 == 0xffff;
            long position = reader.BaseStream.Position + header.ExtraFieldLength;

            using (Stream stream = new SubReadStream(reader.BaseStream, reader.BaseStream.Position, (long)header.ExtraFieldLength))
            {
                if (saveExtraFieldsAndComments)
                {
                    header.ExtraFields = ZipGenericExtraField.ParseExtraField(stream);
                    field = Zip64ExtraField.GetAndRemoveZip64Block(header.ExtraFields, readUncompressedSize, readCompressedSize, readLocalHeaderOffset, readStartDiskNumber);
                }
                else
                {
                    header.ExtraFields = null;
                    field = Zip64ExtraField.GetJustZip64Block(stream, readUncompressedSize, readCompressedSize, readLocalHeaderOffset, readStartDiskNumber);
                }
            }
            reader.BaseStream.AdvanceToPosition(position);
            if (saveExtraFieldsAndComments)
            {
                header.FileComment = reader.ReadBytes(header.FileCommentLength);
            }
            else
            {
                Stream baseStream = reader.BaseStream;
                baseStream.Position += header.FileCommentLength;
                header.FileComment   = null;
            }
            header.UncompressedSize            = !field.UncompressedSize.HasValue ? ((long)num2) : field.UncompressedSize.Value;
            header.CompressedSize              = !field.CompressedSize.HasValue ? ((long)num) : field.CompressedSize.Value;
            header.RelativeOffsetOfLocalHeader = !field.LocalHeaderOffset.HasValue ? ((long)num4) : field.LocalHeaderOffset.Value;
            header.DiskNumberStart             = !field.StartDiskNumber.HasValue ? num3 : field.StartDiskNumber.Value;
            return(true);
        }
コード例 #4
0
ファイル: ZipArchiveEntry.cs プロジェクト: wise0704/SwcBuild
 internal ZipArchiveEntry(ZipArchive archive, ZipCentralDirectoryFileHeader cd, CompressionLevel compressionLevel) : this(archive, cd)
 {
     _compressionLevel = new CompressionLevel?(compressionLevel);
 }