From: Kartavya Vashishtha sendtokartavya@gmail.com
- add FIXME messages for callback and cancel_ptr parameters in CopyFile2 and CopyFileEx
- initialize all elements of CopyFile2 params --- dlls/kernelbase/file.c | 63 +++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 22 deletions(-)
diff --git a/dlls/kernelbase/file.c b/dlls/kernelbase/file.c index cc21f11117a..22fb00926fb 100644 --- a/dlls/kernelbase/file.c +++ b/dlls/kernelbase/file.c @@ -487,15 +487,9 @@ BOOL WINAPI DECLSPEC_HOTPATCH AreFileApisANSI(void) return !oem_file_apis; }
-/*********************************************************************** - * CopyFile2 (kernelbase.@) - * - * FIXME: Silently ignores: - * the callback function - * cancel_ptr - */ -HRESULT WINAPI CopyFile2 ( const PCWSTR source , const PCWSTR dest, COPYFILE2_EXTENDED_PARAMETERS* params) { - static const int buffer_size = 65536; +// uses the SetLastError style of error handling +static BOOL CopyFile2_impl ( const PCWSTR source, const PCWSTR dest, COPYFILE2_EXTENDED_PARAMETERS* params) { + static const int buffer_size = 65536; HANDLE h1, h2; FILE_BASIC_INFORMATION info; IO_STATUS_BLOCK io; @@ -504,14 +498,24 @@ HRESULT WINAPI CopyFile2 ( const PCWSTR source , const PCWSTR dest, COPYFILE2_EX char *buffer;
DWORD flags = params ? params->dwCopyFlags : 0; + BOOL *cancel_ptr = params ? params->pfCancel : NULL; + PCOPYFILE2_PROGRESS_ROUTINE progress = params ? params->pProgressRoutine : NULL; + void *callback_context = params ? params->pvCallbackContext : NULL; + + if (cancel_ptr) + FIXME("pfCancel is not supported\n"); + if (progress) + FIXME("PCOPYFILE2_PROGRESS_ROUTINE is not supported\n");
if (!source || !dest) { - return HRESULT_FROM_WIN32( ERROR_PATH_NOT_FOUND ); + SetLastError( ERROR_PATH_NOT_FOUND ); + return FALSE; } if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) { - return HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY ); + SetLastError( ERROR_NOT_ENOUGH_MEMORY ); + return FALSE; }
TRACE("%s -> %s, %lx\n", debugstr_w(source), debugstr_w(dest), flags); @@ -528,7 +532,8 @@ HRESULT WINAPI CopyFile2 ( const PCWSTR source , const PCWSTR dest, COPYFILE2_EX { WARN("Unable to open source %s\n", debugstr_w(source)); HeapFree( GetProcessHeap(), 0, buffer ); - return HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ); + SetLastError( ERROR_FILE_NOT_FOUND ); + return FALSE; }
if (!set_ntstatus( NtQueryInformationFile( h1, &io, &info, sizeof(info), FileBasicInformation ))) @@ -536,7 +541,7 @@ HRESULT WINAPI CopyFile2 ( const PCWSTR source , const PCWSTR dest, COPYFILE2_EX WARN("GetFileInformationByHandle returned error for %s\n", debugstr_w(source)); HeapFree( GetProcessHeap(), 0, buffer ); CloseHandle( h1 ); - return HRESULT_FROM_WIN32( GetLastError() ); + return FALSE; }
if (!(flags & COPY_FILE_FAIL_IF_EXISTS)) @@ -552,7 +557,8 @@ HRESULT WINAPI CopyFile2 ( const PCWSTR source , const PCWSTR dest, COPYFILE2_EX { HeapFree( GetProcessHeap(), 0, buffer ); CloseHandle( h1 ); - return HRESULT_FROM_WIN32( ERROR_SHARING_VIOLATION ); + SetLastError( ERROR_SHARING_VIOLATION ); + return FALSE; } }
@@ -563,7 +569,7 @@ HRESULT WINAPI CopyFile2 ( const PCWSTR source , const PCWSTR dest, COPYFILE2_EX WARN("Unable to open dest %s\n", debugstr_w(dest)); HeapFree( GetProcessHeap(), 0, buffer ); CloseHandle( h1 ); - return HRESULT_FROM_WIN32( GetLastError() ); + return FALSE; }
while (ReadFile( h1, buffer, buffer_size, &count, NULL ) && count) @@ -577,7 +583,7 @@ HRESULT WINAPI CopyFile2 ( const PCWSTR source , const PCWSTR dest, COPYFILE2_EX count -= res; } } - ret = S_OK; + ret = TRUE; done: /* Maintain the timestamp of source file to destination file */ info.FileAttributes = 0; @@ -588,6 +594,16 @@ done: return ret; }
+/*********************************************************************** + * CopyFile2 (kernelbase.@) + */ +HRESULT WINAPI CopyFile2 ( const PCWSTR source , const PCWSTR dest, COPYFILE2_EXTENDED_PARAMETERS* params) { + if (CopyFile2_impl(source, dest, params)) { + return S_OK; + } + return HRESULT_FROM_WIN32(GetLastError()); +} +
/*********************************************************************** * CopyFileExW (kernelbase.@) @@ -595,17 +611,20 @@ done: BOOL WINAPI CopyFileExW( const WCHAR *source, const WCHAR *dest, LPPROGRESS_ROUTINE progress, void *param, BOOL *cancel_ptr, DWORD flags ) { - HRESULT ret; COPYFILE2_EXTENDED_PARAMETERS params;
+ if (progress) + FIXME("LPPROGRESS_ROUTINE is not supported\n"); + if (cancel_ptr) + FIXME("cancel_ptr is not supported\n"); + params.dwSize = sizeof(params); params.dwCopyFlags = flags; + params.pProgressRoutine = NULL; + params.pvCallbackContext = NULL; + params.pfCancel = NULL;
- ret = CopyFile2( source, dest, ¶ms ); - if (ret != S_OK) { - SetLastError( ret ); - } - return SUCCEEDED(ret); + return CopyFile2_impl( source, dest, ¶ms ); }