//callback from CopyFileEx, call from back back thread private CopyFileExCallbackReturns copy_progress_proc(UInt64 TotalFileSize, UInt64 TotalBytesTransferred, UInt64 StreamSize, UInt64 StreamBytesTransferred, int dwStreamNumber, CopyFileExState dwCallbackReason, IntPtr hSourceFile, IntPtr hDestinationFile, IntPtr lpData) { //early exit if progress dialog absent or begin close if (progress_dialog == null) { return(CopyFileExCallbackReturns.QUIET); } if (ProgressCloseBeginSafe) { stop(); return(CopyFileExCallbackReturns.CANCEL); } var e = new UpdateProgressArgs(); current_file_bytes_transferred = TotalBytesTransferred; var speed = calc_speed(); if (dwCallbackReason == CopyFileExState.STREAM_SWITCH) { //new stream begin copy //retrieve file names from lpData var src = string.Empty; var dst = string.Empty; IOhelper.strings_from_buffer(ref src, ref dst, lpData); //set update args e.DestinationFile = dst; e.SourceFile = src; e.Reason = UpdateProgressReason.StreamSwitch; } else { e.Reason = UpdateProgressReason.ChunkFinish; } //set update args e.KBytesPerSec = speed; e.StreamSize = StreamSize; e.StreamTransferred = StreamBytesTransferred; e.TotalTransferred = total_bytes_transferred + current_file_bytes_transferred; e.FilesCopied = total_files_copied; e.EnableTotalProgress = ((options & CopyEngineOptions.CalculateTotalSize) == CopyEngineOptions.CalculateTotalSize); e.TotalSize = total_source_bytes; //check progress dialog if (ProgressCloseBeginSafe) { stop(); return(CopyFileExCallbackReturns.CANCEL); } //and try invoke //sync errors may be if progress dialog close before invoking update_progress_safe(e); if (ProgressCloseBeginSafe) { stop(); return(CopyFileExCallbackReturns.CANCEL); } //need try becouse sync error may occur if progress_dialog closed try { if (progress_dialog.CancelPressedSafe) { stop(); return(CopyFileExCallbackReturns.CANCEL); } else { return(CopyFileExCallbackReturns.CONTINUE); } } catch { //and if error occur -> stop copy stop(); return(CopyFileExCallbackReturns.CANCEL); } }
//callback from CopyFileEx, call from back back thread private CopyFileExCallbackReturns move_progress_proc(UInt64 TotalFileSize, UInt64 TotalBytesTransferred, UInt64 StreamSize, UInt64 StreamBytesTransferred, int dwStreamNumber, CopyFileExState dwCallbackReason, IntPtr hSourceFile, IntPtr hDestinationFile, IntPtr lpData) { if (progress_dialog == null) { return(CopyFileExCallbackReturns.QUIET); } if (ProgressCloseBeginSafe) { return(CopyFileExCallbackReturns.CANCEL); } var e = new UpdateProgressArgs(); if (dwCallbackReason == CopyFileExState.STREAM_SWITCH) { var src = string.Empty; var dts = string.Empty; IOhelper.strings_from_buffer(ref src, ref dts, lpData); e.SourceFile = src; e.DestinationFile = dts; e.Reason = UpdateProgressReason.StreamSwitch; } else { e.Reason = UpdateProgressReason.ChunkFinish; } e.EnableTotalProgress = false; e.StreamSize = StreamSize; e.StreamTransferred = StreamBytesTransferred; update_progress_safe(e); //need try becouse sync error may occur if progress_dialog closed try { if (progress_dialog.CancelPressedSafe) { AbortJobSafe = true; return(CopyFileExCallbackReturns.CANCEL); } else { return(CopyFileExCallbackReturns.CONTINUE); } } catch { //and if error occur -> stop copy AbortJobSafe = true; return(CopyFileExCallbackReturns.CANCEL); } }