|
|
1.1.1.11 root 1: /*
2: Legal Notice: The source code contained in this file has been derived from
3: the source code of Encryption for the Masses 2.02a, which is Copyright (c)
4: Paul Le Roux and which is covered by the 'License Agreement for Encryption
5: for the Masses'. Modifications and additions to that source code contained
6: in this file are Copyright (c) TrueCrypt Foundation and are covered by the
1.1.1.12! root 7: TrueCrypt License 2.3 the full text of which is contained in the file
1.1.1.11 root 8: License.txt included in TrueCrypt binary and source code distribution
9: packages. */
1.1 root 10:
1.1.1.7 root 11: #include "Tcdefs.h"
1.1.1.5 root 12: #include <time.h>
1.1.1.7 root 13: #include <math.h>
1.1.1.5 root 14: #include <dbt.h>
1.1.1.7 root 15: #include <windowsx.h>
16: #include "Apidrvr.h"
17: #include "Cmdline.h"
18: #include "Crypto.h"
19: #include "Dlgcode.h"
20: #include "Combo.h"
21: #include "Hotkeys.h"
22: #include "Keyfiles.h"
23: #include "Language.h"
1.1.1.11 root 24: #include "MainCom.h"
1.1 root 25: #include "Mount.h"
1.1.1.7 root 26: #include "Pkcs5.h"
27: #include "Registry.h"
28: #include "Resource.h"
1.1 root 29: #include "Password.h"
1.1.1.7 root 30: #include "Xml.h"
31: #include "../Common/Dictionary.h"
32: #include "../Common/Common.h"
33: #include "../Common/Resource.h"
1.1 root 34:
35: BOOL bExplore = FALSE; /* Display explorer window after mount */
36: BOOL bBeep = FALSE; /* Donot beep after mount */
1.1.1.8 root 37: char szFileName[TC_MAX_PATH+1]; /* Volume to mount */
1.1 root 38: char szDriveLetter[3]; /* Drive Letter to mount */
1.1.1.5 root 39: char commandLineDrive = 0;
1.1 root 40: BOOL bCacheInDriver = FALSE; /* Cache any passwords we see */
1.1.1.11 root 41: BOOL bCacheInDriverDefault = FALSE;
1.1 root 42: BOOL bHistoryCmdLine = FALSE; /* History control is always disabled */
43: BOOL bCloseDismountedWindows=TRUE; /* Close all open explorer windows of dismounted volume */
44: BOOL bWipeCacheOnExit = FALSE; /* Wipe password from chace on exit */
1.1.1.7 root 45: BOOL bWipeCacheOnAutoDismount = TRUE;
46: BOOL bStartOnLogon = FALSE;
47: BOOL bMountDevicesOnLogon = FALSE;
48: BOOL bMountFavoritesOnLogon = FALSE;
49: BOOL bEnableBkgTask = FALSE;
50: BOOL bCloseBkgTaskWhenNoVolumes = FALSE;
51: BOOL bDismountOnLogOff = TRUE;
52: BOOL bDismountOnScreenSaver = TRUE;
53: BOOL bDismountOnPowerSaving = FALSE;
54: BOOL bForceAutoDismount = TRUE;
1.1.1.5 root 55: BOOL bForceMount = FALSE; /* Mount volume even if host file/device already in use */
56: BOOL bForceUnmount = FALSE; /* Unmount volume even if it cannot be locked */
1.1 root 57: BOOL bWipe = FALSE; /* Wipe driver passwords */
58: BOOL bAuto = FALSE; /* Do everything without user input */
1.1.1.6 root 59: BOOL bAutoMountDevices = FALSE; /* Auto-mount devices */
1.1.1.7 root 60: BOOL bAutoMountFavorites = FALSE;
61: BOOL bPlaySoundOnHotkeyMountDismount = TRUE;
62: BOOL bDisplayMsgBoxOnHotkeyDismount = FALSE;
1.1 root 63:
1.1.1.7 root 64: BOOL Quit = FALSE; /* Exit after processing command line */
1.1.1.11 root 65: BOOL ComServerMode = FALSE;
1.1.1.7 root 66: BOOL UsePreferences = TRUE;
1.1 root 67:
1.1.1.7 root 68: int MaxVolumeIdleTime = -120;
1.1 root 69: int nCurrentShowType = 0; /* current display mode, mount, unmount etc */
1.1.1.5 root 70: int nSelectedDriveIndex = -1; /* Item number of selected drive */
1.1 root 71:
1.1.1.7 root 72: int cmdUnmountDrive = 0; /* Volume drive letter to unmount (-1 = all) */
73: Password VolumePassword; /* Password used for mounting volumes */
74: Password CmdVolumePassword; /* Password passed from command line */
75: BOOL CmdVolumePasswordValid;
1.1.1.6 root 76: MountOptions mountOptions;
77: MountOptions defaultMountOptions;
1.1.1.7 root 78: KeyFile *FirstCmdKeyFile;
79:
1.1.1.12! root 80: HBITMAP hbmLogoBitmapRescaled = NULL;
! 81:
1.1.1.7 root 82: static KeyFilesDlgParam hidVolProtKeyFilesParam;
83:
84: static MOUNT_LIST_STRUCT LastKnownMountList;
85: static VOLUME_NOTIFICATIONS_LIST VolumeNotificationsList;
86: static DWORD LastKnownLogicalDrives;
87:
88: static HANDLE TaskBarIconMutex = NULL;
89: static BOOL MainWindowHidden = FALSE;
90: static int pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
1.1.1.8 root 91: static int NoCmdLineArgs;
92: static BOOL CmdLineVolumeSpecified;
1.1.1.6 root 93:
1.1 root 94: void
95: localcleanup (void)
96: {
1.1.1.9 root 97: // Wipe command line
98: char *c = GetCommandLineA ();
99: wchar_t *wc = GetCommandLineW ();
100: burn(c, strlen (c));
101: burn(wc, wcslen (wc) * sizeof (wchar_t));
102:
1.1.1.12! root 103: /* Delete buffered bitmaps (if any) */
! 104: if (hbmLogoBitmapRescaled != NULL)
! 105: {
! 106: DeleteObject ((HGDIOBJ) hbmLogoBitmapRescaled);
! 107: hbmLogoBitmapRescaled = NULL;
! 108: }
! 109:
1.1 root 110: /* Cleanup common code resources */
111: cleanup ();
112: }
113:
114: void
115: RefreshMainDlg (HWND hwndDlg)
116: {
117: int drive = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))));
118:
1.1.1.10 root 119: MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME), bHistory);
1.1 root 120: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), drive);
121: EnableDisableButtons (hwndDlg);
122: }
123:
124: void
125: EndMainDlg (HWND hwndDlg)
126: {
1.1.1.10 root 127: MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME), bHistory);
1.1.1.7 root 128:
129: if (UsePreferences)
130: SaveSettings (hwndDlg);
1.1 root 131:
132: if (bWipeCacheOnExit)
133: {
134: DWORD dwResult;
135: DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
136: }
137:
1.1.1.10 root 138: if (!bHistory)
139: {
140: SetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), "");
1.1.1.11 root 141: ClearHistory (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.10 root 142: }
143:
1.1.1.7 root 144: if (TaskBarIconMutex != NULL)
145: {
146: MainWindowHidden = TRUE;
147: ShowWindow (hwndDlg, SW_HIDE);
148: }
149: else
150: {
151: TaskBarIconRemove (hwndDlg);
152: EndDialog (hwndDlg, 0);
153: }
1.1 root 154: }
155:
1.1.1.7 root 156: static void InitMainDialog (HWND hwndDlg)
1.1 root 157: {
1.1.1.7 root 158: MENUITEMINFOW info;
159: char *popupTexts[] = {"MENU_FILE", "MENU_VOLUMES", "MENU_KEYFILES", "MENU_TOOLS", "MENU_SETTINGS", "MENU_HELP", "MENU_WEBSITE", 0};
160: wchar_t *str;
161: int i;
1.1 root 162:
1.1.1.7 root 163: /* Call the common dialog init code */
164: InitDialog (hwndDlg);
165: LocalizeDialog (hwndDlg, NULL);
166:
167: DragAcceptFiles (hwndDlg, TRUE);
1.1 root 168:
1.1.1.7 root 169: SendMessage (GetDlgItem (hwndDlg, IDC_VOLUME), CB_LIMITTEXT, TC_MAX_PATH, 0);
170: SetWindowTextW (hwndDlg, lpszTitle);
171:
172: // Help file name
173: InitHelpFileName();
174:
175: // Localize menu strings
176: for (i = 40001; str = (wchar_t *)GetDictionaryValueByInt (i); i++)
1.1 root 177: {
1.1.1.7 root 178: info.cbSize = sizeof (info);
179: info.fMask = MIIM_TYPE;
180: info.fType = MFT_STRING;
181: info.dwTypeData = str;
182: info.cch = wcslen (str);
1.1 root 183:
1.1.1.7 root 184: SetMenuItemInfoW (GetMenu (hwndDlg), i, FALSE, &info);
1.1 root 185: }
1.1.1.7 root 186:
187: for (i = 0; popupTexts[i] != 0; i++)
188: {
189: str = GetString (popupTexts[i]);
190:
191: info.cbSize = sizeof (info);
192: info.fMask = MIIM_TYPE;
193:
194: if (memcmp (popupTexts[i], "MENU_WEBSITE", 6) == 0)
195: info.fType = MFT_STRING | MFT_RIGHTJUSTIFY;
196: else
197: info.fType = MFT_STRING;
198:
199: info.dwTypeData = str;
200: info.cch = wcslen (str);
201:
202: SetMenuItemInfoW (GetMenu (hwndDlg), i, TRUE, &info);
203: }
204:
1.1.1.12! root 205: // Resize the logo bitmap if the user has a non-default DPI
! 206: if (ScreenDPI != USER_DEFAULT_SCREEN_DPI)
! 207: {
! 208: hbmLogoBitmapRescaled = RenderBitmap (MAKEINTRESOURCE (IDB_LOGO_288DPI),
! 209: GetDlgItem (hwndDlg, IDC_LOGO),
! 210: 0, 0, 0, 0, FALSE, TRUE);
! 211: }
! 212:
1.1.1.7 root 213: BuildTree (GetDlgItem (hwndDlg, IDC_DRIVELIST));
214:
215: if (*szDriveLetter != 0)
1.1 root 216: {
1.1.1.7 root 217: SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST), *szDriveLetter);
1.1 root 218:
1.1.1.7 root 219: if(nSelectedDriveIndex > SendMessage (GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_GETITEMCOUNT, 0, 0)/2)
220: SendMessage(GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_SCROLL, 0, 1000);
1.1 root 221: }
222:
1.1.1.7 root 223: SendMessage (GetDlgItem (hwndDlg, IDC_NO_HISTORY), BM_SETCHECK, bHistory ? BST_UNCHECKED : BST_CHECKED, 0);
224: EnableDisableButtons (hwndDlg);
225: }
226:
227: void
228: EnableDisableButtons (HWND hwndDlg)
229: {
230: HWND hOKButton = GetDlgItem (hwndDlg, IDOK);
231: WORD x;
232:
233: x = LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST)));
234:
235: EnableMenuItem (GetMenu (hwndDlg), IDM_MOUNT_VOLUME, MF_ENABLED);
236: EnableMenuItem (GetMenu (hwndDlg), IDM_MOUNT_VOLUME_OPTIONS, MF_ENABLED);
237: EnableMenuItem (GetMenu (hwndDlg), IDM_BACKUP_VOL_HEADER, MF_ENABLED);
238: EnableMenuItem (GetMenu (hwndDlg), IDM_RESTORE_VOL_HEADER, MF_ENABLED);
239: EnableMenuItem (GetMenu (hwndDlg), IDM_CHANGE_PASSWORD, MF_ENABLED);
240: EnableWindow (hOKButton, TRUE);
241:
1.1 root 242: if (x == VFREE)
243: {
1.1.1.7 root 244: SetWindowTextW (hOKButton, GetString ("MOUNT_BUTTON"));
1.1 root 245:
1.1.1.7 root 246: EnableMenuItem (GetMenu (hwndDlg), IDM_UNMOUNT_VOLUME, MF_GRAYED);
1.1 root 247: }
248:
249: if (x == VMOUNTED)
250: {
1.1.1.7 root 251: SetWindowTextW (hOKButton, GetString ("UNMOUNT_BUTTON"));
1.1 root 252: EnableWindow (hOKButton, TRUE);
1.1.1.7 root 253: EnableMenuItem (GetMenu (hwndDlg), IDM_UNMOUNT_VOLUME, MF_ENABLED);
1.1 root 254:
255: EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), TRUE);
1.1.1.7 root 256: EnableMenuItem (GetMenu (hwndDlg), IDM_VOLUME_PROPERTIES, MF_ENABLED);
1.1 root 257: }
258: else
259: {
1.1.1.7 root 260: SetWindowTextW (hOKButton, GetString ("MOUNT_BUTTON"));
1.1 root 261: EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), FALSE);
1.1.1.7 root 262: EnableMenuItem (GetMenu (hwndDlg), IDM_VOLUME_PROPERTIES, MF_GRAYED);
1.1 root 263: }
264:
265: EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_CACHE), !IsPasswordCacheEmpty());
1.1.1.7 root 266: EnableMenuItem (GetMenu (hwndDlg), IDM_WIPE_CACHE, IsPasswordCacheEmpty() ? MF_GRAYED:MF_ENABLED);
267: EnableMenuItem (GetMenu (hwndDlg), IDM_CLEAR_HISTORY, IsComboEmpty (GetDlgItem (hwndDlg, IDC_VOLUME)) ? MF_GRAYED:MF_ENABLED);
1.1 root 268: }
269:
1.1.1.7 root 270: BOOL VolumeSelected (HWND hwndDlg)
1.1 root 271: {
1.1.1.7 root 272: return (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_VOLUME)) > 0);
1.1 root 273: }
274:
275: void
276: LoadSettings (HWND hwndDlg)
277: {
278: // Options
1.1.1.7 root 279: bExplore = ConfigReadInt ("OpenExplorerWindowAfterMount", FALSE);
280: bCloseDismountedWindows = ConfigReadInt ("CloseExplorerWindowsOnDismount", TRUE);
281:
282: bHistory = ConfigReadInt ("SaveVolumeHistory", FALSE);
283:
1.1.1.11 root 284: bCacheInDriverDefault = bCacheInDriver = ConfigReadInt ("CachePasswords", FALSE);
1.1.1.7 root 285: bWipeCacheOnExit = ConfigReadInt ("WipePasswordCacheOnExit", FALSE);
286: bWipeCacheOnAutoDismount = ConfigReadInt ("WipeCacheOnAutoDismount", TRUE);
287:
288: bStartOnLogon = ConfigReadInt ("StartOnLogon", FALSE);
289: bMountDevicesOnLogon = ConfigReadInt ("MountDevicesOnLogon", FALSE);
290: bMountFavoritesOnLogon = ConfigReadInt ("MountFavoritesOnLogon", FALSE);
291:
292: bEnableBkgTask = ConfigReadInt ("EnableBackgroundTask", TRUE);
293: bCloseBkgTaskWhenNoVolumes = ConfigReadInt ("CloseBackgroundTaskOnNoVolumes", FALSE);
294:
295: bDismountOnLogOff = ConfigReadInt ("DismountOnLogOff", TRUE);
1.1.1.11 root 296: bDismountOnPowerSaving = ConfigReadInt ("DismountOnPowerSaving", TRUE);
1.1.1.7 root 297: bDismountOnScreenSaver = ConfigReadInt ("DismountOnScreenSaver", FALSE);
298: bForceAutoDismount = ConfigReadInt ("ForceAutoDismount", TRUE);
299: MaxVolumeIdleTime = ConfigReadInt ("MaxVolumeIdleTime", -120);
300:
301: defaultKeyFilesParam.EnableKeyFiles = ConfigReadInt ("UseKeyfiles", FALSE);
302:
303: bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = ConfigReadInt ("PreserveTimestamps", TRUE);
304: defaultMountOptions.Removable = ConfigReadInt ("MountVolumesRemovable", FALSE);
305: defaultMountOptions.ReadOnly = ConfigReadInt ("MountVolumesReadOnly", FALSE);
306: defaultMountOptions.ProtectHiddenVolume = FALSE;
307:
1.1.1.6 root 308: mountOptions = defaultMountOptions;
1.1 root 309:
1.1.1.5 root 310: // Drive letter - command line arg overrides registry
311: if (szDriveLetter[0] == 0)
1.1.1.7 root 312: ConfigReadString ("LastSelectedDrive", "", szDriveLetter, sizeof (szDriveLetter));
313:
314: // Hotkeys
315: bPlaySoundOnHotkeyMountDismount = ConfigReadInt ("PlaySoundOnHotkeyMountDismount", TRUE);
316: bDisplayMsgBoxOnHotkeyDismount = ConfigReadInt ("DisplayMsgBoxOnHotkeyDismount", FALSE);
317: Hotkeys [HK_AUTOMOUNT_DEVICES].vKeyModifiers = ConfigReadInt ("HotkeyModAutoMountDevices", 0);
318: Hotkeys [HK_AUTOMOUNT_DEVICES].vKeyCode = ConfigReadInt ("HotkeyCodeAutoMountDevices", 0);
319: Hotkeys [HK_DISMOUNT_ALL].vKeyModifiers = ConfigReadInt ("HotkeyModDismountAll", 0);
320: Hotkeys [HK_DISMOUNT_ALL].vKeyCode = ConfigReadInt ("HotkeyCodeDismountAll", 0);
1.1.1.11 root 321: Hotkeys [HK_WIPE_CACHE].vKeyModifiers = ConfigReadInt ("HotkeyModWipeCache", 0);
322: Hotkeys [HK_WIPE_CACHE].vKeyCode = ConfigReadInt ("HotkeyCodeWipeCache", 0);
1.1.1.7 root 323: Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyModifiers = ConfigReadInt ("HotkeyModForceDismountAllWipe", 0);
324: Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyCode = ConfigReadInt ("HotkeyCodeForceDismountAllWipe", 0);
325: Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyModifiers = ConfigReadInt ("HotkeyModForceDismountAllWipeExit", 0);
326: Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyCode = ConfigReadInt ("HotkeyCodeForceDismountAllWipeExit", 0);
327: Hotkeys [HK_MOUNT_FAVORITE_VOLUMES].vKeyModifiers = ConfigReadInt ("HotkeyModMountFavoriteVolumes", 0);
328: Hotkeys [HK_MOUNT_FAVORITE_VOLUMES].vKeyCode = ConfigReadInt ("HotkeyCodeMountFavoriteVolumes", 0);
329: Hotkeys [HK_SHOW_HIDE_MAIN_WINDOW].vKeyModifiers = ConfigReadInt ("HotkeyModShowHideMainWindow", 0);
330: Hotkeys [HK_SHOW_HIDE_MAIN_WINDOW].vKeyCode = ConfigReadInt ("HotkeyCodeShowHideMainWindow", 0);
1.1 root 331:
332: // History
333: if (bHistoryCmdLine != TRUE)
1.1.1.10 root 334: {
1.1.1.7 root 335: LoadCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.10 root 336: if (CmdLineVolumeSpecified)
337: SetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
338: }
1.1 root 339: }
340:
341: void
342: SaveSettings (HWND hwndDlg)
343: {
344: char szTmp[32] = {0};
345: LPARAM lLetter;
346:
347: // Options
1.1.1.7 root 348: ConfigWriteBegin ();
349:
350: ConfigWriteInt ("OpenExplorerWindowAfterMount", bExplore);
351: ConfigWriteInt ("CloseExplorerWindowsOnDismount", bCloseDismountedWindows);
352: ConfigWriteInt ("SaveVolumeHistory", !IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY)));
353:
1.1.1.11 root 354: ConfigWriteInt ("CachePasswords", bCacheInDriverDefault);
1.1.1.7 root 355: ConfigWriteInt ("WipePasswordCacheOnExit", bWipeCacheOnExit);
356: ConfigWriteInt ("WipeCacheOnAutoDismount", bWipeCacheOnAutoDismount);
357:
358: ConfigWriteInt ("StartOnLogon", bStartOnLogon);
359: ConfigWriteInt ("MountDevicesOnLogon", bMountDevicesOnLogon);
360: ConfigWriteInt ("MountFavoritesOnLogon", bMountFavoritesOnLogon);
361:
362: ConfigWriteInt ("MountVolumesReadOnly", defaultMountOptions.ReadOnly);
363: ConfigWriteInt ("MountVolumesRemovable", defaultMountOptions.Removable);
364: ConfigWriteInt ("PreserveTimestamps", defaultMountOptions.PreserveTimestamp);
365:
366: ConfigWriteInt ("EnableBackgroundTask", bEnableBkgTask);
367: ConfigWriteInt ("CloseBackgroundTaskOnNoVolumes", bCloseBkgTaskWhenNoVolumes);
368:
369: ConfigWriteInt ("DismountOnLogOff", bDismountOnLogOff);
370: ConfigWriteInt ("DismountOnPowerSaving", bDismountOnPowerSaving);
371: ConfigWriteInt ("DismountOnScreenSaver", bDismountOnScreenSaver);
372: ConfigWriteInt ("ForceAutoDismount", bForceAutoDismount);
373: ConfigWriteInt ("MaxVolumeIdleTime", MaxVolumeIdleTime);
374:
375: ConfigWriteInt ("UseKeyfiles", defaultKeyFilesParam.EnableKeyFiles);
1.1 root 376:
377: // Drive Letter
378: lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
379: if (LOWORD (lLetter) != 0xffff)
380: sprintf (szTmp, "%c:", (char) HIWORD (lLetter));
1.1.1.7 root 381: ConfigWriteString ("LastSelectedDrive", szTmp);
382:
383: // Hotkeys
384: ConfigWriteInt ("HotkeyModAutoMountDevices", Hotkeys[HK_AUTOMOUNT_DEVICES].vKeyModifiers);
385: ConfigWriteInt ("HotkeyCodeAutoMountDevices", Hotkeys[HK_AUTOMOUNT_DEVICES].vKeyCode);
386: ConfigWriteInt ("HotkeyModDismountAll", Hotkeys[HK_DISMOUNT_ALL].vKeyModifiers);
387: ConfigWriteInt ("HotkeyCodeDismountAll", Hotkeys[HK_DISMOUNT_ALL].vKeyCode);
1.1.1.11 root 388: ConfigWriteInt ("HotkeyModWipeCache", Hotkeys[HK_WIPE_CACHE].vKeyModifiers);
389: ConfigWriteInt ("HotkeyCodeWipeCache", Hotkeys[HK_WIPE_CACHE].vKeyCode);
1.1.1.7 root 390: ConfigWriteInt ("HotkeyModForceDismountAllWipe", Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyModifiers);
391: ConfigWriteInt ("HotkeyCodeForceDismountAllWipe", Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyCode);
392: ConfigWriteInt ("HotkeyModForceDismountAllWipeExit", Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyModifiers);
393: ConfigWriteInt ("HotkeyCodeForceDismountAllWipeExit", Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyCode);
394: ConfigWriteInt ("HotkeyModMountFavoriteVolumes", Hotkeys[HK_MOUNT_FAVORITE_VOLUMES].vKeyModifiers);
395: ConfigWriteInt ("HotkeyCodeMountFavoriteVolumes", Hotkeys[HK_MOUNT_FAVORITE_VOLUMES].vKeyCode);
396: ConfigWriteInt ("HotkeyModShowHideMainWindow", Hotkeys[HK_SHOW_HIDE_MAIN_WINDOW].vKeyModifiers);
397: ConfigWriteInt ("HotkeyCodeShowHideMainWindow", Hotkeys[HK_SHOW_HIDE_MAIN_WINDOW].vKeyCode);
398: ConfigWriteInt ("PlaySoundOnHotkeyMountDismount", bPlaySoundOnHotkeyMountDismount);
399: ConfigWriteInt ("DisplayMsgBoxOnHotkeyDismount", bDisplayMsgBoxOnHotkeyDismount);
400:
401: // Language
402: if (GetPreferredLangId () != NULL)
403: ConfigWriteString ("Language", GetPreferredLangId ());
404:
405: ConfigWriteEnd ();
1.1 root 406:
407: // History
1.1.1.7 root 408: DumpCombo (GetDlgItem (hwndDlg, IDC_VOLUME), IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY)));
1.1 root 409: }
410:
411: BOOL
412: SelectItem (HWND hTree, char nLetter)
413: {
414: int i;
415: LVITEM item;
416:
417: for (i = 0; i < ListView_GetItemCount(hTree); i++)
418: {
419: memset(&item, 0, sizeof(LVITEM));
420: item.mask = LVIF_PARAM;
421: item.iItem = i;
422:
423: if (ListView_GetItem (hTree, &item) == FALSE)
424: return FALSE;
425: else
426: {
427: if (HIWORD (item.lParam) == nLetter)
428: {
429: memset(&item, 0, sizeof(LVITEM));
430: item.state = LVIS_FOCUSED|LVIS_SELECTED;
431: item.stateMask = LVIS_FOCUSED|LVIS_SELECTED;
432: item.mask = LVIF_STATE;
433: item.iItem = i;
434: SendMessage(hTree, LVM_SETITEMSTATE, i, (LPARAM) &item);
435: return TRUE;
436: }
437: }
438:
439: }
440:
441: return TRUE;
442: }
443:
444:
445: // Fills drive list
446: // drive>0 = update only the corresponding drive subitems
447: void
448: LoadDriveLetters (HWND hTree, int drive)
449: {
450: char *szDriveLetters[]=
451: {"A:", "B:", "C:", "D:",
452: "E:", "F:", "G:", "H:", "I:", "J:", "K:",
453: "L:", "M:", "N:", "O:", "P:", "Q:", "R:",
454: "S:", "T:", "U:", "V:", "W:", "X:", "Y:",
455: "Z:"};
456:
457: DWORD dwResult;
458: BOOL bResult;
459: DWORD dwUsedDrives;
460: MOUNT_LIST_STRUCT driver;
461:
462: LVITEM listItem;
463: int item = 0;
464: char i;
465:
1.1.1.7 root 466: ZeroMemory (&driver, sizeof (driver));
1.1 root 467: bResult = DeviceIoControl (hDriver, MOUNT_LIST, &driver,
468: sizeof (driver), &driver, sizeof (driver), &dwResult,
469: NULL);
1.1.1.7 root 470: memcpy (&LastKnownMountList, &driver, sizeof (driver));
1.1 root 471:
472: if (bResult == FALSE)
473: {
474: handleWin32Error (hTree);
475: driver.ulMountedDrives = 0;
476: }
477:
1.1.1.7 root 478: LastKnownLogicalDrives = dwUsedDrives = GetLogicalDrives ();
479: if (dwUsedDrives == 0)
480: Warning ("DRIVELETTERS");
1.1 root 481:
482: if(drive == 0)
483: ListView_DeleteAllItems(hTree);
484:
485: for (i = 2; i < 26; i++)
486: {
487: int curDrive = 0;
488:
489: if(drive > 0)
490: {
491: LVITEM tmp;
492: memset(&tmp, 0, sizeof(LVITEM));
493: tmp.mask = LVIF_PARAM;
494: tmp.iItem = item;
1.1.1.7 root 495: if (ListView_GetItem (hTree, &tmp))
1.1 root 496: curDrive = HIWORD(tmp.lParam);
497: }
498:
499: if ( driver.ulMountedDrives & (1 << i) )
500: {
1.1.1.7 root 501: char szTmp[1024];
502: wchar_t szTmpW[1024];
503: wchar_t *ws;
1.1 root 504:
505: memset(&listItem, 0, sizeof(listItem));
506:
507: listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
508: listItem.iImage = 1;
509: listItem.iItem = item++;
510:
511: if(drive > 0 && drive != curDrive)
512: continue;
513:
1.1.1.7 root 514: ToSBCS ((void *) driver.wszVolume[i]);
1.1 root 515:
516: if (memcmp (driver.wszVolume[i], "\\Device", 7) == 0)
517: sprintf (szTmp, "%s", ((char *) driver.wszVolume[i]));
518: else
1.1.1.7 root 519: sprintf (szTmp, "%s", ((char *) driver.wszVolume[i]) + 4);
1.1 root 520:
521: listItem.pszText = szDriveLetters[i];
522: listItem.lParam = MAKELONG (VMOUNTED, i + 'A');
523:
524: if(drive == 0)
525: ListView_InsertItem (hTree, &listItem);
526: else
527: ListView_SetItem (hTree, &listItem);
528:
529: listItem.mask=LVIF_TEXT;
530: listItem.pszText = szTmp;
531:
532: listItem.iSubItem = 1;
1.1.1.5 root 533: ListView_SetItem (hTree, &listItem);
1.1 root 534:
1.1.1.7 root 535: GetSizeString (driver.diskLength[i], szTmpW);
536: ListSubItemSetW (hTree, listItem.iItem, 2, szTmpW);
1.1 root 537:
1.1.1.5 root 538: EAGetName (szTmp, driver.ea[i]);
1.1 root 539: listItem.iSubItem = 3;
1.1.1.5 root 540: ListView_SetItem (hTree, &listItem);
1.1 root 541:
1.1.1.7 root 542: switch (driver.volumeType[i])
543: {
544: case PROP_VOL_TYPE_NORMAL:
545: ws = GetString ("NORMAL");
546: break;
547: case PROP_VOL_TYPE_HIDDEN:
548: ws = GetString ("HIDDEN");
549: break;
550: case PROP_VOL_TYPE_OUTER:
551: ws = GetString ("OUTER"); // Normal/outer volume (hidden volume protected)
552: break;
553: case PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED:
554: ws = GetString ("OUTER_VOL_WRITE_PREVENTED"); // Normal/outer volume (hidden volume protected AND write denied)
555: break;
556: default:
557: ws = L"?";
558: }
559: ListSubItemSetW (hTree, listItem.iItem, 4, ws);
560:
561: if (driver.volumeType[i] == PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED) // Normal/outer volume (hidden volume protected AND write denied)
562: {
563: if (!VolumeNotificationsList.bHidVolDamagePrevReported[i])
564: {
1.1.1.11 root 565: wchar_t szTmp[4096];
1.1.1.7 root 566:
567: VolumeNotificationsList.bHidVolDamagePrevReported[i] = TRUE;
1.1.1.11 root 568: swprintf (szTmp, GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), i+'A');
1.1.1.7 root 569: SetForegroundWindow (GetParent(hTree));
570: MessageBoxW (GetParent(hTree), szTmp, lpszTitle, MB_ICONWARNING);
571: }
572: }
1.1.1.5 root 573: else
1.1.1.7 root 574: {
575: VolumeNotificationsList.bHidVolDamagePrevReported[i] = FALSE;
576: }
1.1 root 577: }
578: else
579: {
1.1.1.7 root 580: VolumeNotificationsList.bHidVolDamagePrevReported[i] = FALSE;
581:
1.1 root 582: if (!(dwUsedDrives & 1 << i))
583: {
584: if(drive > 0 && drive != HIWORD (GetSelectedLong (hTree)))
585: {
586: item++;
587: continue;
588: }
589:
590: memset(&listItem,0,sizeof(listItem));
591:
592: listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
593: listItem.iImage = 0;
594: listItem.iItem = item++;
595: listItem.pszText = szDriveLetters[i];
596: listItem.lParam = MAKELONG (VFREE, i + 'A');
597:
598: if(drive == 0)
599: ListView_InsertItem (hTree, &listItem);
600: else
601: ListView_SetItem (hTree, &listItem);
602:
603: listItem.mask=LVIF_TEXT;
604: listItem.pszText = "";
605: listItem.iSubItem = 1;
1.1.1.5 root 606: ListView_SetItem (hTree, &listItem);
1.1 root 607: listItem.iSubItem = 2;
1.1.1.5 root 608: ListView_SetItem (hTree, &listItem);
1.1 root 609: listItem.iSubItem = 3;
1.1.1.5 root 610: ListView_SetItem (hTree, &listItem);
611: listItem.iSubItem = 4;
612: ListView_SetItem (hTree, &listItem);
1.1 root 613:
614: }
615: }
616: }
617: }
618:
619:
1.1.1.7 root 620: static void PasswordChangeEnable (HWND hwndDlg, int button, int passwordId, BOOL keyFilesEnabled,
621: int newPasswordId, int newVerifyId, BOOL newKeyFilesEnabled)
622: {
623: char password[MAX_PASSWORD + 1];
624: char newPassword[MAX_PASSWORD + 1];
625: char newVerify[MAX_PASSWORD + 1];
626: BOOL bEnable = TRUE;
627:
628: GetWindowText (GetDlgItem (hwndDlg, passwordId), password, sizeof (password));
629:
630: if (pwdChangeDlgMode == PCDM_CHANGE_PKCS5_PRF)
631: newKeyFilesEnabled = keyFilesEnabled;
632:
633: switch (pwdChangeDlgMode)
634: {
635: case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
636: case PCDM_ADD_REMOVE_VOL_KEYFILES:
637: case PCDM_CHANGE_PKCS5_PRF:
638: memcpy (newPassword, password, sizeof (newPassword));
639: memcpy (newVerify, password, sizeof (newVerify));
640: break;
641:
642: default:
643: GetWindowText (GetDlgItem (hwndDlg, newPasswordId), newPassword, sizeof (newPassword));
644: GetWindowText (GetDlgItem (hwndDlg, newVerifyId), newVerify, sizeof (newVerify));
645: }
646:
647: if (!keyFilesEnabled && strlen (password) < MIN_PASSWORD)
648: bEnable = FALSE;
649: else if (strcmp (newPassword, newVerify) != 0)
650: bEnable = FALSE;
651: else if (!newKeyFilesEnabled && strlen (newPassword) < MIN_PASSWORD)
652: bEnable = FALSE;
653:
654: burn (password, sizeof (password));
655: burn (newPassword, sizeof (newPassword));
656: burn (newVerify, sizeof (newVerify));
657:
658: EnableWindow (GetDlgItem (hwndDlg, button), bEnable);
659: }
660:
661:
1.1 root 662: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
663: should return nonzero if it processes the message, and zero if it does
664: not. - see DialogProc */
1.1.1.12! root 665: BOOL CALLBACK
1.1 root 666: PasswordChangeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
667: {
1.1.1.7 root 668: static KeyFilesDlgParam newKeyFilesParam;
1.1 root 669:
670: WORD lw = LOWORD (wParam);
671: WORD hw = HIWORD (wParam);
672:
673: if (lParam); /* remove warning */
674: if (hw); /* remove warning */
675:
676: switch (msg)
677: {
678: case WM_INITDIALOG:
679: {
1.1.1.3 root 680: LPARAM nIndex;
1.1.1.7 root 681: HWND hComboBox = GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID);
1.1.1.3 root 682: int i;
1.1 root 683:
1.1.1.7 root 684: ZeroMemory (&newKeyFilesParam, sizeof (newKeyFilesParam));
1.1 root 685:
1.1.1.7 root 686: SetWindowTextW (hwndDlg, GetString ("IDD_PASSWORDCHANGE_DLG"));
687: LocalizeDialog (hwndDlg, "IDD_PASSWORDCHANGE_DLG");
1.1 root 688:
689: SendMessage (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
690: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
691: SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY), EM_LIMITTEXT, MAX_PASSWORD, 0);
692: EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
693:
1.1.1.7 root 694: SetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES, KeyFilesEnable);
695: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES), KeyFilesEnable);
696: EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), FALSE);
697:
1.1.1.3 root 698: SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
699:
1.1.1.7 root 700: nIndex = SendMessageW (hComboBox, CB_ADDSTRING, 0, (LPARAM) GetString ("UNCHANGED"));
1.1.1.3 root 701: SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) 0);
702:
703: for (i = 1; i <= LAST_PRF_ID; i++)
704: {
1.1.1.7 root 705: nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) get_pkcs5_prf_name(i));
1.1.1.3 root 706: SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) i);
707: }
708:
709: SendMessage (hComboBox, CB_SETCURSEL, 0, 0);
710:
1.1.1.7 root 711: switch (pwdChangeDlgMode)
712: {
713: case PCDM_CHANGE_PKCS5_PRF:
714: SetWindowTextW (hwndDlg, GetString ("IDD_PCDM_CHANGE_PKCS5_PRF"));
715: LocalizeDialog (hwndDlg, "IDD_PCDM_CHANGE_PKCS5_PRF");
716: EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD), FALSE);
717: EnableWindow (GetDlgItem (hwndDlg, IDC_VERIFY), FALSE);
718: EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_NEW_KEYFILES), FALSE);
719: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW), FALSE);
720: EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), FALSE);
721: EnableWindow (GetDlgItem (hwndDlg, IDT_NEW_PASSWORD), FALSE);
722: EnableWindow (GetDlgItem (hwndDlg, IDT_CONFIRM_PASSWORD), FALSE);
723: break;
724:
725: case PCDM_ADD_REMOVE_VOL_KEYFILES:
726: SetWindowTextW (hwndDlg, GetString ("IDD_PCDM_ADD_REMOVE_VOL_KEYFILES"));
727: LocalizeDialog (hwndDlg, "IDD_PCDM_ADD_REMOVE_VOL_KEYFILES");
728: newKeyFilesParam.EnableKeyFiles = TRUE;
729: EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD), FALSE);
730: EnableWindow (GetDlgItem (hwndDlg, IDC_VERIFY), FALSE);
731: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW), FALSE);
732: EnableWindow (GetDlgItem (hwndDlg, IDT_NEW_PASSWORD), FALSE);
733: EnableWindow (GetDlgItem (hwndDlg, IDT_CONFIRM_PASSWORD), FALSE);
734: break;
735:
736: case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
737: newKeyFilesParam.EnableKeyFiles = FALSE;
738: SetWindowTextW (hwndDlg, GetString ("IDD_PCDM_REMOVE_ALL_KEYFILES_FROM_VOL"));
739: LocalizeDialog (hwndDlg, "IDD_PCDM_REMOVE_ALL_KEYFILES_FROM_VOL");
740: KeyFilesEnable = TRUE;
741: SetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES, TRUE);
742: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES), TRUE);
743: EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_KEYFILES), TRUE);
744: EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD), FALSE);
745: EnableWindow (GetDlgItem (hwndDlg, IDC_VERIFY), FALSE);
746: EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_NEW_KEYFILES), FALSE);
747: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW), FALSE);
748: EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), FALSE);
749: EnableWindow (GetDlgItem (hwndDlg, IDT_NEW_PASSWORD), FALSE);
750: EnableWindow (GetDlgItem (hwndDlg, IDT_CONFIRM_PASSWORD), FALSE);
751: EnableWindow (GetDlgItem (hwndDlg, IDT_PKCS5_PRF), FALSE);
752: EnableWindow (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), FALSE);
753: break;
754:
755: case PCDM_CHANGE_PASSWORD:
756: default:
757: // NOP
758: break;
759: };
760:
1.1.1.5 root 761: CheckCapsLock (hwndDlg, FALSE);
762:
1.1 root 763: return 1;
764: }
765:
766: case WM_COMMAND:
767: if (lw == IDCANCEL)
768: {
769: // Attempt to wipe passwords stored in the input field buffers
770: char tmp[MAX_PASSWORD+1];
771: memset (tmp, 'X', MAX_PASSWORD);
772: tmp[MAX_PASSWORD] = 0;
773: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
774: SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);
775: SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);
1.1.1.7 root 776: RestoreDefaultKeyFilesParam ();
1.1 root 777:
778: EndDialog (hwndDlg, IDCANCEL);
779: return 1;
780: }
1.1.1.7 root 781:
1.1 root 782: if (hw == EN_CHANGE)
783: {
1.1.1.7 root 784: PasswordChangeEnable (hwndDlg, IDOK,
785: IDC_OLD_PASSWORD,
786: KeyFilesEnable && FirstKeyFile != NULL,
787: IDC_PASSWORD, IDC_VERIFY,
788: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
789:
790: return 1;
791: }
792:
793: if (lw == IDC_KEYFILES)
794: {
795: KeyFilesDlgParam param;
796: param.EnableKeyFiles = KeyFilesEnable;
797: param.FirstKeyFile = FirstKeyFile;
798:
799: if (IDOK == DialogBoxParamW (hInst,
800: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
801: (DLGPROC) KeyFilesDlgProc, (LPARAM) ¶m))
802: {
803: KeyFilesEnable = param.EnableKeyFiles;
804: FirstKeyFile = param.FirstKeyFile;
805:
806: SetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES, KeyFilesEnable);
807: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES), KeyFilesEnable);
808: }
809:
810: PasswordChangeEnable (hwndDlg, IDOK,
811: IDC_OLD_PASSWORD,
812: KeyFilesEnable && FirstKeyFile != NULL,
813: IDC_PASSWORD, IDC_VERIFY,
814: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
815:
816: return 1;
817: }
818:
819:
820: if (lw == IDC_NEW_KEYFILES)
821: {
822: if (IDOK == DialogBoxParamW (hInst,
823: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
824: (DLGPROC) KeyFilesDlgProc, (LPARAM) &newKeyFilesParam))
825: {
826: SetCheckBox (hwndDlg, IDC_ENABLE_NEW_KEYFILES, newKeyFilesParam.EnableKeyFiles);
827: EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), newKeyFilesParam.EnableKeyFiles);
828:
829: VerifyPasswordAndUpdate (hwndDlg, GetDlgItem (hwndDlg, IDOK), GetDlgItem (hwndDlg, IDC_PASSWORD),
830: GetDlgItem (hwndDlg, IDC_VERIFY), NULL, NULL,
831: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
832: }
833:
834: PasswordChangeEnable (hwndDlg, IDOK,
835: IDC_OLD_PASSWORD,
836: KeyFilesEnable && FirstKeyFile != NULL,
837: IDC_PASSWORD, IDC_VERIFY,
838: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
839:
840: return 1;
841: }
842:
843: if (lw == IDC_ENABLE_KEYFILES)
844: {
845: KeyFilesEnable = GetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES);
846: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES), KeyFilesEnable);
847:
848: PasswordChangeEnable (hwndDlg, IDOK,
849: IDC_OLD_PASSWORD,
850: KeyFilesEnable && FirstKeyFile != NULL,
851: IDC_PASSWORD, IDC_VERIFY,
852: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
853:
854: return 1;
855: }
856:
857: if (lw == IDC_ENABLE_NEW_KEYFILES)
858: {
859: newKeyFilesParam.EnableKeyFiles = GetCheckBox (hwndDlg, IDC_ENABLE_NEW_KEYFILES);
860: EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), newKeyFilesParam.EnableKeyFiles);
861:
862: PasswordChangeEnable (hwndDlg, IDOK,
863: IDC_OLD_PASSWORD,
864: KeyFilesEnable && FirstKeyFile != NULL,
865: IDC_PASSWORD, IDC_VERIFY,
866: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
867:
868: return 1;
869: }
870:
871: if (lw == IDC_SHOW_PASSWORD_CHPWD_ORI)
872: {
873: SendMessage (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD),
874: EM_SETPASSWORDCHAR,
875: GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_ORI) ? 0 : '*',
876: 0);
877: InvalidateRect (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), NULL, TRUE);
878: return 1;
879: }
880:
881: if (lw == IDC_SHOW_PASSWORD_CHPWD_NEW)
882: {
883: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD),
884: EM_SETPASSWORDCHAR,
885: GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW) ? 0 : '*',
886: 0);
887: SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY),
888: EM_SETPASSWORDCHAR,
889: GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW) ? 0 : '*',
890: 0);
891: InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD), NULL, TRUE);
892: InvalidateRect (GetDlgItem (hwndDlg, IDC_VERIFY), NULL, TRUE);
1.1 root 893: return 1;
894: }
1.1.1.7 root 895:
1.1 root 896: if (lw == IDOK)
897: {
898: HWND hParent = GetParent (hwndDlg);
1.1.1.7 root 899: Password oldPassword;
900: Password newPassword;
1.1 root 901: int nStatus;
1.1.1.7 root 902: int pkcs5 = SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETITEMDATA,
903: SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETCURSEL, 0, 0), 0);
904:
905: if (!CheckPasswordCharEncoding (GetDlgItem (hwndDlg, IDC_PASSWORD), NULL))
906: {
907: Error ("UNSUPPORTED_CHARS_IN_PWD");
908: return 1;
909: }
1.1 root 910:
1.1.1.7 root 911: if (pwdChangeDlgMode == PCDM_CHANGE_PKCS5_PRF)
912: {
913: newKeyFilesParam.EnableKeyFiles = KeyFilesEnable;
914: }
1.1.1.8 root 915: else if (!(newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL)
916: && pwdChangeDlgMode == PCDM_CHANGE_PASSWORD)
1.1.1.7 root 917: {
918: if (!CheckPasswordLength (hwndDlg, GetDlgItem (hwndDlg, IDC_PASSWORD)))
919: return 1;
920: }
1.1.1.5 root 921:
1.1 root 922: GetWindowText (GetDlgItem (hParent, IDC_VOLUME), szFileName, sizeof (szFileName));
923:
1.1.1.7 root 924: GetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), oldPassword.Text, sizeof (oldPassword.Text));
925: oldPassword.Length = strlen (oldPassword.Text);
926:
927: switch (pwdChangeDlgMode)
928: {
929: case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
930: case PCDM_ADD_REMOVE_VOL_KEYFILES:
931: case PCDM_CHANGE_PKCS5_PRF:
932: memcpy (newPassword.Text, oldPassword.Text, sizeof (newPassword.Text));
933: newPassword.Length = strlen (oldPassword.Text);
934: break;
935:
936: default:
937: GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), newPassword.Text, sizeof (newPassword.Text));
938: newPassword.Length = strlen (newPassword.Text);
939: }
940:
941: if (KeyFilesEnable)
1.1.1.12! root 942: KeyFilesApply (&oldPassword, FirstKeyFile);
1.1 root 943:
1.1.1.7 root 944: if (newKeyFilesParam.EnableKeyFiles)
945: KeyFilesApply (&newPassword,
1.1.1.12! root 946: pwdChangeDlgMode==PCDM_CHANGE_PKCS5_PRF ? FirstKeyFile : newKeyFilesParam.FirstKeyFile);
1.1 root 947:
1.1.1.7 root 948: nStatus = ChangePwd (szFileName, &oldPassword, &newPassword, pkcs5, hwndDlg);
1.1 root 949:
1.1.1.11 root 950: if (nStatus == ERR_OS_ERROR
951: && GetLastError () == ERROR_ACCESS_DENIED
952: && IsUacSupported ()
953: && IsVolumeDeviceHosted (szFileName))
954: {
955: WaitCursor ();
956: nStatus = UacChangePwd (szFileName, &oldPassword, &newPassword, pkcs5, hwndDlg);
957: NormalCursor ();
958: }
959:
1.1.1.7 root 960: burn (&oldPassword, sizeof (oldPassword));
961: burn (&newPassword, sizeof (newPassword));
1.1 root 962:
1.1.1.11 root 963: if (nStatus == 0)
1.1 root 964: {
965: // Attempt to wipe passwords stored in the input field buffers
966: char tmp[MAX_PASSWORD+1];
967: memset (tmp, 'X', MAX_PASSWORD);
968: tmp[MAX_PASSWORD] = 0;
969: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
970: SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);
971: SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);
972:
1.1.1.7 root 973: KeyFileRemoveAll (&newKeyFilesParam.FirstKeyFile);
974: RestoreDefaultKeyFilesParam ();
975:
1.1 root 976: EndDialog (hwndDlg, IDOK);
977: }
978: return 1;
979: }
980: return 0;
981: }
982:
983: return 0;
984: }
985:
1.1.1.7 root 986: static char PasswordDlgVolume[MAX_PATH];
987:
1.1 root 988: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
989: should return nonzero if it processes the message, and zero if it does
990: not. - see DialogProc */
1.1.1.12! root 991: BOOL CALLBACK
1.1 root 992: PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
993: {
994: WORD lw = LOWORD (wParam);
1.1.1.7 root 995: static Password *szXPwd;
1.1 root 996:
997: switch (msg)
998: {
999: case WM_INITDIALOG:
1000: {
1.1.1.7 root 1001: szXPwd = (Password *) lParam;
1002: LocalizeDialog (hwndDlg, "IDD_PASSWORD_DLG");
1.1.1.9 root 1003: DragAcceptFiles (hwndDlg, TRUE);
1.1.1.7 root 1004:
1005: if (strlen (PasswordDlgVolume) > 0)
1006: {
1007: wchar_t s[1024];
1008: wsprintfW (s, GetString ("ENTER_PASSWORD_FOR"), PasswordDlgVolume);
1009: SetWindowTextW (hwndDlg, s);
1010: }
1011:
1.1 root 1012: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
1013: SendMessage (GetDlgItem (hwndDlg, IDC_CACHE), BM_SETCHECK, bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
1.1.1.7 root 1014:
1015: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
1016: EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
1.1.1.8 root 1017:
1018: SetForegroundWindow (hwndDlg);
1.1 root 1019: return 1;
1020: }
1021:
1022: case WM_COMMAND:
1023:
1.1.1.6 root 1024: if (lw == IDC_MOUNT_OPTIONS)
1025: {
1.1.1.7 root 1026: DialogBoxParamW (hInst,
1027: MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
1.1.1.6 root 1028: (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions);
1029: return 1;
1030: }
1031:
1.1.1.7 root 1032: if (lw == IDC_SHOW_PASSWORD)
1033: {
1034: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD),
1035: EM_SETPASSWORDCHAR,
1036: GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD) ? 0 : '*',
1037: 0);
1038: InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD), NULL, TRUE);
1039: return 1;
1040: }
1041:
1042: if (lw == IDC_KEY_FILES)
1043: {
1044: KeyFilesDlgParam param;
1045: param.EnableKeyFiles = KeyFilesEnable;
1046: param.FirstKeyFile = FirstKeyFile;
1047:
1048: if (IDOK == DialogBoxParamW (hInst,
1049: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
1050: (DLGPROC) KeyFilesDlgProc, (LPARAM) ¶m))
1051: {
1052: KeyFilesEnable = param.EnableKeyFiles;
1053: FirstKeyFile = param.FirstKeyFile;
1054:
1055: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
1056: EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
1057: }
1058:
1059: return 1;
1060: }
1061:
1062: if (lw == IDC_KEYFILES_ENABLE)
1063: {
1064: KeyFilesEnable = GetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE);
1065: EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
1066:
1067: return 1;
1068: }
1069:
1.1 root 1070: if (lw == IDCANCEL || lw == IDOK)
1071: {
1072: char tmp[MAX_PASSWORD+1];
1073:
1074: if (lw == IDOK)
1075: {
1.1.1.7 root 1076: if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
1.1.1.12! root 1077: KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile);
1.1.1.7 root 1078:
1079: GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), szXPwd->Text, MAX_PASSWORD + 1);
1080: szXPwd->Length = strlen (szXPwd->Text);
1081:
1.1 root 1082: bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_CACHE));
1083: }
1084:
1085: // Attempt to wipe password stored in the input field buffer
1086: memset (tmp, 'X', MAX_PASSWORD);
1087: tmp[MAX_PASSWORD] = 0;
1088: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
1.1.1.7 root 1089: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), tmp);
1090:
1091: if (hidVolProtKeyFilesParam.FirstKeyFile != NULL)
1092: {
1093: KeyFileRemoveAll (&hidVolProtKeyFilesParam.FirstKeyFile);
1094: hidVolProtKeyFilesParam.EnableKeyFiles = FALSE;
1095: }
1.1 root 1096:
1097: EndDialog (hwndDlg, lw);
1098: return 1;
1099: }
1100: return 0;
1.1.1.9 root 1101:
1102: case WM_DROPFILES:
1103: {
1104: HDROP hdrop = (HDROP) wParam;
1105: int i = 0, count = DragQueryFile (hdrop, -1, NULL, 0);
1106:
1107: while (count-- > 0)
1108: {
1109: KeyFile *kf = malloc (sizeof (KeyFile));
1110: DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName));
1111: FirstKeyFile = KeyFileAdd (FirstKeyFile, kf);
1112: KeyFilesEnable = TRUE;
1113: }
1114:
1115: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
1116: EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
1117:
1118: DragFinish (hdrop);
1119: }
1120: return 1;
1.1 root 1121: }
1122:
1123: return 0;
1124: }
1125:
1.1.1.7 root 1126: static void PreferencesDlgEnableButtons (HWND hwndDlg)
1127: {
1.1.1.11 root 1128: BOOL back = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE));
1.1.1.7 root 1129: BOOL idle = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE));
1130: BOOL logon = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START));
1131: BOOL installed = !IsNonInstallMode();
1132:
1.1.1.11 root 1133: EnableWindow (GetDlgItem (hwndDlg, IDC_CLOSE_BKG_TASK_WHEN_NOVOL), back && installed);
1.1.1.7 root 1134: EnableWindow (GetDlgItem (hwndDlg, IDT_LOGON), installed);
1135: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START), installed);
1136: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_DEVICES), installed && logon);
1137: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_FAVORITES), installed && logon);
1.1.1.11 root 1138: EnableWindow (GetDlgItem (hwndDlg, IDT_AUTO_DISMOUNT), back);
1139: EnableWindow (GetDlgItem (hwndDlg, IDT_AUTO_DISMOUNT_ON), back);
1140: EnableWindow (GetDlgItem (hwndDlg, IDT_MINUTES), back);
1141: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF), back);
1142: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING), back);
1143: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER), back);
1144: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE), back);
1145: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE_TIME), back && idle);
1146: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT), back);
1.1.1.7 root 1147: }
1148:
1.1.1.12! root 1149: BOOL CALLBACK
1.1 root 1150: PreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1151: {
1152: WORD lw = LOWORD (wParam);
1153:
1154: switch (msg)
1155: {
1156: case WM_INITDIALOG:
1157: {
1.1.1.7 root 1158: LocalizeDialog (hwndDlg, "IDD_PREFERENCES_DLG");
1.1 root 1159:
1160: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_OPEN_EXPLORER), BM_SETCHECK,
1161: bExplore ? BST_CHECKED:BST_UNCHECKED, 0);
1162:
1163: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_CLOSE_DISMOUNTED_WINDOWS), BM_SETCHECK,
1164: bCloseDismountedWindows ? BST_CHECKED:BST_UNCHECKED, 0);
1165:
1.1.1.7 root 1166: SendMessage (GetDlgItem (hwndDlg, IDC_PRESERVE_TIMESTAMPS), BM_SETCHECK,
1167: defaultMountOptions.PreserveTimestamp ? BST_CHECKED:BST_UNCHECKED, 0);
1168:
1.1 root 1169: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_EXIT), BM_SETCHECK,
1170: bWipeCacheOnExit ? BST_CHECKED:BST_UNCHECKED, 0);
1171:
1.1.1.7 root 1172: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_AUTODISMOUNT), BM_SETCHECK,
1173: bWipeCacheOnAutoDismount ? BST_CHECKED:BST_UNCHECKED, 0);
1174:
1.1 root 1175: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_CACHE_PASSWORDS), BM_SETCHECK,
1176: bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
1177:
1.1.1.6 root 1178: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_READONLY), BM_SETCHECK,
1179: defaultMountOptions.ReadOnly ? BST_CHECKED:BST_UNCHECKED, 0);
1180:
1181: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_REMOVABLE), BM_SETCHECK,
1182: defaultMountOptions.Removable ? BST_CHECKED:BST_UNCHECKED, 0);
1.1.1.7 root 1183:
1184: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START), BM_SETCHECK,
1185: bStartOnLogon ? BST_CHECKED:BST_UNCHECKED, 0);
1186:
1187: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_DEVICES), BM_SETCHECK,
1188: bMountDevicesOnLogon ? BST_CHECKED:BST_UNCHECKED, 0);
1189:
1190: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_FAVORITES), BM_SETCHECK,
1191: bMountFavoritesOnLogon ? BST_CHECKED:BST_UNCHECKED, 0);
1192:
1193: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE), BM_SETCHECK,
1194: bEnableBkgTask ? BST_CHECKED:BST_UNCHECKED, 0);
1195:
1196: SendMessage (GetDlgItem (hwndDlg, IDC_CLOSE_BKG_TASK_WHEN_NOVOL), BM_SETCHECK,
1197: bCloseBkgTaskWhenNoVolumes || IsNonInstallMode() ? BST_CHECKED:BST_UNCHECKED, 0);
1198:
1199: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF), BM_SETCHECK,
1200: bDismountOnLogOff ? BST_CHECKED:BST_UNCHECKED, 0);
1201:
1202: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING), BM_SETCHECK,
1203: bDismountOnPowerSaving ? BST_CHECKED:BST_UNCHECKED, 0);
1204:
1205: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER), BM_SETCHECK,
1206: bDismountOnScreenSaver ? BST_CHECKED:BST_UNCHECKED, 0);
1.1 root 1207:
1.1.1.7 root 1208: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT), BM_SETCHECK,
1209: bForceAutoDismount ? BST_CHECKED:BST_UNCHECKED, 0);
1210:
1211: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE), BM_SETCHECK,
1212: MaxVolumeIdleTime > 0 ? BST_CHECKED:BST_UNCHECKED, 0);
1213:
1214: SetDlgItemInt (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE_TIME, abs (MaxVolumeIdleTime), FALSE);
1215:
1216: PreferencesDlgEnableButtons (hwndDlg);
1.1 root 1217: return 1;
1218: }
1219:
1220: case WM_COMMAND:
1221:
1.1.1.7 root 1222: if (lw == IDC_PRESERVE_TIMESTAMPS && !IsButtonChecked (GetDlgItem (hwndDlg, IDC_PRESERVE_TIMESTAMPS)))
1223: {
1224: if (AskWarnNoYes ("CONFIRM_TIMESTAMP_UPDATING") == IDNO)
1225: SetCheckBox (hwndDlg, IDC_PRESERVE_TIMESTAMPS, TRUE);
1226: }
1227:
1228: if (lw == IDC_PREF_BKG_TASK_ENABLE && !IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE)))
1229: {
1230: if (AskWarnNoYes ("CONFIRM_BACKGROUND_TASK_DISABLED") == IDNO)
1231: SetCheckBox (hwndDlg, IDC_PREF_BKG_TASK_ENABLE, TRUE);
1232: }
1233:
1234: // Forced dismount disabled warning
1235: if (lw == IDC_PREF_DISMOUNT_INACTIVE
1236: || lw == IDC_PREF_DISMOUNT_POWERSAVING
1237: || lw == IDC_PREF_DISMOUNT_SCREENSAVER
1238: || lw == IDC_PREF_FORCE_AUTO_DISMOUNT)
1239: {
1240: BOOL i = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE));
1241: BOOL p = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING));
1242: BOOL s = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER));
1243: BOOL q = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT));
1244:
1245: if (!q)
1246: {
1247: if (lw == IDC_PREF_FORCE_AUTO_DISMOUNT && (i || p || s))
1248: {
1249: if (AskWarnNoYes ("CONFIRM_NO_FORCED_AUTODISMOUNT") == IDNO)
1250: SetCheckBox (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT, TRUE);
1251: }
1252: else if ((lw == IDC_PREF_DISMOUNT_INACTIVE && i
1253: || lw == IDC_PREF_DISMOUNT_POWERSAVING && p
1254: || lw == IDC_PREF_DISMOUNT_SCREENSAVER && s))
1255: Warning ("WARN_PREF_AUTO_DISMOUNT");
1256: }
1257:
1258: }
1259:
1.1 root 1260: if (lw == IDCANCEL)
1261: {
1262: EndDialog (hwndDlg, lw);
1263: return 1;
1264: }
1265:
1266: if (lw == IDOK)
1267: {
1.1.1.7 root 1268: bExplore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_OPEN_EXPLORER));
1269: bCloseDismountedWindows = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_CLOSE_DISMOUNTED_WINDOWS));
1270: bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PRESERVE_TIMESTAMPS));
1271: bWipeCacheOnExit = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_EXIT));
1272: bWipeCacheOnAutoDismount = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_AUTODISMOUNT));
1.1.1.11 root 1273: bCacheInDriverDefault = bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_CACHE_PASSWORDS));
1.1.1.7 root 1274: defaultMountOptions.ReadOnly = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_READONLY));
1275: defaultMountOptions.Removable = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_REMOVABLE));
1276: bEnableBkgTask = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE));
1277: bCloseBkgTaskWhenNoVolumes = IsNonInstallMode() ? bCloseBkgTaskWhenNoVolumes : IsButtonChecked (GetDlgItem (hwndDlg, IDC_CLOSE_BKG_TASK_WHEN_NOVOL));
1278: bDismountOnLogOff = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF));
1279: bDismountOnPowerSaving = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING));
1280: bDismountOnScreenSaver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER));
1281: bForceAutoDismount = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT));
1282: MaxVolumeIdleTime = GetDlgItemInt (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE_TIME, NULL, FALSE)
1283: * (IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE)) ? 1 : -1);
1284: bStartOnLogon = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START));
1285: bMountDevicesOnLogon = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_DEVICES));
1286: bMountFavoritesOnLogon = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_FAVORITES));
1287:
1288: if (!IsNonInstallMode ())
1289: {
1290: char regk [64];
1291:
1292: // Split the string in order to prevent some antivirus packages from falsely reporting
1293: // TrueCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
1294: sprintf (regk, "%s%s", "Software\\Microsoft\\Windows\\Curren", "tVersion\\Run");
1295:
1296: if (bStartOnLogon)
1297: {
1298: char exe[MAX_PATH * 2] = { '"' };
1299: GetModuleFileName (NULL, exe + 1, sizeof (exe));
1300: strcat (exe, "\" /q preferences");
1301:
1302: if (bMountDevicesOnLogon) strcat (exe, " /a devices");
1303: if (bMountFavoritesOnLogon) strcat (exe, " /a favorites");
1304:
1305: WriteRegistryString (regk, "TrueCrypt", exe);
1306: }
1307: else
1308: DeleteRegistryValue (regk, "TrueCrypt");
1309: }
1310:
1.1.1.12! root 1311: WaitCursor ();
1.1.1.7 root 1312: SaveSettings (hwndDlg);
1.1.1.12! root 1313: NormalCursor ();
1.1 root 1314:
1315: EndDialog (hwndDlg, lw);
1316: return 1;
1317: }
1318:
1.1.1.7 root 1319: if (lw == IDC_PREFS_HOTKEY_SETTINGS)
1320: {
1.1.1.12! root 1321: DialogBoxParamW (hInst,
! 1322: MAKEINTRESOURCEW (IDD_HOTKEYS_DLG), hwndDlg,
1.1.1.7 root 1323: (DLGPROC) HotkeysDlgProc, (LPARAM) 0);
1324: return 1;
1.1 root 1325:
1.1.1.7 root 1326: }
1.1.1.6 root 1327:
1.1.1.7 root 1328: if (lw == IDC_PREFS_KEYFILE_SETTINGS)
1329: {
1330: KeyfileDefaultsDlg (hwndDlg);
1331: return 1;
1332: }
1333:
1334: if (HIWORD (wParam) == BN_CLICKED)
1335: {
1336: PreferencesDlgEnableButtons (hwndDlg);
1337: return 1;
1338: }
1339:
1340: return 0;
1341: }
1342:
1343: return 0;
1344: }
1345:
1346:
1.1.1.12! root 1347: BOOL CALLBACK
1.1.1.7 root 1348: MountOptionsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1349: {
1350: static MountOptions *mountOptions;
1351:
1352: WORD lw = LOWORD (wParam);
1353:
1354: switch (msg)
1355: {
1356: case WM_INITDIALOG:
1357: {
1358: BOOL protect;
1359:
1360: mountOptions = (MountOptions *) lParam;
1361:
1362: LocalizeDialog (hwndDlg, "IDD_MOUNT_OPTIONS");
1363:
1364: SendDlgItemMessage (hwndDlg, IDC_MOUNT_READONLY, BM_SETCHECK,
1365: mountOptions->ReadOnly ? BST_CHECKED : BST_UNCHECKED, 0);
1366: SendDlgItemMessage (hwndDlg, IDC_MOUNT_REMOVABLE, BM_SETCHECK,
1367: mountOptions->Removable ? BST_CHECKED : BST_UNCHECKED, 0);
1368: SendDlgItemMessage (hwndDlg, IDC_PROTECT_HIDDEN_VOL, BM_SETCHECK,
1369: mountOptions->ProtectHiddenVolume ? BST_CHECKED : BST_UNCHECKED, 0);
1370:
1371: protect = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL));
1372:
1373: EnableWindow (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
1374: EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_VOL_PROTECTION), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
1375: EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), protect);
1376: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_MO), protect);
1377: EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_PROT_PASSWD), protect);
1378: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_HIDVOL_PROT), protect && hidVolProtKeyFilesParam.EnableKeyFiles);
1379: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT), protect);
1380:
1381: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT, hidVolProtKeyFilesParam.EnableKeyFiles);
1382:
1.1.1.8 root 1383: SendDlgItemMessage (hwndDlg, IDC_PASSWORD_PROT_HIDVOL, EM_LIMITTEXT, MAX_PASSWORD, 0);
1384:
1.1.1.7 root 1385: if (mountOptions->ProtectedHidVolPassword.Length > 0)
1386: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), mountOptions->ProtectedHidVolPassword.Text);
1.1.1.11 root 1387:
1388: ToHyperlink (hwndDlg, IDC_LINK_HIDVOL_PROTECTION_INFO);
1.1.1.7 root 1389:
1390: return 1;
1391: }
1392:
1393: case WM_COMMAND:
1394:
1395: if (lw == IDC_KEYFILES_HIDVOL_PROT)
1396: {
1397: if (IDOK == DialogBoxParamW (hInst,
1398: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
1399: (DLGPROC) KeyFilesDlgProc, (LPARAM) &hidVolProtKeyFilesParam))
1400: {
1401: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT, hidVolProtKeyFilesParam.EnableKeyFiles);
1402: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_HIDVOL_PROT), hidVolProtKeyFilesParam.EnableKeyFiles);
1403: }
1404: }
1405:
1406: if (lw == IDC_KEYFILES_ENABLE_HIDVOL_PROT)
1407: {
1408: hidVolProtKeyFilesParam.EnableKeyFiles = GetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT);
1409: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_HIDVOL_PROT), hidVolProtKeyFilesParam.EnableKeyFiles);
1410:
1411: return 0;
1412: }
1413:
1414: if (lw == IDC_SHOW_PASSWORD_MO)
1415: {
1416: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL),
1417: EM_SETPASSWORDCHAR,
1418: GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_MO) ? 0 : '*',
1419: 0);
1420: InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), NULL, TRUE);
1421: return 1;
1422: }
1423:
1.1.1.11 root 1424: if (lw == IDC_LINK_HIDVOL_PROTECTION_INFO)
1425: {
1426: Applink ("hiddenvolprotection", TRUE, "");
1427: }
1428:
1.1.1.7 root 1429: if (lw == IDCANCEL)
1430: {
1431: char tmp[MAX_PASSWORD+1];
1432:
1433: // Cleanup
1434: memset (tmp, 'X', MAX_PASSWORD);
1435: tmp[MAX_PASSWORD] = 0;
1436: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), tmp);
1437:
1438: EndDialog (hwndDlg, lw);
1439: return 1;
1440: }
1441:
1442: if (lw == IDOK)
1443: {
1444: char tmp[MAX_PASSWORD+1];
1445:
1446: mountOptions->ReadOnly = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY));
1447: mountOptions->Removable = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_REMOVABLE));
1448: mountOptions->ProtectHiddenVolume = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL));
1449:
1450: if (mountOptions->ProtectHiddenVolume)
1451: {
1452: GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL),
1453: mountOptions->ProtectedHidVolPassword.Text,
1454: sizeof (mountOptions->ProtectedHidVolPassword.Text));
1455:
1456: mountOptions->ProtectedHidVolPassword.Length = strlen (mountOptions->ProtectedHidVolPassword.Text);
1457: }
1458:
1459: // Cleanup
1460: memset (tmp, 'X', MAX_PASSWORD);
1461: tmp[MAX_PASSWORD] = 0;
1462: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), tmp);
1463:
1.1.1.11 root 1464: if ((mountOptions->ProtectHiddenVolume && !bEnableBkgTask)
1465: && (AskWarnYesNo ("HIDVOL_PROT_BKG_TASK_WARNING") == IDYES))
1466: {
1467: bEnableBkgTask = TRUE;
1468: TaskBarIconAdd (MainDlg);
1469: }
1.1.1.7 root 1470:
1471: EndDialog (hwndDlg, lw);
1472: return 1;
1473: }
1474:
1475: if (lw == IDC_MOUNT_READONLY || lw == IDC_PROTECT_HIDDEN_VOL)
1476: {
1477: BOOL protect;
1478:
1479: if (lw == IDC_MOUNT_READONLY)
1480: {
1481: SendDlgItemMessage (hwndDlg, IDC_PROTECT_HIDDEN_VOL, BM_SETCHECK, BST_UNCHECKED, 0);
1482: EnableWindow (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
1483: EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_VOL_PROTECTION), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
1484: }
1485:
1486: protect = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL));
1487:
1488: EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), protect);
1489: EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_PROT_PASSWD), protect);
1490: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_MO), protect);
1491: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_HIDVOL_PROT), protect && hidVolProtKeyFilesParam.EnableKeyFiles);
1492: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT), protect);
1493:
1494: return 1;
1495: }
1496:
1497: return 0;
1498: }
1499:
1500: return 0;
1501: }
1502:
1503:
1.1.1.11 root 1504: // Returns the block size (in bits) of the cipher with which the volume mounted as the
1505: // specified drive letter is encrypted. In case of a cascade of ciphers with different
1506: // block sizes the function returns the smallest block size.
1507: int GetCipherBlockSizeByDriveNo (int nDosDriveNo)
1508: {
1509: VOLUME_PROPERTIES_STRUCT prop;
1510: DWORD dwResult;
1511:
1512: int blockSize = 0, cipherID;
1513:
1514: memset (&prop, 0, sizeof(prop));
1515: prop.driveNo = nDosDriveNo;
1516:
1517: if (DeviceIoControl (hDriver, VOLUME_PROPERTIES, &prop, sizeof (prop), &prop, sizeof (prop), &dwResult, NULL))
1518: {
1519: for (cipherID = EAGetLastCipher (prop.ea);
1520: cipherID != 0;
1521: cipherID = EAGetPreviousCipher (prop.ea, cipherID))
1522: {
1523: if (blockSize > 0)
1524: blockSize = min (blockSize, CipherGetBlockSize (cipherID) * 8);
1525: else
1526: blockSize = CipherGetBlockSize (cipherID) * 8;
1527: }
1528: }
1529:
1530: return blockSize;
1531: }
1532:
1533:
1.1.1.12! root 1534: BOOL CALLBACK
1.1.1.7 root 1535: VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1536: {
1.1 root 1537: WORD lw = LOWORD (wParam);
1.1.1.7 root 1538: int i = 0;
1.1 root 1539:
1540: switch (msg)
1541: {
1542: case WM_INITDIALOG:
1543: {
1544: VOLUME_PROPERTIES_STRUCT prop;
1545: DWORD dwResult;
1546:
1.1.1.7 root 1547: LVCOLUMNW lvCol;
1.1 root 1548: HWND list = GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES_LIST);
1.1.1.7 root 1549: char szTmp[1024];
1550: wchar_t sw[1024];
1551: wchar_t *s;
1.1 root 1552:
1.1.1.7 root 1553: LocalizeDialog (hwndDlg, "IDD_VOLUME_PROPERTIES");
1.1 root 1554:
1.1.1.7 root 1555: SendMessage (list,LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
1.1 root 1556: LVS_EX_FULLROWSELECT
1.1.1.7 root 1557: |LVS_EX_HEADERDRAGDROP
1558: |LVS_EX_LABELTIP
1.1 root 1559: );
1560:
1561: memset (&lvCol,0,sizeof(lvCol));
1562: lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;
1.1.1.7 root 1563: lvCol.pszText = GetString ("VALUE");
1.1.1.12! root 1564: lvCol.cx = CompensateXDPI (208);
1.1 root 1565: lvCol.fmt = LVCFMT_LEFT ;
1.1.1.7 root 1566: SendMessage (list,LVM_INSERTCOLUMNW,0,(LPARAM)&lvCol);
1.1 root 1567:
1.1.1.7 root 1568: lvCol.pszText = GetString ("PROPERTY");
1.1.1.12! root 1569: lvCol.cx = CompensateXDPI (192);
1.1 root 1570: lvCol.fmt = LVCFMT_LEFT;
1.1.1.7 root 1571: SendMessage (list,LVM_INSERTCOLUMNW,0,(LPARAM)&lvCol);
1.1 root 1572:
1573: memset (&prop, 0, sizeof(prop));
1574: prop.driveNo = HIWORD (GetSelectedLong (GetDlgItem (GetParent(hwndDlg), IDC_DRIVELIST))) - 'A';
1575:
1.1.1.11 root 1576: if (!DeviceIoControl (hDriver, VOLUME_PROPERTIES, &prop, sizeof (prop), &prop, sizeof (prop), &dwResult, NULL) || dwResult == 0)
1577: return 1;
1578:
1.1.1.7 root 1579: // Location
1580: ListItemAddW (list, i, GetString ("LOCATION"));
1581: ListSubItemSetW (list, i++, 1, prop.wszVolume[1] != L'?' ? prop.wszVolume : prop.wszVolume + 4);
1582:
1583: // Size
1584: ListItemAddW (list, i, GetString ("SIZE"));
1585: swprintf (sw, L"%I64u %s", prop.diskLength, GetString ("BYTES"));
1586: ListSubItemSetW (list, i++, 1, sw);
1587:
1588: // Type
1589: ListItemAddW (list, i, GetString ("TYPE"));
1590: ListSubItemSetW (list, i++, 1,
1591: prop.hiddenVolume ? GetString ("HIDDEN") :
1592: (prop.hiddenVolProtection != HIDVOL_PROT_STATUS_NONE ? GetString ("OUTER") : GetString ("NORMAL")));
1593:
1594: // Write protection
1595: ListItemAddW (list, i, GetString ("READ_ONLY"));
1.1 root 1596:
1.1.1.7 root 1597: if (prop.readOnly || prop.hiddenVolProtection == HIDVOL_PROT_STATUS_ACTION_TAKEN)
1598: s = GetString ("UISTR_YES");
1599: else
1600: s = GetString ("UISTR_NO");
1.1 root 1601:
1.1.1.7 root 1602: ListSubItemSetW (list, i++, 1, s);
1.1 root 1603:
1.1.1.7 root 1604: // Hidden Volume Protection
1605: ListItemAddW (list, i, GetString ("HIDDEN_VOL_PROTECTION"));
1606: if (prop.hiddenVolume)
1607: s = GetString ("N_A_UISTR");
1608: else if (prop.hiddenVolProtection == HIDVOL_PROT_STATUS_NONE)
1609: s = GetString ("UISTR_NO");
1610: else if (prop.hiddenVolProtection == HIDVOL_PROT_STATUS_ACTIVE)
1611: s = GetString ("UISTR_YES");
1612: else if (prop.hiddenVolProtection == HIDVOL_PROT_STATUS_ACTION_TAKEN)
1613: s = GetString ("HID_VOL_DAMAGE_PREVENTED");
1.1.1.6 root 1614:
1.1.1.7 root 1615: ListSubItemSetW (list, i++, 1, s);
1.1 root 1616:
1.1.1.7 root 1617: // Encryption algorithm
1618: ListItemAddW (list, i, GetString ("ENCRYPTION_ALGORITHM"));
1.1.1.11 root 1619:
1620: if (prop.ea == 0 || prop.ea > EAGetCount ())
1621: {
1622: ListSubItemSet (list, i, 1, "?");
1623: return 1;
1624: }
1625:
1.1.1.7 root 1626: EAGetName (szTmp, prop.ea);
1627: ListSubItemSet (list, i++, 1, szTmp);
1.1.1.5 root 1628:
1.1.1.7 root 1629: // Key size
1630: {
1631: char name[128];
1632: int size = EAGetKeySize (prop.ea);
1633: EAGetName (name, prop.ea);
1634:
1.1.1.12! root 1635: if (strcmp (name, "Triple DES") == 0) /* Deprecated/legacy */
1.1.1.7 root 1636: size -= 3; // Compensate for parity bytes
1637:
1638: ListItemAddW (list, i, GetString ("KEY_SIZE"));
1639: wsprintfW (sw, L"%d %s", size * 8, GetString ("BITS"));
1640: ListSubItemSetW (list, i++, 1, sw);
1641: }
1.1.1.5 root 1642:
1.1.1.7 root 1643: // Block size
1644: ListItemAddW (list, i, GetString ("BLOCK_SIZE"));
1.1.1.8 root 1645: if (EAGetFirstMode (prop.ea) == INNER_CBC)
1.1.1.5 root 1646: {
1.1.1.8 root 1647: // Cascaded ciphers with non-equal block sizes (deprecated/legacy)
1648: wchar_t tmpstr[64];
1.1.1.5 root 1649: int i = EAGetLastCipher(prop.ea);
1650:
1.1.1.7 root 1651: swprintf (sw, L"%d", CipherGetBlockSize(i)*8);
1.1.1.5 root 1652:
1653: while (i = EAGetPreviousCipher(prop.ea, i))
1654: {
1.1.1.7 root 1655: swprintf (tmpstr, L"/%d", CipherGetBlockSize(i)*8);
1656: wcscat (sw, tmpstr);
1.1.1.5 root 1657: }
1.1.1.7 root 1658: wcscat (sw, L" ");
1.1.1.5 root 1659: }
1660: else
1661: {
1.1.1.7 root 1662: swprintf (sw, L"%d ", CipherGetBlockSize (EAGetFirstCipher(prop.ea))*8);
1.1.1.5 root 1663: }
1.1.1.7 root 1664: wcscat (sw, GetString ("BITS"));
1665: ListSubItemSetW (list, i++, 1, sw);
1.1.1.5 root 1666:
1.1.1.7 root 1667: // Mode
1668: ListItemAddW (list, i, GetString ("MODE_OF_OPERATION"));
1.1.1.8 root 1669: ListSubItemSet (list, i++, 1, EAGetModeName (prop.ea, prop.mode, TRUE));
1.1.1.7 root 1670:
1671: // PRF
1672: ListItemAddW (list, i, GetString ("PKCS5_PRF"));
1673: ListSubItemSet (list, i++, 1, get_pkcs5_prf_name (prop.pkcs5));
1.1 root 1674:
1.1.1.7 root 1675: // PCKS iterations
1676: ListItemAddW (list, i, GetString ("PKCS5_ITERATIONS"));
1.1 root 1677: sprintf (szTmp, "%d", prop.pkcs5Iterations);
1.1.1.7 root 1678: ListSubItemSet (list, i++, 1, szTmp);
1679:
1.1 root 1680: {
1681: FILETIME ft, curFt;
1.1.1.12! root 1682: LARGE_INTEGER ft64, curFt64;
1.1 root 1683: SYSTEMTIME st;
1.1.1.7 root 1684: wchar_t date[128];
1.1 root 1685: memset (date, 0, sizeof (date));
1686:
1.1.1.7 root 1687: // Volume date
1688: ListItemAddW (list, i, GetString ("VOLUME_CREATE_DATE"));
1.1 root 1689: *(unsigned __int64 *)(&ft) = prop.volumeCreationTime;
1690: FileTimeToSystemTime (&ft, &st);
1.1.1.7 root 1691: GetDateFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
1692: swprintf (date, L"%s ", sw);
1693: GetTimeFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
1694: wcscat (date, sw);
1695: ListSubItemSetW (list, i++, 1, date);
1.1 root 1696:
1.1.1.7 root 1697: // Header date
1698: ListItemAddW (list, i, GetString ("VOLUME_HEADER_DATE"));
1.1 root 1699: *(unsigned __int64 *)(&ft) = prop.headerCreationTime;
1700: FileTimeToSystemTime (&ft, &st);
1.1.1.7 root 1701: GetDateFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
1702: swprintf (date, L"%s ", sw);
1703: GetTimeFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
1704: wcscat (date, sw);
1.1 root 1705:
1706: GetLocalTime (&st);
1707: SystemTimeToFileTime (&st, &curFt);
1.1.1.12! root 1708: curFt64.HighPart = curFt.dwHighDateTime;
! 1709: curFt64.LowPart = curFt.dwLowDateTime;
! 1710: ft64.HighPart = ft.dwHighDateTime;
! 1711: ft64.LowPart = ft.dwLowDateTime;
1.1.1.7 root 1712: swprintf (date + wcslen (date), GetString ("VOLUME_HEADER_DAYS")
1.1.1.12! root 1713: , (curFt64.QuadPart - ft64.QuadPart)/(24LL*3600*10000000));
1.1.1.7 root 1714: ListSubItemSetW (list, i++, 1, date);
1.1 root 1715: }
1716:
1.1.1.7 root 1717: // Total data read
1718: ListItemAddW (list, i, GetString ("TOTAL_DATA_READ"));
1719: GetSizeString (prop.totalBytesRead, sw);
1720: ListSubItemSetW (list, i++, 1, sw);
1721:
1722: // Total data written
1723: ListItemAddW (list, i, GetString ("TOTAL_DATA_WRITTEN"));
1724: GetSizeString (prop.totalBytesWritten, sw);
1725: ListSubItemSetW (list, i++, 1, sw);
1726:
1.1 root 1727: return 1;
1728: }
1729:
1730: case WM_COMMAND:
1731: if (lw == IDOK)
1732: {
1733: EndDialog (hwndDlg, lw);
1734: return 1;
1735: }
1736: return 0;
1.1.1.9 root 1737:
1738: case WM_CLOSE:
1739: EndDialog (hwndDlg, lw);
1740: return 1;
1.1 root 1741: }
1742:
1743: return 0;
1744: }
1745:
1.1.1.6 root 1746:
1.1.1.12! root 1747: BOOL CALLBACK
1.1.1.6 root 1748: TravellerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1749: {
1750: WORD lw = LOWORD (wParam);
1751:
1752: switch (msg)
1753: {
1754: case WM_INITDIALOG:
1755: {
1756: int i, index;
1757: char drive[] = { 0, ':', 0 };
1758:
1.1.1.7 root 1759: LocalizeDialog (hwndDlg, "IDD_TRAVELLER_DLG");
1.1.1.6 root 1760:
1761: SendDlgItemMessage (hwndDlg, IDC_COPY_WIZARD, BM_SETCHECK,
1762: BST_CHECKED, 0);
1763:
1.1.1.7 root 1764: SendDlgItemMessage (hwndDlg, IDC_TRAVEL_OPEN_EXPLORER, BM_SETCHECK,
1.1.1.6 root 1765: BST_CHECKED, 0);
1766:
1767: SendDlgItemMessage (hwndDlg, IDC_AUTORUN_DISABLE, BM_SETCHECK,
1768: BST_CHECKED, 0);
1769:
1770: SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_RESETCONTENT, 0, 0);
1771:
1.1.1.7 root 1772: index = SendDlgItemMessageW (hwndDlg, IDC_DRIVELIST, CB_ADDSTRING, 0, (LPARAM) GetString ("FIRST_AVAILABLE"));
1.1.1.6 root 1773: SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETITEMDATA, index, (LPARAM) 0);
1774:
1.1.1.11 root 1775: for (i = 'D'; i <= 'Z'; i++)
1.1.1.6 root 1776: {
1777: drive[0] = i;
1778: index = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_ADDSTRING, 0, (LPARAM) drive);
1779: SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETITEMDATA, index, (LPARAM) i);
1780: }
1781:
1782: SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETCURSEL, 0, 0);
1783:
1784: return 1;
1785: }
1786:
1.1.1.7 root 1787:
1.1.1.6 root 1788: case WM_COMMAND:
1789:
1.1.1.7 root 1790: if (HIWORD (wParam) == BN_CLICKED
1791: && (lw == IDC_AUTORUN_DISABLE || lw == IDC_AUTORUN_MOUNT || lw == IDC_AUTORUN_START ))
1792: {
1.1.1.11 root 1793: BOOL enabled = IsButtonChecked (GetDlgItem (hwndDlg, IDC_AUTORUN_MOUNT));
1.1.1.7 root 1794:
1795: EnableWindow (GetDlgItem (hwndDlg, IDC_BROWSE_FILES), enabled);
1796: EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_NAME), enabled);
1797: EnableWindow (GetDlgItem (hwndDlg, IDC_TRAVEL_OPEN_EXPLORER), enabled);
1798: EnableWindow (GetDlgItem (hwndDlg, IDC_TRAV_CACHE_PASSWORDS), enabled);
1799: EnableWindow (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY), enabled);
1800: EnableWindow (GetDlgItem (hwndDlg, IDC_DRIVELIST), enabled);
1801: EnableWindow (GetDlgItem (hwndDlg, IDT_TRAVELLER_MOUNT), enabled);
1802: EnableWindow (GetDlgItem (hwndDlg, IDT_MOUNT_LETTER), enabled);
1803: EnableWindow (GetDlgItem (hwndDlg, IDT_MOUNT_SETTINGS), enabled);
1804:
1805: return 1;
1806: }
1807:
1.1.1.6 root 1808: if (lw == IDC_BROWSE_FILES)
1809: {
1.1.1.11 root 1810: char dstDir[MAX_PATH];
1.1.1.7 root 1811: char volName[MAX_PATH] = { 0 };
1.1.1.6 root 1812:
1.1.1.11 root 1813: GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstDir, sizeof dstDir);
1814:
1815: if (BrowseFilesInDir (hwndDlg, "OPEN_TITLE", dstDir, volName, bHistory, FALSE))
1.1.1.6 root 1816: SetDlgItemText (hwndDlg, IDC_VOLUME_NAME, strchr (volName, '\\') + 1);
1.1.1.7 root 1817:
1.1.1.6 root 1818: return 1;
1819: }
1820:
1821: if (lw == IDC_BROWSE_DIRS)
1822: {
1823: char dstPath[MAX_PATH * 2];
1.1.1.7 root 1824: GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstPath, sizeof dstPath);
1.1.1.6 root 1825:
1.1.1.7 root 1826: if (BrowseDirectories (hwndDlg, "SELECT_DEST_DIR", dstPath))
1.1.1.6 root 1827: SetDlgItemText (hwndDlg, IDC_DIRECTORY, dstPath);
1.1.1.7 root 1828:
1.1.1.6 root 1829: return 1;
1830: }
1831:
1.1.1.11 root 1832: if (lw == IDCANCEL || lw == IDCLOSE)
1.1.1.6 root 1833: {
1834: EndDialog (hwndDlg, lw);
1835: return 1;
1836: }
1837:
1.1.1.7 root 1838: if (lw == IDC_CREATE)
1.1.1.6 root 1839: {
1840: BOOL copyWizard, bExplore, bCacheInDriver, bAutoRun, bAutoMount, bMountReadOnly;
1841: char dstDir[MAX_PATH];
1842: char srcPath[MAX_PATH * 2];
1843: char dstPath[MAX_PATH * 2];
1844: char appDir[MAX_PATH];
1845: char sysDir[MAX_PATH];
1846: char volName[MAX_PATH];
1847: int drive;
1848:
1849: GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstDir, sizeof dstDir);
1850: volName[0] = 0;
1851: GetDlgItemText (hwndDlg, IDC_VOLUME_NAME, volName + 1, sizeof volName);
1852:
1853: drive = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_GETCURSEL, 0, 0);
1854: drive = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_GETITEMDATA, drive, 0);
1855:
1856: copyWizard = IsButtonChecked (GetDlgItem (hwndDlg, IDC_COPY_WIZARD));
1.1.1.7 root 1857: bExplore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_TRAVEL_OPEN_EXPLORER));
1858: bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_TRAV_CACHE_PASSWORDS));
1.1.1.6 root 1859: bMountReadOnly = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY));
1860: bAutoRun = !IsButtonChecked (GetDlgItem (hwndDlg, IDC_AUTORUN_DISABLE));
1861: bAutoMount = IsButtonChecked (GetDlgItem (hwndDlg, IDC_AUTORUN_MOUNT));
1862:
1863: if (dstDir[0] == 0)
1864: {
1865: SetFocus (GetDlgItem (hwndDlg, IDC_DIRECTORY));
1.1.1.7 root 1866: MessageBoxW (hwndDlg, GetString ("NO_PATH_SELECTED"), lpszTitle, MB_ICONEXCLAMATION);
1.1.1.6 root 1867: return 1;
1868: }
1869:
1870:
1871: if (bAutoMount && volName[1] == 0)
1872: {
1873: SetFocus (GetDlgItem (hwndDlg, IDC_VOLUME_NAME));
1.1.1.7 root 1874: MessageBoxW (hwndDlg, GetString ("NO_FILE_SELECTED"), lpszTitle, MB_ICONEXCLAMATION);
1.1.1.6 root 1875: return 1;
1876: }
1877:
1878: if (volName[1] != 0)
1879: {
1880: volName[0] = '"';
1881: strcat (volName, "\"");
1882: }
1883:
1884: GetModuleFileName (NULL, appDir, sizeof (appDir));
1885: strrchr (appDir, '\\')[0] = 0;
1886:
1.1.1.11 root 1887: WaitCursor ();
1.1.1.6 root 1888: GetSystemDirectory (sysDir, sizeof (sysDir));
1889:
1890: sprintf (dstPath, "%s\\TrueCrypt", dstDir);
1891: CreateDirectory (dstPath, NULL);
1892:
1893: // Main app
1894: sprintf (srcPath, "%s\\TrueCrypt.exe", appDir);
1895: sprintf (dstPath, "%s\\TrueCrypt\\TrueCrypt.exe", dstDir);
1896: if (!TCCopyFile (srcPath, dstPath))
1897: {
1898: handleWin32Error (hwndDlg);
1899: goto stop;
1900: }
1901:
1902: // Wizard
1903: if (copyWizard)
1904: {
1905: sprintf (srcPath, "%s\\TrueCrypt Format.exe", appDir);
1906: sprintf (dstPath, "%s\\TrueCrypt\\TrueCrypt Format.exe", dstDir);
1907: if (!TCCopyFile (srcPath, dstPath))
1908: {
1909: handleWin32Error (hwndDlg);
1910: goto stop;
1911: }
1912: }
1913:
1914: // Driver
1.1.1.7 root 1915: sprintf (srcPath, "%s\\truecrypt.sys", appDir);
1.1.1.6 root 1916: sprintf (dstPath, "%s\\TrueCrypt\\truecrypt.sys", dstDir);
1917: if (!TCCopyFile (srcPath, dstPath))
1918: {
1919: handleWin32Error (hwndDlg);
1920: goto stop;
1921: }
1922:
1.1.1.7 root 1923: // Driver x64
1924: sprintf (srcPath, "%s\\truecrypt-x64.sys", appDir);
1925: sprintf (dstPath, "%s\\TrueCrypt\\truecrypt-x64.sys", dstDir);
1926: if (!TCCopyFile (srcPath, dstPath))
1927: {
1928: handleWin32Error (hwndDlg);
1929: goto stop;
1930: }
1931:
1.1.1.11 root 1932: if (GetPreferredLangId () && strcmp (GetPreferredLangId (), "en") != 0)
1933: {
1934: // Language pack
1935: sprintf (srcPath, "%s\\Language.%s.xml", appDir, GetPreferredLangId ());
1936: sprintf (dstPath, "%s\\TrueCrypt\\Language.%s.xml", dstDir, GetPreferredLangId ());
1937: TCCopyFile (srcPath, dstPath);
1938: }
1939:
1.1.1.6 root 1940: // AutoRun
1.1.1.12! root 1941: sprintf (dstPath, "%s\\autorun.inf", dstDir);
! 1942: DeleteFile (dstPath);
1.1.1.6 root 1943: if (bAutoRun)
1944: {
1945: FILE *af;
1946: char autoMount[100];
1947: char driveLetter[] = { ' ', '/', 'l', drive, 0 };
1948:
1.1.1.11 root 1949: af = fopen (dstPath, "w,ccs=UNICODE");
1.1.1.6 root 1950:
1951: if (af == NULL)
1952: {
1.1.1.7 root 1953: MessageBoxW (hwndDlg, GetString ("CANT_CREATE_AUTORUN"), lpszTitle, MB_ICONERROR);
1.1.1.6 root 1954: goto stop;
1955: }
1956:
1.1.1.11 root 1957: sprintf (autoMount, "TrueCrypt\\TrueCrypt.exe /q background%s%s%s%s /m rm /v %s",
1.1.1.6 root 1958: drive > 0 ? driveLetter : "",
1959: bExplore ? " /e" : "",
1.1.1.11 root 1960: bCacheInDriver ? " /c y" : "",
1.1.1.6 root 1961: bMountReadOnly ? " /m ro" : "",
1962: volName);
1963:
1.1.1.11 root 1964: fwprintf (af, L"[autorun]\nlabel=%s\nicon=TrueCrypt\\TrueCrypt.exe\n", GetString ("TC_TRAVELLER_DISK"));
1965: fwprintf (af, L"action=%s\n", bAutoMount ? GetString ("MOUNT_TC_VOLUME") : GetString ("IDC_PREF_LOGON_START"));
1966: fwprintf (af, L"open=%hs\n", bAutoMount ? autoMount : "TrueCrypt\\TrueCrypt.exe");
1967: fwprintf (af, L"shell\\start=%s\nshell\\start\\command=TrueCrypt\\TrueCrypt.exe\n", GetString ("IDC_PREF_LOGON_START"));
1968: fwprintf (af, L"shell\\dismount=%s\nshell\\dismount\\command=TrueCrypt\\TrueCrypt.exe /q /d\n", GetString ("DISMOUNT_ALL_TC_VOLUMES"));
1.1.1.6 root 1969:
1970: fclose (af);
1971: }
1.1.1.7 root 1972: MessageBoxW (hwndDlg, GetString ("TRAVELLER_DISK_CREATED"), lpszTitle, MB_ICONINFORMATION);
1.1.1.6 root 1973:
1974: stop:
1975: NormalCursor ();
1976: return 1;
1977: }
1978: return 0;
1979: }
1980:
1981: return 0;
1982: }
1983:
1984:
1.1 root 1985: void
1986: BuildTree (HWND hTree)
1987: {
1988: HIMAGELIST hList;
1989: HBITMAP hBitmap, hBitmapMask;
1.1.1.7 root 1990: LVCOLUMNW lvCol;
1991:
1992: ListView_DeleteColumn (hTree,0);
1993: ListView_DeleteColumn (hTree,0);
1994: ListView_DeleteColumn (hTree,0);
1995: ListView_DeleteColumn (hTree,0);
1996: ListView_DeleteColumn (hTree,0);
1997: ListView_DeleteColumn (hTree,0);
1998:
1.1 root 1999: SendMessage(hTree,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
2000: LVS_EX_FULLROWSELECT
2001: |LVS_EX_HEADERDRAGDROP
2002: );
2003:
2004: memset(&lvCol,0,sizeof(lvCol));
2005:
2006: lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;
1.1.1.7 root 2007: lvCol.pszText = GetString ("DRIVE");
1.1.1.12! root 2008: lvCol.cx = CompensateXDPI (38);
1.1 root 2009: lvCol.fmt = LVCFMT_COL_HAS_IMAGES|LVCFMT_LEFT ;
1.1.1.7 root 2010: SendMessage (hTree,LVM_INSERTCOLUMNW,0,(LPARAM)&lvCol);
1.1 root 2011:
1.1.1.7 root 2012: lvCol.pszText = GetString ("VOLUME");
1.1.1.12! root 2013: lvCol.cx = CompensateXDPI (253);
1.1 root 2014: lvCol.fmt = LVCFMT_LEFT;
1.1.1.7 root 2015: SendMessage (hTree,LVM_INSERTCOLUMNW,1,(LPARAM)&lvCol);
1.1 root 2016:
1.1.1.7 root 2017: lvCol.pszText = GetString ("SIZE");
1.1.1.12! root 2018: lvCol.cx = CompensateXDPI (55);
1.1 root 2019: lvCol.fmt = LVCFMT_RIGHT;
1.1.1.7 root 2020: SendMessage (hTree,LVM_INSERTCOLUMNW,2,(LPARAM)&lvCol);
1.1 root 2021:
1.1.1.11 root 2022: lvCol.pszText = GetString ("ENCRYPTION_ALGORITHM_LV");
1.1.1.12! root 2023: lvCol.cx = CompensateXDPI (121);
1.1 root 2024: lvCol.fmt = LVCFMT_LEFT;
1.1.1.7 root 2025: SendMessage (hTree,LVM_INSERTCOLUMNW,3,(LPARAM)&lvCol);
1.1 root 2026:
1.1.1.7 root 2027: lvCol.pszText = GetString ("TYPE");
1.1.1.12! root 2028: lvCol.cx = CompensateXDPI (52);
1.1.1.5 root 2029: lvCol.fmt = LVCFMT_LEFT;
1.1.1.7 root 2030: SendMessage (hTree,LVM_INSERTCOLUMNW,4,(LPARAM)&lvCol);
1.1.1.5 root 2031:
1.1 root 2032: hBitmap = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON));
2033: if (hBitmap == NULL)
2034: return;
2035: hBitmapMask = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON_MASK));
2036:
2037: hList = ImageList_Create (16, 12, ILC_COLOR8|ILC_MASK, 2, 2);
2038: if (ImageList_Add (hList, hBitmap, hBitmapMask) == -1)
2039: {
2040: DeleteObject (hBitmap);
2041: return;
2042: }
2043: else
2044: DeleteObject (hBitmap);
2045:
2046: ListView_SetImageList (hTree, hList, LVSIL_NORMAL);
2047: ListView_SetImageList (hTree, hList, LVSIL_SMALL);
2048:
2049: LoadDriveLetters (hTree, 0);
2050: }
2051:
2052: LPARAM
2053: GetSelectedLong (HWND hTree)
2054: {
2055: int hItem = ListView_GetSelectionMark (hTree);
2056: LVITEM item;
2057:
1.1.1.5 root 2058: if (nSelectedDriveIndex >= 0)
1.1 root 2059: hItem = nSelectedDriveIndex;
2060:
2061: memset(&item, 0, sizeof(LVITEM));
2062: item.mask = LVIF_PARAM;
2063: item.iItem = hItem;
2064:
2065: if (ListView_GetItem (hTree, &item) == FALSE)
2066: return MAKELONG (0xffff, 0xffff);
2067: else
2068: return item.lParam;
2069: }
2070:
2071: LPARAM
2072: GetItemLong (HWND hTree, int itemNo)
2073: {
2074: LVITEM item;
2075:
2076: memset(&item, 0, sizeof(LVITEM));
2077: item.mask = LVIF_PARAM;
2078: item.iItem = itemNo;
2079:
2080: if (ListView_GetItem (hTree, &item) == FALSE)
2081: return MAKELONG (0xffff, 0xffff);
2082: else
2083: return item.lParam;
2084: }
2085:
1.1.1.7 root 2086: static int AskUserPassword (HWND hwndDlg, Password *password)
1.1 root 2087: {
1.1.1.7 root 2088: int result;
2089:
2090: result = DialogBoxParamW (hInst,
2091: MAKEINTRESOURCEW (IDD_PASSWORD_DLG), hwndDlg,
1.1 root 2092: (DLGPROC) PasswordDlgProc, (LPARAM) password);
2093:
2094: if (result != IDOK)
1.1.1.7 root 2095: {
2096: password->Length = 0;
2097: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
2098: }
1.1 root 2099:
2100: return result == IDOK;
2101: }
2102:
2103: // GUI actions
2104:
1.1.1.7 root 2105: static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName)
1.1 root 2106: {
1.1.1.7 root 2107: BOOL status = FALSE;
2108: char fileName[MAX_PATH];
1.1 root 2109: int mounted = 0;
1.1.1.7 root 2110: if (nDosDriveNo == 0)
2111: nDosDriveNo = HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A';
1.1 root 2112:
1.1.1.7 root 2113: VolumePassword.Length = 0;
2114:
2115: if (szFileName == NULL)
2116: {
2117: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), fileName, sizeof (fileName));
2118: szFileName = fileName;
2119: }
1.1 root 2120:
2121: if (strlen(szFileName) == 0)
1.1.1.7 root 2122: {
2123: status = FALSE;
2124: goto ret;
2125: }
1.1 root 2126:
2127: if (IsMountedVolume (szFileName))
2128: {
1.1.1.11 root 2129: Warning ("VOL_ALREADY_MOUNTED");
1.1.1.7 root 2130: status = FALSE;
2131: goto ret;
1.1 root 2132: }
2133:
2134: // First try cached passwords and if they fail ask user for a new one
1.1.1.11 root 2135: WaitCursor ();
1.1.1.7 root 2136:
2137: mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, NULL, bCacheInDriver, bForceMount, &mountOptions, FALSE, FALSE);
1.1 root 2138:
1.1.1.7 root 2139: // If keyfiles are enabled, test empty password first
2140: if (!mounted && KeyFilesEnable)
1.1 root 2141: {
1.1.1.12! root 2142: KeyFilesApply (&VolumePassword, FirstKeyFile);
1.1.1.7 root 2143: mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, FALSE, FALSE);
2144: }
1.1 root 2145:
1.1.1.11 root 2146: if (mounted)
2147: {
2148: // Check for legacy 64-bit-block ciphers
2149: if (GetCipherBlockSizeByDriveNo (nDosDriveNo) == 64)
2150: Warning("WARN_64_BIT_BLOCK_CIPHER");
2151:
2152: // Check for problematic file extensions (exe, dll, sys)
2153: if (CheckFileExtension(szFileName))
2154: Warning ("EXE_FILE_EXTENSION_MOUNT_WARNING");
2155: }
2156:
1.1.1.7 root 2157: NormalCursor ();
2158:
2159: while (mounted == 0)
2160: {
2161: if (CmdVolumePassword.Length > 0)
2162: {
2163: VolumePassword = CmdVolumePassword;
2164: }
2165: else if (!Silent)
2166: {
2167: strcpy (PasswordDlgVolume, szFileName);
2168: if (!AskUserPassword (hwndDlg, &VolumePassword))
2169: goto ret;
2170: }
2171:
1.1.1.11 root 2172: WaitCursor ();
1.1.1.7 root 2173:
2174: if (KeyFilesEnable)
1.1.1.12! root 2175: KeyFilesApply (&VolumePassword, FirstKeyFile);
1.1.1.7 root 2176:
2177: mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, FALSE, TRUE);
1.1 root 2178: NormalCursor ();
1.1.1.7 root 2179:
1.1.1.11 root 2180: // Check for legacy 64-bit-block ciphers
2181: if (GetCipherBlockSizeByDriveNo (nDosDriveNo) == 64)
2182: Warning("WARN_64_BIT_BLOCK_CIPHER");
2183:
2184: // Check for legacy non-ASCII passwords
1.1.1.9 root 2185: if (mounted > 0 && !KeyFilesEnable && !CheckPasswordCharEncoding (NULL, &VolumePassword))
2186: Warning ("UNSUPPORTED_CHARS_IN_PWD_RECOM");
2187:
1.1.1.11 root 2188: // Check for problematic file extensions (exe, dll, sys)
2189: if (mounted > 0 && CheckFileExtension(szFileName))
2190: Warning ("EXE_FILE_EXTENSION_MOUNT_WARNING");
2191:
1.1.1.8 root 2192: burn (&VolumePassword, sizeof (VolumePassword));
1.1.1.7 root 2193: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
2194:
2195: if (CmdVolumePassword.Length > 0 || Silent)
2196: break;
1.1 root 2197: }
2198:
1.1.1.5 root 2199: if (mounted > 0)
1.1 root 2200: {
1.1.1.7 root 2201: status = TRUE;
2202:
2203: if (bBeep)
2204: MessageBeep (-1);
1.1 root 2205:
2206: RefreshMainDlg(hwndDlg);
2207:
1.1.1.7 root 2208: if (bExplore)
1.1 root 2209: {
1.1.1.11 root 2210: WaitCursor();
1.1 root 2211: OpenVolumeExplorerWindow (nDosDriveNo);
2212: NormalCursor();
2213: }
1.1.1.7 root 2214:
2215: if (mountOptions.ProtectHiddenVolume)
2216: Info ("HIDVOL_PROT_WARN_AFTER_MOUNT");
1.1 root 2217: }
2218:
1.1.1.7 root 2219: ret:
1.1.1.8 root 2220: burn (&VolumePassword, sizeof (VolumePassword));
1.1.1.7 root 2221: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
1.1.1.11 root 2222:
1.1.1.7 root 2223: RestoreDefaultKeyFilesParam ();
1.1.1.11 root 2224:
2225: if (UsePreferences)
2226: bCacheInDriver = bCacheInDriverDefault;
2227:
1.1.1.7 root 2228: return status;
1.1 root 2229: }
2230:
2231:
1.1.1.7 root 2232: static BOOL Dismount (HWND hwndDlg, int nDosDriveNo)
1.1 root 2233: {
1.1.1.7 root 2234: BOOL status = FALSE;
1.1.1.11 root 2235: WaitCursor ();
1.1 root 2236:
1.1.1.2 root 2237: if (nDosDriveNo == 0)
2238: nDosDriveNo = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A');
1.1 root 2239:
1.1.1.5 root 2240: if (bCloseDismountedWindows)
1.1 root 2241: {
1.1.1.6 root 2242: CloseVolumeExplorerWindows (hwndDlg, nDosDriveNo);
1.1 root 2243: }
2244:
1.1.1.5 root 2245: if (UnmountVolume (hwndDlg, nDosDriveNo, bForceUnmount))
2246: {
1.1.1.7 root 2247: status = TRUE;
2248:
2249: if (bBeep)
2250: MessageBeep (-1);
1.1.1.5 root 2251: RefreshMainDlg (hwndDlg);
1.1.1.10 root 2252:
2253: if (nCurrentOS == WIN_2000 && RemoteSession && !IsAdmin ())
2254: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
1.1 root 2255: }
2256:
1.1.1.5 root 2257: NormalCursor ();
1.1.1.7 root 2258: return status;
1.1 root 2259: }
2260:
1.1.1.7 root 2261: static BOOL DismountAll (HWND hwndDlg, BOOL forceUnmount, BOOL interact, int dismountMaxRetries, int dismountAutoRetryDelay)
1.1 root 2262: {
1.1.1.7 root 2263: BOOL status = TRUE;
1.1.1.5 root 2264: MOUNT_LIST_STRUCT mountList;
2265: DWORD dwResult;
2266: UNMOUNT_STRUCT unmount;
1.1 root 2267: BOOL bResult;
1.1.1.5 root 2268: unsigned __int32 prevMountedDrives = 0;
2269: int i;
1.1 root 2270:
1.1.1.5 root 2271: retry:
1.1.1.11 root 2272: WaitCursor();
1.1 root 2273:
1.1.1.5 root 2274: DeviceIoControl (hDriver, MOUNT_LIST, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
1.1.1.7 root 2275:
2276: if (mountList.ulMountedDrives == 0)
2277: {
2278: NormalCursor();
2279: return TRUE;
2280: }
2281:
1.1.1.11 root 2282: BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, 0, mountList.ulMountedDrives);
2283:
1.1.1.5 root 2284: prevMountedDrives = mountList.ulMountedDrives;
2285:
2286: for (i = 0; i < 26; i++)
1.1 root 2287: {
1.1.1.5 root 2288: if (mountList.ulMountedDrives & (1 << i))
1.1 root 2289: {
1.1.1.5 root 2290: if (bCloseDismountedWindows)
1.1.1.6 root 2291: CloseVolumeExplorerWindows (hwndDlg, i);
1.1 root 2292: }
1.1.1.5 root 2293: }
1.1 root 2294:
1.1.1.5 root 2295: unmount.nDosDriveNo = 0;
2296: unmount.ignoreOpenFiles = forceUnmount;
1.1 root 2297:
1.1.1.6 root 2298: do
2299: {
2300: bResult = DeviceIoControl (hDriver, UNMOUNT_ALL, &unmount,
2301: sizeof (unmount), &unmount, sizeof (unmount), &dwResult, NULL);
2302:
2303: if (bResult == FALSE)
2304: {
2305: NormalCursor();
2306: handleWin32Error (hwndDlg);
1.1.1.7 root 2307: return FALSE;
1.1.1.6 root 2308: }
1.1 root 2309:
1.1.1.6 root 2310: if (unmount.nReturnCode == ERR_FILES_OPEN)
1.1.1.7 root 2311: Sleep (dismountAutoRetryDelay);
1.1.1.6 root 2312: else
2313: break;
1.1 root 2314:
1.1.1.6 root 2315: } while (--dismountMaxRetries > 0);
1.1 root 2316:
1.1.1.7 root 2317: memset (&mountList, 0, sizeof (mountList));
1.1.1.5 root 2318: DeviceIoControl (hDriver, MOUNT_LIST, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
1.1.1.6 root 2319: BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, prevMountedDrives & ~mountList.ulMountedDrives);
1.1 root 2320:
1.1.1.7 root 2321: RefreshMainDlg (hwndDlg);
1.1.1.10 root 2322:
2323: if (nCurrentOS == WIN_2000 && RemoteSession && !IsAdmin ())
2324: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
2325:
1.1.1.5 root 2326: NormalCursor();
1.1 root 2327:
1.1.1.5 root 2328: if (unmount.nReturnCode != 0)
2329: {
1.1.1.7 root 2330: if (forceUnmount)
2331: status = FALSE;
2332:
1.1.1.5 root 2333: if (unmount.nReturnCode == ERR_FILES_OPEN)
2334: {
1.1.1.7 root 2335: if (interact && IDYES == AskWarnNoYes ("UNMOUNTALL_LOCK_FAILED"))
1.1 root 2336: {
1.1.1.5 root 2337: forceUnmount = TRUE;
2338: goto retry;
1.1 root 2339: }
1.1.1.5 root 2340:
1.1.1.7 root 2341: return FALSE;
1.1 root 2342: }
1.1.1.5 root 2343:
1.1.1.7 root 2344: if (interact)
2345: MessageBoxW (hwndDlg, GetString ("UNMOUNT_FAILED"), lpszTitle, MB_ICONERROR);
1.1 root 2346: }
2347: else
2348: {
1.1.1.7 root 2349: if (bBeep)
2350: MessageBeep (-1);
1.1 root 2351: }
1.1.1.7 root 2352:
2353: return status;
1.1 root 2354: }
2355:
1.1.1.7 root 2356: static BOOL MountAllDevices (HWND hwndDlg, BOOL bPasswordPrompt)
1.1 root 2357: {
2358: HWND driveList = GetDlgItem (hwndDlg, IDC_DRIVELIST);
2359: int i, n, selDrive = ListView_GetSelectionMark (driveList);
1.1.1.11 root 2360: BOOL shared = FALSE, status = FALSE, b64BitBlockCipher = FALSE;
1.1.1.7 root 2361: int mountedVolCount = 0;
1.1.1.6 root 2362:
1.1.1.7 root 2363: VolumePassword.Length = 0;
1.1.1.6 root 2364: mountOptions = defaultMountOptions;
2365:
1.1.1.7 root 2366: if (selDrive == -1) selDrive = 0;
1.1 root 2367:
1.1.1.7 root 2368: do
1.1 root 2369: {
1.1.1.7 root 2370: if (!CmdVolumePasswordValid && bPasswordPrompt)
2371: {
2372: PasswordDlgVolume[0] = '\0';
2373: if (!AskUserPassword (hwndDlg, &VolumePassword))
2374: goto ret;
2375: }
2376: else if (CmdVolumePasswordValid)
2377: {
2378: bPasswordPrompt = FALSE;
2379: VolumePassword = CmdVolumePassword;
2380: }
2381:
1.1.1.11 root 2382: WaitCursor();
1.1.1.7 root 2383:
2384: if (FirstCmdKeyFile)
1.1.1.12! root 2385: KeyFilesApply (&VolumePassword, FirstCmdKeyFile);
1.1.1.7 root 2386: else if (KeyFilesEnable)
1.1.1.12! root 2387: KeyFilesApply (&VolumePassword, FirstKeyFile);
1.1.1.7 root 2388:
2389: for (i = 0; i < 64; i++)
1.1 root 2390: {
1.1.1.7 root 2391: // Include partition 0 (whole disk)
2392: for (n = 0; n <= 32; n++)
2393: {
2394: char szFileName[TC_MAX_PATH];
2395: OPEN_TEST_STRUCT driver;
2396: BOOL mounted;
1.1 root 2397:
1.1.1.7 root 2398: sprintf (szFileName, "\\Device\\Harddisk%d\\Partition%d", i, n);
1.1.1.6 root 2399:
1.1.1.7 root 2400: mounted = IsMountedVolume (szFileName);
1.1.1.6 root 2401:
1.1.1.7 root 2402: // Skip other partitions of the disk if partition0 (whole disk) is mounted
2403: if (n == 0 && mounted)
2404: break;
1.1.1.6 root 2405:
1.1.1.7 root 2406: if (!mounted && OpenDevice (szFileName, &driver))
2407: {
2408: int nDosDriveNo;
1.1.1.11 root 2409: PARTITION_INFORMATION pi0, pi1;
2410:
2411: // Skip partition0 if a virtual partition1 exists
2412: if (n == 0 && GetPartitionInfo (szFileName, &pi0))
2413: {
2414: char p[TC_MAX_PATH];
2415: sprintf (p, "\\Device\\Harddisk%d\\Partition1", i);
2416:
2417: if (GetPartitionInfo (p, &pi1) && pi0.PartitionLength.QuadPart == pi1.PartitionLength.QuadPart)
2418: continue;
2419: }
1.1 root 2420:
1.1.1.7 root 2421: while (LOWORD (GetItemLong (driveList, selDrive)) != 0xffff)
1.1 root 2422: {
1.1.1.7 root 2423: if(LOWORD (GetItemLong (driveList, selDrive)) != VFREE)
2424: {
2425: selDrive++;
2426: continue;
2427: }
2428: nDosDriveNo = HIWORD(GetItemLong (driveList, selDrive)) - 'A';
2429: break;
1.1 root 2430: }
2431:
1.1.1.7 root 2432: if (LOWORD (GetItemLong (driveList, selDrive)) == 0xffff)
2433: goto ret;
1.1 root 2434:
1.1.1.7 root 2435: // First try user password then cached passwords
2436: if ((mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, TRUE, FALSE)) > 0
2437: || (mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, NULL, bCacheInDriver, bForceMount, &mountOptions, TRUE, FALSE)) > 0)
2438: {
2439: if (mounted == 2)
2440: shared = TRUE;
1.1.1.5 root 2441:
1.1.1.7 root 2442: LoadDriveLetters (driveList, (HIWORD (GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), selDrive))));
2443: selDrive++;
1.1 root 2444:
1.1.1.7 root 2445: if (bExplore)
2446: {
1.1.1.11 root 2447: WaitCursor();
1.1.1.7 root 2448: OpenVolumeExplorerWindow (nDosDriveNo);
2449: NormalCursor();
2450: }
2451:
2452: if (bBeep)
2453: MessageBeep (-1);
1.1.1.6 root 2454:
1.1.1.7 root 2455: status = TRUE;
2456:
1.1.1.11 root 2457: if (GetCipherBlockSizeByDriveNo(nDosDriveNo) == 64)
2458: b64BitBlockCipher = TRUE;
2459:
1.1.1.7 root 2460: mountedVolCount++;
2461:
2462: // Skip other partitions of the disk if partition0 (whole disk) has been mounted
2463: if (n == 0)
2464: break;
2465: }
1.1 root 2466: }
1.1.1.7 root 2467: else if (n == 0)
2468: break;
1.1 root 2469: }
2470: }
1.1.1.8 root 2471:
2472: burn (&VolumePassword, sizeof (VolumePassword));
2473:
1.1.1.7 root 2474: if (mountedVolCount < 1 && !Silent)
2475: {
1.1.1.11 root 2476: WCHAR szTmp[4096];
1.1.1.7 root 2477:
1.1.1.11 root 2478: swprintf (szTmp, GetString (KeyFilesEnable || FirstCmdKeyFile ? "PASSWORD_OR_KEYFILE_WRONG_AUTOMOUNT" : "PASSWORD_WRONG_AUTOMOUNT"));
1.1.1.7 root 2479: if (CheckCapsLock (hwndDlg, TRUE))
2480: wcscat (szTmp, GetString ("PASSWORD_WRONG_CAPSLOCK_ON"));
2481:
2482: MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONWARNING);
2483: }
2484:
2485: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
2486: } while (bPasswordPrompt && mountedVolCount < 1);
2487:
2488: /* One or more volumes successfully mounted */
1.1 root 2489:
1.1.1.5 root 2490: if (shared)
1.1.1.7 root 2491: Warning ("DEVICE_IN_USE_INFO");
2492:
2493: if (mountOptions.ProtectHiddenVolume)
2494: {
1.1.1.11 root 2495: if (mountedVolCount > 1)
1.1.1.7 root 2496: Info ("HIDVOL_PROT_WARN_AFTER_MOUNT_PLURAL");
2497: else if (mountedVolCount == 1)
2498: Info ("HIDVOL_PROT_WARN_AFTER_MOUNT");
2499: }
2500:
1.1.1.11 root 2501: // Check for legacy 64-bit-block ciphers
2502: if (b64BitBlockCipher)
2503: Warning("WARN_64_BIT_BLOCK_CIPHER");
2504:
2505: // Check for legacy non-ASCII passwords
1.1.1.7 root 2506: if (!KeyFilesEnable
2507: && !FirstCmdKeyFile
2508: && mountedVolCount > 0
2509: && !CheckPasswordCharEncoding (NULL, &VolumePassword))
2510: Warning ("UNSUPPORTED_CHARS_IN_PWD_RECOM");
1.1.1.5 root 2511:
1.1 root 2512: ret:
1.1.1.7 root 2513: burn (&VolumePassword, sizeof (VolumePassword));
2514: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
1.1.1.11 root 2515:
1.1.1.7 root 2516: RestoreDefaultKeyFilesParam ();
1.1.1.11 root 2517:
2518: if (UsePreferences)
2519: bCacheInDriver = bCacheInDriverDefault;
2520:
1.1 root 2521: EnableDisableButtons (hwndDlg);
1.1.1.11 root 2522:
1.1 root 2523: NormalCursor();
1.1.1.7 root 2524:
2525: return status;
1.1 root 2526: }
2527:
2528: static void ChangePassword (HWND hwndDlg)
2529: {
2530: int result;
2531:
2532: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, sizeof (szFileName));
2533: if (IsMountedVolume (szFileName))
2534: {
1.1.1.7 root 2535: Warning (pwdChangeDlgMode == PCDM_CHANGE_PKCS5_PRF ? "MOUNTED_NO_PKCS5_PRF_CHANGE" : "MOUNTED_NOPWCHANGE");
1.1 root 2536: return;
2537: }
2538:
1.1.1.7 root 2539: result = DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_PASSWORDCHANGE_DLG), hwndDlg,
1.1 root 2540: (DLGPROC) PasswordChangeDlgProc);
2541:
2542: if (result == IDOK)
2543: {
2544: HWND tmp = GetDlgItem (hwndDlg, IDC_PASSWORD);
1.1.1.7 root 2545:
2546: switch (pwdChangeDlgMode)
2547: {
2548: case PCDM_CHANGE_PKCS5_PRF:
2549: Info ("PKCS5_PRF_CHANGED");
2550: break;
2551:
2552: case PCDM_ADD_REMOVE_VOL_KEYFILES:
2553: case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
2554: Info ("KEYFILE_CHANGED");
2555: break;
2556:
2557: case PCDM_CHANGE_PASSWORD:
2558: default:
2559: Info ("PASSWORD_CHANGED");
2560: }
1.1 root 2561: SetFocus (tmp);
2562: }
2563: }
2564:
2565: static void SelectContainer (HWND hwndDlg)
2566: {
1.1.1.8 root 2567: if (BrowseFiles (hwndDlg, "OPEN_VOL_TITLE", szFileName, bHistory, FALSE) == FALSE)
1.1 root 2568: return;
2569:
1.1.1.10 root 2570: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1 root 2571: EnableDisableButtons (hwndDlg);
1.1.1.6 root 2572: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1 root 2573: }
2574:
2575: static void SelectPartition (HWND hwndDlg)
2576: {
1.1.1.7 root 2577: int nResult = DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), hwndDlg,
1.1 root 2578: (DLGPROC) RawDevicesDlgProc, (LPARAM) & szFileName[0]);
2579: if (nResult == IDOK)
2580: {
1.1.1.10 root 2581: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1 root 2582: EnableDisableButtons (hwndDlg);
1.1.1.6 root 2583: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1 root 2584: }
2585: }
2586:
2587: static void WipeCache (HWND hwndDlg)
2588: {
2589: DWORD dwResult;
2590: BOOL bResult;
2591:
2592: bResult = DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.11 root 2593: if (hwndDlg == NULL)
2594: return;
1.1 root 2595:
2596: if (bResult == FALSE)
2597: handleWin32Error (hwndDlg);
2598: else
2599: {
2600: EnableDisableButtons (hwndDlg);
2601:
1.1.1.7 root 2602: Info ("WIPE_CACHE");
1.1 root 2603: }
2604: }
2605:
1.1.1.5 root 2606: static void Benchmark (HWND hwndDlg)
2607: {
1.1.1.7 root 2608: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_BENCHMARK_DLG), hwndDlg,
1.1.1.5 root 2609: (DLGPROC) BenchmarkDlgProc, (LPARAM) NULL);
2610: }
1.1 root 2611:
1.1.1.7 root 2612:
2613: static BOOL CheckMountList ()
1.1 root 2614: {
1.1.1.7 root 2615: MOUNT_LIST_STRUCT current;
2616: GetMountList (¤t);
1.1 root 2617:
1.1.1.7 root 2618: if (LastKnownLogicalDrives != GetLogicalDrives()
2619: || memcmp (&LastKnownMountList, ¤t, sizeof (current)) != 0)
1.1 root 2620: {
1.1.1.7 root 2621: LastKnownMountList = current;
1.1 root 2622:
1.1.1.11 root 2623: WaitCursor ();
1.1.1.7 root 2624: LoadDriveLetters (GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
1.1.1.2 root 2625:
1.1.1.7 root 2626: if (nSelectedDriveIndex >= 0)
2627: {
2628: SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),
2629: (char) HIWORD (GetItemLong (GetDlgItem (MainDlg, IDC_DRIVELIST), nSelectedDriveIndex)));
2630: }
1.1 root 2631:
1.1.1.7 root 2632: NormalCursor ();
2633: return FALSE;
2634: }
1.1 root 2635:
1.1.1.7 root 2636: return TRUE;
2637: }
1.1.1.6 root 2638:
1.1 root 2639:
1.1.1.7 root 2640: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
1.1.1.11 root 2641: should return nonzero if it processes a message, and zero if it does not. */
1.1.1.7 root 2642: BOOL CALLBACK
2643: MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
2644: {
1.1.1.11 root 2645: static UINT taskBarCreatedMsg;
1.1.1.7 root 2646: WORD lw = LOWORD (wParam);
2647: WORD hw = HIWORD (wParam);
2648: DWORD mPos;
1.1 root 2649:
1.1.1.7 root 2650: if (lParam); /* remove warning */
1.1 root 2651:
1.1.1.7 root 2652: switch (uMsg)
2653: {
2654: case WM_HOTKEY:
1.1 root 2655:
1.1.1.7 root 2656: HandleHotKey (hwndDlg, wParam);
2657: return 1;
1.1 root 2658:
1.1.1.7 root 2659: case WM_INITDIALOG:
2660: {
2661: int exitCode = 0;
2662: MainDlg = hwndDlg;
1.1 root 2663:
1.1.1.7 root 2664: // Set critical default options in case UsePreferences is false
2665: bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = TRUE;
1.1 root 2666:
1.1.1.7 root 2667: ExtractCommandLine (hwndDlg, (char *) lParam);
2668:
1.1.1.11 root 2669: if (ComServerMode)
2670: {
2671: if (!ComServerMain ())
2672: {
2673: handleWin32Error (hwndDlg);
2674: exit (1);
2675: }
2676: exit (0);
2677: }
2678:
1.1.1.7 root 2679: if (UsePreferences)
1.1 root 2680: {
1.1.1.7 root 2681: // General preferences
2682: LoadSettings (hwndDlg);
2683:
2684: // Keyfiles
2685: LoadDefaultKeyFilesParam ();
2686: RestoreDefaultKeyFilesParam ();
1.1 root 2687: }
2688:
1.1.1.7 root 2689: InitMainDialog (hwndDlg);
2690:
2691: // Wipe cache
2692: if (bWipe)
2693: WipeCache (hwndDlg);
2694:
1.1.1.2 root 2695: // Automount
1.1.1.7 root 2696: if (bAuto || (Quit && szFileName[0] != 0))
1.1 root 2697: {
1.1.1.5 root 2698: // No drive letter specified on command line
2699: if (commandLineDrive == 0)
2700: szDriveLetter[0] = GetFirstAvailableDrive () + 'A';
2701:
1.1.1.6 root 2702: if (bAutoMountDevices)
2703: {
2704: defaultMountOptions = mountOptions;
1.1.1.8 root 2705: if (FirstCmdKeyFile)
2706: {
2707: KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
2708: FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
2709: defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
2710: }
2711:
1.1.1.7 root 2712: if (!MountAllDevices (hwndDlg, !Silent))
2713: exitCode = 1;
2714: }
2715:
2716: if (bAutoMountFavorites)
2717: {
2718: defaultMountOptions = mountOptions;
1.1.1.8 root 2719: if (FirstCmdKeyFile)
2720: {
2721: KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
2722: FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
2723: defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
2724: }
2725:
1.1.1.7 root 2726: if (!MountFavoriteVolumes ())
2727: exitCode = 1;
1.1.1.6 root 2728: }
1.1.1.7 root 2729:
2730: if (szFileName[0] != 0 && !IsMountedVolume (szFileName))
1.1.1.2 root 2731: {
2732: BOOL mounted;
2733:
2734: // Cached password
1.1.1.7 root 2735: mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, NULL, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE);
1.1.1.2 root 2736:
1.1.1.7 root 2737: // Command line password or keyfiles
2738: if (!mounted && (CmdVolumePassword.Length != 0 || FirstCmdKeyFile))
1.1.1.2 root 2739: {
1.1.1.7 root 2740: BOOL reportBadPasswd = CmdVolumePassword.Length > 0;
2741:
2742: if (FirstCmdKeyFile)
1.1.1.12! root 2743: KeyFilesApply (&CmdVolumePassword, FirstCmdKeyFile);
1.1.1.7 root 2744:
2745: mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A',
2746: szFileName, &CmdVolumePassword, bCacheInDriver, bForceMount,
2747: &mountOptions, Silent, reportBadPasswd);
2748:
2749: burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
2750: }
2751:
2752: if (FirstCmdKeyFile)
2753: {
2754: FirstKeyFile = FirstCmdKeyFile;
2755: KeyFilesEnable = TRUE;
1.1.1.2 root 2756: }
2757:
2758: // Ask user for password
1.1.1.7 root 2759: while (!mounted && !Silent)
1.1.1.2 root 2760: {
1.1.1.7 root 2761: VolumePassword.Length = 0;
1.1.1.2 root 2762:
1.1.1.7 root 2763: strcpy (PasswordDlgVolume, szFileName);
2764: if (!AskUserPassword (hwndDlg, &VolumePassword))
1.1.1.2 root 2765: break;
2766:
1.1.1.11 root 2767: WaitCursor ();
1.1.1.7 root 2768:
2769: if (KeyFilesEnable && FirstKeyFile)
1.1.1.12! root 2770: KeyFilesApply (&VolumePassword, FirstKeyFile);
1.1.1.7 root 2771:
2772: mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, FALSE, TRUE);
2773:
2774: burn (&VolumePassword, sizeof (VolumePassword));
2775: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
2776:
1.1.1.2 root 2777: NormalCursor ();
2778: }
2779:
1.1.1.7 root 2780: if (UsePreferences)
1.1.1.11 root 2781: {
1.1.1.7 root 2782: RestoreDefaultKeyFilesParam ();
1.1.1.11 root 2783: bCacheInDriver = bCacheInDriverDefault;
2784: }
1.1.1.7 root 2785:
1.1.1.5 root 2786: if (mounted > 0)
1.1.1.2 root 2787: {
1.1.1.11 root 2788: if (bBeep)
2789: MessageBeep (-1);
2790:
2791: if (bExplore)
2792: OpenVolumeExplorerWindow (szDriveLetter[0] - 'A');
2793:
1.1.1.7 root 2794: RefreshMainDlg(hwndDlg);
1.1.1.11 root 2795:
2796: if(!Silent)
2797: {
2798: // Check for legacy 64-bit-block ciphers
2799: if (GetCipherBlockSizeByDriveNo (szDriveLetter[0] - 'A') == 64)
2800: Warning("WARN_64_BIT_BLOCK_CIPHER");
2801:
2802: // Check for problematic file extensions (exe, dll, sys)
2803: if (CheckFileExtension (szFileName))
2804: Warning ("EXE_FILE_EXTENSION_MOUNT_WARNING");
2805: }
1.1.1.2 root 2806: }
1.1.1.7 root 2807: else
2808: exitCode = 1;
1.1.1.2 root 2809: }
1.1.1.12! root 2810: else if (bExplore && GetMountedVolumeDriveNo (szFileName) != -1)
! 2811: OpenVolumeExplorerWindow (GetMountedVolumeDriveNo (szFileName));
1.1.1.10 root 2812: else if (szFileName[0] != 0 && IsMountedVolume (szFileName))
1.1.1.11 root 2813: Warning ("VOL_ALREADY_MOUNTED");
1.1.1.10 root 2814:
1.1.1.8 root 2815: if (!Quit)
2816: RefreshMainDlg(hwndDlg);
1.1.1.7 root 2817: }
2818:
2819: // Wipe command line password
2820: if (CmdVolumePassword.Length != 0)
2821: {
2822: burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
2823: CmdVolumePassword.Length = 0;
1.1 root 2824: }
2825:
1.1.1.7 root 2826: // Wipe command line keyfiles
2827: if (FirstCmdKeyFile)
1.1.1.8 root 2828: {
2829: if (defaultKeyFilesParam.FirstKeyFile)
2830: KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile);
2831:
2832: defaultKeyFilesParam.EnableKeyFiles = FALSE;
2833:
1.1.1.10 root 2834: if (!Quit)
2835: {
2836: LoadSettings (hwndDlg);
2837: LoadDefaultKeyFilesParam ();
2838: RestoreDefaultKeyFilesParam ();
2839: }
1.1.1.8 root 2840: }
1.1.1.7 root 2841:
2842: // Dismount
1.1.1.5 root 2843: if (cmdUnmountDrive > 0)
1.1.1.7 root 2844: {
2845: if (!Dismount (hwndDlg, (char)toupper(szDriveLetter[0]) - 'A'))
2846: exitCode = 1;
2847: }
1.1.1.5 root 2848: else if (cmdUnmountDrive == -1)
1.1.1.7 root 2849: {
2850: if (!DismountAll (hwndDlg, bForceUnmount, !Silent, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY))
2851: exitCode = 1;
2852: }
1.1.1.5 root 2853:
1.1.1.7 root 2854: // TaskBar icon
2855: if (bEnableBkgTask)
2856: TaskBarIconAdd (hwndDlg);
1.1.1.11 root 2857:
1.1.1.7 root 2858: // Quit
1.1.1.12! root 2859: if (Quit)
! 2860: {
! 2861: if (TaskBarIconMutex == NULL)
! 2862: exit (exitCode);
! 2863:
! 2864: MainWindowHidden = TRUE;
! 2865:
! 2866: LoadSettings (hwndDlg);
! 2867: LoadDefaultKeyFilesParam ();
! 2868: RestoreDefaultKeyFilesParam ();
! 2869:
! 2870: if (!bEnableBkgTask)
! 2871: {
! 2872: if (TaskBarIconMutex)
! 2873: TaskBarIconRemove (hwndDlg);
! 2874: exit (exitCode);
! 2875: }
! 2876: }
1.1.1.7 root 2877:
1.1.1.8 root 2878: // No command line arguments or only /volume => bring active instance
2879: // to foreground if available
2880: if (NoCmdLineArgs == 0 || (CmdLineVolumeSpecified && NoCmdLineArgs <= 2))
2881: {
2882: HWND h = hwndDlg;
2883: EnumWindows (FindTCWindowEnum, (LPARAM) &h);
2884:
2885: if (h != hwndDlg)
2886: {
2887: if (CmdLineVolumeSpecified)
2888: {
2889: COPYDATASTRUCT cd;
2890: memcpy (&cd.dwData, WM_COPY_SET_VOLUME_NAME, 4);
2891: cd.lpData = szFileName;
2892: cd.cbData = strlen (szFileName) + 1;
2893:
2894: SendMessage (h, WM_COPYDATA, (WPARAM)hwndDlg, (LPARAM)&cd);
2895: }
2896:
1.1.1.11 root 2897: SendMessage (h, WM_APP + APPMSG_SHOW_WINDOW, 0, 0);
1.1.1.8 root 2898:
2899: ShowWindow (h, SW_SHOW);
2900: SetForegroundWindow (h);
1.1.1.12! root 2901:
! 2902: if (TaskBarIconMutex == NULL)
! 2903: exit (0);
1.1.1.8 root 2904: }
2905: }
2906:
1.1.1.12! root 2907: // Register hot keys
! 2908: if (!RegisterAllHotkeys (hwndDlg, Hotkeys)
! 2909: && TaskBarIconMutex != NULL) // Warn only if we are the first instance of TrueCrypt
! 2910: Warning("HOTKEY_REGISTRATION_ERROR");
! 2911:
1.1.1.7 root 2912: Silent = FALSE;
2913:
2914: GetMountList (&LastKnownMountList);
2915: SetTimer (hwndDlg, 1, MAIN_TIMER_INTERVAL, NULL);
1.1.1.3 root 2916:
1.1.1.11 root 2917: taskBarCreatedMsg = RegisterWindowMessage ("TaskbarCreated");
2918:
1.1 root 2919: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
2920: }
2921: return 0;
2922:
1.1.1.7 root 2923: case WM_WINDOWPOSCHANGING:
2924: if (MainWindowHidden)
2925: {
2926: PWINDOWPOS wp = (PWINDOWPOS)lParam;
2927: wp->flags &= ~SWP_SHOWWINDOW;
2928: return 0;
2929: }
2930: return 1;
2931:
1.1 root 2932: case WM_SYSCOMMAND:
2933: if (lw == IDC_ABOUT)
2934: {
1.1.1.7 root 2935: DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1 root 2936: return 1;
2937: }
2938: return 0;
2939:
2940: case WM_HELP:
1.1.1.7 root 2941: OpenPageHelp (hwndDlg, 0);
1.1 root 2942: return 1;
2943:
1.1.1.7 root 2944: case WM_ENDSESSION:
2945: if (TaskBarIconMutex != NULL)
1.1 root 2946: {
1.1.1.7 root 2947: if (bDismountOnLogOff)
2948: {
2949: // Auto-dismount when user logs off
2950: DWORD dwResult;
2951:
2952: if (bWipeCacheOnAutoDismount)
2953: DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
2954:
2955: if (!DismountAll (hwndDlg, FALSE, FALSE, 5, 1000))
2956: {
2957: if (bForceAutoDismount)
2958: DismountAll (hwndDlg, TRUE, FALSE, 1, 0);
2959: else
2960: DismountAll (hwndDlg, FALSE, TRUE, 1, 0);
2961: }
2962: }
2963:
2964: TaskBarIconRemove (hwndDlg);
2965: }
2966: return 0;
2967:
2968: case WM_POWERBROADCAST:
2969: if (wParam == PBT_APMSUSPEND
2970: && TaskBarIconMutex != NULL && bDismountOnPowerSaving)
2971: {
2972: // Auto-dismount when entering power-saving mode
2973: DWORD dwResult;
1.1.1.12! root 2974: BOOL volumesMounted = LastKnownMountList.ulMountedDrives != 0;
! 2975:
1.1.1.7 root 2976: if (bWipeCacheOnAutoDismount)
2977: DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.12! root 2978:
! 2979: if (DismountAll (hwndDlg, bForceAutoDismount, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY) && volumesMounted)
! 2980: Info ("MOUNTED_VOLUMES_AUTO_DISMOUNTED");
1.1.1.7 root 2981: }
2982: return 0;
2983:
2984: case WM_TIMER:
2985: {
1.1.1.8 root 2986: MainWindowHidden = !IsWindowVisible (hwndDlg);
2987:
1.1.1.7 root 2988: // Check mount list and update GUI if needed
2989: CheckMountList ();
2990:
2991: // Cache status
2992: if (IsPasswordCacheEmpty() == IsWindowEnabled (GetDlgItem (hwndDlg, IDC_WIPE_CACHE)))
2993: EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_CACHE), !IsPasswordCacheEmpty());
2994:
2995: if (TaskBarIconMutex != NULL)
2996: {
2997: // Idle auto-dismount
2998: if (MaxVolumeIdleTime > 0)
2999: DismountIdleVolumes ();
3000:
3001: // Screen saver auto-dismount
3002: if (bDismountOnScreenSaver)
3003: {
3004: static BOOL previousState = FALSE;
3005: BOOL running = FALSE;
3006: SystemParametersInfo (SPI_GETSCREENSAVERRUNNING, 0, &running, 0);
3007:
3008: if (running && !previousState)
3009: {
3010: DWORD dwResult;
3011: previousState = TRUE;
3012:
3013: if (bWipeCacheOnAutoDismount)
3014: DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.12! root 3015:
! 3016: DismountAll (hwndDlg, bForceAutoDismount, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1.1.7 root 3017: }
3018: else
3019: {
3020: previousState = running;
1.1.1.8 root 3021: }
1.1.1.7 root 3022: }
3023: }
3024:
1.1.1.8 root 3025: // Exit background process in non-install mode or if no volume mounted
1.1.1.7 root 3026: // and no other instance active
3027: if (LastKnownMountList.ulMountedDrives == 0
1.1.1.8 root 3028: && !IsWindowVisible (hwndDlg)
1.1.1.7 root 3029: #ifndef _DEBUG
3030: && (bCloseBkgTaskWhenNoVolumes || IsNonInstallMode ())
3031: #endif
3032: && GetDriverRefCount () < 2)
3033: {
3034: TaskBarIconRemove (hwndDlg);
3035: EndMainDlg (hwndDlg);
3036: }
1.1 root 3037:
3038: return 1;
3039: }
3040:
1.1.1.11 root 3041: case WM_APP + APPMSG_TASKBAR_ICON:
1.1 root 3042: {
1.1.1.7 root 3043: switch (lParam)
3044: {
3045: case WM_LBUTTONDOWN:
1.1.1.8 root 3046: SetForegroundWindow (hwndDlg);
1.1.1.7 root 3047: MainWindowHidden = FALSE;
3048: ShowWindow (hwndDlg, SW_SHOW);
3049: break;
3050:
3051: case WM_RBUTTONDOWN:
3052: {
3053: POINT pos;
3054: HMENU popup = CreatePopupMenu ();
3055: int sel, i, n;
1.1.1.8 root 3056:
3057: MainWindowHidden = !IsWindowVisible (hwndDlg);
1.1.1.7 root 3058: if (MainWindowHidden)
3059: {
3060: AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("SHOW_TC"));
3061: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
3062: }
3063: else if (bEnableBkgTask
3064: && (!(LastKnownMountList.ulMountedDrives == 0
3065: && (bCloseBkgTaskWhenNoVolumes || IsNonInstallMode ())
3066: && GetDriverRefCount () < 2)))
3067: {
3068: AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("HIDE_TC"));
3069: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
3070: }
3071: AppendMenuW (popup, MF_STRING, IDM_MOUNT_FAVORITE_VOLUMES, GetString ("IDM_MOUNT_FAVORITE_VOLUMES"));
3072: AppendMenuW (popup, MF_STRING, IDM_UNMOUNTALL, GetString ("IDM_UNMOUNTALL"));
3073: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
3074:
3075: for (n = 0; n < 2; n++)
3076: {
3077: for (i = 0; i < 26; i++)
3078: {
3079: if (LastKnownMountList.ulMountedDrives & (1 << i))
3080: {
3081: wchar_t s[1024];
3082: wchar_t *vol = LastKnownMountList.wszVolume[i];
3083:
3084: if (wcsstr (vol, L"\\??\\")) vol += 4;
3085:
3086: wsprintfW (s, L"%s %c: (%s)",
3087: GetString (n==0 ? "OPEN" : "DISMOUNT"),
3088: i + L'A',
3089: vol);
3090: AppendMenuW (popup, MF_STRING, n*26 + 9000 + i, s);
3091: }
3092: }
3093: if (LastKnownMountList.ulMountedDrives != 0)
3094: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
3095: }
3096:
3097: AppendMenuW (popup, MF_STRING, IDM_HELP, GetString ("MENU_HELP"));
1.1.1.11 root 3098: AppendMenuW (popup, MF_STRING, IDM_HOMEPAGE_SYSTRAY, GetString ("HOMEPAGE"));
1.1.1.7 root 3099: AppendMenuW (popup, MF_STRING, IDM_PREFERENCES, GetString ("IDM_PREFERENCES"));
3100: AppendMenuW (popup, MF_STRING, IDM_ABOUT, GetString ("IDM_ABOUT"));
3101: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
3102: AppendMenuW (popup, MF_STRING, IDM_EXIT, GetString ("IDM_EXIT"));
3103:
3104: GetCursorPos (&pos);
3105:
3106: SetForegroundWindow(hwndDlg);
3107:
3108: sel = TrackPopupMenu (popup,
3109: TPM_RETURNCMD | TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON,
3110: pos.x,
3111: pos.y,
3112: 0,
3113: hwndDlg,
3114: NULL);
3115:
3116: if (sel >= 9000 && sel < 9026)
3117: {
3118: OpenVolumeExplorerWindow (sel - 9000);
3119: }
3120: else if (sel >= 9026 && sel < 9052)
3121: {
3122: if (CheckMountList ())
3123: Dismount (hwndDlg, sel - 9026);
3124: }
3125: else if (sel == IDM_SHOW_HIDE)
3126: {
3127: MainWindowHidden = !MainWindowHidden;
3128: ShowWindow (hwndDlg, !MainWindowHidden ? SW_SHOW : SW_HIDE);
3129: }
1.1.1.11 root 3130: else if (sel == IDM_HOMEPAGE_SYSTRAY)
3131: {
3132: Applink ("home", TRUE, "");
3133: }
1.1.1.7 root 3134: else if (sel == IDM_EXIT)
3135: {
3136: if (LastKnownMountList.ulMountedDrives == 0
3137: || AskWarnNoYes ("CONFIRM_EXIT") == IDYES)
3138: {
3139: // Close all other TC windows
3140: EnumWindows (CloseTCWindowsEnum, 0);
3141:
3142: TaskBarIconRemove (hwndDlg);
3143: SendMessage (hwndDlg, WM_COMMAND, sel, 0);
3144: }
3145: }
3146: else
3147: {
3148: SendMessage (hwndDlg, WM_COMMAND, sel, 0);
3149: }
3150:
3151: PostMessage(hwndDlg, WM_NULL, 0, 0);
3152: DestroyMenu (popup);
3153: }
1.1 root 3154: }
1.1.1.7 root 3155: return 1;
3156: }
3157:
1.1.1.11 root 3158: case WM_APP + APPMSG_CLOSE_BKG_TASK:
3159: if (TaskBarIconMutex != NULL)
3160: TaskBarIconRemove (hwndDlg);
3161:
3162: return 1;
3163:
3164: case WM_DEVICECHANGE:
1.1.1.12! root 3165: if (!IgnoreWmDeviceChange && wParam != DBT_DEVICEARRIVAL)
1.1.1.11 root 3166: {
3167: // Check if any host device has been removed and force dismount of volumes accordingly
3168: PDEV_BROADCAST_HDR hdr = (PDEV_BROADCAST_HDR) lParam;
1.1.1.12! root 3169: int m;
! 3170:
! 3171: GetMountList (&LastKnownMountList);
! 3172:
1.1.1.11 root 3173: if (wParam == DBT_DEVICEREMOVECOMPLETE && hdr->dbch_devicetype == DBT_DEVTYP_VOLUME)
3174: {
1.1.1.12! root 3175: // File-hosted volumes
1.1.1.11 root 3176: PDEV_BROADCAST_VOLUME vol = (PDEV_BROADCAST_VOLUME) lParam;
1.1.1.12! root 3177: int i;
1.1.1.11 root 3178:
3179: for (i = 0; i < 26; i++)
3180: {
3181: if (vol->dbcv_unitmask & (1 << i))
3182: {
3183: for (m = 0; m < 26; m++)
3184: {
3185: if (LastKnownMountList.ulMountedDrives & (1 << m))
3186: {
3187: wchar_t *vol = LastKnownMountList.wszVolume[m];
3188:
1.1.1.12! root 3189: if (wcsstr (vol, L"\\??\\") == vol)
1.1.1.11 root 3190: vol += 4;
3191:
1.1.1.12! root 3192: if (vol[1] == L':' && i == (vol[0] - (vol[0] <= L'Z' ? L'A' : L'a')))
1.1.1.11 root 3193: {
3194: UnmountVolume (hwndDlg, m, TRUE);
3195: if (bWipeCacheOnAutoDismount || bWipeCacheOnExit)
3196: WipeCache (NULL);
3197: }
3198: }
3199: }
3200: }
3201: }
1.1.1.12! root 3202: }
1.1.1.11 root 3203:
1.1.1.12! root 3204: // Device-hosted volumes
! 3205: for (m = 0; m < 26; m++)
! 3206: {
! 3207: if (LastKnownMountList.ulMountedDrives & (1 << m))
! 3208: {
! 3209: wchar_t *vol = LastKnownMountList.wszVolume[m];
! 3210: char volp[MAX_PATH];
! 3211:
! 3212: if (wcsstr (vol, L"\\??\\") == vol)
! 3213: vol += 4;
! 3214:
! 3215: _snprintf (volp, sizeof(volp), "%ls", vol);
! 3216:
! 3217: if (IsVolumeDeviceHosted (volp))
! 3218: {
! 3219: OPEN_TEST_STRUCT ots;
! 3220:
! 3221: if (!OpenDevice (volp, &ots))
! 3222: {
! 3223: UnmountVolume (hwndDlg, m, TRUE);
! 3224: if (bWipeCacheOnAutoDismount || bWipeCacheOnExit)
! 3225: WipeCache (NULL);
! 3226: }
! 3227: }
! 3228: }
1.1.1.11 root 3229: }
1.1.1.12! root 3230: return 1;
1.1.1.11 root 3231: }
1.1.1.12! root 3232: return 0;
1.1.1.11 root 3233:
1.1.1.7 root 3234: case WM_NOTIFY:
3235:
3236: if(wParam == IDC_DRIVELIST)
3237: {
3238: /* Single click within drive list */
3239: if (((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED ))
3240: {
3241: nSelectedDriveIndex = ((LPNMLISTVIEW) lParam)->iItem;
3242: EnableDisableButtons (hwndDlg);
3243: return 1;
3244: }
3245:
3246: /* Double click within drive list */
3247: if (((LPNMHDR) lParam)->code == LVN_ITEMACTIVATE)
1.1 root 3248: {
1.1.1.7 root 3249: int state = GetItemLong(GetDlgItem (hwndDlg, IDC_DRIVELIST), ((LPNMITEMACTIVATE)lParam)->iItem );
3250: nSelectedDriveIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
3251: if (LOWORD(state) == VMOUNTED)
3252: {
3253: // Open explorer window for mounted volume
1.1.1.11 root 3254: WaitCursor ();
1.1.1.7 root 3255: OpenVolumeExplorerWindow (HIWORD(state) - 'A');
3256: NormalCursor ();
3257: }
3258: else if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VFREE)
3259: {
1.1.1.11 root 3260: mountOptions = defaultMountOptions;
3261:
1.1.1.9 root 3262: if (GetAsyncKeyState (VK_CONTROL) < 0)
3263: {
3264: if (IDCANCEL == DialogBoxParamW (hInst,
3265: MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
3266: (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions))
3267: return 1;
3268:
3269: if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
1.1.1.12! root 3270: KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile);
1.1.1.9 root 3271: }
3272:
1.1.1.7 root 3273: if (CheckMountList ())
3274: Mount (hwndDlg, 0, 0);
3275: }
3276: return 1;
3277: }
3278:
3279: /* Right click and drag&drop operations */
3280: switch(((NM_LISTVIEW *) lParam)->hdr.code)
3281: {
3282: case NM_RCLICK:
3283: case LVN_BEGINRDRAG:
3284: /* If the mouse was moving while the right mouse button is pressed, popup menu would
3285: not open, because drag&drop operation would be initiated. Therefore, we're handling
3286: RMB drag-and-drop operations as well. */
3287: {
3288:
3289: /* Drive list context menu */
3290:
3291: int menuItem;
3292: HMENU popup = CreatePopupMenu ();
3293:
3294: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
3295:
3296: if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VFREE)
3297: {
3298: // No mounted volume at this drive letter
3299: AppendMenuW (popup, MF_STRING, IDM_MOUNT_VOLUME, GetString ("IDM_MOUNT_VOLUME"));
3300: }
3301: else
3302: {
3303: // There's a mounted volume at this drive letter
3304: AppendMenuW (popup, MF_STRING, IDM_UNMOUNT_VOLUME, GetString ("DISMOUNT"));
3305: AppendMenuW (popup, MF_STRING, IDPM_OPEN_VOLUME, GetString ("OPEN"));
3306: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
3307: AppendMenuW (popup, MF_STRING, IDPM_CHECK_FILESYS, GetString ("IDPM_CHECK_FILESYS"));
3308: AppendMenuW (popup, MF_STRING, IDPM_REPAIR_FILESYS, GetString ("IDPM_REPAIR_FILESYS"));
3309: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
3310: AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES"));
3311: }
3312:
3313: mPos=GetMessagePos();
3314:
3315: menuItem = TrackPopupMenu (popup,
3316: TPM_RETURNCMD | TPM_LEFTBUTTON,
3317: GET_X_LPARAM(mPos),
3318: GET_Y_LPARAM(mPos),
3319: 0,
3320: hwndDlg,
3321: NULL);
3322:
3323: DestroyMenu (popup);
3324:
3325: switch (menuItem)
3326: {
3327: case IDPM_CHECK_FILESYS:
3328: case IDPM_REPAIR_FILESYS:
3329: {
3330: LPARAM lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
3331:
3332: if (LOWORD (lLetter) != 0xffff)
3333: {
3334: wchar_t msg[1024], param[1024];
3335: char szTmp[32] = {0};
3336:
3337: sprintf (szTmp, "%c:", (char) HIWORD (lLetter));
3338:
3339: wsprintfW (msg,
3340: GetString (menuItem == IDPM_REPAIR_FILESYS ? "REPAIRING_FS" : "CHECKING_FS")
3341: , szTmp);
3342:
3343: wsprintfW (param,
3344: menuItem == IDPM_REPAIR_FILESYS ?
1.1.1.8 root 3345: L"/C echo %s && (chkdsk %hs /F /X || set X=0) && pause"
3346: : L"/C echo %s && (chkdsk %hs || set X=0) && pause",
1.1.1.7 root 3347: msg,
1.1.1.8 root 3348: szTmp);
1.1.1.7 root 3349:
1.1.1.11 root 3350: ShellExecuteW (NULL,
3351: (!IsAdmin() && IsUacSupported()) ? L"runas" : L"open",
3352: L"cmd.exe", param, NULL, SW_SHOW);
1.1.1.7 root 3353: }
3354: }
3355: break;
3356:
3357: case IDM_UNMOUNT_VOLUME:
3358: if (CheckMountList ())
3359: Dismount (hwndDlg, 0);
3360: break;
3361:
3362: case IDPM_OPEN_VOLUME:
3363: {
3364: int state = GetItemLong(GetDlgItem (hwndDlg, IDC_DRIVELIST), ((LPNMITEMACTIVATE)lParam)->iItem );
3365: nSelectedDriveIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
3366:
1.1.1.11 root 3367: WaitCursor ();
1.1.1.7 root 3368: OpenVolumeExplorerWindow (HIWORD(state) - 'A');
3369: NormalCursor ();
3370: }
3371: break;
3372:
3373: case IDM_VOLUME_PROPERTIES:
3374: DialogBoxParamW (hInst,
3375: MAKEINTRESOURCEW (IDD_VOLUME_PROPERTIES), hwndDlg,
3376: (DLGPROC) VolumePropertiesDlgProc, (LPARAM) 0);
3377: break;
3378:
3379: case IDM_MOUNT_VOLUME:
3380: if (!VolumeSelected(hwndDlg))
3381: {
3382: Warning ("NO_VOLUME_SELECTED");
3383: }
3384: else
3385: {
3386: mountOptions = defaultMountOptions;
3387:
3388: if (CheckMountList ())
3389: Mount (hwndDlg, 0, 0);
3390: }
3391: break;
3392: }
3393: return 1;
3394: }
1.1 root 3395: }
3396: }
3397: return 0;
3398:
3399: case WM_ERASEBKGND:
3400: return 0;
3401:
3402: case WM_COMMAND:
3403:
1.1.1.7 root 3404: if (lw == IDCANCEL || lw == IDC_EXIT || lw == IDM_EXIT)
1.1 root 3405: {
3406: EndMainDlg (hwndDlg);
3407: return 1;
3408: }
3409:
3410: if (lw == IDHELP || lw == IDM_HELP)
3411: {
1.1.1.7 root 3412: OpenPageHelp (hwndDlg, 0);
1.1 root 3413: return 1;
3414: }
3415:
1.1.1.12! root 3416: if (lw == IDM_ABOUT || lw == IDC_LOGO)
1.1 root 3417: {
1.1.1.7 root 3418: DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1 root 3419: return 1;
3420: }
3421:
1.1.1.7 root 3422: if (lw == IDOK && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VMOUNTED
3423: || lw == IDM_UNMOUNT_VOLUME)
1.1 root 3424: {
1.1.1.7 root 3425: if (lw == IDM_UNMOUNT_VOLUME && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) != VMOUNTED)
1.1.1.6 root 3426: {
1.1.1.7 root 3427: Warning ("SELECT_A_MOUNTED_VOLUME");
3428: return 1;
1.1.1.6 root 3429: }
1.1 root 3430:
1.1.1.7 root 3431: if (CheckMountList ())
3432: Dismount (hwndDlg, 0);
1.1 root 3433: return 1;
3434: }
3435:
1.1.1.7 root 3436: if ((lw == IDOK || lw == IDM_MOUNT_VOLUME || lw == IDM_MOUNT_VOLUME_OPTIONS || lw == IDC_MOUNTALL || lw == IDM_MOUNTALL)
1.1 root 3437: && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == 0xffff)
3438: {
1.1.1.7 root 3439: MessageBoxW (hwndDlg, GetString ("SELECT_FREE_DRIVE"), L"TrueCrypt", MB_ICONEXCLAMATION);
1.1 root 3440: return 1;
3441: }
3442:
1.1.1.7 root 3443: if ((lw == IDOK || lw == IDM_MOUNT_VOLUME || lw == IDM_MOUNT_VOLUME_OPTIONS))
1.1 root 3444: {
1.1.1.7 root 3445: if (!VolumeSelected(hwndDlg))
3446: {
3447: Warning ("NO_VOLUME_SELECTED");
3448: }
3449: else if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VFREE)
3450: {
3451: mountOptions = defaultMountOptions;
3452:
3453: if (lw == IDM_MOUNT_VOLUME_OPTIONS || GetAsyncKeyState (VK_CONTROL) < 0)
3454: {
3455: if (IDCANCEL == DialogBoxParamW (hInst,
3456: MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
3457: (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions))
3458: return 1;
3459:
3460: if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
1.1.1.12! root 3461: KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile);
1.1.1.7 root 3462: }
3463:
3464: if (CheckMountList ())
3465: Mount (hwndDlg, 0, 0);
3466: }
1.1 root 3467: return 1;
3468: }
3469:
1.1.1.7 root 3470: if (lw == IDC_UNMOUNTALL || lw == IDM_UNMOUNTALL)
1.1 root 3471: {
1.1.1.7 root 3472: DismountAll (hwndDlg, bForceUnmount, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1 root 3473: return 1;
3474: }
3475:
1.1.1.7 root 3476: if (lw == IDC_MOUNTALL || lw == IDM_MOUNTALL)
1.1 root 3477: {
1.1.1.7 root 3478: // If Shift key is down and the password cache isn't empty, bypass password prompt
3479: MountAllDevices (hwndDlg, !(GetAsyncKeyState (VK_SHIFT) < 0 && !IsPasswordCacheEmpty()));
1.1 root 3480: return 1;
3481: }
3482:
1.1.1.7 root 3483: if (lw == IDC_SELECT_FILE || lw == IDM_SELECT_FILE)
1.1 root 3484: {
3485: SelectContainer (hwndDlg);
3486: return 1;
3487: }
3488:
1.1.1.7 root 3489: if (lw == IDC_SELECT_DEVICE || lw == IDM_SELECT_DEVICE)
1.1 root 3490: {
3491: SelectPartition (hwndDlg);
3492: return 1;
3493: }
3494:
1.1.1.7 root 3495: if (lw == IDC_VOLUME_TOOLS)
3496: {
3497: int menuItem;
3498: char volPath[TC_MAX_PATH]; /* Volume to mount */
3499: HMENU popup = CreatePopupMenu ();
3500: RECT rect;
3501:
3502: AppendMenuW (popup, MF_STRING, IDM_CHANGE_PASSWORD, GetString ("IDM_CHANGE_PASSWORD"));
3503: AppendMenuW (popup, MF_STRING, IDM_CHANGE_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_HEADER_KEY_DERIV_ALGO"));
3504: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
3505: AppendMenuW (popup, MF_STRING, IDM_BACKUP_VOL_HEADER, GetString ("IDM_BACKUP_VOL_HEADER"));
3506: AppendMenuW (popup, MF_STRING, IDM_RESTORE_VOL_HEADER, GetString ("IDM_RESTORE_VOL_HEADER"));
3507:
3508: GetWindowRect (GetDlgItem (hwndDlg, IDC_VOLUME_TOOLS), &rect);
3509:
3510: menuItem = TrackPopupMenu (popup,
3511: TPM_RETURNCMD | TPM_LEFTBUTTON,
3512: rect.left + 2,
3513: rect.top + 2,
3514: 0,
3515: hwndDlg,
3516: NULL);
3517:
3518: DestroyMenu (popup);
3519:
3520: switch (menuItem)
3521: {
3522: case IDM_CHANGE_PASSWORD:
3523: if (!VolumeSelected(hwndDlg))
3524: {
3525: Warning ("NO_VOLUME_SELECTED");
3526: }
3527: else
3528: {
3529: pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
3530: ChangePassword (hwndDlg);
3531: }
3532: break;
3533:
3534: case IDM_CHANGE_HEADER_KEY_DERIV_ALGO:
3535: if (!VolumeSelected(hwndDlg))
3536: {
3537: Warning ("NO_VOLUME_SELECTED");
3538: }
3539: else
3540: {
3541: pwdChangeDlgMode = PCDM_CHANGE_PKCS5_PRF;
3542: ChangePassword (hwndDlg);
3543: }
3544: break;
3545:
3546: case IDM_BACKUP_VOL_HEADER:
3547: if (!VolumeSelected(hwndDlg))
3548: {
3549: Warning ("NO_VOLUME_SELECTED");
3550: }
3551: else
3552: {
3553: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
3554:
1.1.1.11 root 3555: if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
3556: UacBackupVolumeHeader (hwndDlg, TRUE, volPath);
3557: else
3558: BackupVolumeHeader (hwndDlg, TRUE, volPath);
1.1.1.7 root 3559: }
3560: break;
3561:
3562: case IDM_RESTORE_VOL_HEADER:
3563: if (!VolumeSelected(hwndDlg))
3564: {
3565: Warning ("NO_VOLUME_SELECTED");
3566: }
3567: else
3568: {
3569: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
3570:
1.1.1.11 root 3571: if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
3572: UacRestoreVolumeHeader (hwndDlg, volPath);
3573: else
3574: RestoreVolumeHeader (hwndDlg, volPath);
1.1.1.7 root 3575: }
3576: break;
3577: }
3578: return 1;
3579: }
3580:
3581: if (lw == IDM_CHANGE_PASSWORD)
1.1 root 3582: {
1.1.1.7 root 3583: if (!VolumeSelected(hwndDlg))
3584: {
3585: Warning ("NO_VOLUME_SELECTED");
3586: }
3587: else
3588: {
3589: pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
3590: ChangePassword (hwndDlg);
3591: }
1.1 root 3592: return 1;
3593: }
3594:
1.1.1.7 root 3595: if (lw == IDM_CHANGE_HEADER_KEY_DERIV_ALGO)
3596: {
3597: if (!VolumeSelected(hwndDlg))
3598: {
3599: Warning ("NO_VOLUME_SELECTED");
3600: }
3601: else
3602: {
3603: pwdChangeDlgMode = PCDM_CHANGE_PKCS5_PRF;
3604: ChangePassword (hwndDlg);
3605: }
3606: return 1;
3607: }
3608:
3609: if (lw == IDC_WIPE_CACHE || lw == IDM_WIPE_CACHE)
1.1 root 3610: {
3611: WipeCache (hwndDlg);
3612: return 1;
3613: }
3614:
1.1.1.7 root 3615: if (lw == IDM_CLEAR_HISTORY)
1.1 root 3616: {
1.1.1.11 root 3617: ClearHistory (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1 root 3618: EnableDisableButtons (hwndDlg);
3619: return 1;
3620: }
3621:
1.1.1.7 root 3622: if (lw == IDC_CREATE_VOLUME || lw == IDM_CREATE_VOLUME || lw == IDM_VOLUME_WIZARD)
1.1 root 3623: {
3624: char t[TC_MAX_PATH];
3625: char *tmp;
1.1.1.7 root 3626: FILE *fhTemp;
1.1 root 3627:
3628: GetModuleFileName (NULL, t, sizeof (t));
1.1.1.7 root 3629:
1.1 root 3630: tmp = strrchr (t, '\\');
3631: if (tmp)
3632: {
1.1.1.9 root 3633: STARTUPINFO si;
3634: PROCESS_INFORMATION pi;
3635: ZeroMemory (&si, sizeof (si));
3636:
1.1 root 3637: strcpy (++tmp, "TrueCrypt Format.exe");
1.1.1.7 root 3638:
3639: if ((fhTemp = fopen(t, "r")) == NULL)
3640: Error ("VOL_CREATION_WIZARD_NOT_FOUND");
3641: else
3642: fclose (fhTemp);
3643:
1.1.1.9 root 3644: if (!CreateProcess (t, NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi))
3645: {
3646: handleWin32Error (hwndDlg);
3647: }
3648: else
3649: {
3650: CloseHandle (pi.hProcess);
3651: CloseHandle (pi.hThread);
3652: }
1.1 root 3653: }
3654: return 1;
3655: }
3656:
1.1.1.7 root 3657: if (lw == IDM_ADD_REMOVE_VOL_KEYFILES)
1.1.1.3 root 3658: {
1.1.1.7 root 3659: if (!VolumeSelected(hwndDlg))
3660: {
3661: Warning ("NO_VOLUME_SELECTED");
3662: }
3663: else
3664: {
3665: pwdChangeDlgMode = PCDM_ADD_REMOVE_VOL_KEYFILES;
3666: ChangePassword (hwndDlg);
3667: }
3668: return 1;
3669: }
1.1.1.3 root 3670:
1.1.1.7 root 3671: if (lw == IDM_REMOVE_ALL_KEYFILES_FROM_VOL)
3672: {
3673: if (!VolumeSelected(hwndDlg))
1.1.1.3 root 3674: {
1.1.1.7 root 3675: Warning ("NO_VOLUME_SELECTED");
3676: }
3677: else
3678: {
3679: pwdChangeDlgMode = PCDM_REMOVE_ALL_KEYFILES_FROM_VOL;
3680: ChangePassword (hwndDlg);
1.1.1.3 root 3681: }
3682: return 1;
3683: }
1.1.1.7 root 3684:
3685: if (lw == IDM_GENERATE_KEYFILE || lw == IDM_KEYFILE_GENERATOR)
3686: {
3687: DialogBoxParamW (hInst,
3688: MAKEINTRESOURCEW (IDD_KEYFILE_GENERATOR), hwndDlg,
3689: (DLGPROC) KeyfileGeneratorDlgProc, (LPARAM) 0);
3690:
3691: return 1;
3692: }
3693:
3694: if (lw == IDM_LICENSE)
3695: {
3696: DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_LEGAL_NOTICES_DLG), hwndDlg, (DLGPROC) LegalNoticesDlgProc);
3697: return 1;
3698: }
1.1.1.3 root 3699:
1.1.1.11 root 3700: if (lw == IDM_WEBSITE)
1.1.1.7 root 3701: {
1.1.1.11 root 3702: Applink ("website", TRUE, "");
3703: return 1;
3704: }
3705: else if (lw == IDM_HOMEPAGE)
3706: {
3707: Applink ("homepage", TRUE, "");
1.1.1.7 root 3708: return 1;
3709: }
3710: else if (lw == IDM_FORUMS)
1.1 root 3711: {
1.1.1.11 root 3712: Applink ("forum", TRUE, "");
1.1.1.5 root 3713: return 1;
3714: }
1.1.1.9 root 3715: else if (lw == IDM_ONLINE_TUTORIAL)
3716: {
1.1.1.11 root 3717: Applink ("tutorial", TRUE, "");
1.1.1.9 root 3718: return 1;
3719: }
3720: else if (lw == IDM_ONLINE_HELP)
3721: {
1.1.1.10 root 3722: OpenOnlineHelp ();
1.1.1.9 root 3723: return 1;
3724: }
1.1.1.7 root 3725: else if (lw == IDM_FAQ)
3726: {
1.1.1.11 root 3727: Applink ("faq", TRUE, "");
1.1.1.7 root 3728: return 1;
3729: }
3730: else if (lw == IDM_TC_DOWNLOADS)
1.1.1.5 root 3731: {
1.1.1.11 root 3732: Applink ("downloads", TRUE, "");
1.1 root 3733: return 1;
3734: }
1.1.1.7 root 3735: else if (lw == IDM_NEWS)
3736: {
1.1.1.11 root 3737: Applink ("news", TRUE, "");
1.1.1.7 root 3738: return 1;
3739: }
3740: else if (lw == IDM_VERSION_HISTORY)
1.1.1.6 root 3741: {
1.1.1.11 root 3742: Applink ("history", TRUE, "");
1.1.1.6 root 3743: return 1;
3744: }
1.1.1.7 root 3745: else if (lw == IDM_BUGREPORT)
3746: {
1.1.1.11 root 3747: Applink ("bugreport", TRUE, "");
3748: return 1;
3749: }
3750: else if (lw == IDM_DONATIONS)
3751: {
3752: Applink ("donations", FALSE, "");
1.1.1.7 root 3753: return 1;
3754: }
3755: else if (lw == IDM_CONTACT)
1.1 root 3756: {
1.1.1.11 root 3757: Applink ("contact", FALSE, "");
1.1.1.7 root 3758: return 1;
3759: }
3760:
3761: if (lw == IDM_PREFERENCES)
3762: {
3763: if (IDOK == DialogBoxParamW (hInst,
3764: MAKEINTRESOURCEW (IDD_PREFERENCES_DLG), hwndDlg,
3765: (DLGPROC) PreferencesDlgProc, (LPARAM) 0))
3766: {
3767: if (bEnableBkgTask)
1.1.1.12! root 3768: {
1.1.1.7 root 3769: TaskBarIconAdd (hwndDlg);
1.1.1.12! root 3770: }
1.1.1.7 root 3771: else
1.1.1.12! root 3772: {
1.1.1.7 root 3773: TaskBarIconRemove (hwndDlg);
1.1.1.12! root 3774: if (!IsWindowVisible (hwndDlg))
! 3775: EndMainDlg (hwndDlg);
! 3776: }
1.1.1.7 root 3777: }
3778: return 1;
3779: }
3780:
3781: if (lw == IDM_HOTKEY_SETTINGS)
3782: {
3783: DialogBoxParamW (hInst,
3784: MAKEINTRESOURCEW (IDD_HOTKEYS_DLG), hwndDlg,
3785: (DLGPROC) HotkeysDlgProc, (LPARAM) 0);
3786: return 1;
3787: }
3788:
3789: if (lw == IDM_DEFAULT_KEYFILES || lw == IDM_SET_DEFAULT_KEYFILES)
3790: {
3791: KeyfileDefaultsDlg (hwndDlg);
1.1 root 3792: return 1;
3793: }
3794:
1.1.1.7 root 3795: if (lw == IDM_BENCHMARK)
1.1.1.5 root 3796: {
3797: Benchmark (hwndDlg);
3798: return 1;
3799: }
3800:
1.1.1.6 root 3801: if (lw == IDM_TRAVELLER)
3802: {
1.1.1.7 root 3803: DialogBoxParamW (hInst,
3804: MAKEINTRESOURCEW (IDD_TRAVELLER_DLG), hwndDlg,
1.1.1.6 root 3805: (DLGPROC) TravellerDlgProc, (LPARAM) 0);
3806: return 1;
3807: }
3808:
1.1.1.7 root 3809: if (lw == IDM_BACKUP_VOL_HEADER)
3810: {
3811: if (!VolumeSelected(hwndDlg))
3812: {
3813: Warning ("NO_VOLUME_SELECTED");
3814: }
3815: else
3816: {
3817: char volPath[TC_MAX_PATH]; /* Volume to mount */
3818:
3819: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
3820:
1.1.1.11 root 3821: if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
3822: UacBackupVolumeHeader (hwndDlg, TRUE, volPath);
3823: else
3824: BackupVolumeHeader (hwndDlg, TRUE, volPath);
1.1.1.7 root 3825: }
3826: return 1;
3827: }
3828:
3829: if (lw == IDM_RESTORE_VOL_HEADER)
3830: {
3831: if (!VolumeSelected(hwndDlg))
3832: {
3833: Warning ("NO_VOLUME_SELECTED");
3834: }
3835: else
3836: {
3837: char volPath[TC_MAX_PATH]; /* Volume to mount */
3838:
3839: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
3840:
1.1.1.11 root 3841: if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
3842: UacRestoreVolumeHeader (hwndDlg, volPath);
3843: else
3844: RestoreVolumeHeader (hwndDlg, volPath);
1.1.1.7 root 3845: }
3846: return 1;
3847: }
3848:
3849: if (lw == IDM_LANGUAGE)
3850: {
3851: BOOL p;
3852: if (DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_LANGUAGE), hwndDlg,
3853: (DLGPROC) LanguageDlgProc, (LPARAM) 0) == IDOK)
3854: {
3855: LoadLanguageFile ();
3856: SaveSettings (hwndDlg);
3857:
3858: p = LocalizationActive;
3859: LocalizationActive = TRUE;
3860: InitMainDialog (hwndDlg);
3861: InvalidateRect (hwndDlg, NULL, FALSE);
3862: LocalizationActive = p;
3863: DrawMenuBar (hwndDlg);
3864: }
3865: return 1;
3866: }
3867:
3868: if (lw == IDM_TEST_VECTORS)
3869: {
3870: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_CIPHER_TEST_DLG), hwndDlg, (DLGPROC) CipherTestDialogProc, (LPARAM) 1);
3871: return 1;
3872: }
3873:
1.1.1.6 root 3874: if (lw == IDM_REFRESH_DRIVE_LETTERS)
3875: {
3876: DWORD driveMap = GetLogicalDrives ();
3877:
1.1.1.11 root 3878: WaitCursor ();
1.1.1.7 root 3879:
1.1.1.10 root 3880: if (!(nCurrentOS == WIN_2000 && RemoteSession))
3881: {
3882: BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, ~driveMap);
3883: Sleep (100);
3884: BroadcastDeviceChange (DBT_DEVICEARRIVAL, 0, driveMap);
3885: }
1.1.1.7 root 3886:
1.1.1.6 root 3887: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
1.1.1.7 root 3888:
3889: if (nSelectedDriveIndex >= 0)
3890: {
3891: SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST),
3892: (char) HIWORD (GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), nSelectedDriveIndex)));
3893: }
3894:
1.1.1.6 root 3895: NormalCursor ();
1.1.1.7 root 3896: return 1;
3897: }
3898:
3899: if (lw == IDM_MOUNT_FAVORITE_VOLUMES)
3900: {
3901: MountFavoriteVolumes ();
3902: return 1;
3903: }
3904:
3905: if (lw == IDM_SAVE_FAVORITE_VOLUMES)
3906: {
3907: SaveFavoriteVolumes ();
3908: return 1;
1.1.1.6 root 3909: }
1.1.1.5 root 3910:
1.1.1.7 root 3911: if (lw == IDC_VOLUME_PROPERTIES || lw == IDM_VOLUME_PROPERTIES)
1.1 root 3912: {
1.1.1.7 root 3913: DialogBoxParamW (hInst,
3914: MAKEINTRESOURCEW (IDD_VOLUME_PROPERTIES), hwndDlg,
1.1 root 3915: (DLGPROC) VolumePropertiesDlgProc, (LPARAM) 0);
3916: return 1;
3917: }
3918:
3919: if (lw == IDC_VOLUME && hw == CBN_EDITCHANGE)
3920: {
1.1.1.5 root 3921: EnableDisableButtons (hwndDlg);
1.1 root 3922: return 1;
3923: }
3924:
3925: if (lw == IDC_VOLUME && hw == CBN_SELCHANGE)
3926: {
3927: UpdateComboOrder (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.10 root 3928: MoveEditToCombo ((HWND) lParam, bHistory);
1.1.1.11 root 3929: PostMessage (hwndDlg, WM_APP + APPMSG_ENABLE_DISABLE, 0, 0);
1.1.1.5 root 3930: return 1;
3931: }
3932:
3933: if (lw == IDC_NO_HISTORY)
3934: {
1.1.1.11 root 3935: if (!(bHistory = !IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY))))
3936: ClearHistory (GetDlgItem (hwndDlg, IDC_VOLUME));
3937:
1.1 root 3938: return 1;
3939: }
3940:
3941: return 0;
3942:
1.1.1.6 root 3943: case WM_DROPFILES:
3944: {
3945: HDROP hdrop = (HDROP) wParam;
3946: DragQueryFile (hdrop, 0, szFileName, sizeof szFileName);
3947: DragFinish (hdrop);
3948:
1.1.1.10 root 3949: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.6 root 3950: EnableDisableButtons (hwndDlg);
3951: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
3952: }
1.1.1.7 root 3953: return 1;
1.1.1.6 root 3954:
1.1.1.11 root 3955: case WM_APP + APPMSG_ENABLE_DISABLE:
1.1 root 3956: EnableDisableButtons (hwndDlg);
3957: return 1;
3958:
1.1.1.11 root 3959: case WM_APP + APPMSG_SHOW_WINDOW:
1.1.1.8 root 3960: ShowWindow (hwndDlg, SW_SHOW);
3961: MainWindowHidden = FALSE;
3962: return 1;
3963:
3964: case WM_COPYDATA:
3965: {
3966: PCOPYDATASTRUCT cd = (PCOPYDATASTRUCT)lParam;
3967: if (memcmp (&cd->dwData, WM_COPY_SET_VOLUME_NAME, 4) == 0)
3968: {
3969: if (cd->cbData > 0)
1.1.1.10 root 3970: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), (char *)cd->lpData, bHistory);
1.1.1.8 root 3971:
3972: EnableDisableButtons (hwndDlg);
3973: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
3974: }
3975: }
3976: return 1;
3977:
1.1 root 3978: case WM_CLOSE:
3979: EndMainDlg (hwndDlg);
3980: return 1;
1.1.1.11 root 3981:
3982: default:
3983: // Recreate tray icon if Explorer restarted
3984: if (taskBarCreatedMsg != 0 && uMsg == taskBarCreatedMsg && TaskBarIconMutex != NULL)
3985: {
3986: TaskBarIconRemove (hwndDlg);
3987: TaskBarIconAdd (hwndDlg);
3988: return 1;
3989: }
1.1 root 3990: }
3991:
3992: return 0;
3993: }
3994:
3995: void
3996: ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
3997: {
3998: char **lpszCommandLineArgs; /* Array of command line arguments */
3999: int nNoCommandLineArgs; /* The number of arguments in the array */
1.1.1.7 root 4000: char tmpPath[MAX_PATH * 2];
4001:
4002: /* Defaults */
4003: mountOptions.PreserveTimestamp = TRUE;
1.1.1.11 root 4004:
4005: if (_stricmp (lpszCommandLine, "-Embedding") == 0)
4006: {
4007: ComServerMode = TRUE;
4008: return;
4009: }
1.1 root 4010:
4011: /* Extract command line arguments */
1.1.1.8 root 4012: NoCmdLineArgs = nNoCommandLineArgs = Win32CommandLine (lpszCommandLine, &lpszCommandLineArgs);
1.1.1.11 root 4013:
1.1 root 4014: if (nNoCommandLineArgs > 0)
4015: {
4016: int i;
4017:
4018: for (i = 0; i < nNoCommandLineArgs; i++)
4019: {
4020: argument args[]=
4021: {
4022: {"/auto", "/a"},
1.1.1.5 root 4023: {"/beep", "/b"},
1.1 root 4024: {"/cache", "/c"},
1.1.1.5 root 4025: {"/dismount", "/d"},
4026: {"/explore", "/e"},
4027: {"/force", "/f"},
4028: {"/help", "/?"},
1.1 root 4029: {"/history", "/h"},
1.1.1.7 root 4030: {"/keyfile", "/k"},
1.1.1.5 root 4031: {"/letter", "/l"},
1.1.1.6 root 4032: {"/mountoption", "/m"},
1.1.1.5 root 4033: {"/password", "/p"},
1.1.1.7 root 4034: {"/quit", "/q"},
4035: {"/silent", "/s"},
1.1.1.5 root 4036: {"/volume", "/v"},
4037: {"/wipecache", "/w"}
1.1 root 4038: };
4039:
4040: argumentspec as;
4041:
4042: int nArgPos;
4043: int x;
4044:
4045: as.args = args;
4046: as.arg_cnt = sizeof(args)/ sizeof(args[0]);
4047:
4048: x = GetArgumentID (&as, lpszCommandLineArgs[i], &nArgPos);
4049:
4050: switch (x)
4051: {
1.1.1.7 root 4052: case 'a':
4053: {
4054: char szTmp[32];
4055: bAuto = TRUE;
1.1.1.2 root 4056:
1.1.1.7 root 4057: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
4058: nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
4059: {
4060: if (!_stricmp (szTmp, "devices"))
4061: bAutoMountDevices = TRUE;
4062: else if (!_stricmp (szTmp, "favorites"))
4063: bAutoMountFavorites = TRUE;
4064: }
4065: }
4066: break;
1.1.1.2 root 4067:
1.1.1.7 root 4068: case 'b':
4069: bBeep = TRUE;
1.1 root 4070: break;
4071:
1.1.1.7 root 4072: case 'c':
1.1.1.2 root 4073: {
1.1.1.7 root 4074: char szTmp[8];
4075: bCacheInDriver = TRUE;
4076:
4077: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
4078: szTmp, sizeof (szTmp));
4079:
4080: if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
4081: bCacheInDriver = FALSE;
1.1.1.2 root 4082: }
1.1 root 4083: break;
4084:
1.1.1.7 root 4085: case 'd':
4086:
4087: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
4088: szDriveLetter, sizeof (szDriveLetter)))
4089: cmdUnmountDrive = toupper(szDriveLetter[0]) - 'A';
4090: else
4091: cmdUnmountDrive = -1;
4092:
1.1 root 4093: break;
4094:
4095: case 'e':
4096: bExplore = TRUE;
4097: break;
4098:
1.1.1.5 root 4099: case 'f':
4100: bForceMount = TRUE;
4101: bForceUnmount = TRUE;
4102: break;
4103:
1.1.1.7 root 4104: case 'k':
4105: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i,
4106: nNoCommandLineArgs, tmpPath, sizeof (tmpPath)))
4107: {
4108: KeyFile *kf;
4109: RelativePath2Absolute (tmpPath);
4110: kf = malloc (sizeof (KeyFile));
4111: strncpy (kf->FileName, tmpPath, sizeof (kf->FileName));
4112: FirstCmdKeyFile = KeyFileAdd (FirstCmdKeyFile, kf);
4113: }
4114: break;
4115:
4116: case 'l':
1.1.1.2 root 4117: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
1.1.1.7 root 4118: szDriveLetter, sizeof (szDriveLetter));
4119: commandLineDrive = *szDriveLetter = (char) toupper (*szDriveLetter);
1.1 root 4120: break;
4121:
1.1.1.10 root 4122: case 'h':
1.1.1.6 root 4123: {
4124: char szTmp[8];
1.1.1.7 root 4125: bHistory = bHistoryCmdLine = TRUE;
1.1.1.6 root 4126:
1.1.1.7 root 4127: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
4128: szTmp, sizeof (szTmp));
4129:
4130: if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
4131: bHistory = FALSE;
1.1.1.6 root 4132: }
4133: break;
4134:
4135: case 'm':
4136: {
1.1.1.7 root 4137: char szTmp[16];
1.1.1.6 root 4138: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
4139: nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
4140: {
1.1.1.7 root 4141: if (!_stricmp (szTmp, "ro") || !_stricmp (szTmp, "readonly"))
1.1.1.6 root 4142: mountOptions.ReadOnly = TRUE;
4143:
1.1.1.7 root 4144: if (!_stricmp (szTmp, "rm") || !_stricmp (szTmp, "removable"))
1.1.1.6 root 4145: mountOptions.Removable = TRUE;
1.1.1.7 root 4146:
4147: if (!_stricmp (szTmp, "ts") || !_stricmp (szTmp, "timestamp"))
4148: mountOptions.PreserveTimestamp = FALSE;
1.1.1.9 root 4149:
4150: if (!_stricmp (szTmp, "system"))
4151: mountOptions.SystemVolume = TRUE;
4152:
4153: if (!_stricmp (szTmp, "persistent"))
4154: mountOptions.PersistentVolume = TRUE;
1.1.1.6 root 4155: }
4156: }
1.1 root 4157: break;
4158:
1.1.1.7 root 4159: case 'p':
4160: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
4161: CmdVolumePassword.Text, sizeof (CmdVolumePassword.Text));
4162: CmdVolumePassword.Length = strlen (CmdVolumePassword.Text);
4163: CmdVolumePasswordValid = TRUE;
4164: break;
4165:
4166: case 'v':
4167: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i,
4168: nNoCommandLineArgs, szFileName, sizeof (szFileName)))
1.1 root 4169: {
1.1.1.7 root 4170: RelativePath2Absolute (szFileName);
1.1.1.10 root 4171: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.8 root 4172: CmdLineVolumeSpecified = TRUE;
1.1 root 4173: }
4174: break;
4175:
1.1.1.7 root 4176: case 'q':
1.1 root 4177: {
1.1.1.7 root 4178: char szTmp[32];
1.1 root 4179:
1.1.1.7 root 4180: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
4181: nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
1.1 root 4182: {
1.1.1.12! root 4183: if (!_stricmp (szTmp, "UAC")) // Used to indicate non-install elevation
! 4184: break;
! 4185:
1.1.1.7 root 4186: if (!_stricmp (szTmp, "preferences"))
1.1.1.12! root 4187: {
! 4188: Quit = TRUE;
1.1.1.7 root 4189: UsePreferences = TRUE;
1.1.1.12! root 4190: break;
! 4191: }
! 4192:
! 4193: if (!_stricmp (szTmp, "background"))
! 4194: bEnableBkgTask = TRUE;
1.1 root 4195: }
1.1.1.12! root 4196:
! 4197: Quit = TRUE;
! 4198: UsePreferences = FALSE;
1.1 root 4199: }
4200: break;
4201:
1.1.1.7 root 4202: case 's':
4203: Silent = TRUE;
1.1 root 4204: break;
4205:
1.1.1.7 root 4206: case 'w':
4207: bWipe = TRUE;
1.1 root 4208: break;
4209:
4210: case '?':
1.1.1.7 root 4211: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_COMMANDHELP_DLG), hwndDlg, (DLGPROC)
1.1 root 4212: CommandHelpDlgProc, (LPARAM) &as);
4213: exit(0);
4214: break;
4215:
4216: // no option = file name
4217: default:
1.1.1.2 root 4218: {
1.1.1.11 root 4219: strncpy (szFileName, lpszCommandLineArgs[i], MAX_PATH-1);
1.1.1.2 root 4220: if (szFileName[0] != '\\' && strchr (szFileName, ':') == 0)
4221: {
4222: char path[MAX_PATH*2];
4223: GetCurrentDirectory (MAX_PATH, path);
4224: strcat (path, "\\");
4225: strcat (path, szFileName);
4226: strncpy (szFileName, path, MAX_PATH-1);
4227: }
1.1.1.8 root 4228:
4229: if (nNoCommandLineArgs == 1)
4230: CmdLineVolumeSpecified = TRUE;
1.1.1.10 root 4231: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.2 root 4232: }
1.1 root 4233: }
4234: }
4235: }
4236:
4237: /* Free up the command line arguments */
4238: while (--nNoCommandLineArgs >= 0)
4239: {
4240: free (lpszCommandLineArgs[nNoCommandLineArgs]);
4241: }
4242: }
4243:
1.1.1.7 root 4244:
1.1 root 4245: int WINAPI
1.1.1.11 root 4246: WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine, int nCmdShow)
1.1 root 4247: {
4248: int status;
4249:
4250: if (nCmdShow && hPrevInstance); /* Remove unused parameter warning */
4251:
4252: atexit (localcleanup);
4253:
1.1.1.11 root 4254: InitCommonControls ();
4255: InitApp (hInstance, lpszCommandLine);
1.1 root 4256:
1.1.1.7 root 4257: RegisterRedTick(hInstance);
4258:
4259: /* Allocate, dup, then store away the application title */
4260: lpszTitle = L"TrueCrypt";
4261:
1.1 root 4262: status = DriverAttach ();
4263: if (status != 0)
4264: {
4265: if (status == ERR_OS_ERROR)
4266: handleWin32Error (NULL);
4267: else
4268: handleError (NULL, status);
4269:
1.1.1.7 root 4270: AbortProcess ("NODRIVER");
1.1 root 4271: }
4272:
1.1.1.7 root 4273: VirtualLock (&VolumePassword, sizeof (VolumePassword));
4274: VirtualLock (&CmdVolumePassword, sizeof (CmdVolumePassword));
4275: VirtualLock (&mountOptions, sizeof (mountOptions));
4276: VirtualLock (&defaultMountOptions, sizeof (defaultMountOptions));
4277:
1.1 root 4278: /* Create the main dialog box */
1.1.1.7 root 4279: DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_MOUNT_DLG), NULL, (DLGPROC) MainDialogProc,
1.1 root 4280: (LPARAM) lpszCommandLine);
4281:
4282: /* Terminate */
4283: return 0;
4284: }
1.1.1.6 root 4285:
1.1.1.7 root 4286:
4287: BOOL TaskBarIconAdd (HWND hwnd)
4288: {
4289: BOOL res;
4290: NOTIFYICONDATAW tnid;
4291:
4292: // Only one icon may be created
4293: if (TaskBarIconMutex != NULL) return TRUE;
4294:
4295: TaskBarIconMutex = CreateMutex (NULL, TRUE, "TrueCryptTaskBarIcon");
4296: if (TaskBarIconMutex == NULL || GetLastError () == ERROR_ALREADY_EXISTS)
4297: {
4298: TaskBarIconMutex = NULL;
4299: return FALSE;
4300: }
4301:
4302: tnid.cbSize = sizeof (NOTIFYICONDATAW);
4303: tnid.hWnd = hwnd;
4304: tnid.uID = IDI_TRUECRYPT_ICON;
4305: tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
1.1.1.11 root 4306: tnid.uCallbackMessage = WM_APP + APPMSG_TASKBAR_ICON;
1.1.1.12! root 4307: tnid.hIcon = LoadImage (hInst, MAKEINTRESOURCE (IDI_TRUECRYPT_ICON),
! 4308: IMAGE_ICON,
! 4309: ScreenDPI >= 120 ? 0 : 16,
! 4310: ScreenDPI >= 120 ? 0 : 16,
! 4311: (ScreenDPI >= 120 ? LR_DEFAULTSIZE : 0)
! 4312: | (nCurrentOS != WIN_2000 ? LR_DEFAULTCOLOR : LR_VGACOLOR)); // Windows 2000 cannot display more than 16 fixed colors in notification tray
! 4313:
1.1.1.7 root 4314: wcscpy (tnid.szTip, L"TrueCrypt");
4315:
4316: res = Shell_NotifyIconW (NIM_ADD, &tnid);
4317:
4318: if (tnid.hIcon)
4319: DestroyIcon (tnid.hIcon);
4320:
4321: return res;
4322: }
4323:
4324:
4325: BOOL TaskBarIconRemove (HWND hwnd)
4326: {
4327: if (TaskBarIconMutex != NULL)
4328: {
4329: NOTIFYICONDATA tnid;
4330: BOOL res;
4331:
4332: ZeroMemory (&tnid, sizeof (tnid));
4333: tnid.cbSize = sizeof(NOTIFYICONDATA);
4334: tnid.hWnd = hwnd;
4335: tnid.uID = IDI_TRUECRYPT_ICON;
4336:
4337: res = Shell_NotifyIcon (NIM_DELETE, &tnid);
4338: if (TaskBarIconMutex)
4339: {
4340: CloseHandle (TaskBarIconMutex);
4341: TaskBarIconMutex = NULL;
4342: }
4343: return res;
4344: }
4345: else
4346: return FALSE;
4347: }
4348:
4349:
4350: void DismountIdleVolumes ()
4351: {
4352: static int secCounter;
4353: static int InactivityTime[26];
4354: static unsigned __int64 LastRead[26], LastWritten[26];
4355: static int LastId[26];
4356:
4357: VOLUME_PROPERTIES_STRUCT prop;
4358: DWORD dwResult;
4359: BOOL bResult;
4360: int i;
4361:
4362: if (++secCounter % 60 != 0) return;
4363:
4364: for (i = 0; i < 26; i++)
4365: {
4366: if (LastKnownMountList.ulMountedDrives & (1 << i))
4367: {
4368: memset (&prop, 0, sizeof(prop));
4369: prop.driveNo = i;
4370:
4371: bResult = DeviceIoControl (hDriver, VOLUME_PROPERTIES, &prop,
4372: sizeof (prop), &prop, sizeof (prop), &dwResult, NULL);
4373:
4374: if (bResult)
4375: {
4376: if (LastRead[i] == prop.totalBytesRead
4377: && LastWritten[i] == prop.totalBytesWritten
4378: && LastId[i] == prop.uniqueId)
4379: {
4380: if (++InactivityTime[i] >= MaxVolumeIdleTime)
4381: {
1.1.1.11 root 4382: BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, i, 0);
4383:
1.1.1.7 root 4384: if (bCloseDismountedWindows && CloseVolumeExplorerWindows (MainDlg, i))
4385: Sleep (250);
4386:
4387: if (DriverUnmountVolume (MainDlg, i, bForceAutoDismount) == 0)
4388: {
4389: InactivityTime[i] = 0;
4390: BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, i, 0);
4391:
4392: if (bWipeCacheOnAutoDismount)
4393: DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
4394: }
4395: }
4396: }
4397: else
4398: {
4399: InactivityTime[i] = 0;
4400: LastRead[i] = prop.totalBytesRead;
4401: LastWritten[i] = prop.totalBytesWritten;
4402: LastId[i] = prop.uniqueId;
4403: }
4404: }
4405: }
4406: }
4407: }
4408:
4409:
4410: BOOL MountFavoriteVolumes ()
4411: {
4412: BOOL status = TRUE;
4413: DWORD size;
4414: char *favorites = LoadFile (GetConfigPath (FILE_FAVORITE_VOLUMES), &size);
4415: char *xml = favorites;
4416: char mountPoint[MAX_PATH], volume[MAX_PATH];
4417:
4418: if (xml == NULL) return FALSE;
4419:
1.1.1.11 root 4420: mountOptions = defaultMountOptions;
4421:
1.1.1.7 root 4422: while (xml = XmlFindElement (xml, "volume"))
4423: {
4424: int drive;
1.1.1.11 root 4425: XmlGetAttributeText (xml, "mountpoint", mountPoint, sizeof (mountPoint));
4426: XmlGetNodeText (xml, volume, sizeof (volume));
1.1.1.7 root 4427: drive = toupper (mountPoint[0]) - 'A';
4428:
4429: if ((LastKnownMountList.ulMountedDrives & (1 << drive)) == 0)
4430: {
4431: if (!Mount (MainDlg, drive, volume))
4432: status = FALSE;
4433: LoadDriveLetters (GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
4434: }
4435:
4436: xml++;
4437: }
4438:
4439: free (favorites);
4440: return status;
4441: }
4442:
4443:
4444: void SaveFavoriteVolumes ()
4445: {
4446: if (AskNoYes("CONFIRM_SAVE_FAVORITE_VOL") == IDYES)
4447: {
4448: FILE *f;
4449: int i, cnt = 0;
4450:
4451: f = fopen (GetConfigPath (FILE_FAVORITE_VOLUMES), "w");
4452: if (f == NULL)
4453: {
4454: handleWin32Error (MainDlg);
4455: return;
4456: }
4457:
4458: XmlWriteHeader (f);
4459: fputs ("\n\t<favorites>", f);
4460:
4461: for (i = 0; i < 26; i++)
4462: {
4463: if (LastKnownMountList.ulMountedDrives & (1 << i))
4464: {
1.1.1.11 root 4465: char t[2048], tq[2048];
4466:
4467: sprintf_s (t, sizeof (t), "%ls", &LastKnownMountList.wszVolume[i][(LastKnownMountList.wszVolume[i][1] == L'?') ? 4 : 0]);
4468: XmlQuoteText (t, tq, sizeof (tq));
4469:
4470: fprintf (f, "\n\t\t<volume mountpoint=\"%c:\\\">%s</volume>", i + 'A', tq);
1.1.1.7 root 4471: cnt++;
4472: }
4473: }
4474:
4475: fputs ("\n\t</favorites>", f);
4476: XmlWriteFooter (f);
4477: fclose (f);
4478:
4479: if (cnt == 0)
4480: remove (GetConfigPath (FILE_FAVORITE_VOLUMES)); // No volumes to save as favorite
4481:
4482: Info ("FAVORITE_VOLUMES_SAVED");
4483: }
4484: }
4485:
4486:
4487: static void SaveDefaultKeyFilesParam (void)
4488: {
4489: if (defaultKeyFilesParam.FirstKeyFile == NULL)
4490: {
4491: /* No keyfiles selected */
4492: remove (GetConfigPath (FILE_DEFAULT_KEYFILES));
4493: }
4494: else
4495: {
4496: FILE *f;
4497: KeyFile *kf = FirstKeyFile;
4498:
4499: f = fopen (GetConfigPath (FILE_DEFAULT_KEYFILES), "w");
4500: if (f == NULL)
4501: {
4502: handleWin32Error (MainDlg);
4503: return;
4504: }
4505:
4506: XmlWriteHeader (f);
4507:
4508: fputs ("\n\t<defaultkeyfiles>", f);
4509:
4510: while (kf != NULL)
4511: {
1.1.1.11 root 4512: char q[TC_MAX_PATH * 2];
4513:
4514: XmlQuoteText (kf->FileName, q, sizeof (q));
4515: fprintf (f, "\n\t\t<keyfile>%s</keyfile>", q);
4516:
1.1.1.7 root 4517: kf = kf->Next;
4518: }
4519:
4520: fputs ("\n\t</defaultkeyfiles>", f);
4521:
4522: XmlWriteFooter (f);
4523:
4524: fclose (f);
4525: return;
4526: }
4527: }
4528:
4529:
4530: static void KeyfileDefaultsDlg (HWND hwndDlg)
4531: {
4532: KeyFilesDlgParam param;
4533:
4534: param.EnableKeyFiles = defaultKeyFilesParam.EnableKeyFiles;
4535: param.FirstKeyFile = defaultKeyFilesParam.FirstKeyFile;
4536:
4537: if (DialogBoxParamW (hInst,
4538: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
4539: (DLGPROC) KeyFilesDlgProc, (LPARAM) ¶m) == IDOK)
4540: {
1.1.1.11 root 4541: if (!param.EnableKeyFiles || AskYesNo ("CONFIRM_SAVE_DEFAULT_KEYFILES") == IDYES)
1.1.1.7 root 4542: {
4543: KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile);
4544: defaultKeyFilesParam.EnableKeyFiles = param.EnableKeyFiles;
4545: defaultKeyFilesParam.FirstKeyFile = param.FirstKeyFile;
4546:
4547: RestoreDefaultKeyFilesParam ();
4548: SaveDefaultKeyFilesParam ();
4549: }
4550: }
4551: }
4552:
4553:
4554: static void HandleHotKey (HWND hwndDlg, WPARAM wParam)
4555: {
4556: DWORD dwResult;
4557: BOOL success = TRUE;
4558:
4559: switch (wParam)
4560: {
4561: case HK_AUTOMOUNT_DEVICES:
4562: MountAllDevices (hwndDlg, TRUE);
4563:
4564: if (bPlaySoundOnHotkeyMountDismount)
4565: MessageBeep(-1);
4566:
4567: break;
4568:
4569: case HK_DISMOUNT_ALL:
1.1.1.12! root 4570: if (DismountAll (hwndDlg, FALSE, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY) && bDisplayMsgBoxOnHotkeyDismount)
! 4571: Info ("MOUNTED_VOLUMES_DISMOUNTED");
! 4572: else if (bDisplayMsgBoxOnHotkeyDismount)
! 4573: Info ("DISMOUNT_ALL_ATTEMPT_COMPLETED");
1.1.1.7 root 4574:
1.1.1.12! root 4575: if (!bDisplayMsgBoxOnHotkeyDismount && bPlaySoundOnHotkeyMountDismount)
1.1.1.7 root 4576: MessageBeep(-1);
4577:
4578: break;
4579:
1.1.1.11 root 4580: case HK_WIPE_CACHE:
4581: WipeCache (hwndDlg);
4582: break;
4583:
1.1.1.7 root 4584: case HK_FORCE_DISMOUNT_ALL_AND_WIPE:
4585: success = DismountAll (hwndDlg, TRUE, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
4586: success &= DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
4587: if (success)
4588: {
4589: if (bPlaySoundOnHotkeyMountDismount)
4590: MessageBeep(-1);
4591:
4592: if (bDisplayMsgBoxOnHotkeyDismount)
4593: Info ("VOLUMES_DISMOUNTED_CACHE_WIPED");
4594: }
4595: break;
4596:
4597: case HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT:
4598: success = DismountAll (hwndDlg, TRUE, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
4599: success &= DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
4600: if (success)
4601: {
4602: if (bPlaySoundOnHotkeyMountDismount)
4603: MessageBeep(-1);
4604:
4605: if (bDisplayMsgBoxOnHotkeyDismount)
4606: Info ("VOLUMES_DISMOUNTED_CACHE_WIPED");
4607: }
4608: TaskBarIconRemove (hwndDlg);
4609: EndMainDlg (hwndDlg);
4610: break;
4611:
4612: case HK_MOUNT_FAVORITE_VOLUMES:
4613: MountFavoriteVolumes ();
4614:
4615: if (bPlaySoundOnHotkeyMountDismount)
4616: MessageBeep(-1);
4617:
4618: break;
4619:
4620: case HK_SHOW_HIDE_MAIN_WINDOW:
1.1.1.8 root 4621: MainWindowHidden = !IsWindowVisible (hwndDlg);
1.1.1.7 root 4622: MainWindowHidden = !MainWindowHidden;
1.1.1.8 root 4623:
4624: if (!MainWindowHidden)
4625: SetForegroundWindow (hwndDlg);
1.1.1.7 root 4626: ShowWindow (hwndDlg, !MainWindowHidden ? SW_SHOW : SW_HIDE);
4627: break;
4628: }
4629: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.