Example #1
0
 private void StreamingSaveContainer(bool closingFlag)
 {
     try
     {
         long num2 = 0L;
         for (int i = 0; i < this._blockList.Count; i++)
         {
             IZipIOBlock         block  = (IZipIOBlock)this._blockList[i];
             ZipIOLocalFileBlock block2 = block as ZipIOLocalFileBlock;
             if (block2 == null)
             {
                 if (closingFlag)
                 {
                     block.Move(num2 - block.Offset);
                     block.UpdateReferences(closingFlag);
                     if (block.GetDirtyFlag(closingFlag))
                     {
                         block.Save();
                     }
                 }
             }
             else if (block.GetDirtyFlag(closingFlag))
             {
                 block2.SaveStreaming(closingFlag);
             }
             num2 += block.Size;
         }
         this.Stream.Flush();
     }
     finally
     {
         this._propagatingFlushDisposed = false;
     }
 }
Example #2
0
 private void MapBlock(IZipIOBlock block)
 {
     for (int i = this._blockList.Count - 1; i >= 0; i--)
     {
         ZipIORawDataFileBlock block2 = this._blockList[i] as ZipIORawDataFileBlock;
         if ((block2 != null) && block2.DiskImageContains(block))
         {
             ZipIORawDataFileBlock block3;
             ZipIORawDataFileBlock block4;
             block2.SplitIntoPrefixSuffix(block, out block4, out block3);
             this._blockList.RemoveAt(i);
             if (block3 != null)
             {
                 this._blockList.Insert(i, block3);
             }
             this._blockList.Insert(i, block);
             if (block4 != null)
             {
                 this._blockList.Insert(i, block4);
             }
             return;
         }
     }
     throw new FileFormatException(SR.Get("CorruptedData"));
 }
Example #3
0
        internal bool DiskImageContains(IZipIOBlock block)
        {
            checked
            {
                Debug.Assert(block != null);
                Debug.Assert(block.Offset >= 0);
                Debug.Assert(block.Size > 0);

                return((_persistedOffset <= block.Offset) &&
                       (_persistedOffset + _size >= block.Offset + block.Size));
            }
        }
Example #4
0
 internal void SplitIntoPrefixSuffix(IZipIOBlock block, out ZipIORawDataFileBlock prefixBlock, out ZipIORawDataFileBlock suffixBlock)
 {
     prefixBlock = null;
     suffixBlock = null;
     if (block.Offset > this._persistedOffset)
     {
         long offset = this._persistedOffset;
         long size   = block.Offset - this._persistedOffset;
         prefixBlock = Assign(this._blockManager, offset, size);
     }
     if ((block.Offset + block.Size) < (this._persistedOffset + this._size))
     {
         long num  = block.Offset + block.Size;
         long num2 = (this._persistedOffset + this._size) - num;
         suffixBlock = Assign(this._blockManager, num, num2);
     }
 }
Example #5
0
 private void SaveContainer(bool closingFlag)
 {
     this.CheckDisposed();
     if (closingFlag || this.DirtyFlag)
     {
         long num2 = 0L;
         foreach (IZipIOBlock block2 in this._blockList)
         {
             block2.Move(num2 - block2.Offset);
             block2.UpdateReferences(closingFlag);
             num2 += block2.Size;
         }
         bool flag  = false;
         int  count = this._blockList.Count;
         for (int i = 0; i < count; i++)
         {
             IZipIOBlock block = (IZipIOBlock)this._blockList[i];
             if (block.GetDirtyFlag(closingFlag))
             {
                 flag = true;
                 long offset = block.Offset;
                 long size   = block.Size;
                 if (size > 0L)
                 {
                     for (int j = i + 1; j < count; j++)
                     {
                         if (((IZipIOBlock)this._blockList[j]).PreSaveNotification(offset, size) == PreSaveNotificationScanControlInstruction.Stop)
                         {
                             break;
                         }
                     }
                 }
                 block.Save();
             }
         }
         if (flag && (this.Stream.Length > num2))
         {
             this.Stream.SetLength(num2);
         }
         this.Stream.Flush();
         this.DirtyFlag = false;
     }
 }
