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

Windows: Implement waiting dialog for Dismount operations to avoid freezing GUI when dismounting takes long time.

This commit is contained in:
Mounir IDRASSI
2015-09-09 15:53:18 +02:00
parent c55e08b31e
commit ec7b5cd7e6
2 changed files with 141 additions and 50 deletions

View File

@@ -6370,7 +6370,7 @@ int DriverUnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forced)
unmount.ignoreOpenFiles = forced;
bResult = DeviceIoControl (hDriver, TC_IOCTL_DISMOUNT_VOLUME, &unmount,
sizeof (unmount), &unmount, sizeof (unmount), &dwResult, NULL);
sizeof (unmount), &unmount, sizeof (unmount), &dwResult, NULL);
if (bResult == FALSE)
{
@@ -6384,7 +6384,8 @@ int DriverUnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forced)
if (unmount.nReturnCode == ERR_SUCCESS
&& unmount.HiddenVolumeProtectionTriggered
&& !VolumeNotificationsList.bHidVolDamagePrevReported [nDosDriveNo])
&& !VolumeNotificationsList.bHidVolDamagePrevReported [nDosDriveNo]
&& !Silent)
{
wchar_t msg[4096];
@@ -7017,26 +7018,63 @@ retry:
return 1;
}
typedef struct
{
int nDosDriveNo;
BOOL forced;
int dismountMaxRetries;
DWORD retryDelay;
int* presult;
DWORD dwLastError;
} UnmountThreadParam;
void CALLBACK UnmountWaitThreadProc(void* pArg, HWND hwnd)
{
UnmountThreadParam* pThreadParam = (UnmountThreadParam*) pArg;
int dismountMaxRetries = pThreadParam->dismountMaxRetries;
DWORD retryDelay = pThreadParam->retryDelay;
do
{
*pThreadParam->presult = DriverUnmountVolume (hwnd, pThreadParam->nDosDriveNo, pThreadParam->forced);
if (*pThreadParam->presult == ERR_FILES_OPEN)
Sleep (retryDelay);
else
break;
} while (--dismountMaxRetries > 0);
pThreadParam->dwLastError = GetLastError ();
}
static BOOL UnmountVolumeBase (HWND hwndDlg, int nDosDriveNo, BOOL forceUnmount, BOOL ntfsFormatCase)
{
int result;
BOOL forced = forceUnmount;
int dismountMaxRetries = ntfsFormatCase? 5 : UNMOUNT_MAX_AUTO_RETRIES;
DWORD retryDelay = ntfsFormatCase? 2000: UNMOUNT_AUTO_RETRY_DELAY;
UnmountThreadParam param;
retry:
BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, nDosDriveNo, 0);
do
param.nDosDriveNo = nDosDriveNo;
param.forced = forced;
param.dismountMaxRetries = dismountMaxRetries;
param.retryDelay = retryDelay;
param.presult = &result;
if (Silent)
{
result = DriverUnmountVolume (hwndDlg, nDosDriveNo, forced);
UnmountWaitThreadProc (&param, hwndDlg);
}
else
{
ShowWaitDialog (hwndDlg, TRUE, UnmountWaitThreadProc, &param);
}
if (result == ERR_FILES_OPEN)
Sleep (retryDelay);
else
break;
} while (--dismountMaxRetries > 0);
SetLastError (param.dwLastError);
if (result != 0)
{