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

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

unix.superglobalmegacorp.com

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