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

1.1.1.11  root        1: /*
1.1.1.13! root        2:  Legal Notice: Some portions of the source code contained in this file were
        !             3:  derived from the source code of Encryption for the Masses 2.02a, which is
        !             4:  Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License
        !             5:  Agreement for Encryption for the Masses'. Modifications and additions to
        !             6:  the original source code (contained in this file) and all other portions of
        !             7:  this file are Copyright (c) 2003-2008 TrueCrypt Foundation and are governed
        !             8:  by the TrueCrypt License 2.4 the full text of which is contained in the
        !             9:  file License.txt included in TrueCrypt binary and source code distribution
1.1.1.11  root       10:  packages. */
1.1       root       11: 
1.1.1.7   root       12: #include "Tcdefs.h"
1.1.1.13! root       13: 
1.1.1.5   root       14: #include <time.h>
1.1.1.7   root       15: #include <math.h>
1.1.1.5   root       16: #include <dbt.h>
1.1.1.7   root       17: #include <windowsx.h>
1.1.1.13! root       18: 
1.1.1.7   root       19: #include "Apidrvr.h"
1.1.1.13! root       20: #include "BootEncryption.h"
1.1.1.7   root       21: #include "Cmdline.h"
                     22: #include "Crypto.h"
                     23: #include "Dlgcode.h"
                     24: #include "Combo.h"
                     25: #include "Hotkeys.h"
                     26: #include "Keyfiles.h"
                     27: #include "Language.h"
1.1.1.11  root       28: #include "MainCom.h"
1.1       root       29: #include "Mount.h"
1.1.1.7   root       30: #include "Pkcs5.h"
                     31: #include "Registry.h"
                     32: #include "Resource.h"
1.1       root       33: #include "Password.h"
1.1.1.7   root       34: #include "Xml.h"
1.1.1.13! root       35: #include "../Boot/Windows/BootCommon.h"
1.1.1.7   root       36: #include "../Common/Dictionary.h"
                     37: #include "../Common/Common.h"
                     38: #include "../Common/Resource.h"
1.1       root       39: 
1.1.1.13! root       40: using namespace TrueCrypt;
        !            41: 
        !            42: enum timer_ids
        !            43: {
        !            44:        TIMER_ID_MAIN = 0xff,
        !            45:        TIMER_ID_KEYB_LAYOUT_GUARD
        !            46: };
        !            47: 
        !            48: #define TIMER_INTERVAL_MAIN                                    500
        !            49: #define TIMER_INTERVAL_KEYB_LAYOUT_GUARD       10
        !            50: 
        !            51: BootEncryption                 *BootEncObj = NULL;
        !            52: BootEncryptionStatus   BootEncStatus;
        !            53: BootEncryptionStatus   RecentBootEncStatus;
        !            54: 
1.1       root       55: BOOL bExplore = FALSE;                         /* Display explorer window after mount */
                     56: BOOL bBeep = FALSE;                                    /* Donot beep after mount */
1.1.1.8   root       57: char szFileName[TC_MAX_PATH+1];                /* Volume to mount */
1.1       root       58: char szDriveLetter[3];                         /* Drive Letter to mount */
1.1.1.5   root       59: char commandLineDrive = 0;
1.1       root       60: BOOL bCacheInDriver = FALSE;           /* Cache any passwords we see */
1.1.1.11  root       61: BOOL bCacheInDriverDefault = FALSE;
1.1       root       62: BOOL bHistoryCmdLine = FALSE;          /* History control is always disabled */
                     63: BOOL bCloseDismountedWindows=TRUE;     /* Close all open explorer windows of dismounted volume */
                     64: BOOL bWipeCacheOnExit = FALSE;         /* Wipe password from chace on exit */
1.1.1.7   root       65: BOOL bWipeCacheOnAutoDismount = TRUE;
                     66: BOOL bEnableBkgTask = FALSE;
                     67: BOOL bCloseBkgTaskWhenNoVolumes = FALSE;
                     68: BOOL bDismountOnLogOff = TRUE;
                     69: BOOL bDismountOnScreenSaver = TRUE;
                     70: BOOL bDismountOnPowerSaving = FALSE;
                     71: BOOL bForceAutoDismount = TRUE;
1.1.1.5   root       72: BOOL bForceMount = FALSE;                      /* Mount volume even if host file/device already in use */
                     73: BOOL bForceUnmount = FALSE;                    /* Unmount volume even if it cannot be locked */
1.1       root       74: BOOL bWipe = FALSE;                                    /* Wipe driver passwords */
                     75: BOOL bAuto = FALSE;                                    /* Do everything without user input */
1.1.1.6   root       76: BOOL bAutoMountDevices = FALSE;                /* Auto-mount devices */
1.1.1.7   root       77: BOOL bAutoMountFavorites = FALSE;
                     78: BOOL bPlaySoundOnHotkeyMountDismount = TRUE;
                     79: BOOL bDisplayMsgBoxOnHotkeyDismount = FALSE;
1.1.1.13! root       80: BOOL bHibernationPreventionNotified = FALSE;   /* TRUE if the user has been notified that hibernation was prevented (system encryption) during the session. */
1.1       root       81: 
1.1.1.7   root       82: BOOL Quit = FALSE;                                     /* Exit after processing command line */
1.1.1.11  root       83: BOOL ComServerMode = FALSE;
1.1.1.7   root       84: BOOL UsePreferences = TRUE;
1.1       root       85: 
1.1.1.7   root       86: int MaxVolumeIdleTime = -120;
1.1       root       87: int nCurrentShowType = 0;                      /* current display mode, mount, unmount etc */
1.1.1.5   root       88: int nSelectedDriveIndex = -1;          /* Item number of selected drive */
1.1       root       89: 
1.1.1.7   root       90: int cmdUnmountDrive = 0;                       /* Volume drive letter to unmount (-1 = all) */
                     91: Password VolumePassword;                       /* Password used for mounting volumes */
                     92: Password CmdVolumePassword;                    /* Password passed from command line */
                     93: BOOL CmdVolumePasswordValid;
1.1.1.6   root       94: MountOptions mountOptions;
                     95: MountOptions defaultMountOptions;
1.1.1.7   root       96: KeyFile *FirstCmdKeyFile;
                     97: 
1.1.1.12  root       98: HBITMAP hbmLogoBitmapRescaled = NULL;
1.1.1.13! root       99: char OrigKeyboardLayout [8+1] = "00000409";
1.1.1.12  root      100: 
1.1.1.7   root      101: static KeyFilesDlgParam                                hidVolProtKeyFilesParam;
                    102: 
                    103: static MOUNT_LIST_STRUCT                       LastKnownMountList;
                    104: static VOLUME_NOTIFICATIONS_LIST       VolumeNotificationsList;        
                    105: static DWORD                                           LastKnownLogicalDrives;
                    106: 
                    107: static HANDLE TaskBarIconMutex = NULL;
                    108: static BOOL MainWindowHidden = FALSE;
                    109: static int pwdChangeDlgMode    = PCDM_CHANGE_PASSWORD;
1.1.1.13! root      110: static int bSysEncPwdChangeDlgMode = FALSE;
1.1.1.8   root      111: static int NoCmdLineArgs;
                    112: static BOOL CmdLineVolumeSpecified;
1.1.1.6   root      113: 
1.1.1.13! root      114: void localcleanup (void)
1.1       root      115: {
1.1.1.9   root      116:        // Wipe command line
                    117:        char *c = GetCommandLineA ();
                    118:        wchar_t *wc = GetCommandLineW ();
                    119:        burn(c, strlen (c));
                    120:        burn(wc, wcslen (wc) * sizeof (wchar_t));
                    121: 
1.1.1.12  root      122:        /* Delete buffered bitmaps (if any) */
                    123:        if (hbmLogoBitmapRescaled != NULL)
                    124:        {
                    125:                DeleteObject ((HGDIOBJ) hbmLogoBitmapRescaled);
                    126:                hbmLogoBitmapRescaled = NULL;
                    127:        }
                    128: 
1.1       root      129:        /* Cleanup common code resources */
                    130:        cleanup ();
1.1.1.13! root      131: 
        !           132:        if (BootEncObj != NULL)
        !           133:                delete BootEncObj;
1.1       root      134: }
                    135: 
1.1.1.13! root      136: void RefreshMainDlg (HWND hwndDlg)
1.1       root      137: {
                    138:        int drive = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))));
                    139: 
1.1.1.10  root      140:        MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME), bHistory);
1.1       root      141:        LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), drive);
                    142:        EnableDisableButtons (hwndDlg);
                    143: }
                    144: 
1.1.1.13! root      145: void EndMainDlg (HWND hwndDlg)
1.1       root      146: {
1.1.1.10  root      147:        MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME), bHistory);
1.1.1.7   root      148:        
                    149:        if (UsePreferences) 
                    150:                SaveSettings (hwndDlg);
1.1       root      151: 
                    152:        if (bWipeCacheOnExit)
                    153:        {
                    154:                DWORD dwResult;
1.1.1.13! root      155:                DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1       root      156:        }
                    157: 
1.1.1.10  root      158:        if (!bHistory)
                    159:        {
                    160:                SetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), "");
1.1.1.11  root      161:                ClearHistory (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.10  root      162:        }
                    163: 
1.1.1.7   root      164:        if (TaskBarIconMutex != NULL)
                    165:        {
                    166:                MainWindowHidden = TRUE;
                    167:                ShowWindow (hwndDlg, SW_HIDE);
                    168:        }
                    169:        else
                    170:        {
                    171:                TaskBarIconRemove (hwndDlg);
                    172:                EndDialog (hwndDlg, 0);
                    173:        }
1.1       root      174: }
                    175: 
1.1.1.7   root      176: static void InitMainDialog (HWND hwndDlg)
1.1       root      177: {
1.1.1.7   root      178:        MENUITEMINFOW info;
1.1.1.13! root      179:        char *popupTexts[] = {"MENU_VOLUMES", "MENU_SYSTEM_ENCRYPTION", "MENU_KEYFILES", "MENU_TOOLS", "MENU_SETTINGS", "MENU_HELP", "MENU_WEBSITE", 0};
1.1.1.7   root      180:        wchar_t *str;
                    181:        int i;
1.1       root      182: 
1.1.1.7   root      183:        /* Call the common dialog init code */
                    184:        InitDialog (hwndDlg);
                    185:        LocalizeDialog (hwndDlg, NULL);
                    186: 
                    187:        DragAcceptFiles (hwndDlg, TRUE);
1.1       root      188: 
1.1.1.7   root      189:        SendMessage (GetDlgItem (hwndDlg, IDC_VOLUME), CB_LIMITTEXT, TC_MAX_PATH, 0);
                    190:        SetWindowTextW (hwndDlg, lpszTitle);
                    191: 
                    192:        // Help file name
                    193:        InitHelpFileName();
                    194: 
                    195:        // Localize menu strings
                    196:        for (i = 40001; str = (wchar_t *)GetDictionaryValueByInt (i); i++)
1.1       root      197:        {
1.1.1.7   root      198:                info.cbSize = sizeof (info);
                    199:                info.fMask = MIIM_TYPE;
                    200:                info.fType = MFT_STRING;
                    201:                info.dwTypeData = str;
                    202:                info.cch = wcslen (str);
1.1       root      203: 
1.1.1.7   root      204:                SetMenuItemInfoW (GetMenu (hwndDlg), i, FALSE,  &info); 
1.1       root      205:        }
1.1.1.7   root      206: 
                    207:        for (i = 0; popupTexts[i] != 0; i++)
                    208:        {
                    209:                str = GetString (popupTexts[i]);
                    210: 
                    211:                info.cbSize = sizeof (info);
                    212:                info.fMask = MIIM_TYPE;
                    213: 
                    214:                if (memcmp (popupTexts[i], "MENU_WEBSITE", 6) == 0)
                    215:                        info.fType = MFT_STRING | MFT_RIGHTJUSTIFY;
                    216:                else
                    217:                        info.fType = MFT_STRING;
                    218: 
                    219:                info.dwTypeData = str;
                    220:                info.cch = wcslen (str);
                    221: 
                    222:                SetMenuItemInfoW (GetMenu (hwndDlg), i, TRUE,  &info); 
                    223:        }
                    224: 
1.1.1.12  root      225:        // Resize the logo bitmap if the user has a non-default DPI
                    226:        if (ScreenDPI != USER_DEFAULT_SCREEN_DPI)
                    227:        {
                    228:                hbmLogoBitmapRescaled = RenderBitmap (MAKEINTRESOURCE (IDB_LOGO_288DPI),
                    229:                        GetDlgItem (hwndDlg, IDC_LOGO),
                    230:                        0, 0, 0, 0, FALSE, TRUE);
                    231:        }
                    232: 
1.1.1.7   root      233:        BuildTree (GetDlgItem (hwndDlg, IDC_DRIVELIST));
                    234: 
                    235:        if (*szDriveLetter != 0)
1.1       root      236:        {
1.1.1.7   root      237:                SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST), *szDriveLetter);
1.1       root      238: 
1.1.1.7   root      239:                if(nSelectedDriveIndex > SendMessage (GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_GETITEMCOUNT, 0, 0)/2) 
                    240:                        SendMessage(GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_SCROLL, 0, 1000);
1.1       root      241:        }
                    242: 
1.1.1.7   root      243:        SendMessage (GetDlgItem (hwndDlg, IDC_NO_HISTORY), BM_SETCHECK, bHistory ? BST_UNCHECKED : BST_CHECKED, 0);
                    244:        EnableDisableButtons (hwndDlg);
                    245: }
                    246: 
1.1.1.13! root      247: void EnableDisableButtons (HWND hwndDlg)
1.1.1.7   root      248: {
                    249:        HWND hOKButton = GetDlgItem (hwndDlg, IDOK);
                    250:        WORD x;
                    251: 
                    252:        x = LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST)));
                    253: 
                    254:        EnableMenuItem (GetMenu (hwndDlg), IDM_MOUNT_VOLUME, MF_ENABLED);
                    255:        EnableMenuItem (GetMenu (hwndDlg), IDM_MOUNT_VOLUME_OPTIONS, MF_ENABLED);
                    256:        EnableMenuItem (GetMenu (hwndDlg), IDM_BACKUP_VOL_HEADER, MF_ENABLED);
                    257:        EnableMenuItem (GetMenu (hwndDlg), IDM_RESTORE_VOL_HEADER, MF_ENABLED);
                    258:        EnableMenuItem (GetMenu (hwndDlg), IDM_CHANGE_PASSWORD, MF_ENABLED);
                    259:        EnableWindow (hOKButton, TRUE);
                    260: 
1.1.1.13! root      261:        switch (x)
1.1       root      262:        {
1.1.1.13! root      263:        case TC_MLIST_ITEM_NONSYS_VOL:
        !           264:                {
        !           265:                        SetWindowTextW (hOKButton, GetString ("UNMOUNT_BUTTON"));
        !           266:                        EnableWindow (hOKButton, TRUE);
        !           267:                        EnableMenuItem (GetMenu (hwndDlg), IDM_UNMOUNT_VOLUME, MF_ENABLED);
1.1       root      268: 
1.1.1.13! root      269:                        EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), TRUE);
        !           270:                        EnableMenuItem (GetMenu (hwndDlg), IDM_VOLUME_PROPERTIES, MF_ENABLED);
        !           271:                }
        !           272:                break;
1.1       root      273: 
1.1.1.13! root      274:        case TC_MLIST_ITEM_SYS_PARTITION:
        !           275:        case TC_MLIST_ITEM_SYS_DRIVE:
        !           276:                EnableWindow (hOKButton, FALSE);
        !           277:                SetWindowTextW (hOKButton, GetString ("MOUNT_BUTTON"));
1.1       root      278:                EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), TRUE);
1.1.1.13! root      279:                EnableMenuItem (GetMenu (hwndDlg), IDM_UNMOUNT_VOLUME, MF_GRAYED);
        !           280:                break;
        !           281: 
        !           282:        case TC_MLIST_ITEM_FREE:
        !           283:        default:
1.1.1.7   root      284:                SetWindowTextW (hOKButton, GetString ("MOUNT_BUTTON"));
1.1       root      285:                EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), FALSE);
1.1.1.7   root      286:                EnableMenuItem (GetMenu (hwndDlg), IDM_VOLUME_PROPERTIES, MF_GRAYED);
1.1.1.13! root      287:                EnableMenuItem (GetMenu (hwndDlg), IDM_UNMOUNT_VOLUME, MF_GRAYED);
1.1       root      288:        }
                    289: 
                    290:        EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_CACHE), !IsPasswordCacheEmpty());
1.1.1.7   root      291:        EnableMenuItem (GetMenu (hwndDlg), IDM_WIPE_CACHE, IsPasswordCacheEmpty() ? MF_GRAYED:MF_ENABLED);
                    292:        EnableMenuItem (GetMenu (hwndDlg), IDM_CLEAR_HISTORY, IsComboEmpty (GetDlgItem (hwndDlg, IDC_VOLUME)) ? MF_GRAYED:MF_ENABLED);
1.1       root      293: }
                    294: 
1.1.1.7   root      295: BOOL VolumeSelected (HWND hwndDlg)
1.1       root      296: {
1.1.1.7   root      297:        return (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_VOLUME)) > 0);
1.1       root      298: }
                    299: 
1.1.1.13! root      300: /* Returns TRUE if the last partition/drive selected via the Select Device dialog box was the system 
        !           301: partition/drive and if it is encrypted. 
        !           302:          WARNING: This function is very fast but not always reliable (for example, if the user manually types
        !           303:          a device path before Select Device is invoked during the session; after the Select Device dialog 
        !           304:                 has been invoked at least once, the correct system device paths are cached). Therefore, it must NOT
        !           305:                 be used before performing any dangerous operations (such as header backup restore or formatting a 
        !           306:                 supposedly non-system device) -- instead use IsSystemDevicePath(path, hwndDlg, TRUE) for such 
        !           307:                 purposes. This function can be used only for preliminary GUI checks requiring very fast responses. */
        !           308: BOOL ActiveSysEncDeviceSelected (void)
        !           309: {
        !           310:        try
        !           311:        {
        !           312:                BootEncStatus = BootEncObj->GetStatus();
        !           313: 
        !           314:                if (BootEncStatus.DriveEncrypted)
        !           315:                {
        !           316:                        int retCode = 0;
        !           317: 
        !           318:                        GetWindowText (GetDlgItem (MainDlg, IDC_VOLUME), szFileName, sizeof (szFileName));
        !           319: 
        !           320:                        retCode = IsSystemDevicePath (szFileName, MainDlg, FALSE);
        !           321: 
        !           322:                        return (WholeSysDriveEncryption(FALSE) ? (retCode == 2 || retCode == 1) : (retCode == 1));
        !           323:                }
        !           324:        }
        !           325:        catch (Exception &e)
        !           326:        {
        !           327:                e.Show (MainDlg);
        !           328:        }
        !           329: 
        !           330:        return FALSE;
        !           331: }
        !           332: 
        !           333: void LoadSettings (HWND hwndDlg)
1.1       root      334: {
1.1.1.13! root      335:        LoadSysEncSettings (hwndDlg);
        !           336: 
        !           337:        // If the config file has already been loaded during this session
        !           338:        if (ConfigBuffer != NULL)
        !           339:        {
        !           340:                free (ConfigBuffer);
        !           341:                ConfigBuffer = NULL;
        !           342:        }
        !           343: 
1.1       root      344:        // Options
1.1.1.7   root      345:        bExplore =                                              ConfigReadInt ("OpenExplorerWindowAfterMount", FALSE);
                    346:        bCloseDismountedWindows =               ConfigReadInt ("CloseExplorerWindowsOnDismount", TRUE);
                    347: 
                    348:        bHistory =                                              ConfigReadInt ("SaveVolumeHistory", FALSE);
                    349: 
1.1.1.11  root      350:        bCacheInDriverDefault = bCacheInDriver = ConfigReadInt ("CachePasswords", FALSE);
1.1.1.7   root      351:        bWipeCacheOnExit =                              ConfigReadInt ("WipePasswordCacheOnExit", FALSE);
                    352:        bWipeCacheOnAutoDismount =              ConfigReadInt ("WipeCacheOnAutoDismount", TRUE);
                    353: 
                    354:        bStartOnLogon =                                 ConfigReadInt ("StartOnLogon", FALSE);
                    355:        bMountDevicesOnLogon =                  ConfigReadInt ("MountDevicesOnLogon", FALSE);
                    356:        bMountFavoritesOnLogon =                ConfigReadInt ("MountFavoritesOnLogon", FALSE);
                    357: 
                    358:        bEnableBkgTask =                                ConfigReadInt ("EnableBackgroundTask", TRUE);
                    359:        bCloseBkgTaskWhenNoVolumes =    ConfigReadInt ("CloseBackgroundTaskOnNoVolumes", FALSE);
                    360: 
                    361:        bDismountOnLogOff =                             ConfigReadInt ("DismountOnLogOff", TRUE);
1.1.1.11  root      362:        bDismountOnPowerSaving =                ConfigReadInt ("DismountOnPowerSaving", TRUE);
1.1.1.7   root      363:        bDismountOnScreenSaver =                ConfigReadInt ("DismountOnScreenSaver", FALSE);
                    364:        bForceAutoDismount =                    ConfigReadInt ("ForceAutoDismount", TRUE);
                    365:        MaxVolumeIdleTime =                             ConfigReadInt ("MaxVolumeIdleTime", -120);
                    366: 
                    367:        defaultKeyFilesParam.EnableKeyFiles = ConfigReadInt ("UseKeyfiles", FALSE);
                    368: 
                    369:        bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = ConfigReadInt ("PreserveTimestamps", TRUE);
                    370:        defaultMountOptions.Removable = ConfigReadInt ("MountVolumesRemovable", FALSE);
                    371:        defaultMountOptions.ReadOnly =  ConfigReadInt ("MountVolumesReadOnly", FALSE);
                    372:        defaultMountOptions.ProtectHiddenVolume = FALSE;
                    373: 
1.1.1.6   root      374:        mountOptions = defaultMountOptions;
1.1       root      375: 
1.1.1.5   root      376:        // Drive letter - command line arg overrides registry
                    377:        if (szDriveLetter[0] == 0)
1.1.1.7   root      378:                ConfigReadString ("LastSelectedDrive", "", szDriveLetter, sizeof (szDriveLetter));
                    379: 
                    380:        // Hotkeys
                    381:        bPlaySoundOnHotkeyMountDismount                                                                 = ConfigReadInt ("PlaySoundOnHotkeyMountDismount", TRUE);
                    382:        bDisplayMsgBoxOnHotkeyDismount                                                                  = ConfigReadInt ("DisplayMsgBoxOnHotkeyDismount", FALSE);
                    383:        Hotkeys [HK_AUTOMOUNT_DEVICES].vKeyModifiers                                    = ConfigReadInt ("HotkeyModAutoMountDevices", 0);
                    384:        Hotkeys [HK_AUTOMOUNT_DEVICES].vKeyCode                                                 = ConfigReadInt ("HotkeyCodeAutoMountDevices", 0);
                    385:        Hotkeys [HK_DISMOUNT_ALL].vKeyModifiers                                                 = ConfigReadInt ("HotkeyModDismountAll", 0);
                    386:        Hotkeys [HK_DISMOUNT_ALL].vKeyCode                                                              = ConfigReadInt ("HotkeyCodeDismountAll", 0);
1.1.1.11  root      387:        Hotkeys [HK_WIPE_CACHE].vKeyModifiers                                                   = ConfigReadInt ("HotkeyModWipeCache", 0);
                    388:        Hotkeys [HK_WIPE_CACHE].vKeyCode                                                                = ConfigReadInt ("HotkeyCodeWipeCache", 0);
1.1.1.7   root      389:        Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyModifiers                  = ConfigReadInt ("HotkeyModForceDismountAllWipe", 0);
                    390:        Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyCode                               = ConfigReadInt ("HotkeyCodeForceDismountAllWipe", 0);
                    391:        Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyModifiers = ConfigReadInt ("HotkeyModForceDismountAllWipeExit", 0);
                    392:        Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyCode              = ConfigReadInt ("HotkeyCodeForceDismountAllWipeExit", 0);
                    393:        Hotkeys [HK_MOUNT_FAVORITE_VOLUMES].vKeyModifiers                               = ConfigReadInt ("HotkeyModMountFavoriteVolumes", 0);
                    394:        Hotkeys [HK_MOUNT_FAVORITE_VOLUMES].vKeyCode                                    = ConfigReadInt ("HotkeyCodeMountFavoriteVolumes", 0);
                    395:        Hotkeys [HK_SHOW_HIDE_MAIN_WINDOW].vKeyModifiers                                = ConfigReadInt ("HotkeyModShowHideMainWindow", 0);
                    396:        Hotkeys [HK_SHOW_HIDE_MAIN_WINDOW].vKeyCode                                             = ConfigReadInt ("HotkeyCodeShowHideMainWindow", 0);
1.1       root      397: 
                    398:        // History
                    399:        if (bHistoryCmdLine != TRUE)
1.1.1.10  root      400:        {
1.1.1.7   root      401:                LoadCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.10  root      402:                if (CmdLineVolumeSpecified)
                    403:                        SetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
                    404:        }
1.1       root      405: }
                    406: 
1.1.1.13! root      407: void SaveSettings (HWND hwndDlg)
1.1       root      408: {
1.1.1.13! root      409:        WaitCursor ();
        !           410: 
1.1       root      411:        char szTmp[32] = {0};
                    412:        LPARAM lLetter;
                    413: 
                    414:        // Options
1.1.1.7   root      415:        ConfigWriteBegin ();
                    416: 
                    417:        ConfigWriteInt ("OpenExplorerWindowAfterMount",         bExplore);
                    418:        ConfigWriteInt ("CloseExplorerWindowsOnDismount",       bCloseDismountedWindows);
                    419:        ConfigWriteInt ("SaveVolumeHistory",                            !IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY)));
                    420: 
1.1.1.11  root      421:        ConfigWriteInt ("CachePasswords",                                       bCacheInDriverDefault);
1.1.1.7   root      422:        ConfigWriteInt ("WipePasswordCacheOnExit",                      bWipeCacheOnExit);
                    423:        ConfigWriteInt ("WipeCacheOnAutoDismount",                      bWipeCacheOnAutoDismount);
                    424: 
                    425:        ConfigWriteInt ("StartOnLogon",                                         bStartOnLogon);
                    426:        ConfigWriteInt ("MountDevicesOnLogon",                          bMountDevicesOnLogon);
                    427:        ConfigWriteInt ("MountFavoritesOnLogon",                        bMountFavoritesOnLogon);
                    428: 
                    429:        ConfigWriteInt ("MountVolumesReadOnly",                         defaultMountOptions.ReadOnly);
                    430:        ConfigWriteInt ("MountVolumesRemovable",                        defaultMountOptions.Removable);
                    431:        ConfigWriteInt ("PreserveTimestamps",                           defaultMountOptions.PreserveTimestamp);
                    432: 
                    433:        ConfigWriteInt ("EnableBackgroundTask",                         bEnableBkgTask);
                    434:        ConfigWriteInt ("CloseBackgroundTaskOnNoVolumes",       bCloseBkgTaskWhenNoVolumes);
                    435: 
                    436:        ConfigWriteInt ("DismountOnLogOff",                                     bDismountOnLogOff);
                    437:        ConfigWriteInt ("DismountOnPowerSaving",                        bDismountOnPowerSaving);
                    438:        ConfigWriteInt ("DismountOnScreenSaver",                        bDismountOnScreenSaver);
                    439:        ConfigWriteInt ("ForceAutoDismount",                            bForceAutoDismount);
                    440:        ConfigWriteInt ("MaxVolumeIdleTime",                            MaxVolumeIdleTime);
                    441: 
                    442:        ConfigWriteInt ("UseKeyfiles",                                          defaultKeyFilesParam.EnableKeyFiles);
1.1       root      443: 
                    444:        // Drive Letter
                    445:        lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
                    446:        if (LOWORD (lLetter) != 0xffff)
                    447:                sprintf (szTmp, "%c:", (char) HIWORD (lLetter));
1.1.1.7   root      448:        ConfigWriteString ("LastSelectedDrive", szTmp);
                    449: 
                    450:        // Hotkeys
                    451:        ConfigWriteInt ("HotkeyModAutoMountDevices",                            Hotkeys[HK_AUTOMOUNT_DEVICES].vKeyModifiers);
                    452:        ConfigWriteInt ("HotkeyCodeAutoMountDevices",                           Hotkeys[HK_AUTOMOUNT_DEVICES].vKeyCode);
                    453:        ConfigWriteInt ("HotkeyModDismountAll",                                         Hotkeys[HK_DISMOUNT_ALL].vKeyModifiers);
                    454:        ConfigWriteInt ("HotkeyCodeDismountAll",                                        Hotkeys[HK_DISMOUNT_ALL].vKeyCode);
1.1.1.11  root      455:        ConfigWriteInt ("HotkeyModWipeCache",                                           Hotkeys[HK_WIPE_CACHE].vKeyModifiers);
                    456:        ConfigWriteInt ("HotkeyCodeWipeCache",                                          Hotkeys[HK_WIPE_CACHE].vKeyCode);
1.1.1.7   root      457:        ConfigWriteInt ("HotkeyModForceDismountAllWipe",                        Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyModifiers);
                    458:        ConfigWriteInt ("HotkeyCodeForceDismountAllWipe",                       Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyCode);
                    459:        ConfigWriteInt ("HotkeyModForceDismountAllWipeExit",            Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyModifiers);
                    460:        ConfigWriteInt ("HotkeyCodeForceDismountAllWipeExit",           Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyCode);
                    461:        ConfigWriteInt ("HotkeyModMountFavoriteVolumes",                        Hotkeys[HK_MOUNT_FAVORITE_VOLUMES].vKeyModifiers);
                    462:        ConfigWriteInt ("HotkeyCodeMountFavoriteVolumes",                       Hotkeys[HK_MOUNT_FAVORITE_VOLUMES].vKeyCode);
                    463:        ConfigWriteInt ("HotkeyModShowHideMainWindow",                          Hotkeys[HK_SHOW_HIDE_MAIN_WINDOW].vKeyModifiers);
                    464:        ConfigWriteInt ("HotkeyCodeShowHideMainWindow",                         Hotkeys[HK_SHOW_HIDE_MAIN_WINDOW].vKeyCode);
                    465:        ConfigWriteInt ("PlaySoundOnHotkeyMountDismount",                       bPlaySoundOnHotkeyMountDismount);
                    466:        ConfigWriteInt ("DisplayMsgBoxOnHotkeyDismount",                        bDisplayMsgBoxOnHotkeyDismount);
                    467: 
                    468:        // Language
                    469:        if (GetPreferredLangId () != NULL)
                    470:                ConfigWriteString ("Language", GetPreferredLangId ());
                    471: 
                    472:        ConfigWriteEnd ();
1.1       root      473: 
                    474:        // History
