Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1070 lines
25 KiB

  1. //
  2. // Driver Verifier UI
  3. // Copyright (c) Microsoft Corporation, 1999
  4. //
  5. //
  6. //
  7. // module: SDrvPage.cpp
  8. // author: DMihai
  9. // created: 11/1/00
  10. //
  11. // Description:
  12. //
  13. #include "stdafx.h"
  14. #include <Cderr.h>
  15. #include "verifier.h"
  16. #include "SDrvPage.h"
  17. #include "VrfUtil.h"
  18. #include "VGlobal.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. //
  25. // Help IDs
  26. //
  27. static DWORD MyHelpIds[] =
  28. {
  29. IDC_SELDRV_LIST, IDH_DV_SelectDriversToVerify,
  30. IDC_SELDRV_ADD_BUTTON, IDH_DV_Addbut_UnloadedDrivers,
  31. 0, 0
  32. };
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CSelectDriversPage property page
  35. IMPLEMENT_DYNCREATE(CSelectDriversPage, CVerifierPropertyPage)
  36. CSelectDriversPage::CSelectDriversPage()
  37. : CVerifierPropertyPage(CSelectDriversPage::IDD)
  38. {
  39. //{{AFX_DATA_INIT(CSelectDriversPage)
  40. // NOTE: the ClassWizard will add member initialization here
  41. //}}AFX_DATA_INIT
  42. m_pParentSheet = NULL;
  43. m_nSortColumnIndex = 1;
  44. m_bAscendSortVerified = FALSE;
  45. m_bAscendSortDrvName = FALSE;
  46. m_bAscendSortProvName = FALSE;
  47. m_bAscendSortVersion = FALSE;
  48. }
  49. CSelectDriversPage::~CSelectDriversPage()
  50. {
  51. }
  52. void CSelectDriversPage::DoDataExchange(CDataExchange* pDX)
  53. {
  54. CVerifierPropertyPage::DoDataExchange(pDX);
  55. //{{AFX_DATA_MAP(CSelectDriversPage)
  56. DDX_Control(pDX, IDC_SELDRV_NEXT_DESCR_STATIC, m_NextDescription);
  57. DDX_Control(pDX, IDC_SELDRV_LIST, m_DriversList);
  58. //}}AFX_DATA_MAP
  59. }
  60. BEGIN_MESSAGE_MAP(CSelectDriversPage, CVerifierPropertyPage)
  61. //{{AFX_MSG_MAP(CSelectDriversPage)
  62. ON_BN_CLICKED(IDC_SELDRV_ADD_BUTTON, OnAddButton)
  63. ON_NOTIFY(LVN_COLUMNCLICK, IDC_SELDRV_LIST, OnColumnclickSeldrvList)
  64. ON_WM_CONTEXTMENU()
  65. ON_MESSAGE( WM_HELP, OnHelp )
  66. //}}AFX_MSG_MAP
  67. END_MESSAGE_MAP()
  68. /////////////////////////////////////////////////////////////////////////////
  69. VOID CSelectDriversPage::SetupListHeader()
  70. {
  71. CString strTitle;
  72. CRect rectWnd;
  73. LVCOLUMN lvColumn;
  74. //
  75. // The list's rectangle
  76. //
  77. m_DriversList.GetClientRect( &rectWnd );
  78. ZeroMemory( &lvColumn,
  79. sizeof( lvColumn ) );
  80. lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
  81. lvColumn.fmt = LVCFMT_LEFT;
  82. //
  83. // Column 0
  84. //
  85. VERIFY( strTitle.LoadString( IDS_VERIFICATION_STATUS ) );
  86. lvColumn.iSubItem = 0;
  87. lvColumn.cx = (int)( rectWnd.Width() * 0.08 );
  88. lvColumn.pszText = strTitle.GetBuffer( strTitle.GetLength() + 1 );
  89. if (NULL != lvColumn.pszText)
  90. {
  91. VERIFY( m_DriversList.InsertColumn( 0, &lvColumn ) != -1 );
  92. strTitle.ReleaseBuffer();
  93. }
  94. else
  95. {
  96. lvColumn.pszText = g_szVoidText;
  97. VERIFY( m_DriversList.InsertColumn( 0, &lvColumn ) != -1 );
  98. }
  99. //
  100. // Column 1
  101. //
  102. VERIFY( strTitle.LoadString( IDS_DRIVERS ) );
  103. lvColumn.iSubItem = 1;
  104. lvColumn.cx = (int)( rectWnd.Width() * 0.20 );
  105. lvColumn.pszText = strTitle.GetBuffer( strTitle.GetLength() + 1 );
  106. if (NULL != lvColumn.pszText)
  107. {
  108. VERIFY( m_DriversList.InsertColumn( 1, &lvColumn ) != -1 );
  109. strTitle.ReleaseBuffer();
  110. }
  111. else
  112. {
  113. lvColumn.pszText = g_szVoidText;
  114. VERIFY( m_DriversList.InsertColumn( 1, &lvColumn ) != -1 );
  115. }
  116. //
  117. // Column 2
  118. //
  119. VERIFY( strTitle.LoadString( IDS_PROVIDER ) );
  120. lvColumn.iSubItem = 2;
  121. lvColumn.cx = (int)( rectWnd.Width() * 0.47 );
  122. lvColumn.pszText = strTitle.GetBuffer( strTitle.GetLength() + 1 );
  123. if (NULL != lvColumn.pszText)
  124. {
  125. VERIFY( m_DriversList.InsertColumn( 2, &lvColumn ) != -1 );
  126. strTitle.ReleaseBuffer();
  127. }
  128. else
  129. {
  130. lvColumn.pszText = g_szVoidText;
  131. VERIFY( m_DriversList.InsertColumn( 2, &lvColumn ) != -1 );
  132. }
  133. //
  134. // Column 3
  135. //
  136. VERIFY( strTitle.LoadString( IDS_VERSION ) );
  137. lvColumn.iSubItem = 3;
  138. lvColumn.cx = (int)( rectWnd.Width() * 0.22 );
  139. lvColumn.pszText = strTitle.GetBuffer( strTitle.GetLength() + 1 );
  140. if (NULL != lvColumn.pszText)
  141. {
  142. VERIFY( m_DriversList.InsertColumn( 3, &lvColumn ) != -1 );
  143. strTitle.ReleaseBuffer();
  144. }
  145. else
  146. {
  147. VERIFY( m_DriversList.InsertColumn( 3, &lvColumn ) != -1 );
  148. lvColumn.pszText = g_szVoidText;
  149. }
  150. }
  151. /////////////////////////////////////////////////////////////////////////////
  152. VOID CSelectDriversPage::FillTheList()
  153. {
  154. INT_PTR nDriversNo;
  155. INT_PTR nCrtDriverIndex;
  156. CDriverData *pCrtDrvData;
  157. const CDriverDataArray &DrvDataArray = g_NewVerifierSettings.m_DriversSet.m_aDriverData;
  158. m_DriversList.DeleteAllItems();
  159. //
  160. // Parse the driver data array
  161. //
  162. nDriversNo = DrvDataArray.GetSize();
  163. for( nCrtDriverIndex = 0; nCrtDriverIndex < nDriversNo; nCrtDriverIndex += 1)
  164. {
  165. pCrtDrvData = DrvDataArray.GetAt( nCrtDriverIndex );
  166. ASSERT_VALID( pCrtDrvData );
  167. AddListItem( nCrtDriverIndex,
  168. pCrtDrvData );
  169. }
  170. }
  171. /////////////////////////////////////////////////////////////////////////////
  172. INT CSelectDriversPage::AddListItem( INT_PTR nIndexInArray, CDriverData *pCrtDrvData )
  173. {
  174. INT nActualIndex;
  175. LVITEM lvItem;
  176. ASSERT_VALID( pCrtDrvData );
  177. nActualIndex = -1;
  178. ZeroMemory( &lvItem, sizeof( lvItem ) );
  179. //
  180. // LVITEM's member pszText is not a const pointer
  181. // so we need to GetBuffer here :-(
  182. //
  183. //
  184. // Sub-item 0 - verification status - empty text and a checkbox
  185. //
  186. lvItem.pszText = g_szVoidText;
  187. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  188. lvItem.lParam = nIndexInArray;
  189. lvItem.iItem = m_DriversList.GetItemCount();
  190. nActualIndex = m_DriversList.InsertItem( &lvItem );
  191. if( nActualIndex < 0 )
  192. {
  193. //
  194. // Could not add an item in the list - give up
  195. //
  196. goto Done;
  197. }
  198. m_DriversList.SetCheck( nActualIndex, FALSE );
  199. //
  200. // Sub-item 1 - driver name
  201. //
  202. lvItem.pszText = pCrtDrvData->m_strName.GetBuffer( pCrtDrvData->m_strName.GetLength() + 1 );
  203. if( NULL == lvItem.pszText )
  204. {
  205. goto Done;
  206. }
  207. lvItem.mask = LVIF_TEXT;
  208. lvItem.iItem = nActualIndex;
  209. lvItem.iSubItem = 1;
  210. VERIFY( m_DriversList.SetItem( &lvItem ) );
  211. pCrtDrvData->m_strName.ReleaseBuffer();
  212. //
  213. // Sub-item 2 - provider
  214. //
  215. lvItem.pszText = pCrtDrvData->m_strCompanyName.GetBuffer(
  216. pCrtDrvData->m_strCompanyName.GetLength() + 1 );
  217. if( NULL == lvItem.pszText )
  218. {
  219. goto Done;
  220. }
  221. lvItem.mask = LVIF_TEXT;
  222. lvItem.iItem = nActualIndex;
  223. lvItem.iSubItem = 2;
  224. VERIFY( m_DriversList.SetItem( &lvItem ) );
  225. pCrtDrvData->m_strCompanyName.ReleaseBuffer();
  226. //
  227. // Sub-item 3 - version
  228. //
  229. lvItem.pszText = pCrtDrvData->m_strFileVersion.GetBuffer(
  230. pCrtDrvData->m_strFileVersion.GetLength() + 1 );
  231. if( NULL == lvItem.pszText )
  232. {
  233. goto Done;
  234. }
  235. lvItem.mask = LVIF_TEXT;
  236. lvItem.iItem = nActualIndex;
  237. lvItem.iSubItem = 3;
  238. VERIFY( m_DriversList.SetItem( &lvItem ) );
  239. pCrtDrvData->m_strFileVersion.ReleaseBuffer();
  240. Done:
  241. //
  242. // All done
  243. //
  244. return nActualIndex;
  245. }
  246. /////////////////////////////////////////////////////////////////////////////
  247. BOOL CSelectDriversPage::GetNewVerifiedDriversList()
  248. {
  249. INT nListItemCount;
  250. INT nCrtListItem;
  251. INT_PTR nCrtDriversArrayIndex;
  252. BOOL bVerified;
  253. CDriverData *pCrtDrvData;
  254. const CDriverDataArray &DrvDataArray = g_NewVerifierSettings.m_DriversSet.m_aDriverData;
  255. CDriverData::VerifyDriverTypeEnum VerifyStatus;
  256. nListItemCount = m_DriversList.GetItemCount();
  257. for( nCrtListItem = 0; nCrtListItem < nListItemCount; nCrtListItem += 1 )
  258. {
  259. //
  260. // Verification status for the current list item
  261. //
  262. bVerified = m_DriversList.GetCheck( nCrtListItem );
  263. if( bVerified )
  264. {
  265. VerifyStatus = CDriverData::VerifyDriverYes;
  266. }
  267. else
  268. {
  269. VerifyStatus = CDriverData::VerifyDriverNo;
  270. }
  271. //
  272. // Set the right verify state in our driver array
  273. //
  274. nCrtDriversArrayIndex = m_DriversList.GetItemData( nCrtListItem );
  275. pCrtDrvData = DrvDataArray.GetAt( nCrtDriversArrayIndex );
  276. ASSERT_VALID( pCrtDrvData );
  277. pCrtDrvData->m_VerifyDriverStatus = VerifyStatus;
  278. }
  279. return TRUE;
  280. }
  281. /////////////////////////////////////////////////////////////
  282. VOID CSelectDriversPage::SortTheList()
  283. {
  284. if( 0 != m_nSortColumnIndex )
  285. {
  286. //
  287. // Sort by driver name, provider or version
  288. //
  289. m_DriversList.SortItems( StringCmpFunc, (LPARAM)this );
  290. }
  291. else
  292. {
  293. //
  294. // Sort by verified status
  295. //
  296. m_DriversList.SortItems( CheckedStatusCmpFunc, (LPARAM)this );
  297. }
  298. }
  299. /////////////////////////////////////////////////////////////
  300. int CALLBACK CSelectDriversPage::StringCmpFunc( LPARAM lParam1,
  301. LPARAM lParam2,
  302. LPARAM lParamSort)
  303. {
  304. int nCmpRez = 0;
  305. BOOL bSuccess;
  306. CString strName1;
  307. CString strName2;
  308. CSelectDriversPage *pThis = (CSelectDriversPage *)lParamSort;
  309. ASSERT_VALID( pThis );
  310. ASSERT( 0 != pThis->m_nSortColumnIndex );
  311. //
  312. // Get the first name
  313. //
  314. bSuccess = pThis->GetColumnStrValue( lParam1,
  315. strName1 );
  316. if( FALSE == bSuccess )
  317. {
  318. goto Done;
  319. }
  320. //
  321. // Get the second name
  322. //
  323. bSuccess = pThis->GetColumnStrValue( lParam2,
  324. strName2 );
  325. if( FALSE == bSuccess )
  326. {
  327. goto Done;
  328. }
  329. //
  330. // Compare the names
  331. //
  332. nCmpRez = strName1.CompareNoCase( strName2 );
  333. switch( pThis->m_nSortColumnIndex )
  334. {
  335. case 1:
  336. //
  337. // Sort by driver name
  338. //
  339. if( FALSE != pThis->m_bAscendSortDrvName )
  340. {
  341. nCmpRez *= -1;
  342. }
  343. break;
  344. case 2:
  345. //
  346. // Sort by provider name
  347. //
  348. if( FALSE != pThis->m_bAscendSortProvName )
  349. {
  350. nCmpRez *= -1;
  351. }
  352. break;
  353. case 3:
  354. //
  355. // Sort by version
  356. //
  357. if( FALSE != pThis->m_bAscendSortVersion )
  358. {
  359. nCmpRez *= -1;
  360. }
  361. break;
  362. default:
  363. //
  364. // Oops - how did we get here ?!?
  365. //
  366. ASSERT( FALSE );
  367. break;
  368. }
  369. Done:
  370. return nCmpRez;
  371. }
  372. /////////////////////////////////////////////////////////////
  373. int CALLBACK CSelectDriversPage::CheckedStatusCmpFunc( LPARAM lParam1,
  374. LPARAM lParam2,
  375. LPARAM lParamSort)
  376. {
  377. int nCmpRez = 0;
  378. INT nItemIndex;
  379. BOOL bVerified1;
  380. BOOL bVerified2;
  381. LVFINDINFO FindInfo;
  382. CSelectDriversPage *pThis = (CSelectDriversPage *)lParamSort;
  383. ASSERT_VALID( pThis );
  384. ASSERT( 0 == pThis->m_nSortColumnIndex );
  385. //
  386. // Find the first item
  387. //
  388. ZeroMemory( &FindInfo, sizeof( FindInfo ) );
  389. FindInfo.flags = LVFI_PARAM;
  390. FindInfo.lParam = lParam1;
  391. nItemIndex = pThis->m_DriversList.FindItem( &FindInfo );
  392. if( nItemIndex < 0 )
  393. {
  394. ASSERT( FALSE );
  395. goto Done;
  396. }
  397. bVerified1 = pThis->m_DriversList.GetCheck( nItemIndex );
  398. //
  399. // Find the second item
  400. //
  401. FindInfo.flags = LVFI_PARAM;
  402. FindInfo.lParam = lParam2;
  403. nItemIndex = pThis->m_DriversList.FindItem( &FindInfo );
  404. if( nItemIndex < 0 )
  405. {
  406. ASSERT( FALSE );
  407. goto Done;
  408. }
  409. bVerified2 = pThis->m_DriversList.GetCheck( nItemIndex );
  410. //
  411. // Compare them
  412. //
  413. if( bVerified1 != bVerified2 )
  414. {
  415. if( FALSE != bVerified1 )
  416. {
  417. nCmpRez = 1;
  418. }
  419. else
  420. {
  421. nCmpRez = -1;
  422. }
  423. if( FALSE != pThis->m_bAscendSortVerified )
  424. {
  425. nCmpRez *= -1;
  426. }
  427. }
  428. Done:
  429. return nCmpRez;
  430. }
  431. /////////////////////////////////////////////////////////////
  432. BOOL CSelectDriversPage::GetColumnStrValue( LPARAM lItemData,
  433. CString &strName )
  434. {
  435. CDriverData *pCrtDrvData;
  436. pCrtDrvData = g_NewVerifierSettings.m_DriversSet.m_aDriverData.GetAt( (INT_PTR) lItemData );
  437. ASSERT_VALID( pCrtDrvData );
  438. switch( m_nSortColumnIndex )
  439. {
  440. case 1:
  441. //
  442. // Sort by driver name
  443. //
  444. strName = pCrtDrvData->m_strName;
  445. break;
  446. case 2:
  447. //
  448. // Sort by provider name
  449. //
  450. strName = pCrtDrvData->m_strCompanyName;
  451. break;
  452. case 3:
  453. //
  454. // Sort by version
  455. //
  456. strName = pCrtDrvData->m_strFileVersion;
  457. break;
  458. default:
  459. //
  460. // Oops - how did we get here ?!?
  461. //
  462. ASSERT( FALSE );
  463. break;
  464. }
  465. return TRUE;
  466. }
  467. /////////////////////////////////////////////////////////////////////////////
  468. BOOL CSelectDriversPage::OnSetActive()
  469. {
  470. //
  471. // The wizard has at least one more step (display the summarry)
  472. //
  473. if( (FALSE == g_bShowDiskPropertyPage) &&
  474. (FALSE == g_NewVerifierSettings.m_aDiskData.VerifyAnyDisk()) )
  475. {
  476. //
  477. // Disk verifier is disabled.
  478. //
  479. m_pParentSheet->SetWizardButtons( PSWIZB_BACK |
  480. PSWIZB_FINISH );
  481. VrfSetWindowText( m_NextDescription, IDS_SELDRV_PAGE_NEXT_DESCR_FINISH );
  482. }
  483. else
  484. {
  485. //
  486. // Disk verifier is enabled.
  487. //
  488. m_pParentSheet->SetWizardButtons( PSWIZB_BACK |
  489. PSWIZB_NEXT );
  490. VrfSetWindowText( m_NextDescription, IDS_SELDRV_PAGE_NEXT_DESCR_NEXT );
  491. }
  492. return CVerifierPropertyPage::OnSetActive();
  493. }
  494. /////////////////////////////////////////////////////////////////////////////
  495. // CSelectDriversPage message handlers
  496. BOOL CSelectDriversPage::OnInitDialog()
  497. {
  498. CVerifierPropertyPage::OnInitDialog();
  499. //
  500. // setup the list
  501. //
  502. m_DriversList.SetExtendedStyle(
  503. LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES | m_DriversList.GetExtendedStyle() );
  504. SetupListHeader();
  505. FillTheList();
  506. SortTheList();
  507. return TRUE; // return TRUE unless you set the focus to a control
  508. // EXCEPTION: OCX Property Pages should return FALSE
  509. }
  510. /////////////////////////////////////////////////////////////////////////////
  511. BOOL CSelectDriversPage::OnWizardFinish()
  512. {
  513. BOOL bExitTheApp;
  514. bExitTheApp = FALSE;
  515. if( GetNewVerifiedDriversList() )
  516. {
  517. if( FALSE == g_NewVerifierSettings.m_DriversSet.ShouldVerifySomeDrivers() )
  518. {
  519. VrfErrorResourceFormat( IDS_SELECT_AT_LEAST_ONE_DRIVER );
  520. goto Done;
  521. }
  522. g_NewVerifierSettings.SaveToRegistry();
  523. //
  524. // Exit the app
  525. //
  526. bExitTheApp = CVerifierPropertyPage::OnWizardFinish();
  527. }
  528. Done:
  529. return bExitTheApp;
  530. }
  531. /////////////////////////////////////////////////////////////////////////////
  532. LRESULT CSelectDriversPage::OnWizardNext()
  533. {
  534. LRESULT lNextPageId;
  535. lNextPageId = -1;
  536. //
  537. // We can get here only if the disk integrity checking is enabled.
  538. //
  539. ASSERT( FALSE != g_bShowDiskPropertyPage ||
  540. FALSE != g_NewVerifierSettings.m_aDiskData.VerifyAnyDisk() );
  541. if( GetNewVerifiedDriversList() )
  542. {
  543. if( FALSE == g_NewVerifierSettings.m_DriversSet.ShouldVerifySomeDrivers() )
  544. {
  545. VrfErrorResourceFormat( IDS_SELECT_AT_LEAST_ONE_DRIVER );
  546. goto Done;
  547. }
  548. lNextPageId = IDD_DISK_LIST_PAGE;
  549. GoingToNextPageNotify( lNextPageId );
  550. }
  551. Done:
  552. return lNextPageId;
  553. }
  554. /////////////////////////////////////////////////////////////////////////////
  555. #define VRF_MAX_CHARS_FOR_OPEN 4096
  556. void CSelectDriversPage::OnAddButton()
  557. {
  558. POSITION pos;
  559. DWORD dwRetValue;
  560. DWORD dwOldMaxFileName = 0;
  561. DWORD dwErrorCode;
  562. INT nFileNameStartIndex;
  563. INT nNewListItemIndex;
  564. INT_PTR nResult;
  565. INT_PTR nNewDriverDataIndex;
  566. CDriverData *pNewDrvData;
  567. TCHAR szDriversDir[ _MAX_PATH ];
  568. TCHAR szAppTitle[ _MAX_PATH ];
  569. TCHAR *szFilesBuffer = NULL;
  570. TCHAR *szOldFilesBuffer = NULL;
  571. CString strPathName;
  572. CString strFileName;
  573. CFileDialog fileDlg(
  574. TRUE, // open file
  575. _T( "sys" ), // default extension
  576. NULL, // no initial file name
  577. OFN_ALLOWMULTISELECT | // multiple selection
  578. OFN_HIDEREADONLY | // hide the "open read-only" checkbox
  579. OFN_NONETWORKBUTTON | // no network button
  580. OFN_NOTESTFILECREATE | // don't test for write protection, a full disk, etc.
  581. OFN_SHAREAWARE, // don't check the existance of file with OpenFile
  582. _T( "Drivers (*.sys)|*.sys||" ) ); // only one filter
  583. //
  584. // check the max length for the returned string
  585. //
  586. if( fileDlg.m_ofn.nMaxFile < VRF_MAX_CHARS_FOR_OPEN )
  587. {
  588. //
  589. // allocate a new buffer for the file names
  590. //
  591. szFilesBuffer = new TCHAR[ VRF_MAX_CHARS_FOR_OPEN ];
  592. if (NULL == szFilesBuffer)
  593. {
  594. VrfErrorResourceFormat( IDS_NOT_ENOUGH_MEMORY );
  595. goto Done;
  596. }
  597. szFilesBuffer[ 0 ] = (TCHAR)0;
  598. if( szFilesBuffer != NULL )
  599. {
  600. //
  601. // Save the old buffer address and length
  602. //
  603. dwOldMaxFileName = fileDlg.m_ofn.nMaxFile;
  604. szOldFilesBuffer = fileDlg.m_ofn.lpstrFile;
  605. //
  606. // Set the new buffer address and length
  607. //
  608. fileDlg.m_ofn.lpstrFile = szFilesBuffer;
  609. fileDlg.m_ofn.nMaxFile = VRF_MAX_CHARS_FOR_OPEN;
  610. }
  611. }
  612. //
  613. // Dialog title
  614. //
  615. if( VrfLoadString(
  616. IDS_APPTITLE,
  617. szAppTitle,
  618. ARRAY_LENGTH( szAppTitle ) ) )
  619. {
  620. fileDlg.m_ofn.lpstrTitle = szAppTitle;
  621. }
  622. //
  623. // We change directory first time we try this to %windir%\system32\drivers
  624. //
  625. dwRetValue = ExpandEnvironmentStrings(
  626. _T( "%windir%\\system32\\drivers" ),
  627. szDriversDir,
  628. ARRAY_LENGTH( szDriversDir ) );
  629. if( dwRetValue > 0 && dwRetValue <= ARRAY_LENGTH( szDriversDir ) )
  630. {
  631. fileDlg.m_ofn.lpstrInitialDir = szDriversDir;
  632. }
  633. //
  634. // Show the file selection dialog
  635. //
  636. nResult = fileDlg.DoModal();
  637. switch( nResult )
  638. {
  639. case IDOK:
  640. break;
  641. case IDCANCEL:
  642. goto cleanup;
  643. default:
  644. dwErrorCode = CommDlgExtendedError();
  645. if( dwErrorCode == FNERR_BUFFERTOOSMALL )
  646. {
  647. VrfErrorResourceFormat(
  648. IDS_TOO_MANY_FILES_SELECTED );
  649. }
  650. else
  651. {
  652. VrfErrorResourceFormat(
  653. IDS_CANNOT_OPEN_FILES,
  654. dwErrorCode );
  655. }
  656. goto cleanup;
  657. }
  658. //
  659. // Parse all the selected files and try to enable them for verification
  660. //
  661. pos = fileDlg.GetStartPosition();
  662. while( pos != NULL )
  663. {
  664. //
  665. // Get the full path for the next file
  666. //
  667. strPathName = fileDlg.GetNextPathName( pos );
  668. //
  669. // Split only the file name, without the directory
  670. //
  671. nFileNameStartIndex = strPathName.ReverseFind( _T( '\\' ) );
  672. if( nFileNameStartIndex < 0 )
  673. {
  674. //
  675. // This shoudn't happen but you never know :-)
  676. //
  677. nFileNameStartIndex = 0;
  678. }
  679. else
  680. {
  681. //
  682. // skip the backslash
  683. //
  684. nFileNameStartIndex += 1;
  685. }
  686. strFileName = strPathName.Right( strPathName.GetLength() - nFileNameStartIndex );
  687. //
  688. // Try to add this driver to our global driver list
  689. //
  690. if( g_NewVerifierSettings.m_DriversSet.IsDriverNameInList( strFileName ) )
  691. {
  692. VrfErrorResourceFormat( IDS_DRIVER_IS_ALREADY_IN_LIST,
  693. (LPCTSTR) strFileName );
  694. }
  695. else
  696. {
  697. nNewDriverDataIndex = g_NewVerifierSettings.m_DriversSet.AddNewDriverData( strFileName );
  698. if( nNewDriverDataIndex >= 0 )
  699. {
  700. //
  701. // Force refreshing the unsigned driver data
  702. //
  703. g_NewVerifierSettings.m_DriversSet.m_bUnsignedDriverDataInitialized = FALSE;
  704. //
  705. // Add a new item to our list, for the new driver
  706. //
  707. pNewDrvData = g_NewVerifierSettings.m_DriversSet.m_aDriverData.GetAt( nNewDriverDataIndex );
  708. ASSERT_VALID( pNewDrvData );
  709. nNewListItemIndex = AddListItem( nNewDriverDataIndex,
  710. pNewDrvData );
  711. if( nNewListItemIndex >= 0 )
  712. {
  713. m_DriversList.EnsureVisible( nNewListItemIndex, TRUE );
  714. }
  715. }
  716. }
  717. }
  718. cleanup:
  719. if( szFilesBuffer != NULL )
  720. {
  721. fileDlg.m_ofn.nMaxFile = dwOldMaxFileName;
  722. fileDlg.m_ofn.lpstrFile = szOldFilesBuffer;
  723. delete [] szFilesBuffer;
  724. }
  725. Done:
  726. NOTHING;
  727. }
  728. /////////////////////////////////////////////////////////////////////////////
  729. void CSelectDriversPage::OnColumnclickSeldrvList(NMHDR* pNMHDR, LRESULT* pResult)
  730. {
  731. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  732. switch( pNMListView->iSubItem )
  733. {
  734. case 0:
  735. //
  736. // Clicked on the "verified" column
  737. //
  738. if( m_nSortColumnIndex == pNMListView->iSubItem )
  739. {
  740. //
  741. // Change the current ascend/descend order for this column
  742. //
  743. m_bAscendSortVerified = !m_bAscendSortVerified;
  744. }
  745. break;
  746. case 1:
  747. //
  748. // Clicked on the driver name column
  749. //
  750. if( m_nSortColumnIndex == pNMListView->iSubItem )
  751. {
  752. //
  753. // Change the current ascend/descend order for this column
  754. //
  755. m_bAscendSortDrvName = !m_bAscendSortDrvName;
  756. }
  757. break;
  758. case 2:
  759. //
  760. // Clicked on the provider column
  761. //
  762. if( m_nSortColumnIndex == pNMListView->iSubItem )
  763. {
  764. //
  765. // Change the current ascend/descend order for this column
  766. //
  767. m_bAscendSortProvName = !m_bAscendSortProvName;
  768. }
  769. break;
  770. case 3:
  771. //
  772. // Clicked on the version column
  773. //
  774. if( m_nSortColumnIndex == pNMListView->iSubItem )
  775. {
  776. //
  777. // Change the current ascend/descend order for this column
  778. //
  779. m_bAscendSortVersion = !m_bAscendSortVersion;
  780. }
  781. break;
  782. default:
  783. //
  784. // Oops - how did we get here ?!?
  785. //
  786. ASSERT( FALSE );
  787. goto Done;
  788. }
  789. m_nSortColumnIndex = pNMListView->iSubItem;
  790. SortTheList();
  791. Done:
  792. *pResult = 0;
  793. }
  794. /////////////////////////////////////////////////////////////
  795. LONG CSelectDriversPage::OnHelp( WPARAM wParam, LPARAM lParam )
  796. {
  797. LONG lResult = 0;
  798. LPHELPINFO lpHelpInfo = (LPHELPINFO)lParam;
  799. ::WinHelp(
  800. (HWND) lpHelpInfo->hItemHandle,
  801. g_szVerifierHelpFile,
  802. HELP_WM_HELP,
  803. (DWORD_PTR) MyHelpIds );
  804. return lResult;
  805. }
  806. /////////////////////////////////////////////////////////////////////////////
  807. void CSelectDriversPage::OnContextMenu(CWnd* pWnd, CPoint point)
  808. {
  809. ::WinHelp(
  810. pWnd->m_hWnd,
  811. g_szVerifierHelpFile,
  812. HELP_CONTEXTMENU,
  813. (DWORD_PTR) MyHelpIds );
  814. }