VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2018-03-13 18:33:28 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2018-03-13 18:34:21 +0100
commitd20df7c9908525f496157b157556a090ca4588d8 (patch)
treef12f45f8e5d27f57655e9eb4f28dca04dce6c880
parent6c69cbfd2947013aa9acfdaf3dd05f8701867d51 (diff)
downloadVeraCrypt-d20df7c9908525f496157b157556a090ca4588d8.tar.gz
VeraCrypt-d20df7c9908525f496157b157556a090ca4588d8.zip
Windows: when /silent specified in command line, avoid performing any WIN32 UI calls. This fixes issue of current application losing focus when VeraCrypt is run with /quit /silent (cf https://github.com/veracrypt/VeraCrypt/issues/274)
-rw-r--r--src/Common/Dlgcode.c14
-rw-r--r--src/Mount/Mount.c171
2 files changed, 108 insertions, 77 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index ec805e40..6a79bcd2 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -1792,3 +1792,3 @@ WaitCursor ()
{
- static HCURSOR hcWait;
+ static HCURSOR hcWait = NULL;
if (hcWait == NULL)
@@ -1798,3 +1798,3 @@ WaitCursor ()
{
- SetCursor (hcWait);
+ if (!Silent) SetCursor (hcWait);
hCursor = hcWait;
@@ -1807,3 +1807,3 @@ NormalCursor ()
{
- static HCURSOR hcArrow;
+ static HCURSOR hcArrow = NULL;
if (hcArrow == NULL)
@@ -1814,3 +1814,3 @@ NormalCursor ()
{
- SetCursor (hcArrow);
+ if (!Silent) SetCursor (hcArrow);
hCursor = NULL;
@@ -1822,3 +1822,3 @@ ArrowWaitCursor ()
{
- static HCURSOR hcArrowWait;
+ static HCURSOR hcArrowWait = NULL;
if (hcArrowWait == NULL)
@@ -1827,3 +1827,3 @@ ArrowWaitCursor ()
{
- SetCursor (hcArrowWait);
+ if (!Silent) SetCursor (hcArrowWait);
hCursor = hcArrowWait;
@@ -1835,3 +1835,3 @@ void HandCursor ()
{
- static HCURSOR hcHand;
+ static HCURSOR hcHand = NULL;
if (hcHand == NULL)
diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c
index 759b6ca7..f791d055 100644
--- a/src/Mount/Mount.c
+++ b/src/Mount/Mount.c
@@ -381,7 +381,12 @@ void RefreshMainDlg (HWND hwndDlg)
{
- int drive = (wchar_t) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))));
+ if (Silent)
+ LoadDriveLetters (hwndDlg, NULL, 0);
+ else
+ {
+ int drive = (wchar_t) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))));
- MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME), bHistory);
- LoadDriveLetters (hwndDlg, GetDlgItem (hwndDlg, IDC_DRIVELIST), drive);
- EnableDisableButtons (hwndDlg);
+ MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME), bHistory);
+ LoadDriveLetters (hwndDlg, GetDlgItem (hwndDlg, IDC_DRIVELIST), drive);
+ EnableDisableButtons (hwndDlg);
+ }
}
@@ -429,59 +434,62 @@ static void InitMainDialog (HWND hwndDlg)
- /* Call the common dialog init code */
- InitDialog (hwndDlg);
- LocalizeDialog (hwndDlg, NULL);
+ if (!Silent)
+ {
+ /* Call the common dialog init code */
+ InitDialog (hwndDlg);
+ LocalizeDialog (hwndDlg, NULL);
- SetWindowLongPtrW (hwndDlg, DWLP_USER, (LONG_PTR) (IsAdmin() ? TC_MAIN_WINDOW_FLAG_ADMIN_PRIVILEGES : 0));
+ SetWindowLongPtrW (hwndDlg, DWLP_USER, (LONG_PTR) (IsAdmin() ? TC_MAIN_WINDOW_FLAG_ADMIN_PRIVILEGES : 0));
- DragAcceptFiles (hwndDlg, TRUE);
+ DragAcceptFiles (hwndDlg, TRUE);
- SendMessageW (GetDlgItem (hwndDlg, IDC_VOLUME), CB_LIMITTEXT, TC_MAX_PATH, 0);
- SetWindowTextW (hwndDlg, (IsAdmin() && !IsBuiltInAdmin() && IsUacSupported() && !IsNonInstallMode()) ? (wstring (lpszTitle) + L" [" + GetString ("ADMINISTRATOR") + L"]").c_str() : lpszTitle);
+ SendMessageW (GetDlgItem (hwndDlg, IDC_VOLUME), CB_LIMITTEXT, TC_MAX_PATH, 0);
+ SetWindowTextW (hwndDlg, (IsAdmin() && !IsBuiltInAdmin() && IsUacSupported() && !IsNonInstallMode()) ? (wstring (lpszTitle) + L" [" + GetString ("ADMINISTRATOR") + L"]").c_str() : lpszTitle);
- // Help file name
- InitHelpFileName();
+ // Help file name
+ InitHelpFileName();
- // Localize menu strings
- for (i = 40001; str = (wchar_t *)GetDictionaryValueByInt (i); i++)
- {
- info.cbSize = sizeof (info);
- info.fMask = MIIM_TYPE;
- info.fType = MFT_STRING;
- info.dwTypeData = str;
- info.cch = (UINT) wcslen (str);
+ // Localize menu strings
+ for (i = 40001; str = (wchar_t *)GetDictionaryValueByInt (i); i++)
+ {
+ info.cbSize = sizeof (info);
+ info.fMask = MIIM_TYPE;
+ info.fType = MFT_STRING;
+ info.dwTypeData = str;
+ info.cch = (UINT) wcslen (str);
- SetMenuItemInfoW (GetMenu (hwndDlg), i, FALSE, &info);
- }
+ SetMenuItemInfoW (GetMenu (hwndDlg), i, FALSE, &info);
+ }
- for (i = 0; popupTexts[i] != 0; i++)
- {
- str = GetString (popupTexts[i]);
+ for (i = 0; popupTexts[i] != 0; i++)
+ {
+ str = GetString (popupTexts[i]);
- info.cbSize = sizeof (info);
- info.fMask = MIIM_TYPE;
+ info.cbSize = sizeof (info);
+ info.fMask = MIIM_TYPE;
- if (strcmp (popupTexts[i], "MENU_WEBSITE") == 0)
- info.fType = MFT_STRING | MFT_RIGHTJUSTIFY;
- else
- info.fType = MFT_STRING;
+ if (strcmp (popupTexts[i], "MENU_WEBSITE") == 0)
+ info.fType = MFT_STRING | MFT_RIGHTJUSTIFY;
+ else
+ info.fType = MFT_STRING;
- if (strcmp (popupTexts[i], "MENU_FAVORITES") == 0)
- FavoriteVolumesMenu = GetSubMenu (GetMenu (hwndDlg), i);
+ if (strcmp (popupTexts[i], "MENU_FAVORITES") == 0)
+ FavoriteVolumesMenu = GetSubMenu (GetMenu (hwndDlg), i);
- info.dwTypeData = str;
- info.cch = (UINT) wcslen (str);
+ info.dwTypeData = str;
+ info.cch = (UINT) wcslen (str);
- SetMenuItemInfoW (GetMenu (hwndDlg), i, TRUE, &info);
- }
+ SetMenuItemInfoW (GetMenu (hwndDlg), i, TRUE, &info);
+ }
- {
- // disable hidden OS creation for GPT system encryption
- if (bSystemIsGPT)
{
- EnableMenuItem (GetMenu (hwndDlg), IDM_CREATE_HIDDEN_OS, MF_GRAYED);
+ // disable hidden OS creation for GPT system encryption
+ if (bSystemIsGPT)
+ {
+ EnableMenuItem (GetMenu (hwndDlg), IDM_CREATE_HIDDEN_OS, MF_GRAYED);
+ }
}
- }
- // Disable menu item for changing system header key derivation algorithm until it's implemented
- EnableMenuItem (GetMenu (hwndDlg), IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO, MF_GRAYED);
+ // Disable menu item for changing system header key derivation algorithm until it's implemented
+ EnableMenuItem (GetMenu (hwndDlg), IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO, MF_GRAYED);
+ }
@@ -499,27 +507,32 @@ static void InitMainDialog (HWND hwndDlg)
- // Resize the logo bitmap if the user has a non-default DPI
- if (ScreenDPI != USER_DEFAULT_SCREEN_DPI
- && hbmLogoBitmapRescaled == NULL) // If not re-called (e.g. after language pack change)
+ if (Silent)
+ LoadDriveLetters (hwndDlg, NULL, 0);
+ else
{
- hbmLogoBitmapRescaled = RenderBitmap (MAKEINTRESOURCE (IDB_LOGO_288DPI),
- GetDlgItem (hwndDlg, IDC_LOGO),
- 0, 0, 0, 0, FALSE, TRUE);
- }
+ // Resize the logo bitmap if the user has a non-default DPI
+ if (ScreenDPI != USER_DEFAULT_SCREEN_DPI
+ && hbmLogoBitmapRescaled == NULL) // If not re-called (e.g. after language pack change)
+ {
+ hbmLogoBitmapRescaled = RenderBitmap (MAKEINTRESOURCE (IDB_LOGO_288DPI),
+ GetDlgItem (hwndDlg, IDC_LOGO),
+ 0, 0, 0, 0, FALSE, TRUE);
+ }
- BuildTree (hwndDlg, GetDlgItem (hwndDlg, IDC_DRIVELIST));
+ BuildTree (hwndDlg, GetDlgItem (hwndDlg, IDC_DRIVELIST));
- if (*szDriveLetter != 0)
- {
- SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST), *szDriveLetter);
+ if (*szDriveLetter != 0)
+ {
+ SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST), *szDriveLetter);
- if(nSelectedDriveIndex > SendMessage (GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_GETITEMCOUNT, 0, 0)/2)
- SendMessage(GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_SCROLL, 0, 10000);
- }
- else
- {
- SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM) GetDlgItem (hwndDlg, IDC_DRIVELIST), 1L);
- }
+ if(nSelectedDriveIndex > SendMessage (GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_GETITEMCOUNT, 0, 0)/2)
+ SendMessage(GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_SCROLL, 0, 10000);
+ }
+ else
+ {
+ SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM) GetDlgItem (hwndDlg, IDC_DRIVELIST), 1L);
+ }
- SendMessage (GetDlgItem (hwndDlg, IDC_NO_HISTORY), BM_SETCHECK, bHistory ? BST_UNCHECKED : BST_CHECKED, 0);
- EnableDisableButtons (hwndDlg);
+ SendMessage (GetDlgItem (hwndDlg, IDC_NO_HISTORY), BM_SETCHECK, bHistory ? BST_UNCHECKED : BST_CHECKED, 0);
+ EnableDisableButtons (hwndDlg);
+ }
}
@@ -1566,3 +1579,3 @@ void LoadDriveLetters (HWND hwndDlg, HWND hTree, int drive)
// Remember the top-most visible item
- int lastTopMostVisibleItem = ListView_GetTopIndex (hTree);
+ int lastTopMostVisibleItem = (!Silent && hTree)? ListView_GetTopIndex (hTree) : 0;
@@ -1620,2 +1633,5 @@ void LoadDriveLetters (HWND hwndDlg, HWND hTree, int drive)
+ if (Silent)
+ return;
+
if(drive == 0)
@@ -5184,3 +5200,3 @@ retry:
- if (interact)
+ if (interact && !Silent)
MessageBoxW (hwndDlg, GetString ("UNMOUNT_FAILED"), lpszTitle, MB_ICONERROR);
@@ -5487,3 +5503,6 @@ static BOOL MountAllDevices (HWND hwndDlg, BOOL bPasswordPrompt)
- ShowWaitDialog (hwndDlg, FALSE, mountAllDevicesThreadProc, &param);
+ if (Silent)
+ mountAllDevicesThreadProc (&param, hwndDlg);
+ else
+ ShowWaitDialog (hwndDlg, FALSE, mountAllDevicesThreadProc, &param);
@@ -6614,2 +6633,5 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
+ if (Silent && !Quit)
+ Silent = FALSE;
+
try
@@ -6826,3 +6848,2 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
- RefreshMainDlg(hwndDlg);
@@ -6830,2 +6851,3 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
{
+ RefreshMainDlg(hwndDlg);
// Check for problematic file extensions (exe, dll, sys)
@@ -6919,2 +6941,11 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
}
+ else
+ {
+ if (Silent)
+ {
+ Silent = FALSE;
+ InitMainDialog (hwndDlg);
+ RefreshMainDlg(hwndDlg);
+ }
+ }
}
@@ -9533,3 +9564,3 @@ static BOOL MountFavoriteVolumeBase (HWND hwnd, const FavoriteVolume &favorite,
mountOptions.ProtectedHidVolPim = CmdVolumePim;
- if (DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwnd, (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions) == IDCANCEL)
+ if (Silent || (DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwnd, (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions) == IDCANCEL))
{