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

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
1.1.1.14! root     3430:                && !BootEncStatus.DeviceFilterActive
1.1.1.13  root     3431:                && !BootEncStatus.VolumeHeaderPresent
                   3432:                && !SysEncryptionOrDecryptionRequired ())
                   3433:        {
                   3434:                Warning ("SYS_DRIVE_NOT_ENCRYPTED");
                   3435:                return;
                   3436:        }
                   3437: 
                   3438:        if (AskNoYes ("CONFIRM_DECRYPT_SYS_DEVICE") == IDNO)
                   3439:                return;
                   3440: 
                   3441:        if (AskWarnNoYes ("CONFIRM_DECRYPT_SYS_DEVICE_CAUTION") == IDNO)
                   3442:                return;
                   3443: 
                   3444:        if (CreateSysEncMutex ())       // If no instance of the wizard is currently taking care of system encryption
                   3445:        {
                   3446:                try
                   3447:                {
                   3448:                        // User-mode app may have crashed and its mutex may have gotten lost, so we need to check the driver status too
                   3449:                        if (BootEncStatus.SetupInProgress)
                   3450:                        {
                   3451:                                int attempts = 20;
                   3452: 
                   3453:                                BootEncObj->AbortSetup ();
                   3454:                                while (BootEncStatus.SetupInProgress && attempts > 0)
                   3455:                                {
                   3456:                                        Sleep (100);
                   3457:                                        BootEncStatus = BootEncObj->GetStatus();
                   3458:                                        attempts--;
                   3459:                                        WaitCursor();
                   3460:                                }
                   3461:                        }
                   3462:                }
                   3463:                catch (Exception &e)
                   3464:                {
                   3465:                        e.Show (MainDlg);
                   3466:                }
                   3467:                NormalCursor ();
                   3468: 
                   3469:                if (BootEncStatus.SetupInProgress)
                   3470:                {
                   3471:                        CloseSysEncMutex ();    
                   3472:                        Error ("SYS_ENCRYPTION_OR_DECRYPTION_IN_PROGRESS");
                   3473:                        return;
                   3474:                }
                   3475: 
                   3476:                CloseSysEncMutex ();    
                   3477:                LaunchVolCreationWizard (MainDlg, "/dsysenc");
                   3478:        }
                   3479:        else
                   3480:                Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
                   3481: }
                   3482: 
                   3483: // Blindly attempts (without any checks) to instruct the wizard to resume whatever system encryption process
                   3484: // had been interrupted or not started but scheduled or exptected to start.
                   3485: static void ResumeInterruptedSysEncProcess (void)
                   3486: {
                   3487:        if (CreateSysEncMutex ())       // If no instance of the wizard is currently taking care of system encryption
                   3488:        {
                   3489:                CloseSysEncMutex ();    
                   3490:                LaunchVolCreationWizard (MainDlg, "/csysenc");
                   3491:        }
                   3492:        else
                   3493:                Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
                   3494: }
                   3495: 
                   3496: void CreateRescueDisk (void)
                   3497: {
                   3498:        try
                   3499:        {
                   3500:                BootEncStatus = BootEncObj->GetStatus();
                   3501:        }
                   3502:        catch (Exception &e)
                   3503:        {
                   3504:                e.Show (MainDlg);
                   3505:        }
                   3506: 
                   3507:        if (!BootEncStatus.DriveEncrypted 
                   3508:                && !BootEncStatus.DriveMounted
                   3509:                && !BootEncStatus.VolumeHeaderPresent
                   3510:                && !SysEncryptionOrDecryptionRequired ())
                   3511:        {
                   3512:                Warning ("SYS_DRIVE_NOT_ENCRYPTED");
                   3513:                return;
                   3514:        }
                   3515: 
                   3516:        if (SysEncryptionOrDecryptionRequired () 
                   3517:                || BootEncStatus.SetupInProgress)
                   3518:        {
                   3519:                Warning ("SYSTEM_ENCRYPTION_NOT_COMPLETED");
                   3520:                return;
                   3521:        }
                   3522: 
                   3523:        if (CreateSysEncMutex ())       // If no instance of the wizard is currently taking care of system encryption
                   3524:        {
                   3525:                try
                   3526:                {
                   3527:                        wchar_t szTmp [8096];
                   3528:                        char szRescueDiskISO [TC_MAX_PATH+1];
                   3529: 
                   3530:                        if (AskOkCancel ("RESCUE_DISK_NON_WIZARD_CREATION_SELECT_PATH") != IDOK)
                   3531:                                return;
1.1.1.11  root     3532: 
1.1.1.13  root     3533:                        if (BrowseFiles (MainDlg, "OPEN_TITLE", szRescueDiskISO, FALSE, TRUE) == FALSE)
                   3534:                                return;
1.1.1.11  root     3535: 
1.1.1.13  root     3536:                        WaitCursor();
                   3537:                        BootEncObj->CreateRescueIsoImage (false, szRescueDiskISO);
1.1.1.11  root     3538: 
1.1.1.13  root     3539:                        _snwprintf (szTmp, sizeof szTmp / 2,
                   3540:                                GetString ("RESCUE_DISK_NON_WIZARD_CREATION_BURN"),
                   3541:                                szRescueDiskISO);
1.1.1.11  root     3542: 
1.1.1.13  root     3543:                        MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
                   3544:                }
                   3545:                catch (Exception &e)
                   3546:                {
                   3547:                        e.Show (MainDlg);
                   3548:                        Error ("ERROR_CREATING_RESCUE_DISK");
                   3549:                }
                   3550:                CloseSysEncMutex ();
1.1.1.7   root     3551: 
1.1.1.13  root     3552:                NormalCursor ();
                   3553:        }
                   3554:        else
                   3555:                Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
1.1       root     3556: }
                   3557: 
1.1.1.13  root     3558: static void VerifyRescueDisk (void)
1.1       root     3559: {
1.1.1.13  root     3560:        try
1.1       root     3561:        {
1.1.1.13  root     3562:                BootEncStatus = BootEncObj->GetStatus();
                   3563:        }
                   3564:        catch (Exception &e)
                   3565:        {
                   3566:                e.Show (MainDlg);
1.1       root     3567:        }
                   3568: 
1.1.1.13  root     3569:        if (!BootEncStatus.DriveEncrypted 
                   3570:                && !BootEncStatus.DriveMounted
                   3571:                && !BootEncStatus.VolumeHeaderPresent
                   3572:                && !SysEncryptionOrDecryptionRequired ())
                   3573:        {
                   3574:                Warning ("SYS_DRIVE_NOT_ENCRYPTED");
                   3575:                return;
                   3576:        }
1.1       root     3577: 
1.1.1.13  root     3578:        if (SysEncryptionOrDecryptionRequired () 
                   3579:                || BootEncStatus.SetupInProgress)
1.1       root     3580:        {
1.1.1.13  root     3581:                Warning ("SYSTEM_ENCRYPTION_NOT_COMPLETED");
                   3582:                return;
                   3583:        }
1.1.1.7   root     3584: 
1.1.1.13  root     3585:        if (CreateSysEncMutex ())       // If no instance of the wizard is currently taking care of system encryption
                   3586:        {
                   3587:                try
1.1.1.7   root     3588:                {
1.1.1.13  root     3589:                        if (AskOkCancel ("RESCUE_DISK_NON_WIZARD_CHECK_INSERT") != IDOK)
                   3590:                                return;
1.1.1.7   root     3591: 
1.1.1.13  root     3592:                        // Create a temporary up-to-date rescue disk image in RAM (with it the CD/DVD content will be compared)
                   3593:                        BootEncObj->CreateRescueIsoImage (false, "");
1.1.1.7   root     3594: 
1.1.1.13  root     3595:                        WaitCursor();
                   3596:                        if (!BootEncObj->VerifyRescueDisk ())
                   3597:                                Error ("RESCUE_DISK_NON_WIZARD_CHECK_FAILED");
                   3598:                        else
                   3599:                                Info ("RESCUE_DISK_NON_WIZARD_CHECK_PASSED");
1.1.1.7   root     3600:                }
1.1.1.13  root     3601:                catch (Exception &e)
                   3602:                {
                   3603:                        e.Show (MainDlg);
                   3604:                        Error ("RESCUE_DISK_NON_WIZARD_CHECK_FAILED");
                   3605:                }
                   3606:                CloseSysEncMutex ();
                   3607: 
                   3608:                NormalCursor ();
                   3609:        }
                   3610:        else
                   3611:                Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
                   3612: }
                   3613: 
                   3614: static void ShowSystemEncryptionStatus (void)
                   3615: {
                   3616:        try
                   3617:        {
                   3618:                BootEncStatus = BootEncObj->GetStatus();
                   3619:        }
                   3620:        catch (Exception &e)
                   3621:        {
                   3622:                e.Show (MainDlg);
                   3623:        }
                   3624: 
                   3625:        if (GetAsyncKeyState (VK_SHIFT) < 0 && GetAsyncKeyState (VK_CONTROL) < 0)
                   3626:        {
                   3627:                // Ctrl+Shift held (for debugging purposes)
                   3628: 
1.1.1.14! root     3629:                DebugMsgBox ("Debugging information for system encryption:\n\nDeviceFilterActive: %d\nBootLoaderVersion: %x\nSetupInProgress: %d\nSetupMode: %d\nVolumeHeaderPresent: %d\nDriveMounted: %d\nDriveEncrypted: %d\n"
        !          3630:                        "ConfiguredEncryptedAreaStart: %I64d\nConfiguredEncryptedAreaEnd: %I64d\nEncryptedAreaStart: %I64d\nEncryptedAreaEnd: %I64d\nEncrypted: %I64d%%",
1.1.1.13  root     3631:                        BootEncStatus.DeviceFilterActive,
                   3632:                        BootEncStatus.BootLoaderVersion,
                   3633:                        BootEncStatus.SetupInProgress,
                   3634:                        BootEncStatus.SetupMode,
                   3635:                        BootEncStatus.VolumeHeaderPresent,
                   3636:                        BootEncStatus.DriveMounted,
                   3637:                        BootEncStatus.DriveEncrypted,
                   3638:                        BootEncStatus.ConfiguredEncryptedAreaStart,
                   3639:                        BootEncStatus.ConfiguredEncryptedAreaEnd,
                   3640:                        BootEncStatus.EncryptedAreaStart,
                   3641:                        BootEncStatus.EncryptedAreaEnd,
                   3642:                        !BootEncStatus.DriveEncrypted ? 0 : (BootEncStatus.EncryptedAreaEnd + 1 - BootEncStatus.EncryptedAreaStart) * 100I64 / (BootEncStatus.ConfiguredEncryptedAreaEnd + 1 - BootEncStatus.ConfiguredEncryptedAreaStart));
1.1       root     3643:        }
1.1.1.13  root     3644: 
                   3645:        if (!BootEncStatus.DriveEncrypted && !BootEncStatus.DriveMounted)
                   3646:        {
                   3647:                Info ("SYS_DRIVE_NOT_ENCRYPTED");
                   3648:                return;
                   3649:        }
                   3650: 
                   3651:        DialogBoxParamW (hInst, 
                   3652:                MAKEINTRESOURCEW (IDD_VOLUME_PROPERTIES), MainDlg,
                   3653:                (DLGPROC) VolumePropertiesDlgProc, (LPARAM) TRUE);
                   3654: 
1.1       root     3655: }
                   3656: 
                   3657: static void SelectContainer (HWND hwndDlg)
                   3658: {
1.1.1.8   root     3659:        if (BrowseFiles (hwndDlg, "OPEN_VOL_TITLE", szFileName, bHistory, FALSE) == FALSE)
1.1       root     3660:                return;
                   3661: 
1.1.1.10  root     3662:        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1       root     3663:        EnableDisableButtons (hwndDlg);
1.1.1.6   root     3664:        SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1       root     3665: }
                   3666: 
                   3667: static void SelectPartition (HWND hwndDlg)
                   3668: {
1.1.1.7   root     3669:        int nResult = DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), hwndDlg,
1.1       root     3670:                (DLGPROC) RawDevicesDlgProc, (LPARAM) & szFileName[0]);
                   3671:        if (nResult == IDOK)
                   3672:        {
1.1.1.10  root     3673:                AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1       root     3674:                EnableDisableButtons (hwndDlg);
1.1.1.6   root     3675:                SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1       root     3676:        }
                   3677: }
                   3678: 
                   3679: static void WipeCache (HWND hwndDlg)
                   3680: {
                   3681:        DWORD dwResult;
                   3682:        BOOL bResult;
                   3683: 
1.1.1.13  root     3684:        bResult = DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.11  root     3685:        if (hwndDlg == NULL)
                   3686:                return;
1.1       root     3687: 
                   3688:        if (bResult == FALSE)
                   3689:                handleWin32Error (hwndDlg);
                   3690:        else
                   3691:        {
                   3692:                EnableDisableButtons (hwndDlg);
                   3693: 
1.1.1.7   root     3694:                Info ("WIPE_CACHE");
1.1       root     3695:        }
                   3696: }
                   3697: 
1.1.1.5   root     3698: static void Benchmark (HWND hwndDlg)
                   3699: {
1.1.1.7   root     3700:        DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_BENCHMARK_DLG), hwndDlg,
1.1.1.5   root     3701:                (DLGPROC) BenchmarkDlgProc, (LPARAM) NULL);
                   3702: }
1.1       root     3703: 
1.1.1.7   root     3704: 
                   3705: static BOOL CheckMountList ()
