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

1.1.1.3   root        1: /* The source code contained in this file has been derived from the source code
                      2:    of Encryption for the Masses 2.02a by Paul Le Roux. Modifications and
1.1.1.6 ! root        3:    additions to that source code contained in this file are Copyright (c) 2004-2005
1.1.1.5   root        4:    TrueCrypt Foundation and Copyright (c) 2004 TrueCrypt Team. Unmodified
1.1.1.3   root        5:    parts are Copyright (c) 1998-99 Paul Le Roux. This is a TrueCrypt Foundation
                      6:    release. Please see the file license.txt for full license details. */
1.1       root        7: 
                      8: #include "TCdefs.h"
1.1.1.5   root        9: #include <time.h>
                     10: #include <dbt.h>
1.1       root       11: #include "crypto.h"
                     12: #include "apidrvr.h"
                     13: #include "dlgcode.h"
                     14: #include "combo.h"
                     15: #include "registry.h"
                     16: #include "resource.h"
                     17: #include "cmdline.h"
                     18: #include "Mount.h"
                     19: #include "Password.h"
1.1.1.6 ! root       20: #include "../common/common.h"
1.1.1.5   root       21: #include "../common/resource.h"
1.1       root       22: 
                     23: BOOL bExplore = FALSE;                         /* Display explorer window after mount */
                     24: BOOL bBeep = FALSE;                                    /* Donot beep after mount */
                     25: char szFileName[TC_MAX_PATH];          /* Volume to mount */
                     26: char szDriveLetter[3];                         /* Drive Letter to mount */
1.1.1.5   root       27: char commandLineDrive = 0;
1.1       root       28: BOOL bCacheInDriver = FALSE;           /* Cache any passwords we see */
                     29: BOOL bHistory = FALSE;                         /* Don't save history */
                     30: BOOL bHistoryCmdLine = FALSE;          /* History control is always disabled */
                     31: BOOL bCloseDismountedWindows=TRUE;     /* Close all open explorer windows of dismounted volume */
                     32: BOOL bWipeCacheOnExit = FALSE;         /* Wipe password from chace on exit */
                     33: 
1.1.1.5   root       34: BOOL bForceMount = FALSE;                      /* Mount volume even if host file/device already in use */
                     35: BOOL bForceUnmount = FALSE;                    /* Unmount volume even if it cannot be locked */
                     36: 
1.1       root       37: BOOL bWipe = FALSE;                                    /* Wipe driver passwords */
                     38: BOOL bAuto = FALSE;                                    /* Do everything without user input */
1.1.1.6 ! root       39: BOOL bAutoMountDevices = FALSE;                /* Auto-mount devices */
1.1       root       40: 
                     41: BOOL bQuiet = FALSE;                           /* No dialogs/messages */
1.1.1.3   root       42: 
1.1.1.2   root       43: char commandLinePassword[MAX_PASSWORD + 1] = {0};      /* Password passed from command line */
1.1.1.5   root       44: int cmdUnmountDrive = 0;                       /* Volume drive letter to unmount (-1 = all) */
1.1       root       45: 
                     46: #define VMOUNTED 1
                     47: #define VFREE  0
                     48: 
                     49: int nCurrentShowType = 0;                      /* current display mode, mount, unmount etc */
1.1.1.5   root       50: int nSelectedDriveIndex = -1;          /* Item number of selected drive */
1.1       root       51: 
1.1.1.6 ! root       52: MountOptions mountOptions;
        !            53: MountOptions defaultMountOptions;
        !            54: 
1.1       root       55: void
                     56: localcleanup (void)
                     57: {
                     58:        /* Free the application title */
                     59:        if (lpszTitle != NULL)
                     60:                free (lpszTitle);
                     61: 
                     62:        /* Cleanup common code resources */
                     63:        cleanup ();
                     64: }
                     65: 
                     66: void
                     67: RefreshMainDlg (HWND hwndDlg)
                     68: {
                     69:        int drive = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))));
                     70: 
                     71:        MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
                     72:        LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), drive);
                     73:        EnableDisableButtons (hwndDlg);
                     74: }
                     75: 
                     76: void
                     77: EndMainDlg (HWND hwndDlg)
                     78: {
                     79:        MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.2   root       80:        if (!bQuiet) SaveSettings (hwndDlg);
1.1       root       81: 
                     82:        if (bWipeCacheOnExit)
                     83:        {
                     84:                DWORD dwResult;
                     85:                DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
                     86:        }
                     87: 
                     88:        EndDialog (hwndDlg, 0);
                     89: }
                     90: 
                     91: void
                     92: EnableDisableButtons (HWND hwndDlg)
                     93: {
                     94:        HWND hOKButton = GetDlgItem (hwndDlg, IDOK);
                     95:        HWND hChangeButton = GetDlgItem (hwndDlg, IDC_CHANGE_PASSWORD);
                     96:        HWND hVolume = GetDlgItem (hwndDlg, IDC_VOLUME);
                     97:        BOOL bEnable = TRUE;
                     98:        WORD x;
                     99: 
                    100:        x = LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST)));
                    101: 
                    102:        if (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_VOLUME)) > 0)
                    103:        {
                    104:                EnableWindow (hOKButton, TRUE);
                    105:                EnableMenuItem (GetMenu (hwndDlg), ID_MOUNT_VOLUME, MF_ENABLED);
1.1.1.6 ! root      106:                EnableMenuItem (GetMenu (hwndDlg), IDM_MOUNT_VOLUME_OPTIONS, MF_ENABLED);
1.1       root      107: 
                    108:                EnableWindow (hChangeButton, TRUE);
                    109:                EnableMenuItem (GetMenu (hwndDlg), IDC_CHANGE_PASSWORD, MF_ENABLED);
                    110:        }
                    111:        else
                    112:        {
                    113:                EnableWindow (hOKButton, FALSE);
                    114:                EnableMenuItem (GetMenu (hwndDlg), ID_MOUNT_VOLUME, MF_GRAYED);
1.1.1.6 ! root      115:                EnableMenuItem (GetMenu (hwndDlg), IDM_MOUNT_VOLUME_OPTIONS, MF_GRAYED);
1.1       root      116: 
                    117:                EnableWindow (hChangeButton, FALSE);
                    118:                EnableMenuItem (GetMenu (hwndDlg), IDC_CHANGE_PASSWORD, MF_GRAYED);
                    119:        }
                    120: 
                    121:        if (x == VFREE)
                    122:        {
                    123:                SetWindowText (hOKButton, getstr (IDS_MOUNT_BUTTON));
                    124: 
                    125:                EnableMenuItem (GetMenu (hwndDlg), ID_UNMOUNT_VOLUME, MF_GRAYED);
                    126:        }
                    127: 
                    128:        if (x == VMOUNTED)
                    129:        {
                    130:                SetWindowText (hOKButton, getstr (IDS_UNMOUNT_BUTTON));
                    131:                EnableWindow (hOKButton, TRUE);
                    132: 
                    133:                EnableMenuItem (GetMenu (hwndDlg), ID_MOUNT_VOLUME, MF_GRAYED);
1.1.1.6 ! root      134:                EnableMenuItem (GetMenu (hwndDlg), IDM_MOUNT_VOLUME_OPTIONS, MF_GRAYED);
1.1       root      135:                EnableMenuItem (GetMenu (hwndDlg), ID_UNMOUNT_VOLUME, MF_ENABLED);
                    136: 
                    137:                EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), TRUE);
                    138:                EnableMenuItem (GetMenu (hwndDlg), IDC_VOLUME_PROPERTIES, MF_ENABLED);
                    139:        }
                    140:        else
                    141:        {
                    142:                EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), FALSE);
                    143:                EnableMenuItem (GetMenu (hwndDlg), IDC_VOLUME_PROPERTIES, MF_GRAYED);
                    144:        }
                    145: 
                    146:        EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_CACHE), !IsPasswordCacheEmpty());
                    147:        EnableMenuItem (GetMenu (hwndDlg), IDC_WIPE_CACHE, IsPasswordCacheEmpty() ? MF_GRAYED:MF_ENABLED);
                    148:        EnableMenuItem (GetMenu (hwndDlg), IDC_CLEAR_HISTORY, IsComboEmpty (GetDlgItem (hwndDlg, IDC_VOLUME)) ? MF_GRAYED:MF_ENABLED);
                    149: }
                    150: 
                    151: void
                    152: OpenPageHelp (HWND hwndDlg)
                    153: {
                    154:        int r = (int)ShellExecute (NULL, "open", szHelpFile, NULL, NULL, SW_SHOWNORMAL);
                    155: 
                    156:        if (r == ERROR_FILE_NOT_FOUND)
                    157:                MessageBox (hwndDlg, getstr (IDS_HELP_ERROR), lpszTitle, MB_ICONERROR);
                    158: 
                    159:        if (r == SE_ERR_NOASSOC)
                    160:                MessageBox (hwndDlg, getstr (IDS_HELP_READER_ERROR), lpszTitle, MB_ICONERROR);
                    161: }
                    162: 
                    163: void
                    164: LoadSettings (HWND hwndDlg)
                    165: {
                    166:        // Options
1.1.1.6 ! root      167:        bCacheInDriver =                                ReadRegistryInt ("CachePasswordsInDriver", FALSE);
        !           168:        bExplore =                                              ReadRegistryInt ("OpenExplorerWindowAfterMount", FALSE);
        !           169:        bCloseDismountedWindows =               ReadRegistryInt ("CloseExplorerWindowsOnDismount", TRUE);
        !           170:        bHistory =                                              ReadRegistryInt ("SaveMountedVolumesHistory", FALSE);
        !           171:        bWipeCacheOnExit =                              ReadRegistryInt ("WipePasswordCacheOnExit", FALSE);
        !           172:        defaultMountOptions.ReadOnly =  ReadRegistryInt ("MountVolumesReadOnly", FALSE);
        !           173:        defaultMountOptions.Removable = ReadRegistryInt ("MountVolumesRemovable", FALSE);
        !           174:        mountOptions = defaultMountOptions;
1.1       root      175: 
1.1.1.5   root      176:        // Drive letter - command line arg overrides registry
                    177:        if (szDriveLetter[0] == 0)
                    178:                ReadRegistryString ("LastSelectedDrive", "", szDriveLetter, sizeof (szDriveLetter));
1.1       root      179: 
                    180:        // History
                    181:        if (bHistoryCmdLine != TRUE)
                    182:                LoadCombo (GetDlgItem (hwndDlg, IDC_VOLUME), "LastMountedVolume");
                    183: }
                    184: 
                    185: void
                    186: SaveSettings (HWND hwndDlg)
                    187: {
                    188:        char szTmp[32] = {0};
                    189:        LPARAM lLetter;
                    190: 
1.1.1.6 ! root      191:        if (IsNonInstallMode ()) return;
        !           192: 
1.1       root      193:        // Options
                    194:        WriteRegistryInt ("CachePasswordsInDriver",                     bCacheInDriver);
                    195:        WriteRegistryInt ("OpenExplorerWindowAfterMount",       bExplore);
                    196:        WriteRegistryInt ("CloseExplorerWindowsOnDismount", bCloseDismountedWindows);
                    197:        WriteRegistryInt ("SaveMountedVolumesHistory",          !IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY)));
                    198:        WriteRegistryInt ("WipePasswordCacheOnExit",            bWipeCacheOnExit);
1.1.1.6 ! root      199:        WriteRegistryInt ("MountVolumesReadOnly",                       defaultMountOptions.ReadOnly);
        !           200:        WriteRegistryInt ("MountVolumesRemovable",                      defaultMountOptions.Removable);
