Esempio n. 1
0
        public bool HasChanges()
        {
            if (_readOnly)
            {
                return(false);
            }
            if (_totalLength != _stream.Length)
            {
                return(true);
            }
            long num = 0L;

            for (DataBlock dataBlock = _dataMap.FirstBlock; dataBlock != null; dataBlock = dataBlock.NextBlock)
            {
                FileDataBlock fileDataBlock = dataBlock as FileDataBlock;
                if (fileDataBlock == null || fileDataBlock.FileOffset != num)
                {
                    return(true);
                }
                num += fileDataBlock.Length;
            }
            return(num != _stream.Length);
        }
Esempio n. 2
0
 private void MoveFileBlock(FileDataBlock fileBlock, long dataOffset)
 {
     long nextDataOffset;
     FileDataBlock nextFileDataBlock = GetNextFileDataBlock((DataBlock)fileBlock, dataOffset, out nextDataOffset);
     if (nextFileDataBlock != null && dataOffset + fileBlock.Length > nextFileDataBlock.FileOffset)
         MoveFileBlock(nextFileDataBlock, nextDataOffset);
     if (fileBlock.FileOffset > dataOffset)
     {
         byte[] buffer = new byte[4096];
         long num1 = 0L;
         while (num1 < fileBlock.Length)
         {
             long num2 = fileBlock.FileOffset + num1;
             int count = (int)Math.Min((long)buffer.Length, fileBlock.Length - num1);
             _stream.Position = num2;
             _stream.Read(buffer, 0, count);
             _stream.Position = dataOffset + num1;
             _stream.Write(buffer, 0, count);
             num1 += (long)buffer.Length;
         }
     }
     else
     {
         byte[] buffer = new byte[4096];
         long num = 0L;
         while (num < fileBlock.Length)
         {
             int count = (int)Math.Min((long)buffer.Length, fileBlock.Length - num);
             _stream.Position = fileBlock.FileOffset + fileBlock.Length - num - (long)count;
             _stream.Read(buffer, 0, count);
             _stream.Position = dataOffset + fileBlock.Length - num - (long)count;
             _stream.Write(buffer, 0, count);
             num += (long)buffer.Length;
         }
     }
     fileBlock.SetFileOffset(dataOffset);
 }
Esempio n. 3
0
 public void WriteByte(long index, byte value)
 {
     try
     {
         long blockOffset;
         DataBlock dataBlock = GetDataBlock(index, out blockOffset);
         MemoryDataBlock memoryDataBlock1 = dataBlock as MemoryDataBlock;
         if (memoryDataBlock1 != null)
         {
             memoryDataBlock1.Data[index - blockOffset] = value;
         }
         else
         {
             FileDataBlock fileDataBlock1 = (FileDataBlock)dataBlock;
             if (blockOffset == index && dataBlock.PreviousBlock != null)
             {
                 MemoryDataBlock memoryDataBlock2 = dataBlock.PreviousBlock as MemoryDataBlock;
                 if (memoryDataBlock2 != null)
                 {
                     memoryDataBlock2.AddByteToEnd(value);
                     fileDataBlock1.RemoveBytesFromStart(1L);
                     if (fileDataBlock1.Length != 0L)
                         return;
                     _dataMap.Remove((DataBlock)fileDataBlock1);
                     return;
                 }
             }
             if (blockOffset + fileDataBlock1.Length - 1L == index && dataBlock.NextBlock != null)
             {
                 MemoryDataBlock memoryDataBlock2 = dataBlock.NextBlock as MemoryDataBlock;
                 if (memoryDataBlock2 != null)
                 {
                     memoryDataBlock2.AddByteToStart(value);
                     fileDataBlock1.RemoveBytesFromEnd(1L);
                     if (fileDataBlock1.Length != 0L)
                         return;
                     _dataMap.Remove((DataBlock)fileDataBlock1);
                     return;
                 }
             }
             FileDataBlock fileDataBlock2 = (FileDataBlock)null;
             if (index > blockOffset)
                 fileDataBlock2 = new FileDataBlock(fileDataBlock1.FileOffset, index - blockOffset);
             FileDataBlock fileDataBlock3 = (FileDataBlock)null;
             if (index < blockOffset + fileDataBlock1.Length - 1L)
                 fileDataBlock3 = new FileDataBlock(fileDataBlock1.FileOffset + index - blockOffset + 1L, fileDataBlock1.Length - (index - blockOffset + 1L));
             DataBlock block = _dataMap.Replace(dataBlock, (DataBlock)new MemoryDataBlock(value));
             if (fileDataBlock2 != null)
                 _dataMap.AddBefore(block, (DataBlock)fileDataBlock2);
             if (fileDataBlock3 == null)
                 return;
             _dataMap.AddAfter(block, (DataBlock)fileDataBlock3);
         }
     }
     finally
     {
         OnChanged(EventArgs.Empty);
     }
 }