1.1.1.7   root      475:        DumpCombo (GetDlgItem (hwndDlg, IDC_VOLUME), IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY)));
1.1.1.13! root      476: 
        !           477:        NormalCursor ();
        !           478: }
        !           479: 
        !           480: // Returns TRUE if system encryption or decryption had been or is in progress and has not been completed
        !           481: static BOOL SysEncryptionOrDecryptionRequired (void)
        !           482: {
        !           483:        /* If you update this function, revise SysEncryptionOrDecryptionRequired() in Tcformat.c as well. */
        !           484: 
        !           485:        try
        !           486:        {
        !           487:                BootEncStatus = BootEncObj->GetStatus();
        !           488:        }
        !           489:        catch (Exception &e)
        !           490:        {
        !           491:                e.Show (MainDlg);
        !           492:        }
        !           493: 
        !           494:        return (SystemEncryptionStatus == SYSENC_STATUS_ENCRYPTING
        !           495:                || SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING
        !           496:                || 
        !           497:                (
        !           498:                        BootEncStatus.DriveMounted 
        !           499:                        && 
        !           500:                        (
        !           501:                                BootEncStatus.ConfiguredEncryptedAreaStart != BootEncStatus.EncryptedAreaStart
        !           502:                                || BootEncStatus.ConfiguredEncryptedAreaEnd != BootEncStatus.EncryptedAreaEnd
        !           503:                        )
        !           504:                )
        !           505:        );
        !           506: }
        !           507: 
        !           508: // Returns TRUE if the system partition/drive is completely encrypted
        !           509: static BOOL SysDriveOrPartitionFullyEncrypted (BOOL bSilent)
        !           510: {
        !           511:        /* If you update this function, revise SysDriveOrPartitionFullyEncrypted() in Tcformat.c as well. */
        !           512: 
        !           513:        try
        !           514:        {
        !           515:                BootEncStatus = BootEncObj->GetStatus();
        !           516:        }
        !           517:        catch (Exception &e)
        !           518:        {
        !           519:                if (!bSilent)
        !           520:                        e.Show (MainDlg);
        !           521:        }
        !           522: 
        !           523:        return (!BootEncStatus.SetupInProgress
        !           524:                && BootEncStatus.ConfiguredEncryptedAreaEnd != 0
        !           525:                && BootEncStatus.ConfiguredEncryptedAreaEnd != -1
        !           526:                && BootEncStatus.ConfiguredEncryptedAreaStart == BootEncStatus.EncryptedAreaStart
        !           527:                && BootEncStatus.ConfiguredEncryptedAreaEnd == BootEncStatus.EncryptedAreaEnd);
        !           528: }
        !           529: 
        !           530: // Returns TRUE if the system partition/drive is being filtered by the TrueCrypt driver and the key data
        !           531: // was successfully decrypted (the device is fully ready to be encrypted or decrypted). Note that this
        !           532: // function does not examine whether the system device is encrypted or not (or to what extent).
        !           533: static BOOL SysEncDeviceActive (BOOL bSilent)
        !           534: {
        !           535:        try
        !           536:        {
        !           537:                BootEncStatus = BootEncObj->GetStatus();
        !           538:        }
        !           539:        catch (Exception &e)
        !           540:        {
        !           541:                if (!bSilent)
        !           542:                        e.Show (MainDlg);
        !           543: 
        !           544:                return FALSE;
        !           545:        }
        !           546: 
        !           547:        return (BootEncStatus.DriveMounted);
        !           548: }
        !           549: 
        !           550: // Returns TRUE if the entire system drive (as opposed to the system partition only) is (or is to be) encrypted
        !           551: BOOL WholeSysDriveEncryption (BOOL bSilent)
        !           552: {
        !           553:        try
        !           554:        {
        !           555:                BootEncStatus = BootEncObj->GetStatus();
        !           556: 
        !           557:                return (BootEncStatus.ConfiguredEncryptedAreaStart == TC_BOOT_LOADER_AREA_SIZE
        !           558:                        && BootEncStatus.ConfiguredEncryptedAreaEnd >= BootEncStatus.BootDriveLength.QuadPart - 1);
        !           559:        }
        !           560:        catch (Exception &e)
        !           561:        {
        !           562:                if (!bSilent)
        !           563:                        e.Show (MainDlg);
        !           564: 
        !           565:                return FALSE;
        !           566:        }
        !           567: }
        !           568: 
        !           569: // Returns the size of the system drive/partition (if encrypted) in bytes
        !           570: unsigned __int64 GetSysEncDeviceSize (BOOL bSilent)
        !           571: {
        !           572:        try
        !           573:        {
        !           574:                BootEncStatus = BootEncObj->GetStatus();
        !           575:        }
        !           576:        catch (Exception &e)
        !           577:        {
        !           578:                if (!bSilent)
        !           579:                        e.Show (MainDlg);
        !           580:        }
        !           581: 
        !           582:        return (BootEncStatus.ConfiguredEncryptedAreaEnd - BootEncStatus.ConfiguredEncryptedAreaStart + 1);
        !           583: }
        !           584: 
        !           585: // Returns the current size of the encrypted area of the system drive/partition in bytes
        !           586: unsigned __int64 GetSysEncDeviceEncryptedPartSize (BOOL bSilent)
        !           587: {
        !           588:        try
        !           589:        {
        !           590:                BootEncStatus = BootEncObj->GetStatus();
        !           591:        }
        !           592:        catch (Exception &e)
        !           593:        {
        !           594:                if (!bSilent)
        !           595:                        e.Show (MainDlg);
        !           596:        }
        !           597: 
        !           598:        return (BootEncStatus.EncryptedAreaEnd - BootEncStatus.EncryptedAreaStart + 1);
        !           599: }
        !           600: 
        !           601: 
        !           602: static void PopulateSysEncContextMenu (HMENU popup, BOOL bToolsOnly)
        !           603: {
        !           604:        try
        !           605:        {
        !           606:                BootEncStatus = BootEncObj->GetStatus();
        !           607:        }
        !           608:        catch (Exception &e)
        !           609:        {
        !           610:                e.Show (MainDlg);
        !           611:        }
        !           612: 
        !           613:        if (!bToolsOnly)
        !           614:        {
        !           615:                if (SysEncryptionOrDecryptionRequired ())
        !           616:                {
        !           617:                        if (!BootEncStatus.SetupInProgress)
        !           618:                                AppendMenuW (popup, MF_STRING, IDM_SYSENC_RESUME, GetString ("IDM_SYSENC_RESUME"));
        !           619: 
        !           620:                        if (SystemEncryptionStatus != SYSENC_STATUS_DECRYPTING)
        !           621:                                AppendMenuW (popup, MF_STRING, IDM_PERMANENTLY_DECRYPT_SYS, GetString ("PERMANENTLY_DECRYPT"));
        !           622:                        else
        !           623:                                AppendMenuW (popup, MF_STRING, IDM_ENCRYPT_SYSTEM_DEVICE, GetString ("ENCRYPT"));
        !           624: 
        !           625:                        AppendMenu (popup, MF_SEPARATOR, 0, NULL);
        !           626:                }
        !           627:        }
        !           628: 
        !           629:        AppendMenuW (popup, MF_STRING, IDM_CHANGE_SYS_PASSWORD, GetString ("IDM_CHANGE_SYS_PASSWORD"));
        !           630:        AppendMenuW (popup, MF_STRING, IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO"));
        !           631:        AppendMenu (popup, MF_SEPARATOR, 0, NULL);
        !           632:        AppendMenuW (popup, MF_STRING, IDM_CREATE_RESCUE_DISK, GetString ("IDM_CREATE_RESCUE_DISK"));
        !           633:        AppendMenuW (popup, MF_STRING, IDM_VERIFY_RESCUE_DISK, GetString ("IDM_VERIFY_RESCUE_DISK"));
        !           634:        if (!bToolsOnly)
        !           635:        {
        !           636:                if (SysDriveOrPartitionFullyEncrypted (FALSE))
        !           637:                {
        !           638:                        AppendMenu (popup, MF_SEPARATOR, 0, NULL);
        !           639:                        AppendMenuW (popup, MF_STRING, IDM_PERMANENTLY_DECRYPT_SYS, GetString ("PERMANENTLY_DECRYPT"));
        !           640:                }
        !           641:                AppendMenu (popup, MF_SEPARATOR, 0, NULL);
        !           642:                AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES"));
        !           643:        }
1.1       root      644: }
                    645: 
1.1.1.13! root      646: 
        !           647: BOOL SelectItem (HWND hTree, char nLetter)
1.1       root      648: {
                    649:        int i;
                    650:        LVITEM item;
                    651:        
                    652:        for (i = 0; i < ListView_GetItemCount(hTree); i++)
                    653:        {
                    654:                memset(&item, 0, sizeof(LVITEM));
                    655:                item.mask = LVIF_PARAM;
                    656:                item.iItem = i;
                    657: 
                    658:                if (ListView_GetItem (hTree, &item) == FALSE)
                    659:                        return FALSE;
                    660:                else
                    661:                {
                    662:                        if (HIWORD (item.lParam) == nLetter)
                    663:                        {
                    664:                                memset(&item, 0, sizeof(LVITEM));
                    665:                                item.state = LVIS_FOCUSED|LVIS_SELECTED;
                    666:                                item.stateMask = LVIS_FOCUSED|LVIS_SELECTED;
                    667:                                item.mask = LVIF_STATE;
                    668:                                item.iItem = i;
                    669:                                SendMessage(hTree, LVM_SETITEMSTATE, i, (LPARAM) &item);
                    670:                                return TRUE;
                    671:                        }
                    672:                }
                    673:        }
                    674: 
                    675:        return TRUE;
                    676: }
                    677: 
                    678: 
1.1.1.13! root      679: static void LaunchVolCreationWizard (HWND hwndDlg, const char *arg)
        !           680: {
        !           681:        char t[TC_MAX_PATH] = {'"',0};
        !           682:        char *tmp;
        !           683: 
        !           684:        GetModuleFileName (NULL, t+1, sizeof(t)-1);
        !           685: 
        !           686:        tmp = strrchr (t, '\\');
        !           687:        if (tmp)
        !           688:        {
        !           689:                STARTUPINFO si;
        !           690:                PROCESS_INFORMATION pi;
        !           691:                ZeroMemory (&si, sizeof (si));
        !           692: 
        !           693:                strcpy (++tmp, "TrueCrypt Format.exe\"");
        !           694: 
        !           695:                if (!FileExists(t))
        !           696:                        Error ("VOL_CREATION_WIZARD_NOT_FOUND");        // Display a user-friendly error message and advise what to do
        !           697: 
        !           698:                if (strlen (arg) > 0)
        !           699:                {
        !           700:                        strcat (t, " ");
        !           701:                        strcat (t, arg);
        !           702:                }
        !           703: 
        !           704:                if (!CreateProcess (NULL, (LPSTR) t, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi))
        !           705:                {
        !           706:                        handleWin32Error (hwndDlg);
        !           707:                }
        !           708:                else
        !           709:                {
        !           710:                        CloseHandle (pi.hProcess);
        !           711:                        CloseHandle (pi.hThread);
        !           712:                }
        !           713:        }
        !           714: }
        !           715: 
        !           716: 
1.1       root      717: // Fills drive list
                    718: // drive>0 = update only the corresponding drive subitems
1.1.1.13! root      719: void LoadDriveLetters (HWND hTree, int drive)
1.1       root      720: {
                    721:        char *szDriveLetters[]=
                    722:        {"A:", "B:", "C:", "D:",
                    723:         "E:", "F:", "G:", "H:", "I:", "J:", "K:",
                    724:         "L:", "M:", "N:", "O:", "P:", "Q:", "R:",
                    725:         "S:", "T:", "U:", "V:", "W:", "X:", "Y:",
                    726:         "Z:"};
                    727: 
                    728:        DWORD dwResult;
                    729:        BOOL bResult;   
                    730:        DWORD dwUsedDrives;
                    731:        MOUNT_LIST_STRUCT driver;
1.1.1.13! root      732:        VOLUME_PROPERTIES_STRUCT propSysEnc;
        !           733:        char sysDriveLetter = 0;
        !           734: 
        !           735:        BOOL bSysEnc = FALSE;
        !           736:        BOOL bWholeSysDriveEncryption = FALSE;
1.1       root      737: 
                    738:        LVITEM listItem;
                    739:        int item = 0;
                    740:        char i;
                    741: 
1.1.1.13! root      742:        try
        !           743:        {
        !           744:                BootEncStatus = BootEncObj->GetStatus();
        !           745:                if (bSysEnc = BootEncStatus.DriveMounted)
        !           746:                {
        !           747:                        BootEncObj->GetVolumeProperties (&propSysEnc);
        !           748:                }
        !           749:        }
        !           750:        catch (...)
        !           751:        {
        !           752:                bSysEnc = FALSE;
        !           753:        }
        !           754: 
1.1.1.7   root      755:        ZeroMemory (&driver, sizeof (driver));
1.1.1.13! root      756:        bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &driver,
1.1       root      757:                sizeof (driver), &driver, sizeof (driver), &dwResult,
                    758:                NULL);
1.1.1.7   root      759:        memcpy (&LastKnownMountList, &driver, sizeof (driver));
1.1       root      760: 
                    761:        if (bResult == FALSE)
                    762:        {
                    763:                handleWin32Error (hTree);
                    764:                driver.ulMountedDrives = 0;
                    765:        }
                    766: 
1.1.1.7   root      767:        LastKnownLogicalDrives = dwUsedDrives = GetLogicalDrives ();
                    768:        if (dwUsedDrives == 0)
                    769:                        Warning ("DRIVELETTERS");
1.1       root      770: 
                    771:        if(drive == 0)
                    772:                ListView_DeleteAllItems(hTree);
                    773: 
1.1.1.13! root      774:        if (bSysEnc)
1.1       root      775:        {
1.1.1.13! root      776:                bWholeSysDriveEncryption = WholeSysDriveEncryption (TRUE);
        !           777: 
        !           778:                sysDriveLetter = GetSystemDriveLetter ();
        !           779:        }
        !           780: 
        !           781:        /* System drive */
        !           782: 
        !           783:        if (bWholeSysDriveEncryption)
        !           784:        {
        !           785:                i = ENC_SYSDRIVE_PSEUDO_DRIVE_LETTER;
1.1       root      786:                int curDrive = 0;
                    787: 
1.1.1.13! root      788:                if (drive > 0)
1.1       root      789:                {
                    790:                        LVITEM tmp;
                    791:                        memset(&tmp, 0, sizeof(LVITEM));
                    792:                        tmp.mask = LVIF_PARAM;
                    793:                        tmp.iItem = item;
1.1.1.7   root      794:                        if (ListView_GetItem (hTree, &tmp))
1.1       root      795:                                curDrive = HIWORD(tmp.lParam);
                    796:                }
                    797: 
                    798:                {
1.1.1.7   root      799:                        char szTmp[1024];
                    800:                        wchar_t szTmpW[1024];
1.1       root      801: 
                    802:                        memset(&listItem, 0, sizeof(listItem));
                    803: 
                    804:                        listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
1.1.1.13! root      805:                        listItem.iImage = 2;
1.1       root      806:                        listItem.iItem = item++;  
                    807: 
1.1.1.13! root      808:                        listItem.pszText = szTmp;
        !           809:                        strcpy (szTmp, " ");
1.1       root      810: 
1.1.1.13! root      811:                        listItem.lParam = MAKELONG (TC_MLIST_ITEM_SYS_DRIVE, ENC_SYSDRIVE_PSEUDO_DRIVE_LETTER); 
1.1       root      812: 
                    813:                        if(drive == 0) 
                    814:                                ListView_InsertItem (hTree, &listItem);
                    815:                        else
                    816:                                ListView_SetItem (hTree, &listItem);
                    817: 
                    818:                        listItem.mask=LVIF_TEXT;   
                    819: 
1.1.1.13! root      820:                        // Fully encrypted
        !           821:                        if (SysDriveOrPartitionFullyEncrypted (TRUE))
        !           822:                        {
        !           823:                                wcscpy (szTmpW, GetString ("SYSTEM_DRIVE"));
        !           824:                        }
        !           825:                        else
        !           826:                        {
        !           827:                                // Partially encrypted
        !           828: 
        !           829:                                if (BootEncStatus.SetupInProgress)
        !           830:                                {
        !           831:                                        // Currently encrypting/decrypting
        !           832: 
        !           833:                                        if (BootEncStatus.SetupMode != SetupDecryption)
        !           834:                                        {
        !           835:                                                _snwprintf (szTmpW, 
        !           836:                                                        sizeof szTmpW/2,
        !           837:                                                        GetString ("SYSTEM_DRIVE_ENCRYPTING"),
        !           838:                                                        (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
        !           839:                                        }
        !           840:                                        else
        !           841:                                        {
        !           842:                                                _snwprintf (szTmpW, 
        !           843:                                                        sizeof szTmpW/2,
        !           844:                                                        GetString ("SYSTEM_DRIVE_DECRYPTING"),
        !           845:                                                        100.0 - ((double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0));
        !           846:                                        }
        !           847:                                }
        !           848:                                else
        !           849:                                {
        !           850:                                        _snwprintf (szTmpW, 
        !           851:                                                sizeof szTmpW/2,
        !           852:                                                GetString ("SYSTEM_DRIVE_PARTIALLY_ENCRYPTED"),
        !           853:                                                (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
        !           854:                                }
        !           855:                        }
        !           856:                         
        !           857:                        ListSubItemSetW (hTree, listItem.iItem, 1, szTmpW);
1.1       root      858: 
1.1.1.13! root      859:                        GetSizeString (GetSysEncDeviceSize(TRUE), szTmpW);
1.1.1.7   root      860:                        ListSubItemSetW (hTree, listItem.iItem, 2, szTmpW);
1.1       root      861: 
1.1.1.13! root      862:                        EAGetName (szTmp, propSysEnc.ea);
1.1       root      863:                        listItem.iSubItem = 3;
1.1.1.5   root      864:                        ListView_SetItem (hTree, &listItem);
1.1       root      865: 
1.1.1.13! root      866:                        ListSubItemSetW (hTree, listItem.iItem, 4, GetString ("SYSTEM_VOLUME_TYPE_ADJECTIVE"));
        !           867: 
        !           868:                        //if (driver.volumeType[i] == PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED)  // Normal/outer volume (hidden volume protected AND write denied)
        !           869:                        //{                             
        !           870:                        //      if (!VolumeNotificationsList.bHidVolDamagePrevReported[i])
        !           871:                        //      {
        !           872:                        //              wchar_t szTmp[4096];
        !           873: 
        !           874:                        //              VolumeNotificationsList.bHidVolDamagePrevReported[i] = TRUE;
        !           875:                        //              swprintf (szTmp, GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), i+'A');
        !           876:                        //              SetForegroundWindow (GetParent(hTree));
        !           877:                        //              MessageBoxW (GetParent(hTree), szTmp, lpszTitle, MB_ICONWARNING);
        !           878:                        //      }
        !           879:                        //}
        !           880:                        //else
1.1.1.7   root      881:                        {
1.1.1.13! root      882:                                VolumeNotificationsList.bHidVolDamagePrevReported[i] = FALSE;
1.1.1.7   root      883:                        }
1.1.1.13! root      884:                }
        !           885:        }
        !           886: 
        !           887:        /* Drive letters */
        !           888: 
        !           889:        for (i = 2; i < 26; i++)
        !           890:        {
        !           891:                int curDrive = 0;
        !           892: 
        !           893:                BOOL bSysEncPartition = (bSysEnc && !bWholeSysDriveEncryption && sysDriveLetter == *((char *) szDriveLetters[i]));
        !           894: 
        !           895:                if (drive > 0)
        !           896:                {
        !           897:                        LVITEM tmp;
        !           898:                        memset(&tmp, 0, sizeof(LVITEM));
        !           899:                        tmp.mask = LVIF_PARAM;
        !           900:                        tmp.iItem = item;
        !           901:                        if (ListView_GetItem (hTree, &tmp))
        !           902:                                curDrive = HIWORD(tmp.lParam);
        !           903:                }
        !           904: 
        !           905:                if (driver.ulMountedDrives & (1 << i)
        !           906:                        || bSysEncPartition)
        !           907:                {
        !           908:                        char szTmp[1024];
        !           909:                        wchar_t szTmpW[1024];
        !           910:                        wchar_t *ws;
        !           911: 
        !           912:                        memset(&listItem, 0, sizeof(listItem));
        !           913: 
        !           914:                        listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
        !           915:                        listItem.iImage = bSysEncPartition ? 2 : 1;
        !           916:                        listItem.iItem = item++;  
        !           917: 
        !           918:                        if (drive > 0 && drive != curDrive)
        !           919:                                continue;
        !           920: 
        !           921:                        listItem.lParam = MAKELONG (
        !           922:                                bSysEncPartition ? TC_MLIST_ITEM_SYS_PARTITION : TC_MLIST_ITEM_NONSYS_VOL, 
        !           923:                                i + 'A');
        !           924: 
        !           925:                        listItem.pszText = szDriveLetters[i];
        !           926:                        
        !           927:                        if (drive == 0) 
        !           928:                                ListView_InsertItem (hTree, &listItem);
        !           929:                        else
        !           930:                                ListView_SetItem (hTree, &listItem);
        !           931: 
        !           932:                        listItem.mask=LVIF_TEXT;   
        !           933:                        listItem.pszText = szTmp;
1.1.1.7   root      934: 
1.1.1.13! root      935:                        if (bSysEncPartition)
        !           936:                        {
        !           937:                                // Fully encrypted
        !           938:                                if (SysDriveOrPartitionFullyEncrypted (TRUE))
1.1.1.7   root      939:                                {
1.1.1.13! root      940:                                        wcscpy (szTmpW, GetString ("SYSTEM_PARTITION"));
        !           941:                                }
        !           942:                                else
        !           943:                                {
        !           944:                                        // Partially encrypted
1.1.1.7   root      945: 
1.1.1.13! root      946:                                        if (BootEncStatus.SetupInProgress)
        !           947:                                        {
        !           948:                                                // Currently encrypting/decrypting
        !           949: 
        !           950:                                                if (BootEncStatus.SetupMode != SetupDecryption)
        !           951:                                                {
        !           952:                                                        _snwprintf (szTmpW, 
        !           953:                                                                sizeof szTmpW/2,
        !           954:                                                                GetString ("SYSTEM_PARTITION_ENCRYPTING"),
        !           955:                                                                (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
        !           956:                                                }
        !           957:                                                else
        !           958:                                                {
        !           959:                                                        _snwprintf (szTmpW, 
        !           960:                                                                sizeof szTmpW/2,
        !           961:                                                                GetString ("SYSTEM_PARTITION_DECRYPTING"),
        !           962:                                                                100.0 - ((double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0));
        !           963:                                                }
        !           964:                                        }
        !           965:                                        else
        !           966:                                        {
        !           967:                                                _snwprintf (szTmpW, 
        !           968:                                                        sizeof szTmpW/2,
        !           969:                                                        GetString ("SYSTEM_PARTITION_PARTIALLY_ENCRYPTED"),
        !           970:                                                        (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
        !           971:                                        }
1.1.1.7   root      972:                                }
1.1.1.13! root      973: 
        !           974:                                ListSubItemSetW (hTree, listItem.iItem, 1, szTmpW);
1.1.1.7   root      975:                        }
1.1.1.5   root      976:                        else
1.1.1.7   root      977:                        {
1.1.1.13! root      978:                                ToSBCS ((LPWSTR) driver.wszVolume[i]);
        !           979: 
        !           980:                                if (memcmp (driver.wszVolume[i], "\\Device", 7) == 0)
        !           981:                                        sprintf (szTmp, "%s", ((char *) driver.wszVolume[i]));
        !           982:                                else
        !           983:                                        sprintf (szTmp, "%s", ((char *) driver.wszVolume[i]) + 4);
        !           984: 
        !           985:                                listItem.iSubItem = 1;
        !           986:                                ListView_SetItem (hTree, &listItem);
        !           987:                        }
        !           988: 
        !           989:                        GetSizeString (bSysEncPartition ? GetSysEncDeviceSize(TRUE) : driver.diskLength[i], szTmpW);
        !           990:                        ListSubItemSetW (hTree, listItem.iItem, 2, szTmpW);
        !           991: 
        !           992:                        EAGetName (szTmp, bSysEncPartition ? propSysEnc.ea : driver.ea[i]);
        !           993:                        listItem.iSubItem = 3;
        !           994:                        ListView_SetItem (hTree, &listItem);
        !           995: 
        !           996:                        if (bSysEncPartition)
        !           997:                        {
        !           998:                                ws = GetString ("SYSTEM_VOLUME_TYPE_ADJECTIVE");
1.1.1.7   root      999:                                VolumeNotificationsList.bHidVolDamagePrevReported[i] = FALSE;
1.1.1.13! root     1000:                                ListSubItemSetW (hTree, listItem.iItem, 4, ws);
        !          1001:                        }
        !          1002:                        else
        !          1003:                        {
        !          1004:                                switch (driver.volumeType[i])
        !          1005:                                {
        !          1006:                                case PROP_VOL_TYPE_NORMAL:
        !          1007:                                        ws = GetString ("NORMAL");
        !          1008:                                        break;
        !          1009:                                case PROP_VOL_TYPE_HIDDEN:
        !          1010:                                        ws = GetString ("HIDDEN");
        !          1011:                                        break;
        !          1012:                                case PROP_VOL_TYPE_OUTER:
        !          1013:                                        ws = GetString ("OUTER");               // Normal/outer volume (hidden volume protected)
        !          1014:                                        break;
        !          1015:                                case PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED:
        !          1016:                                        ws = GetString ("OUTER_VOL_WRITE_PREVENTED");   // Normal/outer volume (hidden volume protected AND write denied)
        !          1017:                                        break;
        !          1018:                                default:
        !          1019:                                        ws = L"?";
        !          1020:                                }
        !          1021:                                ListSubItemSetW (hTree, listItem.iItem, 4, ws);
        !          1022: 
        !          1023:                                if (driver.volumeType[i] == PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED)    // Normal/outer volume (hidden volume protected AND write denied)
        !          1024:                                {                               
        !          1025:                                        if (!VolumeNotificationsList.bHidVolDamagePrevReported[i])
        !          1026:                                        {
        !          1027:                                                wchar_t szTmp[4096];
        !          1028: 
        !          1029:                                                VolumeNotificationsList.bHidVolDamagePrevReported[i] = TRUE;
        !          1030:                                                swprintf (szTmp, GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), i+'A');
        !          1031:                                                SetForegroundWindow (GetParent(hTree));
        !          1032:                                                MessageBoxW (GetParent(hTree), szTmp, lpszTitle, MB_ICONWARNING);
        !          1033:                                        }
        !          1034:                                }
        !          1035:                                else
        !          1036:                                {
        !          1037:                                        VolumeNotificationsList.bHidVolDamagePrevReported[i] = FALSE;
        !          1038:                                }
1.1.1.7   root     1039:                        }
1.1       root     1040:                }
                   1041:                else
                   1042:                {
1.1.1.7   root     1043:                        VolumeNotificationsList.bHidVolDamagePrevReported[i] = FALSE;
                   1044: 
1.1       root     1045:                        if (!(dwUsedDrives & 1 << i))
                   1046:                        {
                   1047:                                if(drive > 0 && drive != HIWORD (GetSelectedLong (hTree)))
                   1048:                                {
                   1049:                                        item++;
                   1050:                                        continue;
                   1051:                                }
                   1052: 
                   1053:                                memset(&listItem,0,sizeof(listItem));
                   1054: 
                   1055:                                listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
                   1056:                                listItem.iImage = 0;
                   1057:                                listItem.iItem = item++;  
                   1058:                                listItem.pszText = szDriveLetters[i];
1.1.1.13! root     1059:                                listItem.lParam = MAKELONG (TC_MLIST_ITEM_FREE, i + 'A');
1.1       root     1060: 
                   1061:                                if(drive == 0) 
                   1062:                                        ListView_InsertItem (hTree, &listItem);
                   1063:                                else
                   1064:                                        ListView_SetItem (hTree, &listItem);
                   1065: 
                   1066:                                listItem.mask=LVIF_TEXT;   
                   1067:                                listItem.pszText = "";
                   1068:                                listItem.iSubItem = 1;
1.1.1.5   root     1069:                                ListView_SetItem (hTree, &listItem);
1.1       root     1070:                                listItem.iSubItem = 2;
1.1.1.5   root     1071:                                ListView_SetItem (hTree, &listItem);
1.1       root     1072:                                listItem.iSubItem = 3;
1.1.1.5   root     1073:                                ListView_SetItem (hTree, &listItem);
                   1074:                                listItem.iSubItem = 4;
                   1075:                                ListView_SetItem (hTree, &listItem);
1.1       root     1076: 
                   1077:                        }
                   1078:                }
                   1079:        }
                   1080: }
                   1081: 
                   1082: 
1.1.1.7   root     1083: static void PasswordChangeEnable (HWND hwndDlg, int button, int passwordId, BOOL keyFilesEnabled,
                   1084:                                                                  int newPasswordId, int newVerifyId, BOOL newKeyFilesEnabled)
                   1085: {
                   1086:        char password[MAX_PASSWORD + 1];
                   1087:        char newPassword[MAX_PASSWORD + 1];
                   1088:        char newVerify[MAX_PASSWORD + 1];
                   1089:        BOOL bEnable = TRUE;
                   1090: 
                   1091:        GetWindowText (GetDlgItem (hwndDlg, passwordId), password, sizeof (password));
                   1092: 
                   1093:        if (pwdChangeDlgMode == PCDM_CHANGE_PKCS5_PRF)
                   1094:                newKeyFilesEnabled = keyFilesEnabled;
                   1095: 
                   1096:        switch (pwdChangeDlgMode)
                   1097:        {
                   1098:        case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
                   1099:        case PCDM_ADD_REMOVE_VOL_KEYFILES:
                   1100:        case PCDM_CHANGE_PKCS5_PRF:
                   1101:                memcpy (newPassword, password, sizeof (newPassword));
                   1102:                memcpy (newVerify, password, sizeof (newVerify));
                   1103:                break;
                   1104: 
                   1105:        default:
                   1106:                GetWindowText (GetDlgItem (hwndDlg, newPasswordId), newPassword, sizeof (newPassword));
                   1107:                GetWindowText (GetDlgItem (hwndDlg, newVerifyId), newVerify, sizeof (newVerify));
                   1108:        }
                   1109: 
                   1110:        if (!keyFilesEnabled && strlen (password) < MIN_PASSWORD)
                   1111:                bEnable = FALSE;
                   1112:        else if (strcmp (newPassword, newVerify) != 0)
                   1113:                bEnable = FALSE;
                   1114:        else if (!newKeyFilesEnabled && strlen (newPassword) < MIN_PASSWORD)
                   1115:                bEnable = FALSE;
                   1116: 
                   1117:        burn (password, sizeof (password));
                   1118:        burn (newPassword, sizeof (newPassword));
                   1119:        burn (newVerify, sizeof (newVerify));
                   1120: 
                   1121:        EnableWindow (GetDlgItem (hwndDlg, button), bEnable);
                   1122: }
                   1123: 
                   1124: 
1.1       root     1125: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
                   1126:    should return nonzero if it processes the message, and zero if it does
                   1127:    not. - see DialogProc */
1.1.1.12  root     1128: BOOL CALLBACK
1.1       root     1129: PasswordChangeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                   1130: {
1.1.1.7   root     1131:        static KeyFilesDlgParam newKeyFilesParam;
1.1       root     1132: 
                   1133:        WORD lw = LOWORD (wParam);
                   1134:        WORD hw = HIWORD (wParam);
                   1135: 
                   1136:        switch (msg)
                   1137:        {
                   1138:        case WM_INITDIALOG:
                   1139:                {
1.1.1.3   root     1140:                        LPARAM nIndex;
1.1.1.7   root     1141:                        HWND hComboBox = GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID);
1.1.1.3   root     1142:                        int i;
1.1       root     1143: 
1.1.1.7   root     1144:                        ZeroMemory (&newKeyFilesParam, sizeof (newKeyFilesParam));
1.1       root     1145: 
1.1.1.7   root     1146:                        SetWindowTextW (hwndDlg, GetString ("IDD_PASSWORDCHANGE_DLG"));
                   1147:                        LocalizeDialog (hwndDlg, "IDD_PASSWORDCHANGE_DLG");
1.1       root     1148: 
                   1149:                        SendMessage (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
                   1150:                        SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
                   1151:                        SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY), EM_LIMITTEXT, MAX_PASSWORD, 0);
                   1152:                        EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
                   1153: 
1.1.1.7   root     1154:                        SetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES, KeyFilesEnable);
                   1155:                        EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES), KeyFilesEnable);
                   1156:                        EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), FALSE);
                   1157: 
1.1.1.3   root     1158:                        SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
                   1159: 
1.1.1.7   root     1160:                        nIndex = SendMessageW (hComboBox, CB_ADDSTRING, 0, (LPARAM) GetString ("UNCHANGED"));
1.1.1.3   root     1161:                        SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) 0);
                   1162: 
1.1.1.13! root     1163:                        for (i = FIRST_PRF_ID; i <= LAST_PRF_ID; i++)
1.1.1.3   root     1164:                        {
1.1.1.13! root     1165:                                if (!HashIsDeprecated (i))
        !          1166:                                {
        !          1167:                                        nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) get_pkcs5_prf_name(i));
        !          1168:                                        SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) i);
        !          1169:                                }
1.1.1.3   root     1170:                        }
                   1171: 
                   1172:                        SendMessage (hComboBox, CB_SETCURSEL, 0, 0);
                   1173: 
1.1.1.7   root     1174:                        switch (pwdChangeDlgMode)
                   1175:                        {
                   1176:                        case PCDM_CHANGE_PKCS5_PRF:
                   1177:                                SetWindowTextW (hwndDlg, GetString ("IDD_PCDM_CHANGE_PKCS5_PRF"));
                   1178:                                LocalizeDialog (hwndDlg, "IDD_PCDM_CHANGE_PKCS5_PRF");
                   1179:                                EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD), FALSE);
                   1180:                                EnableWindow (GetDlgItem (hwndDlg, IDC_VERIFY), FALSE);
                   1181:                                EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_NEW_KEYFILES), FALSE);
                   1182:                                EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW), FALSE);
                   1183:                                EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), FALSE);
                   1184:                                EnableWindow (GetDlgItem (hwndDlg, IDT_NEW_PASSWORD), FALSE);
                   1185:                                EnableWindow (GetDlgItem (hwndDlg, IDT_CONFIRM_PASSWORD), FALSE);
                   1186:                                break;
                   1187: 
                   1188:                        case PCDM_ADD_REMOVE_VOL_KEYFILES:
                   1189:                                SetWindowTextW (hwndDlg, GetString ("IDD_PCDM_ADD_REMOVE_VOL_KEYFILES"));
                   1190:                                LocalizeDialog (hwndDlg, "IDD_PCDM_ADD_REMOVE_VOL_KEYFILES");
                   1191:                                newKeyFilesParam.EnableKeyFiles = TRUE;
                   1192:                                EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD), FALSE);
                   1193:                                EnableWindow (GetDlgItem (hwndDlg, IDC_VERIFY), FALSE);
                   1194:                                EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW), FALSE);
                   1195:                                EnableWindow (GetDlgItem (hwndDlg, IDT_NEW_PASSWORD), FALSE);
                   1196:                                EnableWindow (GetDlgItem (hwndDlg, IDT_CONFIRM_PASSWORD), FALSE);
                   1197:                                break;
                   1198: 
                   1199:                        case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
                   1200:                                newKeyFilesParam.EnableKeyFiles = FALSE;
                   1201:                                SetWindowTextW (hwndDlg, GetString ("IDD_PCDM_REMOVE_ALL_KEYFILES_FROM_VOL"));
                   1202:                                LocalizeDialog (hwndDlg, "IDD_PCDM_REMOVE_ALL_KEYFILES_FROM_VOL");
                   1203:                                KeyFilesEnable = TRUE;
                   1204:                                SetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES, TRUE);
                   1205:                                EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES), TRUE);
                   1206:                                EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_KEYFILES), TRUE);
                   1207:                                EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD), FALSE);
                   1208:                                EnableWindow (GetDlgItem (hwndDlg, IDC_VERIFY), FALSE);
                   1209:                                EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_NEW_KEYFILES), FALSE);
                   1210:                                EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW), FALSE);
                   1211:                                EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), FALSE);
                   1212:                                EnableWindow (GetDlgItem (hwndDlg, IDT_NEW_PASSWORD), FALSE);
                   1213:                                EnableWindow (GetDlgItem (hwndDlg, IDT_CONFIRM_PASSWORD), FALSE);
                   1214:                                EnableWindow (GetDlgItem (hwndDlg, IDT_PKCS5_PRF), FALSE);
                   1215:                                EnableWindow (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), FALSE);
                   1216:                                break;
                   1217: 
                   1218:                        case PCDM_CHANGE_PASSWORD:
                   1219:                        default:
                   1220:                                // NOP
                   1221:                                break;
                   1222:                        };
                   1223: 
1.1.1.13! root     1224:                        if (bSysEncPwdChangeDlgMode)
        !          1225:                        {
        !          1226:                                ToBootPwdField (hwndDlg, IDC_PASSWORD);
        !          1227:                                ToBootPwdField (hwndDlg, IDC_VERIFY);
        !          1228:                                ToBootPwdField (hwndDlg, IDC_OLD_PASSWORD);
        !          1229: 
        !          1230:                                DWORD keybLayout = (DWORD) LoadKeyboardLayout ("00000409", KLF_ACTIVATE);
        !          1231: 
        !          1232:                                if (keybLayout != 0x00000409 && keybLayout != 0x04090409)
        !          1233:                                {
        !          1234:                                        Error ("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION");
        !          1235:                                        EndDialog (hwndDlg, IDCANCEL);
        !          1236:                                        return 0;
        !          1237:                                }
        !          1238: 
        !          1239:                                ShowWindow(GetDlgItem(hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW), SW_HIDE);
        !          1240:                                ShowWindow(GetDlgItem(hwndDlg, IDC_SHOW_PASSWORD_CHPWD_ORI), SW_HIDE);
        !          1241: 
        !          1242:                                if (SetTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD, TIMER_INTERVAL_KEYB_LAYOUT_GUARD, NULL) == 0)
        !          1243:                                {
        !          1244:                                        Error ("CANNOT_SET_TIMER");
        !          1245:                                        EndDialog (hwndDlg, IDCANCEL);
        !          1246:                                        return 0;
        !          1247:                                }
        !          1248: 
        !          1249:                                newKeyFilesParam.EnableKeyFiles = FALSE;
        !          1250:                                KeyFilesEnable = FALSE;
        !          1251:                                SetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES, FALSE);
        !          1252:                                EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES), FALSE);
        !          1253:                                EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_KEYFILES), FALSE);
        !          1254:                                EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_NEW_KEYFILES), FALSE);
        !          1255:                                EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), FALSE);
        !          1256:                        }
        !          1257: 
1.1.1.5   root     1258:                        CheckCapsLock (hwndDlg, FALSE);
                   1259: 
1.1.1.13! root     1260:                        return 0;
        !          1261:                }
        !          1262: 
        !          1263:        case WM_TIMER:
        !          1264:                switch (wParam)
        !          1265:                {
        !          1266:                case TIMER_ID_KEYB_LAYOUT_GUARD:
        !          1267:                        if (bSysEncPwdChangeDlgMode)
        !          1268:                        {
        !          1269:                                DWORD keybLayout = (DWORD) GetKeyboardLayout (NULL);
        !          1270: 
        !          1271:                                if (keybLayout != 0x00000409 && keybLayout != 0x04090409)
        !          1272:                                {
        !          1273:                                        // Keyboard layout is not standard US
        !          1274: 
        !          1275:                                        // Attempt to wipe passwords stored in the input field buffers
        !          1276:                                        char tmp[MAX_PASSWORD+1];
        !          1277:                                        memset (tmp, 'X', MAX_PASSWORD);
        !          1278:                                        tmp [MAX_PASSWORD] = 0;
        !          1279:                                        SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);
        !          1280:                                        SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
        !          1281:                                        SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);
        !          1282: 
        !          1283:                                        SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), "");
        !          1284:                                        SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), "");
        !          1285:                                        SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), "");
        !          1286: 
        !          1287:                                        keybLayout = (DWORD) LoadKeyboardLayout ("00000409", KLF_ACTIVATE);
        !          1288: 
        !          1289:                                        if (keybLayout != 0x00000409 && keybLayout != 0x04090409)
        !          1290:                                        {
        !          1291:                                                KillTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD);
        !          1292:                                                Error ("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION");
        !          1293:                                                EndDialog (hwndDlg, IDCANCEL);
        !          1294:                                                return 1;
        !          1295:                                        }
        !          1296: 
        !          1297:                                        Warning ("KEYB_LAYOUT_CHANGE_PREVENTED");
        !          1298:                                }
        !          1299:                        }
1.1       root     1300:                        return 1;
                   1301:                }
1.1.1.13! root     1302:                return 0;
1.1       root     1303: 
                   1304:        case WM_COMMAND:
                   1305:                if (lw == IDCANCEL)
                   1306:                {
                   1307:                        // Attempt to wipe passwords stored in the input field buffers
                   1308:                        char tmp[MAX_PASSWORD+1];
                   1309:                        memset (tmp, 'X', MAX_PASSWORD);
                   1310:                        tmp[MAX_PASSWORD] = 0;
                   1311:                        SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);        
                   1312:                        SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);    
                   1313:                        SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);  
1.1.1.7   root     1314:                        RestoreDefaultKeyFilesParam ();
1.1       root     1315: 
                   1316:                        EndDialog (hwndDlg, IDCANCEL);
                   1317:                        return 1;
                   1318:                }
1.1.1.7   root     1319: 
1.1       root     1320:                if (hw == EN_CHANGE)
                   1321:                {
1.1.1.7   root     1322:                        PasswordChangeEnable (hwndDlg, IDOK,
                   1323:                                IDC_OLD_PASSWORD,
                   1324:                                KeyFilesEnable && FirstKeyFile != NULL,
                   1325:                                IDC_PASSWORD, IDC_VERIFY, 
                   1326:                                newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);              
                   1327: 
                   1328:                        return 1;
                   1329:                }
                   1330: 
                   1331:                if (lw == IDC_KEYFILES)
                   1332:                {
                   1333:                        KeyFilesDlgParam param;
                   1334:                        param.EnableKeyFiles = KeyFilesEnable;
                   1335:                        param.FirstKeyFile = FirstKeyFile;
                   1336: 
                   1337:                        if (IDOK == DialogBoxParamW (hInst,
                   1338:                                MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
                   1339:                                (DLGPROC) KeyFilesDlgProc, (LPARAM) &param))
                   1340:                        {
                   1341:                                KeyFilesEnable = param.EnableKeyFiles;
                   1342:                                FirstKeyFile = param.FirstKeyFile;
                   1343:                        
                   1344:                                SetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES, KeyFilesEnable);
                   1345:                                EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES), KeyFilesEnable);
                   1346:                        }
                   1347: 
                   1348:                        PasswordChangeEnable (hwndDlg, IDOK,
                   1349:                                IDC_OLD_PASSWORD,
                   1350:                                KeyFilesEnable && FirstKeyFile != NULL,
                   1351:                                IDC_PASSWORD, IDC_VERIFY, 
                   1352:                                newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);              
                   1353: 
                   1354:                        return 1;
                   1355:                }
                   1356: 
                   1357:                
                   1358:                if (lw == IDC_NEW_KEYFILES)
                   1359:                {
                   1360:                        if (IDOK == DialogBoxParamW (hInst,
                   1361:                                MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
                   1362:                                (DLGPROC) KeyFilesDlgProc, (LPARAM) &newKeyFilesParam))
                   1363:                        {
                   1364:                                SetCheckBox (hwndDlg, IDC_ENABLE_NEW_KEYFILES, newKeyFilesParam.EnableKeyFiles);
                   1365:                                EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), newKeyFilesParam.EnableKeyFiles);
                   1366: 
                   1367:                                VerifyPasswordAndUpdate (hwndDlg, GetDlgItem (hwndDlg, IDOK), GetDlgItem (hwndDlg, IDC_PASSWORD),
                   1368:                                        GetDlgItem (hwndDlg, IDC_VERIFY), NULL, NULL,
                   1369:                                        newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);              
                   1370:                        }
                   1371: 
                   1372:                        PasswordChangeEnable (hwndDlg, IDOK,
                   1373:                                IDC_OLD_PASSWORD,
                   1374:                                KeyFilesEnable && FirstKeyFile != NULL,
                   1375:                                IDC_PASSWORD, IDC_VERIFY, 
                   1376:                                newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);              
                   1377: 
                   1378:                        return 1;
                   1379:                }
                   1380: 
                   1381:                if (lw == IDC_ENABLE_KEYFILES)
                   1382:                {
                   1383:                        KeyFilesEnable = GetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES);
                   1384:                        EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES), KeyFilesEnable);
                   1385: 
                   1386:                        PasswordChangeEnable (hwndDlg, IDOK,
                   1387:                                IDC_OLD_PASSWORD,
                   1388:                                KeyFilesEnable && FirstKeyFile != NULL,
                   1389:                                IDC_PASSWORD, IDC_VERIFY, 
                   1390:                                newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);              
                   1391: 
                   1392:                        return 1;
                   1393:                }
                   1394: 
                   1395:                if (lw == IDC_ENABLE_NEW_KEYFILES)
                   1396:                {
                   1397:                        newKeyFilesParam.EnableKeyFiles = GetCheckBox (hwndDlg, IDC_ENABLE_NEW_KEYFILES);
                   1398:                        EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), newKeyFilesParam.EnableKeyFiles);
                   1399: 
                   1400:                        PasswordChangeEnable (hwndDlg, IDOK,
                   1401:                                IDC_OLD_PASSWORD,
                   1402:                                KeyFilesEnable && FirstKeyFile != NULL,
                   1403:                                IDC_PASSWORD, IDC_VERIFY, 
                   1404:                                newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);              
                   1405: 
                   1406:                        return 1;
                   1407:                }
                   1408: 