1.1       root     3706: {
1.1.1.7   root     3707:        MOUNT_LIST_STRUCT current;
                   3708:        GetMountList (&current);
1.1.1.13  root     3709:        static BootEncryptionStatus newBootEncStatus;
1.1       root     3710: 
1.1.1.7   root     3711:        if (LastKnownLogicalDrives != GetLogicalDrives()
                   3712:                || memcmp (&LastKnownMountList, &current, sizeof (current)) != 0)
1.1       root     3713:        {
1.1.1.13  root     3714:                int selDrive;
1.1       root     3715: 
1.1.1.11  root     3716:                WaitCursor ();
1.1.1.13  root     3717:                LastKnownMountList = current;
                   3718: 
                   3719:                selDrive = HIWORD (GetSelectedLong (GetDlgItem (MainDlg, IDC_DRIVELIST)));
1.1.1.7   root     3720:                LoadDriveLetters (GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
1.1.1.13  root     3721:                NormalCursor ();
                   3722: 
                   3723:                if ((current.ulMountedDrives & (1 << (selDrive - 'A'))) == 0 && !IsDriveAvailable (selDrive - 'A'))
                   3724:                {
                   3725:                        nSelectedDriveIndex = -1;
                   3726:                        return FALSE;
                   3727:                }
1.1.1.2   root     3728: 
1.1.1.7   root     3729:                if (nSelectedDriveIndex >= 0)
                   3730:                {
1.1.1.13  root     3731:                        SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),selDrive);
                   3732: 
                   3733:                        if(nSelectedDriveIndex > SendMessage (GetDlgItem (MainDlg, IDC_DRIVELIST), LVM_GETITEMCOUNT, 0, 0)/2) 
                   3734:                                SendMessage(GetDlgItem (MainDlg, IDC_DRIVELIST), LVM_SCROLL, 0, 1000);
1.1.1.7   root     3735:                }
1.1.1.13  root     3736:        }
1.1       root     3737: 
1.1.1.13  root     3738:        try
                   3739:        {
                   3740:                newBootEncStatus = BootEncObj->GetStatus();
                   3741: 
                   3742:                if (newBootEncStatus.SetupInProgress != RecentBootEncStatus.SetupInProgress
                   3743:                        || newBootEncStatus.EncryptedAreaEnd != RecentBootEncStatus.EncryptedAreaEnd
                   3744:                        || newBootEncStatus.DriveEncrypted != RecentBootEncStatus.DriveEncrypted
                   3745:                        || newBootEncStatus.DriveMounted != RecentBootEncStatus.DriveMounted
                   3746:                        || newBootEncStatus.SetupMode != RecentBootEncStatus.SetupMode
                   3747:                        || newBootEncStatus.EncryptedAreaStart != RecentBootEncStatus.EncryptedAreaStart)
                   3748:                {
                   3749:                        /* System encryption status change */
                   3750: 
                   3751:                        int selDrive;
                   3752:                        int driveLetterToRefresh;
                   3753: 
                   3754:                        if (RecentBootEncStatus.DriveMounted == newBootEncStatus.DriveMounted)  // If an icon (and whole new line) for a system device isn't to be added/removed
                   3755:                        {
                   3756:                                // Partial refresh
                   3757:                                if (WholeSysDriveEncryption (TRUE))
                   3758:                                {
                   3759:                                        // System drive (not just partition)
                   3760:                                        driveLetterToRefresh = ENC_SYSDRIVE_PSEUDO_DRIVE_LETTER;
                   3761:                                }
                   3762:                                else
                   3763:                                {
                   3764:                                        // System partition 
                   3765:                                        driveLetterToRefresh = GetSystemDriveLetter ();
                   3766:                                }
                   3767:                        }
                   3768:                        else
                   3769:                        {
                   3770:                                // Full rebuild of the mount list
                   3771:                                driveLetterToRefresh = 0;       
                   3772:                        }
                   3773: 
                   3774:                        WaitCursor ();
                   3775: 
                   3776:                        selDrive = HIWORD (GetSelectedLong (GetDlgItem (MainDlg, IDC_DRIVELIST)));
                   3777:                        LoadDriveLetters (GetDlgItem (MainDlg, IDC_DRIVELIST), driveLetterToRefresh);
                   3778: 
                   3779:                        memcpy (&RecentBootEncStatus, &newBootEncStatus, sizeof (RecentBootEncStatus));
                   3780: 
                   3781:                        NormalCursor ();
                   3782: 
                   3783:                        if ((current.ulMountedDrives & (1 << (selDrive - 'A'))) == 0 && !IsDriveAvailable (selDrive - 'A'))
                   3784:                        {
                   3785:                                nSelectedDriveIndex = -1;
                   3786:                        }
                   3787: 
                   3788:                        if (nSelectedDriveIndex >= 0)
                   3789:                        {
                   3790:                                SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),selDrive);
                   3791: 
                   3792:                                //if(nSelectedDriveIndex > SendMessage (GetDlgItem (MainDlg, IDC_DRIVELIST), LVM_GETITEMCOUNT, 0, 0)/2) 
                   3793:                                //      SendMessage(GetDlgItem (MainDlg, IDC_DRIVELIST), LVM_SCROLL, 0, 1000);
                   3794:                        }
                   3795:                }
                   3796: 
                   3797:                // Hibernation prevention notifications
                   3798:                if (newBootEncStatus.HibernationPreventionCount != RecentBootEncStatus.HibernationPreventionCount
                   3799:                        && !bHibernationPreventionNotified)
                   3800:                {
                   3801:                        bHibernationPreventionNotified = TRUE;
                   3802:                        RecentBootEncStatus.HibernationPreventionCount = newBootEncStatus.HibernationPreventionCount;
                   3803:                        Warning ("SYS_ENC_HIBERNATION_PREVENTED");
                   3804:                }
                   3805:        }
                   3806:        catch (...)
                   3807:        {
                   3808:                // NOP
1.1.1.7   root     3809:        }
1.1       root     3810: 
1.1.1.7   root     3811:        return TRUE;
                   3812: }
1.1.1.6   root     3813: 
1.1       root     3814: 
1.1.1.13  root     3815: /* Except in response to the WM_INITDIALOG and WM_ENDSESSION messages, the dialog box procedure
1.1.1.11  root     3816:    should return nonzero if it processes a message, and zero if it does not. */
1.1.1.13  root     3817: BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1.1.1.7   root     3818: {
1.1.1.11  root     3819:        static UINT taskBarCreatedMsg;
1.1.1.7   root     3820:        WORD lw = LOWORD (wParam);
                   3821:        WORD hw = HIWORD (wParam);
                   3822:        DWORD mPos;
1.1       root     3823: 
1.1.1.7   root     3824:        switch (uMsg)
                   3825:        {
                   3826:        case WM_HOTKEY:
1.1       root     3827: 
1.1.1.7   root     3828:                HandleHotKey (hwndDlg, wParam);
                   3829:                return 1;
1.1       root     3830: 
1.1.1.7   root     3831:        case WM_INITDIALOG:
                   3832:                {
                   3833:                        int exitCode = 0;
1.1.1.13  root     3834:                        int modeOfOperation;
                   3835: 
1.1.1.7   root     3836:                        MainDlg = hwndDlg;
1.1       root     3837: 
1.1.1.7   root     3838:                        // Set critical default options in case UsePreferences is false
                   3839:                        bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = TRUE;
1.1       root     3840: 
1.1.1.7   root     3841:                        ExtractCommandLine (hwndDlg, (char *) lParam);
                   3842: 
1.1.1.11  root     3843:                        if (ComServerMode)
                   3844:                        {
                   3845:                                if (!ComServerMain ())
                   3846:                                {
                   3847:                                        handleWin32Error (hwndDlg);
                   3848:                                        exit (1);
                   3849:                                }
                   3850:                                exit (0);
                   3851:                        }
                   3852: 
1.1.1.13  root     3853:                        try
                   3854:                        {
                   3855:                                BootEncStatus = BootEncObj->GetStatus();
                   3856:                                memcpy (&RecentBootEncStatus, &BootEncStatus, sizeof (RecentBootEncStatus));
                   3857:                        }
                   3858:                        catch (...)
                   3859:                        {
                   3860:                                // NOP
                   3861:                        }
                   3862: 
1.1.1.7   root     3863:                        if (UsePreferences)
1.1       root     3864:                        {
1.1.1.7   root     3865:                                // General preferences
                   3866:                                LoadSettings (hwndDlg);
                   3867: 
                   3868:                                // Keyfiles
                   3869:                                LoadDefaultKeyFilesParam ();
                   3870:                                RestoreDefaultKeyFilesParam ();
1.1       root     3871:                        }
                   3872: 
1.1.1.7   root     3873:                        InitMainDialog (hwndDlg);
                   3874: 
                   3875:                        // Wipe cache
                   3876:                        if (bWipe)
                   3877:                                WipeCache (hwndDlg);
                   3878: 
1.1.1.2   root     3879:                        // Automount
1.1.1.7   root     3880:                        if (bAuto || (Quit && szFileName[0] != 0))
1.1       root     3881:                        {
1.1.1.5   root     3882:                                // No drive letter specified on command line
                   3883:                                if (commandLineDrive == 0)
                   3884:                                        szDriveLetter[0] = GetFirstAvailableDrive () + 'A';
                   3885: 
1.1.1.6   root     3886:                                if (bAutoMountDevices)
                   3887:                                {
                   3888:                                        defaultMountOptions = mountOptions;
1.1.1.8   root     3889:                                        if (FirstCmdKeyFile)
                   3890:                                        {
                   3891:                                                KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
                   3892:                                                FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
                   3893:                                                defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
                   3894:                                        }
                   3895: 
1.1.1.7   root     3896:                                        if (!MountAllDevices (hwndDlg, !Silent))
                   3897:                                                exitCode = 1;
                   3898:                                }
                   3899: 
                   3900:                                if (bAutoMountFavorites)
                   3901:                                {
                   3902:                                        defaultMountOptions = mountOptions;
1.1.1.8   root     3903:                                        if (FirstCmdKeyFile)
                   3904:                                        {
                   3905:                                                KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
                   3906:                                                FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
                   3907:                                                defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
                   3908:                                        }
                   3909: 
1.1.1.7   root     3910:                                        if (!MountFavoriteVolumes ())
                   3911:                                                exitCode = 1;
1.1.1.6   root     3912:                                }
1.1.1.7   root     3913: 
                   3914:                                if (szFileName[0] != 0 && !IsMountedVolume (szFileName))
1.1.1.2   root     3915:                                {
                   3916:                                        BOOL mounted;
                   3917: 
                   3918:                                        // Cached password
1.1.1.7   root     3919:                                        mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, NULL, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE);
1.1.1.2   root     3920: 
1.1.1.7   root     3921:                                        // Command line password or keyfiles
                   3922:                                        if (!mounted && (CmdVolumePassword.Length != 0 || FirstCmdKeyFile))
1.1.1.2   root     3923:                                        {
1.1.1.7   root     3924:                                                BOOL reportBadPasswd = CmdVolumePassword.Length > 0;
                   3925: 
                   3926:                                                if (FirstCmdKeyFile)
1.1.1.12  root     3927:                                                        KeyFilesApply (&CmdVolumePassword, FirstCmdKeyFile);
1.1.1.7   root     3928: 
                   3929:                                                mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A',
                   3930:                                                        szFileName, &CmdVolumePassword, bCacheInDriver, bForceMount,
                   3931:                                                        &mountOptions, Silent, reportBadPasswd);
                   3932: 
                   3933:                                                burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
                   3934:                                        }
                   3935: 
                   3936:                                        if (FirstCmdKeyFile)
                   3937:                                        {
                   3938:                                                FirstKeyFile = FirstCmdKeyFile;
                   3939:                                                KeyFilesEnable = TRUE;
1.1.1.2   root     3940:                                        }
                   3941: 
                   3942:                                        // Ask user for password
1.1.1.7   root     3943:                                        while (!mounted && !Silent)
1.1.1.2   root     3944:                                        {
1.1.1.7   root     3945:                                                VolumePassword.Length = 0;
1.1.1.2   root     3946: 
1.1.1.7   root     3947:                                                strcpy (PasswordDlgVolume, szFileName);
                   3948:                                                if (!AskUserPassword (hwndDlg, &VolumePassword))
1.1.1.2   root     3949:                                                        break;
                   3950: 
1.1.1.11  root     3951:                                                WaitCursor ();
1.1.1.7   root     3952: 
                   3953:                                                if (KeyFilesEnable && FirstKeyFile)
1.1.1.12  root     3954:                                                        KeyFilesApply (&VolumePassword, FirstKeyFile);
1.1.1.7   root     3955: 
                   3956:                                                mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, FALSE, TRUE);
                   3957: 
                   3958:                                                burn (&VolumePassword, sizeof (VolumePassword));
                   3959:                                                burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
                   3960: 
1.1.1.2   root     3961:                                                NormalCursor ();
                   3962:                                        }
                   3963: 
1.1.1.7   root     3964:                                        if (UsePreferences)
1.1.1.11  root     3965:                                        {
1.1.1.7   root     3966:                                                RestoreDefaultKeyFilesParam ();
1.1.1.11  root     3967:                                                bCacheInDriver = bCacheInDriverDefault;
                   3968:                                        }
1.1.1.7   root     3969: 
1.1.1.5   root     3970:                                        if (mounted > 0)
1.1.1.2   root     3971:                                        {
1.1.1.11  root     3972:                                                if (bBeep) 
                   3973:                                                        MessageBeep (-1);
                   3974: 
                   3975:                                                if (bExplore) 
                   3976:                                                        OpenVolumeExplorerWindow (szDriveLetter[0] - 'A');
                   3977: 
1.1.1.7   root     3978:                                                RefreshMainDlg(hwndDlg);
1.1.1.11  root     3979: 
                   3980:                                                if(!Silent)
                   3981:                                                {
1.1.1.13  root     3982:                                                        // Check for deprecated CBC mode
                   3983:                                                        modeOfOperation = GetModeOfOperationByDriveNo (szDriveLetter[0] - 'A');
                   3984:                                                        if (modeOfOperation == CBC || modeOfOperation == OUTER_CBC)
                   3985:                                                                Warning("WARN_CBC_MODE");
                   3986: 
                   3987:                                                        // Check for deprecated 64-bit-block ciphers
1.1.1.11  root     3988:                                                        if (GetCipherBlockSizeByDriveNo (szDriveLetter[0] - 'A') == 64)
                   3989:                                                                Warning("WARN_64_BIT_BLOCK_CIPHER");
                   3990: 
                   3991:                                                        // Check for problematic file extensions (exe, dll, sys)
                   3992:                                                        if (CheckFileExtension (szFileName))
                   3993:                                                                Warning ("EXE_FILE_EXTENSION_MOUNT_WARNING");
                   3994:                                                }
1.1.1.2   root     3995:                                        }
1.1.1.7   root     3996:                                        else
                   3997:                                                exitCode = 1;
1.1.1.2   root     3998:                                }
1.1.1.12  root     3999:                                else if (bExplore && GetMountedVolumeDriveNo (szFileName) != -1)
                   4000:                                        OpenVolumeExplorerWindow (GetMountedVolumeDriveNo (szFileName));
1.1.1.10  root     4001:                                else if (szFileName[0] != 0 && IsMountedVolume (szFileName))
1.1.1.11  root     4002:                                        Warning ("VOL_ALREADY_MOUNTED");
1.1.1.10  root     4003:                                        
1.1.1.8   root     4004:                                if (!Quit)
                   4005:                                        RefreshMainDlg(hwndDlg);
1.1.1.7   root     4006:                        }
                   4007: 
                   4008:                        // Wipe command line password
                   4009:                        if (CmdVolumePassword.Length != 0)
                   4010:                        {
                   4011:                                burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
                   4012:                                CmdVolumePassword.Length = 0;
1.1       root     4013:                        }
                   4014: 
1.1.1.7   root     4015:                        // Wipe command line keyfiles
                   4016:                        if (FirstCmdKeyFile)
1.1.1.8   root     4017:                        {
                   4018:                                if (defaultKeyFilesParam.FirstKeyFile)
                   4019:                                        KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile);
                   4020: 
                   4021:                                defaultKeyFilesParam.EnableKeyFiles = FALSE;
                   4022: 
1.1.1.10  root     4023:                                if (!Quit)
                   4024:                                {
                   4025:                                        LoadSettings (hwndDlg);
                   4026:                                        LoadDefaultKeyFilesParam ();
                   4027:                                        RestoreDefaultKeyFilesParam ();
                   4028:                                }
1.1.1.8   root     4029:                        }
1.1.1.7   root     4030: 
                   4031:                        // Dismount
1.1.1.5   root     4032:                        if (cmdUnmountDrive > 0)
1.1.1.7   root     4033:                        {
                   4034:                                if (!Dismount (hwndDlg, (char)toupper(szDriveLetter[0]) - 'A'))
                   4035:                                        exitCode = 1;
                   4036:                        }
1.1.1.5   root     4037:                        else if (cmdUnmountDrive == -1)
1.1.1.7   root     4038:                        {
                   4039:                                if (!DismountAll (hwndDlg, bForceUnmount, !Silent, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY))
                   4040:                                        exitCode = 1;
                   4041:                        }
1.1.1.5   root     4042: 
1.1.1.7   root     4043:                        // TaskBar icon
                   4044:                        if (bEnableBkgTask)
                   4045:                                TaskBarIconAdd (hwndDlg);