Esempio n. 4
0
 public void InsertBytes(long index, byte[] bs)
 {
     try
     {
         long blockOffset;
         DataBlock dataBlock = GetDataBlock(index, out blockOffset);
         MemoryDataBlock memoryDataBlock1 = dataBlock as MemoryDataBlock;
         if (memoryDataBlock1 != null)
         {
             memoryDataBlock1.InsertBytes(index - blockOffset, bs);
         }
         else
         {
             FileDataBlock fileDataBlock1 = (FileDataBlock)dataBlock;
             if (blockOffset == index && dataBlock.PreviousBlock != null)
             {
                 MemoryDataBlock memoryDataBlock2 = dataBlock.PreviousBlock as MemoryDataBlock;
                 if (memoryDataBlock2 != null)
                 {
                     memoryDataBlock2.InsertBytes(memoryDataBlock2.Length, bs);
                     return;
                 }
             }
             FileDataBlock fileDataBlock2 = (FileDataBlock)null;
             if (index > blockOffset)
                 fileDataBlock2 = new FileDataBlock(fileDataBlock1.FileOffset, index - blockOffset);
             FileDataBlock fileDataBlock3 = (FileDataBlock)null;
             if (index < blockOffset + fileDataBlock1.Length)
                 fileDataBlock3 = new FileDataBlock(fileDataBlock1.FileOffset + index - blockOffset, fileDataBlock1.Length - (index - blockOffset));
             DataBlock block = _dataMap.Replace(dataBlock, (DataBlock)new MemoryDataBlock(bs));
             if (fileDataBlock2 != null)
                 _dataMap.AddBefore(block, (DataBlock)fileDataBlock2);
             if (fileDataBlock3 == null)
                 return;
             _dataMap.AddAfter(block, (DataBlock)fileDataBlock3);
         }
     }
     finally
     {
         _totalLength += (long)bs.Length;
         OnLengthChanged(EventArgs.Empty);
         OnChanged(EventArgs.Empty);
     }
 }
Esempio n. 5
0
 public void WriteByte(long index, byte value)
 {
     try
     {
         long            num;
         DataBlock       dataBlock = this.GetDataBlock(index, out num);
         MemoryDataBlock block2    = dataBlock as MemoryDataBlock;
         if (block2 != null)
         {
             block2.Data[(int)((IntPtr)(index - num))] = value;
         }
         else
         {
             FileDataBlock block = (FileDataBlock)dataBlock;
             if ((num == index) && (dataBlock.PreviousBlock != null))
             {
                 MemoryDataBlock previousBlock = dataBlock.PreviousBlock as MemoryDataBlock;
                 if (previousBlock != null)
                 {
                     previousBlock.AddByteToEnd(value);
                     block.RemoveBytesFromStart(1L);
                     if (block.Length == 0L)
                     {
                         this._dataMap.Remove(block);
                     }
                     return;
                 }
             }
             if ((((num + block.Length) - 1L) == index) && (dataBlock.NextBlock != null))
             {
                 MemoryDataBlock nextBlock = dataBlock.NextBlock as MemoryDataBlock;
                 if (nextBlock != null)
                 {
                     nextBlock.AddByteToStart(value);
                     block.RemoveBytesFromEnd(1L);
                     if (block.Length == 0L)
                     {
                         this._dataMap.Remove(block);
                     }
                     return;
                 }
             }
             FileDataBlock newBlock = null;
             if (index > num)
             {
                 newBlock = new FileDataBlock(block.FileOffset, index - num);
             }
             FileDataBlock block7 = null;
             if (index < ((num + block.Length) - 1L))
             {
                 block7 = new FileDataBlock(((block.FileOffset + index) - num) + 1L, block.Length - ((index - num) + 1L));
             }
             dataBlock = this._dataMap.Replace(dataBlock, new MemoryDataBlock(value));
             if (newBlock != null)
             {
                 this._dataMap.AddBefore(dataBlock, newBlock);
             }
             if (block7 != null)
             {
                 this._dataMap.AddAfter(dataBlock, block7);
             }
         }
     }
     finally
     {
         this.OnChanged(EventArgs.Empty);
     }
 }
