private bool CopyVfsFileInternal(IArchiveFile vfsFile, string filename) { CopyProgressEventArgs args = new CopyProgressEventArgs { CurrentFileSize = vfsFile.Size, CurrentFile = vfsFile.Name, BytesCopied = 0, TotalBytesCopied = 0 }; using (Stream inStream = vfsFile.OpenStream()) { using (Stream outStream = FileSystem.Current.GetFile(filename).OpenStreamWithTimeout(FileMode.Create, FileAccess.Write, FileShare.None)) { long bytesRemaining = vfsFile.Size; byte[] buffer = new byte[BUFFER_SIZE]; while (bytesRemaining > 0) { int bytesRead = (int)(bytesRemaining < BUFFER_SIZE ? bytesRemaining : BUFFER_SIZE); inStream.Read(buffer, 0, bytesRead); outStream.Write(buffer, 0, bytesRead); bytesRemaining -= bytesRead; args.TotalBytesCopied += bytesRead; args.BytesCopied += bytesRead; if (OnCopyProgress != null && (args.BytesCopied % PROGRESS_INCREMENT_SIZE == 0)) { OnCopyProgress(this, args); args.BytesCopied = 0; if (args.Cancel) { Cancel(); return(true); } } } } } if (OnCopyProgress != null) { OnCopyProgress(this, args); } return(false); }
private bool CopyVfsFileInternal(IArchiveFile vfsFile, string filename) { CopyProgressEventArgs args = new CopyProgressEventArgs { CurrentFileSize = vfsFile.Size, CurrentFile = vfsFile.Name, BytesCopied = 0, TotalBytesCopied = 0 }; using (Stream inStream = vfsFile.OpenStream()) { using (Stream outStream = FileSystem.Current.GetFile(filename).OpenStreamWithTimeout(FileMode.Create,FileAccess.Write,FileShare.None)) { long bytesRemaining = vfsFile.Size; byte[] buffer = new byte[BUFFER_SIZE]; while (bytesRemaining > 0) { int bytesRead = (int)(bytesRemaining < BUFFER_SIZE ? bytesRemaining : BUFFER_SIZE); inStream.Read(buffer, 0, bytesRead); outStream.Write(buffer, 0, bytesRead); bytesRemaining -= bytesRead; args.TotalBytesCopied += bytesRead; args.BytesCopied += bytesRead; if (OnCopyProgress != null && (args.BytesCopied % PROGRESS_INCREMENT_SIZE == 0)) { OnCopyProgress(this, args); args.BytesCopied = 0; if (args.Cancel) { Cancel(); return true; } } } } } if (OnCopyProgress != null) { OnCopyProgress(this, args); } return false; }