1.1       root      201: 
                    202:        // Drive Letter
                    203:        lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
                    204:        if (LOWORD (lLetter) != 0xffff)
                    205:                sprintf (szTmp, "%c:", (char) HIWORD (lLetter));
                    206:        WriteRegistryString ("LastSelectedDrive", szTmp);
                    207: 
                    208:        // History
                    209:        DumpCombo (GetDlgItem (hwndDlg, IDC_VOLUME), "LastMountedVolume", IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY)));
                    210: }
                    211: 
                    212: BOOL
                    213: SelectItem (HWND hTree, char nLetter)
                    214: {
                    215:        int i;
                    216:        LVITEM item;
                    217:        
                    218:        for (i = 0; i < ListView_GetItemCount(hTree); i++)
                    219:        {
                    220:                memset(&item, 0, sizeof(LVITEM));
                    221:                item.mask = LVIF_PARAM;
                    222:                item.iItem = i;
                    223: 
                    224:                if (ListView_GetItem (hTree, &item) == FALSE)
                    225:                        return FALSE;
                    226:                else
                    227:                {
                    228:                        if (HIWORD (item.lParam) == nLetter)
                    229:                        {
                    230:                                memset(&item, 0, sizeof(LVITEM));
                    231:                                item.state = LVIS_FOCUSED|LVIS_SELECTED;
                    232:                                item.stateMask = LVIS_FOCUSED|LVIS_SELECTED;
                    233:                                item.mask = LVIF_STATE;
                    234:                                item.iItem = i;
                    235:                                SendMessage(hTree, LVM_SETITEMSTATE, i, (LPARAM) &item);
                    236:                                return TRUE;
                    237:                        }
                    238:                }
                    239: 
                    240:        }
                    241: 
                    242:        return TRUE;
                    243: }
                    244: 
                    245: 
                    246: // Fills drive list
                    247: // drive>0 = update only the corresponding drive subitems
                    248: void
                    249: LoadDriveLetters (HWND hTree, int drive)
                    250: {
                    251:        char *szDriveLetters[]=
                    252:        {"A:", "B:", "C:", "D:",
                    253:         "E:", "F:", "G:", "H:", "I:", "J:", "K:",
                    254:         "L:", "M:", "N:", "O:", "P:", "Q:", "R:",
                    255:         "S:", "T:", "U:", "V:", "W:", "X:", "Y:",
                    256:         "Z:"};
                    257: 
                    258:        DWORD dwResult;
                    259:        BOOL bResult;   
                    260:        DWORD dwUsedDrives;
                    261:        MOUNT_LIST_STRUCT driver;
                    262: 
                    263:        LVITEM listItem;
                    264:        int item = 0;
                    265:        char i;
                    266: 
                    267:        bResult = DeviceIoControl (hDriver, MOUNT_LIST, &driver,
                    268:                sizeof (driver), &driver, sizeof (driver), &dwResult,
                    269:                NULL);
                    270: 
                    271:        if (bResult == FALSE)
                    272:        {
                    273:                handleWin32Error (hTree);
                    274:                driver.ulMountedDrives = 0;
                    275:        }
                    276: 
                    277:        dwUsedDrives = GetLogicalDrives();
                    278:        if (dwUsedDrives == 0 && bQuiet == FALSE)
                    279:                        MessageBox (hTree, getstr (IDS_DRIVELETTERS), lpszTitle, ICON_HAND);
                    280: 
                    281:        if(drive == 0)
                    282:                ListView_DeleteAllItems(hTree);
                    283: 
                    284:        for (i = 2; i < 26; i++)
                    285:        {
                    286:                int curDrive = 0;
                    287: 
                    288:                if(drive > 0)
                    289:                {
                    290:                        LVITEM tmp;
                    291:                        memset(&tmp, 0, sizeof(LVITEM));
                    292:                        tmp.mask = LVIF_PARAM;
                    293:                        tmp.iItem = item;
                    294:                        if (ListView_GetItem (hTree, &tmp) != FALSE)
                    295:                                curDrive = HIWORD(tmp.lParam);
                    296:                }
                    297: 
                    298:                if ( driver.ulMountedDrives & (1 << i) )
                    299:                {
                    300:                        char szTmp[256];
                    301: 
                    302:                        memset(&listItem, 0, sizeof(listItem));
                    303: 
                    304:                        listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
                    305:                        listItem.iImage = 1;
                    306:                        listItem.iItem = item++;  
                    307: 
                    308:                        if(drive > 0 && drive != curDrive)
                    309:                                continue;
                    310: 
                    311:                        if (nCurrentOS == WIN_NT)
                    312:                                ToSBCS ((void *) driver.wszVolume[i]);
                    313: 
                    314:                        if (memcmp (driver.wszVolume[i], "\\Device", 7) == 0)
                    315:                                sprintf (szTmp, "%s", ((char *) driver.wszVolume[i]));
                    316:                        else
                    317:                        {
                    318:                                if (nCurrentOS == WIN_NT)
                    319:                                        sprintf (szTmp, "%s", ((char *) driver.wszVolume[i]) + 4);
                    320:                                else
                    321:                                        sprintf (szTmp, "%s", (char *) driver.wszVolume[i]);
                    322:                        }
                    323: 
                    324:                        listItem.pszText = szDriveLetters[i];
                    325:                        listItem.lParam = MAKELONG (VMOUNTED, i + 'A');
                    326:                        
                    327:                        if(drive == 0) 
                    328:                                ListView_InsertItem (hTree, &listItem);
                    329:                        else
                    330:                                ListView_SetItem (hTree, &listItem);
                    331: 
                    332:                        listItem.mask=LVIF_TEXT;   
                    333:                        listItem.pszText = szTmp;
                    334: 
                    335:                        listItem.iSubItem = 1;
1.1.1.5   root      336:                        ListView_SetItem (hTree, &listItem);
1.1       root      337: 
1.1.1.5   root      338:                        if(driver.diskLength[i] > 1024I64*1024*1024*1024*1024*99)
1.1.1.6 ! root      339:                                sprintf (szTmp, "%I64d PB", driver.diskLength[i]/1024/1024/1024/1024/1024);
1.1.1.5   root      340:                        if(driver.diskLength[i] > 1024I64*1024*1024*1024*1024)
1.1.1.6 ! root      341:                                sprintf (szTmp, "%.1f PB", (double)(driver.diskLength[i]/1024.0/1024/1024/1024/1024));
1.1.1.5   root      342:                        else if(driver.diskLength[i] > 1024I64*1024*1024*1024*99)
1.1.1.6 ! root      343:                                sprintf (szTmp, "%I64d TB", driver.diskLength[i]/1024/1024/1024/1024);
1.1.1.5   root      344:                        else if(driver.diskLength[i] > 1024I64*1024*1024*1024)
1.1.1.6 ! root      345:                                sprintf (szTmp, "%.1f TB", (double)(driver.diskLength[i]/1024.0/1024/1024/1024));
1.1.1.5   root      346:                        else if(driver.diskLength[i] > 1024I64*1024*1024*99)
1.1.1.6 ! root      347:                                sprintf (szTmp, "%I64d GB", driver.diskLength[i]/1024/1024/1024);
1.1.1.5   root      348:                        else if(driver.diskLength[i] > 1024I64*1024*1024)
1.1.1.6 ! root      349:                                sprintf (szTmp, "%.1f GB", (double)(driver.diskLength[i]/1024.0/1024/1024));
        !           350:                        else if(driver.diskLength[i] > 1024I64*1024*99)
1.1       root      351:                                sprintf (szTmp, "%I64d MB", driver.diskLength[i]/1024/1024);
1.1.1.6 ! root      352:                        else if(driver.diskLength[i] > 1024I64*1024)
        !           353:                                sprintf (szTmp, "%.1f MB", driver.diskLength[i]/1024.0/1024);
1.1       root      354:                        else if(driver.diskLength[i] > 0)
                    355:                                sprintf (szTmp, "%I64d KB", driver.diskLength[i]/1024);
                    356:                        else
                    357:                                szTmp[0] = 0;
                    358: 
                    359:                        listItem.iSubItem = 2;
1.1.1.5   root      360:                        ListView_SetItem (hTree, &listItem);
1.1       root      361: 
1.1.1.5   root      362:                        EAGetName (szTmp, driver.ea[i]);
1.1       root      363:                        listItem.iSubItem = 3;
1.1.1.5   root      364:                        ListView_SetItem (hTree, &listItem);
1.1       root      365: 
1.1.1.5   root      366:                        if (driver.hiddenVol[i] == FALSE)
                    367:                                sprintf (szTmp, "Normal");
                    368:                        else
                    369:                                sprintf (szTmp, "Hidden");
                    370:                        listItem.iSubItem = 4;
                    371:                        ListView_SetItem (hTree, &listItem);
1.1       root      372:                }
                    373:                else
                    374:                {
                    375:                        if (!(dwUsedDrives & 1 << i))
                    376:                        {
                    377:                                if(drive > 0 && drive != HIWORD (GetSelectedLong (hTree)))
                    378:                                {
                    379:                                        item++;
                    380:                                        continue;
                    381:                                }
                    382: 
                    383:                                memset(&listItem,0,sizeof(listItem));
                    384: 
                    385:                                listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
                    386:                                listItem.iImage = 0;
                    387:                                listItem.iItem = item++;  
                    388:                                listItem.pszText = szDriveLetters[i];
                    389:                                listItem.lParam = MAKELONG (VFREE, i + 'A');
                    390: 
                    391:                                if(drive == 0) 
                    392:                                        ListView_InsertItem (hTree, &listItem);
                    393:                                else
                    394:                                        ListView_SetItem (hTree, &listItem);
                    395: 
                    396:                                listItem.mask=LVIF_TEXT;   
                    397:                                listItem.pszText = "";
                    398:                                listItem.iSubItem = 1;
1.1.1.5   root      399:                                ListView_SetItem (hTree, &listItem);
1.1       root      400:                                listItem.iSubItem = 2;
1.1.1.5   root      401:                                ListView_SetItem (hTree, &listItem);
1.1       root      402:                                listItem.iSubItem = 3;
1.1.1.5   root      403:                                ListView_SetItem (hTree, &listItem);
                    404:                                listItem.iSubItem = 4;
                    405:                                ListView_SetItem (hTree, &listItem);
1.1       root      406: 
                    407:                        }
                    408:                }
                    409:        }
                    410: }
                    411: 
                    412: 
                    413: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
                    414:    should return nonzero if it processes the message, and zero if it does
                    415:    not. - see DialogProc */
                    416: BOOL WINAPI
                    417: PasswordChangeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                    418: {
                    419: 
                    420:        WORD lw = LOWORD (wParam);
                    421:        WORD hw = HIWORD (wParam);
                    422: 
                    423:        if (lParam);            /* remove warning */
                    424:        if (hw);                        /* remove warning */
                    425: 
                    426:        switch (msg)
                    427:        {
                    428:        case WM_INITDIALOG:
                    429:                {
                    430:                        UINT nID[4];
1.1.1.3   root      431:                        LPARAM nIndex;
                    432:                        HWND hComboBox = GetDlgItem (hwndDlg, IDC_HASH_CHANGE);
                    433:                        int i;
1.1       root      434: 
1.1.1.5   root      435:                        nID[0] = IDS_PASSWORD_HELP1;
                    436:                        nID[1] = IDS_PASSWORD_HELP2;
                    437:                        nID[2] = IDS_PASSWORD_HELP3;
                    438:                        nID[3] = IDS_PASSWORD_HELP0;
1.1       root      439: 
                    440:                        SetDefaultUserFont (hwndDlg);
                    441: 
                    442:                        SendMessage (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
                    443:                        SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
                    444:                        SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY), EM_LIMITTEXT, MAX_PASSWORD, 0);
                    445:                        SetWindowText (GetDlgItem (hwndDlg, IDC_BOX_HELP), getmultilinestr (nID));
                    446:                        EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
                    447: 
1.1.1.3   root      448:                        SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
                    449: 
                    450:                        nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) "Unchanged");
                    451:                        SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) 0);
                    452: 
                    453:                        for (i = 1; i <= LAST_PRF_ID; i++)
                    454:                        {
                    455:                                nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) get_hash_name(i));
                    456:                                SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) i);
                    457:                        }
                    458: 
                    459:                        SendMessage (hComboBox, CB_SETCURSEL, 0, 0);
                    460: 
1.1.1.5   root      461:                        CheckCapsLock (hwndDlg, FALSE);
                    462: 
1.1       root      463:                        return 1;
                    464:                }
                    465: 
                    466:        case WM_COMMAND:
                    467:                if (lw == IDCANCEL)
                    468:                {
                    469:                        // Attempt to wipe passwords stored in the input field buffers
                    470:                        char tmp[MAX_PASSWORD+1];
                    471:                        memset (tmp, 'X', MAX_PASSWORD);
                    472:                        tmp[MAX_PASSWORD] = 0;
                    473: 
                    474:                        SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);        
                    475:                        SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);    
                    476:                        SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);  
                    477: 
                    478:                        EndDialog (hwndDlg, IDCANCEL);
                    479:                        return 1;
                    480:                }
                    481:                if (hw == EN_CHANGE)
                    482:                {
                    483:                        VerifyPasswordAndUpdate (hwndDlg, GetDlgItem (hwndDlg, IDOK), GetDlgItem (hwndDlg, IDC_PASSWORD),
                    484:                                                 GetDlgItem (hwndDlg, IDC_VERIFY), NULL, NULL);
                    485:                        return 1;
                    486:                }
                    487:                if (lw == IDOK)
                    488:                {
                    489:                        HWND hParent = GetParent (hwndDlg);
                    490:                        char szOldPassword[MAX_PASSWORD + 1];
                    491:                        char szPassword[MAX_PASSWORD + 1];
                    492:                        int nStatus;
1.1.1.3   root      493:                        int pkcs5 = SendMessage (GetDlgItem (hwndDlg, IDC_HASH_CHANGE), CB_GETITEMDATA, 
                    494:                                        SendMessage (GetDlgItem (hwndDlg, IDC_HASH_CHANGE), CB_GETCURSEL, 0, 0), 0);
1.1       root      495: 
1.1.1.5   root      496:                        if (!CheckPasswordLength (hwndDlg, GetDlgItem (hwndDlg, IDC_PASSWORD)))
                    497:                                return 0;
                    498: 
1.1       root      499:                        GetWindowText (GetDlgItem (hParent, IDC_VOLUME), szFileName, sizeof (szFileName));
                    500: 
                    501:                        GetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), szOldPassword, sizeof (szOldPassword));
                    502: 
                    503:                        GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), szPassword, sizeof (szPassword));
                    504: 