1.1.1.11  root     4046: 
1.1.1.7   root     4047:                        // Quit
1.1.1.12  root     4048:                        if (Quit)
                   4049:                        {
                   4050:                                if (TaskBarIconMutex == NULL)
                   4051:                                        exit (exitCode);
                   4052: 
                   4053:                                MainWindowHidden = TRUE;
                   4054: 
                   4055:                                LoadSettings (hwndDlg);
                   4056:                                LoadDefaultKeyFilesParam ();
                   4057:                                RestoreDefaultKeyFilesParam ();
                   4058: 
                   4059:                                if (!bEnableBkgTask)
                   4060:                                {
                   4061:                                        if (TaskBarIconMutex)
                   4062:                                                TaskBarIconRemove (hwndDlg);
                   4063:                                        exit (exitCode);
                   4064:                                }
                   4065:                        }
1.1.1.7   root     4066: 
1.1.1.8   root     4067:                        // No command line arguments or only /volume => bring active instance
                   4068:                        // to foreground if available
                   4069:                        if (NoCmdLineArgs == 0 || (CmdLineVolumeSpecified && NoCmdLineArgs <= 2))
                   4070:                        {
                   4071:                                HWND h = hwndDlg;
                   4072:                                EnumWindows (FindTCWindowEnum, (LPARAM) &h);
                   4073: 
                   4074:                                if (h != hwndDlg)
                   4075:                                {
                   4076:                                        if (CmdLineVolumeSpecified)
                   4077:                                        {
                   4078:                                                COPYDATASTRUCT cd;
                   4079:                                                memcpy (&cd.dwData, WM_COPY_SET_VOLUME_NAME, 4);
                   4080:                                                cd.lpData = szFileName;
                   4081:                                                cd.cbData = strlen (szFileName) + 1;
                   4082: 
                   4083:                                                SendMessage (h, WM_COPYDATA, (WPARAM)hwndDlg, (LPARAM)&cd);
                   4084:                                        }
                   4085: 
1.1.1.13  root     4086:                                        SendMessage (h, TC_APPMSG_MOUNT_SHOW_WINDOW, 0, 0);
1.1.1.8   root     4087: 
                   4088:                                        ShowWindow (h, SW_SHOW);
                   4089:                                        SetForegroundWindow (h);
1.1.1.12  root     4090: 
                   4091:                                        if (TaskBarIconMutex == NULL)
                   4092:                                                exit (0);
1.1.1.8   root     4093:                                }
                   4094:                        }
                   4095: 
1.1.1.12  root     4096:                        // Register hot keys
                   4097:                        if (!RegisterAllHotkeys (hwndDlg, Hotkeys)
                   4098:                                && TaskBarIconMutex != NULL)    // Warn only if we are the first instance of TrueCrypt
                   4099:                                Warning("HOTKEY_REGISTRATION_ERROR");
                   4100: 
1.1.1.7   root     4101:                        Silent = FALSE;
                   4102: 
                   4103:                        GetMountList (&LastKnownMountList);
1.1.1.13  root     4104:                        SetTimer (hwndDlg, TIMER_ID_MAIN, TIMER_INTERVAL_MAIN, NULL);
1.1.1.3   root     4105: 
1.1.1.11  root     4106:                        taskBarCreatedMsg = RegisterWindowMessage ("TaskbarCreated");
                   4107: 
1.1       root     4108:                        SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1.1.13  root     4109: 
                   4110:                        /* Check system encryption status */
                   4111: 
                   4112:                        if (!Quit)              // Do not care about system encryption if we were launched from the system startup sequence (the wizard was added to it too).
                   4113:                        {
                   4114:                                if (SysEncryptionOrDecryptionRequired ())
                   4115:                                {
                   4116:                                        if (CreateSysEncMutex ())       // If no instance of the wizard is currently taking care of system encryption
                   4117:                                        {
                   4118:                                                CloseSysEncMutex ();    // We shouldn't block the mutex for too long at this point
                   4119: 
                   4120:                                                if (SystemEncryptionStatus == SYSENC_STATUS_PRETEST
                   4121:                                                        || AskWarnYesNo ("SYSTEM_ENCRYPTION_RESUME_PROMPT") == IDYES)
                   4122:                                                {
                   4123:                                                        // The wizard was not launched during the system startup seq, or the user may have forgotten
                   4124:                                                        // to resume the encryption/decryption process.
                   4125: 
                   4126: 
                   4127:                                                        LaunchVolCreationWizard (hwndDlg, "/csysenc");
                   4128:                                                }
                   4129:                                        }
                   4130:                                }
                   4131:                        }
1.1       root     4132:                }
                   4133:                return 0;
                   4134: 
1.1.1.7   root     4135:        case WM_WINDOWPOSCHANGING:
                   4136:                if (MainWindowHidden)
                   4137:                {
1.1.1.13  root     4138:                        // Prevent window from being shown
1.1.1.7   root     4139:                        PWINDOWPOS wp = (PWINDOWPOS)lParam;
                   4140:                        wp->flags &= ~SWP_SHOWWINDOW;
                   4141:                        return 0;
                   4142:                }
                   4143:                return 1;
                   4144: 
1.1       root     4145:        case WM_SYSCOMMAND:
                   4146:                if (lw == IDC_ABOUT)
                   4147:                {
1.1.1.7   root     4148:                        DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1       root     4149:                        return 1;
                   4150:                }
                   4151:                return 0;
                   4152: 
                   4153:        case WM_HELP:
1.1.1.7   root     4154:                OpenPageHelp (hwndDlg, 0);
1.1       root     4155:                return 1;
                   4156: 
1.1.1.7   root     4157:        case WM_ENDSESSION:
                   4158:                if (TaskBarIconMutex != NULL)
1.1       root     4159:                {
1.1.1.7   root     4160:                        if (bDismountOnLogOff)
                   4161:                        {
                   4162:                                // Auto-dismount when user logs off
                   4163:                                DWORD dwResult;
                   4164: 
                   4165:                                if (bWipeCacheOnAutoDismount)
1.1.1.13  root     4166:                                        DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.7   root     4167: 
                   4168:                                if (!DismountAll (hwndDlg, FALSE, FALSE, 5, 1000))
                   4169:                                {
                   4170:                                        if (bForceAutoDismount)
                   4171:                                                DismountAll (hwndDlg, TRUE, FALSE, 1, 0);
                   4172:                                        else
                   4173:                                                DismountAll (hwndDlg, FALSE, TRUE, 1, 0);
                   4174:                                }
                   4175:                        }
                   4176: 
                   4177:                        TaskBarIconRemove (hwndDlg);
                   4178:                }
1.1.1.13  root     4179:                EndMainDlg (hwndDlg);
                   4180:                localcleanup ();
1.1.1.7   root     4181:                return 0;
                   4182: 
                   4183:        case WM_POWERBROADCAST:
                   4184:                if (wParam == PBT_APMSUSPEND
                   4185:                        && TaskBarIconMutex != NULL && bDismountOnPowerSaving)
                   4186:                {
                   4187:                        // Auto-dismount when entering power-saving mode
                   4188:                        DWORD dwResult;
1.1.1.12  root     4189:                        BOOL volumesMounted = LastKnownMountList.ulMountedDrives != 0;
                   4190: 
1.1.1.7   root     4191:                        if (bWipeCacheOnAutoDismount)
1.1.1.13  root     4192:                                DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.12  root     4193: 
                   4194:                        if (DismountAll (hwndDlg, bForceAutoDismount, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY) && volumesMounted)
                   4195:                                Info ("MOUNTED_VOLUMES_AUTO_DISMOUNTED");
1.1.1.7   root     4196:                }
                   4197:                return 0;
                   4198: 
                   4199:        case WM_TIMER:
                   4200:                {
                   4201:                        // Check mount list and update GUI if needed
                   4202:                        CheckMountList ();
                   4203: 
                   4204:                        // Cache status
                   4205:                        if (IsPasswordCacheEmpty() == IsWindowEnabled (GetDlgItem (hwndDlg, IDC_WIPE_CACHE)))
                   4206:                                EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_CACHE), !IsPasswordCacheEmpty());
                   4207: 
                   4208:                        if (TaskBarIconMutex != NULL)
                   4209:                        {
                   4210:                                // Idle auto-dismount
                   4211:                                if (MaxVolumeIdleTime > 0)
                   4212:                                        DismountIdleVolumes ();
                   4213: 
                   4214:                                // Screen saver auto-dismount
                   4215:                                if (bDismountOnScreenSaver)
                   4216:                                {
                   4217:                                        static BOOL previousState = FALSE;
                   4218:                                        BOOL running = FALSE;
                   4219:                                        SystemParametersInfo (SPI_GETSCREENSAVERRUNNING, 0, &running, 0);
                   4220: 
                   4221:                                        if (running && !previousState)
                   4222:                                        {
                   4223:                                                DWORD dwResult;
                   4224:                                                previousState = TRUE;
                   4225: 
                   4226:                                                if (bWipeCacheOnAutoDismount)
1.1.1.13  root     4227:                                                        DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.12  root     4228: 
                   4229:                                                DismountAll (hwndDlg, bForceAutoDismount, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1.1.7   root     4230:                                        }
                   4231:                                        else
                   4232:                                        {
                   4233:                                                previousState = running;
1.1.1.8   root     4234:                                        }
1.1.1.7   root     4235:                                }
                   4236:                        }
                   4237: 
1.1.1.8   root     4238:                        // Exit background process in non-install mode or if no volume mounted
1.1.1.7   root     4239:                        // and no other instance active
                   4240:                        if (LastKnownMountList.ulMountedDrives == 0
1.1.1.13  root     4241:                                && MainWindowHidden
1.1.1.7   root     4242: #ifndef _DEBUG
                   4243:                                && (bCloseBkgTaskWhenNoVolumes || IsNonInstallMode ()) 
                   4244: #endif
1.1.1.13  root     4245:                                && !SysEncDeviceActive (TRUE)
1.1.1.7   root     4246:                                && GetDriverRefCount () < 2)
                   4247:                        {
                   4248:                                TaskBarIconRemove (hwndDlg);
                   4249:                                EndMainDlg (hwndDlg);
                   4250:                        }
1.1       root     4251: 
                   4252:                        return 1;
                   4253:                }
1.1.1.13  root     4254:                return 1;
1.1       root     4255: 
1.1.1.13  root     4256:        case TC_APPMSG_TASKBAR_ICON:
1.1       root     4257:                {
1.1.1.7   root     4258:                        switch (lParam)
                   4259:                        {
                   4260:                        case WM_LBUTTONDOWN:
1.1.1.8   root     4261:                                SetForegroundWindow (hwndDlg);
1.1.1.7   root     4262:                                MainWindowHidden = FALSE;
                   4263:                                ShowWindow (hwndDlg, SW_SHOW);
1.1.1.13  root     4264:                                ShowWindow (hwndDlg, SW_RESTORE);
1.1.1.7   root     4265:                                break;
                   4266: 
                   4267:                        case WM_RBUTTONDOWN:
                   4268:                                {
                   4269:                                        POINT pos;
                   4270:                                        HMENU popup = CreatePopupMenu ();
                   4271:                                        int sel, i, n;
1.1.1.8   root     4272:                                        
1.1.1.7   root     4273:                                        if (MainWindowHidden)
                   4274:                                        {
                   4275:                                                AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("SHOW_TC"));
                   4276:                                                AppendMenu (popup, MF_SEPARATOR, 0, NULL);
                   4277:                                        }
                   4278:                                        else if (bEnableBkgTask
                   4279:                                                && (!(LastKnownMountList.ulMountedDrives == 0
                   4280:                                                && (bCloseBkgTaskWhenNoVolumes || IsNonInstallMode ()) 
1.1.1.13  root     4281:                                                && !SysEncDeviceActive (TRUE)
1.1.1.7   root     4282:                                                && GetDriverRefCount () < 2)))
                   4283:                                        {
                   4284:                                                AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("HIDE_TC"));
                   4285:                                                AppendMenu (popup, MF_SEPARATOR, 0, NULL);
                   4286:                                        }
1.1.1.13  root     4287:                                        AppendMenuW (popup, MF_STRING, IDM_MOUNTALL, GetString ("IDC_MOUNTALL"));
1.1.1.7   root     4288:                                        AppendMenuW (popup, MF_STRING, IDM_MOUNT_FAVORITE_VOLUMES, GetString ("IDM_MOUNT_FAVORITE_VOLUMES"));
                   4289:                                        AppendMenuW (popup, MF_STRING, IDM_UNMOUNTALL, GetString ("IDM_UNMOUNTALL"));
                   4290:                                        AppendMenu (popup, MF_SEPARATOR, 0, NULL);
                   4291: 
                   4292:                                        for (n = 0; n < 2; n++)
                   4293:                                        {
                   4294:                                                for (i = 0; i < 26; i++)
                   4295:                                                {
                   4296:                                                        if (LastKnownMountList.ulMountedDrives & (1 << i))
                   4297:                                                        {
                   4298:                                                                wchar_t s[1024];
1.1.1.13  root     4299:                                                                wchar_t *vol = (wchar_t *) LastKnownMountList.wszVolume[i];
1.1.1.7   root     4300: 
                   4301:                                                                if (wcsstr (vol, L"\\??\\")) vol += 4;
                   4302: 
                   4303:                                                                wsprintfW (s, L"%s %c: (%s)",
                   4304:                                                                        GetString (n==0 ? "OPEN" : "DISMOUNT"),
                   4305:                                                                        i + L'A', 
                   4306:                                                                        vol);
1.1.1.13  root     4307:                                                                AppendMenuW (popup, MF_STRING, n*26 + TRAYICON_MENU_DRIVE_OFFSET + i, s);
1.1.1.7   root     4308:                                                        }
                   4309:                                                }
                   4310:                                                if (LastKnownMountList.ulMountedDrives != 0)
                   4311:                                                        AppendMenu (popup, MF_SEPARATOR, 0, NULL);
                   4312:                                        }
                   4313: 
                   4314:                                        AppendMenuW (popup, MF_STRING, IDM_HELP, GetString ("MENU_HELP"));
1.1.1.11  root     4315:                                        AppendMenuW (popup, MF_STRING, IDM_HOMEPAGE_SYSTRAY, GetString ("HOMEPAGE"));
1.1.1.7   root     4316:                                        AppendMenuW (popup, MF_STRING, IDM_PREFERENCES, GetString ("IDM_PREFERENCES"));
                   4317:                                        AppendMenuW (popup, MF_STRING, IDM_ABOUT, GetString ("IDM_ABOUT"));
                   4318:                                        AppendMenu (popup, MF_SEPARATOR, 0, NULL);
1.1.1.13  root     4319:                                        AppendMenuW (popup, MF_STRING, IDCANCEL, GetString ("EXIT"));
1.1.1.7   root     4320: 
                   4321:                                        GetCursorPos (&pos);
                   4322: 
                   4323:                                        SetForegroundWindow(hwndDlg);
                   4324: 
                   4325:                                        sel = TrackPopupMenu (popup,
                   4326:                                                TPM_RETURNCMD | TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON,
                   4327:                                                pos.x,
                   4328:                                                pos.y,
                   4329:                                                0,
                   4330:                                                hwndDlg,
                   4331:                                                NULL);
                   4332: 
1.1.1.13  root     4333:                                        if (sel >= TRAYICON_MENU_DRIVE_OFFSET && sel < TRAYICON_MENU_DRIVE_OFFSET + 26)
1.1.1.7   root     4334:                                        {
1.1.1.13  root     4335:                                                OpenVolumeExplorerWindow (sel - TRAYICON_MENU_DRIVE_OFFSET);
1.1.1.7   root     4336:                                        }
1.1.1.13  root     4337:                                        else if (sel >= TRAYICON_MENU_DRIVE_OFFSET + 26 && sel < TRAYICON_MENU_DRIVE_OFFSET + 26*2)
1.1.1.7   root     4338:                                        {
                   4339:                                                if (CheckMountList ())
1.1.1.13  root     4340:                                                        Dismount (hwndDlg, sel - TRAYICON_MENU_DRIVE_OFFSET - 26);
1.1.1.7   root     4341:                                        }
                   4342:                                        else if (sel == IDM_SHOW_HIDE)
                   4343:                                        {
1.1.1.13  root     4344:                                                ChangeMainWindowVisibility ();
1.1.1.7   root     4345:                                        }
1.1.1.11  root     4346:                                        else if (sel == IDM_HOMEPAGE_SYSTRAY)
                   4347:                                        {
                   4348:                                                Applink ("home", TRUE, "");
                   4349:                                        }
1.1.1.13  root     4350:                                        else if (sel == IDCANCEL)
1.1.1.7   root     4351:                                        {
1.1.1.13  root     4352:                                                if ((LastKnownMountList.ulMountedDrives == 0
                   4353:                                                        && !SysEncDeviceActive (TRUE))
1.1.1.7   root     4354:                                                        || AskWarnNoYes ("CONFIRM_EXIT") == IDYES)
                   4355:                                                {
                   4356:                                                        // Close all other TC windows
                   4357:                                                        EnumWindows (CloseTCWindowsEnum, 0);
                   4358: 
                   4359:                                                        TaskBarIconRemove (hwndDlg);
                   4360:                                                        SendMessage (hwndDlg, WM_COMMAND, sel, 0);
                   4361:                                                }
                   4362:                                        }
                   4363:                                        else
                   4364:                                        {
                   4365:                                                SendMessage (hwndDlg, WM_COMMAND, sel, 0);
                   4366:                                        }
                   4367: 
                   4368:                                        PostMessage(hwndDlg, WM_NULL, 0, 0);
                   4369:                                        DestroyMenu (popup);
                   4370:                                }