1.1.1.13! root     1409:                if (hw == CBN_SELCHANGE)
        !          1410:                {
        !          1411:                        switch (lw)
        !          1412:                        {
        !          1413:                        case IDC_PKCS5_PRF_ID:
        !          1414:                                if (bSysEncPwdChangeDlgMode)
        !          1415:                                {
        !          1416:                                        int new_hash_algo_id = SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETITEMDATA, 
        !          1417:                                                SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETCURSEL, 0, 0), 0);
        !          1418: 
        !          1419:                                        if (new_hash_algo_id != 0 && new_hash_algo_id != DEFAULT_HASH_ALGORITHM_BOOT)
        !          1420:                                        {
        !          1421:                                                int new_hash_algo_id = DEFAULT_HASH_ALGORITHM_BOOT;
        !          1422:                                                Info ("ALGO_NOT_SUPPORTED_FOR_SYS_ENCRYPTION");
        !          1423:                                                SelectAlgo (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), &new_hash_algo_id);
        !          1424:                                        }
        !          1425:                                }
        !          1426:                                break;
        !          1427:                        }
        !          1428:                        return 1;
        !          1429: 
        !          1430:                }
        !          1431: 
1.1.1.7   root     1432:                if (lw == IDC_SHOW_PASSWORD_CHPWD_ORI)
                   1433:                {
                   1434:                        SendMessage (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD),
                   1435:                                                EM_SETPASSWORDCHAR,
                   1436:                                                GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_ORI) ? 0 : '*',
                   1437:                                                0);
                   1438:                        InvalidateRect (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), NULL, TRUE);
                   1439:                        return 1;
                   1440:                }
                   1441: 
                   1442:                if (lw == IDC_SHOW_PASSWORD_CHPWD_NEW)
                   1443:                {
                   1444:                        SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD),
                   1445:                                                EM_SETPASSWORDCHAR,
                   1446:                                                GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW) ? 0 : '*',
                   1447:                                                0);
                   1448:                        SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY),
                   1449:                                                EM_SETPASSWORDCHAR,
                   1450:                                                GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW) ? 0 : '*',
                   1451:                                                0);
                   1452:                        InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD), NULL, TRUE);
                   1453:                        InvalidateRect (GetDlgItem (hwndDlg, IDC_VERIFY), NULL, TRUE);
1.1       root     1454:                        return 1;
                   1455:                }
1.1.1.7   root     1456: 
1.1       root     1457:                if (lw == IDOK)
                   1458:                {
                   1459:                        HWND hParent = GetParent (hwndDlg);
1.1.1.7   root     1460:                        Password oldPassword;
                   1461:                        Password newPassword;
1.1       root     1462:                        int nStatus;
1.1.1.7   root     1463:                        int pkcs5 = SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETITEMDATA, 
                   1464:                                        SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETCURSEL, 0, 0), 0);
                   1465: 
                   1466:                        if (!CheckPasswordCharEncoding (GetDlgItem (hwndDlg, IDC_PASSWORD), NULL))
                   1467:                        {
                   1468:                                Error ("UNSUPPORTED_CHARS_IN_PWD");
                   1469:                                return 1;
                   1470:                        }
1.1       root     1471: 
1.1.1.7   root     1472:                        if (pwdChangeDlgMode == PCDM_CHANGE_PKCS5_PRF)
                   1473:                        {
                   1474:                                newKeyFilesParam.EnableKeyFiles = KeyFilesEnable;
                   1475:                        }
1.1.1.8   root     1476:                        else if (!(newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL)
                   1477:                                && pwdChangeDlgMode == PCDM_CHANGE_PASSWORD)
1.1.1.7   root     1478:                        {
                   1479:                                if (!CheckPasswordLength (hwndDlg, GetDlgItem (hwndDlg, IDC_PASSWORD)))
                   1480:                                        return 1;
                   1481:                        }
1.1.1.5   root     1482: 
1.1       root     1483:                        GetWindowText (GetDlgItem (hParent, IDC_VOLUME), szFileName, sizeof (szFileName));
                   1484: 
1.1.1.13! root     1485:                        GetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), (LPSTR) oldPassword.Text, sizeof (oldPassword.Text));
        !          1486:                        oldPassword.Length = strlen ((char *) oldPassword.Text);
1.1.1.7   root     1487: 
                   1488:                        switch (pwdChangeDlgMode)
                   1489:                        {
                   1490:                        case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
                   1491:                        case PCDM_ADD_REMOVE_VOL_KEYFILES:
                   1492:                        case PCDM_CHANGE_PKCS5_PRF:
                   1493:                                memcpy (newPassword.Text, oldPassword.Text, sizeof (newPassword.Text));
1.1.1.13! root     1494:                                newPassword.Length = strlen ((char *) oldPassword.Text);
1.1.1.7   root     1495:                                break;
                   1496: 
                   1497:                        default:
1.1.1.13! root     1498:                                GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), (LPSTR) newPassword.Text, sizeof (newPassword.Text));
        !          1499:                                newPassword.Length = strlen ((char *) newPassword.Text);
1.1.1.7   root     1500:                        }
                   1501: 
                   1502:                        if (KeyFilesEnable)
1.1.1.12  root     1503:                                KeyFilesApply (&oldPassword, FirstKeyFile);
1.1       root     1504: 
1.1.1.7   root     1505:                        if (newKeyFilesParam.EnableKeyFiles)
                   1506:                                KeyFilesApply (&newPassword,
1.1.1.12  root     1507:                                pwdChangeDlgMode==PCDM_CHANGE_PKCS5_PRF ? FirstKeyFile : newKeyFilesParam.FirstKeyFile);
1.1       root     1508: 
1.1.1.13! root     1509:                        WaitCursor ();
        !          1510: 
        !          1511:                        if (bSysEncPwdChangeDlgMode)
        !          1512:                        {
        !          1513:                                // System
        !          1514: 
        !          1515:                                pkcs5 = 0;      // PKCS-5 PRF unchanged (currently system encryption supports only RIPEMD-160)
        !          1516: 
        !          1517:                                try
        !          1518:                                {
        !          1519:                                        nStatus = BootEncObj->ChangePassword (&oldPassword, &newPassword, pkcs5);
        !          1520:                                }
        !          1521:                                catch (Exception &e)
        !          1522:                                {
        !          1523:                                        e.Show (MainDlg);
        !          1524:                                        nStatus = ERR_OS_ERROR;
        !          1525:                                }
        !          1526:                        }
        !          1527:                        else
        !          1528:                        {
        !          1529:                                // Non-system
        !          1530: 
        !          1531:                                nStatus = ChangePwd (szFileName, &oldPassword, &newPassword, pkcs5, hwndDlg);
1.1       root     1532: 
1.1.1.13! root     1533:                                if (nStatus == ERR_OS_ERROR
        !          1534:                                        && GetLastError () == ERROR_ACCESS_DENIED
        !          1535:                                        && IsUacSupported ()
        !          1536:                                        && IsVolumeDeviceHosted (szFileName))
        !          1537:                                {
        !          1538:                                        nStatus = UacChangePwd (szFileName, &oldPassword, &newPassword, pkcs5, hwndDlg);
        !          1539:                                }
1.1.1.11  root     1540:                        }
                   1541: 
1.1.1.7   root     1542:                        burn (&oldPassword, sizeof (oldPassword));
                   1543:                        burn (&newPassword, sizeof (newPassword));
1.1       root     1544: 
1.1.1.13! root     1545:                        NormalCursor ();
        !          1546: 
1.1.1.11  root     1547:                        if (nStatus == 0)
1.1       root     1548:                        {
                   1549:                                // Attempt to wipe passwords stored in the input field buffers
                   1550:                                char tmp[MAX_PASSWORD+1];
                   1551:                                memset (tmp, 'X', MAX_PASSWORD);
                   1552:                                tmp[MAX_PASSWORD] = 0;
                   1553:                                SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);        
                   1554:                                SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);    
                   1555:                                SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);  
                   1556: 
1.1.1.7   root     1557:                                KeyFileRemoveAll (&newKeyFilesParam.FirstKeyFile);
                   1558:                                RestoreDefaultKeyFilesParam ();
                   1559: 
1.1.1.13! root     1560:                                if (bSysEncPwdChangeDlgMode)
        !          1561:                                {
        !          1562:                                        KillTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD);
        !          1563:                                }
        !          1564: 
1.1       root     1565:                                EndDialog (hwndDlg, IDOK);
                   1566:                        }
                   1567:                        return 1;
                   1568:                }
                   1569:                return 0;
                   1570:        }
                   1571: 
                   1572:        return 0;
                   1573: }
                   1574: 
1.1.1.7   root     1575: static char PasswordDlgVolume[MAX_PATH];
                   1576: 
1.1       root     1577: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
                   1578:    should return nonzero if it processes the message, and zero if it does
                   1579:    not. - see DialogProc */
1.1.1.12  root     1580: BOOL CALLBACK
1.1       root     1581: PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                   1582: {
                   1583:        WORD lw = LOWORD (wParam);
1.1.1.7   root     1584:        static Password *szXPwd;        
1.1       root     1585: 
                   1586:        switch (msg)
                   1587:        {
                   1588:        case WM_INITDIALOG:
                   1589:                {
1.1.1.7   root     1590:                        szXPwd = (Password *) lParam;
                   1591:                        LocalizeDialog (hwndDlg, "IDD_PASSWORD_DLG");
1.1.1.9   root     1592:                        DragAcceptFiles (hwndDlg, TRUE);
1.1.1.7   root     1593: 
                   1594:                        if (strlen (PasswordDlgVolume) > 0)
                   1595:                        {
                   1596:                                wchar_t s[1024];
                   1597:                                wsprintfW (s, GetString ("ENTER_PASSWORD_FOR"), PasswordDlgVolume);
                   1598:                                SetWindowTextW (hwndDlg, s);
                   1599:                        }
                   1600: 
1.1       root     1601:                        SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
                   1602:                        SendMessage (GetDlgItem (hwndDlg, IDC_CACHE), BM_SETCHECK, bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
1.1.1.7   root     1603: 
                   1604:                        SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
                   1605:                        EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
1.1.1.8   root     1606: 
                   1607:                        SetForegroundWindow (hwndDlg);
1.1       root     1608:                }
1.1.1.13! root     1609:                return 0;
1.1       root     1610: 
                   1611:        case WM_COMMAND:
                   1612: 
1.1.1.6   root     1613:                if (lw == IDC_MOUNT_OPTIONS)
                   1614:                {
1.1.1.7   root     1615:                        DialogBoxParamW (hInst, 
                   1616:                                MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
1.1.1.6   root     1617:                                (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions);
                   1618:                        return 1;
                   1619:                }
                   1620: 
1.1.1.7   root     1621:                if (lw == IDC_SHOW_PASSWORD)
                   1622:                {
                   1623:                        SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD),
                   1624:                                                EM_SETPASSWORDCHAR,
                   1625:                                                GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD) ? 0 : '*',
                   1626:                                                0);
                   1627:                        InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD), NULL, TRUE);
                   1628:                        return 1;
                   1629:                }
                   1630: 
                   1631:                if (lw == IDC_KEY_FILES)
                   1632:                {
                   1633:                        KeyFilesDlgParam param;
                   1634:                        param.EnableKeyFiles = KeyFilesEnable;
                   1635:                        param.FirstKeyFile = FirstKeyFile;
                   1636: 
                   1637:                        if (IDOK == DialogBoxParamW (hInst,
                   1638:                                MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
                   1639:                                (DLGPROC) KeyFilesDlgProc, (LPARAM) &param))
                   1640:                        {
                   1641:                                KeyFilesEnable = param.EnableKeyFiles;
                   1642:                                FirstKeyFile = param.FirstKeyFile;
                   1643: 
                   1644:                                SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
                   1645:                                EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
                   1646:                        }
                   1647: 
                   1648:                        return 1;
                   1649:                }
                   1650: 
                   1651:                if (lw == IDC_KEYFILES_ENABLE)
                   1652:                {
                   1653:                        KeyFilesEnable = GetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE);
                   1654:                        EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
                   1655: 
                   1656:                        return 1;
                   1657:                }
                   1658: 
1.1       root     1659:                if (lw == IDCANCEL || lw == IDOK)
                   1660:                {
                   1661:                        char tmp[MAX_PASSWORD+1];
                   1662:                        
                   1663:                        if (lw == IDOK)
                   1664:                        {
1.1.1.7   root     1665:                                if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
1.1.1.12  root     1666:                                        KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile);
1.1.1.7   root     1667: 
1.1.1.13! root     1668:                                GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), (LPSTR) szXPwd->Text, MAX_PASSWORD + 1);
        !          1669:                                szXPwd->Length = strlen ((char *) szXPwd->Text);
1.1.1.7   root     1670: 
1.1       root     1671:                                bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_CACHE));      
                   1672:                        }
                   1673: 
                   1674:                        // Attempt to wipe password stored in the input field buffer
                   1675:                        memset (tmp, 'X', MAX_PASSWORD);
                   1676:                        tmp[MAX_PASSWORD] = 0;
                   1677:                        SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);        
1.1.1.7   root     1678:                        SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), tmp);    
                   1679: 
                   1680:                        if (hidVolProtKeyFilesParam.FirstKeyFile != NULL)
                   1681:                        {
                   1682:                                KeyFileRemoveAll (&hidVolProtKeyFilesParam.FirstKeyFile);
                   1683:                                hidVolProtKeyFilesParam.EnableKeyFiles = FALSE;
                   1684:                        }
1.1       root     1685: 
                   1686:                        EndDialog (hwndDlg, lw);
                   1687:                        return 1;
                   1688:                }
                   1689:                return 0;
1.1.1.9   root     1690: 
                   1691:        case WM_DROPFILES:
                   1692:                {
                   1693:                        HDROP hdrop = (HDROP) wParam;
                   1694:                        int i = 0, count = DragQueryFile (hdrop, -1, NULL, 0);
                   1695: 
                   1696:                        while (count-- > 0)
                   1697:                        {
1.1.1.13! root     1698:                                KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
1.1.1.9   root     1699:                                DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName));
                   1700:                                FirstKeyFile = KeyFileAdd (FirstKeyFile, kf);
                   1701:                                KeyFilesEnable = TRUE;
                   1702:                        }
                   1703: 
                   1704:                        SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
                   1705:                        EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
                   1706: 
                   1707:                        DragFinish (hdrop);
                   1708:                }
                   1709:                return 1;
1.1       root     1710:        }
                   1711: 
                   1712:        return 0;
                   1713: }
                   1714: 
1.1.1.7   root     1715: static void PreferencesDlgEnableButtons (HWND hwndDlg)
                   1716: {
1.1.1.11  root     1717:        BOOL back = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE));
1.1.1.7   root     1718:        BOOL idle = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE));
                   1719:        BOOL logon = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START));
                   1720:        BOOL installed = !IsNonInstallMode();
                   1721: 
1.1.1.11  root     1722:        EnableWindow (GetDlgItem (hwndDlg, IDC_CLOSE_BKG_TASK_WHEN_NOVOL), back && installed);
1.1.1.7   root     1723:        EnableWindow (GetDlgItem (hwndDlg, IDT_LOGON), installed);
                   1724:        EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START), installed);
                   1725:        EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_DEVICES), installed && logon);
                   1726:        EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_FAVORITES), installed && logon);
1.1.1.11  root     1727:        EnableWindow (GetDlgItem (hwndDlg, IDT_AUTO_DISMOUNT), back);
                   1728:        EnableWindow (GetDlgItem (hwndDlg, IDT_AUTO_DISMOUNT_ON), back);
                   1729:        EnableWindow (GetDlgItem (hwndDlg, IDT_MINUTES), back);
                   1730:        EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF), back);
                   1731:        EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING), back);
                   1732:        EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER), back);
                   1733:        EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE), back);
                   1734:        EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE_TIME), back && idle);
                   1735:        EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT), back);
1.1.1.7   root     1736: }
                   1737: 
1.1.1.12  root     1738: BOOL CALLBACK
1.1       root     1739: PreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                   1740: {
                   1741:        WORD lw = LOWORD (wParam);
                   1742: 
                   1743:        switch (msg)
                   1744:        {
                   1745:        case WM_INITDIALOG:
                   1746:                {
1.1.1.7   root     1747:                        LocalizeDialog (hwndDlg, "IDD_PREFERENCES_DLG");
1.1       root     1748:                
                   1749:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_OPEN_EXPLORER), BM_SETCHECK, 
                   1750:                                                bExplore ? BST_CHECKED:BST_UNCHECKED, 0);
                   1751: 
                   1752:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_CLOSE_DISMOUNTED_WINDOWS), BM_SETCHECK, 
                   1753:                                                bCloseDismountedWindows ? BST_CHECKED:BST_UNCHECKED, 0);
                   1754:                        
1.1.1.7   root     1755:                        SendMessage (GetDlgItem (hwndDlg, IDC_PRESERVE_TIMESTAMPS), BM_SETCHECK, 
                   1756:                                                defaultMountOptions.PreserveTimestamp ? BST_CHECKED:BST_UNCHECKED, 0);
                   1757: 
1.1       root     1758:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_EXIT), BM_SETCHECK, 
                   1759:                                                bWipeCacheOnExit ? BST_CHECKED:BST_UNCHECKED, 0);
                   1760: 
1.1.1.7   root     1761:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_AUTODISMOUNT), BM_SETCHECK, 
                   1762:                                                bWipeCacheOnAutoDismount ? BST_CHECKED:BST_UNCHECKED, 0);
                   1763: 
1.1       root     1764:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_CACHE_PASSWORDS), BM_SETCHECK, 
                   1765:                                                bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
                   1766:                        
1.1.1.6   root     1767:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_READONLY), BM_SETCHECK, 
                   1768:                                                defaultMountOptions.ReadOnly ? BST_CHECKED:BST_UNCHECKED, 0);
                   1769: 
                   1770:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_REMOVABLE), BM_SETCHECK, 
                   1771:                                                defaultMountOptions.Removable ? BST_CHECKED:BST_UNCHECKED, 0);
1.1.1.7   root     1772: 
                   1773:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START), BM_SETCHECK, 
                   1774:                                                bStartOnLogon ? BST_CHECKED:BST_UNCHECKED, 0);
                   1775: 
                   1776:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_DEVICES), BM_SETCHECK, 
                   1777:                                                bMountDevicesOnLogon ? BST_CHECKED:BST_UNCHECKED, 0);
                   1778: 
                   1779:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_FAVORITES), BM_SETCHECK, 
                   1780:                                                bMountFavoritesOnLogon ? BST_CHECKED:BST_UNCHECKED, 0);
                   1781: 
                   1782:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE), BM_SETCHECK, 
                   1783:                                                bEnableBkgTask ? BST_CHECKED:BST_UNCHECKED, 0);
                   1784: 
                   1785:                        SendMessage (GetDlgItem (hwndDlg, IDC_CLOSE_BKG_TASK_WHEN_NOVOL), BM_SETCHECK, 
                   1786:                                                bCloseBkgTaskWhenNoVolumes || IsNonInstallMode() ? BST_CHECKED:BST_UNCHECKED, 0);
                   1787:                        
                   1788:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF), BM_SETCHECK, 
                   1789:                                                bDismountOnLogOff ? BST_CHECKED:BST_UNCHECKED, 0);
                   1790: 
                   1791:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING), BM_SETCHECK, 
                   1792:                                                bDismountOnPowerSaving ? BST_CHECKED:BST_UNCHECKED, 0);
                   1793: 
                   1794:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER), BM_SETCHECK, 
                   1795:                                                bDismountOnScreenSaver ? BST_CHECKED:BST_UNCHECKED, 0);
1.1       root     1796:                        
1.1.1.7   root     1797:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT), BM_SETCHECK, 
                   1798:                                                bForceAutoDismount ? BST_CHECKED:BST_UNCHECKED, 0);
                   1799: 
                   1800:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE), BM_SETCHECK, 
                   1801:                                                MaxVolumeIdleTime > 0 ? BST_CHECKED:BST_UNCHECKED, 0);
                   1802: 
                   1803:                        SetDlgItemInt (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE_TIME, abs (MaxVolumeIdleTime), FALSE);
                   1804: 
                   1805:                        PreferencesDlgEnableButtons (hwndDlg);
1.1       root     1806:                }
1.1.1.13! root     1807:                return 0;
1.1       root     1808: 
                   1809:        case WM_COMMAND:
                   1810: 
1.1.1.7   root     1811:                if (lw == IDC_PRESERVE_TIMESTAMPS && !IsButtonChecked (GetDlgItem (hwndDlg, IDC_PRESERVE_TIMESTAMPS)))
                   1812:                {
                   1813:                        if (AskWarnNoYes ("CONFIRM_TIMESTAMP_UPDATING") == IDNO)
                   1814:                                SetCheckBox (hwndDlg, IDC_PRESERVE_TIMESTAMPS, TRUE);
                   1815:                }
                   1816: 
                   1817:                if (lw == IDC_PREF_BKG_TASK_ENABLE && !IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE)))
                   1818:                {
                   1819:                        if (AskWarnNoYes ("CONFIRM_BACKGROUND_TASK_DISABLED") == IDNO)
                   1820:                                SetCheckBox (hwndDlg, IDC_PREF_BKG_TASK_ENABLE, TRUE);
                   1821:                }
                   1822: 
                   1823:                // Forced dismount disabled warning
                   1824:                if (lw == IDC_PREF_DISMOUNT_INACTIVE
                   1825:                        || lw == IDC_PREF_DISMOUNT_POWERSAVING
                   1826:                        || lw == IDC_PREF_DISMOUNT_SCREENSAVER
                   1827:                        || lw == IDC_PREF_FORCE_AUTO_DISMOUNT)
                   1828:                {
                   1829:                        BOOL i = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE));
                   1830:                        BOOL p = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING));
                   1831:                        BOOL s = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER));
                   1832:                        BOOL q = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT));
                   1833: 
                   1834:                        if (!q)
                   1835:                        {
                   1836:                                if (lw == IDC_PREF_FORCE_AUTO_DISMOUNT && (i || p || s))
                   1837:                                {
                   1838:                                        if (AskWarnNoYes ("CONFIRM_NO_FORCED_AUTODISMOUNT") == IDNO)
                   1839:                                                SetCheckBox (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT, TRUE);
                   1840:                                }
                   1841:                                else if ((lw == IDC_PREF_DISMOUNT_INACTIVE && i
                   1842:                                        || lw == IDC_PREF_DISMOUNT_POWERSAVING && p
                   1843:                                        || lw == IDC_PREF_DISMOUNT_SCREENSAVER && s))
                   1844:                                        Warning ("WARN_PREF_AUTO_DISMOUNT");
                   1845:                        }
                   1846: 
                   1847:                }
                   1848: 
1.1       root     1849:                if (lw == IDCANCEL)
                   1850:                {
                   1851:                        EndDialog (hwndDlg, lw);
                   1852:                        return 1;
                   1853:                }
                   1854: 
                   1855:                if (lw == IDOK)
                   1856:                {
1.1.1.7   root     1857:                        bExplore                                                = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_OPEN_EXPLORER));        
                   1858:                        bCloseDismountedWindows                 = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_CLOSE_DISMOUNTED_WINDOWS));     
                   1859:                        bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PRESERVE_TIMESTAMPS));    
                   1860:                        bWipeCacheOnExit                                = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_EXIT));
                   1861:                        bWipeCacheOnAutoDismount                = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_AUTODISMOUNT));
1.1.1.11  root     1862:                        bCacheInDriverDefault = bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_CACHE_PASSWORDS));       
1.1.1.7   root     1863:                        defaultMountOptions.ReadOnly    = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_READONLY));
                   1864:                        defaultMountOptions.Removable   = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_REMOVABLE));
                   1865:                        bEnableBkgTask                          = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE));
                   1866:                        bCloseBkgTaskWhenNoVolumes      = IsNonInstallMode() ? bCloseBkgTaskWhenNoVolumes : IsButtonChecked (GetDlgItem (hwndDlg, IDC_CLOSE_BKG_TASK_WHEN_NOVOL));
                   1867:                        bDismountOnLogOff                               = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF));
                   1868:                        bDismountOnPowerSaving                  = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING));
                   1869:                        bDismountOnScreenSaver                  = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER));
                   1870:                        bForceAutoDismount                              = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT));
                   1871:                        MaxVolumeIdleTime                               = GetDlgItemInt (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE_TIME, NULL, FALSE)
                   1872:                                                                                                * (IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE)) ? 1 : -1);
                   1873:                        bStartOnLogon                                   = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START));  
                   1874:                        bMountDevicesOnLogon                    = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_DEVICES));  
                   1875:                        bMountFavoritesOnLogon                  = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_FAVORITES));        
                   1876: 
1.1.1.13! root     1877:                        ManageStartupSeq ();
1.1.1.7   root     1878: 
1.1.1.12  root     1879:                        WaitCursor ();
1.1.1.7   root     1880:                        SaveSettings (hwndDlg);
1.1.1.12  root     1881:                        NormalCursor ();
1.1       root     1882: 
                   1883:                        EndDialog (hwndDlg, lw);
                   1884:                        return 1;
                   1885:                }
                   1886: 
1.1.1.7   root     1887:                if (lw == IDC_PREFS_HOTKEY_SETTINGS)
                   1888:                {
1.1.1.12  root     1889:                        DialogBoxParamW (hInst, 
                   1890:                                MAKEINTRESOURCEW (IDD_HOTKEYS_DLG), hwndDlg,
1.1.1.7   root     1891:                                (DLGPROC) HotkeysDlgProc, (LPARAM) 0);
                   1892:                        return 1;
1.1       root     1893: 
1.1.1.7   root     1894:                }
1.1.1.6   root     1895: 
1.1.1.7   root     1896:                if (lw == IDC_PREFS_KEYFILE_SETTINGS)
                   1897:                {
                   1898:                        KeyfileDefaultsDlg (hwndDlg);
                   1899:                        return 1;
                   1900:                }
                   1901: 
                   1902:                if (HIWORD (wParam) == BN_CLICKED)
                   1903:                {
                   1904:                        PreferencesDlgEnableButtons (hwndDlg);
                   1905:                        return 1;
                   1906:                }
                   1907: 
                   1908:                return 0;
                   1909:        }
                   1910: 
                   1911:        return 0;
                   1912: }
                   1913: 
                   1914: 
1.1.1.12  root     1915: BOOL CALLBACK
1.1.1.7   root     1916: MountOptionsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                   1917: {
                   1918:        static MountOptions *mountOptions;
                   1919: 
                   1920:        WORD lw = LOWORD (wParam);
                   1921: 
                   1922:        switch (msg)
                   1923:        {
                   1924:        case WM_INITDIALOG:
                   1925:                {
                   1926:                        BOOL protect;
                   1927:                        
                   1928:                        mountOptions = (MountOptions *) lParam;
                   1929: 
                   1930:                        LocalizeDialog (hwndDlg, "IDD_MOUNT_OPTIONS");
                   1931:                
                   1932:                        SendDlgItemMessage (hwndDlg, IDC_MOUNT_READONLY, BM_SETCHECK,
                   1933:                                mountOptions->ReadOnly ? BST_CHECKED : BST_UNCHECKED, 0);
                   1934:                        SendDlgItemMessage (hwndDlg, IDC_MOUNT_REMOVABLE, BM_SETCHECK,
                   1935:                                mountOptions->Removable ? BST_CHECKED : BST_UNCHECKED, 0);
                   1936:                        SendDlgItemMessage (hwndDlg, IDC_PROTECT_HIDDEN_VOL, BM_SETCHECK,
                   1937:                                mountOptions->ProtectHiddenVolume ? BST_CHECKED : BST_UNCHECKED, 0);
                   1938: 
                   1939:                        protect = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL));
                   1940: 
                   1941:                        EnableWindow (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
                   1942:                        EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_VOL_PROTECTION), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
                   1943:                        EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), protect);
                   1944:                        EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_MO), protect);
                   1945:                        EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_PROT_PASSWD), protect);
                   1946:                        EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_HIDVOL_PROT), protect && hidVolProtKeyFilesParam.EnableKeyFiles);
                   1947:                        EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT), protect);
                   1948: 
                   1949:                        SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT, hidVolProtKeyFilesParam.EnableKeyFiles);
                   1950: 
1.1.1.8   root     1951:                        SendDlgItemMessage (hwndDlg, IDC_PASSWORD_PROT_HIDVOL, EM_LIMITTEXT, MAX_PASSWORD, 0);
                   1952: 
1.1.1.7   root     1953:                        if (mountOptions->ProtectedHidVolPassword.Length > 0)
1.1.1.13! root     1954:                                SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), (LPSTR) mountOptions->ProtectedHidVolPassword.Text);     
1.1.1.11  root     1955:                        
                   1956:                        ToHyperlink (hwndDlg, IDC_LINK_HIDVOL_PROTECTION_INFO);
1.1.1.7   root     1957: 
                   1958:                }
1.1.1.13! root     1959:                return 0;
1.1.1.7   root     1960: 
                   1961:        case WM_COMMAND:
                   1962: 
                   1963:                if (lw == IDC_KEYFILES_HIDVOL_PROT)
                   1964:                {
                   1965:                        if (IDOK == DialogBoxParamW (hInst,
                   1966:                                MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
                   1967:                                (DLGPROC) KeyFilesDlgProc, (LPARAM) &hidVolProtKeyFilesParam))
                   1968:                        {
                   1969:                                SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT, hidVolProtKeyFilesParam.EnableKeyFiles);
                   1970:                                EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_HIDVOL_PROT), hidVolProtKeyFilesParam.EnableKeyFiles);
                   1971:                        }
                   1972:                }
                   1973: 
                   1974:                if (lw == IDC_KEYFILES_ENABLE_HIDVOL_PROT)
                   1975:                {
                   1976:                        hidVolProtKeyFilesParam.EnableKeyFiles = GetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT);
                   1977:                        EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_HIDVOL_PROT), hidVolProtKeyFilesParam.EnableKeyFiles);
                   1978: 
                   1979:                        return 0;
                   1980:                }
                   1981: 
                   1982:                if (lw == IDC_SHOW_PASSWORD_MO)
                   1983:                {
                   1984:                        SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL),
                   1985:                                                EM_SETPASSWORDCHAR,
                   1986:                                                GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_MO) ? 0 : '*',
                   1987:                                                0);
                   1988:                        InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), NULL, TRUE);
                   1989:                        return 1;
                   1990:                }
                   1991: 
1.1.1.11  root     1992:                if (lw == IDC_LINK_HIDVOL_PROTECTION_INFO)
                   1993:                {
                   1994:                        Applink ("hiddenvolprotection", TRUE, "");
                   1995:                }
                   1996: 
1.1.1.7   root     1997:                if (lw == IDCANCEL)
                   1998:                {
                   1999:                        char tmp[MAX_PASSWORD+1];
                   2000: 
                   2001:                        // Cleanup
                   2002:                        memset (tmp, 'X', MAX_PASSWORD);
                   2003:                        tmp[MAX_PASSWORD] = 0;
                   2004:                        SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), tmp);    
                   2005: 
                   2006:                        EndDialog (hwndDlg, lw);
                   2007:                        return 1;
                   2008:                }
                   2009: 
                   2010:                if (lw == IDOK)
                   2011:                {
                   2012:                        char tmp[MAX_PASSWORD+1];
                   2013:                        
                   2014:                        mountOptions->ReadOnly = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY));
                   2015:                        mountOptions->Removable = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_REMOVABLE));
                   2016:                        mountOptions->ProtectHiddenVolume = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL));
                   2017: 
                   2018:                        if (mountOptions->ProtectHiddenVolume)
                   2019:                        {
                   2020:                                GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL),
1.1.1.13! root     2021:                                        (LPSTR) mountOptions->ProtectedHidVolPassword.Text,
1.1.1.7   root     2022:                                        sizeof (mountOptions->ProtectedHidVolPassword.Text));
                   2023: 
1.1.1.13! root     2024:                                mountOptions->ProtectedHidVolPassword.Length = strlen ((char *) mountOptions->ProtectedHidVolPassword.Text);
1.1.1.7   root     2025:                        }
                   2026: 
                   2027:                        // Cleanup
                   2028:                        memset (tmp, 'X', MAX_PASSWORD);
                   2029:                        tmp[MAX_PASSWORD] = 0;
                   2030:                        SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), tmp);    
                   2031: 
1.1.1.11  root     2032:                        if ((mountOptions->ProtectHiddenVolume && !bEnableBkgTask)
                   2033:                                && (AskWarnYesNo ("HIDVOL_PROT_BKG_TASK_WARNING") == IDYES))
                   2034:                        {
                   2035:                                bEnableBkgTask = TRUE;
                   2036:                                TaskBarIconAdd (MainDlg);
                   2037:                        }
1.1.1.7   root     2038: 
                   2039:                        EndDialog (hwndDlg, lw);
                   2040:                        return 1;
                   2041:                }
                   2042: 
                   2043:                if (lw == IDC_MOUNT_READONLY || lw == IDC_PROTECT_HIDDEN_VOL)
                   2044:                {
                   2045:                        BOOL protect;
                   2046: 
                   2047:                        if (lw == IDC_MOUNT_READONLY)
                   2048:                        {
                   2049:                                SendDlgItemMessage (hwndDlg, IDC_PROTECT_HIDDEN_VOL, BM_SETCHECK, BST_UNCHECKED, 0);
                   2050:                                EnableWindow (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
                   2051:                                EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_VOL_PROTECTION), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
                   2052:                        }
                   2053: 
                   2054:                        protect = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL));
                   2055: 
                   2056:                        EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), protect);
                   2057:                        EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_PROT_PASSWD), protect);
                   2058:                        EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_MO), protect);
                   2059:                        EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_HIDVOL_PROT), protect && hidVolProtKeyFilesParam.EnableKeyFiles);
                   2060:                        EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT), protect);
                   2061: 
                   2062:                        return 1;
                   2063:                }
                   2064: 
                   2065:                return 0;
                   2066:        }
                   2067: 
                   2068:        return 0;
                   2069: }
                   2070: 
                   2071: 
1.1.1.11  root     2072: // Returns the block size (in bits) of the cipher with which the volume mounted as the
                   2073: // specified drive letter is encrypted. In case of a cascade of ciphers with different
                   2074: // block sizes the function returns the smallest block size.
                   2075: int GetCipherBlockSizeByDriveNo (int nDosDriveNo)
                   2076: {
                   2077:        VOLUME_PROPERTIES_STRUCT prop;
                   2078:        DWORD dwResult;
                   2079: 
                   2080:        int blockSize = 0, cipherID;
                   2081: 
                   2082:        memset (&prop, 0, sizeof(prop));
                   2083:        prop.driveNo = nDosDriveNo;
                   2084: 
1.1.1.13! root     2085:        if (DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop, sizeof (prop), &prop, sizeof (prop), &dwResult, NULL))
1.1.1.11  root     2086:        {
                   2087:                for (cipherID = EAGetLastCipher (prop.ea);
                   2088:                        cipherID != 0;
                   2089:                        cipherID = EAGetPreviousCipher (prop.ea, cipherID))
                   2090:                {
                   2091:                        if (blockSize > 0)
                   2092:                                blockSize = min (blockSize, CipherGetBlockSize (cipherID) * 8);
                   2093:                        else
                   2094:                                blockSize = CipherGetBlockSize (cipherID) * 8;
                   2095:                }
                   2096:        }
                   2097: 
1.1.1.13! root     2098:        return blockSize;
        !          2099: }
        !          2100: 
        !          2101: 
        !          2102: // Returns the mode of operation in which the volume mounted as the specified drive letter is encrypted. 
        !          2103: int GetModeOfOperationByDriveNo (int nDosDriveNo)
        !          2104: {
        !          2105:        VOLUME_PROPERTIES_STRUCT prop;
        !          2106:        DWORD dwResult;
        !          2107: 
        !          2108:        memset (&prop, 0, sizeof(prop));
        !          2109:        prop.driveNo = nDosDriveNo;
        !          2110: 
        !          2111:        if (DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop, sizeof (prop), &prop, sizeof (prop), &dwResult, NULL))
        !          2112:        {
        !          2113:                return prop.mode;
        !          2114:        }
        !          2115: 
        !          2116:        return 0;
1.1.1.11  root     2117: }
                   2118: 
                   2119: 