Esempio n. 6
0
 public void WriteByte(long index, byte value)
 {
     try
     {
         long            blockOffset;
         DataBlock       dataBlock        = GetDataBlock(index, out blockOffset);
         MemoryDataBlock memoryDataBlock1 = dataBlock as MemoryDataBlock;
         if (memoryDataBlock1 != null)
         {
             memoryDataBlock1.Data[index - blockOffset] = value;
         }
         else
         {
             FileDataBlock fileDataBlock1 = (FileDataBlock)dataBlock;
             if (blockOffset == index && dataBlock.PreviousBlock != null)
             {
                 MemoryDataBlock memoryDataBlock2 = dataBlock.PreviousBlock as MemoryDataBlock;
                 if (memoryDataBlock2 != null)
                 {
                     memoryDataBlock2.AddByteToEnd(value);
                     fileDataBlock1.RemoveBytesFromStart(1L);
                     if (fileDataBlock1.Length != 0L)
                     {
                         return;
                     }
                     _dataMap.Remove((DataBlock)fileDataBlock1);
                     return;
                 }
             }
             if (blockOffset + fileDataBlock1.Length - 1L == index && dataBlock.NextBlock != null)
             {
                 MemoryDataBlock memoryDataBlock2 = dataBlock.NextBlock as MemoryDataBlock;
                 if (memoryDataBlock2 != null)
                 {
                     memoryDataBlock2.AddByteToStart(value);
                     fileDataBlock1.RemoveBytesFromEnd(1L);
                     if (fileDataBlock1.Length != 0L)
                     {
                         return;
                     }
                     _dataMap.Remove((DataBlock)fileDataBlock1);
                     return;
                 }
             }
             FileDataBlock fileDataBlock2 = (FileDataBlock)null;
             if (index > blockOffset)
             {
                 fileDataBlock2 = new FileDataBlock(fileDataBlock1.FileOffset, index - blockOffset);
             }
             FileDataBlock fileDataBlock3 = (FileDataBlock)null;
             if (index < blockOffset + fileDataBlock1.Length - 1L)
             {
                 fileDataBlock3 = new FileDataBlock(fileDataBlock1.FileOffset + index - blockOffset + 1L, fileDataBlock1.Length - (index - blockOffset + 1L));
             }
             DataBlock block = _dataMap.Replace(dataBlock, (DataBlock) new MemoryDataBlock(value));
             if (fileDataBlock2 != null)
             {
                 _dataMap.AddBefore(block, (DataBlock)fileDataBlock2);
             }
             if (fileDataBlock3 == null)
             {
                 return;
             }
             _dataMap.AddAfter(block, (DataBlock)fileDataBlock3);
         }
     }
     finally
     {
         OnChanged(EventArgs.Empty);
     }
 }
 public void WriteByte(long index, byte value)
 {
     try
     {
         long num;
         DataBlock dataBlock = this.GetDataBlock(index, out num);
         MemoryDataBlock block2 = dataBlock as MemoryDataBlock;
         if (block2 != null)
         {
             block2.Data[(int) ((IntPtr) (index - num))] = value;
         }
         else
         {
             FileDataBlock block = (FileDataBlock) dataBlock;
             if ((num == index) && (dataBlock.PreviousBlock != null))
             {
                 MemoryDataBlock previousBlock = dataBlock.PreviousBlock as MemoryDataBlock;
                 if (previousBlock != null)
                 {
                     previousBlock.AddByteToEnd(value);
                     block.RemoveBytesFromStart(1L);
                     if (block.Length == 0L)
                     {
                         this._dataMap.Remove(block);
                     }
                     return;
                 }
             }
             if ((((num + block.Length) - 1L) == index) && (dataBlock.NextBlock != null))
             {
                 MemoryDataBlock nextBlock = dataBlock.NextBlock as MemoryDataBlock;
                 if (nextBlock != null)
                 {
                     nextBlock.AddByteToStart(value);
                     block.RemoveBytesFromEnd(1L);
                     if (block.Length == 0L)
                     {
                         this._dataMap.Remove(block);
                     }
                     return;
                 }
             }
             FileDataBlock newBlock = null;
             if (index > num)
             {
                 newBlock = new FileDataBlock(block.FileOffset, index - num);
             }
             FileDataBlock block7 = null;
             if (index < ((num + block.Length) - 1L))
             {
                 block7 = new FileDataBlock(((block.FileOffset + index) - num) + 1L, block.Length - ((index - num) + 1L));
             }
             dataBlock = this._dataMap.Replace(dataBlock, new MemoryDataBlock(value));
             if (newBlock != null)
             {
                 this._dataMap.AddBefore(dataBlock, newBlock);
             }
             if (block7 != null)
             {
                 this._dataMap.AddAfter(dataBlock, block7);
             }
         }
     }
     finally
     {
         this.OnChanged(EventArgs.Empty);
     }
 }
 private void MoveFileBlock(FileDataBlock fileBlock, long dataOffset)
 {
     long num;
     FileDataBlock block = this.GetNextFileDataBlock(fileBlock, dataOffset, out num);
     if ((block != null) && ((dataOffset + fileBlock.Length) > block.FileOffset))
     {
         this.MoveFileBlock(block, num);
     }
     if (fileBlock.FileOffset > dataOffset)
     {
         byte[] buffer = new byte[0x1000];
         for (long i = 0L; i < fileBlock.Length; i += buffer.Length)
         {
             long num3 = fileBlock.FileOffset + i;
             int count = (int) Math.Min((long) buffer.Length, fileBlock.Length - i);
             this._stream.Position = num3;
             this._stream.Read(buffer, 0, count);
             long num5 = dataOffset + i;
             this._stream.Position = num5;
             this._stream.Write(buffer, 0, count);
         }
     }
     else
     {
         byte[] buffer2 = new byte[0x1000];
         for (long j = 0L; j < fileBlock.Length; j += buffer2.Length)
         {
             int num7 = (int) Math.Min((long) buffer2.Length, fileBlock.Length - j);
             long num8 = ((fileBlock.FileOffset + fileBlock.Length) - j) - num7;
             this._stream.Position = num8;
             this._stream.Read(buffer2, 0, num7);
             long num9 = ((dataOffset + fileBlock.Length) - j) - num7;
             this._stream.Position = num9;
             this._stream.Write(buffer2, 0, num7);
         }
     }
     fileBlock.SetFileOffset(dataOffset);
 }
 public void InsertBytes(long index, byte[] bs)
 {
     try
     {
         long num;
         DataBlock dataBlock = this.GetDataBlock(index, out num);
         MemoryDataBlock block2 = dataBlock as MemoryDataBlock;
         if (block2 != null)
         {
             block2.InsertBytes(index - num, bs);
         }
         else
         {
             FileDataBlock block3 = (FileDataBlock) dataBlock;
             if ((num == index) && (dataBlock.PreviousBlock != null))
             {
                 MemoryDataBlock previousBlock = dataBlock.PreviousBlock as MemoryDataBlock;
                 if (previousBlock != null)
                 {
                     previousBlock.InsertBytes(previousBlock.Length, bs);
                     return;
                 }
             }
             FileDataBlock newBlock = null;
             if (index > num)
             {
                 newBlock = new FileDataBlock(block3.FileOffset, index - num);
             }
             FileDataBlock block6 = null;
             if (index < (num + block3.Length))
             {
                 block6 = new FileDataBlock((block3.FileOffset + index) - num, block3.Length - (index - num));
             }
             dataBlock = this._dataMap.Replace(dataBlock, new MemoryDataBlock(bs));
             if (newBlock != null)
             {
                 this._dataMap.AddBefore(dataBlock, newBlock);
             }
             if (block6 != null)
             {
                 this._dataMap.AddAfter(dataBlock, block6);
             }
         }
     }
     finally
     {
         this._totalLength += bs.Length;
         this.OnLengthChanged(EventArgs.Empty);
         this.OnChanged(EventArgs.Empty);
     }
 }