mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
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)
This commit is contained in:
@@ -1790,13 +1790,13 @@ static int g_waitCursorCounter = 0;
|
|||||||
void
|
void
|
||||||
WaitCursor ()
|
WaitCursor ()
|
||||||
{
|
{
|
||||||
static HCURSOR hcWait;
|
static HCURSOR hcWait = NULL;
|
||||||
if (hcWait == NULL)
|
if (hcWait == NULL)
|
||||||
hcWait = LoadCursor (NULL, IDC_WAIT);
|
hcWait = LoadCursor (NULL, IDC_WAIT);
|
||||||
|
|
||||||
if ((g_waitCursorCounter == 0) || (hCursor != hcWait))
|
if ((g_waitCursorCounter == 0) || (hCursor != hcWait))
|
||||||
{
|
{
|
||||||
SetCursor (hcWait);
|
if (!Silent) SetCursor (hcWait);
|
||||||
hCursor = hcWait;
|
hCursor = hcWait;
|
||||||
}
|
}
|
||||||
g_waitCursorCounter++;
|
g_waitCursorCounter++;
|
||||||
@@ -1805,14 +1805,14 @@ WaitCursor ()
|
|||||||
void
|
void
|
||||||
NormalCursor ()
|
NormalCursor ()
|
||||||
{
|
{
|
||||||
static HCURSOR hcArrow;
|
static HCURSOR hcArrow = NULL;
|
||||||
if (hcArrow == NULL)
|
if (hcArrow == NULL)
|
||||||
hcArrow = LoadCursor (NULL, IDC_ARROW);
|
hcArrow = LoadCursor (NULL, IDC_ARROW);
|
||||||
if (g_waitCursorCounter > 0)
|
if (g_waitCursorCounter > 0)
|
||||||
g_waitCursorCounter--;
|
g_waitCursorCounter--;
|
||||||
if (g_waitCursorCounter == 0)
|
if (g_waitCursorCounter == 0)
|
||||||
{
|
{
|
||||||
SetCursor (hcArrow);
|
if (!Silent) SetCursor (hcArrow);
|
||||||
hCursor = NULL;
|
hCursor = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1820,12 +1820,12 @@ NormalCursor ()
|
|||||||
void
|
void
|
||||||
ArrowWaitCursor ()
|
ArrowWaitCursor ()
|
||||||
{
|
{
|
||||||
static HCURSOR hcArrowWait;
|
static HCURSOR hcArrowWait = NULL;
|
||||||
if (hcArrowWait == NULL)
|
if (hcArrowWait == NULL)
|
||||||
hcArrowWait = LoadCursor (NULL, IDC_APPSTARTING);
|
hcArrowWait = LoadCursor (NULL, IDC_APPSTARTING);
|
||||||
if ((g_waitCursorCounter == 0) || (hCursor != hcArrowWait))
|
if ((g_waitCursorCounter == 0) || (hCursor != hcArrowWait))
|
||||||
{
|
{
|
||||||
SetCursor (hcArrowWait);
|
if (!Silent) SetCursor (hcArrowWait);
|
||||||
hCursor = hcArrowWait;
|
hCursor = hcArrowWait;
|
||||||
}
|
}
|
||||||
g_waitCursorCounter++;
|
g_waitCursorCounter++;
|
||||||
@@ -1833,7 +1833,7 @@ ArrowWaitCursor ()
|
|||||||
|
|
||||||
void HandCursor ()
|
void HandCursor ()
|
||||||
{
|
{
|
||||||
static HCURSOR hcHand;
|
static HCURSOR hcHand = NULL;
|
||||||
if (hcHand == NULL)
|
if (hcHand == NULL)
|
||||||
hcHand = LoadCursor (NULL, IDC_HAND);
|
hcHand = LoadCursor (NULL, IDC_HAND);
|
||||||
SetCursor (hcHand);
|
SetCursor (hcHand);
|
||||||
|
|||||||
@@ -379,11 +379,16 @@ static void localcleanup (void)
|
|||||||
|
|
||||||
void RefreshMainDlg (HWND hwndDlg)
|
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);
|
MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME), bHistory);
|
||||||
LoadDriveLetters (hwndDlg, GetDlgItem (hwndDlg, IDC_DRIVELIST), drive);
|
LoadDriveLetters (hwndDlg, GetDlgItem (hwndDlg, IDC_DRIVELIST), drive);
|
||||||
EnableDisableButtons (hwndDlg);
|
EnableDisableButtons (hwndDlg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndMainDlg (HWND hwndDlg)
|
void EndMainDlg (HWND hwndDlg)
|
||||||
@@ -427,63 +432,66 @@ static void InitMainDialog (HWND hwndDlg)
|
|||||||
wchar_t *str;
|
wchar_t *str;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Call the common dialog init code */
|
if (!Silent)
|
||||||
InitDialog (hwndDlg);
|
|
||||||
LocalizeDialog (hwndDlg, NULL);
|
|
||||||
|
|
||||||
SetWindowLongPtrW (hwndDlg, DWLP_USER, (LONG_PTR) (IsAdmin() ? TC_MAIN_WINDOW_FLAG_ADMIN_PRIVILEGES : 0));
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
// Help file name
|
|
||||||
InitHelpFileName();
|
|
||||||
|
|
||||||
// Localize menu strings
|
|
||||||
for (i = 40001; str = (wchar_t *)GetDictionaryValueByInt (i); i++)
|
|
||||||
{
|
{
|
||||||
info.cbSize = sizeof (info);
|
/* Call the common dialog init code */
|
||||||
info.fMask = MIIM_TYPE;
|
InitDialog (hwndDlg);
|
||||||
info.fType = MFT_STRING;
|
LocalizeDialog (hwndDlg, NULL);
|
||||||
info.dwTypeData = str;
|
|
||||||
info.cch = (UINT) wcslen (str);
|
|
||||||
|
|
||||||
SetMenuItemInfoW (GetMenu (hwndDlg), i, FALSE, &info);
|
SetWindowLongPtrW (hwndDlg, DWLP_USER, (LONG_PTR) (IsAdmin() ? TC_MAIN_WINDOW_FLAG_ADMIN_PRIVILEGES : 0));
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; popupTexts[i] != 0; i++)
|
DragAcceptFiles (hwndDlg, TRUE);
|
||||||
{
|
|
||||||
str = GetString (popupTexts[i]);
|
|
||||||
|
|
||||||
info.cbSize = sizeof (info);
|
SendMessageW (GetDlgItem (hwndDlg, IDC_VOLUME), CB_LIMITTEXT, TC_MAX_PATH, 0);
|
||||||
info.fMask = MIIM_TYPE;
|
SetWindowTextW (hwndDlg, (IsAdmin() && !IsBuiltInAdmin() && IsUacSupported() && !IsNonInstallMode()) ? (wstring (lpszTitle) + L" [" + GetString ("ADMINISTRATOR") + L"]").c_str() : lpszTitle);
|
||||||
|
|
||||||
if (strcmp (popupTexts[i], "MENU_WEBSITE") == 0)
|
// Help file name
|
||||||
info.fType = MFT_STRING | MFT_RIGHTJUSTIFY;
|
InitHelpFileName();
|
||||||
else
|
|
||||||
info.fType = MFT_STRING;
|
|
||||||
|
|
||||||
if (strcmp (popupTexts[i], "MENU_FAVORITES") == 0)
|
// Localize menu strings
|
||||||
FavoriteVolumesMenu = GetSubMenu (GetMenu (hwndDlg), i);
|
for (i = 40001; str = (wchar_t *)GetDictionaryValueByInt (i); i++)
|
||||||
|
|
||||||
info.dwTypeData = str;
|
|
||||||
info.cch = (UINT) wcslen (str);
|
|
||||||
|
|
||||||
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);
|
info.cbSize = sizeof (info);
|
||||||
}
|
info.fMask = MIIM_TYPE;
|
||||||
}
|
info.fType = MFT_STRING;
|
||||||
|
info.dwTypeData = str;
|
||||||
|
info.cch = (UINT) wcslen (str);
|
||||||
|
|
||||||
// Disable menu item for changing system header key derivation algorithm until it's implemented
|
SetMenuItemInfoW (GetMenu (hwndDlg), i, FALSE, &info);
|
||||||
EnableMenuItem (GetMenu (hwndDlg), IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO, MF_GRAYED);
|
}
|
||||||
|
|
||||||
|
for (i = 0; popupTexts[i] != 0; i++)
|
||||||
|
{
|
||||||
|
str = GetString (popupTexts[i]);
|
||||||
|
|
||||||
|
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_FAVORITES") == 0)
|
||||||
|
FavoriteVolumesMenu = GetSubMenu (GetMenu (hwndDlg), i);
|
||||||
|
|
||||||
|
info.dwTypeData = str;
|
||||||
|
info.cch = (UINT) wcslen (str);
|
||||||
|
|
||||||
|
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 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);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -497,31 +505,36 @@ static void InitMainDialog (HWND hwndDlg)
|
|||||||
// initialize the list of devices available for mounting as early as possible
|
// initialize the list of devices available for mounting as early as possible
|
||||||
UpdateMountableHostDeviceList ();
|
UpdateMountableHostDeviceList ();
|
||||||
|
|
||||||
// Resize the logo bitmap if the user has a non-default DPI
|
if (Silent)
|
||||||
if (ScreenDPI != USER_DEFAULT_SCREEN_DPI
|
LoadDriveLetters (hwndDlg, NULL, 0);
|
||||||
&& 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));
|
|
||||||
|
|
||||||
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
|
else
|
||||||
{
|
{
|
||||||
SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM) GetDlgItem (hwndDlg, IDC_DRIVELIST), 1L);
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
SendMessage (GetDlgItem (hwndDlg, IDC_NO_HISTORY), BM_SETCHECK, bHistory ? BST_UNCHECKED : BST_CHECKED, 0);
|
BuildTree (hwndDlg, GetDlgItem (hwndDlg, IDC_DRIVELIST));
|
||||||
EnableDisableButtons (hwndDlg);
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
SendMessage (GetDlgItem (hwndDlg, IDC_NO_HISTORY), BM_SETCHECK, bHistory ? BST_UNCHECKED : BST_CHECKED, 0);
|
||||||
|
EnableDisableButtons (hwndDlg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnableDisableButtons (HWND hwndDlg)
|
void EnableDisableButtons (HWND hwndDlg)
|
||||||
@@ -1564,7 +1577,7 @@ static void LaunchVolExpander (HWND hwndDlg)
|
|||||||
void LoadDriveLetters (HWND hwndDlg, HWND hTree, int drive)
|
void LoadDriveLetters (HWND hwndDlg, HWND hTree, int drive)
|
||||||
{
|
{
|
||||||
// Remember the top-most visible item
|
// Remember the top-most visible item
|
||||||
int lastTopMostVisibleItem = ListView_GetTopIndex (hTree);
|
int lastTopMostVisibleItem = (!Silent && hTree)? ListView_GetTopIndex (hTree) : 0;
|
||||||
|
|
||||||
wchar_t *szDriveLetters[]=
|
wchar_t *szDriveLetters[]=
|
||||||
{L"A:", L"B:", L"C:", L"D:",
|
{L"A:", L"B:", L"C:", L"D:",
|
||||||
@@ -1618,6 +1631,9 @@ void LoadDriveLetters (HWND hwndDlg, HWND hTree, int drive)
|
|||||||
if (dwUsedDrives == 0)
|
if (dwUsedDrives == 0)
|
||||||
Warning ("DRIVELETTERS", hwndDlg);
|
Warning ("DRIVELETTERS", hwndDlg);
|
||||||
|
|
||||||
|
if (Silent)
|
||||||
|
return;
|
||||||
|
|
||||||
if(drive == 0)
|
if(drive == 0)
|
||||||
ListView_DeleteAllItems(hTree);
|
ListView_DeleteAllItems(hTree);
|
||||||
|
|
||||||
@@ -5182,7 +5198,7 @@ retry:
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interact)
|
if (interact && !Silent)
|
||||||
MessageBoxW (hwndDlg, GetString ("UNMOUNT_FAILED"), lpszTitle, MB_ICONERROR);
|
MessageBoxW (hwndDlg, GetString ("UNMOUNT_FAILED"), lpszTitle, MB_ICONERROR);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -5485,7 +5501,10 @@ static BOOL MountAllDevices (HWND hwndDlg, BOOL bPasswordPrompt)
|
|||||||
param.bPasswordPrompt = bPasswordPrompt;
|
param.bPasswordPrompt = bPasswordPrompt;
|
||||||
param.bRet = FALSE;
|
param.bRet = FALSE;
|
||||||
|
|
||||||
ShowWaitDialog (hwndDlg, FALSE, mountAllDevicesThreadProc, ¶m);
|
if (Silent)
|
||||||
|
mountAllDevicesThreadProc (¶m, hwndDlg);
|
||||||
|
else
|
||||||
|
ShowWaitDialog (hwndDlg, FALSE, mountAllDevicesThreadProc, ¶m);
|
||||||
|
|
||||||
return param.bRet;
|
return param.bRet;
|
||||||
}
|
}
|
||||||
@@ -6612,6 +6631,9 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
|||||||
|
|
||||||
ExtractCommandLine (hwndDlg, (wchar_t *) lParam);
|
ExtractCommandLine (hwndDlg, (wchar_t *) lParam);
|
||||||
|
|
||||||
|
if (Silent && !Quit)
|
||||||
|
Silent = FALSE;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BootEncObj->SetParentWindow (hwndDlg);
|
BootEncObj->SetParentWindow (hwndDlg);
|
||||||
@@ -6824,10 +6846,10 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
|||||||
if (bExplore)
|
if (bExplore)
|
||||||
OpenVolumeExplorerWindow (szDriveLetter[0] - L'A');
|
OpenVolumeExplorerWindow (szDriveLetter[0] - L'A');
|
||||||
|
|
||||||
RefreshMainDlg(hwndDlg);
|
|
||||||
|
|
||||||
if(!Silent)
|
if(!Silent)
|
||||||
{
|
{
|
||||||
|
RefreshMainDlg(hwndDlg);
|
||||||
// Check for problematic file extensions (exe, dll, sys)
|
// Check for problematic file extensions (exe, dll, sys)
|
||||||
if (CheckFileExtension (szFileName))
|
if (CheckFileExtension (szFileName))
|
||||||
Warning ("EXE_FILE_EXTENSION_MOUNT_WARNING", hwndDlg);
|
Warning ("EXE_FILE_EXTENSION_MOUNT_WARNING", hwndDlg);
|
||||||
@@ -6917,6 +6939,15 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
|||||||
TaskBarIconRemove (hwndDlg);
|
TaskBarIconRemove (hwndDlg);
|
||||||
exit (exitCode);
|
exit (exitCode);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Silent)
|
||||||
|
{
|
||||||
|
Silent = FALSE;
|
||||||
|
InitMainDialog (hwndDlg);
|
||||||
|
RefreshMainDlg(hwndDlg);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No command line arguments or only /volume => bring active instance
|
// No command line arguments or only /volume => bring active instance
|
||||||
@@ -9531,7 +9562,7 @@ static BOOL MountFavoriteVolumeBase (HWND hwnd, const FavoriteVolume &favorite,
|
|||||||
else
|
else
|
||||||
mountOptions.ProtectedHidVolPkcs5Prf = CmdVolumePkcs5;
|
mountOptions.ProtectedHidVolPkcs5Prf = CmdVolumePkcs5;
|
||||||
mountOptions.ProtectedHidVolPim = CmdVolumePim;
|
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))
|
||||||
{
|
{
|
||||||
status = FALSE;
|
status = FALSE;
|
||||||
goto skipMount;
|
goto skipMount;
|
||||||
|
|||||||
Reference in New Issue
Block a user