1.1       root     4371:                        }
1.1.1.7   root     4372:                        return 1;
                   4373:                }
                   4374: 
1.1.1.13  root     4375:        case TC_APPMSG_CLOSE_BKG_TASK:
1.1.1.11  root     4376:                if (TaskBarIconMutex != NULL)
                   4377:                        TaskBarIconRemove (hwndDlg);
                   4378: 
                   4379:                return 1;
                   4380: 
1.1.1.13  root     4381:        case TC_APPMSG_SYSENC_CONFIG_UPDATE:
                   4382:                LoadSysEncSettings (hwndDlg);
                   4383: 
                   4384:                // The wizard adds TrueCrypt.exe to the system startup sequence so we must update our cached settings
                   4385:                LoadSettings (hwndDlg);
                   4386: 
                   4387:                return 1;
                   4388: 
1.1.1.11  root     4389:        case WM_DEVICECHANGE:
1.1.1.12  root     4390:                if (!IgnoreWmDeviceChange && wParam != DBT_DEVICEARRIVAL)
1.1.1.11  root     4391:                {
                   4392:                        // Check if any host device has been removed and force dismount of volumes accordingly
                   4393:                        PDEV_BROADCAST_HDR hdr = (PDEV_BROADCAST_HDR) lParam;
1.1.1.12  root     4394:                        int m;
                   4395: 
                   4396:                        GetMountList (&LastKnownMountList);
                   4397: 
1.1.1.11  root     4398:                        if (wParam == DBT_DEVICEREMOVECOMPLETE && hdr->dbch_devicetype == DBT_DEVTYP_VOLUME)
                   4399:                        {
1.1.1.12  root     4400:                                // File-hosted volumes
1.1.1.11  root     4401:                                PDEV_BROADCAST_VOLUME vol = (PDEV_BROADCAST_VOLUME) lParam;
1.1.1.12  root     4402:                                int i;
1.1.1.11  root     4403: 
                   4404:                                for (i = 0; i < 26; i++)
                   4405:                                {
                   4406:                                        if (vol->dbcv_unitmask & (1 << i))
                   4407:                                        {
                   4408:                                                for (m = 0; m < 26; m++)
                   4409:                                                {
                   4410:                                                        if (LastKnownMountList.ulMountedDrives & (1 << m))
                   4411:                                                        {
1.1.1.13  root     4412:                                                                wchar_t *vol = (wchar_t *) LastKnownMountList.wszVolume[m];
1.1.1.11  root     4413: 
1.1.1.12  root     4414:                                                                if (wcsstr (vol, L"\\??\\") == vol)
1.1.1.11  root     4415:                                                                        vol += 4;
                   4416: 
1.1.1.12  root     4417:                                                                if (vol[1] == L':' && i == (vol[0] - (vol[0] <= L'Z' ? L'A' : L'a')))
1.1.1.11  root     4418:                                                                {
                   4419:                                                                        UnmountVolume (hwndDlg, m, TRUE);
                   4420:                                                                        if (bWipeCacheOnAutoDismount || bWipeCacheOnExit)
                   4421:                                                                                WipeCache (NULL);
                   4422:                                                                }
                   4423:                                                        }
                   4424:                                                }
                   4425:                                        }
                   4426:                                }
1.1.1.12  root     4427:                        }
1.1.1.11  root     4428: 
1.1.1.12  root     4429:                        // Device-hosted volumes
                   4430:                        for (m = 0; m < 26; m++)
                   4431:                        {
                   4432:                                if (LastKnownMountList.ulMountedDrives & (1 << m))
                   4433:                                {
1.1.1.13  root     4434:                                        wchar_t *vol = (wchar_t *) LastKnownMountList.wszVolume[m];
1.1.1.12  root     4435:                                        char volp[MAX_PATH];
                   4436: 
                   4437:                                        if (wcsstr (vol, L"\\??\\") == vol)
                   4438:                                                vol += 4;
                   4439: 
                   4440:                                        _snprintf (volp, sizeof(volp), "%ls", vol);
                   4441: 
                   4442:                                        if (IsVolumeDeviceHosted (volp))
                   4443:                                        {
                   4444:                                                OPEN_TEST_STRUCT ots;
                   4445: 
                   4446:                                                if (!OpenDevice (volp, &ots))
                   4447:                                                {
                   4448:                                                        UnmountVolume (hwndDlg, m, TRUE);
                   4449:                                                        if (bWipeCacheOnAutoDismount || bWipeCacheOnExit)
                   4450:                                                                WipeCache (NULL);
                   4451:                                                }
                   4452:                                        }
                   4453:                                }
1.1.1.11  root     4454:                        }
1.1.1.12  root     4455:                        return 1;
1.1.1.11  root     4456:                }
1.1.1.12  root     4457:                return 0;
1.1.1.11  root     4458: 
1.1.1.7   root     4459:        case WM_NOTIFY:
                   4460: 
                   4461:                if(wParam == IDC_DRIVELIST)
                   4462:                {
                   4463:                        /* Single click within drive list */
                   4464:                        if (((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED ))
                   4465:                        {
                   4466:                                nSelectedDriveIndex = ((LPNMLISTVIEW) lParam)->iItem;
                   4467:                                EnableDisableButtons (hwndDlg);
                   4468:                                return 1;
                   4469:                        }
                   4470: 
                   4471:                        /* Double click within drive list */
                   4472:                        if (((LPNMHDR) lParam)->code == LVN_ITEMACTIVATE)
1.1       root     4473:                        {
1.1.1.13  root     4474:                                int state = GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), ((LPNMITEMACTIVATE)lParam)->iItem );
1.1.1.7   root     4475:                                nSelectedDriveIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
1.1.1.13  root     4476:                                if (LOWORD(state) == TC_MLIST_ITEM_NONSYS_VOL || LOWORD(state) == TC_MLIST_ITEM_SYS_PARTITION)
1.1.1.7   root     4477:                                {
                   4478:                                        // Open explorer window for mounted volume
1.1.1.11  root     4479:                                        WaitCursor ();
1.1.1.7   root     4480:                                        OpenVolumeExplorerWindow (HIWORD(state) - 'A');
                   4481:                                        NormalCursor ();
                   4482:                                }
1.1.1.13  root     4483:                                else if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == TC_MLIST_ITEM_FREE)
1.1.1.7   root     4484:                                {
1.1.1.11  root     4485:                                        mountOptions = defaultMountOptions;
                   4486: 
1.1.1.9   root     4487:                                        if (GetAsyncKeyState (VK_CONTROL) < 0)
                   4488:                                        {
                   4489:                                                if (IDCANCEL == DialogBoxParamW (hInst, 
                   4490:                                                        MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
                   4491:                                                        (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions))
                   4492:                                                        return 1;
                   4493: 
                   4494:                                                if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
1.1.1.12  root     4495:                                                        KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile);
1.1.1.9   root     4496:                                        }
                   4497: 
1.1.1.7   root     4498:                                        if (CheckMountList ())
                   4499:                                                Mount (hwndDlg, 0, 0);
                   4500:                                }
                   4501:                                return 1;
                   4502:                        }
                   4503: 
                   4504:                        /* Right click and drag&drop operations */
1.1.1.13  root     4505: 
                   4506:                        switch (((NM_LISTVIEW *) lParam)->hdr.code)
1.1.1.7   root     4507:                        {
                   4508:                        case NM_RCLICK:
                   4509:                        case LVN_BEGINRDRAG:
                   4510:                                /* If the mouse was moving while the right mouse button is pressed, popup menu would
                   4511:                                not open, because drag&drop operation would be initiated. Therefore, we're handling
                   4512:                                RMB drag-and-drop operations as well. */
                   4513:                                {
                   4514: 
                   4515:                                        /* Drive list context menu */
                   4516: 
                   4517:                                        int menuItem;
                   4518:                                        HMENU popup = CreatePopupMenu ();
                   4519: 
                   4520:                                        SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
                   4521: 
1.1.1.13  root     4522:                                        switch (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))))
1.1.1.7   root     4523:                                        {
1.1.1.13  root     4524:                                        case TC_MLIST_ITEM_FREE:
                   4525:                                        
1.1.1.7   root     4526:                                                // No mounted volume at this drive letter
1.1.1.13  root     4527: 
1.1.1.7   root     4528:                                                AppendMenuW (popup, MF_STRING, IDM_MOUNT_VOLUME, GetString ("IDM_MOUNT_VOLUME"));
1.1.1.13  root     4529:                                                break;
                   4530: 
                   4531:                                        case TC_MLIST_ITEM_NONSYS_VOL:
                   4532: 
                   4533:                                                // There's a mounted non-system volume at this drive letter
                   4534: 
1.1.1.7   root     4535:                                                AppendMenuW (popup, MF_STRING, IDM_UNMOUNT_VOLUME, GetString ("DISMOUNT"));
                   4536:                                                AppendMenuW (popup, MF_STRING, IDPM_OPEN_VOLUME, GetString ("OPEN"));
                   4537:                                                AppendMenu (popup, MF_SEPARATOR, 0, NULL);
                   4538:                                                AppendMenuW (popup, MF_STRING, IDPM_CHECK_FILESYS, GetString ("IDPM_CHECK_FILESYS"));
                   4539:                                                AppendMenuW (popup, MF_STRING, IDPM_REPAIR_FILESYS, GetString ("IDPM_REPAIR_FILESYS"));
                   4540:                                                AppendMenu (popup, MF_SEPARATOR, 0, NULL);
                   4541:                                                AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES"));
1.1.1.13  root     4542:                                                break;
                   4543: 
                   4544:                                        case TC_MLIST_ITEM_SYS_PARTITION:
                   4545:                                        case TC_MLIST_ITEM_SYS_DRIVE:
                   4546: 
                   4547:                                                // System partition/drive
                   4548: 
                   4549:                                                PopulateSysEncContextMenu (popup, FALSE);
                   4550:                                                break;
1.1.1.7   root     4551:                                        }
                   4552: 
                   4553:                                        mPos=GetMessagePos();
                   4554: 
                   4555:                                        menuItem = TrackPopupMenu (popup,
                   4556:                                                TPM_RETURNCMD | TPM_LEFTBUTTON,
                   4557:                                                GET_X_LPARAM(mPos),
                   4558:                                                GET_Y_LPARAM(mPos),
                   4559:                                                0,
                   4560:                                                hwndDlg,
                   4561:                                                NULL);
                   4562: 
                   4563:                                        DestroyMenu (popup);
                   4564: 
                   4565:                                        switch (menuItem)
                   4566:                                        {
                   4567:                                        case IDPM_CHECK_FILESYS:
                   4568:                                        case IDPM_REPAIR_FILESYS:
                   4569:                                                {
                   4570:                                                        LPARAM lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
                   4571: 
                   4572:                                                        if (LOWORD (lLetter) != 0xffff)
                   4573:                                                        {
                   4574:                                                                wchar_t msg[1024], param[1024];
                   4575:                                                                char szTmp[32] = {0};
                   4576: 
                   4577:                                                                sprintf (szTmp, "%c:", (char) HIWORD (lLetter));
                   4578:                                                                
                   4579:                                                                wsprintfW (msg, 
                   4580:                                                                        GetString (menuItem == IDPM_REPAIR_FILESYS ? "REPAIRING_FS" : "CHECKING_FS")
                   4581:                                                                        , szTmp);
                   4582: 
                   4583:                                                                wsprintfW (param, 
                   4584:                                                                        menuItem == IDPM_REPAIR_FILESYS ? 
1.1.1.13  root     4585:                                                                                L"/C echo %s & chkdsk %hs /F /X & pause"
                   4586:                                                                                : L"/C echo %s & chkdsk %hs & pause",
1.1.1.7   root     4587:                                                                        msg,
1.1.1.8   root     4588:                                                                        szTmp);
1.1.1.7   root     4589: 
1.1.1.11  root     4590:                                                                ShellExecuteW (NULL, 
                   4591:                                                                        (!IsAdmin() && IsUacSupported()) ? L"runas" : L"open",
                   4592:                                                                        L"cmd.exe", param, NULL, SW_SHOW);
1.1.1.7   root     4593:                                                        }
                   4594:                                                }
                   4595:                                                break;
                   4596: 
                   4597:                                        case IDM_UNMOUNT_VOLUME:
                   4598:                                                if (CheckMountList ())
                   4599:                                                        Dismount (hwndDlg, 0);
                   4600:                                                break;
                   4601: 
                   4602:                                        case IDPM_OPEN_VOLUME:
                   4603:                                                {
                   4604:                                                        int state = GetItemLong(GetDlgItem (hwndDlg, IDC_DRIVELIST), ((LPNMITEMACTIVATE)lParam)->iItem );
                   4605:                                                        nSelectedDriveIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
                   4606: 
1.1.1.11  root     4607:                                                        WaitCursor ();
1.1.1.7   root     4608:                                                        OpenVolumeExplorerWindow (HIWORD(state) - 'A');
                   4609:                                                        NormalCursor ();
                   4610:                                                }
                   4611:                                                break;
                   4612: 
                   4613:                                        case IDM_VOLUME_PROPERTIES:
                   4614:                                                DialogBoxParamW (hInst, 
                   4615:                                                        MAKEINTRESOURCEW (IDD_VOLUME_PROPERTIES), hwndDlg,
1.1.1.13  root     4616:                                                        (DLGPROC) VolumePropertiesDlgProc, (LPARAM) FALSE);
1.1.1.7   root     4617:                                                break;
                   4618: 
                   4619:                                        case IDM_MOUNT_VOLUME:
                   4620:                                                if (!VolumeSelected(hwndDlg))
                   4621:                                                {
                   4622:                                                        Warning ("NO_VOLUME_SELECTED");
                   4623:                                                }
                   4624:                                                else
                   4625:                                                {
                   4626:                                                        mountOptions = defaultMountOptions;
                   4627: 
                   4628:                                                        if (CheckMountList ())
                   4629:                                                                Mount (hwndDlg, 0, 0);
                   4630:                                                }
                   4631:                                                break;
1.1.1.13  root     4632:                                        case IDM_ENCRYPT_SYSTEM_DEVICE:
                   4633:                                                EncryptSystemDevice ();
                   4634:                                                break;
                   4635:                                        case IDM_PERMANENTLY_DECRYPT_SYS:
                   4636:                                                DecryptSystemDevice ();
                   4637:                                                break;
                   4638:                                        case IDM_SYSENC_RESUME:
                   4639:                                                ResumeInterruptedSysEncProcess ();
                   4640:                                                break;
                   4641:                                        case IDM_CHANGE_SYS_PASSWORD:
                   4642:                                                ChangeSysEncPassword (hwndDlg, FALSE);
                   4643:                                                break;
                   4644:                                        case IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO:
                   4645:                                                ChangeSysEncPassword (hwndDlg, TRUE);
                   4646:                                                break;
                   4647:                                        case IDM_CREATE_RESCUE_DISK:
                   4648:                                                CreateRescueDisk ();
                   4649:                                                break;
                   4650:                                        case IDM_VERIFY_RESCUE_DISK:
                   4651:                                                VerifyRescueDisk ();
                   4652:                                                break;
1.1.1.7   root     4653:                                        }
                   4654:                                        return 1;
                   4655:                                }
