Windows: Implement waiting dialog for Mount All Favorites Volumes operation.

This commit is contained in:
Mounir IDRASSI 2015-09-09 23:33:30 +02:00
parent ec7b5cd7e6
commit 957ff20f37
3 changed files with 49 additions and 40 deletions

View File

@ -134,6 +134,8 @@ BOOL MountVolumesAsSystemFavorite = FALSE;
BOOL FavoriteMountOnArrivalInProgress = FALSE; BOOL FavoriteMountOnArrivalInProgress = FALSE;
BOOL MultipleMountOperationInProgress = FALSE; BOOL MultipleMountOperationInProgress = FALSE;
BOOL WaitDialogDisplaying = FALSE;
/* Handle to the device driver */ /* Handle to the device driver */
HANDLE hDriver = INVALID_HANDLE_VALUE; HANDLE hDriver = INVALID_HANDLE_VALUE;
@ -6597,15 +6599,26 @@ void ShowWaitDialog(HWND hwnd, BOOL bUseHwndAsParent, WaitThreadProc callback, v
threadParam.callback = callback; threadParam.callback = callback;
threadParam.pArg = pArg; threadParam.pArg = pArg;
if (WaitDialogDisplaying)
{
callback (pArg, hwnd);
}
else
{
WaitDialogDisplaying = TRUE;
DialogBoxParamW (hInst, DialogBoxParamW (hInst,
MAKEINTRESOURCEW (IDD_STATIC_MODAL_WAIT_DLG), hParent, MAKEINTRESOURCEW (IDD_STATIC_MODAL_WAIT_DLG), hParent,
(DLGPROC) WaitDlgProc, (LPARAM) &threadParam); (DLGPROC) WaitDlgProc, (LPARAM) &threadParam);
WaitDialogDisplaying = FALSE;
if (hwnd && IsWindowVisible(hwnd) && !bUseHwndAsParent) if (hwnd && IsWindowVisible(hwnd) && !bUseHwndAsParent)
{ {
SetForegroundWindow(hwnd); SetForegroundWindow(hwnd);
BringWindowToTop(hwnd); BringWindowToTop(hwnd);
} }
}
} }
/************************************************************************/ /************************************************************************/

View File