Example #6
0
        internal void SplitIntoPrefixSuffix(IZipIOBlock block,
                                            out ZipIORawDataFileBlock prefixBlock, out ZipIORawDataFileBlock suffixBlock)
        {
            // assert that current's block cache isn't loaded, if it is
            // we probably missed an opportunity to used this cache in order to parse the new block
            // and it might be based on the overriden data on disk
            // This block can only be in cached state as a part of single BlockManager.Save execution.
            // It can NOT be in cached state prior to BlockManager.Save function entry or after
            // BlockManager.Save execution completed
            Debug.Assert(_cachePrefixStream == null);

            // Assert that block is containe inside the current raw block
            Debug.Assert(DiskImageContains(block));

            checked
            {
                prefixBlock = null;
                suffixBlock = null;
                if (block.Offset > _persistedOffset)
                {
                    // we have a new non empty prefix;
                    long newBlockOffset = _persistedOffset;
                    long newBlockSize   = block.Offset - _persistedOffset;

                    prefixBlock = Assign(_blockManager, newBlockOffset, newBlockSize);
                }

                if (block.Offset + block.Size < _persistedOffset + _size)
                {
                    // we have a new non empty suffix;
                    long newBlockOffset = block.Offset + block.Size;
                    long newBlockSize   = _persistedOffset + _size - newBlockOffset;

                    suffixBlock = Assign(_blockManager, newBlockOffset, newBlockSize);
                }
            }
        }
        internal void SplitIntoPrefixSuffix(IZipIOBlock block,
                                        out ZipIORawDataFileBlock prefixBlock, out ZipIORawDataFileBlock suffixBlock) 
        {
            // assert that current's block cache isn't loaded, if it is 
            // we probably missed an opportunity to used this cache in order to parse the new block 
            // and it might be based on the overriden data on disk
            // This block can only be in cached state as a part of single BlockManager.Save execution. 
            // It can NOT be in cached state prior to BlockManager.Save function entry or after
            // BlockManager.Save execution completed
            Debug.Assert(_cachePrefixStream == null);
 
            // Assert that block is containe inside the current raw block
            Debug.Assert(DiskImageContains(block)); 
 
            checked
            { 
                prefixBlock = null;
                suffixBlock = null;
                if (block.Offset > _persistedOffset)
                { 
                    // we have a new non empty prefix;
                    long newBlockOffset = _persistedOffset; 
                    long newBlockSize = block.Offset - _persistedOffset; 

                    prefixBlock = Assign(_blockManager, newBlockOffset , newBlockSize); 
                }

                if (block.Offset + block.Size < _persistedOffset + _size)
                { 
                    // we have a new non empty suffix;
                    long newBlockOffset = block.Offset + block.Size; 
                    long newBlockSize = _persistedOffset + _size - newBlockOffset; 

                    suffixBlock = Assign(_blockManager, newBlockOffset, newBlockSize); 
                }
            }
        }
        internal bool DiskImageContains(IZipIOBlock block) 
        {
            checked 
            {
                Debug.Assert(block != null);
                Debug.Assert(block.Offset >=0);
                Debug.Assert(block.Size > 0); 

                return (_persistedOffset <= block.Offset) && 
                            (_persistedOffset + _size >= block.Offset +block.Size); 
            }
        } 
Example #9
0
 internal bool DiskImageContains(IZipIOBlock block)
 {
     return((this._persistedOffset <= block.Offset) && ((this._persistedOffset + this._size) >= (block.Offset + block.Size)));
 }
Example #10
0
 private void AppendBlock(IZipIOBlock block)
 {
     this._blockList.Add(block);
 }
Example #11
0
 private void InsertBlock(int blockPosition, IZipIOBlock block)
 {
     this._blockList.Insert(blockPosition, block);
 }
Example #12
0
        private void AppendBlock(IZipIOBlock block) 
        {
            // as we are adding a new block it must be dirty unless its size is 0 
            Debug.Assert(block.GetDirtyFlag(true) || // closingFlag==true used as a more conservative option
                                    block.Size == 0);

            // CentralDirectory persistence logic relies on the fact that we always add headers in a fashion that 
            // matches the order of the corresponding file items in the physical archive (currently to the end of the list).
            // If this invariant is violated, the corresponding central directory persistence logic must be updated. 
            _blockList.Add(block); 
        }
Example #13
0
        private void InsertBlock(int blockPosition, IZipIOBlock block) 
        {
            // as we are adding a new block it must be dirty unless its size is 0 
            Debug.Assert(block.GetDirtyFlag(true) ||   // closingFlag==true used as a more conservative option
                                    block.Size == 0);

            _blockList.Insert(blockPosition, block); 
        }
Example #14
0
        private void MapBlock(IZipIOBlock block)
        { 
            // as we map a block to existing file space it must be not dirty.
            Debug.Assert(!block.GetDirtyFlag(true)); // closingFlag==true used as a more conservative option
            Debug.Assert(!_openStreaming, "Not legal in Streaming mode");
 
            for (int blockIndex = _blockList.Count - 1; blockIndex >= 0; --blockIndex)
            { 
                // if we need to find a RawDataBlock that maps to the target area 
                ZipIORawDataFileBlock rawBlock = _blockList[blockIndex] as ZipIORawDataFileBlock;
 
                //check the original loaded RawBlock size / offset against the new block
                if ((rawBlock != null) && rawBlock.DiskImageContains(block))
                {
                    ZipIORawDataFileBlock prefixBlock, suffixBlock; 

                    //split raw block into prefixRawBlock, SuffixRawBlock 
                    rawBlock.SplitIntoPrefixSuffix(block, out prefixBlock, out suffixBlock); 

                    _blockList.RemoveAt(blockIndex); // remove the old big raw data block 

                    // add suffix Raw data block
                    if (suffixBlock != null)
                    { 
                        _blockList.Insert(blockIndex, suffixBlock);
                    } 
 
                    // add new mapped block
                    _blockList.Insert(blockIndex, block); 

                    // add prefix Raw data block
                    if (prefixBlock != null)
                    { 
                        _blockList.Insert(blockIndex, prefixBlock);
                    } 
 
                    return;
                } 
            }

            // we couldn't find a raw data block for mapping this, we can only throw
            throw new FileFormatException(SR.Get(SRID.CorruptedData)); 
        }