1.1       root     4656:                        }
                   4657:                }
                   4658:                return 0;
                   4659: 
                   4660:        case WM_ERASEBKGND:
                   4661:                return 0;
                   4662: 
                   4663:        case WM_COMMAND:
                   4664: 
1.1.1.13  root     4665:                if (lw == IDCANCEL || lw == IDC_EXIT)
1.1       root     4666:                {
                   4667:                        EndMainDlg (hwndDlg);
                   4668:                        return 1;
                   4669:                }
                   4670: 
                   4671:                if (lw == IDHELP || lw == IDM_HELP)
                   4672:                {
1.1.1.7   root     4673:                        OpenPageHelp (hwndDlg, 0);
1.1       root     4674:                        return 1;
                   4675:                }
                   4676: 
1.1.1.12  root     4677:                if (lw == IDM_ABOUT || lw == IDC_LOGO)
1.1       root     4678:                {
1.1.1.7   root     4679:                        DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1       root     4680:                        return 1;
                   4681:                }
                   4682: 
1.1.1.13  root     4683:                if (lw == IDOK && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == TC_MLIST_ITEM_NONSYS_VOL
1.1.1.7   root     4684:                        || lw == IDM_UNMOUNT_VOLUME)
1.1       root     4685:                {
1.1.1.13  root     4686:                        if (lw == IDM_UNMOUNT_VOLUME && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) != TC_MLIST_ITEM_NONSYS_VOL)
1.1.1.6   root     4687:                        {
1.1.1.7   root     4688:                                Warning ("SELECT_A_MOUNTED_VOLUME");
                   4689:                                return 1;
1.1.1.6   root     4690:                        }
1.1       root     4691: 
1.1.1.7   root     4692:                        if (CheckMountList ())
                   4693:                                Dismount (hwndDlg, 0);
1.1       root     4694:                        return 1;
                   4695:                }
                   4696: 
1.1.1.7   root     4697:                if ((lw == IDOK || lw == IDM_MOUNT_VOLUME || lw == IDM_MOUNT_VOLUME_OPTIONS || lw == IDC_MOUNTALL || lw == IDM_MOUNTALL) 
1.1       root     4698:                        && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == 0xffff)
                   4699:                {
1.1.1.7   root     4700:                        MessageBoxW (hwndDlg, GetString ("SELECT_FREE_DRIVE"), L"TrueCrypt", MB_ICONEXCLAMATION);
1.1       root     4701:                        return 1;
                   4702:                }
                   4703: 
1.1.1.7   root     4704:                if ((lw == IDOK || lw == IDM_MOUNT_VOLUME || lw == IDM_MOUNT_VOLUME_OPTIONS))
1.1       root     4705:                {
1.1.1.7   root     4706:                        if (!VolumeSelected(hwndDlg))
                   4707:                        {
                   4708:                                Warning ("NO_VOLUME_SELECTED");
                   4709:                        }
1.1.1.13  root     4710:                        else if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == TC_MLIST_ITEM_FREE)
1.1.1.7   root     4711:                        {
                   4712:                                mountOptions = defaultMountOptions;
                   4713: 
                   4714:                                if (lw == IDM_MOUNT_VOLUME_OPTIONS || GetAsyncKeyState (VK_CONTROL) < 0)
                   4715:                                {
                   4716:                                        if (IDCANCEL == DialogBoxParamW (hInst, 
                   4717:                                                MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
                   4718:                                                (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions))
                   4719:                                                return 1;
                   4720: 
                   4721:                                        if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
1.1.1.12  root     4722:                                                KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile);
1.1.1.7   root     4723:                                }
                   4724: 
                   4725:                                if (CheckMountList ())
                   4726:                                        Mount (hwndDlg, 0, 0);
                   4727:                        }
1.1.1.13  root     4728:                        else
                   4729:                                Warning ("SELECT_FREE_DRIVE");
1.1       root     4730:                        return 1;
                   4731:                }
                   4732: 
