mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-12 11:28:26 -06:00
Windows: Support setting volume label in Explorer through mount option. Support using favorite label as label in Explorer.
This commit is contained in:
@@ -55,6 +55,12 @@ namespace VeraCrypt
|
||||
if (favorite.Path.find ("\\??\\") == 0)
|
||||
favorite.Path = favorite.Path.substr (4);
|
||||
|
||||
if (wcslen (prop.wszLabel))
|
||||
{
|
||||
favorite.Label = prop.wszLabel;
|
||||
favorite.UseLabelInExplorer = true;
|
||||
}
|
||||
|
||||
if (IsVolumeDeviceHosted (favorite.Path.c_str()))
|
||||
{
|
||||
// Get GUID path
|
||||
@@ -373,6 +379,9 @@ namespace VeraCrypt
|
||||
case IDC_FAVORITES_HELP_LINK:
|
||||
Applink (SystemFavoritesMode ? "sysfavorites" : "favorites", TRUE, "");
|
||||
return 1;
|
||||
case IDC_SHOW_PIM:
|
||||
HandleShowPasswordFieldAction (hwndDlg, IDC_SHOW_PIM, IDC_PIM, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -472,20 +481,27 @@ namespace VeraCrypt
|
||||
}
|
||||
|
||||
|
||||
wstring GetFavoriteVolumeLabel (const string &volumePath)
|
||||
wstring GetFavoriteVolumeLabel (const string &volumePath, bool& useInExplorer)
|
||||
{
|
||||
foreach (const FavoriteVolume &favorite, FavoriteVolumes)
|
||||
{
|
||||
if (favorite.Path == volumePath)
|
||||
{
|
||||
useInExplorer = favorite.UseLabelInExplorer;
|
||||
return favorite.Label;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (const FavoriteVolume &favorite, SystemFavoriteVolumes)
|
||||
{
|
||||
if (favorite.Path == volumePath)
|
||||
{
|
||||
useInExplorer = favorite.UseLabelInExplorer;
|
||||
return favorite.Label;
|
||||
}
|
||||
}
|
||||
|
||||
useInExplorer = false;
|
||||
return wstring();
|
||||
}
|
||||
|
||||
@@ -592,6 +608,10 @@ namespace VeraCrypt
|
||||
if (boolVal[0])
|
||||
favorite.MountOnLogOn = (boolVal[0] == '1');
|
||||
|
||||
XmlGetAttributeText (xml, "useLabelInExplorer", boolVal, sizeof (boolVal));
|
||||
if (boolVal[0])
|
||||
favorite.UseLabelInExplorer = (boolVal[0] == '1') && !favorite.ReadOnly;
|
||||
|
||||
if (favorite.Path.find ("\\\\?\\Volume{") == 0 && favorite.Path.rfind ("}\\") == favorite.Path.size() - 2)
|
||||
{
|
||||
string resolvedPath = VolumeGuidPathToDevicePath (favorite.Path);
|
||||
@@ -716,6 +736,9 @@ namespace VeraCrypt
|
||||
if (favorite.OpenExplorerWindow)
|
||||
s += L" openExplorerWindow=\"1\"";
|
||||
|
||||
if (favorite.UseLabelInExplorer && !favorite.ReadOnly)
|
||||
s += L" useLabelInExplorer=\"1\"";
|
||||
|
||||
s += L">" + SingleStringToWide (tq) + L"</volume>";
|
||||
|
||||
fwprintf (f, L"%ws", s.c_str());
|
||||
@@ -791,6 +814,7 @@ namespace VeraCrypt
|
||||
else
|
||||
SetDlgItemText (hwndDlg, IDC_PIM, "");
|
||||
SetDlgItemTextW (hwndDlg, IDC_FAVORITE_LABEL, favorite.Label.c_str());
|
||||
SetCheckBox (hwndDlg, IDC_FAVORITE_USE_LABEL_IN_EXPLORER, favorite.UseLabelInExplorer);
|
||||
SetCheckBox (hwndDlg, IDC_FAVORITE_MOUNT_ON_LOGON, favorite.MountOnLogOn);
|
||||
SetCheckBox (hwndDlg, IDC_FAVORITE_MOUNT_ON_ARRIVAL, favorite.MountOnArrival);
|
||||
SetCheckBox (hwndDlg, IDC_FAVORITE_MOUNT_READONLY, favorite.ReadOnly);
|
||||
@@ -820,6 +844,7 @@ namespace VeraCrypt
|
||||
EnableWindow (GetDlgItem (hwndDlg, IDC_PIM_HELP), enable);
|
||||
EnableWindow (GetDlgItem (hwndDlg, IDT_FAVORITE_LABEL), enable);
|
||||
EnableWindow (GetDlgItem (hwndDlg, IDC_FAVORITE_LABEL), enable);
|
||||
EnableWindow (GetDlgItem (hwndDlg, IDC_FAVORITE_USE_LABEL_IN_EXPLORER), enable);
|
||||
EnableWindow (GetDlgItem (hwndDlg, IDC_FAVORITE_MOUNT_ON_LOGON), enable && !systemFavoritesMode);
|
||||
EnableWindow (GetDlgItem (hwndDlg, IDC_FAVORITE_MOUNT_ON_ARRIVAL), enable && !systemFavoritesMode);
|
||||
EnableWindow (GetDlgItem (hwndDlg, IDC_FAVORITE_MOUNT_READONLY), enable);
|
||||
@@ -846,6 +871,7 @@ namespace VeraCrypt
|
||||
favorite.Label.clear();
|
||||
|
||||
favorite.Pim = GetPim (hwndDlg, IDC_PIM);
|
||||
favorite.UseLabelInExplorer = (IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_USE_LABEL_IN_EXPLORER) != 0);
|
||||
|
||||
favorite.ReadOnly = (IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_MOUNT_READONLY) != 0);
|
||||
favorite.Removable = (IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_MOUNT_REMOVABLE) != 0);
|
||||
|
||||
@@ -29,7 +29,8 @@ namespace VeraCrypt
|
||||
OpenExplorerWindow (false),
|
||||
ReadOnly (false),
|
||||
Removable (false),
|
||||
SystemEncryption (false)
|
||||
SystemEncryption (false),
|
||||
UseLabelInExplorer (false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -47,6 +48,7 @@ namespace VeraCrypt
|
||||
bool ReadOnly;
|
||||
bool Removable;
|
||||
bool SystemEncryption;
|
||||
bool UseLabelInExplorer;
|
||||
};
|
||||
|
||||
struct FavoriteVolumesDlgProcArguments
|
||||
@@ -67,7 +69,7 @@ namespace VeraCrypt
|
||||
static void FillFavoriteVolumesMenu ();
|
||||
static void FillListControl (HWND favoriteListControl, vector <FavoriteVolume> &favorites);
|
||||
static void FillListControlSubItems (HWND favoriteListControl, int line, const FavoriteVolume &favorite);
|
||||
wstring GetFavoriteVolumeLabel (const string &volumePath);
|
||||
wstring GetFavoriteVolumeLabel (const string &volumePath, bool& useInExplorer);
|
||||
void LoadFavoriteVolumes ();
|
||||
void LoadFavoriteVolumes (vector <FavoriteVolume> &favorites, bool systemFavorites, bool noUacElevation = false);
|
||||
static void OnFavoriteVolumesUpdated ();
|
||||
|
||||
@@ -1589,7 +1589,11 @@ void LoadDriveLetters (HWND hwndDlg, HWND hTree, int drive)
|
||||
|
||||
listItem.iSubItem = 1;
|
||||
|
||||
wstring label = GetFavoriteVolumeLabel (path);
|
||||
// first check label used for mounting. If empty, look for it in favorites.
|
||||
bool useInExplorer = false;
|
||||
wstring label = (wchar_t *) driver.wszLabel[i];
|
||||
if (label.empty())
|
||||
label = GetFavoriteVolumeLabel (path, useInExplorer);
|
||||
if (!label.empty())
|
||||
ListSubItemSetW (hTree, listItem.iItem, 1, (wchar_t *) label.c_str());
|
||||
else
|
||||
@@ -2509,10 +2513,13 @@ BOOL CALLBACK PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
|
||||
RECT rect;
|
||||
GetWindowRect (hwndDlg, &rect);
|
||||
|
||||
wstring label = GetFavoriteVolumeLabel (PasswordDlgVolume);
|
||||
bool useInExplorer = false;
|
||||
wstring label = GetFavoriteVolumeLabel (PasswordDlgVolume, useInExplorer);
|
||||
if (!label.empty())
|
||||
{
|
||||
StringCbPrintfW (s, sizeof(s), GetString ("ENTER_PASSWORD_FOR_LABEL"), label.c_str());
|
||||
if (useInExplorer)
|
||||
StringCbCopyW (mountOptions.Label, sizeof (mountOptions.Label), label.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3160,6 +3167,9 @@ BOOL CALLBACK MountOptionsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
|
||||
|
||||
EnableWindow (GetDlgItem (hwndDlg, IDC_MOUNT_SYSENC_PART_WITHOUT_PBA), !bPrebootPasswordDlgMode);
|
||||
|
||||
SetDlgItemTextW (hwndDlg, IDC_VOLUME_LABEL, mountOptions->Label);
|
||||
SendDlgItemMessage (hwndDlg, IDC_VOLUME_LABEL, EM_LIMITTEXT, 32, 0); // 32 is the maximum possible length for a drive label in Windows
|
||||
|
||||
/* Add PRF algorithm list for hidden volume password */
|
||||
HWND hComboBox = GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID);
|
||||
SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
|
||||
@@ -3301,6 +3311,8 @@ BOOL CALLBACK MountOptionsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
|
||||
mountOptions->ProtectHiddenVolume = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL));
|
||||
mountOptions->PartitionInInactiveSysEncScope = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_SYSENC_PART_WITHOUT_PBA));
|
||||
mountOptions->UseBackupHeader = IsButtonChecked (GetDlgItem (hwndDlg, IDC_USE_EMBEDDED_HEADER_BAK));
|
||||
|
||||
GetDlgItemTextW (hwndDlg, IDC_VOLUME_LABEL, mountOptions->Label, sizeof (mountOptions->Label) /sizeof (wchar_t));
|
||||
|
||||
if (mountOptions->ProtectHiddenVolume)
|
||||
{
|
||||
@@ -4421,7 +4433,7 @@ static BOOL DismountAll (HWND hwndDlg, BOOL forceUnmount, BOOL interact, int dis
|
||||
DWORD dwResult;
|
||||
UNMOUNT_STRUCT unmount = {0};
|
||||
BOOL bResult;
|
||||
unsigned __int32 prevMountedDrives = 0;
|
||||
MOUNT_LIST_STRUCT prevMountList = {0};
|
||||
int i;
|
||||
|
||||
retry:
|
||||
@@ -4437,7 +4449,7 @@ retry:
|
||||
|
||||
BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, 0, mountList.ulMountedDrives);
|
||||
|
||||
prevMountedDrives = mountList.ulMountedDrives;
|
||||
memcpy (&prevMountList, &mountList, sizeof (mountList));
|
||||
|
||||
for (i = 0; i < 26; i++)
|
||||
{
|
||||
@@ -4498,7 +4510,17 @@ retry:
|
||||
|
||||
memset (&mountList, 0, sizeof (mountList));
|
||||
DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
|
||||
BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, prevMountedDrives & ~mountList.ulMountedDrives);
|
||||
|
||||
// remove any custom label from registry
|
||||
for (i = 0; i < 26; i++)
|
||||
{
|
||||
if ((prevMountList.ulMountedDrives & (1 << i)) && (!(mountList.ulMountedDrives & (1 << i))) && wcslen (prevMountList.wszLabel[i]))
|
||||
{
|
||||
UpdateDriveCustomLabel (i, prevMountList.wszLabel[i], FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, prevMountList.ulMountedDrives & ~mountList.ulMountedDrives);
|
||||
|
||||
RefreshMainDlg (hwndDlg);
|
||||
|
||||
@@ -6395,7 +6417,11 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
||||
|
||||
if (wcsstr (vol, L"\\??\\")) vol += 4;
|
||||
|
||||
wstring label = GetFavoriteVolumeLabel (WideToSingleString (vol));
|
||||
// first check label used for mounting. If empty, look for it in favorites.
|
||||
bool useInExplorer = false;
|
||||
wstring label = (wchar_t *) LastKnownMountList.wszLabel[i];
|
||||
if (label.empty())
|
||||
label = GetFavoriteVolumeLabel (WideToSingleString (vol), useInExplorer);
|
||||
|
||||
StringCbPrintfW (s, sizeof(s), L"%s %c: (%s)",
|
||||
GetString (n==0 ? "OPEN" : "DISMOUNT"),
|
||||
@@ -7940,7 +7966,7 @@ void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
|
||||
|
||||
case OptionMountOption:
|
||||
{
|
||||
char szTmp[16] = {0};
|
||||
char szTmp[64] = {0};
|
||||
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
|
||||
&i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
|
||||
{
|
||||
@@ -7961,7 +7987,12 @@ void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
|
||||
|
||||
else if (!_stricmp (szTmp, "recovery"))
|
||||
mountOptions.RecoveryMode = TRUE;
|
||||
|
||||
else if ((strlen(szTmp) > 6) && (strlen(szTmp) <= 38) && !_strnicmp (szTmp, "label=", 6))
|
||||
{
|
||||
// get the label
|
||||
memmove (szTmp, &szTmp[6], (strlen(szTmp) - 6) + 1);
|
||||
MultiByteToWideChar (CP_ACP, 0, szTmp, -1, mountOptions.Label, sizeof (mountOptions.Label) / sizeof(wchar_t));
|
||||
}
|
||||
else
|
||||
AbortProcess ("COMMAND_LINE_ERROR");
|
||||
|
||||
@@ -8469,6 +8500,10 @@ static BOOL MountFavoriteVolumeBase (const FavoriteVolume &favorite, BOOL& lastb
|
||||
|
||||
mountOptions.ReadOnly = favorite.ReadOnly || userForcedReadOnly;
|
||||
mountOptions.Removable = favorite.Removable;
|
||||
if (favorite.UseLabelInExplorer && !favorite.Label.empty())
|
||||
StringCbCopyW (mountOptions.Label, sizeof (mountOptions.Label), favorite.Label.c_str());
|
||||
else
|
||||
ZeroMemory (mountOptions.Label, sizeof (mountOptions.Label));
|
||||
|
||||
if (favorite.SystemEncryption)
|
||||
{
|
||||
|
||||
@@ -315,7 +315,7 @@ BEGIN
|
||||
LTEXT "",IDT_LIMIT_ENC_THREAD_POOL_NOTE,18,126,334,33
|
||||
END
|
||||
|
||||
IDD_FAVORITE_VOLUMES DIALOGEX 0, 0, 380, 315
|
||||
IDD_FAVORITE_VOLUMES DIALOGEX 0, 0, 380, 339
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "VeraCrypt - Favorite Volumes"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
@@ -324,28 +324,31 @@ BEGIN
|
||||
PUSHBUTTON "Move &Up",IDC_FAVORITE_MOVE_UP,7,104,63,14
|
||||
PUSHBUTTON "Move &Down",IDC_FAVORITE_MOVE_DOWN,74,104,63,14
|
||||
PUSHBUTTON "&Remove",IDC_FAVORITE_REMOVE,310,104,63,14
|
||||
EDITTEXT IDC_FAVORITE_LABEL,16,173,204,13,ES_AUTOHSCROLL
|
||||
EDITTEXT IDC_FAVORITE_LABEL,18,185,204,13,ES_AUTOHSCROLL
|
||||
CONTROL "Mount selected volume as read-o&nly",IDC_FAVORITE_MOUNT_READONLY,
|
||||
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,193,349,10
|
||||
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,215,349,10
|
||||
CONTROL "Mount selected volume as remo&vable medium",IDC_FAVORITE_MOUNT_REMOVABLE,
|
||||
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,207,349,10
|
||||
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,229,349,10
|
||||
CONTROL "Mount selected volume upon log&on",IDC_FAVORITE_MOUNT_ON_LOGON,
|
||||
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,221,349,10
|
||||
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,243,349,10
|
||||
CONTROL "Mount selected volume when its host device gets &connected",IDC_FAVORITE_MOUNT_ON_ARRIVAL,
|
||||
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,235,349,10
|
||||
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,257,349,10
|
||||
CONTROL "Open &Explorer window for selected volume when successfully mounted",IDC_FAVORITE_OPEN_EXPLORER_WIN_ON_MOUNT,
|
||||
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,249,349,11
|
||||
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,271,349,11
|
||||
CONTROL "Do not mount selected volume when 'Mount Favorite Volumes' &hot key is pressed",IDC_FAVORITE_DISABLE_HOTKEY,
|
||||
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,264,349,11
|
||||
LTEXT "Help on favorite volumes",IDC_FAVORITES_HELP_LINK,17,298,237,10,SS_NOTIFY
|
||||
DEFPUSHBUTTON "OK",IDOK,269,296,50,14
|
||||
PUSHBUTTON "Cancel",IDCANCEL,323,296,50,14
|
||||
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,286,349,11
|
||||
LTEXT "Help on favorite volumes",IDC_FAVORITES_HELP_LINK,17,322,237,10,SS_NOTIFY
|
||||
DEFPUSHBUTTON "OK",IDOK,269,318,50,14
|
||||
PUSHBUTTON "Cancel",IDCANCEL,323,318,50,14
|
||||
GROUPBOX "",IDC_FAV_VOL_OPTIONS_GROUP_BOX,7,122,366,159
|
||||
LTEXT "Label of selected favorite volume:",IDT_FAVORITE_LABEL,18,163,202,8
|
||||
GROUPBOX "Global Settings",IDC_FAV_VOL_OPTIONS_GLOBAL_SETTINGS_BOX,7,230,366,57
|
||||
EDITTEXT IDC_PIM,16,143,42,14,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER
|
||||
LTEXT "Label of selected favorite volume:",IDT_FAVORITE_LABEL,18,175,202,8
|
||||
GROUPBOX "Global Settings",IDC_FAV_VOL_OPTIONS_GLOBAL_SETTINGS_BOX,7,252,366,57
|
||||
EDITTEXT IDC_PIM,18,143,42,13,ES_RIGHT | ES_PASSWORD | ES_AUTOHSCROLL | ES_NUMBER
|
||||
LTEXT "(Empty or 0 for default iterations)",IDC_PIM_HELP,64,145,189,8
|
||||
LTEXT "Volume PIM:",IDT_PIM,18,133,65,8
|
||||
CONTROL "Display PIM",IDC_SHOW_PIM,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,159,150,10
|
||||
CONTROL "Use favorite label as Explorer drive label",IDC_FAVORITE_USE_LABEL_IN_EXPLORER,
|
||||
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,202,203,10
|
||||
END
|
||||
|
||||
IDD_DEFAULT_MOUNT_PARAMETERS DIALOGEX 0, 0, 167, 65
|
||||
@@ -449,7 +452,7 @@ BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 373
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 308
|
||||
BOTTOMMARGIN, 332
|
||||
END
|
||||
|
||||
IDD_DEFAULT_MOUNT_PARAMETERS, DIALOG
|
||||
|
||||
@@ -167,6 +167,8 @@
|
||||
#define IDC_OLD_PIM 1143
|
||||
#define IDC_OLD_PIM_HELP 1144
|
||||
#define IDC_NEW_PIM_ENABLE 1145
|
||||
#define IDC_SHOW_PIM 1146
|
||||
#define IDC_FAVORITE_USE_LABEL_IN_EXPLORER 1147
|
||||
#define IDM_HELP 40001
|
||||
#define IDM_ABOUT 40002
|
||||
#define IDM_UNMOUNT_VOLUME 40003
|
||||
@@ -242,7 +244,7 @@
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 119
|
||||
#define _APS_NEXT_COMMAND_VALUE 40068
|
||||
#define _APS_NEXT_CONTROL_VALUE 1146
|
||||
#define _APS_NEXT_CONTROL_VALUE 1148
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user