private void SwitchModeIfNecessary() { if (this._isolatedStorageMode) { if (this._isolatedStorageStream.Length < this._lowWaterMark) { if (this._isolatedStorageStream.Length > 0L) { MemoryStreamBlock item = new MemoryStreamBlock(this._trackingMemoryStreamFactory.Create((int)this._isolatedStorageStream.Length), 0L); this._isolatedStorageStream.Seek(0L, SeekOrigin.Begin); item.Stream.Seek(0L, SeekOrigin.Begin); PackagingUtilities.CopyStream(this._isolatedStorageStream, item.Stream, 0x7fffffffffffffffL, 0x80000); this._memoryStreamList.Add(item); } this._isolatedStorageMode = false; this._isolatedStorageStream.SetLength(0L); this._isolatedStorageStream.Flush(); } } else if (this._trackingMemoryStreamFactory.CurrentMemoryConsumption > this._highWaterMark) { this.EnsureIsolatedStoreStream(); this.CopyMemoryBlocksToStream(this._isolatedStorageStream); this._isolatedStorageMode = true; foreach (MemoryStreamBlock block2 in this._memoryStreamList) { block2.Stream.Close(); } this._memoryStreamList.Clear(); } }
internal void WriteToStream(Stream stream) { if (this._isolatedStorageMode) { this._isolatedStorageStream.Seek(0L, SeekOrigin.Begin); PackagingUtilities.CopyStream(this._isolatedStorageStream, stream, 0x7fffffffffffffffL, 0x80000); } else { this.CopyMemoryBlocksToStream(stream); } }
internal static PreSaveNotificationScanControlInstruction CommonPreSaveNotificationHandler(Stream stream, long offset, long size, long onDiskOffset, long onDiskSize, ref SparseMemoryStream cachePrefixStream) { if (size != 0L) { long num2; long num4; if (cachePrefixStream != null) { onDiskOffset += cachePrefixStream.Length; onDiskSize -= cachePrefixStream.Length; } if (onDiskSize == 0L) { return(PreSaveNotificationScanControlInstruction.Continue); } PackagingUtilities.CalculateOverlap(onDiskOffset, onDiskSize, offset, size, out num4, out num2); if (num2 <= 0L) { if (onDiskOffset <= offset) { return(PreSaveNotificationScanControlInstruction.Continue); } return(PreSaveNotificationScanControlInstruction.Stop); } long bytesToCopy = (num4 + num2) - onDiskOffset; if (cachePrefixStream == null) { cachePrefixStream = new SparseMemoryStream(0x19000L, 0xa00000L); } else { cachePrefixStream.Seek(0L, SeekOrigin.End); } stream.Seek(onDiskOffset, SeekOrigin.Begin); if (PackagingUtilities.CopyStream(stream, cachePrefixStream, bytesToCopy, 0x1000) != bytesToCopy) { throw new FileFormatException(SR.Get("CorruptedData")); } if ((onDiskOffset + onDiskSize) < (offset + size)) { return(PreSaveNotificationScanControlInstruction.Continue); } } return(PreSaveNotificationScanControlInstruction.Stop); }