1.1.1.7   root     4733:                if (lw == IDC_UNMOUNTALL || lw == IDM_UNMOUNTALL)
1.1       root     4734:                {
1.1.1.7   root     4735:                        DismountAll (hwndDlg, bForceUnmount, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1       root     4736:                        return 1;
                   4737:                }
                   4738: 
1.1.1.7   root     4739:                if (lw == IDC_MOUNTALL || lw == IDM_MOUNTALL)
1.1       root     4740:                {
1.1.1.7   root     4741:                        // If Shift key is down and the password cache isn't empty, bypass password prompt
                   4742:                        MountAllDevices (hwndDlg, !(GetAsyncKeyState (VK_SHIFT) < 0 && !IsPasswordCacheEmpty()));
1.1       root     4743:                        return 1;
                   4744:                }
                   4745:                
1.1.1.7   root     4746:                if (lw == IDC_SELECT_FILE || lw == IDM_SELECT_FILE)
1.1       root     4747:                {
                   4748:                        SelectContainer (hwndDlg);
                   4749:                        return 1;
                   4750:                }
                   4751: 
1.1.1.7   root     4752:                if (lw == IDC_SELECT_DEVICE || lw == IDM_SELECT_DEVICE)
1.1       root     4753:                {
                   4754:                        SelectPartition (hwndDlg);
                   4755:                        return 1;
                   4756:                }
                   4757: 
1.1.1.13  root     4758:                // System Encryption menu
                   4759:                switch (lw)
                   4760:                {
                   4761:                case IDM_ENCRYPT_SYSTEM_DEVICE:
                   4762:                        EncryptSystemDevice ();
                   4763:                        break;
                   4764:                case IDM_PERMANENTLY_DECRYPT_SYS:
                   4765:                        DecryptSystemDevice ();
                   4766:                        break;
                   4767:                case IDM_SYSENC_RESUME:
                   4768:                        ResumeInterruptedSysEncProcess ();
                   4769:                        break;
                   4770:                case IDM_SYSTEM_ENCRYPTION_STATUS:
                   4771:                        ShowSystemEncryptionStatus ();
                   4772:                        break;
                   4773:                case IDM_CHANGE_SYS_PASSWORD:
                   4774:                        ChangeSysEncPassword (hwndDlg, FALSE);
                   4775:                        break;
                   4776:                case IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO:
                   4777:                        ChangeSysEncPassword (hwndDlg, TRUE);
                   4778:                        break;
                   4779:                case IDM_CREATE_RESCUE_DISK:
                   4780:                        CreateRescueDisk ();
                   4781:                        break;
                   4782:                case IDM_VERIFY_RESCUE_DISK:
                   4783:                        VerifyRescueDisk ();
                   4784:                        break;
                   4785:                }
                   4786: 
1.1.1.7   root     4787:                if (lw == IDC_VOLUME_TOOLS)
                   4788:                {
1.1.1.13  root     4789:                        /* Volume Tools popup menu */
                   4790: 
1.1.1.7   root     4791:                        int menuItem;
                   4792:                        char volPath[TC_MAX_PATH];              /* Volume to mount */
                   4793:                        HMENU popup = CreatePopupMenu ();
                   4794:                        RECT rect;
                   4795: 
1.1.1.13  root     4796:                        if (ActiveSysEncDeviceSelected ())
                   4797:                        {
                   4798:                                PopulateSysEncContextMenu (popup, TRUE);
                   4799:                        }
                   4800:                        else
                   4801:                        {
                   4802:                                AppendMenuW (popup, MF_STRING, IDM_CHANGE_PASSWORD, GetString ("IDM_CHANGE_PASSWORD"));
                   4803:                                AppendMenuW (popup, MF_STRING, IDM_CHANGE_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_HEADER_KEY_DERIV_ALGO"));
                   4804:                                AppendMenu (popup, MF_SEPARATOR, 0, NULL);
                   4805:                                AppendMenuW (popup, MF_STRING, IDM_BACKUP_VOL_HEADER, GetString ("IDM_BACKUP_VOL_HEADER"));
                   4806:                                AppendMenuW (popup, MF_STRING, IDM_RESTORE_VOL_HEADER, GetString ("IDM_RESTORE_VOL_HEADER"));
                   4807:                        }
1.1.1.7   root     4808: 
                   4809:                        GetWindowRect (GetDlgItem (hwndDlg, IDC_VOLUME_TOOLS), &rect);
                   4810: 
                   4811:                        menuItem = TrackPopupMenu (popup,
                   4812:                                TPM_RETURNCMD | TPM_LEFTBUTTON,
                   4813:                                rect.left + 2,
                   4814:                                rect.top + 2,
                   4815:                                0,
                   4816:                                hwndDlg,
                   4817:                                NULL);
                   4818: 
                   4819:                        DestroyMenu (popup);
                   4820: 
                   4821:                        switch (menuItem)
                   4822:                        {
                   4823:                        case IDM_CHANGE_PASSWORD:
                   4824:                                if (!VolumeSelected(hwndDlg))
                   4825:                                {
                   4826:                                        Warning ("NO_VOLUME_SELECTED");
                   4827:                                }
                   4828:                                else
                   4829:                                {
                   4830:                                        pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
                   4831:                                        ChangePassword (hwndDlg);
                   4832:                                }
                   4833:                                break;
                   4834: 
                   4835:                        case IDM_CHANGE_HEADER_KEY_DERIV_ALGO:
                   4836:                                if (!VolumeSelected(hwndDlg))
                   4837:                                {
                   4838:                                        Warning ("NO_VOLUME_SELECTED");
                   4839:                                }
                   4840:                                else
                   4841:                                {
                   4842:                                        pwdChangeDlgMode = PCDM_CHANGE_PKCS5_PRF;
                   4843:                                        ChangePassword (hwndDlg);
                   4844:                                }
                   4845:                                break;
                   4846: 
                   4847:                        case IDM_BACKUP_VOL_HEADER:
                   4848:                                if (!VolumeSelected(hwndDlg))
                   4849:                                {
                   4850:                                        Warning ("NO_VOLUME_SELECTED");
                   4851:                                }
                   4852:                                else
                   4853:                                {
                   4854:                                        GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
                   4855: 
1.1.1.11  root     4856:                                        if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
                   4857:                                                UacBackupVolumeHeader (hwndDlg, TRUE, volPath);
                   4858:                                        else
                   4859:                                                BackupVolumeHeader (hwndDlg, TRUE, volPath);
1.1.1.7   root     4860:                                }
                   4861:                                break;
                   4862: 
                   4863:                        case IDM_RESTORE_VOL_HEADER:
                   4864:                                if (!VolumeSelected(hwndDlg))
                   4865:                                {
                   4866:                                        Warning ("NO_VOLUME_SELECTED");
                   4867:                                }
                   4868:                                else
                   4869:                                {
                   4870:                                        GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
                   4871: 
1.1.1.11  root     4872:                                        if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
                   4873:                                                UacRestoreVolumeHeader (hwndDlg, volPath);
                   4874:                                        else
                   4875:                                                RestoreVolumeHeader (hwndDlg, volPath);
1.1.1.7   root     4876:                                }
                   4877:                                break;
1.1.1.13  root     4878: 
                   4879:                        case IDM_CHANGE_SYS_PASSWORD:
                   4880:                                ChangeSysEncPassword (hwndDlg, FALSE);
                   4881:                                break;
                   4882:                        case IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO:
                   4883:                                ChangeSysEncPassword (hwndDlg, TRUE);
                   4884:                                break;
                   4885:                        case IDM_CREATE_RESCUE_DISK:
                   4886:                                CreateRescueDisk ();
                   4887:                                break;
                   4888:                        case IDM_VERIFY_RESCUE_DISK:
                   4889:                                VerifyRescueDisk ();
                   4890:                                break;
1.1.1.7   root     4891:                        }
                   4892:                        return 1;
                   4893:                }
                   4894: 
                   4895:                if (lw == IDM_CHANGE_PASSWORD)
1.1       root     4896:                {
1.1.1.7   root     4897:                        if (!VolumeSelected(hwndDlg))
                   4898:                        {
                   4899:                                Warning ("NO_VOLUME_SELECTED");
                   4900:                        }
                   4901:                        else
                   4902:                        {
1.1.1.13  root     4903:                                if (ActiveSysEncDeviceSelected ())
                   4904:                                {
                   4905:                                        ChangeSysEncPassword (hwndDlg, FALSE);
                   4906:                                }
                   4907:                                else
                   4908:                                {
                   4909:                                        pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
                   4910:                                        ChangePassword (hwndDlg);
                   4911:                                }
1.1.1.7   root     4912:                        }
1.1       root     4913:                        return 1;
                   4914:                }
                   4915: 
1.1.1.7   root     4916:                if (lw == IDM_CHANGE_HEADER_KEY_DERIV_ALGO)
                   4917:                {
                   4918:                        if (!VolumeSelected(hwndDlg))
                   4919:                        {
                   4920:                                Warning ("NO_VOLUME_SELECTED");
                   4921:                        }
                   4922:                        else
                   4923:                        {
1.1.1.13  root     4924:                                if (ActiveSysEncDeviceSelected ())
                   4925:                                {
                   4926:                                        ChangeSysEncPassword (hwndDlg, TRUE);
                   4927:                                }
                   4928:                                else
                   4929:                                {
                   4930:                                        pwdChangeDlgMode = PCDM_CHANGE_PKCS5_PRF;
                   4931:                                        ChangePassword (hwndDlg);
                   4932:                                }
1.1.1.7   root     4933:                        }
                   4934:                        return 1;
                   4935:                }
                   4936: 
                   4937:                if (lw == IDC_WIPE_CACHE || lw == IDM_WIPE_CACHE)
1.1       root     4938:                {
                   4939:                        WipeCache (hwndDlg);
                   4940:                        return 1;
                   4941:                }
                   4942: 
1.1.1.7   root     4943:                if (lw == IDM_CLEAR_HISTORY)
1.1       root     4944:                {
1.1.1.11  root     4945:                        ClearHistory (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1       root     4946:                        EnableDisableButtons (hwndDlg);
                   4947:                        return 1;
                   4948:                }
                   4949: 
1.1.1.7   root     4950:                if (lw == IDC_CREATE_VOLUME || lw == IDM_CREATE_VOLUME || lw == IDM_VOLUME_WIZARD)
1.1       root     4951:                {
1.1.1.13  root     4952:                        LaunchVolCreationWizard (hwndDlg, "");
1.1       root     4953:                        return 1;
                   4954:                }
                   4955: 
1.1.1.7   root     4956:                if (lw == IDM_ADD_REMOVE_VOL_KEYFILES)
1.1.1.3   root     4957:                {
1.1.1.7   root     4958:                        if (!VolumeSelected(hwndDlg))
                   4959:                        {
                   4960:                                Warning ("NO_VOLUME_SELECTED");
                   4961:                        }
                   4962:                        else
                   4963:                        {
                   4964:                                pwdChangeDlgMode = PCDM_ADD_REMOVE_VOL_KEYFILES;
                   4965:                                ChangePassword (hwndDlg);
                   4966:                        }
                   4967:                        return 1;
                   4968:                }
1.1.1.3   root     4969: 
1.1.1.7   root     4970:                if (lw == IDM_REMOVE_ALL_KEYFILES_FROM_VOL)
                   4971:                {
                   4972:                        if (!VolumeSelected(hwndDlg))
1.1.1.3   root     4973:                        {
1.1.1.7   root     4974:                                Warning ("NO_VOLUME_SELECTED");
                   4975:                        }
                   4976:                        else
                   4977:                        {               
                   4978:                                pwdChangeDlgMode = PCDM_REMOVE_ALL_KEYFILES_FROM_VOL;
                   4979:                                ChangePassword (hwndDlg);
1.1.1.3   root     4980:                        }
                   4981:                        return 1;
                   4982:                }
1.1.1.7   root     4983: 
                   4984:                if (lw == IDM_GENERATE_KEYFILE || lw == IDM_KEYFILE_GENERATOR)
                   4985:                {
                   4986:                        DialogBoxParamW (hInst, 
                   4987:                                MAKEINTRESOURCEW (IDD_KEYFILE_GENERATOR), hwndDlg,
                   4988:                                (DLGPROC) KeyfileGeneratorDlgProc, (LPARAM) 0);
                   4989: 
                   4990:                                return 1;
                   4991:                }
                   4992: 
                   4993:                if (lw == IDM_LICENSE)
                   4994:                {
1.1.1.13  root     4995:                        TextInfoDialogBox (TC_TBXID_LEGAL_NOTICES);
1.1.1.7   root     4996:                        return 1;
                   4997:                }
1.1.1.3   root     4998:        
1.1.1.11  root     4999:                if (lw == IDM_WEBSITE)
1.1.1.7   root     5000:                {
1.1.1.11  root     5001:                        Applink ("website", TRUE, "");
                   5002:                        return 1;
                   5003:                }
                   5004:                else if (lw == IDM_HOMEPAGE)
                   5005:                {
                   5006:                        Applink ("homepage", TRUE, "");
1.1.1.7   root     5007:                        return 1;
                   5008:                }
                   5009:                else if (lw == IDM_FORUMS)
1.1       root     5010:                {
1.1.1.11  root     5011:                        Applink ("forum", TRUE, "");
1.1.1.5   root     5012:                        return 1;
                   5013:                }
1.1.1.9   root     5014:                else if (lw == IDM_ONLINE_TUTORIAL)
                   5015:                {
1.1.1.11  root     5016:                        Applink ("tutorial", TRUE, "");
1.1.1.9   root     5017:                        return 1;
                   5018:                }
                   5019:                else if (lw == IDM_ONLINE_HELP)
                   5020:                {
1.1.1.10  root     5021:                        OpenOnlineHelp ();
1.1.1.9   root     5022:                        return 1;
                   5023:                }
1.1.1.7   root     5024:                else if (lw == IDM_FAQ)
                   5025:                {
1.1.1.11  root     5026:                        Applink ("faq", TRUE, "");
1.1.1.7   root     5027:                        return 1;
                   5028:                }
                   5029:                else if (lw == IDM_TC_DOWNLOADS)
1.1.1.5   root     5030:                {
1.1.1.11  root     5031:                        Applink ("downloads", TRUE, "");
1.1       root     5032:                        return 1;
                   5033:                }
1.1.1.7   root     5034:                else if (lw == IDM_NEWS)
                   5035:                {
1.1.1.11  root     5036:                        Applink ("news", TRUE, "");
1.1.1.7   root     5037:                        return 1;
                   5038:                }
                   5039:                else if (lw == IDM_VERSION_HISTORY)
1.1.1.6   root     5040:                {
1.1.1.11  root     5041:                        Applink ("history", TRUE, "");
1.1.1.6   root     5042:                        return 1;
                   5043:                }
1.1.1.7   root     5044:                else if (lw == IDM_BUGREPORT)
                   5045:                {
1.1.1.11  root     5046:                        Applink ("bugreport", TRUE, "");
                   5047:                        return 1;
                   5048:                }
                   5049:                else if (lw == IDM_DONATIONS)
                   5050:                {
                   5051:                        Applink ("donations", FALSE, "");
1.1.1.7   root     5052:                        return 1;
                   5053:                }
                   5054:                else if (lw == IDM_CONTACT)
1.1       root     5055:                {
1.1.1.11  root     5056:                        Applink ("contact", FALSE, "");
1.1.1.7   root     5057:                        return 1;
                   5058:                }
                   5059: 
                   5060:                if (lw == IDM_PREFERENCES)
                   5061:                {
                   5062:                        if (IDOK == DialogBoxParamW (hInst, 
                   5063:                                MAKEINTRESOURCEW (IDD_PREFERENCES_DLG), hwndDlg,
                   5064:                                (DLGPROC) PreferencesDlgProc, (LPARAM) 0))
                   5065:                        {
                   5066:                                if (bEnableBkgTask)
1.1.1.12  root     5067:                                {
1.1.1.7   root     5068:                                        TaskBarIconAdd (hwndDlg);
1.1.1.12  root     5069:                                }
1.1.1.7   root     5070:                                else
1.1.1.12  root     5071:                                {
1.1.1.7   root     5072:                                        TaskBarIconRemove (hwndDlg);
1.1.1.13  root     5073:                                        if (MainWindowHidden)
1.1.1.12  root     5074:                                                EndMainDlg (hwndDlg);
                   5075:                                }
1.1.1.7   root     5076:                        }
                   5077:                        return 1;
                   5078:                }
                   5079: 
                   5080:                if (lw == IDM_HOTKEY_SETTINGS)
                   5081:                {
                   5082:                        DialogBoxParamW (hInst, 
                   5083:                                MAKEINTRESOURCEW (IDD_HOTKEYS_DLG), hwndDlg,
                   5084:                                (DLGPROC) HotkeysDlgProc, (LPARAM) 0);
                   5085:                        return 1;
                   5086:                }
                   5087: 
                   5088:                if (lw == IDM_DEFAULT_KEYFILES || lw == IDM_SET_DEFAULT_KEYFILES)
                   5089:                {
                   5090:                        KeyfileDefaultsDlg (hwndDlg);
1.1       root     5091:                        return 1;
                   5092:                }
                   5093: 
1.1.1.7   root     5094:                if (lw == IDM_BENCHMARK)
1.1.1.5   root     5095:                {
                   5096:                        Benchmark (hwndDlg);
                   5097:                        return 1;
                   5098:                }
                   5099: 
1.1.1.13  root     5100:                if (lw == IDM_TRAVELER)
1.1.1.6   root     5101:                {
1.1.1.7   root     5102:                        DialogBoxParamW (hInst, 
1.1.1.13  root     5103:                                MAKEINTRESOURCEW (IDD_TRAVELER_DLG), hwndDlg,
                   5104:                                (DLGPROC) TravelerDlgProc, (LPARAM) 0);
1.1.1.6   root     5105:                        return 1;
                   5106:                }
                   5107: 
1.1.1.7   root     5108:                if (lw == IDM_BACKUP_VOL_HEADER)
                   5109:                {
                   5110:                        if (!VolumeSelected(hwndDlg))
                   5111:                        {
                   5112:                                Warning ("NO_VOLUME_SELECTED");
                   5113:                        }
                   5114:                        else
                   5115:                        {
                   5116:                                char volPath[TC_MAX_PATH];              /* Volume to mount */
                   5117: 
                   5118:                                GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
                   5119: 
1.1.1.11  root     5120:                                if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
                   5121:                                        UacBackupVolumeHeader (hwndDlg, TRUE, volPath);
                   5122:                                else
                   5123:                                        BackupVolumeHeader (hwndDlg, TRUE, volPath);
1.1.1.7   root     5124:                        }
                   5125:                        return 1;
                   5126:                }
                   5127: 
                   5128:                if (lw == IDM_RESTORE_VOL_HEADER)
                   5129:                {
                   5130:                        if (!VolumeSelected(hwndDlg))
                   5131:                        {
                   5132:                                Warning ("NO_VOLUME_SELECTED");
                   5133:                        }
                   5134:                        else
                   5135:                        {
                   5136:                                char volPath[TC_MAX_PATH];              /* Volume to mount */
                   5137: 
                   5138:                                GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
                   5139: 
1.1.1.11  root     5140:                                if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
                   5141:                                        UacRestoreVolumeHeader (hwndDlg, volPath);
                   5142:                                else
                   5143:                                        RestoreVolumeHeader (hwndDlg, volPath);
1.1.1.7   root     5144:                        }
                   5145:                        return 1;
                   5146:                }
                   5147: 
                   5148:                if (lw == IDM_LANGUAGE)
                   5149:                {
                   5150:                        BOOL p;
                   5151:                        if (DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_LANGUAGE), hwndDlg,
                   5152:                                (DLGPROC) LanguageDlgProc, (LPARAM) 0) == IDOK)
                   5153:                        {
                   5154:                                LoadLanguageFile ();
                   5155:                                SaveSettings (hwndDlg);
                   5156: 
                   5157:                                p = LocalizationActive;
                   5158:                                LocalizationActive = TRUE;
                   5159:                                InitMainDialog (hwndDlg);
                   5160:                                InvalidateRect (hwndDlg, NULL, FALSE);
                   5161:                                LocalizationActive = p;
                   5162:                                DrawMenuBar (hwndDlg);
                   5163:                        }
                   5164:                        return 1;
                   5165:                }
                   5166: 
                   5167:                if (lw == IDM_TEST_VECTORS)
                   5168:                {
                   5169:                        DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_CIPHER_TEST_DLG), hwndDlg, (DLGPROC) CipherTestDialogProc, (LPARAM) 1);
                   5170:                        return 1;
                   5171:                }
                   5172: 
1.1.1.6   root     5173:                if (lw == IDM_REFRESH_DRIVE_LETTERS)
                   5174:                {
                   5175:                        DWORD driveMap = GetLogicalDrives ();
                   5176:                        
1.1.1.11  root     5177:                        WaitCursor ();
1.1.1.7   root     5178: 
1.1.1.10  root     5179:                        if (!(nCurrentOS == WIN_2000 && RemoteSession))
                   5180:                        {
                   5181:                                BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, ~driveMap);
                   5182:                                Sleep (100);
                   5183:                                BroadcastDeviceChange (DBT_DEVICEARRIVAL, 0, driveMap);
                   5184:                        }
1.1.1.7   root     5185: 
1.1.1.6   root     5186:                        LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
1.1.1.7   root     5187: 
                   5188:                        if (nSelectedDriveIndex >= 0)
                   5189:                        {
                   5190:                                SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST),
                   5191:                                        (char) HIWORD (GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), nSelectedDriveIndex)));
                   5192:                        }
                   5193: 
1.1.1.6   root     5194:                        NormalCursor ();
1.1.1.7   root     5195:                        return 1;
                   5196:                }
                   5197: 
                   5198:                if (lw == IDM_MOUNT_FAVORITE_VOLUMES)
                   5199:                {
                   5200:                        MountFavoriteVolumes ();
                   5201:                        return 1;
                   5202:                }
                   5203: 
                   5204:                if (lw == IDM_SAVE_FAVORITE_VOLUMES)
                   5205:                {
                   5206:                        SaveFavoriteVolumes ();
                   5207:                        return 1;
1.1.1.6   root     5208:                }
1.1.1.5   root     5209: 
1.1.1.7   root     5210:                if (lw == IDC_VOLUME_PROPERTIES || lw == IDM_VOLUME_PROPERTIES)
1.1       root     5211:                {
1.1.1.7   root     5212:                        DialogBoxParamW (hInst, 
                   5213:                                MAKEINTRESOURCEW (IDD_VOLUME_PROPERTIES), hwndDlg,
1.1       root     5214:                                (DLGPROC) VolumePropertiesDlgProc, (LPARAM) 0);
                   5215:                        return 1;
                   5216:                }
                   5217: 
                   5218:                if (lw == IDC_VOLUME && hw == CBN_EDITCHANGE)
                   5219:                {
1.1.1.5   root     5220:                        EnableDisableButtons (hwndDlg);
1.1       root     5221:                        return 1;
                   5222:                }
                   5223: 
                   5224:                if (lw == IDC_VOLUME && hw == CBN_SELCHANGE)
                   5225:                {
                   5226:                        UpdateComboOrder (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.10  root     5227:                        MoveEditToCombo ((HWND) lParam, bHistory);
1.1.1.13  root     5228:                        PostMessage (hwndDlg, TC_APPMSG_MOUNT_ENABLE_DISABLE_CONTROLS, 0, 0);
1.1.1.5   root     5229:                        return 1;
                   5230:                }
                   5231: 
                   5232:                if (lw == IDC_NO_HISTORY)
                   5233:                {
1.1.1.11  root     5234:                        if (!(bHistory = !IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY))))
                   5235:                                ClearHistory (GetDlgItem (hwndDlg, IDC_VOLUME));
                   5236: 
1.1       root     5237:                        return 1;
                   5238:                }
                   5239: 
                   5240:                return 0;
                   5241: 
1.1.1.6   root     5242:        case WM_DROPFILES:
                   5243:                {
                   5244:                        HDROP hdrop = (HDROP) wParam;
                   5245:                        DragQueryFile (hdrop, 0, szFileName, sizeof szFileName);
                   5246:                        DragFinish (hdrop);
                   5247: 
1.1.1.10  root     5248:                        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.6   root     5249:                        EnableDisableButtons (hwndDlg);
                   5250:                        SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
                   5251:                }
1.1.1.7   root     5252:                return 1;
1.1.1.6   root     5253: 
1.1.1.13  root     5254:        case TC_APPMSG_MOUNT_ENABLE_DISABLE_CONTROLS:
1.1       root     5255:                EnableDisableButtons (hwndDlg);
                   5256:                return 1;
                   5257: 
1.1.1.13  root     5258:        case TC_APPMSG_MOUNT_SHOW_WINDOW:
1.1.1.8   root     5259:                MainWindowHidden = FALSE;
1.1.1.13  root     5260:                ShowWindow (hwndDlg, SW_SHOW);
                   5261:                ShowWindow (hwndDlg, SW_RESTORE);