@ -4356,7 +4356,7 @@ static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName, int pim)
bPrebootPasswordDlgMode = mountOptions.PartitionInInactiveSysEncScope; bPrebootPasswordDlgMode = mountOptions.PartitionInInactiveSysEncScope;
if (nDosDriveNo == 0) if (nDosDriveNo == 0)
nDosDriveNo = HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A'; nDosDriveNo = HIWORD (GetSelectedLong (GetDlgItem (MainDlg, IDC_DRIVELIST))) - 'A';
if (!MultipleMountOperationInProgress) if (!MultipleMountOperationInProgress)
{ {
@ -4508,7 +4508,7 @@ static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName, int pim)
if (bBeep) if (bBeep)
MessageBeep (0xFFFFFFFF); MessageBeep (0xFFFFFFFF);
RefreshMainDlg(hwndDlg); RefreshMainDlg(MainDlg);
if (bExplore) if (bExplore)
{ {
@ -6526,7 +6526,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (!mountedAndNotDisconnected) if (!mountedAndNotDisconnected)
{ {
FavoriteMountOnArrivalInProgress = TRUE; FavoriteMountOnArrivalInProgress = TRUE;
MountFavoriteVolumes (FALSE, FALSE, FALSE, favorite); MountFavoriteVolumes (hwndDlg, FALSE, FALSE, FALSE, favorite);
FavoriteMountOnArrivalInProgress = FALSE; FavoriteMountOnArrivalInProgress = FALSE;
FavoritesMountedOnArrivalStillConnected.push_back (favorite); FavoritesMountedOnArrivalStillConnected.push_back (favorite);
@ -7801,7 +7801,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (lw == IDM_MOUNT_FAVORITE_VOLUMES) if (lw == IDM_MOUNT_FAVORITE_VOLUMES)
{ {
_beginthread(mountFavoriteVolumeThreadFunction, 0, NULL); ShowWaitDialog (hwndDlg, TRUE, mountFavoriteVolumeThreadFunction, NULL);
return 1; return 1;
} }
@ -7875,13 +7875,13 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
} }
else else
{ {
mountFavoriteVolumeThreadParam* pParam = (mountFavoriteVolumeThreadParam*) calloc(1, sizeof(mountFavoriteVolumeThreadParam)); mountFavoriteVolumeThreadParam param;
pParam->systemFavorites = FALSE; param.systemFavorites = FALSE;
pParam->logOnMount = FALSE; param.logOnMount = FALSE;
pParam->hotKeyMount = FALSE; param.hotKeyMount = FALSE;
pParam->favoriteVolumeToMount = &FavoriteVolumes[favoriteIndex]; param.favoriteVolumeToMount = &FavoriteVolumes[favoriteIndex];
_beginthread(mountFavoriteVolumeThreadFunction, 0, pParam); ShowWaitDialog (hwndDlg, TRUE, mountFavoriteVolumeThreadFunction, &param);
} }
} }
@ -8435,7 +8435,7 @@ static VOID WINAPI SystemFavoritesServiceMain (DWORD argc, LPTSTR *argv)
try try
{ {
status = MountFavoriteVolumes (TRUE); status = MountFavoriteVolumes (NULL, TRUE);
} }
catch (...) { } catch (...) { }
@ -8703,7 +8703,7 @@ void DismountIdleVolumes ()
} }
} }
static BOOL MountFavoriteVolumeBase (const FavoriteVolume &favorite, BOOL& lastbExplore, BOOL& userForcedReadOnly, BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMount, const FavoriteVolume &favoriteVolumeToMount) static BOOL MountFavoriteVolumeBase (HWND hwnd, const FavoriteVolume &favorite, BOOL& lastbExplore, BOOL& userForcedReadOnly, BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMount, const FavoriteVolume &favoriteVolumeToMount)
{ {
BOOL status = TRUE; BOOL status = TRUE;
int drive; int drive;
@ -8763,7 +8763,7 @@ static BOOL MountFavoriteVolumeBase (const FavoriteVolume &favorite, BOOL& lastb
else else
mountOptions.ProtectedHidVolPkcs5Prf = CmdVolumePkcs5; mountOptions.ProtectedHidVolPkcs5Prf = CmdVolumePkcs5;
mountOptions.ProtectedHidVolPim = CmdVolumePim; mountOptions.ProtectedHidVolPim = CmdVolumePim;
if (DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), MainDlg, (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions) == IDCANCEL) if (DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwnd, (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions) == IDCANCEL)
{ {
status = FALSE; status = FALSE;
goto skipMount; goto skipMount;
@ -8775,7 +8775,7 @@ static BOOL MountFavoriteVolumeBase (const FavoriteVolume &favorite, BOOL& lastb
if (ServiceMode) if (ServiceMode)
SystemFavoritesServiceLogInfo (string ("Mounting system favorite \"") + favorite.Path + "\""); SystemFavoritesServiceLogInfo (string ("Mounting system favorite \"") + favorite.Path + "\"");
status = Mount (MainDlg, drive, (char *) favorite.Path.c_str(), favorite.Pim); status = Mount (hwnd, drive, (char *) favorite.Path.c_str(), favorite.Pim);
if (ServiceMode) if (ServiceMode)
{ {
@ -8837,7 +8837,7 @@ static BOOL MountFavoriteVolumeBase (const FavoriteVolume &favorite, BOOL& lastb
} }
BOOL MountFavoriteVolumes (BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMount, const FavoriteVolume &favoriteVolumeToMount) BOOL MountFavoriteVolumes (HWND hwnd, BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMount, const FavoriteVolume &favoriteVolumeToMount)
{ {
BOOL bRet = TRUE, status = TRUE; BOOL bRet = TRUE, status = TRUE;
BOOL lastbExplore; BOOL lastbExplore;
@ -8899,7 +8899,7 @@ BOOL MountFavoriteVolumes (BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMou
continue; continue;
} }
status = MountFavoriteVolumeBase (favorite, lastbExplore, userForcedReadOnly, systemFavorites, logOnMount, hotKeyMount, favoriteVolumeToMount); status = MountFavoriteVolumeBase (hwnd, favorite, lastbExplore, userForcedReadOnly, systemFavorites, logOnMount, hotKeyMount, favoriteVolumeToMount);
if (!status) if (!status)
bRet = FALSE; bRet = FALSE;
} }
@ -8938,7 +8938,7 @@ BOOL MountFavoriteVolumes (BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMou
// favorite OK. // favorite OK.
SystemFavoritesServiceLogInfo (string ("Favorite \"") + favorite->VolumePathId + "\" is connected. Performing mount."); SystemFavoritesServiceLogInfo (string ("Favorite \"") + favorite->VolumePathId + "\" is connected. Performing mount.");
status = MountFavoriteVolumeBase (*favorite, lastbExplore, userForcedReadOnly, systemFavorites, logOnMount, hotKeyMount, favoriteVolumeToMount); status = MountFavoriteVolumeBase (hwnd, *favorite, lastbExplore, userForcedReadOnly, systemFavorites, logOnMount, hotKeyMount, favoriteVolumeToMount);
if (!status) if (!status)
bRet = FALSE; bRet = FALSE;
} }
@ -8968,24 +8968,19 @@ BOOL MountFavoriteVolumes (BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMou
return bRet; return bRet;
} }
void __cdecl mountFavoriteVolumeThreadFunction (void *pArg) void CALLBACK mountFavoriteVolumeThreadFunction (void *pArg, HWND hwnd)
{ {
mountFavoriteVolumeThreadParam* pParam = (mountFavoriteVolumeThreadParam*) pArg; mountFavoriteVolumeThreadParam* pParam = (mountFavoriteVolumeThreadParam*) pArg;
// Disable main dialog during processing to avoid user interaction
EnableWindow(MainDlg, FALSE);
finally_do ({ EnableWindow(MainDlg, TRUE); });
if (pParam) if (pParam)
{ {
if (pParam->favoriteVolumeToMount) if (pParam->favoriteVolumeToMount)
MountFavoriteVolumes (pParam->systemFavorites, pParam->logOnMount, pParam->hotKeyMount, *(pParam->favoriteVolumeToMount)); MountFavoriteVolumes (hwnd, pParam->systemFavorites, pParam->logOnMount, pParam->hotKeyMount, *(pParam->favoriteVolumeToMount));
else else
MountFavoriteVolumes (pParam->systemFavorites, pParam->logOnMount, pParam->hotKeyMount); MountFavoriteVolumes (hwnd, pParam->systemFavorites, pParam->logOnMount, pParam->hotKeyMount);
free(pParam);
} }
else else
MountFavoriteVolumes (); MountFavoriteVolumes (hwnd);
} }
@ -9121,12 +9116,13 @@ static void HandleHotKey (HWND hwndDlg, WPARAM wParam)
case HK_MOUNT_FAVORITE_VOLUMES: case HK_MOUNT_FAVORITE_VOLUMES:
{ {
mountFavoriteVolumeThreadParam* pParam = (mountFavoriteVolumeThreadParam*) calloc(1, sizeof(mountFavoriteVolumeThreadParam)); mountFavoriteVolumeThreadParam param;
pParam->systemFavorites = FALSE; param.systemFavorites = FALSE;
pParam->logOnMount = FALSE; param.logOnMount = FALSE;
pParam->hotKeyMount = TRUE; param.hotKeyMount = TRUE;
param.favoriteVolumeToMount = NULL;
_beginthread(mountFavoriteVolumeThreadFunction, 0, pParam); ShowWaitDialog (hwndDlg, TRUE, mountFavoriteVolumeThreadFunction, &param);
} }
break; break;

View File

@ -126,7 +126,7 @@ typedef struct
} mountFavoriteVolumeThreadParam; } mountFavoriteVolumeThreadParam;
void SetDriverConfigurationFlag (uint32 flag, BOOL state); void SetDriverConfigurationFlag (uint32 flag, BOOL state);
BOOL MountFavoriteVolumes (BOOL systemFavorites = FALSE, BOOL logOnMount = FALSE, BOOL hotKeyMount = FALSE, const VeraCrypt::FavoriteVolume &favoriteVolumeToMount = VeraCrypt::FavoriteVolume()); BOOL MountFavoriteVolumes (HWND hwnd, BOOL systemFavorites = FALSE, BOOL logOnMount = FALSE, BOOL hotKeyMount = FALSE, const VeraCrypt::FavoriteVolume &favoriteVolumeToMount = VeraCrypt::FavoriteVolume());
void __cdecl mountFavoriteVolumeThreadFunction (void *pArg); void CALLBACK mountFavoriteVolumeThreadFunction (void *pArg, HWND hwnd);
#endif #endif