1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-13 03:48:26 -06:00

Windows: solve installer issue on Windows 10 caused by failure to overwrite VeraCrypt driver file.

This commit is contained in:
Mounir IDRASSI
2015-06-09 23:29:33 +02:00
parent a7a8d57bca
commit b7eadfd310
6 changed files with 70 additions and 28 deletions

View File

@@ -7520,18 +7520,47 @@ BOOL TCCopyFile (char *sourceFileName, char *destinationFile)
// If bAppend is TRUE, the buffer is appended to an existing file. If bAppend is FALSE, any existing file
// is replaced. If an error occurs, the incomplete file is deleted (provided that bAppend is FALSE).
BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWORD inputLength, BOOL bAppend)
BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWORD inputLength, BOOL bAppend, BOOL bRenameIfFailed)
{
HANDLE dst;
DWORD bytesWritten;
BOOL res = TRUE;
DWORD dwLastError = 0;
dst = CreateFile (destinationFile,
GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, bAppend ? OPEN_EXISTING : CREATE_ALWAYS, 0, NULL);
dwLastError = GetLastError();
if (!bAppend && bRenameIfFailed && (dst == INVALID_HANDLE_VALUE) && (GetLastError () == ERROR_SHARING_VIOLATION))
{
char renamedPath[TC_MAX_PATH + 1];
StringCbCopyA (renamedPath, sizeof(renamedPath), destinationFile);
StringCbCatA (renamedPath, sizeof(renamedPath), VC_FILENAME_RENAMED_SUFFIX);
/* rename the locked file in order to be able to create a new one */
if (MoveFileEx (destinationFile, renamedPath, MOVEFILE_REPLACE_EXISTING))
{
dst = CreateFile (destinationFile,
GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, bAppend ? OPEN_EXISTING : CREATE_ALWAYS, 0, NULL);
dwLastError = GetLastError();
if (dst == INVALID_HANDLE_VALUE)
{
/* restore the original file name */
MoveFileEx (renamedPath, destinationFile, MOVEFILE_REPLACE_EXISTING);
}
else
{
/* delete the renamed file when the machine reboots */
MoveFileEx (renamedPath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
}
}
}
if (dst == INVALID_HANDLE_VALUE)
{
SetLastError (dwLastError);
handleWin32Error (MainDlg);
return FALSE;
}
@@ -7603,14 +7632,14 @@ BOOL PrintHardCopyTextUTF16 (wchar_t *text, char *title, size_t textByteLen)
}
// Write the Unicode signature
if (!SaveBufferToFile ("\xFF\xFE", path, 2, FALSE))
if (!SaveBufferToFile ("\xFF\xFE", path, 2, FALSE, FALSE))
{
remove (path);
return FALSE;
}
// Write the actual text
if (!SaveBufferToFile ((char *) text, path, (DWORD) textByteLen, TRUE))
if (!SaveBufferToFile ((char *) text, path, (DWORD) textByteLen, TRUE, FALSE))
{
remove (path);
return FALSE;
@@ -10068,7 +10097,7 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam
finally_do_arg (vector <byte> *, &keyfileData, { burn (&finally_arg->front(), finally_arg->size()); });
if (!SaveBufferToFile ((char *) &keyfileData.front(), keyfilePath, (DWORD) keyfileData.size(), FALSE))
if (!SaveBufferToFile ((char *) &keyfileData.front(), keyfilePath, (DWORD) keyfileData.size(), FALSE, FALSE))
throw SystemException ();
}

View File

@@ -77,6 +77,8 @@ enum
#define TC_APPD_FILENAME_POST_INSTALL_TASK_TUTORIAL "Post-Install Task - Tutorial"
#define TC_APPD_FILENAME_POST_INSTALL_TASK_RELEASE_NOTES "Post-Install Task - Release Notes"
#define VC_FILENAME_RENAMED_SUFFIX "_old"
#ifndef USER_DEFAULT_SCREEN_DPI
#define USER_DEFAULT_SCREEN_DPI 96
#endif
@@ -351,7 +353,7 @@ int64 FindString (const char *buf, const char *str, int64 bufLen, int64 strLen,
BOOL FileExists (const char *filePathPtr);
__int64 FindStringInFile (const char *filePath, const char *str, int strLen);
BOOL TCCopyFile (char *sourceFileName, char *destinationFile);
BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWORD inputLength, BOOL bAppend);
BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWORD inputLength, BOOL bAppend, BOOL bRenameIfFailed);
BOOL TCFlushFile (FILE *f);
BOOL PrintHardCopyTextUTF16 (wchar_t *text, char *title, size_t byteLen);
void GetSpeedString (unsigned __int64 speed, wchar_t *str, size_t cbStr);