Use winpr_DeleteFile and winpr_MoveFileEx

This commit is contained in:
akallabeth 2022-10-25 13:46:22 +02:00 committed by akallabeth
parent 22dce52d15
commit 1c0908bdfb

View File

@ -189,13 +189,12 @@ out:
static BOOL saveCal(rdpSettings* settings, const BYTE* data, size_t length, const char* hostname) static BOOL saveCal(rdpSettings* settings, const BYTE* data, size_t length, const char* hostname)
{ {
char hash[41]; char hash[41] = { 0 };
FILE* fp; FILE* fp;
char* licenseStorePath = NULL; char* licenseStorePath = NULL;
char filename[MAX_PATH], filenameNew[MAX_PATH]; char filename[MAX_PATH] = { 0 }, filenameNew[MAX_PATH] = { 0 };
char *filepath = NULL, *filepathNew = NULL; char *filepath = NULL, *filepathNew = NULL;
WCHAR* wFilepathNew = NULL;
WCHAR* wFilepath = NULL;
size_t written; size_t written;
BOOL ret = FALSE; BOOL ret = FALSE;
@ -232,10 +231,6 @@ static BOOL saveCal(rdpSettings* settings, const BYTE* data, size_t length, cons
if (!(filepathNew = GetCombinedPath(licenseStorePath, filenameNew))) if (!(filepathNew = GetCombinedPath(licenseStorePath, filenameNew)))
goto out; goto out;
if (ConvertToUnicode(CP_UTF8, 0, filepathNew, -1, &wFilepathNew, 0) <= 0)
goto out;
if (ConvertToUnicode(CP_UTF8, 0, filepath, -1, &wFilepath, 0) <= 0)
goto out;
fp = winpr_fopen(filepathNew, "wb"); fp = winpr_fopen(filepathNew, "wb");
if (!fp) if (!fp)
@ -246,16 +241,14 @@ static BOOL saveCal(rdpSettings* settings, const BYTE* data, size_t length, cons
if (written != 1) if (written != 1)
{ {
DeleteFileW(wFilepathNew); winpr_DeleteFile(filepathNew);
goto out; goto out;
} }
ret = MoveFileExW(wFilepathNew, wFilepath, MOVEFILE_REPLACE_EXISTING); ret = winpr_MoveFileEx(filepathNew, filepath, MOVEFILE_REPLACE_EXISTING);
out: out:
free(wFilepathNew);
free(filepathNew); free(filepathNew);
free(wFilepath);
free(filepath); free(filepath);
free(licenseStorePath); free(licenseStorePath);
return ret; return ret;