Ejemplo n.º 1
0
 // Methods
 internal ZipIOModeEnforcingStream(Stream baseStream, FileAccess access, ZipIOBlockManager blockManager, ZipIOLocalFileBlock block)
 {
     this._baseStream   = baseStream;
     this._access       = access;
     this._blockManager = blockManager;
     this._block        = block;
 }
Ejemplo n.º 2
0
        internal void AddFileBlock(ZipIOLocalFileBlock fileBlock)
        {
            this._dirtyFlag = true;
            ZipIOCentralDirectoryFileHeader header = ZipIOCentralDirectoryFileHeader.CreateNew(this._blockManager.Encoding, fileBlock);

            this.CentralDirectoryDictionary.Add(header.FileName, header);
        }
Ejemplo n.º 3
0
 public void UpdateReferences(bool closingFlag)
 {
     foreach (IZipIOBlock block3 in (IEnumerable)this._blockManager)
     {
         ZipIOLocalFileBlock   fileBlock = block3 as ZipIOLocalFileBlock;
         ZipIORawDataFileBlock block     = block3 as ZipIORawDataFileBlock;
         if (fileBlock != null)
         {
             ZipIOCentralDirectoryFileHeader header2 = (ZipIOCentralDirectoryFileHeader)this.CentralDirectoryDictionary[fileBlock.FileName];
             if (header2.UpdateIfNeeded(fileBlock))
             {
                 this._dirtyFlag = true;
             }
         }
         else if (block != null)
         {
             long diskImageShift = block.DiskImageShift;
             if (diskImageShift != 0L)
             {
                 foreach (ZipIOCentralDirectoryFileHeader header in this.CentralDirectoryDictionary.Values)
                 {
                     if (block.DiskImageContains(header.OffsetOfLocalHeader))
                     {
                         header.MoveReference(diskImageShift);
                         this._dirtyFlag = true;
                     }
                 }
                 continue;
             }
         }
     }
 }
Ejemplo n.º 4
0
        internal ZipFileInfo AddFile(string zipFileName, CompressionMethodEnum compressionMethod, DeflateOptionEnum deflateOption)
        {
            this.CheckDisposed();
            if (this._openAccess == FileAccess.Read)
            {
                throw new InvalidOperationException(SR.Get("CanNotWriteInReadOnlyMode"));
            }
            zipFileName = ZipIOBlockManager.ValidateNormalizeFileName(zipFileName);
            if ((compressionMethod != CompressionMethodEnum.Stored) && (compressionMethod != CompressionMethodEnum.Deflated))
            {
                throw new ArgumentOutOfRangeException("compressionMethod");
            }
            if ((deflateOption < DeflateOptionEnum.Normal) || ((deflateOption > DeflateOptionEnum.SuperFast) && (deflateOption != DeflateOptionEnum.None)))
            {
                throw new ArgumentOutOfRangeException("deflateOption");
            }
            if (this.FileExists(zipFileName))
            {
                throw new InvalidOperationException(SR.Get("AttemptedToCreateDuplicateFileName"));
            }
            ZipIOLocalFileBlock fileBlock = this._blockManager.CreateLocalFileBlock(zipFileName, compressionMethod, deflateOption);
            ZipFileInfo         info      = new ZipFileInfo(this, fileBlock);

            this.ZipFileInfoDictionary.Add(info.Name, info);
            return(info);
        }
Ejemplo n.º 5
0
        internal ZipIOLocalFileBlock LoadLocalFileBlock(string zipFileName)
        {
            this.CheckDisposed();
            ZipIOLocalFileBlock block = ZipIOLocalFileBlock.SeekableLoad(this, zipFileName);

            this.MapBlock(block);
            return(block);
        }