1.1.1.8   root     5262:                return 1;
                   5263: 
                   5264:        case WM_COPYDATA:
                   5265:                {
                   5266:                        PCOPYDATASTRUCT cd = (PCOPYDATASTRUCT)lParam;
                   5267:                        if (memcmp (&cd->dwData, WM_COPY_SET_VOLUME_NAME, 4) == 0)
                   5268:                        {
                   5269:                                if (cd->cbData > 0)
1.1.1.10  root     5270:                                        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), (char *)cd->lpData, bHistory);
1.1.1.8   root     5271: 
                   5272:                                EnableDisableButtons (hwndDlg);
                   5273:                                SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
                   5274:                        }
                   5275:                }
                   5276:                return 1;
                   5277: 
1.1       root     5278:        case WM_CLOSE:
                   5279:                EndMainDlg (hwndDlg);
                   5280:                return 1;
1.1.1.11  root     5281: 
                   5282:        default:
                   5283:                // Recreate tray icon if Explorer restarted
                   5284:                if (taskBarCreatedMsg != 0 && uMsg == taskBarCreatedMsg && TaskBarIconMutex != NULL)
                   5285:                {
                   5286:                        TaskBarIconRemove (hwndDlg);
                   5287:                        TaskBarIconAdd (hwndDlg);
                   5288:                        return 1;
                   5289:                }
1.1       root     5290:        }
                   5291: 
                   5292:        return 0;
                   5293: }
                   5294: 
                   5295: void
                   5296: ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
                   5297: {
                   5298:        char **lpszCommandLineArgs;     /* Array of command line arguments */
                   5299:        int nNoCommandLineArgs; /* The number of arguments in the array */
1.1.1.7   root     5300:        char tmpPath[MAX_PATH * 2];
                   5301: 
                   5302:        /* Defaults */
                   5303:        mountOptions.PreserveTimestamp = TRUE;
1.1.1.11  root     5304:        
                   5305:        if (_stricmp (lpszCommandLine, "-Embedding") == 0)
                   5306:        {
                   5307:                ComServerMode = TRUE;
                   5308:                return;
                   5309:        }
1.1       root     5310: 
                   5311:        /* Extract command line arguments */
1.1.1.8   root     5312:        NoCmdLineArgs = nNoCommandLineArgs = Win32CommandLine (lpszCommandLine, &lpszCommandLineArgs);
1.1.1.11  root     5313: 
1.1       root     5314:        if (nNoCommandLineArgs > 0)
                   5315:        {
                   5316:                int i;
                   5317: 
                   5318:                for (i = 0; i < nNoCommandLineArgs; i++)
                   5319:                {
                   5320:                        argument args[]=
                   5321:                        {
                   5322:                                {"/auto", "/a"},
1.1.1.5   root     5323:                                {"/beep", "/b"},
1.1       root     5324:                                {"/cache", "/c"},
1.1.1.5   root     5325:                                {"/dismount", "/d"},
                   5326:                                {"/explore", "/e"},
                   5327:                                {"/force", "/f"},
                   5328:                                {"/help", "/?"},
1.1       root     5329:                                {"/history", "/h"},
1.1.1.7   root     5330:                                {"/keyfile", "/k"},
1.1.1.5   root     5331:                                {"/letter", "/l"},
1.1.1.6   root     5332:                                {"/mountoption", "/m"},
1.1.1.5   root     5333:                                {"/password", "/p"},
1.1.1.7   root     5334:                                {"/quit", "/q"},
                   5335:                                {"/silent", "/s"},
1.1.1.5   root     5336:                                {"/volume", "/v"},
                   5337:                                {"/wipecache", "/w"}
1.1       root     5338:                        };
                   5339: 
                   5340:                        argumentspec as;
                   5341: 
                   5342:                        int nArgPos;
                   5343:                        int x;
                   5344: 
                   5345:                        as.args = args;
                   5346:                        as.arg_cnt = sizeof(args)/ sizeof(args[0]);
                   5347:                        
                   5348:                        x = GetArgumentID (&as, lpszCommandLineArgs[i], &nArgPos);
                   5349: 
                   5350:                        switch (x)
                   5351:                        {
1.1.1.7   root     5352:                        case 'a':
                   5353:                                {
                   5354:                                        char szTmp[32];
                   5355:                                        bAuto = TRUE;
1.1.1.2   root     5356: 
1.1.1.7   root     5357:                                        if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
                   5358:                                                nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
                   5359:                                        {
                   5360:                                                if (!_stricmp (szTmp, "devices"))
                   5361:                                                        bAutoMountDevices = TRUE;
                   5362:                                                else if (!_stricmp (szTmp, "favorites"))
                   5363:                                                        bAutoMountFavorites = TRUE;
                   5364:                                        }
                   5365:                                }
                   5366:                                break;
1.1.1.2   root     5367: 
1.1.1.7   root     5368:                        case 'b':
                   5369:                                bBeep = TRUE;
1.1       root     5370:                                break;
                   5371: 
1.1.1.7   root     5372:                        case 'c':
1.1.1.2   root     5373:                                {
1.1.1.7   root     5374:                                        char szTmp[8];
                   5375:                                        bCacheInDriver = TRUE;
                   5376: 
                   5377:                                        GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
                   5378:                                                     szTmp, sizeof (szTmp));
                   5379: 
                   5380:                                        if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
                   5381:                                                bCacheInDriver = FALSE;
1.1.1.2   root     5382:                                }
1.1       root     5383:                                break;
                   5384: 
1.1.1.7   root     5385:                        case 'd':
                   5386: 
                   5387:                                if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
                   5388:                                     szDriveLetter, sizeof (szDriveLetter)))
                   5389:                                        cmdUnmountDrive = toupper(szDriveLetter[0]) - 'A';
                   5390:                                else 
                   5391:                                        cmdUnmountDrive = -1;
                   5392: 
1.1       root     5393:                                break;
                   5394: 
                   5395:                        case 'e':
                   5396:                                bExplore = TRUE;
                   5397:                                break;
                   5398: 
1.1.1.5   root     5399:                        case 'f':
                   5400:                                bForceMount = TRUE;
                   5401:                                bForceUnmount = TRUE;
                   5402:                                break;
                   5403: 
1.1.1.7   root     5404:                        case 'k':
                   5405:                                if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i,
                   5406:                                        nNoCommandLineArgs, tmpPath, sizeof (tmpPath)))
                   5407:                                {
                   5408:                                        KeyFile *kf;
                   5409:                                        RelativePath2Absolute (tmpPath);
1.1.1.13  root     5410:                                        kf = (KeyFile *) malloc (sizeof (KeyFile));
1.1.1.7   root     5411:                                        strncpy (kf->FileName, tmpPath, sizeof (kf->FileName));
                   5412:                                        FirstCmdKeyFile = KeyFileAdd (FirstCmdKeyFile, kf);
                   5413:                                }
                   5414:                                break;
                   5415: 
                   5416:                        case 'l':
1.1.1.2   root     5417:                                GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
1.1.1.7   root     5418:                                        szDriveLetter, sizeof (szDriveLetter));
                   5419:                                commandLineDrive = *szDriveLetter = (char) toupper (*szDriveLetter);
1.1       root     5420:                                break;
                   5421: 
1.1.1.10  root     5422:                        case 'h':
1.1.1.6   root     5423:                                {
                   5424:                                        char szTmp[8];
1.1.1.7   root     5425:                                        bHistory = bHistoryCmdLine = TRUE;
1.1.1.6   root     5426: 
1.1.1.7   root     5427:                                        GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
                   5428:                                                     szTmp, sizeof (szTmp));
                   5429: 
                   5430:                                        if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
                   5431:                                                bHistory = FALSE;
1.1.1.6   root     5432:                                }
                   5433:                                break;
                   5434: 
                   5435:                        case 'm':
                   5436:                                {
1.1.1.7   root     5437:                                        char szTmp[16];
1.1.1.6   root     5438:                                        if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
                   5439:                                                nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
                   5440:                                        {
1.1.1.7   root     5441:                                                if (!_stricmp (szTmp, "ro") || !_stricmp (szTmp, "readonly"))
1.1.1.6   root     5442:                                                        mountOptions.ReadOnly = TRUE;
                   5443: 
1.1.1.7   root     5444:                                                if (!_stricmp (szTmp, "rm") || !_stricmp (szTmp, "removable"))
1.1.1.6   root     5445:                                                        mountOptions.Removable = TRUE;
1.1.1.7   root     5446: 
                   5447:                                                if (!_stricmp (szTmp, "ts") || !_stricmp (szTmp, "timestamp"))
                   5448:                                                        mountOptions.PreserveTimestamp = FALSE;
1.1.1.6   root     5449:                                        }
                   5450:                                }
1.1       root     5451:                                break;
                   5452: 
1.1.1.7   root     5453:                        case 'p':
                   5454:                                GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
1.1.1.13  root     5455:                                                     (char *) CmdVolumePassword.Text, sizeof (CmdVolumePassword.Text));
                   5456:                                CmdVolumePassword.Length = strlen ((char *) CmdVolumePassword.Text);
1.1.1.7   root     5457:                                CmdVolumePasswordValid = TRUE;
                   5458:                                break;
                   5459: 
                   5460:                        case 'v':
                   5461:                                if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i,
                   5462:                                                                      nNoCommandLineArgs, szFileName, sizeof (szFileName)))
1.1       root     5463:                                {
1.1.1.7   root     5464:                                        RelativePath2Absolute (szFileName);
1.1.1.10  root     5465:                                        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.8   root     5466:                                        CmdLineVolumeSpecified = TRUE;
1.1       root     5467:                                }
                   5468:                                break;
                   5469: 
1.1.1.7   root     5470:                        case 'q':
1.1       root     5471:                                {
1.1.1.7   root     5472:                                        char szTmp[32];
1.1       root     5473: 
1.1.1.7   root     5474:                                        if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
                   5475:                                                nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
1.1       root     5476:                                        {
1.1.1.12  root     5477:                                                if (!_stricmp (szTmp, "UAC")) // Used to indicate non-install elevation
                   5478:                                                        break;
                   5479: 
1.1.1.7   root     5480:                                                if (!_stricmp (szTmp, "preferences"))
1.1.1.12  root     5481:                                                {
                   5482:                                                        Quit = TRUE;
1.1.1.7   root     5483:                                                        UsePreferences = TRUE;
1.1.1.12  root     5484:                                                        break;
                   5485:                                                }
                   5486: 
                   5487:                                                if (!_stricmp (szTmp, "background"))
                   5488:                                                        bEnableBkgTask = TRUE;
1.1       root     5489:                                        }
1.1.1.12  root     5490: 
                   5491:                                        Quit = TRUE;
                   5492:                                        UsePreferences = FALSE;
1.1       root     5493:                                }
                   5494:                                break;
                   5495: 
1.1.1.7   root     5496:                        case 's':
                   5497:                                Silent = TRUE;
1.1       root     5498:                                break;
                   5499: 
1.1.1.7   root     5500:                        case 'w':
                   5501:                                bWipe = TRUE;
1.1       root     5502:                                break;
                   5503: 
                   5504:                        case '?':
1.1.1.7   root     5505:                                DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_COMMANDHELP_DLG), hwndDlg, (DLGPROC)
1.1       root     5506:                                                CommandHelpDlgProc, (LPARAM) &as);
                   5507:                                exit(0);
                   5508:                                break;
                   5509: 
                   5510:                                // no option = file name
                   5511:                        default:
1.1.1.2   root     5512:                                {
1.1.1.11  root     5513:                                        strncpy (szFileName, lpszCommandLineArgs[i], MAX_PATH-1);
1.1.1.2   root     5514:                                        if (szFileName[0] != '\\' && strchr (szFileName, ':') == 0)
                   5515:                                        {
                   5516:                                                char path[MAX_PATH*2];
                   5517:                                                GetCurrentDirectory (MAX_PATH, path);
                   5518:                                                strcat (path, "\\");
                   5519:                                                strcat (path, szFileName);
                   5520:                                                strncpy (szFileName, path, MAX_PATH-1);
                   5521:                                        }
1.1.1.8   root     5522: 
                   5523:                                        if (nNoCommandLineArgs == 1)
                   5524:                                                CmdLineVolumeSpecified = TRUE;
1.1.1.10  root     5525:                                        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.2   root     5526:                                }
1.1       root     5527:                        }
                   5528:                }
                   5529:        }
                   5530: 
                   5531:        /* Free up the command line arguments */
                   5532:        while (--nNoCommandLineArgs >= 0)
                   5533:        {
                   5534:                free (lpszCommandLineArgs[nNoCommandLineArgs]);
                   5535:        }
                   5536: }
                   5537: 
1.1.1.7   root     5538: 
1.1.1.13  root     5539: int WINAPI WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine, int nCmdShow)
1.1       root     5540: {
                   5541:        int status;
1.1.1.13  root     5542:        atexit (localcleanup);
                   5543: 
                   5544:        VirtualLock (&VolumePassword, sizeof (VolumePassword));
                   5545:        VirtualLock (&CmdVolumePassword, sizeof (CmdVolumePassword));
                   5546:        VirtualLock (&mountOptions, sizeof (mountOptions));
                   5547:        VirtualLock (&defaultMountOptions, sizeof (defaultMountOptions));
1.1       root     5548: 
1.1.1.13  root     5549:        try
                   5550:        {
                   5551:                BootEncObj = new BootEncryption (NULL);
                   5552:        }
                   5553:        catch (Exception &e)
                   5554:        {
                   5555:                e.Show (NULL);
                   5556:        }
1.1       root     5557: 
1.1.1.13  root     5558:        if (BootEncObj == NULL)
                   5559:                AbortProcess ("INIT_SYS_ENC");
1.1       root     5560: 
1.1.1.11  root     5561:        InitCommonControls ();
                   5562:        InitApp (hInstance, lpszCommandLine);
1.1       root     5563: 
1.1.1.7   root     5564:        RegisterRedTick(hInstance);
                   5565: 
                   5566:        /* Allocate, dup, then store away the application title */
                   5567:        lpszTitle = L"TrueCrypt";
                   5568: 
1.1       root     5569:        status = DriverAttach ();
                   5570:        if (status != 0)
                   5571:        {
                   5572:                if (status == ERR_OS_ERROR)
                   5573:                        handleWin32Error (NULL);
                   5574:                else
                   5575:                        handleError (NULL, status);
                   5576: 
1.1.1.7   root     5577:                AbortProcess ("NODRIVER");
1.1       root     5578:        }
                   5579: 
                   5580:        /* Create the main dialog box */
1.1.1.7   root     5581:        DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_MOUNT_DLG), NULL, (DLGPROC) MainDialogProc,
1.1       root     5582:                        (LPARAM) lpszCommandLine);
                   5583: 
                   5584:        /* Terminate */
                   5585:        return 0;
                   5586: }