1.1.1.5   root      505:                        nStatus = ChangePwd (szFileName, szOldPassword, szPassword, pkcs5, hwndDlg);
1.1       root      506: 
                    507:                        burn (szOldPassword, sizeof (szOldPassword));
                    508:                        burn (szPassword, sizeof (szPassword));
                    509: 
                    510:                        if (nStatus != 0)
                    511:                                handleError (hwndDlg, nStatus);
                    512:                        else
                    513:                        {
                    514:                                // Attempt to wipe passwords stored in the input field buffers
                    515:                                char tmp[MAX_PASSWORD+1];
                    516:                                memset (tmp, 'X', MAX_PASSWORD);
                    517:                                tmp[MAX_PASSWORD] = 0;
                    518:                                SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);        
                    519:                                SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);    
                    520:                                SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);  
                    521: 
                    522:                                EndDialog (hwndDlg, IDOK);
                    523:                        }
                    524: 
                    525:                        return 1;
                    526:                }
                    527:                return 0;
                    528:        }
                    529: 
                    530:        return 0;
                    531: }
                    532: 
                    533: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
                    534:    should return nonzero if it processes the message, and zero if it does
                    535:    not. - see DialogProc */
                    536: BOOL WINAPI
                    537: PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                    538: {
                    539:        WORD lw = LOWORD (wParam);
                    540:        static char* szXPwd;    
                    541: 
                    542:        switch (msg)
                    543:        {
                    544:        case WM_INITDIALOG:
                    545:                {
                    546:                        szXPwd = (char*) lParam;
                    547:                        SetDefaultUserFont (hwndDlg);
                    548:                        SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
                    549:                        SendMessage (GetDlgItem (hwndDlg, IDC_CACHE), BM_SETCHECK, bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
                    550:                        return 1;
                    551:                }
                    552: 
                    553:        case WM_COMMAND:
                    554: 
1.1.1.6 ! root      555:                if (lw == IDC_MOUNT_OPTIONS)
        !           556:                {
        !           557:                        DialogBoxParam (hInst, 
        !           558:                                MAKEINTRESOURCE (IDD_MOUNT_OPTIONS), hwndDlg,
        !           559:                                (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions);
        !           560:                        return 1;
        !           561:                }
        !           562: 
1.1       root      563:                if (lw == IDCANCEL || lw == IDOK)
                    564:                {
                    565:                        char tmp[MAX_PASSWORD+1];
                    566:                        
                    567:                        if (lw == IDOK)
                    568:                        {
                    569:                                GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), szXPwd, MAX_PASSWORD + 1);
                    570:                                bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_CACHE));      
                    571:                        }
                    572: 
                    573:                        // Attempt to wipe password stored in the input field buffer
                    574:                        memset (tmp, 'X', MAX_PASSWORD);
                    575:                        tmp[MAX_PASSWORD] = 0;
                    576:                        SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);        
                    577:                        SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), 0);  
                    578: 
                    579:                        EndDialog (hwndDlg, lw);
                    580:                        return 1;
                    581:                }
                    582:                return 0;
                    583:        }
                    584: 
                    585:        return 0;
                    586: }
                    587: 
                    588: BOOL WINAPI
                    589: PreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                    590: {
                    591:        WORD lw = LOWORD (wParam);
                    592: 
                    593:        switch (msg)
                    594:        {
                    595:        case WM_INITDIALOG:
                    596:                {
                    597:                        SetDefaultUserFont (hwndDlg);
                    598:                
                    599:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_OPEN_EXPLORER), BM_SETCHECK, 
                    600:                                                bExplore ? BST_CHECKED:BST_UNCHECKED, 0);
                    601: 
                    602:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_CLOSE_DISMOUNTED_WINDOWS), BM_SETCHECK, 
                    603:                                                bCloseDismountedWindows ? BST_CHECKED:BST_UNCHECKED, 0);
                    604:                        
                    605:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_EXIT), BM_SETCHECK, 
                    606:                                                bWipeCacheOnExit ? BST_CHECKED:BST_UNCHECKED, 0);
                    607: 
                    608:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_CACHE_PASSWORDS), BM_SETCHECK, 
                    609:                                                bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
                    610:                        
1.1.1.6 ! root      611:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_READONLY), BM_SETCHECK, 
        !           612:                                                defaultMountOptions.ReadOnly ? BST_CHECKED:BST_UNCHECKED, 0);
        !           613: 
        !           614:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_REMOVABLE), BM_SETCHECK, 
        !           615:                                                defaultMountOptions.Removable ? BST_CHECKED:BST_UNCHECKED, 0);
1.1       root      616:                        
                    617:                        return 1;
                    618:                }
                    619: 
                    620:        case WM_COMMAND:
                    621: 
                    622:                if (lw == IDCANCEL)
                    623:                {
                    624:                        EndDialog (hwndDlg, lw);
                    625:                        return 1;
                    626:                }
                    627: 
                    628:                if (lw == IDOK)
                    629:                {
                    630:                        bExplore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_OPEN_EXPLORER));       
                    631:                        bCloseDismountedWindows = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_CLOSE_DISMOUNTED_WINDOWS));     
                    632:                        bWipeCacheOnExit = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_EXIT));  
                    633:                        bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_CACHE_PASSWORDS));       
1.1.1.6 ! root      634:                        defaultMountOptions.ReadOnly = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_READONLY));
        !           635:                        defaultMountOptions.Removable = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_REMOVABLE));
1.1       root      636: 
                    637:                        EndDialog (hwndDlg, lw);
                    638:                        return 1;
                    639:                }
                    640:                return 0;
                    641:        }
                    642: 
                    643:        return 0;
                    644: }
                    645: 
1.1.1.6 ! root      646: 
1.1       root      647: BOOL WINAPI
                    648: VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                    649: {
                    650:        WORD lw = LOWORD (wParam);
                    651: 
                    652:        switch (msg)
                    653:        {
                    654:        case WM_INITDIALOG:
                    655:                {
                    656:                        VOLUME_PROPERTIES_STRUCT prop;
                    657:                        DWORD dwResult;
                    658:                        BOOL bResult;   
                    659: 
                    660:                        LVCOLUMN lvCol;
                    661:                        LVITEM listItem;
                    662:                        HWND list = GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES_LIST);
                    663:                        char szTmp[128];
                    664: 
                    665:                        SetDefaultUserFont (hwndDlg);
                    666: 
                    667:                        SendMessage (list,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
                    668:                                LVS_EX_FULLROWSELECT
                    669:                                |LVS_EX_HEADERDRAGDROP 
                    670:                                //|LVS_EX_GRIDLINES 
                    671:                                //|LVS_EX_TWOCLICKACTIVATE 
                    672:                                ); 
                    673: 
                    674:                        memset (&lvCol,0,sizeof(lvCol));               
                    675:                        lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;  
                    676:                        lvCol.pszText = "Value";                           
1.1.1.5   root      677:                        lvCol.cx = 213;
1.1       root      678:                        lvCol.fmt = LVCFMT_LEFT ;
                    679:                        SendMessage (list,LVM_INSERTCOLUMN,0,(LPARAM)&lvCol);
                    680: 
                    681:                        lvCol.pszText = "Property";  
1.1.1.5   root      682:                        lvCol.cx = 107;           
1.1       root      683:                        lvCol.fmt = LVCFMT_LEFT;
                    684:                        SendMessage (list,LVM_INSERTCOLUMN,0,(LPARAM)&lvCol);
                    685:        
                    686:        
                    687:                        memset (&prop, 0, sizeof(prop));
                    688:                        prop.driveNo = HIWORD (GetSelectedLong (GetDlgItem (GetParent(hwndDlg), IDC_DRIVELIST))) - 'A';
                    689: 
                    690:                        bResult = DeviceIoControl (hDriver, VOLUME_PROPERTIES, &prop,
                    691:                                sizeof (prop), &prop, sizeof (prop), &dwResult,
                    692:                                NULL);
                    693:        
                    694:                        memset (&listItem, 0, sizeof(listItem));
                    695: 
                    696:                        listItem.mask = LVIF_TEXT;
                    697:                        listItem.iItem = -1;
                    698: 
                    699:                        listItem.pszText = "Volume Location";
                    700:                        listItem.iItem++; 
                    701:                        listItem.iSubItem = 0;
1.1.1.5   root      702:                        ListView_InsertItem (list, &listItem);
1.1       root      703:                        listItem.iSubItem++;
                    704:                        listItem.pszText = (LPSTR)prop.wszVolume;
                    705:                        if (nCurrentOS == WIN_NT)
                    706:                        {
                    707:                                ToSBCS (prop.wszVolume);
                    708:                                if (prop.wszVolume[0] == '?\\')
                    709:                                listItem.pszText = (LPSTR)prop.wszVolume + 4;
                    710:                        }
1.1.1.5   root      711:                        ListView_SetItem (list, &listItem);
1.1       root      712: 
                    713:                        listItem.pszText = "Volume Size";
                    714:                        listItem.iItem++;  
                    715:                        listItem.iSubItem = 0;
1.1.1.5   root      716:                        ListView_InsertItem (list, &listItem);
1.1       root      717:                        listItem.iSubItem++;
1.1.1.5   root      718:                        sprintf (szTmp, "%I64u bytes", prop.diskLength);
1.1       root      719:                        listItem.pszText = szTmp;
                    720:                        ListView_SetItem (list, &listItem);
                    721: 
1.1.1.6 ! root      722:                        listItem.pszText = "Volume Type";
        !           723:                        listItem.iItem++;  
        !           724:                        listItem.iSubItem = 0;
        !           725:                        ListView_InsertItem (list, &listItem);
        !           726:                        listItem.iSubItem++;
        !           727:                        if (prop.hiddenVolume == TRUE)
        !           728:                                sprintf (szTmp, "Hidden");
        !           729:                        else
        !           730:                                sprintf (szTmp, "Normal");
        !           731:                        listItem.pszText = szTmp;
        !           732:                        ListView_SetItem (list, &listItem);
        !           733: 
1.1.1.5   root      734:                        listItem.pszText = "Encryption Algorithm";
1.1       root      735:                        listItem.iItem++; 
                    736:                        listItem.iSubItem = 0;
1.1.1.5   root      737:                        ListView_InsertItem (list, &listItem);
1.1       root      738:                        listItem.iSubItem++;
1.1.1.5   root      739:                        EAGetName (szTmp, prop.ea);
                    740:                        listItem.pszText = szTmp;
1.1       root      741:                        ListView_SetItem (list, &listItem);
                    742: 
                    743:                        listItem.pszText = "Key Size";
                    744:                        listItem.iItem++;  
                    745:                        listItem.iSubItem = 0;
1.1.1.5   root      746:                        ListView_InsertItem (list, &listItem);
1.1       root      747:                        listItem.iSubItem++;
1.1.1.5   root      748:                        sprintf (szTmp, "%d bits", EAGetKeySize (prop.ea)*8);
                    749:                        listItem.pszText = szTmp;
                    750:                        ListView_SetItem (list, &listItem);
                    751: 
                    752:                        listItem.pszText = "Block Size";
                    753:                        listItem.iItem++;  
                    754:                        listItem.iSubItem = 0;
                    755:                        ListView_InsertItem (list, &listItem);
                    756:                        listItem.iSubItem++;
                    757: 
                    758:                        if (EAGetMode (prop.ea) == INNER_CBC)
                    759:                        {
                    760:                                // Cascaded ciphers with non-equal block sizes
                    761:                                char tmpstr[20];
                    762:                                int i = EAGetLastCipher(prop.ea);
                    763: 
                    764:                                sprintf (tmpstr, "%d", CipherGetBlockSize(i)*8);
                    765:                                strcpy (szTmp, tmpstr);
                    766:                                
                    767:                                while (i = EAGetPreviousCipher(prop.ea, i))
                    768:                                {
                    769:                                        sprintf (tmpstr, "/%d", CipherGetBlockSize(i)*8);
                    770:                                        strcat (szTmp, tmpstr);
                    771:                                }
                    772:                                strcat (szTmp, " bits");
                    773:                        }
                    774:                        else
                    775:                        {
                    776:                                sprintf (szTmp, "%d bits", CipherGetBlockSize (EAGetFirstCipher(prop.ea))*8);
                    777:                        }
                    778:                        listItem.pszText = szTmp;
                    779:                        ListView_SetItem (list, &listItem);
                    780: 
                    781:                        listItem.pszText = "Mode";
                    782:                        listItem.iItem++; 
                    783:                        listItem.iSubItem = 0;
                    784:                        ListView_InsertItem (list, &listItem);
                    785:                        listItem.iSubItem++;
                    786:                        EAGetModeName (szTmp, prop.ea, TRUE);
1.1       root      787:                        listItem.pszText = szTmp;
                    788:                        ListView_SetItem (list, &listItem);
                    789: 
                    790:                        listItem.pszText = "PKCS5 PRF";
                    791:                        listItem.iItem++; 
                    792:                        listItem.iSubItem = 0;
1.1.1.5   root      793:                        ListView_InsertItem (list, &listItem);
1.1       root      794:                        listItem.iSubItem++;
                    795:                        listItem.pszText = get_hash_name (prop.pkcs5);
                    796:                        ListView_SetItem (list, &listItem);
                    797: 
                    798:                        listItem.pszText = "PKCS5 Iterations";
                    799:                        listItem.iItem++;  
                    800:                        listItem.iSubItem = 0;
1.1.1.5   root      801:                        ListView_InsertItem (list, &listItem);
1.1       root      802:                        listItem.iSubItem++;
                    803:                        sprintf (szTmp, "%d", prop.pkcs5Iterations);
                    804:                        listItem.pszText = szTmp;
                    805:                        ListView_SetItem (list, &listItem);
                    806:                        
                    807:                        {
                    808:                                FILETIME ft, curFt;
                    809:                                SYSTEMTIME st;
                    810:                                char date[128];
                    811:                                memset (date, 0, sizeof (date));
                    812: 
                    813:                                listItem.pszText = "Volume Created";
                    814:                                listItem.iItem++;  
                    815:                                listItem.iSubItem = 0;
                    816:                                ListView_InsertItem (list, &listItem);
                    817: 
                    818:                                listItem.iSubItem++;
                    819:                                *(unsigned __int64 *)(&ft) = prop.volumeCreationTime;
                    820:                                FileTimeToSystemTime (&ft, &st);
                    821:                                GetDateFormat (LOCALE_USER_DEFAULT, 0, &st, 0, (LPSTR) szTmp, sizeof (szTmp));
                    822:                                sprintf (date, "%s ", szTmp);
                    823:                                GetTimeFormat (LOCALE_USER_DEFAULT, 0, &st, 0, (LPSTR) szTmp, sizeof (szTmp));
                    824:                                strcat (date, szTmp);
                    825:                                listItem.pszText = date;
                    826:                                ListView_SetItem (list, &listItem);
                    827: 
                    828:                                listItem.pszText = "Password Changed";
                    829:                                listItem.iItem++;  
                    830:                                listItem.iSubItem = 0;
                    831:                                ListView_InsertItem (list, &listItem);
                    832: 
                    833:                                listItem.iSubItem++;
                    834:                                *(unsigned __int64 *)(&ft) = prop.headerCreationTime;
                    835:                                FileTimeToSystemTime (&ft, &st);
                    836:                                GetDateFormat (LOCALE_USER_DEFAULT, 0, &st, 0, (LPSTR) szTmp, sizeof (szTmp));
                    837:                                sprintf (date, "%s ", szTmp);
                    838:                                GetTimeFormat (LOCALE_USER_DEFAULT, 0, &st, 0, (LPSTR) szTmp, sizeof (szTmp));
                    839:                                strcat (date, szTmp);
                    840: 
                    841:                                GetLocalTime (&st);
                    842:                                SystemTimeToFileTime (&st, &curFt);
                    843:                                sprintf (date + strlen (date), " (%I64d days ago)"
                    844:                                        , (*(__int64 *)&curFt - *(__int64 *)&ft)/1000000000000 );
                    845:                                listItem.pszText = date;
                    846:                                ListView_SetItem (list, &listItem);
                    847:                        }
                    848: 
                    849:                        return 1;
                    850:                }
                    851: 
                    852:        case WM_COMMAND:
                    853: 
                    854:                if (lw == IDCANCEL)
                    855:                {
                    856:                        EndDialog (hwndDlg, lw);
                    857:                        return 1;
                    858:                }
                    859: 
                    860:                if (lw == IDOK)
                    861:                {
                    862:                        EndDialog (hwndDlg, lw);
                    863:                        return 1;
                    864:                }
                    865:                return 0;
                    866:        }
                    867: 
                    868:        return 0;
                    869: }
                    870: 