Ejemplo n.º 6
0
 // Methods
 internal ZipIOFileItemStream(ZipIOBlockManager blockManager, ZipIOLocalFileBlock block, long persistedOffset, long persistedSize)
 {
     this._persistedOffset     = persistedOffset;
     this._offset              = persistedOffset;
     this._persistedSize       = persistedSize;
     this._blockManager        = blockManager;
     this._block               = block;
     this._currentStreamLength = persistedSize;
 }
 internal bool UpdateIfNeeded(ZipIOLocalFileBlock fileBlock)
 {
     if (this.CheckIfUpdateNeeded(fileBlock))
     {
         this.UpdateFromLocalFileBlock(fileBlock);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 8
0
        internal ZipIOLocalFileBlock CreateLocalFileBlock(string zipFileName, CompressionMethodEnum compressionMethod, DeflateOptionEnum deflateOption)
        {
            this.CheckDisposed();
            ZipIOLocalFileBlock block = ZipIOLocalFileBlock.CreateNew(this, zipFileName, compressionMethod, deflateOption);

            this.InsertBlock(this.CentralDirectoryBlockIndex, block);
            this.CentralDirectoryBlock.AddFileBlock(block);
            this.DirtyFlag = true;
            return(block);
        }
        private bool CheckIfUpdateNeeded(ZipIOLocalFileBlock fileBlock)
        {
            bool flag2 = 0 != (fileBlock.GeneralPurposeBitFlag & 8);
            bool flag  = 0 != (this._generalPurposeBitFlag & 8);

            if ((flag2 || !flag) && ((((this._signature == 0x2014b50) && (this._versionNeededToExtract == fileBlock.VersionNeededToExtract)) && ((this._generalPurposeBitFlag == fileBlock.GeneralPurposeBitFlag) && (this._compressionMethod == fileBlock.CompressionMethod))) && (((this._crc32 == fileBlock.Crc32) && (this.CompressedSize == fileBlock.CompressedSize)) && (this.UncompressedSize == fileBlock.UncompressedSize))))
            {
                return(this.OffsetOfLocalHeader != fileBlock.Offset);
            }
            return(true);
        }
 private void UpdateFromLocalFileBlock(ZipIOLocalFileBlock fileBlock)
 {
     this._signature             = 0x2014b50;
     this._generalPurposeBitFlag = fileBlock.GeneralPurposeBitFlag;
     this._compressionMethod     = (ushort)fileBlock.CompressionMethod;
     this._lastModFileDateTime   = fileBlock.LastModFileDateTime;
     this._crc32          = fileBlock.Crc32;
     this._fileNameLength = (ushort)fileBlock.FileName.Length;
     this._fileName       = this._encoding.GetBytes(fileBlock.FileName);
     this._stringFileName = fileBlock.FileName;
     this.UpdateZip64Structures(fileBlock.CompressedSize, fileBlock.UncompressedSize, fileBlock.Offset);
     this._versionNeededToExtract = fileBlock.VersionNeededToExtract;
 }
Ejemplo n.º 11
0
        internal static ZipIOLocalFileBlock SeekableLoad(ZipIOBlockManager blockManager, string fileName)
        {
            ZipIOCentralDirectoryBlock      centralDirectoryBlock      = blockManager.CentralDirectoryBlock;
            ZipIOCentralDirectoryFileHeader centralDirectoryFileHeader = centralDirectoryBlock.GetCentralDirectoryFileHeader(fileName);
            long offsetOfLocalHeader = centralDirectoryFileHeader.OffsetOfLocalHeader;
            bool folderFlag          = centralDirectoryFileHeader.FolderFlag;
            bool volumeLabelFlag     = centralDirectoryFileHeader.VolumeLabelFlag;

            blockManager.Stream.Seek(offsetOfLocalHeader, SeekOrigin.Begin);
            ZipIOLocalFileBlock block = new ZipIOLocalFileBlock(blockManager, folderFlag, volumeLabelFlag);

            block.ParseRecord(blockManager.BinaryReader, fileName, offsetOfLocalHeader, centralDirectoryBlock, centralDirectoryFileHeader);
            return(block);
        }
        internal static ZipIOCentralDirectoryFileHeader CreateNew(Encoding encoding, ZipIOLocalFileBlock fileBlock)
        {
            ZipIOCentralDirectoryFileHeader header = new ZipIOCentralDirectoryFileHeader(encoding);

            header._fileCommentLength      = 0;
            header._fileComment            = null;
            header._diskNumberStart        = 0;
            header._internalFileAttributes = 0;
            header._externalFileAttributes = 0;
            header._versionMadeBy          = 0x2d;
            header._extraField             = ZipIOExtraField.CreateNew(false);
            header.UpdateFromLocalFileBlock(fileBlock);
            return(header);
        }
Ejemplo n.º 13
0
        internal static ZipIOLocalFileBlock CreateNew(ZipIOBlockManager blockManager, string fileName, CompressionMethodEnum compressionMethod, DeflateOptionEnum deflateOption)
        {
            ZipIOLocalFileBlock block = new ZipIOLocalFileBlock(blockManager, false, false);

            block._localFileHeader = ZipIOLocalFileHeader.CreateNew(fileName, blockManager.Encoding, compressionMethod, deflateOption, blockManager.Streaming);
            if (blockManager.Streaming)
            {
                block._localFileDataDescriptor = ZipIOLocalFileDataDescriptor.CreateNew();
            }
            block._offset         = 0L;
            block._dirtyFlag      = true;
            block._fileItemStream = new ZipIOFileItemStream(blockManager, block, block._offset + block._localFileHeader.Size, 0L);
            if (compressionMethod == CompressionMethodEnum.Deflated)
            {
                block._deflateStream        = new CompressStream(block._fileItemStream, 0L, true);
                block._crcCalculatingStream = new ProgressiveCrcCalculatingStream(blockManager, block._deflateStream);
                return(block);
            }
            block._crcCalculatingStream = new ProgressiveCrcCalculatingStream(blockManager, block._fileItemStream);
            return(block);
        }
Ejemplo n.º 14
0
        internal ZipFileInfo GetFile(string zipFileName)
        {
            this.CheckDisposed();
            if (this._openAccess == FileAccess.Write)
            {
                throw new InvalidOperationException(SR.Get("CanNotReadInWriteOnlyMode"));
            }
            zipFileName = ZipIOBlockManager.ValidateNormalizeFileName(zipFileName);
            if (this.ZipFileInfoDictionary.Contains(zipFileName))
            {
                return((ZipFileInfo)this.ZipFileInfoDictionary[zipFileName]);
            }
            if (!this.FileExists(zipFileName))
            {
                throw new InvalidOperationException(SR.Get("FileDoesNotExists"));
            }
            ZipIOLocalFileBlock fileBlock = this._blockManager.LoadLocalFileBlock(zipFileName);
            ZipFileInfo         info      = new ZipFileInfo(this, fileBlock);

            this.ZipFileInfoDictionary.Add(info.Name, info);
            return(info);
        }
Ejemplo n.º 15
0
 // Methods
 internal ZipFileInfo(ZipArchive zipArchive, ZipIOLocalFileBlock fileBlock)
 {
     this._fileBlock  = fileBlock;
     this._zipArchive = zipArchive;
 }