1.1.1.13! root     2120: BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1.1.1.7   root     2121: {
1.1.1.13! root     2122:        BOOL bSysEnc = (BOOL) lParam;
        !          2123:        BOOL bSysEncWholeDrive = FALSE;
1.1       root     2124:        WORD lw = LOWORD (wParam);
1.1.1.7   root     2125:        int i = 0;
1.1       root     2126: 
                   2127:        switch (msg)
                   2128:        {
                   2129:        case WM_INITDIALOG:
                   2130:                {
                   2131:                        VOLUME_PROPERTIES_STRUCT prop;
                   2132:                        DWORD dwResult;
                   2133: 
1.1.1.7   root     2134:                        LVCOLUMNW lvCol;
1.1       root     2135:                        HWND list = GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES_LIST);
1.1.1.7   root     2136:                        char szTmp[1024];
                   2137:                        wchar_t sw[1024];
                   2138:                        wchar_t *s;
1.1       root     2139: 
1.1.1.13! root     2140:                        if (bSysEnc)
        !          2141:                        {
        !          2142:                                try
        !          2143:                                {
        !          2144:                                        BootEncStatus = BootEncObj->GetStatus();
        !          2145:                                        bSysEncWholeDrive = WholeSysDriveEncryption(FALSE);
        !          2146:                                }
        !          2147:                                catch (Exception &e)
        !          2148:                                {
        !          2149:                                        e.Show (MainDlg);
        !          2150:                                        return 0;
        !          2151:                                }
        !          2152: 
        !          2153:                                if (!BootEncStatus.DriveEncrypted && !BootEncStatus.DriveMounted)
        !          2154:                                        return 0;
        !          2155:                        }
        !          2156:                        else
        !          2157:                        {
        !          2158:                                switch (LOWORD (GetSelectedLong (GetDlgItem (GetParent(hwndDlg), IDC_DRIVELIST))))
        !          2159:                                {
        !          2160:                                case TC_MLIST_ITEM_FREE:
        !          2161: 
        !          2162:                                        // No mounted volume
        !          2163:                                        EndDialog (hwndDlg, IDOK);
        !          2164:                                        return 0;
        !          2165: 
        !          2166:                                case TC_MLIST_ITEM_NONSYS_VOL:
        !          2167:                                        // NOP
        !          2168:                                        break;
        !          2169: 
        !          2170:                                case TC_MLIST_ITEM_SYS_DRIVE:
        !          2171:                                        // Encrypted system drive
        !          2172:                                        bSysEnc = TRUE;
        !          2173:                                        bSysEncWholeDrive = TRUE;
        !          2174:                                        break;
        !          2175: 
        !          2176:                                case TC_MLIST_ITEM_SYS_PARTITION:
        !          2177:                                        // Encrypted system partition
        !          2178:                                        bSysEnc = TRUE;
        !          2179:                                        bSysEncWholeDrive = FALSE;
        !          2180:                                        break;
        !          2181:                                }
        !          2182:                        }
        !          2183: 
1.1.1.7   root     2184:                        LocalizeDialog (hwndDlg, "IDD_VOLUME_PROPERTIES");
1.1       root     2185: 
1.1.1.7   root     2186:                        SendMessage (list,LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
1.1       root     2187:                                LVS_EX_FULLROWSELECT
1.1.1.7   root     2188:                                |LVS_EX_HEADERDRAGDROP
                   2189:                                |LVS_EX_LABELTIP
1.1       root     2190:                                ); 
                   2191: 
                   2192:                        memset (&lvCol,0,sizeof(lvCol));               
                   2193:                        lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;  
1.1.1.7   root     2194:                        lvCol.pszText = GetString ("VALUE");                           
1.1.1.12  root     2195:                        lvCol.cx = CompensateXDPI (208);
1.1       root     2196:                        lvCol.fmt = LVCFMT_LEFT ;
1.1.1.7   root     2197:                        SendMessage (list,LVM_INSERTCOLUMNW,0,(LPARAM)&lvCol);
1.1       root     2198: 
1.1.1.7   root     2199:                        lvCol.pszText = GetString ("PROPERTY");  
1.1.1.12  root     2200:                        lvCol.cx = CompensateXDPI (192);           
1.1       root     2201:                        lvCol.fmt = LVCFMT_LEFT;
1.1.1.7   root     2202:                        SendMessage (list,LVM_INSERTCOLUMNW,0,(LPARAM)&lvCol);
1.1       root     2203:        
                   2204:                        memset (&prop, 0, sizeof(prop));
                   2205:                        prop.driveNo = HIWORD (GetSelectedLong (GetDlgItem (GetParent(hwndDlg), IDC_DRIVELIST))) - 'A';
                   2206: 
1.1.1.13! root     2207:                        if (bSysEnc)
        !          2208:                        {
        !          2209:                                try
        !          2210:                                {
        !          2211:                                        BootEncStatus = BootEncObj->GetStatus();
        !          2212:                                        if (!BootEncStatus.DriveEncrypted && !BootEncStatus.DriveMounted)
        !          2213:                                                return 0;
        !          2214: 
        !          2215:                                        BootEncObj->GetVolumeProperties (&prop);
        !          2216:                                }
        !          2217:                                catch (Exception &e)
        !          2218:                                {
        !          2219:                                        e.Show (MainDlg);
        !          2220:                                        return 0;
        !          2221:                                }
        !          2222:                        }
        !          2223:                        else
        !          2224:                        {
        !          2225:                                if (!DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop, sizeof (prop), &prop, sizeof (prop), &dwResult, NULL) || dwResult == 0)
        !          2226:                                        return 0;
        !          2227:                        }
1.1.1.11  root     2228: 
1.1.1.7   root     2229:                        // Location
                   2230:                        ListItemAddW (list, i, GetString ("LOCATION"));
1.1.1.13! root     2231:                        if (bSysEnc)
        !          2232:                                ListSubItemSetW (list, i++, 1, GetString (bSysEncWholeDrive ? "SYSTEM_DRIVE" : "SYSTEM_PARTITION"));
        !          2233:                        else
        !          2234:                                ListSubItemSetW (list, i++, 1, (wchar_t *) (prop.wszVolume[1] != L'?' ? prop.wszVolume : prop.wszVolume + 4));
1.1.1.7   root     2235: 
                   2236:                        // Size
                   2237:                        ListItemAddW (list, i, GetString ("SIZE"));
                   2238:                        swprintf (sw, L"%I64u %s", prop.diskLength, GetString ("BYTES"));
                   2239:                        ListSubItemSetW (list, i++, 1, sw);
                   2240: 
                   2241:                        // Type
                   2242:                        ListItemAddW (list, i, GetString ("TYPE"));
1.1.1.13! root     2243:                        if (bSysEnc)
        !          2244:                                ListSubItemSetW (list, i++, 1, GetString ("SYSTEM_VOLUME_TYPE_ADJECTIVE"));
        !          2245:                        else
        !          2246:                        {
        !          2247:                                ListSubItemSetW (list, i++, 1, 
        !          2248:                                        prop.hiddenVolume ? GetString ("HIDDEN") : 
        !          2249:                                        (prop.hiddenVolProtection != HIDVOL_PROT_STATUS_NONE ? GetString ("OUTER") : GetString ("NORMAL")));
        !          2250:                        }
1.1.1.7   root     2251:                        
1.1.1.13! root     2252:                        if (!bSysEnc)
        !          2253:                        {
        !          2254:                                // Write protection
        !          2255:                                ListItemAddW (list, i, GetString ("READ_ONLY"));
1.1       root     2256: 
1.1.1.13! root     2257:                                if (prop.readOnly || prop.hiddenVolProtection == HIDVOL_PROT_STATUS_ACTION_TAKEN)
        !          2258:                                        s = GetString ("UISTR_YES");
        !          2259:                                else
        !          2260:                                        s = GetString ("UISTR_NO");
1.1       root     2261: 
1.1.1.13! root     2262:                                ListSubItemSetW (list, i++, 1, s);
1.1       root     2263: 
1.1.1.13! root     2264:                                // Hidden Volume Protection
        !          2265:                                ListItemAddW (list, i, GetString ("HIDDEN_VOL_PROTECTION"));
        !          2266:                                if (prop.hiddenVolume)
        !          2267:                                        s = GetString ("N_A_UISTR");
        !          2268:                                else if (prop.hiddenVolProtection == HIDVOL_PROT_STATUS_NONE)
        !          2269:                                        s = GetString ("UISTR_NO");
        !          2270:                                else if (prop.hiddenVolProtection == HIDVOL_PROT_STATUS_ACTIVE)
        !          2271:                                        s = GetString ("UISTR_YES");
        !          2272:                                else if (prop.hiddenVolProtection == HIDVOL_PROT_STATUS_ACTION_TAKEN)
        !          2273:                                        s = GetString ("HID_VOL_DAMAGE_PREVENTED");
1.1.1.6   root     2274: 
1.1.1.13! root     2275:                                ListSubItemSetW (list, i++, 1, s);
        !          2276:                        }
1.1       root     2277: 
1.1.1.7   root     2278:                        // Encryption algorithm
                   2279:                        ListItemAddW (list, i, GetString ("ENCRYPTION_ALGORITHM"));
1.1.1.11  root     2280: 
                   2281:                        if (prop.ea == 0 || prop.ea > EAGetCount ())
                   2282:                        {
                   2283:                                ListSubItemSet (list, i, 1, "?");
                   2284:                                return 1;
                   2285:                        }
                   2286: 
1.1.1.7   root     2287:                        EAGetName (szTmp, prop.ea);
                   2288:                        ListSubItemSet (list, i++, 1, szTmp);
1.1.1.5   root     2289: 
1.1.1.7   root     2290:                        // Key size
                   2291:                        {
                   2292:                                char name[128];
                   2293:                                int size = EAGetKeySize (prop.ea);      
                   2294:                                EAGetName (name, prop.ea);
                   2295: 
1.1.1.12  root     2296:                                if (strcmp (name, "Triple DES") == 0)   /* Deprecated/legacy */
1.1.1.7   root     2297:                                        size -= 3; // Compensate for parity bytes
                   2298: 
                   2299:                                ListItemAddW (list, i, GetString ("KEY_SIZE"));
                   2300:                                wsprintfW (sw, L"%d %s", size * 8, GetString ("BITS"));
                   2301:                                ListSubItemSetW (list, i++, 1, sw);
                   2302:                        }
1.1.1.5   root     2303: 
1.1.1.7   root     2304:                        // Block size
                   2305:                        ListItemAddW (list, i, GetString ("BLOCK_SIZE"));
1.1.1.8   root     2306:                        if (EAGetFirstMode (prop.ea) == INNER_CBC)
1.1.1.5   root     2307:                        {
1.1.1.8   root     2308:                                // Cascaded ciphers with non-equal block sizes  (deprecated/legacy)
                   2309:                                wchar_t tmpstr[64];
1.1.1.5   root     2310:                                int i = EAGetLastCipher(prop.ea);
                   2311: 
1.1.1.7   root     2312:                                swprintf (sw, L"%d", CipherGetBlockSize(i)*8);
1.1.1.5   root     2313:                                
                   2314:                                while (i = EAGetPreviousCipher(prop.ea, i))
                   2315:                                {
1.1.1.7   root     2316:                                        swprintf (tmpstr, L"/%d", CipherGetBlockSize(i)*8);
                   2317:                                        wcscat (sw, tmpstr);
1.1.1.5   root     2318:                                }
1.1.1.7   root     2319:                                wcscat (sw, L" ");
1.1.1.5   root     2320:                        }
                   2321:                        else
                   2322:                        {
1.1.1.7   root     2323:                                swprintf (sw, L"%d ", CipherGetBlockSize (EAGetFirstCipher(prop.ea))*8);
1.1.1.5   root     2324:                        }
1.1.1.7   root     2325:                        wcscat (sw, GetString ("BITS"));
                   2326:                        ListSubItemSetW (list, i++, 1, sw);
1.1.1.5   root     2327: 
1.1.1.7   root     2328:                        // Mode
                   2329:                        ListItemAddW (list, i, GetString ("MODE_OF_OPERATION"));
1.1.1.8   root     2330:                        ListSubItemSet (list, i++, 1, EAGetModeName (prop.ea, prop.mode, TRUE));
1.1.1.7   root     2331: 
                   2332:                        // PRF
                   2333:                        ListItemAddW (list, i, GetString ("PKCS5_PRF"));
                   2334:                        ListSubItemSet (list, i++, 1, get_pkcs5_prf_name (prop.pkcs5));
1.1       root     2335: 
1.1.1.7   root     2336:                        // PCKS iterations
                   2337:                        ListItemAddW (list, i, GetString ("PKCS5_ITERATIONS"));
1.1       root     2338:                        sprintf (szTmp, "%d", prop.pkcs5Iterations);
1.1.1.7   root     2339:                        ListSubItemSet (list, i++, 1, szTmp);
                   2340: 
1.1       root     2341:                        {
                   2342:                                FILETIME ft, curFt;
1.1.1.12  root     2343:                                LARGE_INTEGER ft64, curFt64;
1.1       root     2344:                                SYSTEMTIME st;
1.1.1.7   root     2345:                                wchar_t date[128];
1.1       root     2346:                                memset (date, 0, sizeof (date));
                   2347: 
1.1.1.7   root     2348:                                // Volume date
                   2349:                                ListItemAddW (list, i, GetString ("VOLUME_CREATE_DATE"));
1.1       root     2350:                                *(unsigned __int64 *)(&ft) = prop.volumeCreationTime;
                   2351:                                FileTimeToSystemTime (&ft, &st);
1.1.1.7   root     2352:                                GetDateFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
                   2353:                                swprintf (date, L"%s ", sw);
                   2354:                                GetTimeFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
                   2355:                                wcscat (date, sw);
                   2356:                                ListSubItemSetW (list, i++, 1, date);
1.1       root     2357: 
1.1.1.7   root     2358:                                // Header date
                   2359:                                ListItemAddW (list, i, GetString ("VOLUME_HEADER_DATE"));
1.1       root     2360:                                *(unsigned __int64 *)(&ft) = prop.headerCreationTime;
                   2361:                                FileTimeToSystemTime (&ft, &st);
1.1.1.7   root     2362:                                GetDateFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
                   2363:                                swprintf (date, L"%s ", sw);
                   2364:                                GetTimeFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
                   2365:                                wcscat (date, sw);
1.1       root     2366: 
                   2367:                                GetLocalTime (&st);
                   2368:                                SystemTimeToFileTime (&st, &curFt);
1.1.1.12  root     2369:                                curFt64.HighPart = curFt.dwHighDateTime;
                   2370:                                curFt64.LowPart = curFt.dwLowDateTime;
                   2371:                                ft64.HighPart = ft.dwHighDateTime;
                   2372:                                ft64.LowPart = ft.dwLowDateTime;
1.1.1.7   root     2373:                                swprintf (date + wcslen (date),  GetString ("VOLUME_HEADER_DAYS")
1.1.1.12  root     2374:                                        , (curFt64.QuadPart - ft64.QuadPart)/(24LL*3600*10000000));
1.1.1.7   root     2375:                                ListSubItemSetW (list, i++, 1, date);
1.1       root     2376:                        }
                   2377: 
1.1.1.7   root     2378:                        // Total data read
                   2379:                        ListItemAddW (list, i, GetString ("TOTAL_DATA_READ"));
                   2380:                        GetSizeString (prop.totalBytesRead, sw);
                   2381:                        ListSubItemSetW (list, i++, 1, sw);
                   2382: 
                   2383:                        // Total data written
                   2384:                        ListItemAddW (list, i, GetString ("TOTAL_DATA_WRITTEN"));
                   2385:                        GetSizeString (prop.totalBytesWritten, sw);
                   2386:                        ListSubItemSetW (list, i++, 1, sw);
                   2387: 
1.1.1.13! root     2388:                        if (bSysEnc)
        !          2389:                        {
        !          2390:                                // Encrypted portion
        !          2391:                                ListItemAddW (list, i, GetString ("ENCRYPTED_PORTION"));
        !          2392:                                if (GetSysEncDeviceEncryptedPartSize (FALSE) == GetSysEncDeviceSize (FALSE))
        !          2393:                                        ListSubItemSetW (list, i++, 1, GetString ("ENCRYPTED_PORTION_FULLY_ENCRYPTED"));
        !          2394:                                else if (GetSysEncDeviceEncryptedPartSize (FALSE) <= 1)
        !          2395:                                        ListSubItemSetW (list, i++, 1, GetString ("ENCRYPTED_PORTION_NOT_ENCRYPTED"));
        !          2396:                                else
        !          2397:                                {
        !          2398: 
        !          2399:                                        _snwprintf (sw, 
        !          2400:                                                sizeof sw/2,
        !          2401:                                                GetString ("PROCESSED_PORTION_X_PERCENT"),
        !          2402:                                                (double) GetSysEncDeviceEncryptedPartSize (FALSE) / (double) GetSysEncDeviceSize (FALSE) * 100.0);
        !          2403: 
        !          2404:                                        ListSubItemSetW (list, i++, 1, sw);
        !          2405:                                }
        !          2406:                        }
        !          2407: 
        !          2408:                        return 0;
1.1       root     2409:                }
                   2410: 
                   2411:        case WM_COMMAND:
                   2412:                if (lw == IDOK)
                   2413:                {
                   2414:                        EndDialog (hwndDlg, lw);
                   2415:                        return 1;
                   2416:                }
                   2417:                return 0;
1.1.1.9   root     2418: 
                   2419:        case WM_CLOSE:
                   2420:                EndDialog (hwndDlg, lw);
                   2421:                return 1;
1.1       root     2422:        }
                   2423: 
                   2424:        return 0;
                   2425: }
                   2426: 
1.1.1.6   root     2427: 
1.1.1.12  root     2428: BOOL CALLBACK
1.1.1.13! root     2429: TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1.1.1.6   root     2430: {
                   2431:        WORD lw = LOWORD (wParam);
                   2432: 
                   2433:        switch (msg)
                   2434:        {
                   2435:        case WM_INITDIALOG:
                   2436:                {
                   2437:                        int i, index;
                   2438:                        char drive[] = { 0, ':', 0 };
                   2439: 
1.1.1.13! root     2440:                        LocalizeDialog (hwndDlg, "IDD_TRAVELER_DLG");
1.1.1.6   root     2441: 
                   2442:                        SendDlgItemMessage (hwndDlg, IDC_COPY_WIZARD, BM_SETCHECK, 
                   2443:                                                BST_CHECKED, 0);
                   2444: 
1.1.1.7   root     2445:                        SendDlgItemMessage (hwndDlg, IDC_TRAVEL_OPEN_EXPLORER, BM_SETCHECK, 
1.1.1.6   root     2446:                                                BST_CHECKED, 0);
                   2447: 
                   2448:                        SendDlgItemMessage (hwndDlg, IDC_AUTORUN_DISABLE, BM_SETCHECK, 
                   2449:                                                BST_CHECKED, 0);
                   2450: 
                   2451:                        SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_RESETCONTENT, 0, 0);
                   2452: 
1.1.1.7   root     2453:                        index = SendDlgItemMessageW (hwndDlg, IDC_DRIVELIST, CB_ADDSTRING, 0, (LPARAM) GetString ("FIRST_AVAILABLE"));
1.1.1.6   root     2454:                        SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETITEMDATA, index, (LPARAM) 0);
                   2455: 
1.1.1.11  root     2456:                        for (i = 'D'; i <= 'Z'; i++)
1.1.1.6   root     2457:                        {
                   2458:                                drive[0] = i;
                   2459:                                index = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_ADDSTRING, 0, (LPARAM) drive);
                   2460:                                SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETITEMDATA, index, (LPARAM) i);
                   2461:                        }
                   2462:                
                   2463:                        SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETCURSEL, 0, 0);
                   2464: 
1.1.1.13! root     2465:                        return 0;
1.1.1.6   root     2466:                }
                   2467: 
1.1.1.7   root     2468: 
1.1.1.6   root     2469:        case WM_COMMAND:
                   2470: 
1.1.1.7   root     2471:                if (HIWORD (wParam) == BN_CLICKED
                   2472:                        && (lw == IDC_AUTORUN_DISABLE || lw == IDC_AUTORUN_MOUNT || lw == IDC_AUTORUN_START ))
                   2473:                {
1.1.1.11  root     2474:                        BOOL enabled = IsButtonChecked (GetDlgItem (hwndDlg, IDC_AUTORUN_MOUNT));
1.1.1.7   root     2475:                        
                   2476:                        EnableWindow (GetDlgItem (hwndDlg, IDC_BROWSE_FILES), enabled);
                   2477:                        EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_NAME), enabled);
                   2478:                        EnableWindow (GetDlgItem (hwndDlg, IDC_TRAVEL_OPEN_EXPLORER), enabled);
                   2479:                        EnableWindow (GetDlgItem (hwndDlg, IDC_TRAV_CACHE_PASSWORDS), enabled);
                   2480:                        EnableWindow (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY), enabled);
                   2481:                        EnableWindow (GetDlgItem (hwndDlg, IDC_DRIVELIST), enabled);
1.1.1.13! root     2482:                        EnableWindow (GetDlgItem (hwndDlg, IDT_TRAVELER_MOUNT), enabled);
1.1.1.7   root     2483:                        EnableWindow (GetDlgItem (hwndDlg, IDT_MOUNT_LETTER), enabled);
                   2484:                        EnableWindow (GetDlgItem (hwndDlg, IDT_MOUNT_SETTINGS), enabled);
                   2485: 
                   2486:                        return 1;
                   2487:                }
                   2488: 
1.1.1.6   root     2489:                if (lw == IDC_BROWSE_FILES)
                   2490:                {
1.1.1.11  root     2491:                        char dstDir[MAX_PATH];
1.1.1.7   root     2492:                        char volName[MAX_PATH] = { 0 };
1.1.1.6   root     2493: 
1.1.1.11  root     2494:                        GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstDir, sizeof dstDir);
                   2495: 
                   2496:                        if (BrowseFilesInDir (hwndDlg, "OPEN_TITLE", dstDir, volName, bHistory, FALSE))
1.1.1.6   root     2497:                                SetDlgItemText (hwndDlg, IDC_VOLUME_NAME, strchr (volName, '\\') + 1);
1.1.1.7   root     2498: 
1.1.1.6   root     2499:                        return 1;
                   2500:                }
                   2501: 
                   2502:                if (lw == IDC_BROWSE_DIRS)
                   2503:                {
                   2504:                        char dstPath[MAX_PATH * 2];
1.1.1.7   root     2505:                        GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstPath, sizeof dstPath);
1.1.1.6   root     2506: 
1.1.1.7   root     2507:                        if (BrowseDirectories (hwndDlg, "SELECT_DEST_DIR", dstPath))
1.1.1.6   root     2508:                                SetDlgItemText (hwndDlg, IDC_DIRECTORY, dstPath);
1.1.1.7   root     2509: 
1.1.1.6   root     2510:                        return 1;
                   2511:                }
                   2512: 
1.1.1.11  root     2513:                if (lw == IDCANCEL || lw == IDCLOSE)
1.1.1.6   root     2514:                {
                   2515:                        EndDialog (hwndDlg, lw);
                   2516:                        return 1;
                   2517:                }
                   2518: 
1.1.1.7   root     2519:                if (lw == IDC_CREATE)
1.1.1.6   root     2520:                {
1.1.1.13! root     2521: 
1.1.1.6   root     2522:                        BOOL copyWizard, bExplore, bCacheInDriver, bAutoRun, bAutoMount, bMountReadOnly;
                   2523:                        char dstDir[MAX_PATH];
                   2524:                        char srcPath[MAX_PATH * 2];
                   2525:                        char dstPath[MAX_PATH * 2];
                   2526:                        char appDir[MAX_PATH];
                   2527:                        char sysDir[MAX_PATH];
                   2528:                        char volName[MAX_PATH];
                   2529:                        int drive;
                   2530: 
                   2531:                        GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstDir, sizeof dstDir);
                   2532:                        volName[0] = 0;
                   2533:                        GetDlgItemText (hwndDlg, IDC_VOLUME_NAME, volName + 1, sizeof volName);
                   2534:                        
                   2535:                        drive = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_GETCURSEL, 0, 0);
                   2536:                        drive = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_GETITEMDATA, drive, 0);
                   2537: 
                   2538:                        copyWizard = IsButtonChecked (GetDlgItem (hwndDlg, IDC_COPY_WIZARD));
1.1.1.7   root     2539:                        bExplore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_TRAVEL_OPEN_EXPLORER));
                   2540:                        bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_TRAV_CACHE_PASSWORDS));
1.1.1.6   root     2541:                        bMountReadOnly = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY));
                   2542:                        bAutoRun = !IsButtonChecked (GetDlgItem (hwndDlg, IDC_AUTORUN_DISABLE));
                   2543:                        bAutoMount = IsButtonChecked (GetDlgItem (hwndDlg, IDC_AUTORUN_MOUNT));
                   2544: 
                   2545:                        if (dstDir[0] == 0)
                   2546:                        {
                   2547:                                SetFocus (GetDlgItem (hwndDlg, IDC_DIRECTORY));
1.1.1.7   root     2548:                                MessageBoxW (hwndDlg, GetString ("NO_PATH_SELECTED"), lpszTitle, MB_ICONEXCLAMATION);
1.1.1.6   root     2549:                                return 1;
                   2550:                        }
                   2551: 
                   2552:                        
                   2553:                        if (bAutoMount && volName[1] == 0)
                   2554:                        {
                   2555:                                SetFocus (GetDlgItem (hwndDlg, IDC_VOLUME_NAME));
1.1.1.7   root     2556:                                MessageBoxW (hwndDlg, GetString ("NO_FILE_SELECTED"), lpszTitle, MB_ICONEXCLAMATION);
1.1.1.6   root     2557:                                return 1;
                   2558:                        }
                   2559: 
                   2560:                        if (volName[1] != 0)
                   2561:                        {
                   2562:                                volName[0] = '"';
                   2563:                                strcat (volName, "\"");
                   2564:                        }
                   2565: 
                   2566:                        GetModuleFileName (NULL, appDir, sizeof (appDir));
                   2567:                        strrchr (appDir, '\\')[0] = 0;
                   2568: 
1.1.1.11  root     2569:                        WaitCursor ();
1.1.1.6   root     2570:                        GetSystemDirectory (sysDir, sizeof (sysDir));
                   2571: 
                   2572:                        sprintf (dstPath, "%s\\TrueCrypt", dstDir);
                   2573:                        CreateDirectory (dstPath, NULL);
                   2574: 
                   2575:                        // Main app
                   2576:                        sprintf (srcPath, "%s\\TrueCrypt.exe", appDir);
                   2577:                        sprintf (dstPath, "%s\\TrueCrypt\\TrueCrypt.exe", dstDir);
                   2578:                        if (!TCCopyFile (srcPath, dstPath))
                   2579:                        {
                   2580:                                handleWin32Error (hwndDlg);
                   2581:                                goto stop;
                   2582:                        }
                   2583: 
                   2584:                        // Wizard
                   2585:                        if (copyWizard)
                   2586:                        {
                   2587:                                sprintf (srcPath, "%s\\TrueCrypt Format.exe", appDir);
                   2588:                                sprintf (dstPath, "%s\\TrueCrypt\\TrueCrypt Format.exe", dstDir);
                   2589:                                if (!TCCopyFile (srcPath, dstPath))
                   2590:                                {
                   2591:                                        handleWin32Error (hwndDlg);
                   2592:                                        goto stop;
                   2593:                                }
                   2594:                        }
                   2595: 
                   2596:                        // Driver
1.1.1.7   root     2597:                        sprintf (srcPath, "%s\\truecrypt.sys", appDir);
1.1.1.6   root     2598:                        sprintf (dstPath, "%s\\TrueCrypt\\truecrypt.sys", dstDir);
                   2599:                        if (!TCCopyFile (srcPath, dstPath))
                   2600:                        {
                   2601:                                handleWin32Error (hwndDlg);
                   2602:                                goto stop;
                   2603:                        }
                   2604: 
1.1.1.7   root     2605:                        // Driver x64
                   2606:                        sprintf (srcPath, "%s\\truecrypt-x64.sys", appDir);
                   2607:                        sprintf (dstPath, "%s\\TrueCrypt\\truecrypt-x64.sys", dstDir);
                   2608:                        if (!TCCopyFile (srcPath, dstPath))
                   2609:                        {
                   2610:                                handleWin32Error (hwndDlg);
                   2611:                                goto stop;
                   2612:                        }
                   2613: 
1.1.1.11  root     2614:                        if (GetPreferredLangId () && strcmp (GetPreferredLangId (), "en") != 0)
                   2615:                        {
                   2616:                                // Language pack
                   2617:                                sprintf (srcPath, "%s\\Language.%s.xml", appDir, GetPreferredLangId ());
                   2618:                                sprintf (dstPath, "%s\\TrueCrypt\\Language.%s.xml", dstDir, GetPreferredLangId ());
                   2619:                                TCCopyFile (srcPath, dstPath);
                   2620:                        }
                   2621: 
1.1.1.6   root     2622:                        // AutoRun
1.1.1.12  root     2623:                        sprintf (dstPath, "%s\\autorun.inf", dstDir);
                   2624:                        DeleteFile (dstPath);
1.1.1.6   root     2625:                        if (bAutoRun)
                   2626:                        {
                   2627:                                FILE *af;
                   2628:                                char autoMount[100];
                   2629:                                char driveLetter[] = { ' ', '/', 'l', drive, 0 };
                   2630: 
1.1.1.11  root     2631:                                af = fopen (dstPath, "w,ccs=UNICODE");
1.1.1.6   root     2632: 
                   2633:                                if (af == NULL)
                   2634:                                {
1.1.1.7   root     2635:                                        MessageBoxW (hwndDlg, GetString ("CANT_CREATE_AUTORUN"), lpszTitle, MB_ICONERROR);
1.1.1.6   root     2636:                                        goto stop;
                   2637:                                }
                   2638: 
1.1.1.11  root     2639:                                sprintf (autoMount, "TrueCrypt\\TrueCrypt.exe /q background%s%s%s%s /m rm /v %s",
1.1.1.6   root     2640:                                        drive > 0 ? driveLetter : "",
                   2641:                                        bExplore ? " /e" : "",
1.1.1.11  root     2642:                                        bCacheInDriver ? " /c y" : "",
1.1.1.6   root     2643:                                        bMountReadOnly ? " /m ro" : "",
                   2644:                                        volName);
                   2645: 
1.1.1.13! root     2646:                                fwprintf (af, L"[autorun]\nlabel=%s\nicon=TrueCrypt\\TrueCrypt.exe\n", GetString ("TC_TRAVELER_DISK"));
1.1.1.11  root     2647:                                fwprintf (af, L"action=%s\n", bAutoMount ? GetString ("MOUNT_TC_VOLUME") : GetString ("IDC_PREF_LOGON_START"));
                   2648:                                fwprintf (af, L"open=%hs\n", bAutoMount ? autoMount : "TrueCrypt\\TrueCrypt.exe");
                   2649:                                fwprintf (af, L"shell\\start=%s\nshell\\start\\command=TrueCrypt\\TrueCrypt.exe\n", GetString ("IDC_PREF_LOGON_START"));
                   2650:                                fwprintf (af, L"shell\\dismount=%s\nshell\\dismount\\command=TrueCrypt\\TrueCrypt.exe /q /d\n", GetString ("DISMOUNT_ALL_TC_VOLUMES"));
1.1.1.6   root     2651: 
                   2652:                                fclose (af);
                   2653:                        }
1.1.1.13! root     2654:                        MessageBoxW (hwndDlg, GetString ("TRAVELER_DISK_CREATED"), lpszTitle, MB_ICONINFORMATION);
1.1.1.6   root     2655: 
                   2656: stop:
                   2657:                        NormalCursor ();
                   2658:                        return 1;
                   2659:                }
                   2660:                return 0;
                   2661:        }
                   2662: 
                   2663:        return 0;
                   2664: }
                   2665: 
                   2666: 
1.1       root     2667: void
                   2668: BuildTree (HWND hTree)
                   2669: {
                   2670:        HIMAGELIST hList;
                   2671:        HBITMAP hBitmap, hBitmapMask;
1.1.1.7   root     2672:        LVCOLUMNW lvCol;
                   2673: 
                   2674:        ListView_DeleteColumn (hTree,0);
                   2675:        ListView_DeleteColumn (hTree,0);
                   2676:        ListView_DeleteColumn (hTree,0);
                   2677:        ListView_DeleteColumn (hTree,0);
                   2678:        ListView_DeleteColumn (hTree,0);
                   2679:        ListView_DeleteColumn (hTree,0);
                   2680: 
1.1       root     2681:        SendMessage(hTree,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
                   2682:                LVS_EX_FULLROWSELECT
                   2683:                |LVS_EX_HEADERDRAGDROP 
                   2684:                ); 
                   2685: 
                   2686:        memset(&lvCol,0,sizeof(lvCol)); 
                   2687: 
                   2688:        lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;  
1.1.1.7   root     2689:        lvCol.pszText = GetString ("DRIVE");                           
1.1.1.12  root     2690:        lvCol.cx = CompensateXDPI (38);
1.1       root     2691:        lvCol.fmt = LVCFMT_COL_HAS_IMAGES|LVCFMT_LEFT ;
1.1.1.7   root     2692:        SendMessage (hTree,LVM_INSERTCOLUMNW,0,(LPARAM)&lvCol);
1.1       root     2693: 
1.1.1.7   root     2694:        lvCol.pszText = GetString ("VOLUME");  
1.1.1.12  root     2695:        lvCol.cx = CompensateXDPI (253);           
1.1       root     2696:        lvCol.fmt = LVCFMT_LEFT;
1.1.1.7   root     2697:        SendMessage (hTree,LVM_INSERTCOLUMNW,1,(LPARAM)&lvCol);
1.1       root     2698: 
1.1.1.7   root     2699:        lvCol.pszText = GetString ("SIZE");  
1.1.1.12  root     2700:        lvCol.cx = CompensateXDPI (55);
1.1       root     2701:        lvCol.fmt = LVCFMT_RIGHT;
1.1.1.7   root     2702:        SendMessage (hTree,LVM_INSERTCOLUMNW,2,(LPARAM)&lvCol);
1.1       root     2703: 
1.1.1.11  root     2704:        lvCol.pszText = GetString ("ENCRYPTION_ALGORITHM_LV");  
1.1.1.12  root     2705:        lvCol.cx = CompensateXDPI (121);
1.1       root     2706:        lvCol.fmt = LVCFMT_LEFT;
1.1.1.7   root     2707:        SendMessage (hTree,LVM_INSERTCOLUMNW,3,(LPARAM)&lvCol);
1.1       root     2708: 
1.1.1.7   root     2709:        lvCol.pszText = GetString ("TYPE");  
1.1.1.12  root     2710:        lvCol.cx = CompensateXDPI (52);
1.1.1.5   root     2711:        lvCol.fmt = LVCFMT_LEFT;
1.1.1.7   root     2712:        SendMessage (hTree,LVM_INSERTCOLUMNW,4,(LPARAM)&lvCol);
1.1.1.5   root     2713: 
1.1.1.13! root     2714:        // Regular drive icon
        !          2715: 
1.1       root     2716:        hBitmap = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON));
                   2717:        if (hBitmap == NULL)
                   2718:                return;
                   2719:        hBitmapMask = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON_MASK));
                   2720: 
                   2721:        hList = ImageList_Create (16, 12, ILC_COLOR8|ILC_MASK, 2, 2);
                   2722:        if (ImageList_Add (hList, hBitmap, hBitmapMask) == -1)
                   2723:        {
                   2724:                DeleteObject (hBitmap);
1.1.1.13! root     2725:                DeleteObject (hBitmapMask);
        !          2726:                return;
        !          2727:        }
        !          2728:        else
        !          2729:        {
        !          2730:                DeleteObject (hBitmap);
        !          2731:                DeleteObject (hBitmapMask);
        !          2732:        }
        !          2733: 
        !          2734:        // System drive icon
        !          2735: 
        !          2736:        hBitmap = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_SYS_DRIVEICON));
        !          2737:        if (hBitmap == NULL)
        !          2738:                return;
        !          2739:        hBitmapMask = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_SYS_DRIVEICON_MASK));
        !          2740: 
        !          2741:        if (ImageList_Add (hList, hBitmap, hBitmapMask) == -1)
        !          2742:        {
        !          2743:                DeleteObject (hBitmap);
        !          2744:                DeleteObject (hBitmapMask);
1.1       root     2745:                return;
                   2746:        }
                   2747:        else
1.1.1.13! root     2748:        {
1.1       root     2749:                DeleteObject (hBitmap);
1.1.1.13! root     2750:                DeleteObject (hBitmapMask);
        !          2751:        }
1.1       root     2752: 
                   2753:        ListView_SetImageList (hTree, hList, LVSIL_NORMAL); 
                   2754:        ListView_SetImageList (hTree, hList, LVSIL_SMALL);
                   2755: 
                   2756:        LoadDriveLetters (hTree, 0);
                   2757: }
                   2758: 
                   2759: LPARAM
                   2760: GetSelectedLong (HWND hTree)
                   2761: {
                   2762:        int hItem = ListView_GetSelectionMark (hTree);
                   2763:        LVITEM item;
                   2764: 
1.1.1.5   root     2765:        if (nSelectedDriveIndex >= 0)
1.1       root     2766:                hItem = nSelectedDriveIndex;
                   2767: 
                   2768:        memset(&item, 0, sizeof(LVITEM));
                   2769:        item.mask = LVIF_PARAM;
                   2770:        item.iItem = hItem;
                   2771: 
                   2772:        if (ListView_GetItem (hTree, &item) == FALSE)
                   2773:                return MAKELONG (0xffff, 0xffff);
                   2774:        else
                   2775:                return item.lParam;
                   2776: }
                   2777: 
                   2778: LPARAM
                   2779: GetItemLong (HWND hTree, int itemNo)
                   2780: {
                   2781:        LVITEM item;
                   2782: 
                   2783:        memset(&item, 0, sizeof(LVITEM));
                   2784:        item.mask = LVIF_PARAM;
                   2785:        item.iItem = itemNo;
                   2786: 
                   2787:        if (ListView_GetItem (hTree, &item) == FALSE)
                   2788:                return MAKELONG (0xffff, 0xffff);
                   2789:        else
                   2790:                return item.lParam;
                   2791: }
                   2792: 
1.1.1.7   root     2793: static int AskUserPassword (HWND hwndDlg, Password *password)
1.1       root     2794: {
1.1.1.7   root     2795:        int result;
                   2796: 
                   2797:        result = DialogBoxParamW (hInst, 
                   2798:                MAKEINTRESOURCEW (IDD_PASSWORD_DLG), hwndDlg,
1.1       root     2799:                (DLGPROC) PasswordDlgProc, (LPARAM) password);
                   2800: 
                   2801:        if (result != IDOK)
1.1.1.7   root     2802:        {
                   2803:                password->Length = 0;
                   2804:                burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
                   2805:        }
1.1       root     2806: 
                   2807:        return result == IDOK;
                   2808: }
                   2809: 
                   2810: // GUI actions
                   2811: 
1.1.1.7   root     2812: static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName)
1.1       root     2813: {
1.1.1.7   root     2814:        BOOL status = FALSE;
                   2815:        char fileName[MAX_PATH];
1.1.1.13! root     2816:        int mounted = 0, modeOfOperation;
1.1.1.7   root     2817:        if (nDosDriveNo == 0)
                   2818:                nDosDriveNo = HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A';
1.1       root     2819: 
1.1.1.7   root     2820:        VolumePassword.Length = 0;
                   2821: 
                   2822:        if (szFileName == NULL)
                   2823:        {
                   2824:                GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), fileName, sizeof (fileName));
                   2825:                szFileName = fileName;
                   2826:        }
1.1       root     2827: 
                   2828:        if (strlen(szFileName) == 0)
1.1.1.7   root     2829:        {
                   2830:                status = FALSE;
                   2831:                goto ret;
                   2832:        }
