Add function winpr_MoveFileEx

This commit is contained in:
akallabeth 2022-10-25 13:45:44 +02:00 committed by akallabeth
parent 6e7b91c5ad
commit 22dce52d15
2 changed files with 28 additions and 0 deletions

View File

@ -336,6 +336,7 @@ extern "C"
#endif
WINPR_API BOOL winpr_MoveFile(LPCSTR lpExistingFileName, LPCSTR lpNewFileName);
WINPR_API BOOL winpr_MoveFileEx(LPCSTR lpExistingFileName, LPCSTR lpNewFileName, DWORD dwFlags);
WINPR_API BOOL winpr_DeleteFile(const char* lpFileName);
WINPR_API BOOL winpr_RemoveDirectory(LPCSTR lpPathName);
WINPR_API BOOL winpr_PathFileExists(const char* pszPath);

View File

@ -689,6 +689,33 @@ cleanup:
#endif
}
BOOL winpr_MoveFileEx(LPCSTR lpExistingFileName, LPCSTR lpNewFileName, DWORD dwFlags)
{
#ifndef _WIN32
return MoveFileExA(lpExistingFileName, lpNewFileName, dwFlags);
#else
BOOL result = FALSE;
LPWSTR lpExistingFileNameW = NULL;
LPWSTR lpNewFileNameW = NULL;
if (!lpExistingFileName || !lpNewFileName)
return FALSE;
if (ConvertToUnicode(CP_UTF8, 0, lpExistingFileName, -1, &lpExistingFileNameW, 0) < 1)
goto cleanup;
if (ConvertToUnicode(CP_UTF8, 0, lpNewFileName, -1, &lpNewFileNameW, 0) < 1)
goto cleanup;
result = MoveFileExW(lpExistingFileNameW, lpNewFileNameW, dwFlags);
cleanup:
free(lpExistingFileNameW);
free(lpNewFileNameW);
return result;
#endif
}
BOOL winpr_DeleteFile(const char* lpFileName)
{
#ifndef _WIN32