VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2015-09-09 15:53:18 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2015-09-10 01:44:12 +0200
commitec7b5cd7e63bf78fa98c9b9713846b99b835dd71 (patch)
treef8f031b31b58e978841ab1162f89c8ca86b4633b /src/Common
parentc55e08b31e8100a593b4f81784489a820de807a1 (diff)
downloadVeraCrypt-ec7b5cd7e63bf78fa98c9b9713846b99b835dd71.tar.gz
VeraCrypt-ec7b5cd7e63bf78fa98c9b9713846b99b835dd71.zip
Windows: Implement waiting dialog for Dismount operations to avoid freezing GUI when dismounting takes long time.
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Dlgcode.c58
1 files changed, 48 insertions, 10 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index e858c3b4..4e8dc015 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -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
- {
- result = DriverUnmountVolume (hwndDlg, nDosDriveNo, forced);
+ param.nDosDriveNo = nDosDriveNo;
+ param.forced = forced;
+ param.dismountMaxRetries = dismountMaxRetries;
+ param.retryDelay = retryDelay;
+ param.presult = &result;
- if (result == ERR_FILES_OPEN)
- Sleep (retryDelay);
- else
- break;
+ if (Silent)
+ {
+ UnmountWaitThreadProc (&param, hwndDlg);
+ }
+ else
+ {
+ ShowWaitDialog (hwndDlg, TRUE, UnmountWaitThreadProc, &param);
+ }
- } while (--dismountMaxRetries > 0);
+ SetLastError (param.dwLastError);
if (result != 0)
{