1.1       root     2833: 
                   2834:        if (IsMountedVolume (szFileName))
                   2835:        {
1.1.1.11  root     2836:                Warning ("VOL_ALREADY_MOUNTED");
1.1.1.7   root     2837:                status = FALSE;
                   2838:                goto ret;
1.1       root     2839:        }
                   2840: 
                   2841:        // First try cached passwords and if they fail ask user for a new one
1.1.1.11  root     2842:        WaitCursor ();
1.1.1.7   root     2843: 
                   2844:        mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, NULL, bCacheInDriver, bForceMount, &mountOptions, FALSE, FALSE);
1.1       root     2845:        
1.1.1.7   root     2846:        // If keyfiles are enabled, test empty password first
                   2847:        if (!mounted && KeyFilesEnable)
1.1       root     2848:        {
1.1.1.12  root     2849:                KeyFilesApply (&VolumePassword, FirstKeyFile);
1.1.1.7   root     2850:                mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, FALSE, FALSE);
                   2851:        }
1.1       root     2852: 
1.1.1.13! root     2853:        NormalCursor ();
        !          2854: 
1.1.1.11  root     2855:        if (mounted)
                   2856:        {
1.1.1.13! root     2857:                // Check for deprecated CBC mode
        !          2858:                modeOfOperation = GetModeOfOperationByDriveNo (nDosDriveNo);
        !          2859:                if (modeOfOperation == CBC || modeOfOperation == OUTER_CBC)
        !          2860:                        Warning("WARN_CBC_MODE");
        !          2861: 
        !          2862:                // Check for deprecated 64-bit-block ciphers
1.1.1.11  root     2863:                if (GetCipherBlockSizeByDriveNo (nDosDriveNo) == 64)
                   2864:                        Warning("WARN_64_BIT_BLOCK_CIPHER");
                   2865: 
                   2866:                // Check for problematic file extensions (exe, dll, sys)
                   2867:                if (CheckFileExtension(szFileName))
                   2868:                        Warning ("EXE_FILE_EXTENSION_MOUNT_WARNING");
                   2869:        }
                   2870: 
1.1.1.7   root     2871:        while (mounted == 0)
                   2872:        {
                   2873:                if (CmdVolumePassword.Length > 0)
                   2874:                {
                   2875:                        VolumePassword = CmdVolumePassword;
                   2876:                }
                   2877:                else if (!Silent)
                   2878:                {
                   2879:                        strcpy (PasswordDlgVolume, szFileName);
                   2880:                        if (!AskUserPassword (hwndDlg, &VolumePassword))
                   2881:                                goto ret;
                   2882:                }
                   2883:                
1.1.1.11  root     2884:                WaitCursor ();
1.1.1.7   root     2885: 
                   2886:                if (KeyFilesEnable)
1.1.1.12  root     2887:                        KeyFilesApply (&VolumePassword, FirstKeyFile);
1.1.1.7   root     2888: 
                   2889:                mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, FALSE, TRUE);
1.1       root     2890:                NormalCursor ();
1.1.1.7   root     2891: 
1.1.1.13! root     2892:                // Check for deprecated CBC mode
        !          2893:                modeOfOperation = GetModeOfOperationByDriveNo (nDosDriveNo);
        !          2894:                if (modeOfOperation == CBC || modeOfOperation == OUTER_CBC)
        !          2895:                        Warning("WARN_CBC_MODE");
        !          2896: 
        !          2897:                // Check for deprecated 64-bit-block ciphers
1.1.1.11  root     2898:                if (GetCipherBlockSizeByDriveNo (nDosDriveNo) == 64)
                   2899:                        Warning("WARN_64_BIT_BLOCK_CIPHER");
                   2900: 
                   2901:                // Check for legacy non-ASCII passwords
1.1.1.9   root     2902:                if (mounted > 0 && !KeyFilesEnable && !CheckPasswordCharEncoding (NULL, &VolumePassword))
                   2903:                        Warning ("UNSUPPORTED_CHARS_IN_PWD_RECOM");
                   2904: 
1.1.1.11  root     2905:                // Check for problematic file extensions (exe, dll, sys)
1.1.1.13! root     2906:                if (mounted > 0 && CheckFileExtension (szFileName))
1.1.1.11  root     2907:                        Warning ("EXE_FILE_EXTENSION_MOUNT_WARNING");
                   2908: 
1.1.1.8   root     2909:                burn (&VolumePassword, sizeof (VolumePassword));
1.1.1.7   root     2910:                burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
                   2911: 
                   2912:                if (CmdVolumePassword.Length > 0 || Silent)
                   2913:                        break;
1.1       root     2914:        }
                   2915: 
1.1.1.5   root     2916:        if (mounted > 0)
1.1       root     2917:        {
1.1.1.7   root     2918:                status = TRUE;
                   2919: 
                   2920:                if (bBeep)
                   2921:                        MessageBeep (-1);
1.1       root     2922: 
                   2923:                RefreshMainDlg(hwndDlg);
                   2924: 
1.1.1.7   root     2925:                if (bExplore)
1.1       root     2926:                {       
1.1.1.11  root     2927:                        WaitCursor();
1.1       root     2928:                        OpenVolumeExplorerWindow (nDosDriveNo);
                   2929:                        NormalCursor();
                   2930:                }
1.1.1.7   root     2931: 
                   2932:                if (mountOptions.ProtectHiddenVolume)
                   2933:                        Info ("HIDVOL_PROT_WARN_AFTER_MOUNT");
1.1       root     2934:        }
                   2935: 
1.1.1.7   root     2936: ret:
1.1.1.8   root     2937:        burn (&VolumePassword, sizeof (VolumePassword));
1.1.1.7   root     2938:        burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
1.1.1.11  root     2939: 
1.1.1.7   root     2940:        RestoreDefaultKeyFilesParam ();
1.1.1.11  root     2941: 
                   2942:        if (UsePreferences)
                   2943:                bCacheInDriver = bCacheInDriverDefault;
                   2944: 
1.1.1.7   root     2945:        return status;
1.1       root     2946: }
                   2947: 
                   2948: 
1.1.1.7   root     2949: static BOOL Dismount (HWND hwndDlg, int nDosDriveNo)
1.1       root     2950: {
1.1.1.7   root     2951:        BOOL status = FALSE;
1.1.1.11  root     2952:        WaitCursor ();
1.1       root     2953: 
1.1.1.2   root     2954:        if (nDosDriveNo == 0)
                   2955:                nDosDriveNo = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A');
1.1       root     2956: 
1.1.1.5   root     2957:        if (bCloseDismountedWindows)
1.1       root     2958:        {
1.1.1.6   root     2959:                CloseVolumeExplorerWindows (hwndDlg, nDosDriveNo);
1.1       root     2960:        }
                   2961: 
1.1.1.5   root     2962:        if (UnmountVolume (hwndDlg, nDosDriveNo, bForceUnmount))
                   2963:        {
1.1.1.7   root     2964:                status = TRUE;
                   2965: 
                   2966:                if (bBeep)
                   2967:                        MessageBeep (-1);
1.1.1.5   root     2968:                RefreshMainDlg (hwndDlg);
1.1.1.10  root     2969: 
                   2970:                if (nCurrentOS == WIN_2000 && RemoteSession && !IsAdmin ())
                   2971:                        LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
1.1       root     2972:        }
                   2973: 
1.1.1.5   root     2974:        NormalCursor ();
1.1.1.7   root     2975:        return status;
1.1       root     2976: }
                   2977: 
1.1.1.7   root     2978: static BOOL DismountAll (HWND hwndDlg, BOOL forceUnmount, BOOL interact, int dismountMaxRetries, int dismountAutoRetryDelay)
1.1       root     2979: {
1.1.1.7   root     2980:        BOOL status = TRUE;
1.1.1.5   root     2981:        MOUNT_LIST_STRUCT mountList;
                   2982:        DWORD dwResult;
                   2983:        UNMOUNT_STRUCT unmount;
1.1       root     2984:        BOOL bResult;
1.1.1.5   root     2985:        unsigned __int32 prevMountedDrives = 0;
                   2986:        int i;
1.1       root     2987: 
1.1.1.5   root     2988: retry:
1.1.1.11  root     2989:        WaitCursor();
1.1       root     2990: 
1.1.1.13! root     2991:        DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
1.1.1.7   root     2992: 
                   2993:        if (mountList.ulMountedDrives == 0)
                   2994:        {
                   2995:                NormalCursor();
                   2996:                return TRUE;
                   2997:        }
                   2998: 
1.1.1.11  root     2999:        BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, 0, mountList.ulMountedDrives);
                   3000: 
1.1.1.5   root     3001:        prevMountedDrives = mountList.ulMountedDrives;
                   3002: 
                   3003:        for (i = 0; i < 26; i++)
1.1       root     3004:        {
1.1.1.5   root     3005:                if (mountList.ulMountedDrives & (1 << i))
1.1       root     3006:                {
1.1.1.5   root     3007:                        if (bCloseDismountedWindows)
1.1.1.6   root     3008:                                CloseVolumeExplorerWindows (hwndDlg, i);
1.1       root     3009:                }
1.1.1.5   root     3010:        }
1.1       root     3011: 
1.1.1.5   root     3012:        unmount.nDosDriveNo = 0;
                   3013:        unmount.ignoreOpenFiles = forceUnmount;
1.1       root     3014: 
1.1.1.6   root     3015:        do
                   3016:        {
1.1.1.13! root     3017:                bResult = DeviceIoControl (hDriver, TC_IOCTL_DISMOUNT_ALL_VOLUMES, &unmount,
1.1.1.6   root     3018:                        sizeof (unmount), &unmount, sizeof (unmount), &dwResult, NULL);
                   3019: 
                   3020:                if (bResult == FALSE)
                   3021:                {
                   3022:                        NormalCursor();
                   3023:                        handleWin32Error (hwndDlg);
1.1.1.7   root     3024:                        return FALSE;
1.1.1.6   root     3025:                }
1.1       root     3026: 
1.1.1.6   root     3027:                if (unmount.nReturnCode == ERR_FILES_OPEN)
1.1.1.7   root     3028:                        Sleep (dismountAutoRetryDelay);
1.1.1.6   root     3029:                else
                   3030:                        break;
1.1       root     3031: 
1.1.1.6   root     3032:        } while (--dismountMaxRetries > 0);
1.1       root     3033: 
1.1.1.7   root     3034:        memset (&mountList, 0, sizeof (mountList));
1.1.1.13! root     3035:        DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
1.1.1.6   root     3036:        BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, prevMountedDrives & ~mountList.ulMountedDrives);
1.1       root     3037: 
1.1.1.7   root     3038:        RefreshMainDlg (hwndDlg);
1.1.1.10  root     3039: 
                   3040:        if (nCurrentOS == WIN_2000 && RemoteSession && !IsAdmin ())
                   3041:                LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
                   3042: 
1.1.1.5   root     3043:        NormalCursor();
1.1       root     3044: 
1.1.1.5   root     3045:        if (unmount.nReturnCode != 0)
                   3046:        {
1.1.1.7   root     3047:                if (forceUnmount)
                   3048:                        status = FALSE;
                   3049: 
1.1.1.5   root     3050:                if (unmount.nReturnCode == ERR_FILES_OPEN)
                   3051:                {
1.1.1.7   root     3052:                        if (interact && IDYES == AskWarnNoYes ("UNMOUNTALL_LOCK_FAILED"))
1.1       root     3053:                        {
1.1.1.5   root     3054:                                forceUnmount = TRUE;
                   3055:                                goto retry;
1.1       root     3056:                        }
1.1.1.5   root     3057: 
1.1.1.7   root     3058:                        return FALSE;
1.1       root     3059:                }
1.1.1.5   root     3060:                
1.1.1.7   root     3061:                if (interact)
                   3062:                        MessageBoxW (hwndDlg, GetString ("UNMOUNT_FAILED"), lpszTitle, MB_ICONERROR);
1.1       root     3063:        }
                   3064:        else
                   3065:        {
1.1.1.7   root     3066:                if (bBeep)
                   3067:                        MessageBeep (-1);
1.1       root     3068:        }
1.1.1.7   root     3069: 
                   3070:        return status;
1.1       root     3071: }
                   3072: 
1.1.1.7   root     3073: static BOOL MountAllDevices (HWND hwndDlg, BOOL bPasswordPrompt)
1.1       root     3074: {
                   3075:        HWND driveList = GetDlgItem (hwndDlg, IDC_DRIVELIST);
                   3076:        int i, n, selDrive = ListView_GetSelectionMark (driveList);
1.1.1.13! root     3077:        BOOL shared = FALSE, status = FALSE, b64BitBlockCipher = FALSE, bCBCMode = FALSE;
        !          3078:        int mountedVolCount = 0, modeOfOperation;
1.1.1.6   root     3079: 
1.1.1.7   root     3080:        VolumePassword.Length = 0;
1.1.1.6   root     3081:        mountOptions = defaultMountOptions;
                   3082: 
1.1.1.7   root     3083:        if (selDrive == -1) selDrive = 0;
1.1       root     3084: 
1.1.1.7   root     3085:        do
1.1       root     3086:        {
1.1.1.7   root     3087:                if (!CmdVolumePasswordValid && bPasswordPrompt)
                   3088:                {
                   3089:                        PasswordDlgVolume[0] = '\0';
                   3090:                        if (!AskUserPassword (hwndDlg, &VolumePassword))
                   3091:                                goto ret;
                   3092:                }
                   3093:                else if (CmdVolumePasswordValid)
                   3094:                {
                   3095:                        bPasswordPrompt = FALSE;
                   3096:                        VolumePassword = CmdVolumePassword;
                   3097:                }
                   3098: 
1.1.1.11  root     3099:                WaitCursor();
1.1.1.7   root     3100: 
                   3101:                if (FirstCmdKeyFile)
1.1.1.12  root     3102:                        KeyFilesApply (&VolumePassword, FirstCmdKeyFile);
1.1.1.7   root     3103:                else if (KeyFilesEnable)
1.1.1.12  root     3104:                        KeyFilesApply (&VolumePassword, FirstKeyFile);
1.1.1.7   root     3105: 
                   3106:                for (i = 0; i < 64; i++)
1.1       root     3107:                {
1.1.1.7   root     3108:                        // Include partition 0 (whole disk)
                   3109:                        for (n = 0; n <= 32; n++)
                   3110:                        {
                   3111:                                char szFileName[TC_MAX_PATH];
                   3112:                                OPEN_TEST_STRUCT driver;
                   3113:                                BOOL mounted;
1.1       root     3114: 
1.1.1.7   root     3115:                                sprintf (szFileName, "\\Device\\Harddisk%d\\Partition%d", i, n);
1.1.1.6   root     3116: 
1.1.1.7   root     3117:                                mounted = IsMountedVolume (szFileName);
1.1.1.6   root     3118: 
1.1.1.7   root     3119:                                // Skip other partitions of the disk if partition0 (whole disk) is mounted
                   3120:                                if (n == 0 && mounted)
                   3121:                                        break;
1.1.1.6   root     3122: 
1.1.1.7   root     3123:                                if (!mounted && OpenDevice (szFileName, &driver))
                   3124:                                {       
                   3125:                                        int nDosDriveNo;
1.1.1.11  root     3126:                                        PARTITION_INFORMATION pi0, pi1;
                   3127: 
                   3128:                                        // Skip partition0 if a virtual partition1 exists
                   3129:                                        if (n == 0 && GetPartitionInfo (szFileName, &pi0))
                   3130:                                        {
                   3131:                                                char p[TC_MAX_PATH];
                   3132:                                                sprintf (p, "\\Device\\Harddisk%d\\Partition1", i);
                   3133: 
                   3134:                                                if (GetPartitionInfo (p, &pi1) && pi0.PartitionLength.QuadPart == pi1.PartitionLength.QuadPart)
                   3135:                                                        continue;
                   3136:                                        }
1.1       root     3137: 
1.1.1.7   root     3138:                                        while (LOWORD (GetItemLong (driveList, selDrive)) != 0xffff)
1.1       root     3139:                                        {
1.1.1.13! root     3140:                                                if(LOWORD (GetItemLong (driveList, selDrive)) != TC_MLIST_ITEM_FREE)
1.1.1.7   root     3141:                                                {
                   3142:                                                        selDrive++;
                   3143:                                                        continue;
                   3144:                                                }
                   3145:                                                nDosDriveNo = HIWORD(GetItemLong (driveList, selDrive)) - 'A';
                   3146:                                                break;
1.1       root     3147:                                        }
                   3148: 
1.1.1.7   root     3149:                                        if (LOWORD (GetItemLong (driveList, selDrive)) == 0xffff)
                   3150:                                                goto ret;
1.1       root     3151: 
1.1.1.7   root     3152:                                        // First try user password then cached passwords
                   3153:                                        if ((mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, TRUE, FALSE)) > 0
                   3154:                                                || (mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, NULL, bCacheInDriver, bForceMount, &mountOptions, TRUE, FALSE)) > 0)
                   3155:                                        {
                   3156:                                                if (mounted == 2)
                   3157:                                                        shared = TRUE;
1.1.1.5   root     3158: 
1.1.1.7   root     3159:                                                LoadDriveLetters (driveList, (HIWORD (GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), selDrive))));
                   3160:                                                selDrive++;
1.1       root     3161: 
1.1.1.7   root     3162:                                                if (bExplore)
                   3163:                                                {       
1.1.1.11  root     3164:                                                        WaitCursor();
1.1.1.7   root     3165:                                                        OpenVolumeExplorerWindow (nDosDriveNo);
                   3166:                                                        NormalCursor();
                   3167:                                                }
                   3168: 
                   3169:                                                if (bBeep)
                   3170:                                                        MessageBeep (-1);
1.1.1.6   root     3171: 
1.1.1.7   root     3172:                                                status = TRUE;
                   3173: 
1.1.1.13! root     3174:                                                // Check for deprecated CBC mode
        !          3175:                                                modeOfOperation = GetModeOfOperationByDriveNo (nDosDriveNo);
        !          3176:                                                bCBCMode = (modeOfOperation == CBC || modeOfOperation == OUTER_CBC);
        !          3177: 
1.1.1.11  root     3178:                                                if (GetCipherBlockSizeByDriveNo(nDosDriveNo) == 64)
                   3179:                                                        b64BitBlockCipher = TRUE;
                   3180: 
1.1.1.7   root     3181:                                                mountedVolCount++;
                   3182: 
                   3183:                                                // Skip other partitions of the disk if partition0 (whole disk) has been mounted
                   3184:                                                if (n == 0)
                   3185:                                                        break;
                   3186:                                        }
1.1       root     3187:                                }
1.1.1.7   root     3188:                                else if (n == 0)
                   3189:                                        break;
1.1       root     3190:                        }
                   3191:                }
1.1.1.8   root     3192: 
                   3193:                burn (&VolumePassword, sizeof (VolumePassword));
                   3194: 
1.1.1.7   root     3195:                if (mountedVolCount < 1 && !Silent)
                   3196:                {
1.1.1.11  root     3197:                        WCHAR szTmp[4096];
1.1.1.7   root     3198: 
1.1.1.11  root     3199:                        swprintf (szTmp, GetString (KeyFilesEnable || FirstCmdKeyFile ? "PASSWORD_OR_KEYFILE_WRONG_AUTOMOUNT" : "PASSWORD_WRONG_AUTOMOUNT"));
1.1.1.7   root     3200:                        if (CheckCapsLock (hwndDlg, TRUE))
                   3201:                                wcscat (szTmp, GetString ("PASSWORD_WRONG_CAPSLOCK_ON"));
                   3202: 
                   3203:                        MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONWARNING);
                   3204:                }
                   3205: 
                   3206:                burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
                   3207:        } while (bPasswordPrompt && mountedVolCount < 1);
                   3208: 
                   3209:        /* One or more volumes successfully mounted */
1.1       root     3210: 
1.1.1.5   root     3211:        if (shared)
1.1.1.7   root     3212:                Warning ("DEVICE_IN_USE_INFO");
                   3213: 
                   3214:        if (mountOptions.ProtectHiddenVolume)
                   3215:        {
1.1.1.11  root     3216:                if (mountedVolCount > 1) 
1.1.1.7   root     3217:                        Info ("HIDVOL_PROT_WARN_AFTER_MOUNT_PLURAL");
                   3218:                else if (mountedVolCount == 1)
                   3219:                        Info ("HIDVOL_PROT_WARN_AFTER_MOUNT");
                   3220:        }
                   3221: 
1.1.1.13! root     3222:        // Check for deprecated CBC mode
        !          3223:        if (bCBCMode)
        !          3224:                Warning("WARN_CBC_MODE");
        !          3225: 
        !          3226:        // Check for deprecated 64-bit-block ciphers
1.1.1.11  root     3227:        if (b64BitBlockCipher)
                   3228:                Warning("WARN_64_BIT_BLOCK_CIPHER");
                   3229: 
                   3230:        // Check for legacy non-ASCII passwords
1.1.1.7   root     3231:        if (!KeyFilesEnable
                   3232:                && !FirstCmdKeyFile
                   3233:                && mountedVolCount > 0
                   3234:                && !CheckPasswordCharEncoding (NULL, &VolumePassword))
                   3235:                        Warning ("UNSUPPORTED_CHARS_IN_PWD_RECOM");
1.1.1.5   root     3236: 
1.1.1.13! root     3237: ret:
        !          3238:        burn (&VolumePassword, sizeof (VolumePassword));
        !          3239:        burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
        !          3240: 
        !          3241:        RestoreDefaultKeyFilesParam ();
        !          3242: 
        !          3243:        if (UsePreferences)
        !          3244:                bCacheInDriver = bCacheInDriverDefault;
        !          3245: 
        !          3246:        EnableDisableButtons (hwndDlg);
        !          3247: 
        !          3248:        NormalCursor();
        !          3249: 
        !          3250:        return status;
        !          3251: }
        !          3252: 
        !          3253: static void ChangePassword (HWND hwndDlg)
        !          3254: {
        !          3255:        int result;
        !          3256:        
        !          3257:        GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, sizeof (szFileName));
        !          3258:        if (IsMountedVolume (szFileName))
        !          3259:        {
        !          3260:                Warning (pwdChangeDlgMode == PCDM_CHANGE_PKCS5_PRF ? "MOUNTED_NO_PKCS5_PRF_CHANGE" : "MOUNTED_NOPWCHANGE");
        !          3261:                return;
        !          3262:        }
        !          3263: 
        !          3264:        bSysEncPwdChangeDlgMode = FALSE;
        !          3265: 
        !          3266:        result = DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_PASSWORDCHANGE_DLG), hwndDlg,
        !          3267:                (DLGPROC) PasswordChangeDlgProc);
        !          3268: 
        !          3269:        if (result == IDOK)
        !          3270:        {
        !          3271:                switch (pwdChangeDlgMode)
        !          3272:                {
        !          3273:                case PCDM_CHANGE_PKCS5_PRF:
        !          3274:                        Info ("PKCS5_PRF_CHANGED");
        !          3275:                        break;
        !          3276: 
        !          3277:                case PCDM_ADD_REMOVE_VOL_KEYFILES:
        !          3278:                case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
        !          3279:                        Info ("KEYFILE_CHANGED");
        !          3280:                        break;
        !          3281: 
        !          3282:                case PCDM_CHANGE_PASSWORD:
        !          3283:                default:
        !          3284:                        Info ("PASSWORD_CHANGED");
        !          3285:                }
        !          3286:        }
        !          3287: }
        !          3288: 
        !          3289: // Change password of the system partition/drive
        !          3290: static void ChangeSysEncPassword (HWND hwndDlg, BOOL bOnlyChangeKDF)
        !          3291: {
        !          3292:        try
        !          3293:        {
        !          3294:                BootEncStatus = BootEncObj->GetStatus();
        !          3295:        }
        !          3296:        catch (Exception &e)
        !          3297:        {
        !          3298:                e.Show (MainDlg);
        !          3299:        }
        !          3300: 
        !          3301:        if (!BootEncStatus.DriveEncrypted 
        !          3302:                && !BootEncStatus.DriveMounted
        !          3303:                && !BootEncStatus.VolumeHeaderPresent
        !          3304:                && !SysEncryptionOrDecryptionRequired ())
        !          3305:        {
        !          3306:                Warning ("SYS_DRIVE_NOT_ENCRYPTED");
        !          3307:                return;
        !          3308:        }
        !          3309: 
        !          3310:        if (SysEncryptionOrDecryptionRequired () 
        !          3311:                || BootEncStatus.SetupInProgress)
        !          3312:        {
        !          3313:                Warning ("SYSTEM_ENCRYPTION_NOT_COMPLETED");
        !          3314:                return;
        !          3315:        }
        !          3316: 
        !          3317:        if (CreateSysEncMutex ())       // If no instance of the wizard is currently taking care of system encryption
        !          3318:        {
        !          3319:                sprintf (OrigKeyboardLayout, "%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF);
        !          3320: 
        !          3321:                bSysEncPwdChangeDlgMode = TRUE;
        !          3322: 
        !          3323:                if (bOnlyChangeKDF)
        !          3324:                        pwdChangeDlgMode = PCDM_CHANGE_PKCS5_PRF;
        !          3325:                else
        !          3326:                        pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
        !          3327: 
        !          3328: 
        !          3329:                if (DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_PASSWORDCHANGE_DLG), hwndDlg,
        !          3330:                        (DLGPROC) PasswordChangeDlgProc) == IDOK)
        !          3331:                {
        !          3332:                        switch (pwdChangeDlgMode)
        !          3333:                        {
        !          3334:                        case PCDM_CHANGE_PKCS5_PRF:
        !          3335:                                Info ("PKCS5_PRF_CHANGED");
        !          3336: 
        !          3337:                                if (AskWarnYesNo ("SYS_HKD_ALGO_CHANGED_ASK_RESCUE_DISK") == IDYES)
        !          3338:                                        CreateRescueDisk ();
        !          3339: 
        !          3340:                                break;
        !          3341: 
        !          3342:                        case PCDM_ADD_REMOVE_VOL_KEYFILES:
        !          3343:                        case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
        !          3344:                                // NOP - Keyfiles are not supported for system encryption
        !          3345:                                break;
        !          3346: 
        !          3347:                        case PCDM_CHANGE_PASSWORD:
        !          3348:                        default:
        !          3349:                                Info ("PASSWORD_CHANGED");
        !          3350: 
        !          3351:                                if (AskWarnYesNo ("SYS_PASSWORD_CHANGED_ASK_RESCUE_DISK") == IDYES)
        !          3352:                                        CreateRescueDisk ();
        !          3353:                        }
        !          3354:                }
        !          3355: 
        !          3356:                bSysEncPwdChangeDlgMode = FALSE;
        !          3357: 
        !          3358:                // Restore the original keyboard layout
        !          3359:                LoadKeyboardLayout (OrigKeyboardLayout, KLF_ACTIVATE | KLF_SUBSTITUTE_OK);
        !          3360: 
        !          3361:                CloseSysEncMutex ();
        !          3362:        }
        !          3363:        else
        !          3364:                Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
        !          3365: }
        !          3366: 
        !          3367: // Initiates or resumes encryption of the system partition/drive
        !          3368: static void EncryptSystemDevice (void)
        !          3369: {
        !          3370:        try
        !          3371:        {
        !          3372:                BootEncStatus = BootEncObj->GetStatus();
        !          3373:        }
        !          3374:        catch (Exception &e)
        !          3375:        {
        !          3376:                e.Show (MainDlg);
        !          3377:        }
        !          3378: 
        !          3379:        if (!BootEncStatus.DriveEncrypted 
        !          3380:                && !BootEncStatus.DriveMounted
        !          3381:                && !SysEncryptionOrDecryptionRequired ())
        !          3382:        {
        !          3383:                // System partition/drive is not encrypted (nothing to resume). Initiate the process.
        !          3384: 
        !          3385:                if (CreateSysEncMutex ())       // If no instance of the wizard is currently taking care of system encryption
        !          3386:                {
        !          3387:                        CloseSysEncMutex ();    
        !          3388:                        LaunchVolCreationWizard (MainDlg, "/sysenc");
        !          3389:                }
        !          3390:                else
        !          3391:                        Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
        !          3392: 
        !          3393:                return;
        !          3394:        }
        !          3395:        else if (SysEncryptionOrDecryptionRequired ())
        !          3396:        {
        !          3397:                // System partition/drive encryption already initiated but is incomplete -- attempt to resume the process.
        !          3398:                // Note that this also covers the pretest phase and paused decryption (reverses decrypting and starts encrypting)
        !          3399: 
        !          3400:                if (CreateSysEncMutex ())       // If no instance of the wizard is currently taking care of system encryption
        !          3401:                {
        !          3402:                        CloseSysEncMutex ();    
        !          3403:                        LaunchVolCreationWizard (MainDlg, "/sysenc");
        !          3404:                }
        !          3405:                else
        !          3406:                        Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
        !          3407:        }
        !          3408:        else if (SysDriveOrPartitionFullyEncrypted (FALSE))
        !          3409:        {
        !          3410:                // System partition/drive appears to be fully encrypted
        !          3411:                Info ("SYS_PARTITION_OR_DRIVE_APPEARS_FULLY_ENCRYPTED");
        !          3412:                return;
        !          3413:        }
        !          3414: }
        !          3415: 
        !          3416: // Initiates decryption of the system partition/drive
        !          3417: static void DecryptSystemDevice (void)
        !          3418: {
        !          3419:        try
        !          3420:        {
        !          3421:                BootEncStatus = BootEncObj->GetStatus();
        !          3422:        }
        !          3423:        catch (Exception &e)
        !          3424:        {
        !          3425:                e.Show (MainDlg);
        !          3426:        }
        !          3427: 
        !          3428:        if (!BootEncStatus.DriveEncrypted 
        !          3429:                && !BootEncStatus.DriveMounted
        !          3430:                && !BootEncStatus.VolumeHeaderPresent
        !          3431:                && !SysEncryptionOrDecryptionRequired ())
        !          3432:        {
        !          3433:                Warning ("SYS_DRIVE_NOT_ENCRYPTED");
        !          3434:                return;
        !          3435:        }
        !          3436: 
        !          3437:        if (AskNoYes ("CONFIRM_DECRYPT_SYS_DEVICE") == IDNO)
        !          3438:                return;
        !          3439: 
        !          3440:        if (AskWarnNoYes ("CONFIRM_DECRYPT_SYS_DEVICE_CAUTION") == IDNO)
        !          3441:                return;
        !          3442: 
        !          3443:        if (CreateSysEncMutex ())       // If no instance of the wizard is currently taking care of system encryption
        !          3444:        {
        !          3445:                try
        !          3446:                {
        !          3447:                        // User-mode app may have crashed and its mutex may have gotten lost, so we need to check the driver status too
        !          3448:                        if (BootEncStatus.SetupInProgress)
        !          3449:                        {
        !          3450:                                int attempts = 20;
        !          3451: 
        !          3452:                                BootEncObj->AbortSetup ();
        !          3453:                                while (BootEncStatus.SetupInProgress && attempts > 0)
        !          3454:                                {
        !          3455:                                        Sleep (100);
        !          3456:                                        BootEncStatus = BootEncObj->GetStatus();
        !          3457:                                        attempts--;
        !          3458:                                        WaitCursor();
        !          3459:                                }
        !          3460:                        }
        !          3461:                }
        !          3462:                catch (Exception &e)
        !          3463:                {
        !          3464:                        e.Show (MainDlg);
        !          3465:                }
        !          3466:                NormalCursor ();
        !          3467: 
        !          3468:                if (BootEncStatus.SetupInProgress)
        !          3469:                {
        !          3470:                        CloseSysEncMutex ();    
        !          3471:                        Error ("SYS_ENCRYPTION_OR_DECRYPTION_IN_PROGRESS");
        !          3472:                        return;
        !          3473:                }
        !          3474: 
        !          3475:                CloseSysEncMutex ();    
        !          3476:                LaunchVolCreationWizard (MainDlg, "/dsysenc");
        !          3477:        }
        !          3478:        else
        !          3479:                Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
        !          3480: }
        !          3481: 
        !          3482: // Blindly attempts (without any checks) to instruct the wizard to resume whatever system encryption process
        !          3483: // had been interrupted or not started but scheduled or exptected to start.
        !          3484: static void ResumeInterruptedSysEncProcess (void)
        !          3485: {
        !          3486:        if (CreateSysEncMutex ())       // If no instance of the wizard is currently taking care of system encryption
        !          3487:        {
        !          3488:                CloseSysEncMutex ();    
        !          3489:                LaunchVolCreationWizard (MainDlg, "/csysenc");
        !          3490:        }
        !          3491:        else
        !          3492:                Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
        !          3493: }
        !          3494: 
        !          3495: void CreateRescueDisk (void)
        !          3496: {
        !          3497:        try
        !          3498:        {
        !          3499:                BootEncStatus = BootEncObj->GetStatus();
        !          3500:        }
        !          3501:        catch (Exception &e)
        !          3502:        {
        !          3503:                e.Show (MainDlg);
        !          3504:        }
        !          3505: 
        !          3506:        if (!BootEncStatus.DriveEncrypted 
        !          3507:                && !BootEncStatus.DriveMounted
        !          3508:                && !BootEncStatus.VolumeHeaderPresent
        !          3509:                && !SysEncryptionOrDecryptionRequired ())
        !          3510:        {
        !          3511:                Warning ("SYS_DRIVE_NOT_ENCRYPTED");
        !          3512:                return;
        !          3513:        }
        !          3514: 
        !          3515:        if (SysEncryptionOrDecryptionRequired () 
        !          3516:                || BootEncStatus.SetupInProgress)
        !          3517:        {
        !          3518:                Warning ("SYSTEM_ENCRYPTION_NOT_COMPLETED");
        !          3519:                return;
        !          3520:        }
        !          3521: 
        !          3522:        if (CreateSysEncMutex ())       // If no instance of the wizard is currently taking care of system encryption
        !          3523:        {
        !          3524:                try
        !          3525:                {
        !          3526:                        wchar_t szTmp [8096];
        !          3527:                        char szRescueDiskISO [TC_MAX_PATH+1];
        !          3528: 
        !          3529:                        if (AskOkCancel ("RESCUE_DISK_NON_WIZARD_CREATION_SELECT_PATH") != IDOK)
        !          3530:                                return;
1.1.1.11  root     3531: 
1.1.1.13! root     3532:                        if (BrowseFiles (MainDlg, "OPEN_TITLE", szRescueDiskISO, FALSE, TRUE) == FALSE)
        !          3533:                                return;
1.1.1.11  root     3534: 
1.1.1.13! root     3535:                        WaitCursor();
        !          3536:                        BootEncObj->CreateRescueIsoImage (false, szRescueDiskISO);
1.1.1.11  root     3537: 
1.1.1.13! root     3538:                        _snwprintf (szTmp, sizeof szTmp / 2,
        !          3539:                                GetString ("RESCUE_DISK_NON_WIZARD_CREATION_BURN"),
        !          3540:                                szRescueDiskISO);
1.1.1.11  root     3541: 
1.1.1.13! root     3542:                        MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
        !          3543:                }
        !          3544:                catch (Exception &e)
        !          3545:                {
        !          3546:                        e.Show (MainDlg);
        !          3547:                        Error ("ERROR_CREATING_RESCUE_DISK");
        !          3548:                }
        !          3549:                CloseSysEncMutex ();
1.1.1.7   root     3550: 
1.1.1.13! root     3551:                NormalCursor ();
        !          3552:        }
        !          3553:        else
        !          3554:                Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
1.1       root     3555: }
                   3556: 
