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.

1077 lines
29 KiB

  1. //
  2. // Driver Verifier UI
  3. // Copyright (c) Microsoft Corporation, 1999
  4. //
  5. //
  6. // module: VSetPage.cxx
  7. // author: DMihai
  8. // created: 07/07/99
  9. //
  10. // Description:
  11. //
  12. // Volatile settings PropertyPage.
  13. #include "stdafx.h"
  14. #include "drvvctrl.hxx"
  15. #include "VSetPage.hxx"
  16. #include "DrvCSht.hxx"
  17. #include <Cderr.h>
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. // timer ID
  24. #define REFRESH_TIMER_ID 0x1324
  25. // manual, high, normal, low speed
  26. #define REFRESH_SPEED_VARS 4
  27. // timer intervals in millisec for manual, high, normal, low speed
  28. static UINT uTimerIntervals[ REFRESH_SPEED_VARS ] =
  29. {
  30. 0, // Manual
  31. 1000, // High Speed
  32. 5000, // Normal Speed
  33. 10000 // Low Speed
  34. };
  35. //
  36. // help IDs
  37. //
  38. static DWORD MyHelpIds[] =
  39. {
  40. IDC_VSETTINGS_DRIVERS_LIST, IDH_DV_VolatileTab_driver_details,
  41. IDC_VSETTINGS_NORMAL_VERIF_CHECK, IDH_DV_SettingsTab_verifytype_sppool,
  42. IDC_VSETTINGS_PAGEDC_VERIF_CHECK, IDH_DV_SettingsTab_verifytype_irql,
  43. IDC_VSETTINGS_ALLOCF_VERIF_CHECK, IDH_DV_SettingsTab_verifytype_resource,
  44. IDC_VSETTINGS_APPLY_BUTTON, IDH_DV_VolatileTab_Applybut,
  45. IDC_VSETTINGS_ADD_BUTTON, IDH_DV_VolatileTab_Addbut,
  46. IDC_VSETTINGS_DONTVERIFY_BUTTON, IDH_DV_VolatileTab_Removebut,
  47. IDC_VSETTINGS_REFRESH_BUTTON, IDH_DV_common_refresh_nowbutton,
  48. IDC_VSETTINGS_MANUAL_RADIO, IDH_DV_common_refresh_manual,
  49. IDC_VSETTINGS_HSPEED_RADIO, IDH_DV_common_refresh_high,
  50. IDC_VSETTINGS_NORM_RADIO, IDH_DV_common_refresh_normal,
  51. IDC_VSETTINGS_LOW_RADIO, IDH_DV_common_refresh_low,
  52. 0, 0
  53. };
  54. /////////////////////////////////////////////////////////////
  55. // CVolatileSettPage property page
  56. IMPLEMENT_DYNCREATE(CVolatileSettPage, CPropertyPage)
  57. CVolatileSettPage::CVolatileSettPage() : CPropertyPage(CVolatileSettPage::IDD)
  58. {
  59. //{{AFX_DATA_INIT(CVolatileSettPage)
  60. m_nUpdateIntervalIndex = 2;
  61. m_bAllocFCheck = FALSE;
  62. m_bNormalCheck = FALSE;
  63. m_bPagedCCheck = FALSE;
  64. //}}AFX_DATA_INIT
  65. m_bAscendDrvNameSort = FALSE;
  66. m_bAscendDrvStatusSort = FALSE;
  67. m_uTimerHandler = 0;
  68. m_nSortColumnIndex = 0;
  69. m_eApplyButtonState = vrfControlDisabled;
  70. m_bTimerBlocked = FALSE;
  71. }
  72. CVolatileSettPage::~CVolatileSettPage()
  73. {
  74. }
  75. void CVolatileSettPage::DoDataExchange(CDataExchange* pDX)
  76. {
  77. if( ! pDX->m_bSaveAndValidate )
  78. {
  79. // query the kernel
  80. KrnGetSystemVerifierState( &m_KrnVerifState );
  81. }
  82. CPropertyPage::DoDataExchange(pDX);
  83. //{{AFX_DATA_MAP(CVolatileSettPage)
  84. DDX_Control(pDX, IDC_VSETTINGS_DRIVERS_LIST, m_DriversList);
  85. DDX_Control(pDX, IDC_VSETTINGS_PAGEDC_VERIF_CHECK, m_PagedCCheck);
  86. DDX_Control(pDX, IDC_VSETTINGS_NORMAL_VERIF_CHECK, m_NormalVerifCheck);
  87. DDX_Control(pDX, IDC_VSETTINGS_ALLOCF_VERIF_CHECK, m_AllocFCheck);
  88. DDX_Control(pDX, IDC_VSETTINGS_APPLY_BUTTON, m_ApplyButton);
  89. DDX_Radio(pDX, IDC_VSETTINGS_MANUAL_RADIO, m_nUpdateIntervalIndex);
  90. //}}AFX_DATA_MAP
  91. if( pDX->m_bSaveAndValidate )
  92. {
  93. DDX_Check(pDX, IDC_VSETTINGS_NORMAL_VERIF_CHECK, m_bNormalCheck);
  94. DDX_Check(pDX, IDC_VSETTINGS_PAGEDC_VERIF_CHECK, m_bPagedCCheck);
  95. DDX_Check(pDX, IDC_VSETTINGS_ALLOCF_VERIF_CHECK, m_bAllocFCheck);
  96. }
  97. }
  98. BEGIN_MESSAGE_MAP(CVolatileSettPage, CPropertyPage)
  99. //{{AFX_MSG_MAP(CVolatileSettPage)
  100. ON_BN_CLICKED(IDC_VSETTINGS_REFRESH_BUTTON, OnCrtstatRefreshButton)
  101. ON_NOTIFY(LVN_COLUMNCLICK, IDC_VSETTINGS_DRIVERS_LIST, OnColumnclickCrtstatDriversList)
  102. ON_WM_TIMER()
  103. ON_BN_CLICKED(IDC_VSETTINGS_HSPEED_RADIO, OnCrtstatHspeedRadio)
  104. ON_BN_CLICKED(IDC_VSETTINGS_LOW_RADIO, OnCrtstatLowRadio)
  105. ON_BN_CLICKED(IDC_VSETTINGS_MANUAL_RADIO, OnCrtstatManualRadio)
  106. ON_BN_CLICKED(IDC_VSETTINGS_NORM_RADIO, OnCrtstatNormRadio)
  107. ON_BN_CLICKED(IDC_VSETTINGS_APPLY_BUTTON, OnApplyButton)
  108. ON_BN_CLICKED(IDC_VSETTINGS_ALLOCF_VERIF_CHECK, OnCheck )
  109. ON_BN_CLICKED(IDC_VSETTINGS_ADD_BUTTON, OnAddButton)
  110. ON_BN_CLICKED(IDC_VSETTINGS_DONTVERIFY_BUTTON, OnDontVerifyButton)
  111. ON_BN_CLICKED(IDC_VSETTINGS_NORMAL_VERIF_CHECK, OnCheck )
  112. ON_BN_CLICKED(IDC_VSETTINGS_PAGEDC_VERIF_CHECK, OnCheck )
  113. ON_NOTIFY(NM_RCLICK, IDC_VSETTINGS_DRIVERS_LIST, OnRclickDriversList)
  114. ON_COMMAND(ID_VOLATILE_ADD_DRIVERS, OnAddButton)
  115. ON_COMMAND(ID_VOLATILE_REMOVE_DRIVERS, OnDontVerifyButton)
  116. ON_MESSAGE( WM_HELP, OnHelp )
  117. ON_MESSAGE( WM_CONTEXTMENU, OnContextMenu )
  118. //}}AFX_MSG_MAP
  119. END_MESSAGE_MAP()
  120. /////////////////////////////////////////////////////////////////////////////
  121. void CVolatileSettPage::UpdateControlsState()
  122. {
  123. EnableControl( m_ApplyButton, m_eApplyButtonState );
  124. }
  125. /////////////////////////////////////////////////////////////////////////////
  126. void CVolatileSettPage::EnableControl( CWnd &wndCtrl,
  127. VRF_CONTROL_STATE eNewState )
  128. {
  129. BOOL bEnabled = wndCtrl.IsWindowEnabled();
  130. if( bEnabled )
  131. {
  132. if( eNewState == vrfControlDisabled )
  133. wndCtrl.EnableWindow( FALSE );
  134. }
  135. else
  136. {
  137. if( eNewState == vrfControlEnabled )
  138. wndCtrl.EnableWindow( TRUE );
  139. }
  140. }
  141. /////////////////////////////////////////////////////////////
  142. void CVolatileSettPage::SetupListHeader()
  143. {
  144. CString strDrivers, strStatus;
  145. VERIFY( strDrivers.LoadString( IDS_DRIVERS ) );
  146. VERIFY( strStatus.LoadString( IDS_STATUS ) );
  147. // list's regtangle
  148. CRect rectWnd;
  149. m_DriversList.GetClientRect( &rectWnd );
  150. LVCOLUMN lvColumn;
  151. // column 0
  152. memset( &lvColumn, 0, sizeof( lvColumn ) );
  153. lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
  154. lvColumn.fmt = LVCFMT_LEFT;
  155. lvColumn.iSubItem = 0;
  156. lvColumn.pszText = strDrivers.GetBuffer( strDrivers.GetLength() + 1 );
  157. lvColumn.cx = (int)( rectWnd.Width() * 0.47 );
  158. VERIFY( m_DriversList.InsertColumn( 0, &lvColumn ) != -1 );
  159. strDrivers.ReleaseBuffer();
  160. // column 1
  161. lvColumn.iSubItem = 1;
  162. lvColumn.pszText = strStatus.GetBuffer( strStatus.GetLength() + 1 );
  163. lvColumn.cx = (int)( rectWnd.Width() * 0.47 );
  164. VERIFY( m_DriversList.InsertColumn( 1, &lvColumn ) != -1 );
  165. strStatus.ReleaseBuffer();
  166. }
  167. /////////////////////////////////////////////////////////////
  168. void CVolatileSettPage::FillTheList()
  169. {
  170. LVITEM lvItem;
  171. int nActualIndex;
  172. BOOL *pbAlreadyInList;
  173. ULONG uCrtVerifiedDriver;
  174. int nItemCount;
  175. int nCrtListItem;
  176. TCHAR strDriverName[ _MAX_PATH ];
  177. BOOL bResult;
  178. if( m_KrnVerifState.DriverCount == 0 )
  179. {
  180. //
  181. // clear the list
  182. //
  183. VERIFY( m_DriversList.DeleteAllItems() );
  184. }
  185. else
  186. {
  187. //
  188. // there are some drivers currently verified
  189. //
  190. pbAlreadyInList = new BOOL[ m_KrnVerifState.DriverCount ];
  191. if( pbAlreadyInList == NULL )
  192. {
  193. return;
  194. }
  195. for( uCrtVerifiedDriver = 0; uCrtVerifiedDriver < m_KrnVerifState.DriverCount; uCrtVerifiedDriver++)
  196. {
  197. pbAlreadyInList[ uCrtVerifiedDriver ] = FALSE;
  198. }
  199. //
  200. // parse all the current list items
  201. //
  202. nItemCount = m_DriversList.GetItemCount();
  203. for( nCrtListItem = 0; nCrtListItem < nItemCount; nCrtListItem++ )
  204. {
  205. //
  206. // get the current driver's name from the list
  207. //
  208. ZeroMemory( &lvItem, sizeof( lvItem ) );
  209. lvItem.mask = LVIF_TEXT;
  210. lvItem.iItem = nCrtListItem;
  211. lvItem.iSubItem = 0;
  212. lvItem.pszText = strDriverName;
  213. lvItem.cchTextMax = sizeof( strDriverName ) / sizeof( strDriverName[0] );
  214. bResult = m_DriversList.GetItem( &lvItem );
  215. if( bResult == FALSE )
  216. {
  217. //
  218. // could not get the current item's attributes?
  219. //
  220. ASSERT( FALSE );
  221. //
  222. // remove this item from the list
  223. //
  224. VERIFY( m_DriversList.DeleteItem( nCrtListItem ) );
  225. nCrtListItem--;
  226. nItemCount--;
  227. }
  228. else
  229. {
  230. //
  231. // see is the current driver is still in m_KrnVerifState
  232. //
  233. for( uCrtVerifiedDriver = 0; uCrtVerifiedDriver < m_KrnVerifState.DriverCount; uCrtVerifiedDriver++)
  234. {
  235. if( _tcsicmp( strDriverName,
  236. m_KrnVerifState.DriverInfo[ uCrtVerifiedDriver ].Name ) == 0 )
  237. {
  238. //
  239. // update the item's data with the current index in the array
  240. //
  241. lvItem.mask = LVIF_PARAM;
  242. lvItem.lParam = uCrtVerifiedDriver;
  243. VERIFY( m_DriversList.SetItem( &lvItem ) != -1 );
  244. //
  245. // update the second column
  246. //
  247. UpdateStatusColumn( nCrtListItem, uCrtVerifiedDriver );
  248. //
  249. // mark the current driver as updated
  250. //
  251. pbAlreadyInList[ uCrtVerifiedDriver ] = TRUE;
  252. break;
  253. }
  254. }
  255. //
  256. // If the driver is no longer verified, remove it from the list
  257. //
  258. if( uCrtVerifiedDriver >= m_KrnVerifState.DriverCount )
  259. {
  260. VERIFY( m_DriversList.DeleteItem( nCrtListItem ) );
  261. nCrtListItem--;
  262. nItemCount--;
  263. }
  264. }
  265. }
  266. //
  267. // add the drivers that were not in the list before this update
  268. //
  269. for( uCrtVerifiedDriver = 0; uCrtVerifiedDriver < m_KrnVerifState.DriverCount; uCrtVerifiedDriver++)
  270. {
  271. if( ! pbAlreadyInList[ uCrtVerifiedDriver ] )
  272. {
  273. //
  274. // add a new item for this
  275. //
  276. ZeroMemory( &lvItem, sizeof( lvItem ) );
  277. //
  278. // sub-item 0
  279. //
  280. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  281. lvItem.lParam = uCrtVerifiedDriver;
  282. lvItem.iItem = m_DriversList.GetItemCount();
  283. lvItem.iSubItem = 0;
  284. lvItem.pszText = m_KrnVerifState.DriverInfo[ uCrtVerifiedDriver ].Name;
  285. nActualIndex = m_DriversList.InsertItem( &lvItem );
  286. VERIFY( nActualIndex != -1 );
  287. //
  288. // sub-item 1
  289. //
  290. UpdateStatusColumn( nActualIndex, uCrtVerifiedDriver );
  291. }
  292. }
  293. delete pbAlreadyInList;
  294. }
  295. }
  296. /////////////////////////////////////////////////////////////
  297. void CVolatileSettPage::UpdateStatusColumn( int nItemIndex, ULONG uCrtDriver )
  298. {
  299. LVITEM lvItem;
  300. CString strStatus;
  301. ASSERT( nItemIndex >= 0 &&
  302. (UINT)nItemIndex < m_KrnVerifState.DriverCount &&
  303. nItemIndex < m_DriversList.GetItemCount() &&
  304. uCrtDriver >= 0 &&
  305. uCrtDriver < m_KrnVerifState.DriverCount &&
  306. uCrtDriver < (ULONG)m_DriversList.GetItemCount() );
  307. // determine what's the appropriate value for the second column
  308. if( ! m_KrnVerifState.DriverInfo[ uCrtDriver ].Loads )
  309. {
  310. VERIFY( strStatus.LoadString( IDS_NEVER_LOADED ) );
  311. }
  312. else
  313. {
  314. if( m_KrnVerifState.DriverInfo[ uCrtDriver ].Loads ==
  315. m_KrnVerifState.DriverInfo[ uCrtDriver ].Unloads )
  316. {
  317. VERIFY( strStatus.LoadString( IDS_UNLOADED ) );
  318. }
  319. else
  320. {
  321. if( m_KrnVerifState.DriverInfo[ uCrtDriver ].Loads >
  322. m_KrnVerifState.DriverInfo[ uCrtDriver ].Unloads )
  323. {
  324. VERIFY( strStatus.LoadString( IDS_LOADED ) );
  325. }
  326. else
  327. {
  328. ASSERT( FALSE );
  329. VERIFY( strStatus.LoadString( IDS_UNKNOWN ) );
  330. }
  331. }
  332. }
  333. // update the list item
  334. memset( &lvItem, 0, sizeof( lvItem ) );
  335. lvItem.mask = LVIF_TEXT;
  336. lvItem.iItem = nItemIndex;
  337. lvItem.iSubItem = 1;
  338. lvItem.pszText = strStatus.GetBuffer( strStatus.GetLength() + 1 );
  339. VERIFY( m_DriversList.SetItem( &lvItem ) != -1 );
  340. strStatus.ReleaseBuffer();
  341. }
  342. /////////////////////////////////////////////////////////////
  343. int CALLBACK CVolatileSettPage::DrvStatusCmpFunc(
  344. LPARAM lParam1,
  345. LPARAM lParam2,
  346. LPARAM lParamSort)
  347. {
  348. UINT uIndex1 = (UINT)lParam1;
  349. UINT uIndex2 = (UINT)lParam2;
  350. CVolatileSettPage *pThis = (CVolatileSettPage *)lParamSort;
  351. ASSERT_VALID( pThis );
  352. int nCmpRez = 0;
  353. // sanity check
  354. if( uIndex1 > pThis->m_KrnVerifState.DriverCount ||
  355. uIndex2 > pThis->m_KrnVerifState.DriverCount )
  356. {
  357. ASSERT( FALSE );
  358. return 0;
  359. }
  360. // difference between loads and unloads #
  361. LONG lLoadDiff1 = (LONG)pThis->m_KrnVerifState.DriverInfo[ uIndex1 ].Loads -
  362. (LONG)pThis->m_KrnVerifState.DriverInfo[ uIndex1 ].Unloads;
  363. LONG lLoadDiff2 = (LONG)pThis->m_KrnVerifState.DriverInfo[ uIndex2 ].Loads -
  364. (LONG)pThis->m_KrnVerifState.DriverInfo[ uIndex2 ].Unloads;
  365. if( lLoadDiff1 == lLoadDiff2 )
  366. {
  367. nCmpRez = 0;
  368. }
  369. else
  370. {
  371. if( lLoadDiff1 > lLoadDiff2 )
  372. nCmpRez = 1;
  373. else
  374. nCmpRez = -1;
  375. }
  376. if( pThis->m_bAscendDrvStatusSort )
  377. nCmpRez *= -1;
  378. return nCmpRez;
  379. }
  380. /////////////////////////////////////////////////////////////
  381. int CALLBACK CVolatileSettPage::DrvNameCmpFunc(
  382. LPARAM lParam1,
  383. LPARAM lParam2,
  384. LPARAM lParamSort)
  385. {
  386. UINT uIndex1 = (UINT)lParam1;
  387. UINT uIndex2 = (UINT)lParam2;
  388. CVolatileSettPage *pThis = (CVolatileSettPage *)lParamSort;
  389. ASSERT_VALID( pThis );
  390. int nCmpRez = 0;
  391. // sanity check
  392. if( uIndex1 > pThis->m_KrnVerifState.DriverCount ||
  393. uIndex2 > pThis->m_KrnVerifState.DriverCount )
  394. {
  395. ASSERT( FALSE );
  396. return 0;
  397. }
  398. nCmpRez = _tcsicmp( pThis->m_KrnVerifState.DriverInfo[ uIndex1 ].Name,
  399. pThis->m_KrnVerifState.DriverInfo[ uIndex2 ].Name );
  400. if( ! nCmpRez )
  401. {
  402. // same name ???
  403. nCmpRez = 0;
  404. }
  405. else
  406. {
  407. if( pThis->m_bAscendDrvNameSort )
  408. nCmpRez *= -1;
  409. }
  410. return nCmpRez;
  411. }
  412. /////////////////////////////////////////////////////////////
  413. void CVolatileSettPage::OnRefreshTimerChanged()
  414. {
  415. UINT uTimerElapse = 0;
  416. // kill the pending timer
  417. if( m_uTimerHandler != 0 )
  418. {
  419. VERIFY( KillTimer( REFRESH_TIMER_ID ) );
  420. }
  421. // sanity check
  422. if( m_nUpdateIntervalIndex < 0 ||
  423. m_nUpdateIntervalIndex >= REFRESH_SPEED_VARS )
  424. {
  425. m_nUpdateIntervalIndex = 0;
  426. CheckRadioButton( IDC_VSETTINGS_MANUAL_RADIO, IDC_VSETTINGS_LOW_RADIO,
  427. IDC_VSETTINGS_MANUAL_RADIO );
  428. }
  429. // new timer interval
  430. uTimerElapse = uTimerIntervals[ m_nUpdateIntervalIndex ];
  431. if( uTimerElapse > 0 )
  432. {
  433. VERIFY( m_uTimerHandler = SetTimer( REFRESH_TIMER_ID,
  434. uTimerElapse, NULL ) );
  435. }
  436. }
  437. /////////////////////////////////////////////////////////////
  438. void CVolatileSettPage::SortTheList()
  439. {
  440. if( m_nSortColumnIndex )
  441. {
  442. m_DriversList.SortItems( DrvStatusCmpFunc, (LPARAM)this );
  443. }
  444. else
  445. {
  446. m_DriversList.SortItems( DrvNameCmpFunc, (LPARAM)this );
  447. }
  448. }
  449. /////////////////////////////////////////////////////////////
  450. // CVolatileSettPage message handlers
  451. BOOL CVolatileSettPage::OnInitDialog()
  452. {
  453. CPropertyPage::OnInitDialog();
  454. //
  455. // set the checkboxes state
  456. //
  457. if( KrnGetSystemVerifierState( &m_KrnVerifState ) &&
  458. m_KrnVerifState.DriverCount > 0 )
  459. {
  460. m_NormalVerifCheck.SetCheck( m_KrnVerifState.SpecialPool );
  461. m_PagedCCheck.SetCheck( m_KrnVerifState.IrqlChecking );
  462. m_AllocFCheck.SetCheck( m_KrnVerifState.FaultInjection );
  463. }
  464. //
  465. // see if we can modify options on the fly
  466. //
  467. if( g_OsVersion.dwMajorVersion < 5 || g_OsVersion.dwBuildNumber < 2055 )
  468. {
  469. m_NormalVerifCheck.EnableWindow( FALSE );
  470. m_PagedCCheck.EnableWindow( FALSE );
  471. m_AllocFCheck.EnableWindow( FALSE );
  472. }
  473. //
  474. // setup the list
  475. //
  476. SetupListHeader();
  477. FillTheList();
  478. SortTheList();
  479. OnRefreshTimerChanged();
  480. UpdateControlsState();
  481. return TRUE; // return TRUE unless you set the focus to a control
  482. // EXCEPTION: OCX Property Pages should return FALSE
  483. }
  484. /////////////////////////////////////////////////////////////
  485. void CVolatileSettPage::OnCrtstatRefreshButton()
  486. {
  487. if( UpdateData( FALSE ) )
  488. {
  489. FillTheList();
  490. SortTheList();
  491. }
  492. }
  493. /////////////////////////////////////////////////////////////
  494. void CVolatileSettPage::OnColumnclickCrtstatDriversList(NMHDR* pNMHDR,
  495. LRESULT* pResult)
  496. {
  497. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  498. if( pNMListView->iSubItem )
  499. {
  500. if( m_nSortColumnIndex == pNMListView->iSubItem )
  501. {
  502. // change the current ascend/descend order for this column
  503. m_bAscendDrvStatusSort = !m_bAscendDrvStatusSort;
  504. }
  505. }
  506. else
  507. {
  508. if( m_nSortColumnIndex == pNMListView->iSubItem )
  509. {
  510. // change the current ascend/descend order for this column
  511. m_bAscendDrvNameSort = !m_bAscendDrvNameSort;
  512. }
  513. }
  514. m_nSortColumnIndex = pNMListView->iSubItem;
  515. SortTheList();
  516. *pResult = 0;
  517. }
  518. /////////////////////////////////////////////////////////////
  519. void CVolatileSettPage::OnRclickDriversList(NMHDR* pNMHDR, LRESULT* pResult)
  520. {
  521. POINT point;
  522. CMenu theMenu, *pTrackedMenu = NULL;
  523. BOOL bShowRemoveMenuItem = FALSE;
  524. int nItems = m_DriversList.GetItemCount();
  525. for(int nCrtItem = 0; nCrtItem < nItems; nCrtItem++ )
  526. {
  527. if( m_DriversList.GetItemState( nCrtItem, LVIS_SELECTED ) &
  528. LVIS_SELECTED )
  529. {
  530. bShowRemoveMenuItem = TRUE;
  531. }
  532. }
  533. if( bShowRemoveMenuItem )
  534. {
  535. VERIFY( theMenu.LoadMenu( IDM_ADD_REMOVE_DRIVERS ) );
  536. }
  537. else
  538. {
  539. VERIFY( theMenu.LoadMenu( IDM_ADD_DRIVERS ) );
  540. }
  541. pTrackedMenu = theMenu.GetSubMenu( 0 );
  542. if( pTrackedMenu != NULL )
  543. {
  544. ASSERT_VALID( pTrackedMenu );
  545. VERIFY( ::GetCursorPos( &point ) );
  546. VERIFY( pTrackedMenu->TrackPopupMenu(
  547. TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
  548. point.x, point.y,
  549. this ) );
  550. }
  551. else
  552. {
  553. ASSERT( FALSE );
  554. }
  555. *pResult = 0;
  556. }
  557. /////////////////////////////////////////////////////////////
  558. void CVolatileSettPage::OnTimer(UINT nIDEvent)
  559. {
  560. if( m_bTimerBlocked != TRUE && nIDEvent == REFRESH_TIMER_ID )
  561. {
  562. CDrvChkSheet *pParentSheet = (CDrvChkSheet *)GetParent();
  563. if( pParentSheet != NULL )
  564. {
  565. ASSERT_VALID( pParentSheet );
  566. if( pParentSheet->GetActivePage() == this )
  567. {
  568. // refresh the displayed data
  569. OnCrtstatRefreshButton();
  570. }
  571. }
  572. }
  573. CPropertyPage::OnTimer(nIDEvent);
  574. }
  575. /////////////////////////////////////////////////////////////////////////////
  576. void CVolatileSettPage::OnCheck()
  577. {
  578. m_eApplyButtonState = vrfControlEnabled;
  579. UpdateControlsState();
  580. }
  581. /////////////////////////////////////////////////////////////////////////////
  582. void CVolatileSettPage::OnApplyButton()
  583. {
  584. if( ApplyTheChanges() )
  585. {
  586. m_eApplyButtonState = vrfControlDisabled;
  587. UpdateControlsState();
  588. }
  589. }
  590. /////////////////////////////////////////////////////////////////////////////
  591. BOOL CVolatileSettPage::ApplyTheChanges()
  592. {
  593. if( UpdateData( TRUE ) )
  594. {
  595. return VrfSetVolatileOptions(
  596. m_bNormalCheck,
  597. m_bPagedCCheck,
  598. m_bAllocFCheck );
  599. }
  600. return FALSE;
  601. }
  602. /////////////////////////////////////////////////////////////
  603. BOOL CVolatileSettPage::OnQueryCancel()
  604. {
  605. // give parent PropertySheet a chance to refuse the Cancel if needed
  606. CDrvChkSheet *pParentSheet = (CDrvChkSheet *)GetParent();
  607. if( pParentSheet != NULL )
  608. {
  609. ASSERT_VALID( pParentSheet );
  610. if( ! pParentSheet->OnQueryCancel() )
  611. {
  612. return FALSE;
  613. }
  614. }
  615. return CPropertyPage::OnQueryCancel();
  616. }
  617. /////////////////////////////////////////////////////////////
  618. BOOL CVolatileSettPage::OnApply()
  619. {
  620. // refuse to apply
  621. // (we don't use the standard PropertSheet buttons; Apply, OK)
  622. return FALSE;
  623. }
  624. /////////////////////////////////////////////////////////////
  625. void CVolatileSettPage::OnCrtstatManualRadio()
  626. {
  627. // switch to manual refresh
  628. m_nUpdateIntervalIndex = 0;
  629. OnRefreshTimerChanged();
  630. }
  631. void CVolatileSettPage::OnCrtstatHspeedRadio()
  632. {
  633. // switch to high speed refresh
  634. m_nUpdateIntervalIndex = 1;
  635. OnRefreshTimerChanged();
  636. }
  637. void CVolatileSettPage::OnCrtstatNormRadio()
  638. {
  639. // switch to normal speed refresh
  640. m_nUpdateIntervalIndex = 2;
  641. OnRefreshTimerChanged();
  642. }
  643. void CVolatileSettPage::OnCrtstatLowRadio()
  644. {
  645. // switch to low speed refresh
  646. m_nUpdateIntervalIndex = 3;
  647. OnRefreshTimerChanged();
  648. }
  649. /////////////////////////////////////////////////////////////
  650. #define VRF_MAX_CHARS_FOR_OPEN 4096
  651. void CVolatileSettPage::OnAddButton()
  652. {
  653. static BOOL bChangedDirectory = FALSE;
  654. POSITION pos;
  655. BOOL bEnabledSome = FALSE;
  656. DWORD dwRetValue;
  657. DWORD dwOldMaxFileName = 0;
  658. DWORD dwErrorCode;
  659. int nFileNameStartIndex;
  660. INT_PTR nResult;
  661. TCHAR szDriversDir[ _MAX_PATH ];
  662. TCHAR szAppTitle[ _MAX_PATH ];
  663. TCHAR *szFilesBuffer = NULL;
  664. TCHAR *szOldFilesBuffer = NULL;
  665. CString strPathName;
  666. CString strFileName;
  667. CFileDialog fileDlg(
  668. TRUE, // open file
  669. _T( "sys" ), // default extension
  670. NULL, // no initial file name
  671. OFN_ALLOWMULTISELECT | // multiple selection
  672. OFN_HIDEREADONLY | // hide the "open read-only" checkbox
  673. OFN_NONETWORKBUTTON | // no network button
  674. OFN_NOTESTFILECREATE | // don't test for write protection, a full disk, etc.
  675. OFN_SHAREAWARE, // don't check the existance of file with OpenFile
  676. _T( "Drivers (*.sys)|*.sys||" ) ); // only one filter
  677. //
  678. // check the max length for the returned string
  679. //
  680. if( fileDlg.m_ofn.nMaxFile < VRF_MAX_CHARS_FOR_OPEN )
  681. {
  682. //
  683. // allocate a new buffer for the file names
  684. //
  685. szFilesBuffer = new TCHAR[ VRF_MAX_CHARS_FOR_OPEN ];
  686. szFilesBuffer[ 0 ] = (TCHAR)0;
  687. if( szFilesBuffer != NULL )
  688. {
  689. //
  690. // Save the old buffer address and length
  691. //
  692. dwOldMaxFileName = fileDlg.m_ofn.nMaxFile;
  693. szOldFilesBuffer = fileDlg.m_ofn.lpstrFile;
  694. //
  695. // Set the new buffer address and length
  696. //
  697. fileDlg.m_ofn.lpstrFile = szFilesBuffer;
  698. fileDlg.m_ofn.nMaxFile = VRF_MAX_CHARS_FOR_OPEN;
  699. }
  700. }
  701. //
  702. // Dialog title
  703. //
  704. if( GetStringFromResources(
  705. IDS_APPTITLE,
  706. szAppTitle,
  707. ARRAY_LENGTH( szAppTitle ) ) )
  708. {
  709. fileDlg.m_ofn.lpstrTitle = szAppTitle;
  710. }
  711. //
  712. // We change directory first time we try this to %windir%\system32\drivers
  713. //
  714. if( bChangedDirectory == FALSE )
  715. {
  716. dwRetValue = ExpandEnvironmentStrings(
  717. _T( "%windir%\\system32\\drivers" ),
  718. szDriversDir,
  719. ARRAY_LENGTH( szDriversDir ) );
  720. if( dwRetValue > 0 && dwRetValue <= ARRAY_LENGTH( szDriversDir ) )
  721. {
  722. fileDlg.m_ofn.lpstrInitialDir = szDriversDir;
  723. }
  724. bChangedDirectory = TRUE;
  725. }
  726. //
  727. // show the file selection dialog
  728. //
  729. nResult = fileDlg.DoModal();
  730. switch( nResult )
  731. {
  732. case IDOK:
  733. break;
  734. case IDCANCEL:
  735. goto cleanup;
  736. default:
  737. dwErrorCode = CommDlgExtendedError();
  738. if( dwErrorCode == FNERR_BUFFERTOOSMALL )
  739. {
  740. VrfErrorResourceFormat(
  741. IDS_TOO_MANY_FILES_SELECTED );
  742. }
  743. else
  744. {
  745. VrfErrorResourceFormat(
  746. IDS_CANNOT_OPEN_FILES,
  747. dwErrorCode );
  748. }
  749. goto cleanup;
  750. }
  751. //
  752. // Block the timer
  753. //
  754. m_bTimerBlocked = TRUE;
  755. //
  756. // Parse all the selected files and try to enable them for verification
  757. //
  758. pos = fileDlg.GetStartPosition();
  759. while( pos != NULL )
  760. {
  761. //
  762. // Get the full path for the next file
  763. //
  764. strPathName = fileDlg.GetNextPathName( pos );
  765. //
  766. // split only the file name, without the directory
  767. //
  768. nFileNameStartIndex = strPathName.ReverseFind( _T( '\\' ) );
  769. if( nFileNameStartIndex < 0 )
  770. {
  771. //
  772. // this shoudn't happen but you never know :-)
  773. //
  774. nFileNameStartIndex = 0;
  775. }
  776. else
  777. {
  778. //
  779. // skip the backslash
  780. //
  781. nFileNameStartIndex++;
  782. }
  783. strFileName = strPathName.Right( strPathName.GetLength() - nFileNameStartIndex );
  784. //
  785. // Try to add this driver to the current verification list
  786. //
  787. if( VrfVolatileAddDriver( (LPCTSTR)strFileName ) )
  788. {
  789. bEnabledSome = TRUE;
  790. }
  791. }
  792. //
  793. // Enable the timer
  794. //
  795. m_bTimerBlocked = FALSE;
  796. //
  797. // Refresh
  798. //
  799. if( bEnabledSome == TRUE )
  800. {
  801. OnCrtstatRefreshButton();
  802. }
  803. cleanup:
  804. if( szFilesBuffer != NULL )
  805. {
  806. fileDlg.m_ofn.nMaxFile = dwOldMaxFileName;
  807. fileDlg.m_ofn.lpstrFile = szOldFilesBuffer;
  808. delete szFilesBuffer;
  809. }
  810. }
  811. /////////////////////////////////////////////////////////////
  812. void CVolatileSettPage::OnDontVerifyButton()
  813. {
  814. int nItems;
  815. UINT uIndexInArray;
  816. BOOL bDisabledSome = FALSE;
  817. //
  818. // Block the timer
  819. //
  820. m_bTimerBlocked = TRUE;
  821. //
  822. // The number of items in the list
  823. //
  824. nItems = m_DriversList.GetItemCount();
  825. //
  826. // Parse all the items, looking for the selected ones.
  827. //
  828. for(int nCrtItem = 0; nCrtItem < nItems; nCrtItem++ )
  829. {
  830. if( m_DriversList.GetItemState( nCrtItem, LVIS_SELECTED ) & LVIS_SELECTED )
  831. {
  832. //
  833. // Get the index of the corresponding entry in the array
  834. //
  835. uIndexInArray = (UINT)m_DriversList.GetItemData( nCrtItem );
  836. //
  837. // sanity checks
  838. //
  839. if( uIndexInArray >= m_KrnVerifState.DriverCount )
  840. {
  841. ASSERT( FALSE );
  842. continue;
  843. }
  844. if( VrfVolatileRemoveDriver( m_KrnVerifState.DriverInfo[ uIndexInArray ].Name ) )
  845. {
  846. bDisabledSome = TRUE;
  847. }
  848. }
  849. }
  850. //
  851. // Enable the timer
  852. //
  853. m_bTimerBlocked = FALSE;
  854. //
  855. // If we disabled some drivers' verification we need to refresh the list
  856. //
  857. if( bDisabledSome )
  858. {
  859. OnCrtstatRefreshButton();
  860. }
  861. }
  862. /////////////////////////////////////////////////////////////
  863. LONG CVolatileSettPage::OnHelp( WPARAM wParam, LPARAM lParam )
  864. {
  865. LONG lResult = 0;
  866. LPHELPINFO lpHelpInfo = (LPHELPINFO)lParam;
  867. ::WinHelp(
  868. (HWND) lpHelpInfo->hItemHandle,
  869. VERIFIER_HELP_FILE,
  870. HELP_WM_HELP,
  871. (DWORD_PTR) MyHelpIds );
  872. return lResult;
  873. }
  874. /////////////////////////////////////////////////////////////
  875. LONG CVolatileSettPage::OnContextMenu( WPARAM wParam, LPARAM lParam )
  876. {
  877. LONG lResult = 0;
  878. ::WinHelp(
  879. (HWND) wParam,
  880. VERIFIER_HELP_FILE,
  881. HELP_CONTEXTMENU,
  882. (DWORD_PTR) MyHelpIds );
  883. return lResult;
  884. }