VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Mount/Favorites.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mount/Favorites.cpp')
-rw-r--r--src/Mount/Favorites.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/Mount/Favorites.cpp b/src/Mount/Favorites.cpp
index 825562f2..45883bc9 100644
--- a/src/Mount/Favorites.cpp
+++ b/src/Mount/Favorites.cpp
@@ -98,6 +98,7 @@ namespace VeraCrypt
favorite.SystemEncryption = prop.partitionInInactiveSysEncScope ? true : false;
favorite.OpenExplorerWindow = (bExplore == TRUE);
favorite.Pim = prop.volumePim;
+ memcpy (favorite.VolumeID, prop.volumeID, VOLUME_ID_SIZE);
if (favorite.VolumePathId.empty()
&& IsVolumeDeviceHosted (favorite.Path.c_str())
@@ -416,6 +417,19 @@ namespace VeraCrypt
case WM_CLOSE:
EndDialog (hwndDlg, IDCLOSE);
return 1;
+ case WM_CTLCOLORSTATIC:
+ {
+ HDC hdc = (HDC) wParam;
+ HWND hw = (HWND) lParam;
+ if (hw == GetDlgItem(hwndDlg, IDC_FAVORITE_VOLUME_ID))
+ {
+ // This the favorite ID field. Make its background like normal edit
+ HBRUSH hbr = GetSysColorBrush (COLOR_WINDOW);
+ ::SelectObject(hdc, hbr);
+ return (BOOL) hbr;
+ }
+ }
+ break;
}
return 0;
@@ -566,6 +580,17 @@ namespace VeraCrypt
favorite.Path = Utf8StringToWide (volume);
char label[1024];
+
+ XmlGetAttributeText (xml, "ID", label, sizeof (label));
+ if (strlen (label) == (2*VOLUME_ID_SIZE))
+ {
+ std::vector<byte> arr;
+ if (HexWideStringToArray (Utf8StringToWide (label).c_str(), arr) && arr.size() == VOLUME_ID_SIZE)
+ {
+ memcpy (favorite.VolumeID, &arr[0], VOLUME_ID_SIZE);
+ }
+ }
+
XmlGetAttributeText (xml, "label", label, sizeof (label));
favorite.Label = Utf8StringToWide (label);
@@ -612,6 +637,10 @@ namespace VeraCrypt
if (boolVal[0])
favorite.UseLabelInExplorer = (boolVal[0] == '1') && !favorite.ReadOnly;
+ XmlGetAttributeText (xml, "useVolumeID", boolVal, sizeof (boolVal));
+ if (boolVal[0])
+ favorite.UseVolumeID = (boolVal[0] == '1') && !IsRepeatedByteArray (0, favorite.VolumeID, sizeof (favorite.VolumeID));
+
if (favorite.Path.find (L"\\\\?\\Volume{") == 0 && favorite.Path.rfind (L"}\\") == favorite.Path.size() - 2)
{
wstring resolvedPath = VolumeGuidPathToDevicePath (favorite.Path);
@@ -709,6 +738,9 @@ namespace VeraCrypt
wstring s = L"\n\t\t<volume mountpoint=\"" + favorite.MountPoint + L"\"";
+ if (!IsRepeatedByteArray (0, favorite.VolumeID, sizeof (favorite.VolumeID)))
+ s += L" ID=\"" + ArrayToHexWideString (favorite.VolumeID, sizeof (favorite.VolumeID)) + L"\"";
+
if (!favorite.Label.empty())
s += L" label=\"" + favorite.Label + L"\"";
@@ -739,6 +771,9 @@ namespace VeraCrypt
if (favorite.UseLabelInExplorer && !favorite.ReadOnly)
s += L" useLabelInExplorer=\"1\"";
+ if (favorite.UseVolumeID && !IsRepeatedByteArray (0, favorite.VolumeID, sizeof (favorite.VolumeID)))
+ s += L" useVolumeID=\"1\"";
+
s += L">" + wstring (tq) + L"</volume>";
fwprintf (f, L"%ws", s.c_str());
@@ -805,6 +840,7 @@ namespace VeraCrypt
static void SetControls (HWND hwndDlg, const FavoriteVolume &favorite, bool systemFavoritesMode, bool enable)
{
+ BOOL bIsDevice = favorite.DisconnectedDevice || IsVolumeDeviceHosted (favorite.Path.c_str()) || !enable;
if (favorite.Pim > 0)
{
wchar_t szTmp[MAX_PIM + 1];
@@ -819,6 +855,14 @@ namespace VeraCrypt
SetCheckBox (hwndDlg, IDC_FAVORITE_MOUNT_ON_ARRIVAL, favorite.MountOnArrival);
SetCheckBox (hwndDlg, IDC_FAVORITE_MOUNT_READONLY, favorite.ReadOnly);
SetCheckBox (hwndDlg, IDC_FAVORITE_MOUNT_REMOVABLE, favorite.Removable);
+ SetCheckBox (hwndDlg, IDC_FAVORITE_USE_VOLUME_ID, favorite.UseVolumeID && bIsDevice);
+
+ if (IsRepeatedByteArray (0, favorite.VolumeID, sizeof (favorite.VolumeID)) || !bIsDevice)
+ {
+ SetDlgItemText (hwndDlg, IDC_FAVORITE_VOLUME_ID, L"");
+ }
+ else
+ SetDlgItemText (hwndDlg, IDC_FAVORITE_VOLUME_ID, ArrayToHexWideString (favorite.VolumeID, sizeof (favorite.VolumeID)).c_str());
if (systemFavoritesMode)
{
@@ -852,6 +896,44 @@ namespace VeraCrypt
EnableWindow (GetDlgItem (hwndDlg, IDC_FAVORITE_MOUNT_REMOVABLE), enable);
EnableWindow (GetDlgItem (hwndDlg, IDC_FAVORITE_OPEN_EXPLORER_WIN_ON_MOUNT), enable || systemFavoritesMode);
EnableWindow (GetDlgItem (hwndDlg, IDC_FAVORITE_DISABLE_HOTKEY), enable || systemFavoritesMode);
+ EnableWindow (GetDlgItem (hwndDlg, IDT_VOLUME_ID), enable && bIsDevice);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_FAVORITE_VOLUME_ID), enable && bIsDevice);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_FAVORITE_USE_VOLUME_ID), enable && bIsDevice && !IsRepeatedByteArray (0, favorite.VolumeID, sizeof (favorite.VolumeID)));
+
+ ShowWindow (GetDlgItem (hwndDlg, IDT_VOLUME_ID), bIsDevice? SW_SHOW : SW_HIDE);
+ ShowWindow (GetDlgItem (hwndDlg, IDC_FAVORITE_VOLUME_ID), bIsDevice? SW_SHOW : SW_HIDE);
+ ShowWindow (GetDlgItem (hwndDlg, IDC_FAVORITE_USE_VOLUME_ID), bIsDevice? SW_SHOW : SW_HIDE);
+
+ // Group box
+ RECT boxRect, checkRect, labelRect;
+
+ GetWindowRect (GetDlgItem (hwndDlg, IDC_FAV_VOL_OPTIONS_GROUP_BOX), &boxRect);
+ GetWindowRect (GetDlgItem (hwndDlg, IDC_FAVORITE_USE_VOLUME_ID), &checkRect);
+ GetWindowRect (GetDlgItem (hwndDlg, IDT_VOLUME_ID), &labelRect);
+
+ if (!bIsDevice && (boxRect.top < checkRect.top))
+ {
+ POINT pt = {boxRect.left, checkRect.bottom};
+ ScreenToClient (hwndDlg, &pt);
+ SetWindowPos (GetDlgItem (hwndDlg, IDC_FAV_VOL_OPTIONS_GROUP_BOX), 0, pt.x, pt.y,
+ boxRect.right - boxRect.left,
+ boxRect.bottom - checkRect.bottom,
+ SWP_NOZORDER);
+
+ InvalidateRect (GetDlgItem (hwndDlg, IDC_FAV_VOL_OPTIONS_GROUP_BOX), NULL, TRUE);
+ }
+
+ if (bIsDevice && (boxRect.top >= checkRect.top))
+ {
+ POINT pt = {boxRect.left, labelRect.top - CompensateYDPI (10)};
+ ScreenToClient (hwndDlg, &pt);
+ SetWindowPos (GetDlgItem (hwndDlg, IDC_FAV_VOL_OPTIONS_GROUP_BOX), 0, pt.x, pt.y,
+ boxRect.right - boxRect.left,
+ boxRect.bottom - labelRect.top + CompensateYDPI (10),
+ SWP_NOZORDER);
+
+ InvalidateRect (GetDlgItem (hwndDlg, IDC_FAV_VOL_OPTIONS_GROUP_BOX), NULL, TRUE);
+ }
}
@@ -873,6 +955,7 @@ namespace VeraCrypt
favorite.Pim = GetPim (hwndDlg, IDC_PIM);
favorite.UseLabelInExplorer = (IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_USE_LABEL_IN_EXPLORER) != 0);
+ favorite.UseVolumeID = (IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_USE_VOLUME_ID) != 0);
favorite.ReadOnly = (IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_MOUNT_READONLY) != 0);
favorite.Removable = (IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_MOUNT_REMOVABLE) != 0);