1.1.1.6 ! root      871: 
        !           872: BOOL WINAPI
        !           873: TravellerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
        !           874: {
        !           875:        WORD lw = LOWORD (wParam);
        !           876: 
        !           877:        switch (msg)
        !           878:        {
        !           879:        case WM_INITDIALOG:
        !           880:                {
        !           881:                        int i, index;
        !           882:                        char drive[] = { 0, ':', 0 };
        !           883: 
        !           884:                        SetDefaultUserFont (hwndDlg);
        !           885: 
        !           886:                        SendDlgItemMessage (hwndDlg, IDC_COPY_WIZARD, BM_SETCHECK, 
        !           887:                                                BST_CHECKED, 0);
        !           888: 
        !           889:                        SendDlgItemMessage (hwndDlg, IDC_PREF_OPEN_EXPLORER, BM_SETCHECK, 
        !           890:                                                BST_CHECKED, 0);
        !           891: 
        !           892:                        SendDlgItemMessage (hwndDlg, IDC_AUTORUN_DISABLE, BM_SETCHECK, 
        !           893:                                                BST_CHECKED, 0);
        !           894: 
        !           895:                        SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_RESETCONTENT, 0, 0);
        !           896: 
        !           897:                        index = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_ADDSTRING, 0, (LPARAM) "First available");
        !           898:                        SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETITEMDATA, index, (LPARAM) 0);
        !           899: 
        !           900:                        for (i = 'A'; i <= 'Z'; i++)
        !           901:                        {
        !           902:                                drive[0] = i;
        !           903:                                index = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_ADDSTRING, 0, (LPARAM) drive);
        !           904:                                SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETITEMDATA, index, (LPARAM) i);
        !           905:                        }
        !           906:                
        !           907:                        SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETCURSEL, 0, 0);
        !           908: 
        !           909:                        return 1;
        !           910:                }
        !           911: 
        !           912:        case WM_COMMAND:
        !           913: 
        !           914:                if (lw == IDC_BROWSE_FILES)
        !           915:                {
        !           916:                        char volName[MAX_PATH];
        !           917: 
        !           918:                        if (BrowseFiles (hwndDlg, IDS_OPEN_TITLE, volName, FALSE))
        !           919:                        {
        !           920:                                SetDlgItemText (hwndDlg, IDC_VOLUME_NAME, strchr (volName, '\\') + 1);
        !           921:                        }       
        !           922:                        return 1;
        !           923:                }
        !           924: 
        !           925:                if (lw == IDC_BROWSE_DIRS)
        !           926:                {
        !           927:                        char dstPath[MAX_PATH * 2];
        !           928: 
        !           929:                        if (BrowseDirectories (hwndDlg, IDS_SELECT_DEST_DIR, dstPath))
        !           930:                        {
        !           931:                                SetDlgItemText (hwndDlg, IDC_DIRECTORY, dstPath);
        !           932:                        }       
        !           933:                        return 1;
        !           934:                }
        !           935: 
        !           936:                if (lw == IDCANCEL)
        !           937:                {
        !           938:                        EndDialog (hwndDlg, lw);
        !           939:                        return 1;
        !           940:                }
        !           941: 
        !           942:                if (lw == IDOK)
        !           943:                {
        !           944:                        BOOL copyWizard, bExplore, bCacheInDriver, bAutoRun, bAutoMount, bMountReadOnly;
        !           945:                        char dstDir[MAX_PATH];
        !           946:                        char srcPath[MAX_PATH * 2];
        !           947:                        char dstPath[MAX_PATH * 2];
        !           948:                        char appDir[MAX_PATH];
        !           949:                        char sysDir[MAX_PATH];
        !           950:                        char volName[MAX_PATH];
        !           951:                        char tmpMsg[1024];
        !           952:                        int drive;
        !           953: 
        !           954:                        GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstDir, sizeof dstDir);
        !           955:                        volName[0] = 0;
        !           956:                        GetDlgItemText (hwndDlg, IDC_VOLUME_NAME, volName + 1, sizeof volName);
        !           957:                        
        !           958:                        drive = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_GETCURSEL, 0, 0);
        !           959:                        drive = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_GETITEMDATA, drive, 0);
        !           960: 
        !           961:                        copyWizard = IsButtonChecked (GetDlgItem (hwndDlg, IDC_COPY_WIZARD));
        !           962:                        bExplore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_OPEN_EXPLORER));
        !           963:                        bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_CACHE_PASSWORDS));
        !           964:                        bMountReadOnly = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY));
        !           965:                        bAutoRun = !IsButtonChecked (GetDlgItem (hwndDlg, IDC_AUTORUN_DISABLE));
        !           966:                        bAutoMount = IsButtonChecked (GetDlgItem (hwndDlg, IDC_AUTORUN_MOUNT));
        !           967: 
        !           968:                        if (dstDir[0] == 0)
        !           969:                        {
        !           970:                                SetFocus (GetDlgItem (hwndDlg, IDC_DIRECTORY));
        !           971:                                MessageBox(hwndDlg, getstr (IDS_NO_PATH_SELECTED), lpszTitle, MB_ICONEXCLAMATION);
        !           972:                                return 1;
        !           973:                        }
        !           974: 
        !           975:                        
        !           976:                        if (bAutoMount && volName[1] == 0)
        !           977:                        {
        !           978:                                SetFocus (GetDlgItem (hwndDlg, IDC_VOLUME_NAME));
        !           979:                                MessageBox(hwndDlg, getstr (IDS_NO_FILE_SELECTED), lpszTitle, MB_ICONEXCLAMATION);
        !           980:                                return 1;
        !           981:                        }
        !           982: 
        !           983:                        if (volName[1] != 0)
        !           984:                        {
        !           985:                                volName[0] = '"';
        !           986:                                strcat (volName, "\"");
        !           987:                        }
        !           988: 
        !           989:                        EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
        !           990:                        EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), FALSE);
        !           991: 
        !           992:                        GetModuleFileName (NULL, appDir, sizeof (appDir));
        !           993:                        strrchr (appDir, '\\')[0] = 0;
        !           994: 
        !           995:                        ArrowWaitCursor();
        !           996:                        GetSystemDirectory (sysDir, sizeof (sysDir));
        !           997: 
        !           998:                        sprintf (dstPath, "%s\\TrueCrypt", dstDir);
        !           999:                        CreateDirectory (dstPath, NULL);
        !          1000: 
        !          1001:                        // Main app
        !          1002:                        sprintf (srcPath, "%s\\TrueCrypt.exe", appDir);
        !          1003:                        sprintf (dstPath, "%s\\TrueCrypt\\TrueCrypt.exe", dstDir);
        !          1004:                        if (!TCCopyFile (srcPath, dstPath))
        !          1005:                        {
        !          1006:                                handleWin32Error (hwndDlg);
        !          1007:                                goto stop;
        !          1008:                        }
        !          1009: 
        !          1010:                        // Wizard
        !          1011:                        if (copyWizard)
        !          1012:                        {
        !          1013:                                sprintf (srcPath, "%s\\TrueCrypt Format.exe", appDir);
        !          1014:                                sprintf (dstPath, "%s\\TrueCrypt\\TrueCrypt Format.exe", dstDir);
        !          1015:                                if (!TCCopyFile (srcPath, dstPath))
        !          1016:                                {
        !          1017:                                        handleWin32Error (hwndDlg);
        !          1018:                                        goto stop;
        !          1019:                                }
        !          1020:                        }
        !          1021: 
        !          1022:                        // Driver
        !          1023:                        sprintf (srcPath, "%s\\Drivers\\truecrypt.sys", sysDir);
        !          1024:                        sprintf (dstPath, "%s\\TrueCrypt\\truecrypt.sys", dstDir);
        !          1025:                        if (!TCCopyFile (srcPath, dstPath))
        !          1026:                        {
        !          1027:                                handleWin32Error (hwndDlg);
        !          1028:                                goto stop;
        !          1029:                        }
        !          1030: 
        !          1031:                        // AutoRun
        !          1032:                        if (bAutoRun)
        !          1033:                        {
        !          1034:                                FILE *af;
        !          1035:                                char autoMount[100];
        !          1036:                                char openApp[100];
        !          1037:                                char driveLetter[] = { ' ', '/', 'l', drive, 0 };
        !          1038: 
        !          1039:                                sprintf (dstPath, "%s\\autorun.inf", dstDir);
        !          1040:                                af = fopen (dstPath, "w");
        !          1041: 
        !          1042:                                if (af == NULL)
        !          1043:                                {
        !          1044:                                        MessageBox (hwndDlg, "Cannot create autorun.inf", lpszTitle, MB_ICONERROR);
        !          1045:                                        goto stop;
        !          1046:                                }
        !          1047: 
        !          1048:                                fprintf (af, "[autorun]\n");
        !          1049: 
        !          1050:                                sprintf (autoMount, "TrueCrypt\\TrueCrypt.exe /q /a%s%s%s%s /m rm /v %s",
        !          1051:                                        drive > 0 ? driveLetter : "",
        !          1052:                                        bExplore ? " /e" : "",
        !          1053:                                        bCacheInDriver ? " /cy" : "",
        !          1054:                                        bMountReadOnly ? " /m ro" : "",
        !          1055:                                        volName);
        !          1056: 
        !          1057:                                sprintf (openApp, "TrueCrypt\\TrueCrypt.exe%s%s%s%s /m rm%s%s",
        !          1058:                                        drive > 0 ? driveLetter : "",
        !          1059:                                        bExplore ? " /e" : "",
        !          1060:                                        bCacheInDriver ? " /cy" : "",
        !          1061:                                        bMountReadOnly ? " /m ro" : "",
        !          1062:                                        volName[0] != 0 ? " /v " : "",
        !          1063:                                        volName[0] != 0 ? volName : "");
        !          1064: 
        !          1065:                                fprintf (af, "open=%s\n", 
        !          1066:                                        bAutoMount ? autoMount : openApp);
        !          1067: 
        !          1068:                                fprintf (af, "shell=%s\n", 
        !          1069:                                        bAutoMount ? "mount" : "open");
        !          1070: 
        !          1071:                                fprintf (af, "action=%s\n", 
        !          1072:                                        bAutoMount ? "Mount TrueCrypt Volume" : "Start TrueCrypt");
        !          1073: 
        !          1074:                                fprintf (af, "shell\\open\\command=%s\nshell\\open=TrueCrypt Start\n", openApp);
        !          1075:                                
        !          1076:                                if (volName[0] != 0)
        !          1077:                                        fprintf (af, "shell\\mount\\command=%s\nshell\\mount=TrueCrypt Mount\n", autoMount);
        !          1078: 
        !          1079:                                fprintf (af, "shell\\dismount\\command=TrueCrypt\\TrueCrypt.exe /q /d\nshell\\dismount=TrueCrypt Dismount All\n");
        !          1080: 
        !          1081:                                fclose (af);
        !          1082:                        }
        !          1083:                        strcpy (tmpMsg, getstr (IDS_TRAVELLER_DISK_CREATED));
        !          1084:                        strcat (tmpMsg, getstr (IDS_TRAVELLER_DISK_CREATED2));
        !          1085:                        MessageBox (hwndDlg, tmpMsg, lpszTitle, MB_ICONINFORMATION);
        !          1086: 
        !          1087: stop:
        !          1088:                        NormalCursor ();
        !          1089:                        EnableWindow (GetDlgItem (hwndDlg, IDOK), TRUE);
        !          1090:                        EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), TRUE);
        !          1091: 
        !          1092:                        return 1;
        !          1093:                }
        !          1094:                return 0;
        !          1095:        }
        !          1096: 
        !          1097:        return 0;
        !          1098: }
        !          1099: 
        !          1100: 
