Example #1
0
        public bool DoCopy4()  // with kernel32.dll  CopyFile2  -- ооооочень медленно!!
        {
            while (!_bCancelCopying && (_bPause || _bPauseFile))
            {
                System.Threading.Thread.Sleep(300);
            }

            bool bRetVal = false;

            if (!_bCancelCopying)
            {
                COPYFILE2_EXTENDED_PARAMETERS stParams = new COPYFILE2_EXTENDED_PARAMETERS();
                int    bCancel = 0;
                int    size    = Marshal.SizeOf(bCancel);
                IntPtr pBool   = Marshal.AllocHGlobal(size);
                Marshal.WriteInt32(pBool, 0, bCancel);  // last parameter 0 (FALSE), 1 (TRUE)

                stParams.dwSize            = (uint)Marshal.SizeOf(stParams);
                stParams.dwCopyFlags       = Copy2FileFlags.COPY_FILE_NO_BUFFERING | Copy2FileFlags.COPY_FILE_RESTARTABLE;
                stParams.pfCancel          = pBool;
                stParams.pProgressRoutine  = null;
                stParams.pvCallbackContext = IntPtr.Zero;
                bRetVal = CopyFile2(_sSrcFile, _sDestFile, ref stParams);
                Marshal.FreeHGlobal(pBool);
            }
            return(bRetVal);
        }
Example #2
0
        /// <summary>
        /// CopyFile2 wrapper. Only available on Windows8 and above.
        /// </summary>
        public unsafe static void CopyFile2(string source, string destination, bool overwrite = false)
        {
            Boolean32 cancel = false;
            COPYFILE2_EXTENDED_PARAMETERS parameters = new COPYFILE2_EXTENDED_PARAMETERS()
            {
                dwSize      = (uint)sizeof(COPYFILE2_EXTENDED_PARAMETERS),
                pfCancel    = &cancel,
                dwCopyFlags = overwrite ? 0 : CopyFileFlags.FailIfExists
            };

            Imports.CopyFile2(source, destination, ref parameters).ThrowIfFailed();
        }
Example #3
0
        /// <summary>
        /// CopyFile2 wrapper. Only available on Windows8 and above.
        /// </summary>
        public static void CopyFile2(string source, string destination, bool overwrite = false)
        {
            unsafe
            {
                int cancel = 0;
                COPYFILE2_EXTENDED_PARAMETERS parameters = new COPYFILE2_EXTENDED_PARAMETERS();
                parameters.dwSize      = (uint)Marshal.SizeOf <COPYFILE2_EXTENDED_PARAMETERS>();
                parameters.pfCanel     = &cancel;
                parameters.dwCopyFlags = overwrite ? 0 : CopyFileFlags.COPY_FILE_FAIL_IF_EXISTS;

                HRESULT hr = Direct.CopyFile2(source, destination, &parameters);
                if (ErrorMacros.FAILED(hr))
                {
                    throw ErrorHelper.GetIoExceptionForHResult(hr, source);
                }
            }
        }
Example #4
0
        /// <summary>
        /// CopyFile2 wrapper. Only available on Windows8 and above.
        /// </summary>
        public static void CopyFile2(string source, string destination, bool overwrite = false)
        {
            unsafe
            {
                int cancel = 0;
                COPYFILE2_EXTENDED_PARAMETERS parameters = new COPYFILE2_EXTENDED_PARAMETERS()
                {
                    dwSize      = (uint)sizeof(COPYFILE2_EXTENDED_PARAMETERS),
                    pfCanel     = &cancel,
                    dwCopyFlags = overwrite ? 0 : CopyFileFlags.COPY_FILE_FAIL_IF_EXISTS
                };

                HRESULT hr = Imports.CopyFile2(source, destination, &parameters);
                if (ErrorMacros.FAILED(hr))
                {
                    throw Errors.GetIoExceptionForHResult(hr, source);
                }
            }
        }
Example #5
0
 internal static extern int CopyFile2(string pwszExistingFileName, string pwszNewFileName, ref COPYFILE2_EXTENDED_PARAMETERS pExtendedParameters);
Example #6
0
 internal static extern int CopyFile2(string pwszExistingFileName, string pwszNewFileName, ref COPYFILE2_EXTENDED_PARAMETERS pExtendedParameters);
Example #7
0
 private static extern bool CopyFile2(string lpExistingFileName, string lpNewFileName, ref COPYFILE2_EXTENDED_PARAMETERS pExtendedParameters);