1.1.1.13! root     3557: static void VerifyRescueDisk (void)
1.1       root     3558: {
1.1.1.13! root     3559:        try
1.1       root     3560:        {
1.1.1.13! root     3561:                BootEncStatus = BootEncObj->GetStatus();
        !          3562:        }
        !          3563:        catch (Exception &e)
        !          3564:        {
        !          3565:                e.Show (MainDlg);
1.1       root     3566:        }
                   3567: 
1.1.1.13! root     3568:        if (!BootEncStatus.DriveEncrypted 
        !          3569:                && !BootEncStatus.DriveMounted
        !          3570:                && !BootEncStatus.VolumeHeaderPresent
        !          3571:                && !SysEncryptionOrDecryptionRequired ())
        !          3572:        {
        !          3573:                Warning ("SYS_DRIVE_NOT_ENCRYPTED");
        !          3574:                return;
        !          3575:        }
1.1       root     3576: 
1.1.1.13! root     3577:        if (SysEncryptionOrDecryptionRequired () 
        !          3578:                || BootEncStatus.SetupInProgress)
1.1       root     3579:        {
1.1.1.13! root     3580:                Warning ("SYSTEM_ENCRYPTION_NOT_COMPLETED");
        !          3581:                return;
        !          3582:        }
1.1.1.7   root     3583: 
1.1.1.13! root     3584:        if (CreateSysEncMutex ())       // If no instance of the wizard is currently taking care of system encryption
        !          3585:        {
        !          3586:                try
1.1.1.7   root     3587:                {
1.1.1.13! root     3588:                        if (AskOkCancel ("RESCUE_DISK_NON_WIZARD_CHECK_INSERT") != IDOK)
        !          3589:                                return;
1.1.1.7   root     3590: 
1.1.1.13! root     3591:                        // Create a temporary up-to-date rescue disk image in RAM (with it the CD/DVD content will be compared)
        !          3592:                        BootEncObj->CreateRescueIsoImage (false, "");
1.1.1.7   root     3593: 
1.1.1.13! root     3594:                        WaitCursor();
        !          3595:                        if (!BootEncObj->VerifyRescueDisk ())
        !          3596:                                Error ("RESCUE_DISK_NON_WIZARD_CHECK_FAILED");
        !          3597:                        else
        !          3598:                                Info ("RESCUE_DISK_NON_WIZARD_CHECK_PASSED");
1.1.1.7   root     3599:                }
1.1.1.13! root     3600:                catch (Exception &e)
        !          3601:                {
        !          3602:                        e.Show (MainDlg);
        !          3603:                        Error ("RESCUE_DISK_NON_WIZARD_CHECK_FAILED");
        !          3604:                }
        !          3605:                CloseSysEncMutex ();
        !          3606: 
        !          3607:                NormalCursor ();
        !          3608:        }
        !          3609:        else
        !          3610:                Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
        !          3611: }
        !          3612: 
        !          3613: static void ShowSystemEncryptionStatus (void)
        !          3614: {
        !          3615:        try
        !          3616:        {
        !          3617:                BootEncStatus = BootEncObj->GetStatus();
        !          3618:        }
        !          3619:        catch (Exception &e)
        !          3620:        {
        !          3621:                e.Show (MainDlg);
        !          3622:        }
        !          3623: 
        !          3624:        if (GetAsyncKeyState (VK_SHIFT) < 0 && GetAsyncKeyState (VK_CONTROL) < 0)
        !          3625:        {
        !          3626:                // Ctrl+Shift held (for debugging purposes)
        !          3627: 
        !          3628:                DebugMsgBox ("Debugging information:\n\nDeviceFilterActive %d\nBootLoaderVersion %x\nSetupInProgress %d\nSetupMode %d\nVolumeHeaderPresent %d\nDriveMounted %d\nDriveEncrypted %d\n"
        !          3629:                        "ConfiguredEncryptedAreaStart %I64d\nConfiguredEncryptedAreaEnd %I64d\nEncryptedAreaStart %I64d\nEncryptedAreaEnd %I64d\nDone %I64d%%",
        !          3630:                        BootEncStatus.DeviceFilterActive,
        !          3631:                        BootEncStatus.BootLoaderVersion,
        !          3632:                        BootEncStatus.SetupInProgress,
        !          3633:                        BootEncStatus.SetupMode,
        !          3634:                        BootEncStatus.VolumeHeaderPresent,
        !          3635:                        BootEncStatus.DriveMounted,
        !          3636:                        BootEncStatus.DriveEncrypted,
        !          3637:                        BootEncStatus.ConfiguredEncryptedAreaStart,
        !          3638:                        BootEncStatus.ConfiguredEncryptedAreaEnd,
        !          3639:                        BootEncStatus.EncryptedAreaStart,
        !          3640:                        BootEncStatus.EncryptedAreaEnd,
        !          3641:                        !BootEncStatus.DriveEncrypted ? 0 : (BootEncStatus.EncryptedAreaEnd + 1 - BootEncStatus.EncryptedAreaStart) * 100I64 / (BootEncStatus.ConfiguredEncryptedAreaEnd + 1 - BootEncStatus.ConfiguredEncryptedAreaStart));
1.1       root     3642:        }
1.1.1.13! root     3643: 
        !          3644:        if (!BootEncStatus.DriveEncrypted && !BootEncStatus.DriveMounted)
        !          3645:        {
        !          3646:                Info ("SYS_DRIVE_NOT_ENCRYPTED");
        !          3647:                return;
        !          3648:        }
        !          3649: 
        !          3650:        DialogBoxParamW (hInst, 
        !          3651:                MAKEINTRESOURCEW (IDD_VOLUME_PROPERTIES), MainDlg,
        !          3652:                (DLGPROC) VolumePropertiesDlgProc, (LPARAM) TRUE);
        !          3653: 
1.1       root     3654: }
                   3655: 
                   3656: static void SelectContainer (HWND hwndDlg)
                   3657: {
1.1.1.8   root     3658:        if (BrowseFiles (hwndDlg, "OPEN_VOL_TITLE", szFileName, bHistory, FALSE) == FALSE)
1.1       root     3659:                return;
                   3660: 
1.1.1.10  root     3661:        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1       root     3662:        EnableDisableButtons (hwndDlg);
1.1.1.6   root     3663:        SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1       root     3664: }
                   3665: 
                   3666: static void SelectPartition (HWND hwndDlg)
                   3667: {
1.1.1.7   root     3668:        int nResult = DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), hwndDlg,
1.1       root     3669:                (DLGPROC) RawDevicesDlgProc, (LPARAM) & szFileName[0]);
                   3670:        if (nResult == IDOK)
                   3671:        {
1.1.1.10  root     3672:                AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1       root     3673:                EnableDisableButtons (hwndDlg);
1.1.1.6   root     3674:                SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1       root     3675:        }
                   3676: }
                   3677: 
                   3678: static void WipeCache (HWND hwndDlg)
                   3679: {
                   3680:        DWORD dwResult;
                   3681:        BOOL bResult;
                   3682: 
1.1.1.13! root     3683:        bResult = DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.11  root     3684:        if (hwndDlg == NULL)
                   3685:                return;
1.1       root     3686: 
                   3687:        if (bResult == FALSE)
                   3688:                handleWin32Error (hwndDlg);
                   3689:        else
                   3690:        {
                   3691:                EnableDisableButtons (hwndDlg);
                   3692: 
1.1.1.7   root     3693:                Info ("WIPE_CACHE");
1.1       root     3694:        }
                   3695: }
                   3696: 
1.1.1.5   root     3697: static void Benchmark (HWND hwndDlg)
                   3698: {
1.1.1.7   root     3699:        DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_BENCHMARK_DLG), hwndDlg,
1.1.1.5   root     3700:                (DLGPROC) BenchmarkDlgProc, (LPARAM) NULL);
                   3701: }
1.1       root     3702: 
1.1.1.7   root     3703: 
                   3704: static BOOL CheckMountList ()
1.1       root     3705: {
1.1.1.7   root     3706:        MOUNT_LIST_STRUCT current;
                   3707:        GetMountList (&current);
1.1.1.13! root     3708:        static BootEncryptionStatus newBootEncStatus;
1.1       root     3709: 
1.1.1.7   root     3710:        if (LastKnownLogicalDrives != GetLogicalDrives()
                   3711:                || memcmp (&LastKnownMountList, &current, sizeof (current)) != 0)
1.1       root     3712:        {
1.1.1.13! root     3713:                int selDrive;
1.1       root     3714: 
1.1.1.11  root     3715:                WaitCursor ();
1.1.1.13! root     3716:                LastKnownMountList = current;
        !          3717: 
        !          3718:                selDrive = HIWORD (GetSelectedLong (GetDlgItem (MainDlg, IDC_DRIVELIST)));
1.1.1.7   root     3719:                LoadDriveLetters (GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
1.1.1.13! root     3720:                NormalCursor ();
        !          3721: 
        !          3722:                if ((current.ulMountedDrives & (1 << (selDrive - 'A'))) == 0 && !IsDriveAvailable (selDrive - 'A'))
        !          3723:                {
        !          3724:                        nSelectedDriveIndex = -1;
        !          3725:                        return FALSE;
        !          3726:                }
1.1.1.2   root     3727: 
1.1.1.7   root     3728:                if (nSelectedDriveIndex >= 0)
                   3729:                {
1.1.1.13! root     3730:                        SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),selDrive);
        !          3731: 
        !          3732:                        if(nSelectedDriveIndex > SendMessage (GetDlgItem (MainDlg, IDC_DRIVELIST), LVM_GETITEMCOUNT, 0, 0)/2) 
        !          3733:                                SendMessage(GetDlgItem (MainDlg, IDC_DRIVELIST), LVM_SCROLL, 0, 1000);
1.1.1.7   root     3734:                }
1.1.1.13! root     3735:        }
1.1       root     3736: 
1.1.1.13! root     3737:        try
        !          3738:        {
        !          3739:                newBootEncStatus = BootEncObj->GetStatus();
        !          3740: 
        !          3741:                if (newBootEncStatus.SetupInProgress != RecentBootEncStatus.SetupInProgress
        !          3742:                        || newBootEncStatus.EncryptedAreaEnd != RecentBootEncStatus.EncryptedAreaEnd
        !          3743:                        || newBootEncStatus.DriveEncrypted != RecentBootEncStatus.DriveEncrypted
        !          3744:                        || newBootEncStatus.DriveMounted != RecentBootEncStatus.DriveMounted
        !          3745:                        || newBootEncStatus.SetupMode != RecentBootEncStatus.SetupMode
        !          3746:                        || newBootEncStatus.EncryptedAreaStart != RecentBootEncStatus.EncryptedAreaStart)
        !          3747:                {
        !          3748:                        /* System encryption status change */
        !          3749: 
        !          3750:                        int selDrive;
        !          3751:                        int driveLetterToRefresh;
        !          3752: 
        !          3753:                        if (RecentBootEncStatus.DriveMounted == newBootEncStatus.DriveMounted)  // If an icon (and whole new line) for a system device isn't to be added/removed
        !          3754:                        {
        !          3755:                                // Partial refresh
        !          3756:                                if (WholeSysDriveEncryption (TRUE))
        !          3757:                                {
        !          3758:                                        // System drive (not just partition)
        !          3759:                                        driveLetterToRefresh = ENC_SYSDRIVE_PSEUDO_DRIVE_LETTER;
        !          3760:                                }
        !          3761:                                else
        !          3762:                                {
        !          3763:                                        // System partition 
        !          3764:                                        driveLetterToRefresh = GetSystemDriveLetter ();
        !          3765:                                }
        !          3766:                        }
        !          3767:                        else
        !          3768:                        {
        !          3769:                                // Full rebuild of the mount list
        !          3770:                                driveLetterToRefresh = 0;       
        !          3771:                        }
        !          3772: 
        !          3773:                        WaitCursor ();
        !          3774: 
        !          3775:                        selDrive = HIWORD (GetSelectedLong (GetDlgItem (MainDlg, IDC_DRIVELIST)));
        !          3776:                        LoadDriveLetters (GetDlgItem (MainDlg, IDC_DRIVELIST), driveLetterToRefresh);
        !          3777: 
        !          3778:                        memcpy (&RecentBootEncStatus, &newBootEncStatus, sizeof (RecentBootEncStatus));
        !          3779: 
        !          3780:                        NormalCursor ();
        !          3781: 
        !          3782:                        if ((current.ulMountedDrives & (1 << (selDrive - 'A'))) == 0 && !IsDriveAvailable (selDrive - 'A'))
        !          3783:                        {
        !          3784:                                nSelectedDriveIndex = -1;
        !          3785:                        }
        !          3786: 
        !          3787:                        if (nSelectedDriveIndex >= 0)
        !          3788:                        {
        !          3789:                                SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),selDrive);
        !          3790: 
        !          3791:                                //if(nSelectedDriveIndex > SendMessage (GetDlgItem (MainDlg, IDC_DRIVELIST), LVM_GETITEMCOUNT, 0, 0)/2) 
        !          3792:                                //      SendMessage(GetDlgItem (MainDlg, IDC_DRIVELIST), LVM_SCROLL, 0, 1000);
        !          3793:                        }
        !          3794:                }
        !          3795: 
        !          3796:                // Hibernation prevention notifications
        !          3797:                if (newBootEncStatus.HibernationPreventionCount != RecentBootEncStatus.HibernationPreventionCount
        !          3798:                        && !bHibernationPreventionNotified)
        !          3799:                {
        !          3800:                        bHibernationPreventionNotified = TRUE;
        !          3801:                        RecentBootEncStatus.HibernationPreventionCount = newBootEncStatus.HibernationPreventionCount;
        !          3802:                        Warning ("SYS_ENC_HIBERNATION_PREVENTED");
        !          3803:                }
        !          3804:        }
        !          3805:        catch (...)
        !          3806:        {
        !          3807:                // NOP
1.1.1.7   root     3808:        }
1.1       root     3809: 
1.1.1.7   root     3810:        return TRUE;
                   3811: }
1.1.1.6   root     3812: 
1.1       root     3813: 
1.1.1.13! root     3814: /* Except in response to the WM_INITDIALOG and WM_ENDSESSION messages, the dialog box procedure
1.1.1.11  root     3815:    should return nonzero if it processes a message, and zero if it does not. */
1.1.1.13! root     3816: BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1.1.1.7   root     3817: {
1.1.1.11  root     3818:        static UINT taskBarCreatedMsg;
1.1.1.7   root     3819:        WORD lw = LOWORD (wParam);
                   3820:        WORD hw = HIWORD (wParam);
                   3821:        DWORD mPos;
1.1       root     3822: 
1.1.1.7   root     3823:        switch (uMsg)
                   3824:        {
                   3825:        case WM_HOTKEY:
1.1       root     3826: 
1.1.1.7   root     3827:                HandleHotKey (hwndDlg, wParam);
                   3828:                return 1;
1.1       root     3829: 
1.1.1.7   root     3830:        case WM_INITDIALOG:
                   3831:                {
                   3832:                        int exitCode = 0;
1.1.1.13! root     3833:                        int modeOfOperation;
        !          3834: 
1.1.1.7   root     3835:                        MainDlg = hwndDlg;
1.1       root     3836: 
1.1.1.7   root     3837:                        // Set critical default options in case UsePreferences is false
                   3838:                        bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = TRUE;
1.1       root     3839: 
1.1.1.7   root     3840:                        ExtractCommandLine (hwndDlg, (char *) lParam);
                   3841: 
1.1.1.11  root     3842:                        if (ComServerMode)
                   3843:                        {
                   3844:                                if (!ComServerMain ())
                   3845:                                {
                   3846:                                        handleWin32Error (hwndDlg);
                   3847:                                        exit (1);
                   3848:                                }
                   3849:                                exit (0);
                   3850:                        }
                   3851: 
1.1.1.13! root     3852:                        try
        !          3853:                        {
        !          3854:                                BootEncStatus = BootEncObj->GetStatus();
        !          3855:                                memcpy (&RecentBootEncStatus, &BootEncStatus, sizeof (RecentBootEncStatus));
        !          3856:                        }
        !          3857:                        catch (...)
        !          3858:                        {
        !          3859:                                // NOP
        !          3860:                        }
        !          3861: 
1.1.1.7   root     3862:                        if (UsePreferences)
1.1       root     3863:                        {
1.1.1.7   root     3864:                                // General preferences
                   3865:                                LoadSettings (hwndDlg);
                   3866: 
                   3867:                                // Keyfiles
                   3868:                                LoadDefaultKeyFilesParam ();
                   3869:                                RestoreDefaultKeyFilesParam ();
1.1       root     3870:                        }
                   3871: 
1.1.1.7   root     3872:                        InitMainDialog (hwndDlg);
                   3873: 
                   3874:                        // Wipe cache
                   3875:                        if (bWipe)
                   3876:                                WipeCache (hwndDlg);
                   3877: 
1.1.1.2   root     3878:                        // Automount
1.1.1.7   root     3879:                        if (bAuto || (Quit && szFileName[0] != 0))
1.1       root     3880:                        {
1.1.1.5   root     3881:                                // No drive letter specified on command line
                   3882:                                if (commandLineDrive == 0)
                   3883:                                        szDriveLetter[0] = GetFirstAvailableDrive () + 'A';
                   3884: 
1.1.1.6   root     3885:                                if (bAutoMountDevices)
                   3886:                                {
                   3887:                                        defaultMountOptions = mountOptions;
1.1.1.8   root     3888:                                        if (FirstCmdKeyFile)
                   3889:                                        {
                   3890:                                                KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
                   3891:                                                FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
                   3892:                                                defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
                   3893:                                        }
                   3894: 
1.1.1.7   root     3895:                                        if (!MountAllDevices (hwndDlg, !Silent))
                   3896:                                                exitCode = 1;
                   3897:                                }
                   3898: 
                   3899:                                if (bAutoMountFavorites)
                   3900:                                {
                   3901:                                        defaultMountOptions = mountOptions;
1.1.1.8   root     3902:                                        if (FirstCmdKeyFile)
                   3903:                                        {
                   3904:                                                KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
                   3905:                                                FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
                   3906:                                                defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
                   3907:                                        }
                   3908: 
1.1.1.7   root     3909:                                        if (!MountFavoriteVolumes ())
                   3910:                                                exitCode = 1;
1.1.1.6   root     3911:                                }
1.1.1.7   root     3912: 
                   3913:                                if (szFileName[0] != 0 && !IsMountedVolume (szFileName))
1.1.1.2   root     3914:                                {
                   3915:                                        BOOL mounted;
                   3916: 
                   3917:                                        // Cached password
1.1.1.7   root     3918:                                        mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, NULL, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE);
1.1.1.2   root     3919: 
1.1.1.7   root     3920:                                        // Command line password or keyfiles
                   3921:                                        if (!mounted && (CmdVolumePassword.Length != 0 || FirstCmdKeyFile))
1.1.1.2   root     3922:                                        {
1.1.1.7   root     3923:                                                BOOL reportBadPasswd = CmdVolumePassword.Length > 0;
                   3924: 
                   3925:                                                if (FirstCmdKeyFile)
1.1.1.12  root     3926:                                                        KeyFilesApply (&CmdVolumePassword, FirstCmdKeyFile);
1.1.1.7   root     3927: 
                   3928:                                                mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A',
                   3929:                                                        szFileName, &CmdVolumePassword, bCacheInDriver, bForceMount,
                   3930:                                                        &mountOptions, Silent, reportBadPasswd);
                   3931: 
                   3932:                                                burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
                   3933:                                        }
                   3934: 
                   3935:                                        if (FirstCmdKeyFile)
                   3936:                                        {
                   3937:                                                FirstKeyFile = FirstCmdKeyFile;
                   3938:                                                KeyFilesEnable = TRUE;
1.1.1.2   root     3939:                                        }
                   3940: 
                   3941:                                        // Ask user for password
1.1.1.7   root     3942:                                        while (!mounted && !Silent)
1.1.1.2   root     3943:                                        {
1.1.1.7   root     3944:                                                VolumePassword.Length = 0;
1.1.1.2   root     3945: 
1.1.1.7   root     3946:                                                strcpy (PasswordDlgVolume, szFileName);
                   3947:                                                if (!AskUserPassword (hwndDlg, &VolumePassword))
1.1.1.2   root     3948:                                                        break;
                   3949: 
1.1.1.11  root     3950:                                                WaitCursor ();
1.1.1.7   root     3951: 
                   3952:                                                if (KeyFilesEnable && FirstKeyFile)
1.1.1.12  root     3953:                                                        KeyFilesApply (&VolumePassword, FirstKeyFile);
1.1.1.7   root     3954: 
                   3955:                                                mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, FALSE, TRUE);
                   3956: 
                   3957:                                                burn (&VolumePassword, sizeof (VolumePassword));
                   3958:                                                burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
                   3959: 
1.1.1.2   root     3960:                                                NormalCursor ();
                   3961:                                        }
                   3962: 
1.1.1.7   root     3963:                                        if (UsePreferences)
1.1.1.11  root     3964:                                        {
1.1.1.7   root     3965:                                                RestoreDefaultKeyFilesParam ();
1.1.1.11  root     3966:                                                bCacheInDriver = bCacheInDriverDefault;
                   3967:                                        }
1.1.1.7   root     3968: 
1.1.1.5   root     3969:                                        if (mounted > 0)
1.1.1.2   root     3970:                                        {
1.1.1.11  root     3971:                                                if (bBeep) 
                   3972:                                                        MessageBeep (-1);
                   3973: 
                   3974:                                                if (bExplore) 
                   3975:                                                        OpenVolumeExplorerWindow (szDriveLetter[0] - 'A');
                   3976: 
1.1.1.7   root     3977:                                                RefreshMainDlg(hwndDlg);
1.1.1.11  root     3978: 
                   3979:                                                if(!Silent)
                   3980:                                                {
1.1.1.13! root     3981:                                                        // Check for deprecated CBC mode
        !          3982:                                                        modeOfOperation = GetModeOfOperationByDriveNo (szDriveLetter[0] - 'A');
        !          3983:                                                        if (modeOfOperation == CBC || modeOfOperation == OUTER_CBC)
        !          3984:                                                                Warning("WARN_CBC_MODE");
        !          3985: 
        !          3986:                                                        // Check for deprecated 64-bit-block ciphers
1.1.1.11  root     3987:                                                        if (GetCipherBlockSizeByDriveNo (szDriveLetter[0] - 'A') == 64)
                   3988:                                                                Warning("WARN_64_BIT_BLOCK_CIPHER");
                   3989: 
                   3990:                                                        // Check for problematic file extensions (exe, dll, sys)
                   3991:                                                        if (CheckFileExtension (szFileName))
                   3992:                                                                Warning ("EXE_FILE_EXTENSION_MOUNT_WARNING");
                   3993:                                                }
1.1.1.2   root     3994:                                        }
1.1.1.7   root     3995:                                        else
                   3996:                                                exitCode = 1;
1.1.1.2   root     3997:                                }
1.1.1.12  root     3998:                                else if (bExplore && GetMountedVolumeDriveNo (szFileName) != -1)
                   3999:                                        OpenVolumeExplorerWindow (GetMountedVolumeDriveNo (szFileName));
1.1.1.10  root     4000:                                else if (szFileName[0] != 0 && IsMountedVolume (szFileName))
1.1.1.11  root     4001:                                        Warning ("VOL_ALREADY_MOUNTED");
1.1.1.10  root     4002:                                        
1.1.1.8   root     4003:                                if (!Quit)
                   4004:                                        RefreshMainDlg(hwndDlg);
1.1.1.7   root     4005:                        }
                   4006: 
                   4007:                        // Wipe command line password
                   4008:                        if (CmdVolumePassword.Length != 0)
                   4009:                        {
                   4010:                                burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
                   4011:                                CmdVolumePassword.Length = 0;
1.1       root     4012:                        }
                   4013: 
1.1.1.7   root     4014:                        // Wipe command line keyfiles
                   4015:                        if (FirstCmdKeyFile)
1.1.1.8   root     4016:                        {
                   4017:                                if (defaultKeyFilesParam.FirstKeyFile)
                   4018:                                        KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile);
                   4019: 
                   4020:                                defaultKeyFilesParam.EnableKeyFiles = FALSE;
                   4021: 
1.1.1.10  root     4022:                                if (!Quit)
                   4023:                                {
                   4024:                                        LoadSettings (hwndDlg);
                   4025:                                        LoadDefaultKeyFilesParam ();
                   4026:                                        RestoreDefaultKeyFilesParam ();
                   4027:                                }
1.1.1.8   root     4028:                        }
1.1.1.7   root     4029: 
                   4030:                        // Dismount
1.1.1.5   root     4031:                        if (cmdUnmountDrive > 0)
1.1.1.7   root     4032:                        {
                   4033:                                if (!Dismount (hwndDlg, (char)toupper(szDriveLetter[0]) - 'A'))
                   4034:                                        exitCode = 1;
                   4035:                        }
1.1.1.5   root     4036:                        else if (cmdUnmountDrive == -1)
1.1.1.7   root     4037:                        {
                   4038:                                if (!DismountAll (hwndDlg, bForceUnmount, !Silent, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY))
                   4039:                                        exitCode = 1;
                   4040:                        }
1.1.1.5   root     4041: 
1.1.1.7   root     4042:                        // TaskBar icon
                   4043:                        if (bEnableBkgTask)
                   4044:                                TaskBarIconAdd (hwndDlg);
1.1.1.11  root     4045: 
1.1.1.7   root     4046:                        // Quit
1.1.1.12  root     4047:                        if (Quit)
                   4048:                        {
                   4049:                                if (TaskBarIconMutex == NULL)
                   4050:                                        exit (exitCode);
                   4051: 
                   4052:                                MainWindowHidden = TRUE;
                   4053: 
                   4054:                                LoadSettings (hwndDlg);
                   4055:                                LoadDefaultKeyFilesParam ();
                   4056:                                RestoreDefaultKeyFilesParam ();
                   4057: 
                   4058:                                if (!bEnableBkgTask)
                   4059:                                {
                   4060:                                        if (TaskBarIconMutex)
                   4061:                                                TaskBarIconRemove (hwndDlg);
                   4062:                                        exit (exitCode);
                   4063:                                }
                   4064:                        }
1.1.1.7   root     4065: 
1.1.1.8   root     4066:                        // No command line arguments or only /volume => bring active instance
                   4067:                        // to foreground if available
                   4068:                        if (NoCmdLineArgs == 0 || (CmdLineVolumeSpecified && NoCmdLineArgs <= 2))
                   4069:                        {
                   4070:                                HWND h = hwndDlg;
                   4071:                                EnumWindows (FindTCWindowEnum, (LPARAM) &h);
                   4072: 
                   4073:                                if (h != hwndDlg)
                   4074:                                {
                   4075:                                        if (CmdLineVolumeSpecified)
                   4076:                                        {
                   4077:                                                COPYDATASTRUCT cd;
                   4078:                                                memcpy (&cd.dwData, WM_COPY_SET_VOLUME_NAME, 4);
                   4079:                                                cd.lpData = szFileName;
                   4080:                                                cd.cbData = strlen (szFileName) + 1;
                   4081: 
                   4082:                                                SendMessage (h, WM_COPYDATA, (WPARAM)hwndDlg, (LPARAM)&cd);
                   4083:                                        }
                   4084: 
1.1.1.13! root     4085:                                        SendMessage (h, TC_APPMSG_MOUNT_SHOW_WINDOW, 0, 0);
1.1.1.8   root     4086: 
                   4087:                                        ShowWindow (h, SW_SHOW);
                   4088:                                        SetForegroundWindow (h);
1.1.1.12  root     4089: 
                   4090:                                        if (TaskBarIconMutex == NULL)
                   4091:                                                exit (0);
1.1.1.8   root     4092:                                }
                   4093:                        }
                   4094: 
1.1.1.12  root     4095:                        // Register hot keys
                   4096:                        if (!RegisterAllHotkeys (hwndDlg, Hotkeys)
                   4097:                                && TaskBarIconMutex != NULL)    // Warn only if we are the first instance of TrueCrypt
                   4098:                                Warning("HOTKEY_REGISTRATION_ERROR");
                   4099: 
1.1.1.7   root     4100:                        Silent = FALSE;
                   4101: 
                   4102:                        GetMountList (&LastKnownMountList);
1.1.1.13! root     4103:                        SetTimer (hwndDlg, TIMER_ID_MAIN, TIMER_INTERVAL_MAIN, NULL);
1.1.1.3   root     4104: 
1.1.1.11  root     4105:                        taskBarCreatedMsg = RegisterWindowMessage ("TaskbarCreated");
                   4106: 
1.1       root     4107:                        SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1.1.13! root     4108: 
        !          4109:                        /* Check system encryption status */
        !          4110: 
        !          4111:                        if (!Quit)              // Do not care about system encryption if we were launched from the system startup sequence (the wizard was added to it too).
        !          4112:                        {
        !          4113:                                if (SysEncryptionOrDecryptionRequired ())
        !          4114:                                {
        !          4115:                                        if (CreateSysEncMutex ())       // If no instance of the wizard is currently taking care of system encryption
        !          4116:                                        {
        !          4117:                                                CloseSysEncMutex ();    // We shouldn't block the mutex for too long at this point
        !          4118: 
        !          4119:                                                if (SystemEncryptionStatus == SYSENC_STATUS_PRETEST
        !          4120:                                                        || AskWarnYesNo ("SYSTEM_ENCRYPTION_RESUME_PROMPT") == IDYES)
        !          4121:                                                {
        !          4122:                                                        // The wizard was not launched during the system startup seq, or the user may have forgotten
        !          4123:                                                        // to resume the encryption/decryption process.
        !          4124: 
        !          4125: 
        !          4126:                                                        LaunchVolCreationWizard (hwndDlg, "/csysenc");
        !          4127:                                                }
        !          4128:                                        }
        !          4129:                                }
        !          4130:                        }
1.1       root     4131:                }
                   4132:                return 0;
                   4133: 
1.1.1.7   root     4134:        case WM_WINDOWPOSCHANGING:
                   4135:                if (MainWindowHidden)
                   4136:                {
1.1.1.13! root     4137:                        // Prevent window from being shown
1.1.1.7   root     4138:                        PWINDOWPOS wp = (PWINDOWPOS)lParam;
                   4139:                        wp->flags &= ~SWP_SHOWWINDOW;
                   4140:                        return 0;
                   4141:                }
                   4142:                return 1;
                   4143: 
1.1       root     4144:        case WM_SYSCOMMAND:
                   4145:                if (lw == IDC_ABOUT)
                   4146:                {
1.1.1.7   root     4147:                        DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1       root     4148:                        return 1;
                   4149:                }
                   4150:                return 0;
                   4151: 
                   4152:        case WM_HELP:
1.1.1.7   root     4153:                OpenPageHelp (hwndDlg, 0);
1.1       root     4154:                return 1;
                   4155: 
1.1.1.7   root     4156:        case WM_ENDSESSION:
                   4157:                if (TaskBarIconMutex != NULL)
1.1       root     4158:                {
1.1.1.7   root     4159:                        if (bDismountOnLogOff)
                   4160:                        {
                   4161:                                // Auto-dismount when user logs off
                   4162:                                DWORD dwResult;
                   4163: 
                   4164:                                if (bWipeCacheOnAutoDismount)
1.1.1.13! root     4165:                                        DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.7   root     4166: 
                   4167:                                if (!DismountAll (hwndDlg, FALSE, FALSE, 5, 1000))
                   4168:                                {
                   4169:                                        if (bForceAutoDismount)
                   4170:                                                DismountAll (hwndDlg, TRUE, FALSE, 1, 0);
                   4171:                                        else
                   4172:                                                DismountAll (hwndDlg, FALSE, TRUE, 1, 0);
                   4173:                                }
                   4174:                        }
                   4175: 
                   4176:                        TaskBarIconRemove (hwndDlg);
                   4177:                }
1.1.1.13! root     4178:                EndMainDlg (hwndDlg);
        !          4179:                localcleanup ();
1.1.1.7   root     4180:                return 0;
                   4181: 
                   4182:        case WM_POWERBROADCAST:
                   4183:                if (wParam == PBT_APMSUSPEND
                   4184:                        && TaskBarIconMutex != NULL && bDismountOnPowerSaving)
                   4185:                {
                   4186:                        // Auto-dismount when entering power-saving mode
                   4187:                        DWORD dwResult;
1.1.1.12  root     4188:                        BOOL volumesMounted = LastKnownMountList.ulMountedDrives != 0;
                   4189: 
1.1.1.7   root     4190:                        if (bWipeCacheOnAutoDismount)
1.1.1.13! root     4191:                                DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.12  root     4192: 
                   4193:                        if (DismountAll (hwndDlg, bForceAutoDismount, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY) && volumesMounted)
                   4194:                                Info ("MOUNTED_VOLUMES_AUTO_DISMOUNTED");
1.1.1.7   root     4195:                }
                   4196:                return 0;
                   4197: 
                   4198:        case WM_TIMER:
                   4199:                {
                   4200:                        // Check mount list and update GUI if needed
                   4201:                        CheckMountList ();
                   4202: 
                   4203:                        // Cache status
                   4204:                        if (IsPasswordCacheEmpty() == IsWindowEnabled (GetDlgItem (hwndDlg, IDC_WIPE_CACHE)))
                   4205:                                EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_CACHE), !IsPasswordCacheEmpty());
                   4206: 
                   4207:                        if (TaskBarIconMutex != NULL)
                   4208:                        {
                   4209:                                // Idle auto-dismount
                   4210:                                if (MaxVolumeIdleTime > 0)
                   4211:                                        DismountIdleVolumes ();
                   4212: 
                   4213:                                // Screen saver auto-dismount
                   4214:                                if (bDismountOnScreenSaver)
                   4215:                                {
                   4216:                                        static BOOL previousState = FALSE;
                   4217:                                        BOOL running = FALSE;
                   4218:                                        SystemParametersInfo (SPI_GETSCREENSAVERRUNNING, 0, &running, 0);
                   4219: 
                   4220:                                        if (running && !previousState)
                   4221:                                        {
                   4222:                                                DWORD dwResult;
                   4223:                                                previousState = TRUE;
                   4224: 
                   4225:                                                if (bWipeCacheOnAutoDismount)
1.1.1.13! root     4226:                                                        DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.12  root     4227: 
                   4228:                                                DismountAll (hwndDlg, bForceAutoDismount, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1.1.7   root     4229:                                        }
                   4230:                                        else
                   4231:                                        {
                   4232:                                                previousState = running;
1.1.1.8   root     4233:                                        }
1.1.1.7   root     4234:                                }
                   4235:                        }
                   4236: 
1.1.1.8   root     4237:                        // Exit background process in non-install mode or if no volume mounted
1.1.1.7   root     4238:                        // and no other instance active
                   4239:                        if (LastKnownMountList.ulMountedDrives == 0
1.1.1.13! root     4240:                                && MainWindowHidden
1.1.1.7   root     4241: #ifndef _DEBUG
                   4242:                                && (bCloseBkgTaskWhenNoVolumes || IsNonInstallMode ()) 
                   4243: #endif
1.1.1.13! root     4244:                                && !SysEncDeviceActive (TRUE)
1.1.1.7   root     4245:                                && GetDriverRefCount () < 2)
                   4246:                        {
                   4247:                                TaskBarIconRemove (hwndDlg);
                   4248:                                EndMainDlg (hwndDlg);
                   4249:                        }
1.1       root     4250: 
                   4251:                        return 1;
                   4252:                }
1.1.1.13! root     4253:                return 1;
1.1       root     4254: 
1.1.1.13! root     4255:        case TC_APPMSG_TASKBAR_ICON:
1.1       root     4256:                {
1.1.1.7   root     4257:                        switch (lParam)
                   4258:                        {
                   4259:                        case WM_LBUTTONDOWN:
1.1.1.8   root     4260:                                SetForegroundWindow (hwndDlg);
1.1.1.7   root     4261:                                MainWindowHidden = FALSE;
                   4262:                                ShowWindow (hwndDlg, SW_SHOW);
1.1.1.13! root     4263:                                ShowWindow (hwndDlg, SW_RESTORE);
1.1.1.7   root     4264:                                break;
                   4265: 
                   4266:                        case WM_RBUTTONDOWN:
                   4267:                                {
                   4268:                                        POINT pos;
                   4269:                                        HMENU popup = CreatePopupMenu ();
                   4270:                                        int sel, i, n;
1.1.1.8   root     4271:                                        
1.1.1.7   root     4272:                                        if (MainWindowHidden)
                   4273:                                        {
                   4274:                                                AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("SHOW_TC"));
                   4275:                                                AppendMenu (popup, MF_SEPARATOR, 0, NULL);
                   4276:                                        }
                   4277:                                        else if (bEnableBkgTask
                   4278:                                                && (!(LastKnownMountList.ulMountedDrives == 0
                   4279:                                                && (bCloseBkgTaskWhenNoVolumes || IsNonInstallMode ()) 
1.1.1.13! root     4280:                                                && !SysEncDeviceActive (TRUE)
1.1.1.7   root     4281:                                                && GetDriverRefCount () < 2)))
                   4282:                                        {
                   4283:                                                AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("HIDE_TC"));
                   4284:                                                AppendMenu (popup, MF_SEPARATOR, 0, NULL);
                   4285:                                        }
1.1.1.13! root     4286:                                        AppendMenuW (popup, MF_STRING, IDM_MOUNTALL, GetString ("IDC_MOUNTALL"));
1.1.1.7   root     4287:                                        AppendMenuW (popup, MF_STRING, IDM_MOUNT_FAVORITE_VOLUMES, GetString ("IDM_MOUNT_FAVORITE_VOLUMES"));
                   4288:                                        AppendMenuW (popup, MF_STRING, IDM_UNMOUNTALL, GetString ("IDM_UNMOUNTALL"));
                   4289:                                        AppendMenu (popup, MF_SEPARATOR, 0, NULL);
                   4290: 
                   4291:                                        for (n = 0; n < 2; n++)
                   4292:                                        {
                   4293:                                                for (i = 0; i < 26; i++)
                   4294:                                                {
                   4295:                                                        if (LastKnownMountList.ulMountedDrives & (1 << i))
                   4296:                                                        {
                   4297:                                                                wchar_t s[1024];
1.1.1.13! root     4298:                                                                wchar_t *vol = (wchar_t *) LastKnownMountList.wszVolume[i];
1.1.1.7   root     4299: 
                   4300:                                                                if (wcsstr (vol, L"\\??\\")) vol += 4;
                   4301: 
                   4302:                                                                wsprintfW (s, L"%s %c: (%s)",
                   4303:                                                                        GetString (n==0 ? "OPEN" : "DISMOUNT"),
                   4304:                                                                        i + L'A', 
                   4305:                                                                        vol);
1.1.1.13! root     4306:                                                                AppendMenuW (popup, MF_STRING, n*26 + TRAYICON_MENU_DRIVE_OFFSET + i, s);
1.1.1.7   root     4307:                                                        }
                   4308:                                                }
                   4309:                                                if (LastKnownMountList.ulMountedDrives != 0)
                   4310:                                                        AppendMenu (popup, MF_SEPARATOR, 0, NULL);
                   4311:                                        }
                   4312: 
                   4313:                                        AppendMenuW (popup, MF_STRING, IDM_HELP, GetString ("MENU_HELP"));
1.1.1.11  root     4314:                                        AppendMenuW (popup, MF_STRING, IDM_HOMEPAGE_SYSTRAY, GetString ("HOMEPAGE"));
1.1.1.7   root     4315:                                        AppendMenuW (popup, MF_STRING, IDM_PREFERENCES, GetString ("IDM_PREFERENCES"));
                   4316:                                        AppendMenuW (popup, MF_STRING, IDM_ABOUT, GetString ("IDM_ABOUT"));
                   4317:                                        AppendMenu (popup, MF_SEPARATOR, 0, NULL);
1.1.1.13! root     4318:                                        AppendMenuW (popup, MF_STRING, IDCANCEL, GetString ("EXIT"));
1.1.1.7   root     4319: 
                   4320:                                        GetCursorPos (&pos);
                   4321: 
                   4322:                                        SetForegroundWindow(hwndDlg);
                   4323: 
                   4324:                                        sel = TrackPopupMenu (popup,
                   4325:                                                TPM_RETURNCMD | TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON,
                   4326:                                                pos.x,
                   4327:                                                pos.y,
                   4328:                                                0,
                   4329:                                                hwndDlg,
                   4330:                                                NULL);
                   4331: 
1.1.1.13! root     4332:                                        if (sel >= TRAYICON_MENU_DRIVE_OFFSET && sel < TRAYICON_MENU_DRIVE_OFFSET + 26)
1.1.1.7   root     4333:                                        {
1.1.1.13! root     4334:                                                OpenVolumeExplorerWindow (sel - TRAYICON_MENU_DRIVE_OFFSET);
1.1.1.7   root     4335:                                        }
1.1.1.13! root     4336:                                        else if (sel >= TRAYICON_MENU_DRIVE_OFFSET + 26 && sel < TRAYICON_MENU_DRIVE_OFFSET + 26*2)
1.1.1.7   root     4337:                                        {
                   4338:                                                if (CheckMountList ())
1.1.1.13! root     4339:                                                        Dismount (hwndDlg, sel - TRAYICON_MENU_DRIVE_OFFSET - 26);
1.1.1.7   root     4340:                                        }
                   4341:                                        else if (sel == IDM_SHOW_HIDE)
                   4342:                                        {
1.1.1.13! root     4343:                                                ChangeMainWindowVisibility ();
1.1.1.7   root     4344:                                        }
1.1.1.11  root     4345:                                        else if (sel == IDM_HOMEPAGE_SYSTRAY)
                   4346:                                        {
                   4347:                                                Applink ("home", TRUE, "");
                   4348:                                        }
1.1.1.13! root     4349:                                        else if (sel == IDCANCEL)
1.1.1.7   root     4350:                                        {
1.1.1.13! root     4351:                                                if ((LastKnownMountList.ulMountedDrives == 0
        !          4352:                                                        && !SysEncDeviceActive (TRUE))
1.1.1.7   root     4353:                                                        || AskWarnNoYes ("CONFIRM_EXIT") == IDYES)
                   4354:                                                {
                   4355:                                                        // Close all other TC windows
                   4356:                                                        EnumWindows (CloseTCWindowsEnum, 0);
                   4357: 
                   4358:                                                        TaskBarIconRemove (hwndDlg);
                   4359:                                                        SendMessage (hwndDlg, WM_COMMAND, sel, 0);
                   4360:                                                }
                   4361:                                        }
                   4362:                                        else
                   4363:                                        {
                   4364:                                                SendMessage (hwndDlg, WM_COMMAND, sel, 0);
                   4365:                                        }
                   4366: 
                   4367:                                        PostMessage(hwndDlg, WM_NULL, 0, 0);
                   4368:                                        DestroyMenu (popup);
                   4369:                                }
