public override void CopyFile(string sourceFullPath, string destFullPath, bool overwrite)
{
Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = default(Interop.Kernel32.SECURITY_ATTRIBUTES);
int errorCode = Interop.Kernel32.CopyFile(sourceFullPath, destFullPath, !overwrite);
if (errorCode != Interop.Errors.ERROR_SUCCESS)
{
string fileName = destFullPath;
if (errorCode != Interop.Errors.ERROR_FILE_EXISTS)
{
// For a number of error codes (sharing violation, path
// not found, etc) we don't know if the problem was with
// the source or dest file. Try reading the source file.
using (SafeFileHandle handle = Interop.Kernel32.UnsafeCreateFile(sourceFullPath, GENERIC_READ, FileShare.Read, ref secAttrs, FileMode.Open, 0, IntPtr.Zero))
{
if (handle.IsInvalid)
fileName = sourceFullPath;
}
if (errorCode == Interop.Errors.ERROR_ACCESS_DENIED)
{
if (DirectoryExists(destFullPath))
throw new IOException(SR.Format(SR.Arg_FileIsDirectory_Name, destFullPath), Interop.Errors.ERROR_ACCESS_DENIED);
}
}
throw Win32Marshal.GetExceptionForWin32Error(errorCode, fileName);
}
}