1.1       root     1101: void
                   1102: BuildTree (HWND hTree)
                   1103: {
                   1104:        HIMAGELIST hList;
                   1105:        HBITMAP hBitmap, hBitmapMask;
                   1106:        LVCOLUMN lvCol;
                   1107:        SendMessage(hTree,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
                   1108:                LVS_EX_FULLROWSELECT
                   1109:                |LVS_EX_HEADERDRAGDROP 
                   1110:                //|LVS_EX_GRIDLINES 
                   1111:                //|LVS_EX_TWOCLICKACTIVATE 
                   1112:                ); 
                   1113: 
                   1114:        memset(&lvCol,0,sizeof(lvCol)); 
                   1115: 
                   1116:        lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;  
                   1117:        lvCol.pszText="Drive";                           
1.1.1.5   root     1118:        lvCol.cx=37;
1.1       root     1119:        lvCol.fmt = LVCFMT_COL_HAS_IMAGES|LVCFMT_LEFT ;
                   1120:        SendMessage (hTree,LVM_INSERTCOLUMN,0,(LPARAM)&lvCol);
                   1121: 
                   1122:        lvCol.pszText="Volume";  
1.1.1.5   root     1123:        lvCol.cx=263;           
1.1       root     1124:        lvCol.fmt = LVCFMT_LEFT;
                   1125:        SendMessage (hTree,LVM_INSERTCOLUMN,1,(LPARAM)&lvCol);
                   1126: 
                   1127:        lvCol.pszText="Size";  
1.1.1.5   root     1128:        lvCol.cx=55;
1.1       root     1129:        lvCol.fmt = LVCFMT_RIGHT;
                   1130:        SendMessage (hTree,LVM_INSERTCOLUMN,2,(LPARAM)&lvCol);
                   1131: 
1.1.1.5   root     1132:        lvCol.pszText="Encryption Algorithm";  
                   1133:        lvCol.cx=117;
1.1       root     1134:        lvCol.fmt = LVCFMT_LEFT;
                   1135:        SendMessage (hTree,LVM_INSERTCOLUMN,3,(LPARAM)&lvCol);
                   1136: 
1.1.1.5   root     1137:        lvCol.pszText="Type";  
                   1138:        lvCol.cx=47;
                   1139:        lvCol.fmt = LVCFMT_LEFT;
                   1140:        SendMessage (hTree,LVM_INSERTCOLUMN,4,(LPARAM)&lvCol);
                   1141: 
1.1       root     1142:        hBitmap = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON));
                   1143:        if (hBitmap == NULL)
                   1144:                return;
                   1145:        hBitmapMask = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON_MASK));
                   1146: 
                   1147:        hList = ImageList_Create (16, 12, ILC_COLOR8|ILC_MASK, 2, 2);
                   1148:        if (ImageList_Add (hList, hBitmap, hBitmapMask) == -1)
                   1149:        {
                   1150:                DeleteObject (hBitmap);
                   1151:                return;
                   1152:        }
                   1153:        else
                   1154:                DeleteObject (hBitmap);
                   1155: 
                   1156:        ListView_SetImageList (hTree, hList, LVSIL_NORMAL); 
                   1157:        ListView_SetImageList (hTree, hList, LVSIL_SMALL);
                   1158: 
                   1159:        LoadDriveLetters (hTree, 0);
                   1160: }
                   1161: 
                   1162: LPARAM
                   1163: GetSelectedLong (HWND hTree)
                   1164: {
                   1165:        int hItem = ListView_GetSelectionMark (hTree);
                   1166:        LVITEM item;
                   1167: 
1.1.1.5   root     1168:        if (nSelectedDriveIndex >= 0)
1.1       root     1169:                hItem = nSelectedDriveIndex;
                   1170: 
                   1171:        memset(&item, 0, sizeof(LVITEM));
                   1172:        item.mask = LVIF_PARAM;
                   1173:        item.iItem = hItem;
                   1174: 
                   1175:        if (ListView_GetItem (hTree, &item) == FALSE)
                   1176:                return MAKELONG (0xffff, 0xffff);
                   1177:        else
                   1178:                return item.lParam;
                   1179: }
                   1180: 
                   1181: LPARAM
                   1182: GetItemLong (HWND hTree, int itemNo)
                   1183: {
                   1184:        LVITEM item;
                   1185: 
                   1186:        memset(&item, 0, sizeof(LVITEM));
                   1187:        item.mask = LVIF_PARAM;
                   1188:        item.iItem = itemNo;
                   1189: 
                   1190:        if (ListView_GetItem (hTree, &item) == FALSE)
                   1191:                return MAKELONG (0xffff, 0xffff);
                   1192:        else
                   1193:                return item.lParam;
                   1194: }
                   1195: 
                   1196: static int AskUserPassword (HWND hwndDlg, char *password)
                   1197: {
                   1198:        int result = DialogBoxParam (hInst, 
                   1199:                MAKEINTRESOURCE (IDD_PASSWORD_DLG), hwndDlg,
                   1200:                (DLGPROC) PasswordDlgProc, (LPARAM) password);
                   1201: 
                   1202:        if (result != IDOK)
                   1203:                *password = 0;
                   1204: 
                   1205:        return result == IDOK;
                   1206: }
                   1207: 
                   1208: // GUI actions
                   1209: 
                   1210: static void Mount (HWND hwndDlg)
                   1211: {
                   1212:        char szPassword[MAX_PASSWORD + 1];
                   1213:        int mounted = 0;
                   1214:        int nDosDriveNo = HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A';
                   1215: 
                   1216:        burn (szPassword, sizeof (szPassword));
                   1217:        GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName,
                   1218:                sizeof (szFileName));
                   1219: 
                   1220:        if (strlen(szFileName) == 0)
                   1221:                return;
                   1222: 
                   1223:        if (IsMountedVolume (szFileName))
                   1224:        {
                   1225:                MessageBox(0, getstr (IDS_ALREADY_MOUNTED), lpszTitle, MB_ICONASTERISK);
                   1226:                return;
                   1227:        }
                   1228: 
                   1229:        // First try cached passwords and if they fail ask user for a new one
                   1230:        ArrowWaitCursor ();
1.1.1.6 ! root     1231:        mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, "", bCacheInDriver, bForceMount, &mountOptions, FALSE);
1.1       root     1232:        NormalCursor ();
                   1233:        
1.1.1.5   root     1234:        while (mounted == 0)
1.1       root     1235:        {
                   1236:                if (!AskUserPassword (hwndDlg, szPassword))
                   1237:                        return;
                   1238: 
                   1239:                ArrowWaitCursor ();
1.1.1.6 ! root     1240:                mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, szPassword, bCacheInDriver, bForceMount, &mountOptions, FALSE);
1.1       root     1241:                NormalCursor ();
                   1242:        }
                   1243: 
1.1.1.5   root     1244:        if (mounted > 0)
1.1       root     1245:        {
                   1246:                if (bBeep == TRUE)
                   1247:                        MessageBeep (MB_OK);
                   1248: 
                   1249:                RefreshMainDlg(hwndDlg);
                   1250: 
                   1251:                if (bExplore == TRUE)
                   1252:                {       
                   1253:                        ArrowWaitCursor();
                   1254:                        OpenVolumeExplorerWindow (nDosDriveNo);
                   1255:                        NormalCursor();
                   1256:                }
                   1257:        }
                   1258: 
                   1259:        burn (szPassword, sizeof (szPassword));
                   1260:        return;
                   1261: }
                   1262: 
                   1263: 
1.1.1.2   root     1264: static void Dismount (HWND hwndDlg, int nDosDriveNo)
1.1       root     1265: {
1.1.1.5   root     1266:        ArrowWaitCursor ();
1.1       root     1267: 
1.1.1.2   root     1268:        if (nDosDriveNo == 0)
                   1269:                nDosDriveNo = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A');
1.1       root     1270: 
1.1.1.5   root     1271:        if (bCloseDismountedWindows)
1.1       root     1272:        {
1.1.1.6 ! root     1273:                CloseVolumeExplorerWindows (hwndDlg, nDosDriveNo);
1.1       root     1274:        }
                   1275: 
1.1.1.5   root     1276:        if (UnmountVolume (hwndDlg, nDosDriveNo, bForceUnmount))
                   1277:        {
1.1.1.6 ! root     1278:                if (bBeep == TRUE)
        !          1279:                        MessageBeep (MB_OK);
1.1.1.5   root     1280:                RefreshMainDlg (hwndDlg);
1.1       root     1281:        }
                   1282: 
1.1.1.5   root     1283:        NormalCursor ();
1.1       root     1284:        return;
                   1285: }
                   1286: 