1.1       root     4370:                        }
1.1.1.7   root     4371:                        return 1;
                   4372:                }
                   4373: 
1.1.1.13! root     4374:        case TC_APPMSG_CLOSE_BKG_TASK:
1.1.1.11  root     4375:                if (TaskBarIconMutex != NULL)
                   4376:                        TaskBarIconRemove (hwndDlg);
                   4377: 
                   4378:                return 1;
                   4379: 
1.1.1.13! root     4380:        case TC_APPMSG_SYSENC_CONFIG_UPDATE:
        !          4381:                LoadSysEncSettings (hwndDlg);
        !          4382: 
        !          4383:                // The wizard adds TrueCrypt.exe to the system startup sequence so we must update our cached settings
        !          4384:                LoadSettings (hwndDlg);
        !          4385: 
        !          4386:                return 1;
        !          4387: 
1.1.1.11  root     4388:        case WM_DEVICECHANGE:
1.1.1.12  root     4389:                if (!IgnoreWmDeviceChange && wParam != DBT_DEVICEARRIVAL)
1.1.1.11  root     4390:                {
                   4391:                        // Check if any host device has been removed and force dismount of volumes accordingly
                   4392:                        PDEV_BROADCAST_HDR hdr = (PDEV_BROADCAST_HDR) lParam;
1.1.1.12  root     4393:                        int m;
                   4394: 
                   4395:                        GetMountList (&LastKnownMountList);
                   4396: 
1.1.1.11  root     4397:                        if (wParam == DBT_DEVICEREMOVECOMPLETE && hdr->dbch_devicetype == DBT_DEVTYP_VOLUME)
                   4398:                        {
1.1.1.12  root     4399:                                // File-hosted volumes
1.1.1.11  root     4400:                                PDEV_BROADCAST_VOLUME vol = (PDEV_BROADCAST_VOLUME) lParam;
1.1.1.12  root     4401:                                int i;
1.1.1.11  root     4402: 
                   4403:                                for (i = 0; i < 26; i++)
                   4404:                                {
                   4405:                                        if (vol->dbcv_unitmask & (1 << i))
                   4406:                                        {
                   4407:                                                for (m = 0; m < 26; m++)
                   4408:                                                {
                   4409:                                                        if (LastKnownMountList.ulMountedDrives & (1 << m))
                   4410:                                                        {
1.1.1.13! root     4411:                                                                wchar_t *vol = (wchar_t *) LastKnownMountList.wszVolume[m];
1.1.1.11  root     4412: 
1.1.1.12  root     4413:                                                                if (wcsstr (vol, L"\\??\\") == vol)
1.1.1.11  root     4414:                                                                        vol += 4;
                   4415: 
1.1.1.12  root     4416:                                                                if (vol[1] == L':' && i == (vol[0] - (vol[0] <= L'Z' ? L'A' : L'a')))
1.1.1.11  root     4417:                                                                {
                   4418:                                                                        UnmountVolume (hwndDlg, m, TRUE);
                   4419:                                                                        if (bWipeCacheOnAutoDismount || bWipeCacheOnExit)
                   4420:                                                                                WipeCache (NULL);
                   4421:                                                                }
                   4422:                                                        }
                   4423:                                                }
                   4424:                                        }
                   4425:                                }
1.1.1.12  root     4426:                        }
1.1.1.11  root     4427: 
1.1.1.12  root     4428:                        // Device-hosted volumes
                   4429:                        for (m = 0; m < 26; m++)
                   4430:                        {
                   4431:                                if (LastKnownMountList.ulMountedDrives & (1 << m))
                   4432:                                {
1.1.1.13! root     4433:                                        wchar_t *vol = (wchar_t *) LastKnownMountList.wszVolume[m];
1.1.1.12  root     4434:                                        char volp[MAX_PATH];
                   4435: 
                   4436:                                        if (wcsstr (vol, L"\\??\\") == vol)
                   4437:                                                vol += 4;
                   4438: 
                   4439:                                        _snprintf (volp, sizeof(volp), "%ls", vol);
                   4440: 
                   4441:                                        if (IsVolumeDeviceHosted (volp))
                   4442:                                        {
                   4443:                                                OPEN_TEST_STRUCT ots;
                   4444: 
                   4445:                                                if (!OpenDevice (volp, &ots))
                   4446:                                                {
                   4447:                                                        UnmountVolume (hwndDlg, m, TRUE);
                   4448:                                                        if (bWipeCacheOnAutoDismount || bWipeCacheOnExit)
                   4449:                                                                WipeCache (NULL);
                   4450:                                                }
                   4451:                                        }
                   4452:                                }
1.1.1.11  root     4453:                        }
1.1.1.12  root     4454:                        return 1;
1.1.1.11  root     4455:                }
1.1.1.12  root     4456:                return 0;
1.1.1.11  root     4457: 
1.1.1.7   root     4458:        case WM_NOTIFY:
                   4459: 
                   4460:                if(wParam == IDC_DRIVELIST)
                   4461:                {
                   4462:                        /* Single click within drive list */
                   4463:                        if (((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED ))
                   4464:                        {
                   4465:                                nSelectedDriveIndex = ((LPNMLISTVIEW) lParam)->iItem;
                   4466:                                EnableDisableButtons (hwndDlg);
                   4467:                                return 1;
                   4468:                        }
                   4469: 
                   4470:                        /* Double click within drive list */
                   4471:                        if (((LPNMHDR) lParam)->code == LVN_ITEMACTIVATE)
1.1       root     4472:                        {
1.1.1.13! root     4473:                                int state = GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), ((LPNMITEMACTIVATE)lParam)->iItem );
1.1.1.7   root     4474:                                nSelectedDriveIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
1.1.1.13! root     4475:                                if (LOWORD(state) == TC_MLIST_ITEM_NONSYS_VOL || LOWORD(state) == TC_MLIST_ITEM_SYS_PARTITION)
1.1.1.7   root     4476:                                {
                   4477:                                        // Open explorer window for mounted volume
1.1.1.11  root     4478:                                        WaitCursor ();
1.1.1.7   root     4479:                                        OpenVolumeExplorerWindow (HIWORD(state) - 'A');
                   4480:                                        NormalCursor ();
                   4481:                                }
1.1.1.13! root     4482:                                else if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == TC_MLIST_ITEM_FREE)
1.1.1.7   root     4483:                                {
1.1.1.11  root     4484:                                        mountOptions = defaultMountOptions;
                   4485: 
1.1.1.9   root     4486:                                        if (GetAsyncKeyState (VK_CONTROL) < 0)
                   4487:                                        {
                   4488:                                                if (IDCANCEL == DialogBoxParamW (hInst, 
                   4489:                                                        MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
                   4490:                                                        (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions))
                   4491:                                                        return 1;
                   4492: 
                   4493:                                                if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
1.1.1.12  root     4494:                                                        KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile);
1.1.1.9   root     4495:                                        }
                   4496: 
1.1.1.7   root     4497:                                        if (CheckMountList ())
                   4498:                                                Mount (hwndDlg, 0, 0);
                   4499:                                }
                   4500:                                return 1;
                   4501:                        }
                   4502: 
                   4503:                        /* Right click and drag&drop operations */
1.1.1.13! root     4504: 
        !          4505:                        switch (((NM_LISTVIEW *) lParam)->hdr.code)
1.1.1.7   root     4506:                        {
                   4507:                        case NM_RCLICK:
                   4508:                        case LVN_BEGINRDRAG:
                   4509:                                /* If the mouse was moving while the right mouse button is pressed, popup menu would
                   4510:                                not open, because drag&drop operation would be initiated. Therefore, we're handling
                   4511:                                RMB drag-and-drop operations as well. */
                   4512:                                {
                   4513: 
                   4514:                                        /* Drive list context menu */
                   4515: 
                   4516:                                        int menuItem;
                   4517:                                        HMENU popup = CreatePopupMenu ();
                   4518: 
                   4519:                                        SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
                   4520: 
1.1.1.13! root     4521:                                        switch (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))))
1.1.1.7   root     4522:                                        {
1.1.1.13! root     4523:                                        case TC_MLIST_ITEM_FREE:
        !          4524:                                        
1.1.1.7   root     4525:                                                // No mounted volume at this drive letter
1.1.1.13! root     4526: 
1.1.1.7   root     4527:                                                AppendMenuW (popup, MF_STRING, IDM_MOUNT_VOLUME, GetString ("IDM_MOUNT_VOLUME"));
1.1.1.13! root     4528:                                                break;
        !          4529: 
        !          4530:                                        case TC_MLIST_ITEM_NONSYS_VOL:
        !          4531: 
        !          4532:                                                // There's a mounted non-system volume at this drive letter
        !          4533: 
1.1.1.7   root     4534:                                                AppendMenuW (popup, MF_STRING, IDM_UNMOUNT_VOLUME, GetString ("DISMOUNT"));
                   4535:                                                AppendMenuW (popup, MF_STRING, IDPM_OPEN_VOLUME, GetString ("OPEN"));
                   4536:                                                AppendMenu (popup, MF_SEPARATOR, 0, NULL);
                   4537:                                                AppendMenuW (popup, MF_STRING, IDPM_CHECK_FILESYS, GetString ("IDPM_CHECK_FILESYS"));
                   4538:                                                AppendMenuW (popup, MF_STRING, IDPM_REPAIR_FILESYS, GetString ("IDPM_REPAIR_FILESYS"));
                   4539:                                                AppendMenu (popup, MF_SEPARATOR, 0, NULL);
                   4540:                                                AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES"));
1.1.1.13! root     4541:                                                break;
        !          4542: 
        !          4543:                                        case TC_MLIST_ITEM_SYS_PARTITION:
        !          4544:                                        case TC_MLIST_ITEM_SYS_DRIVE:
        !          4545: 
        !          4546:                                                // System partition/drive
        !          4547: 
        !          4548:                                                PopulateSysEncContextMenu (popup, FALSE);
        !          4549:                                                break;
1.1.1.7   root     4550:                                        }
                   4551: 
                   4552:                                        mPos=GetMessagePos();
                   4553: 
                   4554:                                        menuItem = TrackPopupMenu (popup,
                   4555:                                                TPM_RETURNCMD | TPM_LEFTBUTTON,
                   4556:                                                GET_X_LPARAM(mPos),
                   4557:                                                GET_Y_LPARAM(mPos),
                   4558:                                                0,
                   4559:                                                hwndDlg,
                   4560:                                                NULL);
                   4561: 
                   4562:                                        DestroyMenu (popup);
                   4563: 
                   4564:                                        switch (menuItem)
                   4565:                                        {
                   4566:                                        case IDPM_CHECK_FILESYS:
                   4567:                                        case IDPM_REPAIR_FILESYS:
                   4568:                                                {
                   4569:                                                        LPARAM lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
                   4570: 
                   4571:                                                        if (LOWORD (lLetter) != 0xffff)
                   4572:                                                        {
                   4573:                                                                wchar_t msg[1024], param[1024];
                   4574:                                                                char szTmp[32] = {0};
                   4575: 
                   4576:                                                                sprintf (szTmp, "%c:", (char) HIWORD (lLetter));
                   4577:                                                                
                   4578:                                                                wsprintfW (msg, 
                   4579:                                                                        GetString (menuItem == IDPM_REPAIR_FILESYS ? "REPAIRING_FS" : "CHECKING_FS")
                   4580:                                                                        , szTmp);
                   4581: 
                   4582:                                                                wsprintfW (param, 
                   4583:                                                                        menuItem == IDPM_REPAIR_FILESYS ? 
1.1.1.13! root     4584:                                                                                L"/C echo %s & chkdsk %hs /F /X & pause"
        !          4585:                                                                                : L"/C echo %s & chkdsk %hs & pause",
1.1.1.7   root     4586:                                                                        msg,
1.1.1.8   root     4587:                                                                        szTmp);
1.1.1.7   root     4588: 
1.1.1.11  root     4589:                                                                ShellExecuteW (NULL, 
                   4590:                                                                        (!IsAdmin() && IsUacSupported()) ? L"runas" : L"open",
                   4591:                                                                        L"cmd.exe", param, NULL, SW_SHOW);
1.1.1.7   root     4592:                                                        }
                   4593:                                                }
                   4594:                                                break;
                   4595: 
                   4596:                                        case IDM_UNMOUNT_VOLUME:
                   4597:                                                if (CheckMountList ())
                   4598:                                                        Dismount (hwndDlg, 0);
                   4599:                                                break;
                   4600: 
                   4601:                                        case IDPM_OPEN_VOLUME:
                   4602:                                                {
                   4603:                                                        int state = GetItemLong(GetDlgItem (hwndDlg, IDC_DRIVELIST), ((LPNMITEMACTIVATE)lParam)->iItem );
                   4604:                                                        nSelectedDriveIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
                   4605: 
1.1.1.11  root     4606:                                                        WaitCursor ();
1.1.1.7   root     4607:                                                        OpenVolumeExplorerWindow (HIWORD(state) - 'A');
                   4608:                                                        NormalCursor ();
                   4609:                                                }
                   4610:                                                break;
                   4611: 
                   4612:                                        case IDM_VOLUME_PROPERTIES:
                   4613:                                                DialogBoxParamW (hInst, 
                   4614:                                                        MAKEINTRESOURCEW (IDD_VOLUME_PROPERTIES), hwndDlg,
1.1.1.13! root     4615:                                                        (DLGPROC) VolumePropertiesDlgProc, (LPARAM) FALSE);
1.1.1.7   root     4616:                                                break;
                   4617: 
                   4618:                                        case IDM_MOUNT_VOLUME:
                   4619:                                                if (!VolumeSelected(hwndDlg))
                   4620:                                                {
                   4621:                                                        Warning ("NO_VOLUME_SELECTED");
                   4622:                                                }
                   4623:                                                else
                   4624:                                                {
                   4625:                                                        mountOptions = defaultMountOptions;
                   4626: 
                   4627:                                                        if (CheckMountList ())
                   4628:                                                                Mount (hwndDlg, 0, 0);
                   4629:                                                }
                   4630:                                                break;
1.1.1.13! root     4631:                                        case IDM_ENCRYPT_SYSTEM_DEVICE:
        !          4632:                                                EncryptSystemDevice ();
        !          4633:                                                break;
        !          4634:                                        case IDM_PERMANENTLY_DECRYPT_SYS:
        !          4635:                                                DecryptSystemDevice ();
        !          4636:                                                break;
        !          4637:                                        case IDM_SYSENC_RESUME:
        !          4638:                                                ResumeInterruptedSysEncProcess ();
        !          4639:                                                break;
        !          4640:                                        case IDM_CHANGE_SYS_PASSWORD:
        !          4641:                                                ChangeSysEncPassword (hwndDlg, FALSE);
        !          4642:                                                break;
        !          4643:                                        case IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO:
        !          4644:                                                ChangeSysEncPassword (hwndDlg, TRUE);
        !          4645:                                                break;
        !          4646:                                        case IDM_CREATE_RESCUE_DISK:
        !          4647:                                                CreateRescueDisk ();
        !          4648:                                                break;
        !          4649:                                        case IDM_VERIFY_RESCUE_DISK:
        !          4650:                                                VerifyRescueDisk ();
        !          4651:                                                break;
1.1.1.7   root     4652:                                        }
                   4653:                                        return 1;
                   4654:                                }
1.1       root     4655:                        }
                   4656:                }
                   4657:                return 0;
                   4658: 
                   4659:        case WM_ERASEBKGND:
                   4660:                return 0;
                   4661: 
                   4662:        case WM_COMMAND:
                   4663: 
1.1.1.13! root     4664:                if (lw == IDCANCEL || lw == IDC_EXIT)
1.1       root     4665:                {
                   4666:                        EndMainDlg (hwndDlg);
                   4667:                        return 1;
                   4668:                }
                   4669: 
                   4670:                if (lw == IDHELP || lw == IDM_HELP)
                   4671:                {
1.1.1.7   root     4672:                        OpenPageHelp (hwndDlg, 0);
1.1       root     4673:                        return 1;
                   4674:                }
                   4675: 
1.1.1.12  root     4676:                if (lw == IDM_ABOUT || lw == IDC_LOGO)
1.1       root     4677:                {
1.1.1.7   root     4678:                        DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1       root     4679:                        return 1;
                   4680:                }
                   4681: 
1.1.1.13! root     4682:                if (lw == IDOK && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == TC_MLIST_ITEM_NONSYS_VOL
1.1.1.7   root     4683:                        || lw == IDM_UNMOUNT_VOLUME)
1.1       root     4684:                {
1.1.1.13! root     4685:                        if (lw == IDM_UNMOUNT_VOLUME && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) != TC_MLIST_ITEM_NONSYS_VOL)
1.1.1.6   root     4686:                        {
1.1.1.7   root     4687:                                Warning ("SELECT_A_MOUNTED_VOLUME");
                   4688:                                return 1;
1.1.1.6   root     4689:                        }
1.1       root     4690: 
1.1.1.7   root     4691:                        if (CheckMountList ())
                   4692:                                Dismount (hwndDlg, 0);
1.1       root     4693:                        return 1;
                   4694:                }
                   4695: 
1.1.1.7   root     4696:                if ((lw == IDOK || lw == IDM_MOUNT_VOLUME || lw == IDM_MOUNT_VOLUME_OPTIONS || lw == IDC_MOUNTALL || lw == IDM_MOUNTALL) 
1.1       root     4697:                        && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == 0xffff)
                   4698:                {
1.1.1.7   root     4699:                        MessageBoxW (hwndDlg, GetString ("SELECT_FREE_DRIVE"), L"TrueCrypt", MB_ICONEXCLAMATION);
1.1       root     4700:                        return 1;
                   4701:                }
                   4702: 
1.1.1.7   root     4703:                if ((lw == IDOK || lw == IDM_MOUNT_VOLUME || lw == IDM_MOUNT_VOLUME_OPTIONS))
1.1       root     4704:                {
1.1.1.7   root     4705:                        if (!VolumeSelected(hwndDlg))
                   4706:                        {
                   4707:                                Warning ("NO_VOLUME_SELECTED");
                   4708:                        }
1.1.1.13! root     4709:                        else if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == TC_MLIST_ITEM_FREE)
1.1.1.7   root     4710:                        {
                   4711:                                mountOptions = defaultMountOptions;
                   4712: 
                   4713:                                if (lw == IDM_MOUNT_VOLUME_OPTIONS || GetAsyncKeyState (VK_CONTROL) < 0)
                   4714:                                {
                   4715:                                        if (IDCANCEL == DialogBoxParamW (hInst, 
                   4716:                                                MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
                   4717:                                                (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions))
                   4718:                                                return 1;
                   4719: 
                   4720:                                        if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
1.1.1.12  root     4721:                                                KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile);
1.1.1.7   root     4722:                                }
                   4723: 
                   4724:                                if (CheckMountList ())
                   4725:                                        Mount (hwndDlg, 0, 0);
                   4726:                        }
1.1.1.13! root     4727:                        else
        !          4728:                                Warning ("SELECT_FREE_DRIVE");
1.1       root     4729:                        return 1;
                   4730:                }
                   4731: 
1.1.1.7   root     4732:                if (lw == IDC_UNMOUNTALL || lw == IDM_UNMOUNTALL)
1.1       root     4733:                {
1.1.1.7   root     4734:                        DismountAll (hwndDlg, bForceUnmount, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1       root     4735:                        return 1;
                   4736:                }
                   4737: 
1.1.1.7   root     4738:                if (lw == IDC_MOUNTALL || lw == IDM_MOUNTALL)
1.1       root     4739:                {
1.1.1.7   root     4740:                        // If Shift key is down and the password cache isn't empty, bypass password prompt
                   4741:                        MountAllDevices (hwndDlg, !(GetAsyncKeyState (VK_SHIFT) < 0 && !IsPasswordCacheEmpty()));
1.1       root     4742:                        return 1;
                   4743:                }
                   4744:                
1.1.1.7   root     4745:                if (lw == IDC_SELECT_FILE || lw == IDM_SELECT_FILE)
1.1       root     4746:                {
                   4747:                        SelectContainer (hwndDlg);
                   4748:                        return 1;
                   4749:                }
                   4750: 
1.1.1.7   root     4751:                if (lw == IDC_SELECT_DEVICE || lw == IDM_SELECT_DEVICE)
1.1       root     4752:                {
                   4753:                        SelectPartition (hwndDlg);
                   4754:                        return 1;
                   4755:                }
                   4756: 
1.1.1.13! root     4757:                // System Encryption menu
        !          4758:                switch (lw)
        !          4759:                {
        !          4760:                case IDM_ENCRYPT_SYSTEM_DEVICE:
        !          4761:                        EncryptSystemDevice ();
        !          4762:                        break;
        !          4763:                case IDM_PERMANENTLY_DECRYPT_SYS:
        !          4764:                        DecryptSystemDevice ();
        !          4765:                        break;
        !          4766:                case IDM_SYSENC_RESUME:
        !          4767:                        ResumeInterruptedSysEncProcess ();
        !          4768:                        break;
        !          4769:                case IDM_SYSTEM_ENCRYPTION_STATUS:
        !          4770:                        ShowSystemEncryptionStatus ();
        !          4771:                        break;
        !          4772:                case IDM_CHANGE_SYS_PASSWORD:
        !          4773:                        ChangeSysEncPassword (hwndDlg, FALSE);
        !          4774:                        break;
        !          4775:                case IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO:
        !          4776:                        ChangeSysEncPassword (hwndDlg, TRUE);
        !          4777:                        break;
        !          4778:                case IDM_CREATE_RESCUE_DISK:
        !          4779:                        CreateRescueDisk ();
        !          4780:                        break;
        !          4781:                case IDM_VERIFY_RESCUE_DISK:
        !          4782:                        VerifyRescueDisk ();
        !          4783:                        break;
        !          4784:                }
        !          4785: 
1.1.1.7   root     4786:                if (lw == IDC_VOLUME_TOOLS)
                   4787:                {
1.1.1.13! root     4788:                        /* Volume Tools popup menu */
        !          4789: 
1.1.1.7   root     4790:                        int menuItem;
                   4791:                        char volPath[TC_MAX_PATH];              /* Volume to mount */
                   4792:                        HMENU popup = CreatePopupMenu ();
                   4793:                        RECT rect;
                   4794: 
1.1.1.13! root     4795:                        if (ActiveSysEncDeviceSelected ())
        !          4796:                        {
        !          4797:                                PopulateSysEncContextMenu (popup, TRUE);
        !          4798:                        }
        !          4799:                        else
        !          4800:                        {
        !          4801:                                AppendMenuW (popup, MF_STRING, IDM_CHANGE_PASSWORD, GetString ("IDM_CHANGE_PASSWORD"));
        !          4802:                                AppendMenuW (popup, MF_STRING, IDM_CHANGE_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_HEADER_KEY_DERIV_ALGO"));
        !          4803:                                AppendMenu (popup, MF_SEPARATOR, 0, NULL);
        !          4804:                                AppendMenuW (popup, MF_STRING, IDM_BACKUP_VOL_HEADER, GetString ("IDM_BACKUP_VOL_HEADER"));
        !          4805:                                AppendMenuW (popup, MF_STRING, IDM_RESTORE_VOL_HEADER, GetString ("IDM_RESTORE_VOL_HEADER"));
        !          4806:                        }
1.1.1.7   root     4807: 
                   4808:                        GetWindowRect (GetDlgItem (hwndDlg, IDC_VOLUME_TOOLS), &rect);
                   4809: 
                   4810:                        menuItem = TrackPopupMenu (popup,
                   4811:                                TPM_RETURNCMD | TPM_LEFTBUTTON,
                   4812:                                rect.left + 2,
                   4813:                                rect.top + 2,
                   4814:                                0,
                   4815:                                hwndDlg,
                   4816:                                NULL);
                   4817: 
                   4818:                        DestroyMenu (popup);
                   4819: 
                   4820:                        switch (menuItem)
                   4821:                        {
                   4822:                        case IDM_CHANGE_PASSWORD:
                   4823:                                if (!VolumeSelected(hwndDlg))
                   4824:                                {
                   4825:                                        Warning ("NO_VOLUME_SELECTED");
                   4826:                                }
                   4827:                                else
                   4828:                                {
                   4829:                                        pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
                   4830:                                        ChangePassword (hwndDlg);
                   4831:                                }
                   4832:                                break;
                   4833: 
                   4834:                        case IDM_CHANGE_HEADER_KEY_DERIV_ALGO:
                   4835:                                if (!VolumeSelected(hwndDlg))
                   4836:                                {
                   4837:                                        Warning ("NO_VOLUME_SELECTED");
                   4838:                                }
                   4839:                                else
                   4840:                                {
                   4841:                                        pwdChangeDlgMode = PCDM_CHANGE_PKCS5_PRF;
                   4842:                                        ChangePassword (hwndDlg);
                   4843:                                }
                   4844:                                break;
                   4845: 
                   4846:                        case IDM_BACKUP_VOL_HEADER:
                   4847:                                if (!VolumeSelected(hwndDlg))
                   4848:                                {
                   4849:                                        Warning ("NO_VOLUME_SELECTED");
                   4850:                                }
                   4851:                                else
                   4852:                                {
                   4853:                                        GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
                   4854: 
1.1.1.11  root     4855:                                        if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
                   4856:                                                UacBackupVolumeHeader (hwndDlg, TRUE, volPath);
                   4857:                                        else
                   4858:                                                BackupVolumeHeader (hwndDlg, TRUE, volPath);
1.1.1.7   root     4859:                                }
                   4860:                                break;
                   4861: 
                   4862:                        case IDM_RESTORE_VOL_HEADER:
                   4863:                                if (!VolumeSelected(hwndDlg))
                   4864:                                {
                   4865:                                        Warning ("NO_VOLUME_SELECTED");
                   4866:                                }
                   4867:                                else
                   4868:                                {
                   4869:                                        GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
                   4870: 
1.1.1.11  root     4871:                                        if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
                   4872:                                                UacRestoreVolumeHeader (hwndDlg, volPath);
                   4873:                                        else
                   4874:                                                RestoreVolumeHeader (hwndDlg, volPath);
1.1.1.7   root     4875:                                }
                   4876:                                break;
1.1.1.13! root     4877: 
        !          4878:                        case IDM_CHANGE_SYS_PASSWORD:
        !          4879:                                ChangeSysEncPassword (hwndDlg, FALSE);
        !          4880:                                break;
        !          4881:                        case IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO:
        !          4882:                                ChangeSysEncPassword (hwndDlg, TRUE);
        !          4883:                                break;
        !          4884:                        case IDM_CREATE_RESCUE_DISK:
        !          4885:                                CreateRescueDisk ();
        !          4886:                                break;
        !          4887:                        case IDM_VERIFY_RESCUE_DISK:
        !          4888:                                VerifyRescueDisk ();
        !          4889:                                break;
1.1.1.7   root     4890:                        }
                   4891:                        return 1;
                   4892:                }
                   4893: 
                   4894:                if (lw == IDM_CHANGE_PASSWORD)
1.1       root     4895:                {
1.1.1.7   root     4896:                        if (!VolumeSelected(hwndDlg))
                   4897:                        {
                   4898:                                Warning ("NO_VOLUME_SELECTED");
                   4899:                        }
                   4900:                        else
                   4901:                        {
1.1.1.13! root     4902:                                if (ActiveSysEncDeviceSelected ())
        !          4903:                                {
        !          4904:                                        ChangeSysEncPassword (hwndDlg, FALSE);
        !          4905:                                }
        !          4906:                                else
        !          4907:                                {
        !          4908:                                        pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
        !          4909:                                        ChangePassword (hwndDlg);
        !          4910:                                }
1.1.1.7   root     4911:                        }
1.1       root     4912:                        return 1;
                   4913:                }
                   4914: 
1.1.1.7   root     4915:                if (lw == IDM_CHANGE_HEADER_KEY_DERIV_ALGO)
                   4916:                {
                   4917:                        if (!VolumeSelected(hwndDlg))
                   4918:                        {
                   4919:                                Warning ("NO_VOLUME_SELECTED");
                   4920:                        }
                   4921:                        else
                   4922:                        {
1.1.1.13! root     4923:                                if (ActiveSysEncDeviceSelected ())
        !          4924:                                {
        !          4925:                                        ChangeSysEncPassword (hwndDlg, TRUE);
        !          4926:                                }
        !          4927:                                else
        !          4928:                                {
        !          4929:                                        pwdChangeDlgMode = PCDM_CHANGE_PKCS5_PRF;
        !          4930:                                        ChangePassword (hwndDlg);
        !          4931:                                }
1.1.1.7   root     4932:                        }
                   4933:                        return 1;
                   4934:                }
                   4935: 
                   4936:                if (lw == IDC_WIPE_CACHE || lw == IDM_WIPE_CACHE)
1.1       root     4937:                {
                   4938:                        WipeCache (hwndDlg);
                   4939:                        return 1;
                   4940:                }
                   4941: 
1.1.1.7   root     4942:                if (lw == IDM_CLEAR_HISTORY)
1.1       root     4943:                {
1.1.1.11  root     4944:                        ClearHistory (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1       root     4945:                        EnableDisableButtons (hwndDlg);
                   4946:                        return 1;
                   4947:                }
                   4948: 
1.1.1.7   root     4949:                if (lw == IDC_CREATE_VOLUME || lw == IDM_CREATE_VOLUME || lw == IDM_VOLUME_WIZARD)
1.1       root     4950:                {
1.1.1.13! root     4951:                        LaunchVolCreationWizard (hwndDlg, "");
1.1       root     4952:                        return 1;
                   4953:                }
                   4954: 
1.1.1.7   root     4955:                if (lw == IDM_ADD_REMOVE_VOL_KEYFILES)
1.1.1.3   root     4956:                {
1.1.1.7   root     4957:                        if (!VolumeSelected(hwndDlg))
                   4958:                        {
                   4959:                                Warning ("NO_VOLUME_SELECTED");
                   4960:                        }
                   4961:                        else
                   4962:                        {
                   4963:                                pwdChangeDlgMode = PCDM_ADD_REMOVE_VOL_KEYFILES;
                   4964:                                ChangePassword (hwndDlg);
                   4965:                        }
                   4966:                        return 1;
                   4967:                }
1.1.1.3   root     4968: 
1.1.1.7   root     4969:                if (lw == IDM_REMOVE_ALL_KEYFILES_FROM_VOL)
                   4970:                {
                   4971:                        if (!VolumeSelected(hwndDlg))
1.1.1.3   root     4972:                        {
1.1.1.7   root     4973:                                Warning ("NO_VOLUME_SELECTED");
                   4974:                        }
                   4975:                        else
                   4976:                        {               
                   4977:                                pwdChangeDlgMode = PCDM_REMOVE_ALL_KEYFILES_FROM_VOL;
                   4978:                                ChangePassword (hwndDlg);
1.1.1.3   root     4979:                        }
                   4980:                        return 1;
                   4981:                }
1.1.1.7   root     4982: 
                   4983:                if (lw == IDM_GENERATE_KEYFILE || lw == IDM_KEYFILE_GENERATOR)
                   4984:                {
                   4985:                        DialogBoxParamW (hInst, 
                   4986:                                MAKEINTRESOURCEW (IDD_KEYFILE_GENERATOR), hwndDlg,
                   4987:                                (DLGPROC) KeyfileGeneratorDlgProc, (LPARAM) 0);
                   4988: 
                   4989:                                return 1;
                   4990:                }
                   4991: 
                   4992:                if (lw == IDM_LICENSE)
                   4993:                {
1.1.1.13! root     4994:                        TextInfoDialogBox (TC_TBXID_LEGAL_NOTICES);
1.1.1.7   root     4995:                        return 1;
                   4996:                }
1.1.1.3   root     4997:        
1.1.1.11  root     4998:                if (lw == IDM_WEBSITE)
1.1.1.7   root     4999:                {
1.1.1.11  root     5000:                        Applink ("website", TRUE, "");
                   5001:                        return 1;
                   5002:                }
                   5003:                else if (lw == IDM_HOMEPAGE)
                   5004:                {
                   5005:                        Applink ("homepage", TRUE, "");
1.1.1.7   root     5006:                        return 1;
                   5007:                }
                   5008:                else if (lw == IDM_FORUMS)
1.1       root     5009:                {
1.1.1.11  root     5010:                        Applink ("forum", TRUE, "");
1.1.1.5   root     5011:                        return 1;
                   5012:                }
1.1.1.9   root     5013:                else if (lw == IDM_ONLINE_TUTORIAL)
                   5014:                {
1.1.1.11  root     5015:                        Applink ("tutorial", TRUE, "");
1.1.1.9   root     5016:                        return 1;
                   5017:                }
                   5018:                else if (lw == IDM_ONLINE_HELP)
                   5019:                {
1.1.1.10  root     5020:                        OpenOnlineHelp ();
1.1.1.9   root     5021:                        return 1;
                   5022:                }
1.1.1.7   root     5023:                else if (lw == IDM_FAQ)
                   5024:                {
1.1.1.11  root     5025:                        Applink ("faq", TRUE, "");
1.1.1.7   root     5026:                        return 1;
                   5027:                }
                   5028:                else if (lw == IDM_TC_DOWNLOADS)
1.1.1.5   root     5029:                {
1.1.1.11  root     5030:                        Applink ("downloads", TRUE, "");
1.1       root     5031:                        return 1;
                   5032:                }
1.1.1.7   root     5033:                else if (lw == IDM_NEWS)
                   5034:                {
1.1.1.11  root     5035:                        Applink ("news", TRUE, "");
1.1.1.7   root     5036:                        return 1;
                   5037:                }
                   5038:                else if (lw == IDM_VERSION_HISTORY)
1.1.1.6   root     5039:                {
1.1.1.11  root     5040:                        Applink ("history", TRUE, "");
1.1.1.6   root     5041:                        return 1;
                   5042:                }
1.1.1.7   root     5043:                else if (lw == IDM_BUGREPORT)
                   5044:                {
1.1.1.11  root     5045:                        Applink ("bugreport", TRUE, "");
                   5046:                        return 1;
                   5047:                }
                   5048:                else if (lw == IDM_DONATIONS)
                   5049:                {
                   5050:                        Applink ("donations", FALSE, "");
1.1.1.7   root     5051:                        return 1;
                   5052:                }
                   5053:                else if (lw == IDM_CONTACT)
1.1       root     5054:                {
1.1.1.11  root     5055:                        Applink ("contact", FALSE, "");
1.1.1.7   root     5056:                        return 1;
                   5057:                }
                   5058: 
                   5059:                if (lw == IDM_PREFERENCES)
                   5060:                {
                   5061:                        if (IDOK == DialogBoxParamW (hInst, 
                   5062:                                MAKEINTRESOURCEW (IDD_PREFERENCES_DLG), hwndDlg,
                   5063:                                (DLGPROC) PreferencesDlgProc, (LPARAM) 0))
                   5064:                        {
                   5065:                                if (bEnableBkgTask)
1.1.1.12  root     5066:                                {
1.1.1.7   root     5067:                                        TaskBarIconAdd (hwndDlg);
1.1.1.12  root     5068:                                }
1.1.1.7   root     5069:                                else
1.1.1.12  root     5070:                                {
1.1.1.7   root     5071:                                        TaskBarIconRemove (hwndDlg);
1.1.1.13! root     5072:                                        if (MainWindowHidden)
1.1.1.12  root     5073:                                                EndMainDlg (hwndDlg);
                   5074:                                }
1.1.1.7   root     5075:                        }
                   5076:                        return 1;
                   5077:                }
                   5078: 
                   5079:                if (lw == IDM_HOTKEY_SETTINGS)
                   5080:                {
                   5081:                        DialogBoxParamW (hInst, 
                   5082:                                MAKEINTRESOURCEW (IDD_HOTKEYS_DLG), hwndDlg,
                   5083:                                (DLGPROC) HotkeysDlgProc, (LPARAM) 0);
                   5084:                        return 1;
                   5085:                }
                   5086: 
                   5087:                if (lw == IDM_DEFAULT_KEYFILES || lw == IDM_SET_DEFAULT_KEYFILES)
                   5088:                {
                   5089:                        KeyfileDefaultsDlg (hwndDlg);
1.1       root     5090:                        return 1;
                   5091:                }
                   5092: 
1.1.1.7   root     5093:                if (lw == IDM_BENCHMARK)
1.1.1.5   root     5094:                {
                   5095:                        Benchmark (hwndDlg);
                   5096:                        return 1;
                   5097:                }
                   5098: 
1.1.1.13! root     5099:                if (lw == IDM_TRAVELER)
1.1.1.6   root     5100:                {
1.1.1.7   root     5101:                        DialogBoxParamW (hInst, 
1.1.1.13! root     5102:                                MAKEINTRESOURCEW (IDD_TRAVELER_DLG), hwndDlg,
        !          5103:                                (DLGPROC) TravelerDlgProc, (LPARAM) 0);
1.1.1.6   root     5104:                        return 1;
                   5105:                }
                   5106: 
1.1.1.7   root     5107:                if (lw == IDM_BACKUP_VOL_HEADER)
                   5108:                {
                   5109:                        if (!VolumeSelected(hwndDlg))
                   5110:                        {
                   5111:                                Warning ("NO_VOLUME_SELECTED");
                   5112:                        }
                   5113:                        else
                   5114:                        {
                   5115:                                char volPath[TC_MAX_PATH];              /* Volume to mount */
                   5116: 
                   5117:                                GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
                   5118: 
1.1.1.11  root     5119:                                if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
                   5120:                                        UacBackupVolumeHeader (hwndDlg, TRUE, volPath);
                   5121:                                else
                   5122:                                        BackupVolumeHeader (hwndDlg, TRUE, volPath);
1.1.1.7   root     5123:                        }
                   5124:                        return 1;
                   5125:                }
                   5126: 
                   5127:                if (lw == IDM_RESTORE_VOL_HEADER)
                   5128:                {
                   5129:                        if (!VolumeSelected(hwndDlg))
                   5130:                        {
                   5131:                                Warning ("NO_VOLUME_SELECTED");
                   5132:                        }
                   5133:                        else
                   5134:                        {
                   5135:                                char volPath[TC_MAX_PATH];              /* Volume to mount */
                   5136: 
                   5137:                                GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
                   5138: 
1.1.1.11  root     5139:                                if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
                   5140:                                        UacRestoreVolumeHeader (hwndDlg, volPath);
                   5141:                                else
                   5142:                                        RestoreVolumeHeader (hwndDlg, volPath);
1.1.1.7   root     5143:                        }
                   5144:                        return 1;
                   5145:                }
                   5146: 
                   5147:                if (lw == IDM_LANGUAGE)
                   5148:                {
                   5149:                        BOOL p;
                   5150:                        if (DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_LANGUAGE), hwndDlg,
                   5151:                                (DLGPROC) LanguageDlgProc, (LPARAM) 0) == IDOK)
                   5152:                        {
                   5153:                                LoadLanguageFile ();
                   5154:                                SaveSettings (hwndDlg);
                   5155: 
                   5156:                                p = LocalizationActive;
                   5157:                                LocalizationActive = TRUE;
                   5158:                                InitMainDialog (hwndDlg);
                   5159:                                InvalidateRect (hwndDlg, NULL, FALSE);
                   5160:                                LocalizationActive = p;
                   5161:                                DrawMenuBar (hwndDlg);
                   5162:                        }
                   5163:                        return 1;
                   5164:                }
                   5165: 
                   5166:                if (lw == IDM_TEST_VECTORS)
                   5167:                {
                   5168:                        DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_CIPHER_TEST_DLG), hwndDlg, (DLGPROC) CipherTestDialogProc, (LPARAM) 1);
                   5169:                        return 1;
                   5170:                }
                   5171: 
