示例#1
0
#pragma warning restore 169
        // ReSharper restore InconsistentNaming

        #region Methods

        /// <summary>
        /// The CopyProgressRoutine delegate is an application-defined callback function used with the CopyFileEx and MoveFileWithProgress functions.
        /// It is called when a portion of a copy or move operation is completed.
        /// </summary>
        /// <param name="totalFileSize">Total size of the file, in bytes.</param>
        /// <param name="totalBytesTransferred">Total number of bytes transferred from the source file to the destination file since the copy operation began.</param>
        /// <param name="streamSize">Total size of the current file stream, in bytes.</param>
        /// <param name="streamBytesTransferred">Total number of bytes in the current stream that have been transferred from the source file to the destination file since the copy operation began. </param>
        /// <param name="dwStreamNumber">Handle to the current stream. The first time CopyProgressRoutine is called, the stream number is 1.</param>
        /// <param name="dwCallbackReason">Reason that CopyProgressRoutine was called.</param>
        /// <param name="hSourceFile">Handle to the source file.</param>
        /// <param name="hDestinationFile">Handle to the destination file.</param>
        /// <param name="lpData">Argument passed to CopyProgressRoutine by the CopyFileEx or MoveFileWithProgress function.</param>
        /// <returns>A value indicating how to proceed with the copy operation.</returns>
        protected uint CopyProgressCallback(
            long totalFileSize,
            long totalBytesTransferred,
            long streamSize,
            long streamBytesTransferred,
            uint dwStreamNumber,
            uint dwCallbackReason,
            IntPtr hSourceFile,
            IntPtr hDestinationFile,
            IntPtr lpData)
        {
            switch (dwCallbackReason)
            {
            case CALLBACK_CHUNK_FINISHED:
                // Another part of the file was copied.
                var e = new CopyProgressEventArgs(totalFileSize, totalBytesTransferred);
                InvokeCopyProgress(e);
                return(e.Cancel ? PROGRESS_CANCEL : PROGRESS_CONTINUE);

            case CALLBACK_STREAM_SWITCH:
                // A new stream was created. We don't care about this one - just continue the move operation.
                return(PROGRESS_CONTINUE);

            default:
                return(PROGRESS_CONTINUE);
            }
        }
示例#2
0
 protected void InvokeCopyProgress(CopyProgressEventArgs e)
 {
     if (CopyProgress != null)
     {
         CopyProgress(this, e);
     }
 }
示例#3
0
        void CopierExCopyProgress(object sender, CopyProgressEventArgs e)
        {
            var percent = (int)(e.TotalBytesTransferred * 100 / (e.TotalFileSize * 1.0));

            progressBar1.SetPropertyThreadSafe(() => progressBar1.Value, percent);

            if (_cancelled)
            {
                e.Cancel = true;
            }
        }
示例#4
0
        void CopierExCopyProgress(object sender, CopyProgressEventArgs e)
        {
            var percent = (int)(e.TotalBytesTransferred * 100 / (e.TotalFileSize * 1.0));
            progressBar1.SetPropertyThreadSafe(() => progressBar1.Value, percent);

            if (_cancelled)
                e.Cancel = true;
        }
示例#5
0
#pragma warning restore 169
        // ReSharper restore InconsistentNaming

        #region Methods

        /// <summary>
        /// The CopyProgressRoutine delegate is an application-defined callback function used with the CopyFileEx and MoveFileWithProgress functions.
        /// It is called when a portion of a copy or move operation is completed.
        /// </summary>
        /// <param name="totalFileSize">Total size of the file, in bytes.</param>
        /// <param name="totalBytesTransferred">Total number of bytes transferred from the source file to the destination file since the copy operation began.</param>
        /// <param name="streamSize">Total size of the current file stream, in bytes.</param>
        /// <param name="streamBytesTransferred">Total number of bytes in the current stream that have been transferred from the source file to the destination file since the copy operation began. </param>
        /// <param name="dwStreamNumber">Handle to the current stream. The first time CopyProgressRoutine is called, the stream number is 1.</param>
        /// <param name="dwCallbackReason">Reason that CopyProgressRoutine was called.</param>
        /// <param name="hSourceFile">Handle to the source file.</param>
        /// <param name="hDestinationFile">Handle to the destination file.</param>
        /// <param name="lpData">Argument passed to CopyProgressRoutine by the CopyFileEx or MoveFileWithProgress function.</param>
        /// <returns>A value indicating how to proceed with the copy operation.</returns>
        protected uint CopyProgressCallback(
            long totalFileSize,
            long totalBytesTransferred,
            long streamSize,
            long streamBytesTransferred,
            uint dwStreamNumber,
            uint dwCallbackReason,
            IntPtr hSourceFile,
            IntPtr hDestinationFile,
            IntPtr lpData)
        {
            switch (dwCallbackReason)
            {
                case CALLBACK_CHUNK_FINISHED:
                    // Another part of the file was copied.
                    var e = new CopyProgressEventArgs(totalFileSize, totalBytesTransferred);
                    InvokeCopyProgress(e);
                    return e.Cancel ? PROGRESS_CANCEL : PROGRESS_CONTINUE;

                case CALLBACK_STREAM_SWITCH:
                    // A new stream was created. We don't care about this one - just continue the move operation.
                    return PROGRESS_CONTINUE;

                default:
                    return PROGRESS_CONTINUE;
            }
        }
示例#6
0
 protected void InvokeCopyProgress(CopyProgressEventArgs e)
 {
     if (CopyProgress != null)
     {
         CopyProgress(this, e);
     }
 }