Annotation of truecrypt/mount/mount.c, revision 1.1.1.11

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.