1.1.1.5   root     1287: static void DismountAll (HWND hwndDlg, BOOL forceUnmount)
1.1       root     1288: {
1.1.1.5   root     1289:        MOUNT_LIST_STRUCT mountList;
                   1290:        DWORD dwResult;
                   1291:        UNMOUNT_STRUCT unmount;
1.1       root     1292:        BOOL bResult;
1.1.1.5   root     1293:        unsigned __int32 prevMountedDrives = 0;
1.1.1.6 ! root     1294:        int dismountMaxRetries = UNMOUNT_MAX_AUTO_RETRIES;
1.1.1.5   root     1295:        int i;
1.1       root     1296: 
1.1.1.5   root     1297: retry:
1.1       root     1298:        ArrowWaitCursor();
                   1299: 
1.1.1.5   root     1300:        DeviceIoControl (hDriver, MOUNT_LIST, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
                   1301:        prevMountedDrives = mountList.ulMountedDrives;
                   1302: 
                   1303:        for (i = 0; i < 26; i++)
1.1       root     1304:        {
1.1.1.5   root     1305:                if (mountList.ulMountedDrives & (1 << i))
1.1       root     1306:                {
1.1.1.5   root     1307:                        if (bCloseDismountedWindows)
1.1.1.6 ! root     1308:                                CloseVolumeExplorerWindows (hwndDlg, i);
1.1       root     1309:                }
1.1.1.5   root     1310:        }
1.1       root     1311: 
1.1.1.5   root     1312:        unmount.nDosDriveNo = 0;
                   1313:        unmount.ignoreOpenFiles = forceUnmount;
1.1       root     1314: 
1.1.1.6 ! root     1315:        do
        !          1316:        {
        !          1317:                bResult = DeviceIoControl (hDriver, UNMOUNT_ALL, &unmount,
        !          1318:                        sizeof (unmount), &unmount, sizeof (unmount), &dwResult, NULL);
        !          1319: 
        !          1320:                if (bResult == FALSE)
        !          1321:                {
        !          1322:                        NormalCursor();
        !          1323:                        handleWin32Error (hwndDlg);
        !          1324:                        return;
        !          1325:                }
1.1       root     1326: 
1.1.1.6 ! root     1327:                if (unmount.nReturnCode == ERR_FILES_OPEN)
        !          1328:                        Sleep (UNMOUNT_AUTO_RETRY_DELAY);
        !          1329:                else
        !          1330:                        break;
1.1       root     1331: 
1.1.1.6 ! root     1332:        } while (--dismountMaxRetries > 0);
1.1       root     1333: 
1.1.1.5   root     1334:        DeviceIoControl (hDriver, MOUNT_LIST, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
1.1.1.6 ! root     1335:        BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, prevMountedDrives & ~mountList.ulMountedDrives);
1.1       root     1336: 
1.1.1.5   root     1337:        RefreshMainDlg(hwndDlg);
                   1338:        NormalCursor();
1.1       root     1339: 
1.1.1.5   root     1340:        if (unmount.nReturnCode != 0)
                   1341:        {
                   1342:                if (unmount.nReturnCode == ERR_FILES_OPEN)
                   1343:                {
                   1344:                        if (IDYES == MessageBox (hwndDlg, getstr (IDS_UNMOUNTALL_LOCK_FAILED),
                   1345:                                lpszTitle, MB_YESNO | MB_DEFBUTTON2 | MB_ICONEXCLAMATION))
1.1       root     1346:                        {
1.1.1.5   root     1347:                                forceUnmount = TRUE;
                   1348:                                goto retry;
1.1       root     1349:                        }
1.1.1.5   root     1350: 
                   1351:                        return;
1.1       root     1352:                }
1.1.1.5   root     1353:                
                   1354:                MessageBox (hwndDlg, getstr (IDS_UNMOUNT_FAILED), lpszTitle, MB_ICONERROR);
1.1       root     1355:        }
                   1356:        else
                   1357:        {
1.1.1.5   root     1358:                if (bBeep == TRUE)
                   1359:                        MessageBeep (MB_OK);
1.1       root     1360:        }
                   1361: }
                   1362: 
1.1.1.6 ! root     1363: static void MountAllDevices (HWND hwndDlg)
1.1       root     1364: {
                   1365:        HWND driveList = GetDlgItem (hwndDlg, IDC_DRIVELIST);
                   1366:        int i, n, selDrive = ListView_GetSelectionMark (driveList);
                   1367:        char szPassword[MAX_PASSWORD + 1];
1.1.1.5   root     1368:        int mounted;
                   1369:        BOOL shared = FALSE;
1.1       root     1370: 
1.1.1.6 ! root     1371:        if (selDrive == -1) selDrive = 0;
        !          1372: 
        !          1373:        mountOptions = defaultMountOptions;
        !          1374: 
1.1       root     1375:        // User is always asked for password as we can't tell 
                   1376:        // for sure if it is needed or not
                   1377:        burn (szPassword, sizeof (szPassword));
                   1378:        if (!AskUserPassword (hwndDlg, szPassword))
                   1379:                return;
                   1380: 
                   1381:        ArrowWaitCursor();
                   1382:        
                   1383:        for (i = 0; i < 64; i++)
                   1384:        {
1.1.1.5   root     1385:                // Include partition 0 (whole disk)
                   1386:                for (n = 0; n <= 32; n++)
1.1       root     1387:                {
                   1388:                        char szFileName[TC_MAX_PATH];
                   1389:                        OPEN_TEST_STRUCT driver;
1.1.1.6 ! root     1390:                        BOOL mounted;
1.1       root     1391: 
                   1392:                        sprintf (szFileName, "\\Device\\Harddisk%d\\Partition%d", i, n);
1.1.1.6 ! root     1393: 
        !          1394:                        mounted = IsMountedVolume (szFileName);
        !          1395: 
        !          1396:                        // Skip other partitions of the disk if partition0 (whole disk) is mounted
        !          1397:                        if (n == 0 && mounted)
        !          1398:                                break;
        !          1399: 
        !          1400:                        if (!mounted && OpenDevice (szFileName, &driver) == TRUE)
1.1       root     1401:                        {       
                   1402:                                int nDosDriveNo;
                   1403: 
                   1404:                                while (LOWORD (GetItemLong (driveList, selDrive)) != 0xffff)
                   1405:                                {
                   1406:                                        if(LOWORD (GetItemLong (driveList, selDrive)) != VFREE)
                   1407:                                        {
                   1408:                                                selDrive++;
                   1409:                                                continue;
                   1410:                                        }
                   1411:                                        nDosDriveNo = HIWORD(GetItemLong (driveList, selDrive)) - 'A';
                   1412:                                        break;
                   1413:                                }
                   1414: 
                   1415:                                if (LOWORD (GetItemLong (driveList, selDrive)) == 0xffff)
                   1416:                                        goto ret;
                   1417: 
                   1418:                                // First try user password then cached passwords
1.1.1.6 ! root     1419:                                if ((mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, szPassword, bCacheInDriver, bForceMount, &mountOptions, TRUE)) > 0
        !          1420:                                        || (mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, "", bCacheInDriver, bForceMount, &mountOptions, TRUE)) > 0)
1.1       root     1421:                                {
1.1.1.5   root     1422:                                        if (mounted == 2)
                   1423:                                                shared = TRUE;
                   1424: 
1.1       root     1425:                                        LoadDriveLetters (driveList, (HIWORD (GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), selDrive))));
                   1426:                                        selDrive++;
                   1427: 
                   1428:                                        if (bExplore == TRUE)
                   1429:                                        {       
                   1430:                                                ArrowWaitCursor();
                   1431:                                                OpenVolumeExplorerWindow (nDosDriveNo);
                   1432:                                                NormalCursor();
                   1433:                                        }
1.1.1.6 ! root     1434: 
        !          1435:                                        // Skip other partitions of the disk if partition0 (whole disk) has been mounted
        !          1436:                                        if (n == 0)
        !          1437:                                                break;
1.1       root     1438:                                }
                   1439:                        }
1.1.1.6 ! root     1440:                        else if (n == 0)
        !          1441:                                break;
1.1       root     1442:                }
                   1443:        }
                   1444: 
1.1.1.5   root     1445:        if (shared)
                   1446:                MessageBox (hwndDlg, getstr (IDS_DEVICE_IN_USE_INFO), lpszTitle, MB_ICONEXCLAMATION);
                   1447: 
1.1       root     1448: ret:
                   1449:        burn (szPassword, sizeof (szPassword));
                   1450:        EnableDisableButtons (hwndDlg);
                   1451:        NormalCursor();
                   1452: }
                   1453: 
                   1454: static void ChangePassword (HWND hwndDlg)
                   1455: {
                   1456:        int result;
                   1457:        
                   1458:        GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, sizeof (szFileName));
                   1459:        if (IsMountedVolume (szFileName))
                   1460:        {
                   1461:                MessageBox (hwndDlg, getstr (IDS_MOUNTED_NOPWCHANGE), lpszTitle, MB_ICONEXCLAMATION);
                   1462:                return;
                   1463:        }
                   1464: 
                   1465:        result = DialogBox (hInst, MAKEINTRESOURCE (IDD_PASSWORDCHANGE_DLG), hwndDlg,
                   1466:                (DLGPROC) PasswordChangeDlgProc);
                   1467: 
                   1468:        if (result == IDOK)
                   1469:        {
                   1470:                HWND tmp = GetDlgItem (hwndDlg, IDC_PASSWORD);
                   1471:                MessageBox (hwndDlg, getstr (IDS_PASSWORD_CHANGED), lpszTitle, MB_ICONASTERISK);
                   1472:                SetFocus (tmp);
                   1473:        }
                   1474: }
                   1475: 
                   1476: static void SelectContainer (HWND hwndDlg)
                   1477: {
1.1.1.5   root     1478:        if (BrowseFiles (hwndDlg, IDS_OPEN_TITLE, szFileName, bHistory) == FALSE)
1.1       root     1479:                return;
                   1480: 
                   1481:        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
                   1482:        EnableDisableButtons (hwndDlg);
1.1.1.6 ! root     1483:        SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1       root     1484: }
                   1485: 
                   1486: static void SelectPartition (HWND hwndDlg)
                   1487: {
                   1488:        int nResult = DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_RAWDEVICES_DLG), hwndDlg,
                   1489:                (DLGPROC) RawDevicesDlgProc, (LPARAM) & szFileName[0]);
                   1490:        if (nResult == IDOK)
                   1491:        {
                   1492:                AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
                   1493:                EnableDisableButtons (hwndDlg);
1.1.1.6 ! root     1494:                SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1       root     1495:        }
                   1496: }
                   1497: 
                   1498: static void WipeCache (HWND hwndDlg)
                   1499: {
                   1500:        DWORD dwResult;
                   1501:        BOOL bResult;
                   1502: 
                   1503:        bResult = DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
                   1504: 
                   1505:        if (bResult == FALSE)
                   1506:                handleWin32Error (hwndDlg);
                   1507:        else
                   1508:        {
                   1509:                EnableDisableButtons (hwndDlg);
                   1510: 
                   1511:                if (bQuiet == FALSE)
                   1512:                        MessageBox (hwndDlg, getstr (IDS_WIPE_CACHE), lpszTitle, MB_ICONINFORMATION);
                   1513:        }
                   1514: }
                   1515: 
1.1.1.5   root     1516: static void Benchmark (HWND hwndDlg)
                   1517: {
                   1518:        int nResult = DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_BENCHMARK_DLG), hwndDlg,
                   1519:                (DLGPROC) BenchmarkDlgProc, (LPARAM) NULL);
                   1520: }