1.1.1.6   root     5172:                if (lw == IDM_REFRESH_DRIVE_LETTERS)
                   5173:                {
                   5174:                        DWORD driveMap = GetLogicalDrives ();
                   5175:                        
1.1.1.11  root     5176:                        WaitCursor ();
1.1.1.7   root     5177: 
1.1.1.10  root     5178:                        if (!(nCurrentOS == WIN_2000 && RemoteSession))
                   5179:                        {
                   5180:                                BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, ~driveMap);
                   5181:                                Sleep (100);
                   5182:                                BroadcastDeviceChange (DBT_DEVICEARRIVAL, 0, driveMap);
                   5183:                        }
1.1.1.7   root     5184: 
1.1.1.6   root     5185:                        LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
1.1.1.7   root     5186: 
                   5187:                        if (nSelectedDriveIndex >= 0)
                   5188:                        {
                   5189:                                SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST),
                   5190:                                        (char) HIWORD (GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), nSelectedDriveIndex)));
                   5191:                        }
                   5192: 
1.1.1.6   root     5193:                        NormalCursor ();
1.1.1.7   root     5194:                        return 1;
                   5195:                }
                   5196: 
                   5197:                if (lw == IDM_MOUNT_FAVORITE_VOLUMES)
                   5198:                {
                   5199:                        MountFavoriteVolumes ();
                   5200:                        return 1;
                   5201:                }
                   5202: 
                   5203:                if (lw == IDM_SAVE_FAVORITE_VOLUMES)
                   5204:                {
                   5205:                        SaveFavoriteVolumes ();
                   5206:                        return 1;
1.1.1.6   root     5207:                }
1.1.1.5   root     5208: 
1.1.1.7   root     5209:                if (lw == IDC_VOLUME_PROPERTIES || lw == IDM_VOLUME_PROPERTIES)
1.1       root     5210:                {
1.1.1.7   root     5211:                        DialogBoxParamW (hInst, 
                   5212:                                MAKEINTRESOURCEW (IDD_VOLUME_PROPERTIES), hwndDlg,
1.1       root     5213:                                (DLGPROC) VolumePropertiesDlgProc, (LPARAM) 0);
                   5214:                        return 1;
                   5215:                }
                   5216: 
                   5217:                if (lw == IDC_VOLUME && hw == CBN_EDITCHANGE)
                   5218:                {
1.1.1.5   root     5219:                        EnableDisableButtons (hwndDlg);
1.1       root     5220:                        return 1;
                   5221:                }
                   5222: 
                   5223:                if (lw == IDC_VOLUME && hw == CBN_SELCHANGE)
                   5224:                {
                   5225:                        UpdateComboOrder (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.10  root     5226:                        MoveEditToCombo ((HWND) lParam, bHistory);
1.1.1.13! root     5227:                        PostMessage (hwndDlg, TC_APPMSG_MOUNT_ENABLE_DISABLE_CONTROLS, 0, 0);
1.1.1.5   root     5228:                        return 1;
                   5229:                }
                   5230: 
                   5231:                if (lw == IDC_NO_HISTORY)
                   5232:                {
1.1.1.11  root     5233:                        if (!(bHistory = !IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY))))
                   5234:                                ClearHistory (GetDlgItem (hwndDlg, IDC_VOLUME));
                   5235: 
1.1       root     5236:                        return 1;
                   5237:                }
                   5238: 
                   5239:                return 0;
                   5240: 
1.1.1.6   root     5241:        case WM_DROPFILES:
                   5242:                {
                   5243:                        HDROP hdrop = (HDROP) wParam;
                   5244:                        DragQueryFile (hdrop, 0, szFileName, sizeof szFileName);
                   5245:                        DragFinish (hdrop);
                   5246: 
1.1.1.10  root     5247:                        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.6   root     5248:                        EnableDisableButtons (hwndDlg);
                   5249:                        SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
                   5250:                }
1.1.1.7   root     5251:                return 1;
1.1.1.6   root     5252: 
1.1.1.13! root     5253:        case TC_APPMSG_MOUNT_ENABLE_DISABLE_CONTROLS:
1.1       root     5254:                EnableDisableButtons (hwndDlg);
                   5255:                return 1;
                   5256: 
1.1.1.13! root     5257:        case TC_APPMSG_MOUNT_SHOW_WINDOW:
1.1.1.8   root     5258:                MainWindowHidden = FALSE;
1.1.1.13! root     5259:                ShowWindow (hwndDlg, SW_SHOW);
        !          5260:                ShowWindow (hwndDlg, SW_RESTORE);
1.1.1.8   root     5261:                return 1;
                   5262: 
                   5263:        case WM_COPYDATA:
                   5264:                {
                   5265:                        PCOPYDATASTRUCT cd = (PCOPYDATASTRUCT)lParam;
                   5266:                        if (memcmp (&cd->dwData, WM_COPY_SET_VOLUME_NAME, 4) == 0)
                   5267:                        {
                   5268:                                if (cd->cbData > 0)
1.1.1.10  root     5269:                                        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), (char *)cd->lpData, bHistory);
1.1.1.8   root     5270: 
                   5271:                                EnableDisableButtons (hwndDlg);
                   5272:                                SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
                   5273:                        }
                   5274:                }
                   5275:                return 1;
                   5276: 
1.1       root     5277:        case WM_CLOSE:
                   5278:                EndMainDlg (hwndDlg);
                   5279:                return 1;
1.1.1.11  root     5280: 
                   5281:        default:
                   5282:                // Recreate tray icon if Explorer restarted
                   5283:                if (taskBarCreatedMsg != 0 && uMsg == taskBarCreatedMsg && TaskBarIconMutex != NULL)
                   5284:                {
                   5285:                        TaskBarIconRemove (hwndDlg);
                   5286:                        TaskBarIconAdd (hwndDlg);
                   5287:                        return 1;
                   5288:                }
1.1       root     5289:        }
                   5290: 
                   5291:        return 0;
                   5292: }
                   5293: 
                   5294: void
                   5295: ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
                   5296: {
                   5297:        char **lpszCommandLineArgs;     /* Array of command line arguments */
                   5298:        int nNoCommandLineArgs; /* The number of arguments in the array */
1.1.1.7   root     5299:        char tmpPath[MAX_PATH * 2];
                   5300: 
                   5301:        /* Defaults */
                   5302:        mountOptions.PreserveTimestamp = TRUE;
1.1.1.11  root     5303:        
                   5304:        if (_stricmp (lpszCommandLine, "-Embedding") == 0)
                   5305:        {
                   5306:                ComServerMode = TRUE;
                   5307:                return;
                   5308:        }
1.1       root     5309: 
                   5310:        /* Extract command line arguments */
1.1.1.8   root     5311:        NoCmdLineArgs = nNoCommandLineArgs = Win32CommandLine (lpszCommandLine, &lpszCommandLineArgs);
1.1.1.11  root     5312: 
1.1       root     5313:        if (nNoCommandLineArgs > 0)
                   5314:        {
                   5315:                int i;
                   5316: 
                   5317:                for (i = 0; i < nNoCommandLineArgs; i++)
                   5318:                {
                   5319:                        argument args[]=
                   5320:                        {
                   5321:                                {"/auto", "/a"},
1.1.1.5   root     5322:                                {"/beep", "/b"},
1.1       root     5323:                                {"/cache", "/c"},
1.1.1.5   root     5324:                                {"/dismount", "/d"},
                   5325:                                {"/explore", "/e"},
                   5326:                                {"/force", "/f"},
                   5327:                                {"/help", "/?"},
1.1       root     5328:                                {"/history", "/h"},
1.1.1.7   root     5329:                                {"/keyfile", "/k"},
1.1.1.5   root     5330:                                {"/letter", "/l"},
1.1.1.6   root     5331:                                {"/mountoption", "/m"},
1.1.1.5   root     5332:                                {"/password", "/p"},
1.1.1.7   root     5333:                                {"/quit", "/q"},
                   5334:                                {"/silent", "/s"},
1.1.1.5   root     5335:                                {"/volume", "/v"},
                   5336:                                {"/wipecache", "/w"}
1.1       root     5337:                        };
                   5338: 
                   5339:                        argumentspec as;
                   5340: 
                   5341:                        int nArgPos;
                   5342:                        int x;
                   5343: 
                   5344:                        as.args = args;
                   5345:                        as.arg_cnt = sizeof(args)/ sizeof(args[0]);
                   5346:                        
                   5347:                        x = GetArgumentID (&as, lpszCommandLineArgs[i], &nArgPos);
                   5348: 
                   5349:                        switch (x)
                   5350:                        {
1.1.1.7   root     5351:                        case 'a':
                   5352:                                {
                   5353:                                        char szTmp[32];
                   5354:                                        bAuto = TRUE;
1.1.1.2   root     5355: 
1.1.1.7   root     5356:                                        if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
                   5357:                                                nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
                   5358:                                        {
                   5359:                                                if (!_stricmp (szTmp, "devices"))
                   5360:                                                        bAutoMountDevices = TRUE;
                   5361:                                                else if (!_stricmp (szTmp, "favorites"))
                   5362:                                                        bAutoMountFavorites = TRUE;
                   5363:                                        }
                   5364:                                }
                   5365:                                break;
1.1.1.2   root     5366: 
1.1.1.7   root     5367:                        case 'b':
                   5368:                                bBeep = TRUE;
1.1       root     5369:                                break;
                   5370: 
1.1.1.7   root     5371:                        case 'c':
1.1.1.2   root     5372:                                {
1.1.1.7   root     5373:                                        char szTmp[8];
                   5374:                                        bCacheInDriver = TRUE;
                   5375: 
                   5376:                                        GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
                   5377:                                                     szTmp, sizeof (szTmp));
                   5378: 
                   5379:                                        if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
                   5380:                                                bCacheInDriver = FALSE;
1.1.1.2   root     5381:                                }
1.1       root     5382:                                break;
                   5383: 
1.1.1.7   root     5384:                        case 'd':
                   5385: 
                   5386:                                if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
                   5387:                                     szDriveLetter, sizeof (szDriveLetter)))
                   5388:                                        cmdUnmountDrive = toupper(szDriveLetter[0]) - 'A';
                   5389:                                else 
                   5390:                                        cmdUnmountDrive = -1;
                   5391: 
1.1       root     5392:                                break;
                   5393: 
                   5394:                        case 'e':
                   5395:                                bExplore = TRUE;
                   5396:                                break;
                   5397: 
1.1.1.5   root     5398:                        case 'f':
                   5399:                                bForceMount = TRUE;
                   5400:                                bForceUnmount = TRUE;
                   5401:                                break;
                   5402: 
1.1.1.7   root     5403:                        case 'k':
                   5404:                                if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i,
                   5405:                                        nNoCommandLineArgs, tmpPath, sizeof (tmpPath)))
                   5406:                                {
                   5407:                                        KeyFile *kf;
                   5408:                                        RelativePath2Absolute (tmpPath);
1.1.1.13! root     5409:                                        kf = (KeyFile *) malloc (sizeof (KeyFile));
1.1.1.7   root     5410:                                        strncpy (kf->FileName, tmpPath, sizeof (kf->FileName));
                   5411:                                        FirstCmdKeyFile = KeyFileAdd (FirstCmdKeyFile, kf);
                   5412:                                }
                   5413:                                break;
                   5414: 
                   5415:                        case 'l':
1.1.1.2   root     5416:                                GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
1.1.1.7   root     5417:                                        szDriveLetter, sizeof (szDriveLetter));
                   5418:                                commandLineDrive = *szDriveLetter = (char) toupper (*szDriveLetter);
1.1       root     5419:                                break;
                   5420: 
1.1.1.10  root     5421:                        case 'h':
1.1.1.6   root     5422:                                {
                   5423:                                        char szTmp[8];
1.1.1.7   root     5424:                                        bHistory = bHistoryCmdLine = TRUE;
1.1.1.6   root     5425: 
1.1.1.7   root     5426:                                        GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
                   5427:                                                     szTmp, sizeof (szTmp));
                   5428: 
                   5429:                                        if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
                   5430:                                                bHistory = FALSE;
1.1.1.6   root     5431:                                }
                   5432:                                break;
                   5433: 
                   5434:                        case 'm':
                   5435:                                {
1.1.1.7   root     5436:                                        char szTmp[16];
1.1.1.6   root     5437:                                        if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
                   5438:                                                nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
                   5439:                                        {
1.1.1.7   root     5440:                                                if (!_stricmp (szTmp, "ro") || !_stricmp (szTmp, "readonly"))
1.1.1.6   root     5441:                                                        mountOptions.ReadOnly = TRUE;
                   5442: 
1.1.1.7   root     5443:                                                if (!_stricmp (szTmp, "rm") || !_stricmp (szTmp, "removable"))
1.1.1.6   root     5444:                                                        mountOptions.Removable = TRUE;
1.1.1.7   root     5445: 
                   5446:                                                if (!_stricmp (szTmp, "ts") || !_stricmp (szTmp, "timestamp"))
                   5447:                                                        mountOptions.PreserveTimestamp = FALSE;
1.1.1.6   root     5448:                                        }
                   5449:                                }
1.1       root     5450:                                break;
                   5451: 
1.1.1.7   root     5452:                        case 'p':
                   5453:                                GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
1.1.1.13! root     5454:                                                     (char *) CmdVolumePassword.Text, sizeof (CmdVolumePassword.Text));
        !          5455:                                CmdVolumePassword.Length = strlen ((char *) CmdVolumePassword.Text);
1.1.1.7   root     5456:                                CmdVolumePasswordValid = TRUE;
                   5457:                                break;
                   5458: 
                   5459:                        case 'v':
                   5460:                                if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i,
                   5461:                                                                      nNoCommandLineArgs, szFileName, sizeof (szFileName)))
1.1       root     5462:                                {
1.1.1.7   root     5463:                                        RelativePath2Absolute (szFileName);
1.1.1.10  root     5464:                                        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.8   root     5465:                                        CmdLineVolumeSpecified = TRUE;
1.1       root     5466:                                }
                   5467:                                break;
                   5468: 
1.1.1.7   root     5469:                        case 'q':
1.1       root     5470:                                {
1.1.1.7   root     5471:                                        char szTmp[32];
1.1       root     5472: 
1.1.1.7   root     5473:                                        if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
                   5474:                                                nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
1.1       root     5475:                                        {
1.1.1.12  root     5476:                                                if (!_stricmp (szTmp, "UAC")) // Used to indicate non-install elevation
                   5477:                                                        break;
                   5478: 
1.1.1.7   root     5479:                                                if (!_stricmp (szTmp, "preferences"))
1.1.1.12  root     5480:                                                {
                   5481:                                                        Quit = TRUE;
1.1.1.7   root     5482:                                                        UsePreferences = TRUE;
1.1.1.12  root     5483:                                                        break;
                   5484:                                                }
                   5485: 
                   5486:                                                if (!_stricmp (szTmp, "background"))
                   5487:                                                        bEnableBkgTask = TRUE;
1.1       root     5488:                                        }
1.1.1.12  root     5489: 
                   5490:                                        Quit = TRUE;
                   5491:                                        UsePreferences = FALSE;
1.1       root     5492:                                }
                   5493:                                break;
                   5494: 
1.1.1.7   root     5495:                        case 's':
                   5496:                                Silent = TRUE;
1.1       root     5497:                                break;
                   5498: 
1.1.1.7   root     5499:                        case 'w':
                   5500:                                bWipe = TRUE;
1.1       root     5501:                                break;
                   5502: 
                   5503:                        case '?':
1.1.1.7   root     5504:                                DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_COMMANDHELP_DLG), hwndDlg, (DLGPROC)
1.1       root     5505:                                                CommandHelpDlgProc, (LPARAM) &as);
                   5506:                                exit(0);
                   5507:                                break;
                   5508: 
                   5509:                                // no option = file name
                   5510:                        default:
1.1.1.2   root     5511:                                {
1.1.1.11  root     5512:                                        strncpy (szFileName, lpszCommandLineArgs[i], MAX_PATH-1);
1.1.1.2   root     5513:                                        if (szFileName[0] != '\\' && strchr (szFileName, ':') == 0)
                   5514:                                        {
                   5515:                                                char path[MAX_PATH*2];
                   5516:                                                GetCurrentDirectory (MAX_PATH, path);
                   5517:                                                strcat (path, "\\");
                   5518:                                                strcat (path, szFileName);
                   5519:                                                strncpy (szFileName, path, MAX_PATH-1);
                   5520:                                        }
1.1.1.8   root     5521: 
                   5522:                                        if (nNoCommandLineArgs == 1)
                   5523:                                                CmdLineVolumeSpecified = TRUE;
1.1.1.10  root     5524:                                        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.2   root     5525:                                }
1.1       root     5526:                        }
                   5527:                }
                   5528:        }
                   5529: 
                   5530:        /* Free up the command line arguments */
                   5531:        while (--nNoCommandLineArgs >= 0)
                   5532:        {
                   5533:                free (lpszCommandLineArgs[nNoCommandLineArgs]);
                   5534:        }
                   5535: }
                   5536: 
1.1.1.7   root     5537: 
1.1.1.13! root     5538: int WINAPI WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine, int nCmdShow)
1.1       root     5539: {
                   5540:        int status;
1.1.1.13! root     5541:        atexit (localcleanup);
        !          5542: 
        !          5543:        VirtualLock (&VolumePassword, sizeof (VolumePassword));
        !          5544:        VirtualLock (&CmdVolumePassword, sizeof (CmdVolumePassword));
        !          5545:        VirtualLock (&mountOptions, sizeof (mountOptions));
        !          5546:        VirtualLock (&defaultMountOptions, sizeof (defaultMountOptions));
1.1       root     5547: 
1.1.1.13! root     5548:        try
        !          5549:        {
        !          5550:                BootEncObj = new BootEncryption (NULL);
        !          5551:        }
        !          5552:        catch (Exception &e)
        !          5553:        {
        !          5554:                e.Show (NULL);
        !          5555:        }
1.1       root     5556: 
1.1.1.13! root     5557:        if (BootEncObj == NULL)
        !          5558:                AbortProcess ("INIT_SYS_ENC");
1.1       root     5559: 
1.1.1.11  root     5560:        InitCommonControls ();
                   5561:        InitApp (hInstance, lpszCommandLine);
1.1       root     5562: 
1.1.1.7   root     5563:        RegisterRedTick(hInstance);
                   5564: 
                   5565:        /* Allocate, dup, then store away the application title */
                   5566:        lpszTitle = L"TrueCrypt";
                   5567: 
1.1       root     5568:        status = DriverAttach ();
                   5569:        if (status != 0)
                   5570:        {
                   5571:                if (status == ERR_OS_ERROR)
                   5572:                        handleWin32Error (NULL);
                   5573:                else
                   5574:                        handleError (NULL, status);
                   5575: 
1.1.1.7   root     5576:                AbortProcess ("NODRIVER");
1.1       root     5577:        }
                   5578: 
                   5579:        /* Create the main dialog box */
1.1.1.7   root     5580:        DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_MOUNT_DLG), NULL, (DLGPROC) MainDialogProc,
1.1       root     5581:                        (LPARAM) lpszCommandLine);
                   5582: 
                   5583:        /* Terminate */
                   5584:        return 0;
                   5585: }
1.1.1.6   root     5586: 
1.1.1.7   root     5587: 
                   5588: BOOL TaskBarIconAdd (HWND hwnd) 
                   5589: { 
                   5590:     BOOL res; 
                   5591:     NOTIFYICONDATAW tnid; 
                   5592:  
                   5593:        // Only one icon may be created
                   5594:        if (TaskBarIconMutex != NULL) return TRUE;
                   5595: 
                   5596:        TaskBarIconMutex = CreateMutex (NULL, TRUE, "TrueCryptTaskBarIcon");
                   5597:        if (TaskBarIconMutex == NULL || GetLastError () == ERROR_ALREADY_EXISTS)
                   5598:        {
                   5599:                TaskBarIconMutex = NULL;
                   5600:                return FALSE;
                   5601:        }
                   5602: 
                   5603:     tnid.cbSize = sizeof (NOTIFYICONDATAW); 
                   5604:     tnid.hWnd = hwnd; 
                   5605:     tnid.uID = IDI_TRUECRYPT_ICON; 
                   5606:     tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; 
1.1.1.13! root     5607:     tnid.uCallbackMessage = TC_APPMSG_TASKBAR_ICON; 
        !          5608:        tnid.hIcon = (HICON) LoadImage (hInst, MAKEINTRESOURCE (IDI_TRUECRYPT_ICON), 
1.1.1.12  root     5609:                IMAGE_ICON, 
                   5610:                ScreenDPI >= 120 ? 0 : 16, 
                   5611:                ScreenDPI >= 120 ? 0 : 16,
                   5612:                (ScreenDPI >= 120 ? LR_DEFAULTSIZE : 0) 
                   5613:                | (nCurrentOS != WIN_2000 ? LR_DEFAULTCOLOR : LR_VGACOLOR)); // Windows 2000 cannot display more than 16 fixed colors in notification tray
                   5614: 
1.1.1.7   root     5615:        wcscpy (tnid.szTip, L"TrueCrypt");
                   5616:        
                   5617:        res = Shell_NotifyIconW (NIM_ADD, &tnid); 
                   5618:  
                   5619:     if (tnid.hIcon) 
                   5620:         DestroyIcon (tnid.hIcon); 
                   5621:  
                   5622:     return res; 
                   5623: }
                   5624: 
                   5625: 
                   5626: BOOL TaskBarIconRemove (HWND hwnd) 
                   5627: { 
                   5628:        if (TaskBarIconMutex != NULL)
                   5629:        {
                   5630:                NOTIFYICONDATA tnid; 
                   5631:                BOOL res;
                   5632: 
                   5633:                ZeroMemory (&tnid, sizeof (tnid));
                   5634:                tnid.cbSize = sizeof(NOTIFYICONDATA); 
                   5635:                tnid.hWnd = hwnd; 
                   5636:                tnid.uID = IDI_TRUECRYPT_ICON; 
                   5637: 
                   5638:                res = Shell_NotifyIcon (NIM_DELETE, &tnid);
                   5639:                if (TaskBarIconMutex)
                   5640:                {
                   5641:                        CloseHandle (TaskBarIconMutex);
                   5642:                        TaskBarIconMutex = NULL;
                   5643:                }
                   5644:                return res;
                   5645:        }
                   5646:        else
                   5647:                return FALSE;
                   5648: }
                   5649: 
                   5650: 
                   5651: void DismountIdleVolumes ()
                   5652: {
1.1.1.13! root     5653:        static DWORD lastMinTickCount;
1.1.1.7   root     5654:        static int InactivityTime[26];
                   5655:        static unsigned __int64 LastRead[26], LastWritten[26];
                   5656:        static int LastId[26];
                   5657: 
                   5658:        VOLUME_PROPERTIES_STRUCT prop;
                   5659:        DWORD dwResult;
                   5660:        BOOL bResult;
                   5661:        int i;
                   5662: 
1.1.1.13! root     5663:        if (GetTickCount() > lastMinTickCount && GetTickCount() - lastMinTickCount < 60 * 1000)
        !          5664:                return;
        !          5665:        
        !          5666:        lastMinTickCount = GetTickCount();
1.1.1.7   root     5667: 
                   5668:        for (i = 0; i < 26; i++)
                   5669:        {
                   5670:                if (LastKnownMountList.ulMountedDrives & (1 << i))
                   5671:                {
                   5672:                        memset (&prop, 0, sizeof(prop));
                   5673:                        prop.driveNo = i;
                   5674: 
1.1.1.13! root     5675:                        bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop,
1.1.1.7   root     5676:                                sizeof (prop), &prop, sizeof (prop), &dwResult, NULL);
                   5677: 
                   5678:                        if (bResult)
                   5679:                        {
                   5680:                                if (LastRead[i] == prop.totalBytesRead 
                   5681:                                        && LastWritten[i] == prop.totalBytesWritten
                   5682:                                        && LastId[i] == prop.uniqueId)
                   5683:                                {
                   5684:                                        if (++InactivityTime[i] >= MaxVolumeIdleTime)
                   5685:                                        {
1.1.1.11  root     5686:                                                BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, i, 0);
                   5687: 
1.1.1.7   root     5688:                                                if (bCloseDismountedWindows && CloseVolumeExplorerWindows (MainDlg, i))
                   5689:                                                        Sleep (250);
                   5690: 
                   5691:                                                if (DriverUnmountVolume (MainDlg, i, bForceAutoDismount) == 0)
                   5692:                                                {
                   5693:                                                        InactivityTime[i] = 0;
                   5694:                                                        BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, i, 0);
                   5695: 
                   5696:                                                        if (bWipeCacheOnAutoDismount)
1.1.1.13! root     5697:                                                                DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.7   root     5698:                                                }
                   5699:                                        }
                   5700:                                }
                   5701:                                else
                   5702:                                {
                   5703:                                        InactivityTime[i] = 0;
                   5704:                                        LastRead[i] = prop.totalBytesRead;
                   5705:                                        LastWritten[i] = prop.totalBytesWritten;
                   5706:                                        LastId[i] = prop.uniqueId;
                   5707:                                }
                   5708:                        }
                   5709:                }
                   5710:        }
                   5711: }
                   5712: 
                   5713: 
                   5714: BOOL MountFavoriteVolumes ()
                   5715: {
                   5716:        BOOL status = TRUE;
                   5717:        DWORD size;
                   5718:        char *favorites = LoadFile (GetConfigPath (FILE_FAVORITE_VOLUMES), &size);
                   5719:        char *xml = favorites;
                   5720:        char mountPoint[MAX_PATH], volume[MAX_PATH];
                   5721: 
                   5722:        if (xml == NULL) return FALSE;
                   5723: 
1.1.1.11  root     5724:        mountOptions = defaultMountOptions;
                   5725: 
1.1.1.7   root     5726:        while (xml = XmlFindElement (xml, "volume"))
                   5727:        {
                   5728:                int drive;
1.1.1.11  root     5729:                XmlGetAttributeText (xml, "mountpoint", mountPoint, sizeof (mountPoint));
                   5730:                XmlGetNodeText (xml, volume, sizeof (volume));
1.1.1.7   root     5731:                drive = toupper (mountPoint[0]) - 'A';
                   5732: 
                   5733:                if ((LastKnownMountList.ulMountedDrives & (1 << drive)) == 0)
                   5734:                {
                   5735:                        if (!Mount (MainDlg, drive, volume))
                   5736:                                status = FALSE;
                   5737:                        LoadDriveLetters (GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
                   5738:                }
                   5739: 
                   5740:                xml++;
                   5741:        }
                   5742: 
                   5743:        free (favorites);
                   5744:        return status;
                   5745: }
                   5746: 
                   5747: 
                   5748: void SaveFavoriteVolumes ()
                   5749: {
                   5750:        if (AskNoYes("CONFIRM_SAVE_FAVORITE_VOL") == IDYES)
                   5751:        {
                   5752:                FILE *f;
                   5753:                int i, cnt = 0;
                   5754: 
                   5755:                f = fopen (GetConfigPath (FILE_FAVORITE_VOLUMES), "w");
                   5756:                if (f == NULL)
                   5757:                {
                   5758:                        handleWin32Error (MainDlg);
                   5759:                        return;
                   5760:                }
                   5761: 
                   5762:                XmlWriteHeader (f);
                   5763:                fputs ("\n\t<favorites>", f);
                   5764: 
                   5765:                for (i = 0; i < 26; i++)
                   5766:                {
                   5767:                        if (LastKnownMountList.ulMountedDrives & (1 << i))
                   5768:                        {
1.1.1.11  root     5769:                                char t[2048], tq[2048];
                   5770:                                
                   5771:                                sprintf_s (t, sizeof (t), "%ls", &LastKnownMountList.wszVolume[i][(LastKnownMountList.wszVolume[i][1] == L'?') ? 4 : 0]);
                   5772:                                XmlQuoteText (t, tq, sizeof (tq));
                   5773: 
                   5774:                                fprintf (f, "\n\t\t<volume mountpoint=\"%c:\\\">%s</volume>", i + 'A', tq);
1.1.1.7   root     5775:                                cnt++;
                   5776:                        }
                   5777:                }
                   5778: 
                   5779:                fputs ("\n\t</favorites>", f);
                   5780:                XmlWriteFooter (f);
                   5781:                fclose (f);
                   5782: 
                   5783:                if (cnt == 0)
                   5784:                        remove (GetConfigPath (FILE_FAVORITE_VOLUMES));         // No volumes to save as favorite
                   5785: 
                   5786:                Info ("FAVORITE_VOLUMES_SAVED");
                   5787:        }
                   5788: }
                   5789: 
                   5790: 
                   5791: static void SaveDefaultKeyFilesParam (void)
                   5792: {
                   5793:        if (defaultKeyFilesParam.FirstKeyFile == NULL)
                   5794:        {
                   5795:                /* No keyfiles selected */ 
                   5796:                remove (GetConfigPath (FILE_DEFAULT_KEYFILES));
                   5797:        }
                   5798:        else
                   5799:        {
                   5800:                FILE *f;
                   5801:                KeyFile *kf = FirstKeyFile;
                   5802: 
                   5803:                f = fopen (GetConfigPath (FILE_DEFAULT_KEYFILES), "w");
                   5804:                if (f == NULL)
                   5805:                {
                   5806:                        handleWin32Error (MainDlg);
                   5807:                        return;
                   5808:                }
                   5809: 
                   5810:                XmlWriteHeader (f);
                   5811: 
                   5812:                fputs ("\n\t<defaultkeyfiles>", f);
                   5813: 
                   5814:                while (kf != NULL)
                   5815:                {
1.1.1.11  root     5816:                        char q[TC_MAX_PATH * 2];
                   5817: 
                   5818:                        XmlQuoteText (kf->FileName, q, sizeof (q));
                   5819:                        fprintf (f, "\n\t\t<keyfile>%s</keyfile>", q); 
                   5820: 
1.1.1.7   root     5821:                        kf = kf->Next;
                   5822:                }
                   5823: 
                   5824:                fputs ("\n\t</defaultkeyfiles>", f); 
                   5825: 
                   5826:                XmlWriteFooter (f);
                   5827: 
                   5828:                fclose (f);
                   5829:                return;
                   5830:        }
                   5831: }
                   5832: 
                   5833: 
                   5834: static void KeyfileDefaultsDlg (HWND hwndDlg)
                   5835: {
                   5836:        KeyFilesDlgParam param;
                   5837: 
                   5838:        param.EnableKeyFiles = defaultKeyFilesParam.EnableKeyFiles;
                   5839:        param.FirstKeyFile = defaultKeyFilesParam.FirstKeyFile;
                   5840: 
                   5841:        if (DialogBoxParamW (hInst,
                   5842:                MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
                   5843:                (DLGPROC) KeyFilesDlgProc, (LPARAM) &param) == IDOK)
                   5844:        {
1.1.1.13! root     5845:                if (!param.EnableKeyFiles || AskWarnYesNo ("CONFIRM_SAVE_DEFAULT_KEYFILES") == IDYES)
1.1.1.7   root     5846:                {
                   5847:                        KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile);
                   5848:                        defaultKeyFilesParam.EnableKeyFiles = param.EnableKeyFiles;
                   5849:                        defaultKeyFilesParam.FirstKeyFile = param.FirstKeyFile;
                   5850: 
                   5851:                        RestoreDefaultKeyFilesParam ();
                   5852:                        SaveDefaultKeyFilesParam ();
                   5853:                }
                   5854:        }
                   5855: }
                   5856: 
                   5857: 
                   5858: static void HandleHotKey (HWND hwndDlg, WPARAM wParam)
                   5859: {
                   5860:        DWORD dwResult;
                   5861:        BOOL success = TRUE;
                   5862: 
                   5863:        switch (wParam)
                   5864:        {
                   5865:        case HK_AUTOMOUNT_DEVICES:
                   5866:                MountAllDevices (hwndDlg, TRUE);
                   5867: 
                   5868:                if (bPlaySoundOnHotkeyMountDismount)
                   5869:                        MessageBeep(-1);
                   5870: 
                   5871:                break;
                   5872: 
                   5873:        case HK_DISMOUNT_ALL:
1.1.1.12  root     5874:                if (DismountAll (hwndDlg, FALSE, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY) && bDisplayMsgBoxOnHotkeyDismount)
                   5875:                        Info ("MOUNTED_VOLUMES_DISMOUNTED");
                   5876:                else if (bDisplayMsgBoxOnHotkeyDismount)
                   5877:                        Info ("DISMOUNT_ALL_ATTEMPT_COMPLETED");
1.1.1.7   root     5878: 
1.1.1.12  root     5879:                if (!bDisplayMsgBoxOnHotkeyDismount && bPlaySoundOnHotkeyMountDismount)
1.1.1.7   root     5880:                        MessageBeep(-1);
                   5881: 
                   5882:                break;
                   5883: 
1.1.1.11  root     5884:        case HK_WIPE_CACHE:
                   5885:                WipeCache (hwndDlg);
                   5886:                break;
                   5887: 
1.1.1.7   root     5888:        case HK_FORCE_DISMOUNT_ALL_AND_WIPE:
                   5889:                success = DismountAll (hwndDlg, TRUE, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1.1.13! root     5890:                success &= DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.7   root     5891:                if (success)
                   5892:                {
                   5893:                        if (bPlaySoundOnHotkeyMountDismount)
                   5894:                                MessageBeep(-1);
                   5895: 
                   5896:                        if (bDisplayMsgBoxOnHotkeyDismount)
                   5897:                                Info ("VOLUMES_DISMOUNTED_CACHE_WIPED");
                   5898:                }
                   5899:                break;
                   5900: 
                   5901:        case HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT:
                   5902:                success = DismountAll (hwndDlg, TRUE, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1.1.13! root     5903:                success &= DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.7   root     5904:                if (success)
                   5905:                {
                   5906:                        if (bPlaySoundOnHotkeyMountDismount)
                   5907:                                MessageBeep(-1);
                   5908: 
                   5909:                        if (bDisplayMsgBoxOnHotkeyDismount)
                   5910:                                Info ("VOLUMES_DISMOUNTED_CACHE_WIPED");
                   5911:                }
                   5912:                TaskBarIconRemove (hwndDlg);
                   5913:                EndMainDlg (hwndDlg);
                   5914:                break;
                   5915: 
                   5916:        case HK_MOUNT_FAVORITE_VOLUMES:
                   5917:                MountFavoriteVolumes ();
                   5918: 
                   5919:                if (bPlaySoundOnHotkeyMountDismount)
                   5920:                        MessageBeep(-1);
                   5921: 
                   5922:                break;
                   5923: 
                   5924:        case HK_SHOW_HIDE_MAIN_WINDOW:
1.1.1.13! root     5925:                ChangeMainWindowVisibility ();
1.1.1.7   root     5926:                break;
                   5927:        }
1.1.1.13! root     5928: }
        !          5929: 
        !          5930: 
        !          5931: void ChangeMainWindowVisibility ()
        !          5932: {
        !          5933:        MainWindowHidden = !MainWindowHidden;
        !          5934: 
        !          5935:        if (!MainWindowHidden)
        !          5936:                SetForegroundWindow (MainDlg);
        !          5937: 
        !          5938:        ShowWindow (MainDlg, !MainWindowHidden ? SW_SHOW : SW_HIDE);
        !          5939: 
        !          5940:        if (!MainWindowHidden)
        !          5941:                ShowWindow (MainDlg, SW_RESTORE);
1.1.1.7   root     5942: }

unix.superglobalmegacorp.com

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