private void Initialize() { _currentFile = null; _currentDirectory = null; _averageTransferRate = new TransferRateInfo(); _fileChunkStopwatch = new Stopwatch(); _stopPending = false; }
private void CopyFile(IFileInfo source, IFileInfo target) { _currentFile = new FileProgressInfo(source); if (FileStarted != null) { var fileSystemItemStartedEventArgs = new FileSystemItemStartedEventArgs(source.FullName, target.FullName, source.Length); OnFileStarted(fileSystemItemStartedEventArgs); if (fileSystemItemStartedEventArgs.Cancel) { return; } } CopyFileHelper(source, target); if (FileComplete != null) { OnFileComplete(new FileSystemItemCompleteEventArgs(source.FullName, target.FullName, source.Length, _currentFile.Stopwatch.Elapsed)); } }
private void CopyFileHelper(IFileInfo sourceFile, IFileInfo destinationFile) { _currentFile = new FileProgressInfo(sourceFile); _currentFile.Stopwatch.Start(); var success = CopyFileEx(sourceFile.FullName, destinationFile.FullName, CopyProgressCallback, IntPtr.Zero, false, CopyFileAllowDecryptedDestination); if (success) { destinationFile.Attributes = sourceFile.Attributes; } _currentFile.Stopwatch.Stop(); //Throw an exception if the copy failed if (!success) { int error = Marshal.GetLastWin32Error(); if (error != 1235) { throw new Win32Exception(error); } } }