1.1       root     1521: 
                   1522: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
                   1523:    should return nonzero if it processes the message, and zero if it does
                   1524:    not. - see DialogProc */
                   1525: BOOL CALLBACK
                   1526: MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
                   1527: {
                   1528:        WORD lw = LOWORD (wParam);
                   1529:        WORD hw = HIWORD (wParam);
                   1530:        if (lParam);            /* remove warning */
                   1531: 
                   1532:        switch (uMsg)
                   1533:        {
                   1534: 
                   1535:        case WM_INITDIALOG:
                   1536:                {
1.1.1.2   root     1537:                        ExtractCommandLine (hwndDlg, (char *) lParam);
                   1538: 
                   1539:                        if (!bQuiet) LoadSettings (hwndDlg);
1.1       root     1540: 
                   1541:                        /* Call the common dialog init code */
                   1542:                        InitDialog (hwndDlg);
                   1543:                        SetDefaultUserFont (hwndDlg);
                   1544: 
1.1.1.6 ! root     1545:                        DragAcceptFiles (hwndDlg, TRUE);
        !          1546: 
1.1       root     1547:                        SendMessage (GetDlgItem (hwndDlg, IDC_VOLUME), CB_LIMITTEXT, TC_MAX_PATH, 0);
                   1548: 
                   1549:                        SendMessage (GetDlgItem (hwndDlg, IDC_NO_DRIVES_STATIC), WM_SETFONT, (WPARAM) hBoldFont, (LPARAM) TRUE);
                   1550:                        SetWindowText (hwndDlg, lpszTitle);
                   1551: 
                   1552:                        BuildTree (GetDlgItem (hwndDlg, IDC_DRIVELIST));
                   1553: 
                   1554:                        if (*szDriveLetter != 0)
                   1555:                        {
                   1556:                                SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST), *szDriveLetter);
                   1557: 
                   1558:                                if(nSelectedDriveIndex > SendMessage (GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_GETITEMCOUNT, 0, 0)/2) 
                   1559:                                        SendMessage(GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_SCROLL, 0, 1000);
                   1560:                        }
                   1561: 
                   1562:                        SendMessage (GetDlgItem (hwndDlg, IDC_NO_HISTORY), BM_SETCHECK, bHistory ? BST_UNCHECKED : BST_CHECKED, 0);
1.1.1.6 ! root     1563:                        EnableMenuItem (GetMenu (hwndDlg), IDM_TRAVELLER, IsNonInstallMode() ? MF_GRAYED : MF_ENABLED);
1.1       root     1564: 
                   1565:                        EnableDisableButtons (hwndDlg);
                   1566: 
                   1567:                        if (bWipe == TRUE)
                   1568:                        {
1.1.1.2   root     1569:                                WipeCache (hwndDlg);
1.1       root     1570:                        }
                   1571: 
1.1.1.2   root     1572:                        // Automount
1.1.1.6 ! root     1573:                        if (bAuto == TRUE)
1.1       root     1574:                        {
1.1.1.5   root     1575:                                // No drive letter specified on command line
                   1576:                                if (commandLineDrive == 0)
                   1577:                                        szDriveLetter[0] = GetFirstAvailableDrive () + 'A';
                   1578: 
1.1.1.6 ! root     1579:                                if (bAutoMountDevices)
        !          1580:                                {
        !          1581:                                        defaultMountOptions = mountOptions;
        !          1582:                                        MountAllDevices (hwndDlg);
        !          1583:                                }
        !          1584:                                else if (!IsMountedVolume (szFileName))
1.1.1.2   root     1585:                                {
                   1586:                                        BOOL mounted;
                   1587: 
                   1588:                                        // Cached password
1.1.1.6 ! root     1589:                                        mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, "", bCacheInDriver, bForceMount, &mountOptions, FALSE);
1.1.1.2   root     1590: 
                   1591:                                        if (!mounted && commandLinePassword[0] != 0)
                   1592:                                        {
                   1593:                                                // Command line password
1.1.1.6 ! root     1594:                                                mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, commandLinePassword, bCacheInDriver, bForceMount, &mountOptions, TRUE);
1.1.1.2   root     1595:                                                burn (commandLinePassword, sizeof (commandLinePassword));
                   1596:                                        }
                   1597: 
                   1598:                                        // Ask user for password
                   1599:                                        while (!mounted)
                   1600:                                        {
                   1601:                                                char szPassword[MAX_PASSWORD + 1];
                   1602: 
                   1603:                                                if (!AskUserPassword (hwndDlg, szPassword))
                   1604:                                                        break;
                   1605: 
                   1606:                                                ArrowWaitCursor ();
1.1.1.6 ! root     1607:                                                mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, szPassword, bCacheInDriver, bForceMount, &mountOptions, FALSE);
1.1.1.2   root     1608:                                                burn (szPassword, sizeof (szPassword));
                   1609:                                                NormalCursor ();
                   1610:                                        }
                   1611: 
1.1.1.5   root     1612:                                        if (mounted > 0)
1.1.1.2   root     1613:                                        {
                   1614:                                                if (bBeep == TRUE) MessageBeep (MB_OK);
                   1615:                                                if (bExplore == TRUE) OpenVolumeExplorerWindow (szDriveLetter[0] - 'A');
                   1616:                                                if (bQuiet) ExitProcess (0);
                   1617:                                        }
                   1618:                                        else if (bQuiet) ExitProcess (1);
                   1619:                                        
                   1620:                                        RefreshMainDlg(hwndDlg);
                   1621:                                }
1.1.1.5   root     1622:                                else if (bExplore == TRUE) OpenVolumeExplorerWindow (szDriveLetter[0] - 'A');
1.1       root     1623:                        }
                   1624: 
1.1.1.5   root     1625:                        if (cmdUnmountDrive > 0)
                   1626:                                Dismount (hwndDlg, (char)toupper(szDriveLetter[0]) - 'A');
                   1627:                        else if (cmdUnmountDrive == -1)
                   1628:                                DismountAll (hwndDlg, bForceUnmount);
                   1629: 
1.1.1.3   root     1630:                        if (bQuiet) ExitProcess (0);
                   1631: 
1.1       root     1632:                        SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
                   1633:                }
                   1634:                return 0;
                   1635: 
                   1636:        case WM_SYSCOMMAND:
                   1637:                if (lw == IDC_ABOUT)
                   1638:                {
                   1639:                        DialogBox (hInst, MAKEINTRESOURCE (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
                   1640:                        return 1;
                   1641:                }
                   1642:                return 0;
                   1643: 
                   1644:        case WM_HELP:
                   1645:                OpenPageHelp (hwndDlg);
                   1646:                return 1;
                   1647: 
                   1648:        case WM_NOTIFY:
                   1649:                // Single click in drive list
                   1650:                if (((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED ))
                   1651:                {
                   1652:                        nSelectedDriveIndex = ((LPNMLISTVIEW) lParam)->iItem;
                   1653:                        EnableDisableButtons (hwndDlg);
                   1654: 
                   1655:                        return 1;
                   1656:                }
                   1657: 
                   1658:                // Double click in drive list
                   1659:                if (((LPNMHDR) lParam)->code == LVN_ITEMACTIVATE)
                   1660:                {
                   1661:                        int state = GetItemLong(GetDlgItem (hwndDlg, IDC_DRIVELIST), ((LPNMITEMACTIVATE)lParam)->iItem );
                   1662:                        nSelectedDriveIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
                   1663:                        if (LOWORD(state) == VMOUNTED)
                   1664:                        {
                   1665:                                // Open explorer window for mounted volume
                   1666:                                ArrowWaitCursor ();
                   1667:                                OpenVolumeExplorerWindow (HIWORD(state) - 'A');
                   1668:                                NormalCursor ();
                   1669:                        }
                   1670:                        else if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VFREE)
                   1671:                        {
                   1672:                                Mount (hwndDlg);
                   1673:                        }
                   1674:                }
                   1675:                return 0;
                   1676: 
                   1677:        case WM_ERASEBKGND:
                   1678:                return 0;
                   1679: 
                   1680:        case WM_COMMAND:
                   1681: 
                   1682:                if (lw == IDCANCEL)
                   1683:                {
                   1684:                        EndMainDlg (hwndDlg);
                   1685:                        return 1;
                   1686:                }
                   1687: 
                   1688:                if (lw == IDHELP || lw == IDM_HELP)
                   1689:                {
                   1690:                        OpenPageHelp (hwndDlg);
                   1691:                        return 1;
                   1692:                }
                   1693: 
                   1694:                if (lw == IDM_ABOUT || lw == IDB_LOGO)
                   1695:                {
                   1696:                        DialogBox (hInst, MAKEINTRESOURCE (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
                   1697:                        return 1;
                   1698:                }
                   1699: 
1.1.1.6 ! root     1700:                if ((lw == IDOK || lw == ID_MOUNT_VOLUME || lw == IDM_MOUNT_VOLUME_OPTIONS) 
1.1       root     1701:                        && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VFREE)
                   1702:                {
1.1.1.6 ! root     1703:                        mountOptions = defaultMountOptions;
        !          1704: 
        !          1705:                        if (lw == IDM_MOUNT_VOLUME_OPTIONS || GetAsyncKeyState (VK_CONTROL) < 0)
        !          1706:                        {
        !          1707:                                if (IDCANCEL == DialogBoxParam (hInst, 
        !          1708:                                        MAKEINTRESOURCE (IDD_MOUNT_OPTIONS), hwndDlg,
        !          1709:                                        (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions))
        !          1710:                                        return 1;
        !          1711:                        }
1.1       root     1712: 
                   1713:                        Mount (hwndDlg);
                   1714:                        return 1;
                   1715:                }
                   1716: 
                   1717:                if ((lw == IDOK || lw == ID_MOUNT_VOLUME || lw == IDC_MOUNTALL) 
                   1718:                        && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == 0xffff)
                   1719:                {
1.1.1.5   root     1720:                        MessageBox (hwndDlg, "Please select a free drive letter from the list.","TrueCrypt", MB_ICONEXCLAMATION);
1.1       root     1721:                        return 1;
                   1722:                }
                   1723: 
                   1724:                if (lw == IDOK && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VMOUNTED
                   1725:                        || lw == ID_UNMOUNT_VOLUME)
                   1726:                {
1.1.1.2   root     1727:                        Dismount (hwndDlg, 0);
1.1       root     1728:                        return 1;
                   1729:                }
                   1730: 
                   1731:                if (lw == IDUNMOUNTALL)
                   1732:                {
1.1.1.5   root     1733:                        DismountAll (hwndDlg, bForceUnmount);
1.1       root     1734:                        return 1;
                   1735:                }
                   1736: 
                   1737:                if (lw == IDC_MOUNTALL)
                   1738:                {
1.1.1.6 ! root     1739:                        MountAllDevices (hwndDlg);
1.1       root     1740:                        return 1;
                   1741:                }
                   1742:                
                   1743:                if (lw == IDC_BROWSE_FILES)
                   1744:                {
                   1745:                        SelectContainer (hwndDlg);
                   1746:                        return 1;
                   1747:                }
                   1748: 
                   1749:                if (lw == IDC_BROWSE_DEVICES)
                   1750:                {
                   1751:                        SelectPartition (hwndDlg);
                   1752:                        return 1;
                   1753:                }
                   1754: 
                   1755:                if (lw == IDC_CHANGE_PASSWORD)
                   1756:                {
                   1757:                        ChangePassword (hwndDlg);
                   1758:                        return 1;
                   1759:                }
                   1760: 
                   1761:                if (lw == IDC_WIPE_CACHE)
                   1762:                {
                   1763:                        WipeCache (hwndDlg);
                   1764:                        return 1;
                   1765:                }
                   1766: 
                   1767:                if (lw == IDC_CLEAR_HISTORY)
                   1768:                {
                   1769:                        ClearCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
                   1770:                        DumpCombo (GetDlgItem (hwndDlg, IDC_VOLUME), "LastMountedVolume", TRUE);
                   1771:                        EnableDisableButtons (hwndDlg);
                   1772:                        return 1;
                   1773:                }
                   1774: 
                   1775:                if (lw == IDC_CREATE_VOLUME)
                   1776:                {
                   1777:                        char t[TC_MAX_PATH];
                   1778:                        char *tmp;
                   1779: 
                   1780:                        GetModuleFileName (NULL, t, sizeof (t));
                   1781:                        tmp = strrchr (t, '\\');
                   1782:                        if (tmp)
                   1783:                        {
                   1784:                                strcpy (++tmp, "TrueCrypt Format.exe");
                   1785:                                ShellExecute (NULL, "open", t, NULL, NULL, SW_SHOWNORMAL);
                   1786:                        }
                   1787:                        return 1;
                   1788:                }
                   1789: 
1.1.1.3   root     1790:                if (lw == ID_LICENSE)
                   1791:                {
                   1792:                        char t[TC_MAX_PATH];
                   1793:                        char *tmp;
                   1794: 
                   1795:                        GetModuleFileName (NULL, t, sizeof (t));
                   1796:                        tmp = strrchr (t, '\\');
                   1797:                        if (tmp)
                   1798:                        {
                   1799:                                strcpy (++tmp, "license.txt");
                   1800:                                ShellExecute (NULL, "open", t, NULL, NULL, SW_SHOWNORMAL);
                   1801:                        }
                   1802:                        return 1;
                   1803:                }
                   1804:        
1.1       root     1805:                if (lw == ID_WEBSITE)
                   1806:                {
1.1.1.5   root     1807:                        char tmpstr [256];
                   1808: 
                   1809:                        sprintf (tmpstr, "http://truecrypt.sourceforge.net/applink.php?version=%s", VERSION_STRING);
                   1810:                        ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
                   1811:                        return 1;
                   1812:                }
                   1813: 
                   1814:                if (lw == ID_FORUMS)
                   1815:                {
                   1816:                        char tmpstr [256];
                   1817: 
                   1818:                        sprintf (tmpstr, "http://truecrypt.sourceforge.net/applink.php?version=%s&dest=forum", VERSION_STRING);
                   1819:                        ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
1.1       root     1820:                        return 1;
                   1821:                }
1.1.1.3   root     1822: 
1.1.1.6 ! root     1823:                if (lw == IDM_FAQ)
        !          1824:                {
        !          1825:                        char tmpstr [256];
        !          1826: 
        !          1827:                        sprintf (tmpstr, "http://truecrypt.sourceforge.net/applink.php?version=%s&dest=faq", VERSION_STRING);
        !          1828:                        ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
        !          1829:                        return 1;
        !          1830:                }
        !          1831: 
1.1       root     1832:                if (lw == ID_PREFERENCES)
                   1833:                {
                   1834:                        DialogBoxParam (hInst, 
                   1835:                                MAKEINTRESOURCE (IDD_PREFERENCES_DLG), hwndDlg,
                   1836:                                (DLGPROC) PreferencesDlgProc, (LPARAM) 0);
                   1837:                        return 1;
                   1838:                }
                   1839: 
1.1.1.5   root     1840:                if (lw == ID_BENCHMARK)
                   1841:                {
                   1842:                        Benchmark (hwndDlg);
                   1843:                        return 1;
                   1844:                }
                   1845: 
1.1.1.6 ! root     1846:                if (lw == IDM_TRAVELLER)
        !          1847:                {
        !          1848:                        DialogBoxParam (hInst, 
        !          1849:                                MAKEINTRESOURCE (IDD_TRAVELLER_DLG), hwndDlg,
        !          1850:                                (DLGPROC) TravellerDlgProc, (LPARAM) 0);
        !          1851:                        return 1;
        !          1852:                }
        !          1853: 
        !          1854:                if (lw == IDM_REFRESH_DRIVE_LETTERS)
        !          1855:                {
        !          1856:                        DWORD driveMap = GetLogicalDrives ();
        !          1857:                        
        !          1858:                        ArrowWaitCursor ();
        !          1859:                        BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, ~driveMap);
        !          1860:                        Sleep (100);
        !          1861:                        BroadcastDeviceChange (DBT_DEVICEARRIVAL, 0, driveMap);
        !          1862:                        LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
        !          1863:                        NormalCursor ();
        !          1864:                }
1.1.1.5   root     1865: 
1.1       root     1866:                if (lw == IDC_VOLUME_PROPERTIES)
                   1867:                {
                   1868:                        DialogBoxParam (hInst, 
                   1869:                                MAKEINTRESOURCE (IDD_VOLUME_PROPERTIES), hwndDlg,
                   1870:                                (DLGPROC) VolumePropertiesDlgProc, (LPARAM) 0);
                   1871:                        return 1;
                   1872:                }
                   1873: 
                   1874:                if (lw == IDC_VOLUME && hw == CBN_EDITCHANGE)
                   1875:                {
1.1.1.5   root     1876:                        EnableDisableButtons (hwndDlg);
1.1       root     1877:                        return 1;
                   1878:                }
                   1879: 
                   1880:                if (lw == IDC_VOLUME && hw == CBN_SELCHANGE)
                   1881:                {
                   1882:                        UpdateComboOrder (GetDlgItem (hwndDlg, IDC_VOLUME));
                   1883:                        MoveEditToCombo ((HWND) lParam);
1.1.1.5   root     1884:                        PostMessage (hwndDlg, WM_USER+100, 0, 0);
                   1885:                        return 1;
                   1886:                }
                   1887: 
                   1888:                if (lw == IDC_NO_HISTORY)
                   1889:                {
                   1890:                        bHistory = !IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY));
1.1       root     1891:                        return 1;
                   1892:                }
                   1893: 
                   1894:                return 0;
                   1895: 
1.1.1.6 ! root     1896:        case WM_DROPFILES:
        !          1897:                {
        !          1898:                        HDROP hdrop = (HDROP) wParam;
        !          1899:                        DragQueryFile (hdrop, 0, szFileName, sizeof szFileName);
        !          1900:                        DragFinish (hdrop);
        !          1901: 
        !          1902:                        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
        !          1903:                        EnableDisableButtons (hwndDlg);
        !          1904:                        SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
        !          1905:                }
        !          1906:                return 0;
        !          1907: 
1.1.1.5   root     1908:        case WM_USER+100:
1.1       root     1909:                EnableDisableButtons (hwndDlg);
                   1910:                return 1;
                   1911: 
                   1912:        case WM_CLOSE:
                   1913:                EndMainDlg (hwndDlg);
                   1914:                return 1;
                   1915:        }
                   1916: 
                   1917:        return 0;
                   1918: }
                   1919: 
                   1920: void
                   1921: ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
                   1922: {
                   1923:        char **lpszCommandLineArgs;     /* Array of command line arguments */
                   1924:        int nNoCommandLineArgs; /* The number of arguments in the array */
                   1925: 
                   1926:        /* Extract command line arguments */
                   1927:        nNoCommandLineArgs = Win32CommandLine (lpszCommandLine, &lpszCommandLineArgs);
                   1928:        if (nNoCommandLineArgs > 0)
                   1929:        {
                   1930:                int i;
                   1931: 
                   1932:                for (i = 0; i < nNoCommandLineArgs; i++)
                   1933:                {
                   1934:                        argument args[]=
                   1935:                        {
                   1936:                                {"/auto", "/a"},
1.1.1.5   root     1937:                                {"/beep", "/b"},
1.1       root     1938:                                {"/cache", "/c"},
1.1.1.5   root     1939:                                {"/dismount", "/d"},
                   1940:                                {"/explore", "/e"},
                   1941:                                {"/force", "/f"},
                   1942:                                {"/help", "/?"},
1.1       root     1943:                                {"/history", "/h"},
1.1.1.5   root     1944:                                {"/letter", "/l"},
1.1.1.6 ! root     1945:                                {"/mountoption", "/m"},
1.1.1.5   root     1946:                                {"/password", "/p"},
1.1       root     1947:                                {"/quiet", "/q"},
1.1.1.5   root     1948:                                {"/volume", "/v"},
                   1949:                                {"/wipecache", "/w"}
1.1       root     1950:                        };
                   1951: 
                   1952:                        argumentspec as;
                   1953: 
                   1954:                        int nArgPos;
                   1955:                        int x;
                   1956: 
                   1957:                        as.args = args;
                   1958:                        as.arg_cnt = sizeof(args)/ sizeof(args[0]);
                   1959:                        
                   1960:                        x = GetArgumentID (&as, lpszCommandLineArgs[i], &nArgPos);
                   1961: 
                   1962:                        switch (x)
                   1963:                        {
                   1964:                        case 'd':
1.1.1.2   root     1965: 
                   1966:                                if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
                   1967:                                     szDriveLetter, sizeof (szDriveLetter)))
1.1.1.5   root     1968:                                        cmdUnmountDrive = toupper(szDriveLetter[0]) - 'A';
1.1.1.2   root     1969:                                else 
1.1.1.5   root     1970:                                        cmdUnmountDrive = -1;
1.1.1.2   root     1971: 
1.1       root     1972:                                break;
                   1973: 
                   1974:                        case 'v':
                   1975:                                if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i,
                   1976:                                                                      nNoCommandLineArgs, szFileName, sizeof (szFileName)))