1.1.1.6   root     5587: 
1.1.1.7   root     5588: 
                   5589: BOOL TaskBarIconAdd (HWND hwnd) 
                   5590: { 
                   5591:     BOOL res; 
                   5592:     NOTIFYICONDATAW tnid; 
                   5593:  
                   5594:        // Only one icon may be created
                   5595:        if (TaskBarIconMutex != NULL) return TRUE;
                   5596: 
                   5597:        TaskBarIconMutex = CreateMutex (NULL, TRUE, "TrueCryptTaskBarIcon");
                   5598:        if (TaskBarIconMutex == NULL || GetLastError () == ERROR_ALREADY_EXISTS)
                   5599:        {
                   5600:                TaskBarIconMutex = NULL;
                   5601:                return FALSE;
                   5602:        }
                   5603: 
                   5604:     tnid.cbSize = sizeof (NOTIFYICONDATAW); 
                   5605:     tnid.hWnd = hwnd; 
                   5606:     tnid.uID = IDI_TRUECRYPT_ICON; 
                   5607:     tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; 
1.1.1.13  root     5608:     tnid.uCallbackMessage = TC_APPMSG_TASKBAR_ICON; 
                   5609:        tnid.hIcon = (HICON) LoadImage (hInst, MAKEINTRESOURCE (IDI_TRUECRYPT_ICON), 
1.1.1.12  root     5610:                IMAGE_ICON, 
                   5611:                ScreenDPI >= 120 ? 0 : 16, 
                   5612:                ScreenDPI >= 120 ? 0 : 16,
                   5613:                (ScreenDPI >= 120 ? LR_DEFAULTSIZE : 0) 
                   5614:                | (nCurrentOS != WIN_2000 ? LR_DEFAULTCOLOR : LR_VGACOLOR)); // Windows 2000 cannot display more than 16 fixed colors in notification tray
                   5615: 
1.1.1.7   root     5616:        wcscpy (tnid.szTip, L"TrueCrypt");
                   5617:        
                   5618:        res = Shell_NotifyIconW (NIM_ADD, &tnid); 
                   5619:  
                   5620:     if (tnid.hIcon) 
                   5621:         DestroyIcon (tnid.hIcon); 
                   5622:  
                   5623:     return res; 
                   5624: }
                   5625: 
                   5626: 
                   5627: BOOL TaskBarIconRemove (HWND hwnd) 
                   5628: { 
                   5629:        if (TaskBarIconMutex != NULL)
                   5630:        {
                   5631:                NOTIFYICONDATA tnid; 
                   5632:                BOOL res;
                   5633: 
                   5634:                ZeroMemory (&tnid, sizeof (tnid));
                   5635:                tnid.cbSize = sizeof(NOTIFYICONDATA); 
                   5636:                tnid.hWnd = hwnd; 
                   5637:                tnid.uID = IDI_TRUECRYPT_ICON; 
                   5638: 
                   5639:                res = Shell_NotifyIcon (NIM_DELETE, &tnid);
                   5640:                if (TaskBarIconMutex)
                   5641:                {
                   5642:                        CloseHandle (TaskBarIconMutex);
                   5643:                        TaskBarIconMutex = NULL;
                   5644:                }
                   5645:                return res;
                   5646:        }
                   5647:        else
                   5648:                return FALSE;
                   5649: }
                   5650: 
                   5651: 
                   5652: void DismountIdleVolumes ()
                   5653: {
1.1.1.13  root     5654:        static DWORD lastMinTickCount;
1.1.1.7   root     5655:        static int InactivityTime[26];
                   5656:        static unsigned __int64 LastRead[26], LastWritten[26];
                   5657:        static int LastId[26];
                   5658: 
                   5659:        VOLUME_PROPERTIES_STRUCT prop;
                   5660:        DWORD dwResult;
                   5661:        BOOL bResult;
                   5662:        int i;
                   5663: 
1.1.1.13  root     5664:        if (GetTickCount() > lastMinTickCount && GetTickCount() - lastMinTickCount < 60 * 1000)
                   5665:                return;
                   5666:        
                   5667:        lastMinTickCount = GetTickCount();
1.1.1.7   root     5668: 
                   5669:        for (i = 0; i < 26; i++)
                   5670:        {
                   5671:                if (LastKnownMountList.ulMountedDrives & (1 << i))
                   5672:                {
                   5673:                        memset (&prop, 0, sizeof(prop));
                   5674:                        prop.driveNo = i;
                   5675: 
1.1.1.13  root     5676:                        bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop,
1.1.1.7   root     5677:                                sizeof (prop), &prop, sizeof (prop), &dwResult, NULL);
                   5678: 
                   5679:                        if (bResult)
                   5680:                        {
                   5681:                                if (LastRead[i] == prop.totalBytesRead 
                   5682:                                        && LastWritten[i] == prop.totalBytesWritten
                   5683:                                        && LastId[i] == prop.uniqueId)
                   5684:                                {
                   5685:                                        if (++InactivityTime[i] >= MaxVolumeIdleTime)
                   5686:                                        {
1.1.1.11  root     5687:                                                BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, i, 0);
                   5688: 
1.1.1.7   root     5689:                                                if (bCloseDismountedWindows && CloseVolumeExplorerWindows (MainDlg, i))
                   5690:                                                        Sleep (250);
                   5691: 
                   5692:                                                if (DriverUnmountVolume (MainDlg, i, bForceAutoDismount) == 0)
                   5693:                                                {
                   5694:                                                        InactivityTime[i] = 0;
                   5695:                                                        BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, i, 0);
                   5696: 
                   5697:                                                        if (bWipeCacheOnAutoDismount)
1.1.1.13  root     5698:                                                                DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.7   root     5699:                                                }
                   5700:                                        }
                   5701:                                }
                   5702:                                else
                   5703:                                {
                   5704:                                        InactivityTime[i] = 0;
                   5705:                                        LastRead[i] = prop.totalBytesRead;
                   5706:                                        LastWritten[i] = prop.totalBytesWritten;
                   5707:                                        LastId[i] = prop.uniqueId;
                   5708:                                }
                   5709:                        }
                   5710:                }
                   5711:        }
                   5712: }
                   5713: 
                   5714: 
                   5715: BOOL MountFavoriteVolumes ()
                   5716: {
                   5717:        BOOL status = TRUE;
                   5718:        DWORD size;
                   5719:        char *favorites = LoadFile (GetConfigPath (FILE_FAVORITE_VOLUMES), &size);
                   5720:        char *xml = favorites;
                   5721:        char mountPoint[MAX_PATH], volume[MAX_PATH];
                   5722: 
                   5723:        if (xml == NULL) return FALSE;
                   5724: 
1.1.1.11  root     5725:        mountOptions = defaultMountOptions;
                   5726: 
1.1.1.7   root     5727:        while (xml = XmlFindElement (xml, "volume"))
                   5728:        {
                   5729:                int drive;
1.1.1.11  root     5730:                XmlGetAttributeText (xml, "mountpoint", mountPoint, sizeof (mountPoint));
                   5731:                XmlGetNodeText (xml, volume, sizeof (volume));
1.1.1.7   root     5732:                drive = toupper (mountPoint[0]) - 'A';
                   5733: 
                   5734:                if ((LastKnownMountList.ulMountedDrives & (1 << drive)) == 0)
                   5735:                {
                   5736:                        if (!Mount (MainDlg, drive, volume))
                   5737:                                status = FALSE;
                   5738:                        LoadDriveLetters (GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
                   5739:                }
                   5740: 
                   5741:                xml++;
                   5742:        }
                   5743: 
                   5744:        free (favorites);
                   5745:        return status;
                   5746: }
                   5747: 
                   5748: 
                   5749: void SaveFavoriteVolumes ()
                   5750: {
                   5751:        if (AskNoYes("CONFIRM_SAVE_FAVORITE_VOL") == IDYES)
                   5752:        {
                   5753:                FILE *f;
                   5754:                int i, cnt = 0;
                   5755: 
                   5756:                f = fopen (GetConfigPath (FILE_FAVORITE_VOLUMES), "w");
                   5757:                if (f == NULL)
                   5758:                {
                   5759:                        handleWin32Error (MainDlg);
                   5760:                        return;
                   5761:                }
                   5762: 
                   5763:                XmlWriteHeader (f);
                   5764:                fputs ("\n\t<favorites>", f);
                   5765: 
                   5766:                for (i = 0; i < 26; i++)
                   5767:                {
                   5768:                        if (LastKnownMountList.ulMountedDrives & (1 << i))
                   5769:                        {
1.1.1.11  root     5770:                                char t[2048], tq[2048];
                   5771:                                
                   5772:                                sprintf_s (t, sizeof (t), "%ls", &LastKnownMountList.wszVolume[i][(LastKnownMountList.wszVolume[i][1] == L'?') ? 4 : 0]);
                   5773:                                XmlQuoteText (t, tq, sizeof (tq));
                   5774: 
                   5775:                                fprintf (f, "\n\t\t<volume mountpoint=\"%c:\\\">%s</volume>", i + 'A', tq);
1.1.1.7   root     5776:                                cnt++;
                   5777:                        }
                   5778:                }
                   5779: 
                   5780:                fputs ("\n\t</favorites>", f);
                   5781:                XmlWriteFooter (f);
                   5782:                fclose (f);
                   5783: 
                   5784:                if (cnt == 0)
                   5785:                        remove (GetConfigPath (FILE_FAVORITE_VOLUMES));         // No volumes to save as favorite
                   5786: 
                   5787:                Info ("FAVORITE_VOLUMES_SAVED");
                   5788:        }
                   5789: }
                   5790: 
                   5791: 
                   5792: static void SaveDefaultKeyFilesParam (void)
                   5793: {
                   5794:        if (defaultKeyFilesParam.FirstKeyFile == NULL)
                   5795:        {
                   5796:                /* No keyfiles selected */ 
                   5797:                remove (GetConfigPath (FILE_DEFAULT_KEYFILES));
                   5798:        }
                   5799:        else
                   5800:        {
                   5801:                FILE *f;
                   5802:                KeyFile *kf = FirstKeyFile;
                   5803: 
                   5804:                f = fopen (GetConfigPath (FILE_DEFAULT_KEYFILES), "w");
                   5805:                if (f == NULL)
                   5806:                {
                   5807:                        handleWin32Error (MainDlg);
                   5808:                        return;
                   5809:                }
                   5810: 
                   5811:                XmlWriteHeader (f);
                   5812: 
                   5813:                fputs ("\n\t<defaultkeyfiles>", f);
                   5814: 
                   5815:                while (kf != NULL)
                   5816:                {
1.1.1.11  root     5817:                        char q[TC_MAX_PATH * 2];
                   5818: 
                   5819:                        XmlQuoteText (kf->FileName, q, sizeof (q));
                   5820:                        fprintf (f, "\n\t\t<keyfile>%s</keyfile>", q); 
                   5821: 
1.1.1.7   root     5822:                        kf = kf->Next;
                   5823:                }
                   5824: 
                   5825:                fputs ("\n\t</defaultkeyfiles>", f); 
                   5826: 
                   5827:                XmlWriteFooter (f);
                   5828: 
                   5829:                fclose (f);
                   5830:                return;
                   5831:        }
                   5832: }
                   5833: 
                   5834: 
                   5835: static void KeyfileDefaultsDlg (HWND hwndDlg)
                   5836: {
                   5837:        KeyFilesDlgParam param;
                   5838: 
                   5839:        param.EnableKeyFiles = defaultKeyFilesParam.EnableKeyFiles;
                   5840:        param.FirstKeyFile = defaultKeyFilesParam.FirstKeyFile;
                   5841: 
                   5842:        if (DialogBoxParamW (hInst,
                   5843:                MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
                   5844:                (DLGPROC) KeyFilesDlgProc, (LPARAM) &param) == IDOK)
                   5845:        {
1.1.1.13  root     5846:                if (!param.EnableKeyFiles || AskWarnYesNo ("CONFIRM_SAVE_DEFAULT_KEYFILES") == IDYES)
1.1.1.7   root     5847:                {
                   5848:                        KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile);
                   5849:                        defaultKeyFilesParam.EnableKeyFiles = param.EnableKeyFiles;
                   5850:                        defaultKeyFilesParam.FirstKeyFile = param.FirstKeyFile;
                   5851: 
                   5852:                        RestoreDefaultKeyFilesParam ();
                   5853:                        SaveDefaultKeyFilesParam ();
                   5854:                }
                   5855:        }
                   5856: }
                   5857: 
                   5858: 
                   5859: static void HandleHotKey (HWND hwndDlg, WPARAM wParam)
                   5860: {
                   5861:        DWORD dwResult;
                   5862:        BOOL success = TRUE;
                   5863: 
                   5864:        switch (wParam)
                   5865:        {
                   5866:        case HK_AUTOMOUNT_DEVICES:
                   5867:                MountAllDevices (hwndDlg, TRUE);
                   5868: 
                   5869:                if (bPlaySoundOnHotkeyMountDismount)
                   5870:                        MessageBeep(-1);
                   5871: 
                   5872:                break;
                   5873: 
                   5874:        case HK_DISMOUNT_ALL:
1.1.1.12  root     5875:                if (DismountAll (hwndDlg, FALSE, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY) && bDisplayMsgBoxOnHotkeyDismount)
                   5876:                        Info ("MOUNTED_VOLUMES_DISMOUNTED");
                   5877:                else if (bDisplayMsgBoxOnHotkeyDismount)
                   5878:                        Info ("DISMOUNT_ALL_ATTEMPT_COMPLETED");
1.1.1.7   root     5879: 
1.1.1.12  root     5880:                if (!bDisplayMsgBoxOnHotkeyDismount && bPlaySoundOnHotkeyMountDismount)
1.1.1.7   root     5881:                        MessageBeep(-1);
                   5882: 
                   5883:                break;
                   5884: 
1.1.1.11  root     5885:        case HK_WIPE_CACHE:
                   5886:                WipeCache (hwndDlg);
                   5887:                break;
                   5888: 
1.1.1.7   root     5889:        case HK_FORCE_DISMOUNT_ALL_AND_WIPE:
                   5890:                success = DismountAll (hwndDlg, TRUE, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1.1.13  root     5891:                success &= DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.7   root     5892:                if (success)
                   5893:                {
                   5894:                        if (bPlaySoundOnHotkeyMountDismount)
                   5895:                                MessageBeep(-1);
                   5896: 
                   5897:                        if (bDisplayMsgBoxOnHotkeyDismount)
                   5898:                                Info ("VOLUMES_DISMOUNTED_CACHE_WIPED");
                   5899:                }
                   5900:                break;
                   5901: 
                   5902:        case HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT:
                   5903:                success = DismountAll (hwndDlg, TRUE, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1.1.13  root     5904:                success &= DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.7   root     5905:                if (success)
                   5906:                {
                   5907:                        if (bPlaySoundOnHotkeyMountDismount)
                   5908:                                MessageBeep(-1);
                   5909: 
                   5910:                        if (bDisplayMsgBoxOnHotkeyDismount)
                   5911:                                Info ("VOLUMES_DISMOUNTED_CACHE_WIPED");
                   5912:                }
                   5913:                TaskBarIconRemove (hwndDlg);
                   5914:                EndMainDlg (hwndDlg);
                   5915:                break;
                   5916: 
                   5917:        case HK_MOUNT_FAVORITE_VOLUMES:
                   5918:                MountFavoriteVolumes ();
                   5919: 
                   5920:                if (bPlaySoundOnHotkeyMountDismount)
                   5921:                        MessageBeep(-1);
                   5922: 
                   5923:                break;
                   5924: 
                   5925:        case HK_SHOW_HIDE_MAIN_WINDOW:
1.1.1.13  root     5926:                ChangeMainWindowVisibility ();
1.1.1.7   root     5927:                break;
                   5928:        }
1.1.1.13  root     5929: }
                   5930: 
                   5931: 
                   5932: void ChangeMainWindowVisibility ()
                   5933: {
                   5934:        MainWindowHidden = !MainWindowHidden;
                   5935: 
                   5936:        if (!MainWindowHidden)
                   5937:                SetForegroundWindow (MainDlg);
                   5938: 
                   5939:        ShowWindow (MainDlg, !MainWindowHidden ? SW_SHOW : SW_HIDE);
                   5940: 
                   5941:        if (!MainWindowHidden)
                   5942:                ShowWindow (MainDlg, SW_RESTORE);
1.1.1.7   root     5943: }

unix.superglobalmegacorp.com

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