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

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

unix.superglobalmegacorp.com

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