1.1.1.2   root     1977:                                {
                   1978:                                        // Relative path must be converted to absolute
                   1979:                                        if (szFileName[0] != '\\' && strchr (szFileName, ':') == 0)
                   1980:                                        {
                   1981:                                                char path[MAX_PATH*2];
                   1982:                                                GetCurrentDirectory (MAX_PATH, path);
                   1983:                                                strcat (path, szFileName);
                   1984:                                                strncpy (szFileName, path, MAX_PATH-1);
                   1985:                                        }
1.1       root     1986:                                        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
1.1.1.2   root     1987:                                }
1.1       root     1988:                                break;
                   1989: 
                   1990:                        case 'l':
                   1991:                                GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
                   1992:                                     szDriveLetter, sizeof (szDriveLetter));
1.1.1.5   root     1993:                                commandLineDrive = *szDriveLetter = (char) toupper (*szDriveLetter);
1.1       root     1994:                                break;
                   1995: 
                   1996:                        case 'e':
                   1997:                                bExplore = TRUE;
                   1998:                                break;
                   1999: 
                   2000:                        case 'b':
                   2001:                                bBeep = TRUE;
                   2002:                                break;
                   2003: 
1.1.1.5   root     2004:                        case 'f':
                   2005:                                bForceMount = TRUE;
                   2006:                                bForceUnmount = TRUE;
                   2007:                                break;
                   2008: 
1.1       root     2009:                        case 'p':
1.1.1.2   root     2010:                                GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
                   2011:                                                     commandLinePassword, sizeof (commandLinePassword));
1.1       root     2012:                                break;
                   2013: 
                   2014:                        case 'a':
1.1.1.6 ! root     2015:                                {
        !          2016:                                        char szTmp[8];
        !          2017:                                        bAuto = TRUE;
        !          2018: 
        !          2019:                                        if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
        !          2020:                                                nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
        !          2021:                                        {
        !          2022:                                                if (!_stricmp (szTmp, "devices"))
        !          2023:                                                        bAutoMountDevices = TRUE;
        !          2024:                                        }
        !          2025:                                }
        !          2026:                                break;
        !          2027: 
        !          2028:                        case 'm':
        !          2029:                                {
        !          2030:                                        char szTmp[8];
        !          2031:                                        if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
        !          2032:                                                nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
        !          2033:                                        {
        !          2034:                                                if (!_stricmp (szTmp, "ro"))
        !          2035:                                                        mountOptions.ReadOnly = TRUE;
        !          2036: 
        !          2037:                                                if (!_stricmp (szTmp, "rm"))
        !          2038:                                                        mountOptions.Removable = TRUE;
        !          2039:                                        }
        !          2040:                                }
1.1       root     2041:                                break;
                   2042: 
                   2043:                        case 'c':
                   2044:                                {
                   2045:                                        char szTmp[8];
                   2046:                                        GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
                   2047:                                                     szTmp, sizeof (szTmp));
                   2048:                                        if (!_stricmp(szTmp,"y") || !_stricmp(szTmp,"yes"))
                   2049:                                                bCacheInDriver = TRUE;
                   2050:                                        if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
                   2051:                                                bCacheInDriver = FALSE;
                   2052:                                }
                   2053:                                break;
                   2054: 
                   2055:                        case 'h':
                   2056:                                {
                   2057:                                        char szTmp[8];
                   2058:                                        GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
                   2059:                                                     szTmp, sizeof (szTmp));
                   2060:                                        if (!_stricmp(szTmp,"y") || !_stricmp(szTmp,"yes"))
                   2061:                                        {
                   2062:                                                bHistory = TRUE;
                   2063:                                                bHistoryCmdLine = TRUE;
                   2064:                                        }
                   2065: 
                   2066:                                        if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
                   2067:                                        {
                   2068:                                                bHistory = FALSE;
                   2069:                                                bHistoryCmdLine = TRUE;
                   2070:                                        }
                   2071:                                }
                   2072:                                break;
                   2073: 
                   2074:                        case 'w':
                   2075:                                bWipe = TRUE;
                   2076:                                break;
                   2077: 
                   2078:                        case 'q':
                   2079:                                bQuiet = TRUE;
                   2080:                                break;
                   2081: 
                   2082:                        case '?':
                   2083:                                DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_COMMANDHELP_DLG), hwndDlg, (DLGPROC)
                   2084:                                                CommandHelpDlgProc, (LPARAM) &as);
                   2085:                                exit(0);
                   2086:                                break;
                   2087: 
                   2088:                                // no option = file name
                   2089:                        default:
1.1.1.2   root     2090:                                {
                   2091:                                        strncpy (szFileName, lpszCommandLineArgs[0], MAX_PATH-1);
                   2092:                                        if (szFileName[0] != '\\' && strchr (szFileName, ':') == 0)
                   2093:                                        {
                   2094:                                                char path[MAX_PATH*2];
                   2095:                                                GetCurrentDirectory (MAX_PATH, path);
                   2096:                                                strcat (path, "\\");
                   2097:                                                strcat (path, szFileName);
                   2098:                                                strncpy (szFileName, path, MAX_PATH-1);
                   2099:                                        }
                   2100:                                        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
                   2101:                                }
1.1       root     2102:                        }
                   2103:                }
                   2104:        }
                   2105: 
                   2106:        /* Free up the command line arguments */
                   2107:        while (--nNoCommandLineArgs >= 0)
                   2108:        {
                   2109:                free (lpszCommandLineArgs[nNoCommandLineArgs]);
                   2110:        }
                   2111: }
                   2112: 
                   2113: int WINAPI
                   2114: WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine,
                   2115:         int nCmdShow)
                   2116: {
                   2117:        int status;
                   2118: 
                   2119:        if (nCmdShow && hPrevInstance); /* Remove unused parameter warning */
                   2120: 
                   2121:        atexit (localcleanup);
                   2122: 
                   2123:        /* Allocate, dup, then store away the application title */
                   2124:        lpszTitle = err_strdup (getstr (IDS_TITLE));
                   2125: 
                   2126:        /* Call InitApp to initialize the common code */
                   2127:        InitApp (hInstance);
                   2128: 
                   2129:        status = DriverAttach ();
                   2130:        if (status != 0)
                   2131:        {
                   2132:                if (status == ERR_OS_ERROR)
                   2133:                        handleWin32Error (NULL);
                   2134:                else
                   2135:                        handleError (NULL, status);
                   2136: 
                   2137:                AbortProcess (IDS_NODRIVER);
                   2138:        }
                   2139: 
                   2140:        /* Create the main dialog box */
                   2141:        DialogBoxParam (hInstance, MAKEINTRESOURCE (IDD_MOUNT_DLG), NULL, (DLGPROC) MainDialogProc,
                   2142:                        (LPARAM) lpszCommandLine);
                   2143: 
                   2144:        /* Terminate */
                   2145:        return 0;
                   2146: }
1.1.1.6 ! root     2147: 

unix.superglobalmegacorp.com

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