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.

3726 lines
113 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 2001.
  5. //
  6. // File: Snapin.cxx
  7. //
  8. // Contents: MMC snapin for CI.
  9. //
  10. // History: 26-Nov-1996 KyleP Created
  11. // 20-Jan-1999 SLarimor Modified rescan interface to include
  12. // Full and Incremental options separatly
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include <ISReg.hxx>
  18. #include <CIARes.h>
  19. #include <snapin.hxx>
  20. #include <dataobj.hxx>
  21. #include <propsht.hxx>
  22. #include <callback.hxx>
  23. #include <cmddlg.hxx>
  24. #include <classid.hxx>
  25. #include <catadmin.hxx>
  26. #include <catalog.hxx>
  27. #include <ntverp.h>
  28. //
  29. // Global data
  30. //
  31. //
  32. // NOTE: Any new menus added to this array must be at the same location as
  33. // the value of "lCommandID", which is the third member of the
  34. // struct CONTEXTMENUITEM ie. comidAddScope = 0 below.
  35. // Additionally, you should add another Win4Assert in the
  36. // "CCISnapinData::Initialize" method below.
  37. CONTEXTMENUITEM aContextMenus[] = {
  38. // Add scope
  39. { STRINGRESOURCE( srCMScope ),
  40. STRINGRESOURCE( srCMScopeHelp ),
  41. comidAddScope,
  42. CCM_INSERTIONPOINTID_PRIMARY_NEW,
  43. MF_ENABLED,
  44. 0 },
  45. // Add catalog
  46. { STRINGRESOURCE( srCMAddCatalog ),
  47. STRINGRESOURCE( srCMAddCatalogHelp ),
  48. comidAddCatalog,
  49. CCM_INSERTIONPOINTID_PRIMARY_NEW,
  50. MF_ENABLED,
  51. 0 },
  52. // Rescan Full scope
  53. { STRINGRESOURCE( srCMRescanFull ),
  54. STRINGRESOURCE( srCMRescanFullHelp ),
  55. comidRescanFullScope,
  56. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  57. MF_ENABLED,
  58. 0 },
  59. // Force merge
  60. { STRINGRESOURCE( srCMMerge ),
  61. STRINGRESOURCE( srCMMergeHelp ),
  62. comidMergeCatalog,
  63. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  64. MF_ENABLED,
  65. 0 },
  66. // Start CI
  67. { STRINGRESOURCE( srCMStartCI ),
  68. STRINGRESOURCE( srCMStartCIHelp ),
  69. comidStartCI,
  70. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  71. MF_ENABLED,
  72. 0 },
  73. // Stop CI
  74. { STRINGRESOURCE( srCMStopCI ),
  75. STRINGRESOURCE( srCMStopCIHelp ),
  76. comidStopCI,
  77. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  78. MF_ENABLED,
  79. 0 },
  80. // Pause CI
  81. { STRINGRESOURCE( srCMPauseCI ),
  82. STRINGRESOURCE( srCMPauseCIHelp ),
  83. comidPauseCI,
  84. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  85. MF_ENABLED,
  86. 0 },
  87. // Refresh properties list
  88. { STRINGRESOURCE( srRefreshProperties ),
  89. STRINGRESOURCE( srRefreshPropertiesHelp ),
  90. comidRefreshProperties,
  91. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  92. MF_ENABLED,
  93. 0 },
  94. // Empty catalog
  95. { STRINGRESOURCE( srCMEmptyCatalog ),
  96. STRINGRESOURCE( srCMEmptyCatalogHelp ),
  97. comidEmptyCatalog,
  98. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  99. MF_ENABLED,
  100. 0 },
  101. // Tune performance
  102. { STRINGRESOURCE( srCMTunePerformance ),
  103. STRINGRESOURCE( srCMTunePerformanceHelp ),
  104. comidTunePerfCITop,
  105. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  106. MF_ENABLED,
  107. 0 },
  108. // Duplication of the commonly used menus
  109. // at the top of the menu.
  110. // Start CI
  111. { STRINGRESOURCE( srCMStartCI ),
  112. STRINGRESOURCE( srCMStartCIHelp ),
  113. comidStartCITop,
  114. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  115. MF_ENABLED,
  116. 0 },
  117. // Stop CI
  118. { STRINGRESOURCE( srCMStopCI ),
  119. STRINGRESOURCE( srCMStopCIHelp ),
  120. comidStopCITop,
  121. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  122. MF_ENABLED,
  123. 0 },
  124. // Pause CI
  125. { STRINGRESOURCE( srCMPauseCI ),
  126. STRINGRESOURCE( srCMPauseCIHelp ),
  127. comidPauseCITop,
  128. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  129. MF_ENABLED,
  130. 0 },
  131. // Rescan Incremental scope
  132. { STRINGRESOURCE( srCMRescanIncremental ),
  133. STRINGRESOURCE( srCMRescanIncrementalHelp ),
  134. comidRescanIncrementalScope,
  135. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  136. MF_ENABLED,
  137. 0 },
  138. };
  139. static DWORD aIds[] =
  140. {
  141. IDOK, HIDP_OK,
  142. IDCANCEL, HIDP_CANCEL,
  143. // Catalog properties
  144. IDDI_FILTER_UNKNOWN, HIDP_GENERATION_FILTER_UNKNOWN,
  145. IDDI_CHARACTERIZATION, HIDP_GENERATION_GENERATE_CHARACTERIZATION,
  146. IDDI_CHARSIZE_STATIC, HIDP_GENERATION_MAXIMUM_SIZE,
  147. IDDI_CHARACTERIZATION_SIZE, HIDP_GENERATION_MAXIMUM_SIZE,
  148. IDDI_SPIN_CHARACTERIZATION, HIDP_GENERATION_MAXIMUM_SIZE,
  149. IDDI_SELECT_SIZE, HIDP_LOCATION_SIZE,
  150. IDDI_SIZE, HIDP_LOCATION_SIZE,
  151. IDDI_SELECT_PATH2, HIDP_CATALOG_LOCATION,
  152. IDDI_PATH, HIDP_CATALOG_LOCATION,
  153. IDDI_SELECT_PROPCACHE_SIZE, HIDP_PROPCACHE_SIZE,
  154. IDDI_PROPCACHE_SIZE, HIDP_PROPCACHE_SIZE,
  155. IDDI_VSERVER_STATIC, HIDP_WEB_VSERVER,
  156. IDDI_VIRTUAL_SERVER, HIDP_WEB_VSERVER,
  157. IDDI_NNTP_STATIC, HIDP_WEB_NNTPSERVER,
  158. IDDI_NNTP_SERVER, HIDP_WEB_NNTPSERVER,
  159. IDDI_AUTO_ALIAS, HIDP_ALIAS_NETWORK_SHARES,
  160. IDDI_INHERIT1, HIDP_SETTINGS_INHERIT1,
  161. IDDI_INHERIT2, HIDP_SETTINGS_INHERIT2,
  162. IDDI_GROUP_INHERIT, HIDP_INHERIT,
  163. IDDI_SELECT_CATNAME, HIDP_CATALOG_NAME,
  164. IDDI_CATNAME, HIDP_CATALOG_NAME,
  165. // New catalog
  166. IDDI_SELECT_CATPATH, HIDP_LOCATION_LOCATION,
  167. IDDI_CATPATH, HIDP_LOCATION_LOCATION,
  168. IDDI_SELECT_CATNAME2, HIDP_LOCATION_NAME,
  169. IDDI_CATNAME2, HIDP_LOCATION_NAME,
  170. IDDI_BROWSE, HIDP_LOCATION_BROWSE,
  171. // Property dialog box
  172. IDDI_SELECT_PROPSET, HIDP_PROPERTY_SET,
  173. IDDI_PROPSET, HIDP_PROPERTY_SET,
  174. IDDI_SELECT_PROPERTY, HIDP_PROPERTY_PROPERTY,
  175. IDDI_PROPERTY, HIDP_PROPERTY_PROPERTY,
  176. IDDI_CACHED, HIDP_PROPERTY_CACHED,
  177. IDDI_SELECT_DATATYPE, HIDP_PROPERTY_DATATYPE,
  178. IDDI_DATATYPE, HIDP_PROPERTY_DATATYPE,
  179. IDDI_SELECT_CACHEDSIZE, HIDP_PROPERTY_SIZE,
  180. IDDI_CACHEDSIZE, HIDP_PROPERTY_SIZE,
  181. IDDI_SPIN_CACHEDSIZE, HIDP_PROPERTY_SIZE,
  182. IDDI_SELECT_STORAGELEVEL, HIDP_PROPERTY_STORAGELEVEL,
  183. IDDI_STORAGELEVEL, HIDP_PROPERTY_STORAGELEVEL,
  184. //IDDI_COMPNAME, ,
  185. IDDI_LOCAL_COMPUTER, HIDP_CONNECT_LOCAL,
  186. IDDI_REMOTE_COMPUTER, HIDP_CONNECT_ANOTHER,
  187. IDDI_COMPNAME, HIDP_CONNECT_ANOTHER,
  188. // New directory
  189. IDDI_SELECT_PATH, HIDP_SCOPE_PATH,
  190. IDDI_DIRPATH, HIDP_SCOPE_PATH,
  191. IDDI_BROWSE, HIDP_SCOPE_BROWSE,
  192. IDDI_SELECT_ALIAS, HIDP_SCOPE_ALIAS,
  193. IDDI_ALIAS, HIDP_SCOPE_ALIAS,
  194. IDDI_SELECT_USER_NAME, HIDP_SCOPE_USER_NAME,
  195. IDDI_USER_NAME, HIDP_SCOPE_USER_NAME,
  196. IDDI_SELECT_PASSWORD, HIDP_SCOPE_PASSWORD,
  197. IDDI_PASSWORD, HIDP_SCOPE_PASSWORD,
  198. IDDI_INCLUDE, HIDP_SCOPE_INCLUDE,
  199. IDDI_EXCLUDE, HIDP_SCOPE_EXCLUDE,
  200. IDDI_ACCOUNT_INFORMATION, HIDP_ACCOUNT_INFORMATION,
  201. IDDI_INCLUSION, HIDP_INCLUSION,
  202. // Performance Tuning
  203. IDDI_DEDICATED, HIDP_DEDICATED,
  204. IDDI_USEDOFTEN, HIDP_USEDOFTEN,
  205. IDDI_USEDOCCASIONALLY, HIDP_USEDOCCASIONALLY,
  206. IDDI_NEVERUSED, HIDP_NEVERUSED,
  207. IDDI_CUSTOMIZE, HIDP_CUSTOMIZE,
  208. IDDI_ADVANCED, HIDP_ADVANCED_CONFIG,
  209. IDDI_SELECT_INDEXING, HIDP_INDEXING_PERFORMANCE,
  210. IDDI_SLIDER_INDEXING, HIDP_INDEXING_PERFORMANCE,
  211. IDDI_SELECT_QUERYING, HIDP_QUERY_PERFORMANCE,
  212. IDDI_SLIDER_QUERYING, HIDP_QUERY_PERFORMANCE,
  213. 0, 0 };
  214. MMCBUTTON aContextButtons[] =
  215. {
  216. // Start CI
  217. { comidStartCIButton, // 0
  218. comidStartCITop,
  219. TBSTATE_ENABLED,
  220. TBSTYLE_BUTTON,
  221. STRINGRESOURCE( srCMStartCI ),
  222. STRINGRESOURCE( srCMStartCIHelp )
  223. },
  224. // Stop CI
  225. { comidStopCIButton, // 1
  226. comidStopCITop,
  227. TBSTATE_ENABLED,
  228. TBSTYLE_BUTTON,
  229. STRINGRESOURCE( srCMStopCI ),
  230. STRINGRESOURCE( srCMStopCIHelp )
  231. },
  232. // Pause CI
  233. { comidPauseCIButton, // 1
  234. comidPauseCITop,
  235. TBSTATE_ENABLED,
  236. TBSTYLE_BUTTON,
  237. STRINGRESOURCE( srCMPauseCI ),
  238. STRINGRESOURCE( srCMPauseCIHelp )
  239. }
  240. };
  241. //
  242. // Registry constants
  243. //
  244. WCHAR const wszSnapinPath[] = L"Software\\Microsoft\\MMC\\SnapIns\\";
  245. WCHAR const wszTriedEnable[] = L"TriedEnable";
  246. //
  247. // Global variables
  248. //
  249. extern long gulcInstances;
  250. extern CStaticMutexSem gmtxTimer;
  251. HINSTANCE ghInstance;
  252. DECLARE_INFOLEVEL(cia)
  253. //
  254. // Function prototypes
  255. //
  256. SCODE StartMenu( IContextMenuCallback * piCallback, BOOL fTop = TRUE );
  257. SCODE StopMenu( IContextMenuCallback * piCallback, BOOL fTop = TRUE );
  258. SCODE PauseMenu( IContextMenuCallback * piCallback, BOOL fTop = TRUE );
  259. SCODE DisabledMenu( IContextMenuCallback * piCallback, BOOL fTop = TRUE );
  260. SCODE SetStartStopMenu( IContextMenuCallback * piCallback, BOOL fTop = TRUE );
  261. BOOL WINAPI DllMain( HANDLE hInstance, DWORD dwReason, LPVOID dwReserved )
  262. {
  263. BOOL fRetval = TRUE;
  264. TRANSLATE_EXCEPTIONS;
  265. TRY
  266. {
  267. if ( dwReason == DLL_PROCESS_ATTACH )
  268. {
  269. ghInstance = (HINSTANCE)hInstance;
  270. gmtxTimer.Init();
  271. InitStrings( ghInstance );
  272. }
  273. }
  274. CATCH( CException, e )
  275. {
  276. // About the only thing this could be is STATUS_NO_MEMORY which
  277. // can be thrown by InitializeCriticalSection.
  278. ciaDebugOut(( DEB_ERROR,
  279. "CIADMIN: Exception %#x in DllMain\n",
  280. e.GetErrorCode()));
  281. #if CIDBG == 1 // for debugging NTRAID 340297
  282. if (e.GetErrorCode() == STATUS_NO_MEMORY)
  283. DbgPrint( "CIADMIN: STATUS_NO_MEMORY exception in DllMain\n");
  284. else
  285. DbgPrint( "CIADMIN: ??? Exception in DllMain\n");
  286. #endif // CIDBG == 1
  287. fRetval = FALSE;
  288. }
  289. END_CATCH
  290. UNTRANSLATE_EXCEPTIONS;
  291. return fRetval;
  292. }
  293. // Detect if we are running on a server or a workstation
  294. BOOL IsNTServer()
  295. {
  296. BOOL fServer = FALSE;
  297. CRegAccess reg( RTL_REGISTRY_CONTROL,
  298. L"ProductOptions" );
  299. WCHAR awcProductType[ MAX_PATH ];
  300. reg.Get( L"ProductType",
  301. awcProductType,
  302. sizeof awcProductType / sizeof WCHAR );
  303. // winnt, pdc/bdc, server.
  304. // note: 4.0 bdcs are LanmanNt, 5.0+ are spec'ed to be LansecNt
  305. if ( !_wcsicmp( awcProductType, L"WinNt" ) )
  306. fServer = FALSE;
  307. else if ( ( !_wcsicmp( awcProductType, L"LanmanNt" ) ) ||
  308. ( !_wcsicmp( awcProductType, L"LansecNt" ) ) ||
  309. ( !_wcsicmp( awcProductType, L"ServerNt" ) ) )
  310. fServer = TRUE;
  311. return fServer;
  312. } //IsNTServer
  313. //+-------------------------------------------------------------------------
  314. //
  315. // Method: CCISnapinData::QueryInterface
  316. //
  317. // Synopsis: Switch from one interface to another
  318. //
  319. // History: 26-Nov-1996 KyleP Created
  320. //
  321. //--------------------------------------------------------------------------
  322. SCODE STDMETHODCALLTYPE CCISnapinData::QueryInterface( REFIID riid,
  323. void ** ppvObject )
  324. {
  325. ciaDebugOut(( DEB_ITRACE, "CCISnapin::QueryInterface " ));
  326. SCODE sc = S_OK;
  327. if ( 0 == ppvObject )
  328. return E_INVALIDARG;
  329. if ( IID_IComponentData == riid )
  330. *ppvObject = (IUnknown *)(IComponentData *)this;
  331. else if ( IID_IExtendPropertySheet == riid )
  332. *ppvObject = (IUnknown *)(IExtendPropertySheet *)this;
  333. else if ( IID_IExtendContextMenu == riid )
  334. *ppvObject = (IUnknown *)(IExtendContextMenu *)this;
  335. else if ( IID_IPersistStream == riid )
  336. *ppvObject = (IUnknown *)(IPersistStream *)this;
  337. else if ( IID_ISnapinAbout == riid )
  338. *ppvObject = (IUnknown *)(ISnapinAbout *)this;
  339. else if ( IID_ISnapinHelp == riid )
  340. *ppvObject = (IUnknown *)(ISnapinHelp *)this;
  341. else if ( IID_IExtendControlbar == riid )
  342. *ppvObject = (IUnknown *)(IExtendControlbar *)this;
  343. else if ( IID_IUnknown == riid )
  344. *ppvObject = (IUnknown *)(IComponentData *)this;
  345. else
  346. sc = E_NOINTERFACE;
  347. if ( SUCCEEDED( sc ) )
  348. AddRef();
  349. return sc;
  350. } //QueryInterface
  351. //+-------------------------------------------------------------------------
  352. //
  353. // Method: CCISnapinData::AddRef
  354. //
  355. // Synopsis: Increment ref count
  356. //
  357. // History: 26-Nov-1996 KyleP Created
  358. //
  359. //--------------------------------------------------------------------------
  360. ULONG STDMETHODCALLTYPE CCISnapinData::AddRef()
  361. {
  362. ciaDebugOut(( DEB_ITRACE, "CCISnapinData::AddRef\n" ));
  363. return InterlockedIncrement( &_uRefs );
  364. }
  365. //+-------------------------------------------------------------------------
  366. //
  367. // Method: CCISnapinData::Release
  368. //
  369. // Synopsis: Deccrement ref count
  370. //
  371. // History: 26-Nov-1996 KyleP Created
  372. //
  373. //--------------------------------------------------------------------------
  374. ULONG STDMETHODCALLTYPE CCISnapinData::Release()
  375. {
  376. ciaDebugOut(( DEB_ITRACE, "CCISnapinData::Release\n" ));
  377. unsigned long uTmp = InterlockedDecrement( &_uRefs );
  378. if ( 0 == uTmp )
  379. delete this;
  380. return(uTmp);
  381. }
  382. SCODE STDMETHODCALLTYPE CCISnapinData::Initialize( IUnknown * pUnk )
  383. {
  384. ciaDebugOut(( DEB_ITRACE, "CCISnapinData::Initialize\n" ));
  385. //
  386. // Parameter checking.
  387. //
  388. if ( 0 == pUnk )
  389. return E_INVALIDARG;
  390. // Ensure that contex menus are in correct location in menu array.
  391. Win4Assert( comidAddScope == aContextMenus[comidAddScope].lCommandID );
  392. Win4Assert( comidAddCatalog == aContextMenus[comidAddCatalog].lCommandID );
  393. Win4Assert( comidRescanFullScope == aContextMenus[comidRescanFullScope].lCommandID );
  394. Win4Assert( comidMergeCatalog == aContextMenus[comidMergeCatalog].lCommandID );
  395. Win4Assert( comidStartCI == aContextMenus[comidStartCI].lCommandID );
  396. Win4Assert( comidStopCI == aContextMenus[comidStopCI].lCommandID );
  397. Win4Assert( comidPauseCI == aContextMenus[comidPauseCI].lCommandID );
  398. Win4Assert( comidRefreshProperties == aContextMenus[comidRefreshProperties].lCommandID );
  399. Win4Assert( comidEmptyCatalog == aContextMenus[comidEmptyCatalog].lCommandID );
  400. Win4Assert( comidTunePerfCITop == aContextMenus[comidTunePerfCITop].lCommandID );
  401. Win4Assert( comidStartCITop == aContextMenus[comidStartCITop].lCommandID );
  402. Win4Assert( comidStopCITop == aContextMenus[comidStopCITop].lCommandID );
  403. Win4Assert( comidPauseCITop == aContextMenus[comidPauseCITop].lCommandID );
  404. Win4Assert( comidRescanIncrementalScope == aContextMenus[comidRescanIncrementalScope].lCommandID );
  405. TRANSLATE_EXCEPTIONS;
  406. SCODE sc;
  407. TRY
  408. {
  409. do
  410. {
  411. //
  412. // Collect interfaces
  413. //
  414. sc = pUnk->QueryInterface( IID_IConsole, (void **)&_pFrame );
  415. if ( FAILED(sc) )
  416. break;
  417. sc = _pFrame->GetMainWindow(&_hFrameWindow);
  418. if ( FAILED(sc) )
  419. break;
  420. //sc = _pFrame->QueryInterface( IID_IHeaderCtrl, (void **)&_pHeader );
  421. //
  422. //if ( FAILED(sc) )
  423. // break;
  424. sc = _pFrame->QueryInterface(IID_IConsoleNameSpace, (void **)&_pScopePane );
  425. if ( FAILED(sc) )
  426. break;
  427. _rootNode.Init( _pScopePane );
  428. _Catalogs.Init( _pScopePane );
  429. //
  430. // Initialize resources
  431. //
  432. IImageList * pImageList;
  433. sc = _pFrame->QueryScopeImageList( &pImageList );
  434. if ( FAILED(sc) )
  435. break;
  436. sc = InitImageResources( pImageList );
  437. pImageList->Release();
  438. if ( FAILED(sc) )
  439. break;
  440. }
  441. while ( FALSE );
  442. }
  443. CATCH( CException, e )
  444. {
  445. sc = e.GetErrorCode();
  446. ciaDebugOut(( DEB_ERROR, "Exception 0x%x caught in CCISnapinData::Initialize\n", sc ));
  447. }
  448. END_CATCH
  449. UNTRANSLATE_EXCEPTIONS;
  450. //
  451. // Damage control
  452. //
  453. if ( FAILED(sc) )
  454. {
  455. if ( 0 != _pScopePane )
  456. {
  457. _pScopePane->Release();
  458. _pScopePane = 0;
  459. }
  460. if ( 0 != _pFrame )
  461. {
  462. _pFrame->Release();
  463. _pFrame = 0;
  464. }
  465. }
  466. return sc;
  467. }
  468. SCODE STDMETHODCALLTYPE CCISnapinData::CreateComponent( IComponent * * ppComponent )
  469. {
  470. TRANSLATE_EXCEPTIONS;
  471. SCODE sc = S_OK;
  472. TRY
  473. {
  474. CCISnapin * p = new CCISnapin( *this, _pChild );
  475. *ppComponent = p;
  476. _pChild = p;
  477. }
  478. CATCH( CException, e )
  479. {
  480. sc = E_FAIL;
  481. }
  482. END_CATCH
  483. UNTRANSLATE_EXCEPTIONS;
  484. return sc;
  485. }
  486. SCODE STDMETHODCALLTYPE CCISnapinData::Notify( IDataObject * pDO,
  487. MMC_NOTIFY_TYPE event,
  488. LPARAM arg,
  489. LPARAM param )
  490. {
  491. ciaDebugOut(( DEB_ITRACE,
  492. "CCISnapinData::Notify (pDO = 0x%x, event = 0x%x)\n",
  493. pDO, event ));
  494. TRANSLATE_EXCEPTIONS;
  495. SCODE sc = S_OK;
  496. TRY
  497. {
  498. switch ( event )
  499. {
  500. case MMCN_EXPAND:
  501. ShowFolder( (CCIAdminDO *)pDO, // Cookie
  502. (BOOL)arg, // TRUE --> Expand, FALSE --> Contract
  503. (HSCOPEITEM)param ); // Scope item selected
  504. break;
  505. case MMCN_DELETE:
  506. RemoveCatalog( (CCIAdminDO *)pDO );
  507. break;
  508. case MMCN_REMOVE_CHILDREN:
  509. if ( _rootNode.IsParent( (HSCOPEITEM)arg ) )
  510. {
  511. Win4Assert( _fIsExtension );
  512. sc = _Catalogs.ReInit();
  513. if ( SUCCEEDED(sc) )
  514. sc = _rootNode.Delete();
  515. _fIsInitialized = FALSE;
  516. }
  517. break;
  518. default:
  519. ciaDebugOut(( DEB_WARN, "unhandled notify 0x%x\n", event ));
  520. break;
  521. }
  522. }
  523. CATCH( CException, e )
  524. {
  525. ciaDebugOut(( DEB_ERROR, "Exception 0x%x in CCISnapinData::Notify\n", e.GetErrorCode() ));
  526. sc = E_UNEXPECTED;
  527. }
  528. END_CATCH
  529. UNTRANSLATE_EXCEPTIONS;
  530. return sc;
  531. }
  532. SCODE STDMETHODCALLTYPE CCISnapinData::Destroy()
  533. {
  534. ciaDebugOut(( DEB_ITRACE, "CCISnapinData::Destroy\n" ));
  535. if ( 0 != _pFrame )
  536. {
  537. _pFrame->Release();
  538. _pFrame = 0;
  539. _pScopePane->Release();
  540. _pScopePane = 0;
  541. for ( CCISnapin * pCurrent = _pChild;
  542. 0 != pCurrent;
  543. pCurrent = pCurrent->Next() )
  544. {
  545. pCurrent->ClearSnapinData();
  546. }
  547. // It's MMC's responsibility to destroy IConsole pointer we give them
  548. // I checked with Gautam in mmc team and confirmed this.
  549. _pChild = 0;
  550. }
  551. return S_OK;
  552. }
  553. SCODE STDMETHODCALLTYPE CCISnapinData::QueryDataObject( MMC_COOKIE cookie,
  554. DATA_OBJECT_TYPES type,
  555. IDataObject * * ppDataObject )
  556. {
  557. //ciaDebugOut(( DEB_ITRACE,
  558. // "CCISnapinData::QueryDataObject (cookie = 0x%x, type = 0x%x)\n",
  559. // cookie, type ));
  560. //
  561. // Minimal parameter validation
  562. //
  563. if ( 0 == ppDataObject )
  564. return E_INVALIDARG;
  565. //
  566. // Create a data object
  567. //
  568. TRANSLATE_EXCEPTIONS;
  569. SCODE sc = S_OK;
  570. TRY
  571. {
  572. *ppDataObject = new CCIAdminDO( cookie, type, _fIsExtension ? 0 : _Catalogs.GetMachine() );
  573. }
  574. CATCH( CException, e )
  575. {
  576. sc = E_UNEXPECTED;
  577. }
  578. END_CATCH
  579. UNTRANSLATE_EXCEPTIONS;
  580. return sc;
  581. }
  582. SCODE STDMETHODCALLTYPE CCISnapinData::GetDisplayInfo( SCOPEDATAITEM * pScopeDataItem )
  583. {
  584. //ciaDebugOut(( DEB_ITRACE, "CCISnapinData::GetDisplayInfo( 0x%x )\n", pScopeDataItem ));
  585. if (pScopeDataItem == NULL)
  586. return E_POINTER;
  587. TRANSLATE_EXCEPTIONS;
  588. SCODE sc = E_UNEXPECTED;
  589. TRY
  590. {
  591. PCIObjectType * pType = (PCIObjectType *)pScopeDataItem->lParam;
  592. if ( 0 == pType )
  593. return sc;
  594. switch ( pType->Type() )
  595. {
  596. case PCIObjectType::RootNode:
  597. {
  598. if ( pScopeDataItem->mask == SDI_STR )
  599. {
  600. pScopeDataItem->displayname = (WCHAR *)GetRootDisplay();
  601. sc = S_OK;
  602. }
  603. break;
  604. }
  605. case PCIObjectType::Catalog:
  606. {
  607. CCatalog * pCat = (CCatalog *)pScopeDataItem->lParam;
  608. if ( pScopeDataItem->mask == SDI_STR )
  609. {
  610. pScopeDataItem->displayname = (WCHAR *)pCat->GetCat( TRUE );
  611. sc = S_OK;
  612. }
  613. break;
  614. }
  615. case PCIObjectType::Intermediate_Scope:
  616. {
  617. if ( pScopeDataItem->mask == SDI_STR )
  618. {
  619. pScopeDataItem->displayname = STRINGRESOURCE( srNodeDirectories );
  620. sc = S_OK;
  621. }
  622. break;
  623. }
  624. case PCIObjectType::Intermediate_Properties:
  625. {
  626. if ( pScopeDataItem->mask == SDI_STR )
  627. {
  628. pScopeDataItem->displayname = STRINGRESOURCE( srNodeProperties );
  629. sc = S_OK;
  630. }
  631. break;
  632. }
  633. case PCIObjectType::Intermediate_UnfilteredURL:
  634. {
  635. if ( pScopeDataItem->mask == SDI_STR )
  636. {
  637. pScopeDataItem->displayname = STRINGRESOURCE( srNodeUnfiltered );
  638. sc = S_OK;
  639. }
  640. break;
  641. }
  642. case PCIObjectType::Property:
  643. case PCIObjectType::Directory:
  644. default:
  645. Win4Assert( !"Oops!" );
  646. break;
  647. }
  648. }
  649. CATCH( CException, e )
  650. {
  651. ciaDebugOut(( DEB_ERROR, "Exception 0x%x in CCISnapinData::GetDisplayInfo\n", e.GetErrorCode() ));
  652. sc = E_UNEXPECTED;
  653. }
  654. END_CATCH
  655. UNTRANSLATE_EXCEPTIONS;
  656. return sc;
  657. }
  658. SCODE STDMETHODCALLTYPE CCISnapinData::CompareObjects( IDataObject * lpDataObjectA,
  659. IDataObject * lpDataObjectB )
  660. {
  661. ciaDebugOut(( DEB_ITRACE, "CCISnapinData::CompareObjects( 0x%x, 0x%x )\n", lpDataObjectA, lpDataObjectB ));
  662. if ( *((CCIAdminDO *)lpDataObjectA) == *((CCIAdminDO *)lpDataObjectB) )
  663. return S_OK;
  664. else
  665. return S_FALSE;
  666. }
  667. SCODE STDMETHODCALLTYPE CCISnapinData::AddMenuItems( IDataObject * piDataObject,
  668. IContextMenuCallback * piCallback,
  669. long * pInsertionAllowed )
  670. {
  671. if ( 0 == piDataObject )
  672. return E_UNEXPECTED;
  673. if ( 0 == (*pInsertionAllowed & CCM_INSERTIONALLOWED_TOP ) )
  674. {
  675. ciaDebugOut(( DEB_WARN, "Menu Insertion not allowed.\n" ));
  676. return S_OK;
  677. }
  678. TRANSLATE_EXCEPTIONS;
  679. SCODE sc = S_OK;
  680. TRY
  681. {
  682. CCIAdminDO * pDO = (CCIAdminDO *)piDataObject;
  683. ciaDebugOut(( DEB_ITRACE, "CCISnapinData::AddMenuItems (cookie = 0x%x, type = 0x%x)\n",
  684. pDO->Cookie(), pDO->Type() ));
  685. if ( pDO->Type() == CCT_RESULT )
  686. {
  687. if ( SUCCEEDED(sc) && pDO->IsACatalog() )
  688. {
  689. sc = piCallback->AddItem( &aContextMenus[comidMergeCatalog] );
  690. }
  691. else if ( SUCCEEDED(sc) && pDO->IsADirectory() )
  692. {
  693. CMachineAdmin MachineAdmin( _Catalogs.IsLocalMachine() ? 0 : _Catalogs.GetMachine() );
  694. if (MachineAdmin.IsCIStarted())
  695. {
  696. // Add both Full and Incremental rescan options to menu.
  697. sc = piCallback->AddItem( &aContextMenus[comidRescanFullScope] );
  698. if ( SUCCEEDED(sc) )
  699. sc = piCallback->AddItem( &aContextMenus[comidRescanIncrementalScope] );
  700. }
  701. }
  702. else
  703. ciaDebugOut(( DEB_WARN, "No menu items for (cookie = 0x%x, type = 0x%x)\n",
  704. pDO->Cookie(), pDO->Type() ));
  705. }
  706. else if ( SUCCEEDED(sc) && pDO->Type() == CCT_SCOPE )
  707. {
  708. if ( (pDO->IsRoot() || pDO->IsStandAloneRoot()) )
  709. {
  710. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_TASK )
  711. {
  712. //
  713. // Adjust state accordingly.
  714. //
  715. CMachineAdmin MachineAdmin( _Catalogs.IsLocalMachine() ? 0 : _Catalogs.GetMachine() );
  716. if ( MachineAdmin.IsCIStarted() )
  717. {
  718. sc = StartMenu( piCallback );
  719. if (SUCCEEDED(sc))
  720. {
  721. aContextMenus[comidTunePerfCITop].fFlags = MF_ENABLED;
  722. sc = piCallback->AddItem( &aContextMenus[comidTunePerfCITop] );
  723. }
  724. }
  725. else if ( MachineAdmin.IsCIPaused() )
  726. {
  727. sc = PauseMenu( piCallback );
  728. if (SUCCEEDED(sc))
  729. {
  730. aContextMenus[comidTunePerfCITop].fFlags = MF_ENABLED;
  731. sc = piCallback->AddItem( &aContextMenus[comidTunePerfCITop] );
  732. }
  733. }
  734. else
  735. {
  736. Win4Assert( MachineAdmin.IsCIStopped() );
  737. sc = StopMenu( piCallback );
  738. if (SUCCEEDED(sc))
  739. {
  740. aContextMenus[comidTunePerfCITop].fFlags = MF_ENABLED;
  741. sc = piCallback->AddItem( &aContextMenus[comidTunePerfCITop] );
  742. }
  743. }
  744. }
  745. if (SUCCEEDED(sc) && (*pInsertionAllowed & CCM_INSERTIONALLOWED_NEW ) )
  746. {
  747. sc = piCallback->AddItem( &aContextMenus[comidAddCatalog] );
  748. }
  749. }
  750. else if ( pDO->IsACatalog() )
  751. {
  752. if (SUCCEEDED(sc) && (*pInsertionAllowed & CCM_INSERTIONALLOWED_NEW ) )
  753. {
  754. sc = piCallback->AddItem( &aContextMenus[comidAddScope] );
  755. }
  756. if (SUCCEEDED(sc) && (*pInsertionAllowed & CCM_INSERTIONALLOWED_TASK ) )
  757. {
  758. CMachineAdmin MachineAdmin( _Catalogs.IsLocalMachine() ? 0 : _Catalogs.GetMachine() );
  759. //
  760. // Only append individual catalog control if service is running.
  761. //
  762. if ( MachineAdmin.IsCIStarted() || MachineAdmin.IsCIPaused() )
  763. {
  764. // Menu item to trigger clean up of the catalog
  765. aContextMenus[comidEmptyCatalog].fFlags = MF_GRAYED;
  766. piCallback->AddItem( &aContextMenus[comidEmptyCatalog] );
  767. aContextMenus[comidMergeCatalog].fFlags = MF_ENABLED;
  768. XPtr<CCatalogAdmin> xCat( MachineAdmin.QueryCatalogAdmin( pDO->GetCatalog()->GetCat(TRUE) ) );
  769. if ( xCat->IsStarted() )
  770. {
  771. aContextMenus[comidMergeCatalog].fFlags = MF_ENABLED;
  772. sc = StartMenu( piCallback, FALSE );
  773. }
  774. else if ( xCat->IsPaused() )
  775. {
  776. aContextMenus[comidMergeCatalog].fFlags = MF_GRAYED;
  777. sc = PauseMenu( piCallback, FALSE );
  778. }
  779. else
  780. {
  781. Win4Assert( xCat->IsStopped() );
  782. aContextMenus[comidMergeCatalog].fFlags = MF_GRAYED;
  783. sc = StopMenu( piCallback, FALSE );
  784. }
  785. }
  786. else
  787. {
  788. // Menu item to trigger clean up of the catalog
  789. aContextMenus[comidEmptyCatalog].fFlags = MF_ENABLED;
  790. piCallback->AddItem( &aContextMenus[comidEmptyCatalog] );
  791. aContextMenus[comidMergeCatalog].fFlags = MF_GRAYED;
  792. sc = DisabledMenu( piCallback, FALSE );
  793. }
  794. if (SUCCEEDED(sc))
  795. {
  796. sc = piCallback->AddItem( &aContextMenus[comidMergeCatalog] );
  797. }
  798. }
  799. }
  800. else if ( pDO->IsADirectoryIntermediate() && (*pInsertionAllowed & CCM_INSERTIONALLOWED_NEW ) )
  801. {
  802. if (SUCCEEDED(sc))
  803. {
  804. sc = piCallback->AddItem( &aContextMenus[comidAddScope] );
  805. }
  806. }
  807. else if ( pDO->IsAPropertyIntermediate() && (*pInsertionAllowed & CCM_INSERTIONALLOWED_TASK ) )
  808. {
  809. if (SUCCEEDED(sc))
  810. {
  811. sc = piCallback->AddItem( &aContextMenus[comidRefreshProperties] );
  812. }
  813. }
  814. else
  815. {
  816. ciaDebugOut(( DEB_WARN, "No menu items for (cookie = 0x%x, type = 0x%x)\n",
  817. pDO->Cookie(), pDO->Type() ));
  818. }
  819. }
  820. else
  821. {
  822. ciaDebugOut(( DEB_WARN, "No menu items for (cookie = 0x%x, type = 0x%x)\n",
  823. pDO->Cookie(), pDO->Type() ));
  824. }
  825. }
  826. CATCH( CException, e )
  827. {
  828. ciaDebugOut(( DEB_ERROR, "Exception 0x%x in CCISnapinData::AddMenuItems\n", e.GetErrorCode() ));
  829. sc = E_UNEXPECTED;
  830. }
  831. END_CATCH
  832. UNTRANSLATE_EXCEPTIONS;
  833. return sc;
  834. }
  835. SCODE STDMETHODCALLTYPE CCISnapinData::Command( long lCommandID,
  836. IDataObject * piDataObject )
  837. {
  838. if ( 0 == piDataObject )
  839. return E_POINTER;
  840. TRANSLATE_EXCEPTIONS;
  841. SCODE sc = S_OK;
  842. TRY
  843. {
  844. CCIAdminDO * pDO = (CCIAdminDO *)piDataObject;
  845. switch ( lCommandID )
  846. {
  847. case comidRescanFullScope:
  848. {
  849. CScope * pScope = pDO->GetScope();
  850. Win4Assert( 0 != pScope );
  851. //
  852. // Make sure the user wants to do a full rescan.
  853. //
  854. WCHAR awcMsg[MAX_PATH];
  855. WCHAR awcTemp[2 * MAX_PATH];
  856. LoadString( ghInstance, MSG_RESCAN_FULL_SCOPE_EXPLAIN, awcMsg, sizeof(awcMsg) / sizeof(WCHAR) );
  857. wsprintf( awcTemp, awcMsg, pScope->GetPath() );
  858. int iResult;
  859. // Pop up YES/NO box
  860. sc = _pFrame->MessageBox( awcTemp,
  861. STRINGRESOURCE( srMsgRescanFull ),
  862. MB_YESNO | /* MB_HELP | */
  863. MB_ICONWARNING | MB_DEFBUTTON2 |
  864. MB_APPLMODAL,
  865. &iResult );
  866. if ( SUCCEEDED(sc) )
  867. {
  868. switch ( iResult )
  869. {
  870. // Rescan( TRUE ) means "Full scan"
  871. case IDYES:
  872. {
  873. pScope->Rescan( TRUE );
  874. break;
  875. }
  876. case IDNO:
  877. {
  878. // Do nothing.
  879. break;
  880. }
  881. /* Help is not being used...
  882. case IDHELP:
  883. {
  884. DisplayHelp( _hFrameWindow, HIDD_RESCAN );
  885. break;
  886. }
  887. */
  888. default:
  889. break;
  890. }
  891. }
  892. break;
  893. }
  894. case comidRescanIncrementalScope:
  895. {
  896. CScope * pScope = pDO->GetScope();
  897. Win4Assert( 0 != pScope );
  898. //
  899. // Make sure the user wants to do an incremental rescan.
  900. //
  901. WCHAR awcMsg[MAX_PATH];
  902. WCHAR awcTemp[2 * MAX_PATH];
  903. LoadString( ghInstance, MSG_RESCAN_INCREMENTAL_SCOPE_EXPLAIN, awcMsg, sizeof(awcMsg) / sizeof(WCHAR) );
  904. wsprintf( awcTemp, awcMsg, pScope->GetPath() );
  905. int iResult;
  906. // Pop up YES/NO box
  907. sc = _pFrame->MessageBox( awcTemp,
  908. STRINGRESOURCE( srMsgRescanIncremental ),
  909. MB_YESNO | /* MB_HELP | */
  910. MB_ICONWARNING | MB_DEFBUTTON2 |
  911. MB_APPLMODAL,
  912. &iResult );
  913. if ( SUCCEEDED(sc) )
  914. {
  915. switch ( iResult )
  916. {
  917. // Rescan( FALSE ) means "Incremental scan"
  918. case IDYES:
  919. {
  920. pScope->Rescan( FALSE );
  921. break;
  922. }
  923. case IDNO:
  924. {
  925. // Do nothing.
  926. break;
  927. }
  928. /* Help is not being used...
  929. case IDHELP:
  930. {
  931. DisplayHelp( _hFrameWindow, HIDD_RESCAN );
  932. break;
  933. }
  934. */
  935. default:
  936. break;
  937. }
  938. }
  939. break;
  940. }
  941. case comidRefreshProperties:
  942. {
  943. // The user has explicitly requested a refresh of the list.
  944. // Delete the old list and recreate it.
  945. CCatalog * pcat = pDO->GetCatalog();
  946. BOOL fClearedYet = FALSE;
  947. for ( CCISnapin * pCurrent = _pChild;
  948. 0 != pCurrent;
  949. pCurrent = pCurrent->Next() )
  950. {
  951. if ( CCISnapin::Properties == pCurrent->GetCurrentView() &&
  952. pCurrent->GetCurrentCatalog() == pcat )
  953. {
  954. if ( !fClearedYet )
  955. {
  956. pcat->ClearProperties( pCurrent->ResultPane() );
  957. fClearedYet = TRUE;
  958. }
  959. pCurrent->ResultPane()->DeleteAllRsltItems();
  960. pcat->DisplayProperties( TRUE, pCurrent->ResultPane() );
  961. }
  962. }
  963. break;
  964. }
  965. case comidEmptyCatalog:
  966. {
  967. // NOTE: The service must be stopped before we can do this. Deleting
  968. // files under an active catalog leads to unpredictable results.
  969. int iResult;
  970. sc = _pFrame->MessageBox( STRINGRESOURCE( srMsgEmptyCatalogPrompt ),
  971. STRINGRESOURCE( srMsgEmptyCatalogAsk ),
  972. MB_YESNO | /* MB_HELP | */
  973. MB_ICONWARNING | MB_DEFBUTTON2 |
  974. MB_APPLMODAL,
  975. &iResult );
  976. if ( SUCCEEDED(sc) )
  977. {
  978. switch ( iResult )
  979. {
  980. case IDYES:
  981. {
  982. CMachineAdmin MachineAdmin( _Catalogs.IsLocalMachine() ? 0 : _Catalogs.GetMachine() );
  983. XPtr<CCatalogAdmin> xCat( MachineAdmin.QueryCatalogAdmin( pDO->GetCatalog()->GetCat(TRUE) ) );
  984. //xCat->EmptyThisCatalog();
  985. MachineAdmin.RemoveCatalogFiles(pDO->GetCatalog()->GetCat(TRUE));
  986. break;
  987. }
  988. case IDNO:
  989. // Do nothing.
  990. break;
  991. default:
  992. break;
  993. }
  994. }
  995. break;
  996. }
  997. case comidAddScope:
  998. {
  999. CCatalog * pCat = pDO->GetCatalog();
  1000. Win4Assert( 0 != pCat );
  1001. INT_PTR err = DialogBoxParam( ghInstance, // Application instance
  1002. MAKEINTRESOURCE( IDD_ADD_SCOPE ), // Dialog box
  1003. _hFrameWindow, // main window
  1004. AddScopeDlg, // Dialog box function
  1005. (LPARAM)pCat ); // User parameter
  1006. if ( -1 == err )
  1007. THROW( CException() );
  1008. Refresh(); // Update all result pane(s)
  1009. break;
  1010. }
  1011. case comidMergeCatalog:
  1012. {
  1013. CCatalog * pCat = pDO->GetCatalog();
  1014. Win4Assert( 0 != pCat );
  1015. //
  1016. // Make sure the user wants to remove scope.
  1017. //
  1018. int iResult;
  1019. sc = _pFrame->MessageBox( STRINGRESOURCE( srMsgMerge ),
  1020. STRINGRESOURCE( srMsgMerge ),
  1021. MB_YESNO | /* MB_HELP | */
  1022. MB_ICONWARNING | MB_DEFBUTTON2 |
  1023. MB_APPLMODAL,
  1024. &iResult );
  1025. if ( SUCCEEDED(sc) )
  1026. {
  1027. switch ( iResult )
  1028. {
  1029. case IDYES:
  1030. {
  1031. pCat->Merge();
  1032. break;
  1033. }
  1034. case IDNO:
  1035. case IDCANCEL:
  1036. // Do nothing.
  1037. break;
  1038. /* Help is not being used...
  1039. case IDHELP:
  1040. {
  1041. DisplayHelp( _hFrameWindow, HIDD_MERGE_CATALOG );
  1042. break;
  1043. }
  1044. */
  1045. default:
  1046. break;
  1047. }
  1048. }
  1049. break;
  1050. }
  1051. case comidAddCatalog:
  1052. {
  1053. Win4Assert( pDO->IsRoot() || pDO->IsStandAloneRoot() );
  1054. INT_PTR err = DialogBoxParam( ghInstance, // Application instance
  1055. MAKEINTRESOURCE( IDD_ADD_CATALOG ), // Dialog box
  1056. _hFrameWindow, // main frame window
  1057. AddCatalogDlg, // Dialog box function
  1058. (LPARAM)&_Catalogs ); // User parameter
  1059. if ( -1 == err )
  1060. THROW( CException() );
  1061. // Ensure that only and all active catalogs are listed.
  1062. _Catalogs.UpdateActiveState();
  1063. Refresh(); // Update all result pane(s)
  1064. break;
  1065. }
  1066. case comidStartCI:
  1067. case comidStartCITop:
  1068. {
  1069. CMachineAdmin MachineAdmin( _Catalogs.IsLocalMachine() ? 0 : _Catalogs.GetMachine() );
  1070. if ( pDO->IsRoot() || pDO->IsStandAloneRoot() )
  1071. {
  1072. MaybeEnableCI( MachineAdmin );
  1073. MachineAdmin.StartCI();
  1074. // Ensure that only and all active catalogs are listed.
  1075. _Catalogs.UpdateActiveState();
  1076. _Catalogs.SetSnapinData( this );
  1077. }
  1078. else
  1079. {
  1080. Win4Assert( pDO->IsACatalog() );
  1081. XPtr<CCatalogAdmin> xCat( MachineAdmin.QueryCatalogAdmin( pDO->GetCatalog()->GetCat(TRUE) ) );
  1082. xCat->Start();
  1083. // We are using the top-level buttons to control individual catalogs. Accordingly, they
  1084. // should be updated to reflect the selected catalog's state.
  1085. // The toolbar may not be created yet, so check if it is non-zero
  1086. if ( xCat->IsStarted() && _pChild->_xToolbar.GetPointer() )
  1087. {
  1088. // This is more efficient than calling CCISnapinData::SetButtonState
  1089. for ( CCISnapin * pCurrent = _pChild;
  1090. 0 != pCurrent;
  1091. pCurrent = pCurrent->Next() )
  1092. {
  1093. pCurrent->_xToolbar->SetButtonState(comidStartCITop, ENABLED, FALSE);
  1094. pCurrent->_xToolbar->SetButtonState(comidStopCITop, ENABLED, TRUE);
  1095. pCurrent->_xToolbar->SetButtonState(comidPauseCITop, ENABLED, TRUE);
  1096. }
  1097. }
  1098. }
  1099. break;
  1100. }
  1101. case comidStopCI:
  1102. case comidStopCITop:
  1103. {
  1104. CMachineAdmin MachineAdmin( _Catalogs.IsLocalMachine() ? 0 : _Catalogs.GetMachine() );
  1105. if ( pDO->IsRoot() || pDO->IsStandAloneRoot() )
  1106. {
  1107. MachineAdmin.StopCI();
  1108. // The toolbar may not be created yet, so check if it is non-zero
  1109. if ( MachineAdmin.IsCIStopped() && _pChild->_xToolbar.GetPointer() )
  1110. {
  1111. for ( CCISnapin * pCurrent = _pChild;
  1112. 0 != pCurrent;
  1113. pCurrent = pCurrent->Next() )
  1114. {
  1115. pCurrent->_xToolbar->SetButtonState(comidStartCITop, ENABLED, TRUE);
  1116. pCurrent->_xToolbar->SetButtonState(comidStopCITop, ENABLED, FALSE);
  1117. pCurrent->_xToolbar->SetButtonState(comidPauseCITop, ENABLED, FALSE);
  1118. }
  1119. }
  1120. // Ensure that only and all active catalogs are listed.
  1121. _Catalogs.UpdateActiveState();
  1122. }
  1123. else
  1124. {
  1125. Win4Assert( pDO->IsACatalog() );
  1126. XPtr<CCatalogAdmin> xCat( MachineAdmin.QueryCatalogAdmin( pDO->GetCatalog()->GetCat(TRUE) ) );
  1127. xCat->Stop();
  1128. // The toolbar may not be created yet, so check if it is non-zero
  1129. if ( xCat->IsStopped() && _pChild->_xToolbar.GetPointer() )
  1130. {
  1131. for ( CCISnapin * pCurrent = _pChild;
  1132. 0 != pCurrent;
  1133. pCurrent = pCurrent->Next() )
  1134. {
  1135. pCurrent->_xToolbar->SetButtonState(comidStartCITop, ENABLED, TRUE);
  1136. pCurrent->_xToolbar->SetButtonState(comidStopCITop, ENABLED, FALSE);
  1137. pCurrent->_xToolbar->SetButtonState(comidPauseCITop, ENABLED, FALSE);
  1138. }
  1139. }
  1140. }
  1141. break;
  1142. }
  1143. case comidPauseCI:
  1144. case comidPauseCITop:
  1145. {
  1146. CMachineAdmin MachineAdmin( _Catalogs.IsLocalMachine() ? 0 : _Catalogs.GetMachine() );
  1147. if ( pDO->IsRoot() || pDO->IsStandAloneRoot() )
  1148. {
  1149. MachineAdmin.PauseCI();
  1150. // The toolbar may not be created yet, so check if it is non-zero
  1151. if ( MachineAdmin.IsCIPaused() && _pChild->_xToolbar.GetPointer() )
  1152. {
  1153. for ( CCISnapin * pCurrent = _pChild;
  1154. 0 != pCurrent;
  1155. pCurrent = pCurrent->Next() )
  1156. {
  1157. pCurrent->_xToolbar->SetButtonState(comidStartCITop, ENABLED, TRUE);
  1158. pCurrent->_xToolbar->SetButtonState(comidStopCITop, ENABLED, TRUE);
  1159. pCurrent->_xToolbar->SetButtonState(comidPauseCITop, ENABLED, FALSE);
  1160. }
  1161. }
  1162. // Ensure that only and all active catalogs are listed.
  1163. _Catalogs.UpdateActiveState();
  1164. }
  1165. else
  1166. {
  1167. Win4Assert( pDO->IsACatalog() );
  1168. XPtr<CCatalogAdmin> xCat( MachineAdmin.QueryCatalogAdmin( pDO->GetCatalog()->GetCat(TRUE) ) );
  1169. xCat->Pause();
  1170. // The toolbar may bot be created yet, so check if it is non-zero
  1171. if ( xCat->IsPaused() && _pChild->_xToolbar.GetPointer() )
  1172. {
  1173. for ( CCISnapin * pCurrent = _pChild;
  1174. 0 != pCurrent;
  1175. pCurrent = pCurrent->Next() )
  1176. {
  1177. pCurrent->_xToolbar->SetButtonState(comidStartCITop, ENABLED, TRUE);
  1178. pCurrent->_xToolbar->SetButtonState(comidStopCITop, ENABLED, TRUE);
  1179. pCurrent->_xToolbar->SetButtonState(comidPauseCITop, ENABLED, FALSE);
  1180. }
  1181. }
  1182. }
  1183. break;
  1184. }
  1185. case comidTunePerfCITop:
  1186. {
  1187. Win4Assert( pDO->IsRoot() || pDO->IsStandAloneRoot() );
  1188. if ( IsNTServer() )
  1189. {
  1190. DialogBoxParam( ghInstance, // Application instance
  1191. MAKEINTRESOURCE( IDD_USAGE_ON_SERVER ), // Dialog box
  1192. _hFrameWindow, // main frame window
  1193. SrvTunePerfDlg, // Dialog box function
  1194. (LPARAM)&_Catalogs ); // User parameter
  1195. }
  1196. else
  1197. {
  1198. DialogBoxParam( ghInstance, // Application instance
  1199. MAKEINTRESOURCE( IDD_USAGE_ON_WORKSTATION ), // Dialog box
  1200. _hFrameWindow, // main frame window
  1201. WksTunePerfDlg, // Dialog box function
  1202. (LPARAM)&_Catalogs ); // User parameter
  1203. }
  1204. // Ensure that only and all active catalogs are listed.
  1205. _Catalogs.UpdateActiveState();
  1206. Refresh(); // Update all result pane(s)
  1207. break;
  1208. }
  1209. default:
  1210. sc = E_UNEXPECTED;
  1211. break;
  1212. }
  1213. }
  1214. CATCH( CException, e )
  1215. {
  1216. ciaDebugOut(( DEB_ERROR, "Exception 0x%x in CCISnapinData::Command\n", e.GetErrorCode() ));
  1217. sc = E_UNEXPECTED;
  1218. }
  1219. END_CATCH
  1220. UNTRANSLATE_EXCEPTIONS;
  1221. return sc;
  1222. }
  1223. //+---------------------------------------------------------------------------
  1224. //
  1225. // Member: CCISnapinData::GetClassID, public
  1226. //
  1227. // Synopsis: Identifies class of storage
  1228. //
  1229. // Arguments: [pClassID] -- Class written here.
  1230. //
  1231. // Returns: S_OK
  1232. //
  1233. // History: 14-Jul-97 KyleP Created
  1234. //
  1235. //----------------------------------------------------------------------------
  1236. SCODE CCISnapinData::GetClassID( CLSID * pClassID )
  1237. {
  1238. *pClassID = guidCISnapin;
  1239. return S_OK;
  1240. }
  1241. //+---------------------------------------------------------------------------
  1242. //
  1243. // Member: CCISnapinData::IsDirty, public
  1244. //
  1245. // Returns: TRUE if snapin data has not been saved.
  1246. //
  1247. // History: 14-Jul-97 KyleP Created
  1248. //
  1249. //----------------------------------------------------------------------------
  1250. SCODE CCISnapinData::IsDirty()
  1251. {
  1252. return (_fDirty) ? S_OK : S_FALSE;
  1253. }
  1254. //+---------------------------------------------------------------------------
  1255. //
  1256. // Member: CCISnapinData::Load, public
  1257. //
  1258. // Synopsis: Load persistent state
  1259. //
  1260. // Arguments: [pStm] -- State stored in stream.
  1261. //
  1262. // Returns: S_OK on successful load
  1263. //
  1264. // History: 14-Jul-97 KyleP Created
  1265. //
  1266. //----------------------------------------------------------------------------
  1267. SCODE CCISnapinData::Load( IStream * pStm )
  1268. {
  1269. //
  1270. // Read in machine name.
  1271. //
  1272. ULONG cbRead = 0;
  1273. ULONG cc = 0;
  1274. SCODE sc = pStm->Read( &cc, sizeof(cc), &cbRead );
  1275. if ( S_OK != sc || cbRead != sizeof(cc) )
  1276. {
  1277. ciaDebugOut(( DEB_ERROR, "Could not load catalog name: 0x%x\n", sc ));
  1278. return E_FAIL;
  1279. }
  1280. XGrowable<WCHAR> xwcsMachine( cc );
  1281. sc = pStm->Read( xwcsMachine.Get(), cc * sizeof(WCHAR), &cbRead );
  1282. if ( S_OK != sc || cbRead != cc * sizeof(WCHAR) )
  1283. {
  1284. ciaDebugOut(( DEB_ERROR, "Could not load catalog name: 0x%x\n", sc ));
  1285. return E_FAIL;
  1286. }
  1287. _Catalogs.SetMachine( xwcsMachine.Get() );
  1288. _fDirty = FALSE;
  1289. return S_OK;
  1290. }
  1291. //+---------------------------------------------------------------------------
  1292. //
  1293. // Member: CCISnapinData::Save, public
  1294. //
  1295. // Synopsis: Save persistent state
  1296. //
  1297. // Arguments: [pStm] -- Stream into which state can be stored.
  1298. // [fClearDirty] -- TRUE if dirty bit should be cleared
  1299. //
  1300. // Returns: S_OK if save succeeded.
  1301. //
  1302. // History: 14-Jul-97 KyleP Created
  1303. //
  1304. //----------------------------------------------------------------------------
  1305. SCODE CCISnapinData::Save( IStream * pStm, BOOL fClearDirty )
  1306. {
  1307. ULONG cbWritten;
  1308. ULONG cc = wcslen( _Catalogs.GetMachine() ) + 1;
  1309. SCODE sc = pStm->Write( &cc, sizeof(cc), &cbWritten );
  1310. if ( S_OK != sc || cbWritten != sizeof(cc) )
  1311. {
  1312. ciaDebugOut(( DEB_ERROR, "Could not save catalog name: 0x%x\n", sc ));
  1313. return E_FAIL;
  1314. }
  1315. sc = pStm->Write( _Catalogs.GetMachine(), cc * sizeof(WCHAR), &cbWritten );
  1316. if ( S_OK != sc || cbWritten != cc * sizeof(WCHAR) )
  1317. {
  1318. ciaDebugOut(( DEB_ERROR, "Could not save catalog name: 0x%x\n", sc ));
  1319. return E_FAIL;
  1320. }
  1321. if ( fClearDirty )
  1322. _fDirty = FALSE;
  1323. return S_OK;
  1324. }
  1325. //+---------------------------------------------------------------------------
  1326. //
  1327. // Member: CCISnapinData::GetSizeMax, public
  1328. //
  1329. // Synopsis: Computes size of persistent state
  1330. //
  1331. // Arguments: [pcbSize] -- Size returned here.
  1332. //
  1333. // Returns: S_OK
  1334. //
  1335. // History: 14-Jul-97 KyleP Created
  1336. //
  1337. //----------------------------------------------------------------------------
  1338. SCODE CCISnapinData::GetSizeMax( ULARGE_INTEGER * pcbSize )
  1339. {
  1340. pcbSize->HighPart = 0;
  1341. pcbSize->LowPart = sizeof(ULONG) +
  1342. sizeof(WCHAR) * (wcslen(_Catalogs.GetMachine()) + 1);
  1343. return S_OK;
  1344. }
  1345. //+-------------------------------------------------------------------------
  1346. //
  1347. // Method: CCISnapinData::CCISnapinData
  1348. //
  1349. // Synopsis: Constructor
  1350. //
  1351. // History: 26-Nov-1996 KyleP Created
  1352. //
  1353. //--------------------------------------------------------------------------
  1354. CCISnapinData::CCISnapinData( )
  1355. : _pFrame( 0 ),
  1356. _pScopePane( 0 ),
  1357. _pChild( 0 ),
  1358. _uRefs( 1 ),
  1359. _fDirty( TRUE ),
  1360. _fIsInitialized( FALSE ),
  1361. _fIsExtension( FALSE ),
  1362. _fTriedEnable( FALSE ),
  1363. _notifHandle( 0 ),
  1364. _fURLDeselected( FALSE )
  1365. {
  1366. InterlockedIncrement( &gulcInstances );
  1367. }
  1368. //+-------------------------------------------------------------------------
  1369. //
  1370. // Method: CCISnapinData::~CCISnapinData
  1371. //
  1372. // Synopsis: Destructor
  1373. //
  1374. // History: 26-Nov-1996 KyleP Created
  1375. //
  1376. //--------------------------------------------------------------------------
  1377. CCISnapinData::~CCISnapinData()
  1378. {
  1379. ciaDebugOut(( DEB_ITRACE, "CCISnapinData::~CCISnapinData\n" ));
  1380. Win4Assert( 0 == _pFrame );
  1381. Win4Assert( 0 == _pScopePane );
  1382. // Tell catalogs that snapindata is no longer valid!
  1383. _Catalogs.SetSnapinData(0);
  1384. for ( CCISnapin * pCurrent = _pChild;
  1385. 0 != pCurrent;
  1386. pCurrent = pCurrent->Next() )
  1387. {
  1388. pCurrent->ClearSnapinData();
  1389. }
  1390. InterlockedDecrement( &gulcInstances );
  1391. }
  1392. void CCISnapinData::Refresh()
  1393. {
  1394. _Catalogs.DisplayScope( 0xFFFFFFFF );
  1395. for ( CCISnapin * pCurrent = _pChild;
  1396. 0 != pCurrent;
  1397. pCurrent = pCurrent->Next() )
  1398. {
  1399. pCurrent->Refresh();
  1400. }
  1401. }
  1402. //+-------------------------------------------------------------------------
  1403. //
  1404. // Method: CCISnapin::QueryInterface
  1405. //
  1406. // Synopsis: Switch from one interface to another
  1407. //
  1408. // History: 26-Nov-1996 KyleP Created
  1409. //
  1410. //--------------------------------------------------------------------------
  1411. SCODE STDMETHODCALLTYPE CCISnapin::QueryInterface( REFIID riid,
  1412. void ** ppvObject )
  1413. {
  1414. ciaDebugOut(( DEB_ITRACE, "CCISnapin::QueryInterface\n" ));
  1415. SCODE sc = S_OK;
  1416. if ( 0 == ppvObject )
  1417. return E_INVALIDARG;
  1418. if ( IID_IComponent == riid )
  1419. *ppvObject = (IUnknown *)(IComponent *)this;
  1420. else if ( IID_IExtendPropertySheet == riid )
  1421. *ppvObject = (IUnknown *)(IExtendPropertySheet *)this;
  1422. else if ( IID_IExtendContextMenu == riid )
  1423. *ppvObject = (IUnknown *)(IExtendContextMenu *)this;
  1424. else if ( IID_IExtendControlbar == riid )
  1425. *ppvObject = (IUnknown *)(IExtendControlbar *)this;
  1426. else if ( IID_IUnknown == riid )
  1427. *ppvObject = (IUnknown *)(IComponent *)this;
  1428. else
  1429. sc = E_NOINTERFACE;
  1430. if ( SUCCEEDED( sc ) )
  1431. AddRef();
  1432. return sc;
  1433. } //QueryInterface
  1434. //+-------------------------------------------------------------------------
  1435. //
  1436. // Method: CCISnapin::AddRef
  1437. //
  1438. // Synopsis: Increment ref count
  1439. //
  1440. // History: 26-Nov-1996 KyleP Created
  1441. //
  1442. //--------------------------------------------------------------------------
  1443. ULONG STDMETHODCALLTYPE CCISnapin::AddRef()
  1444. {
  1445. ciaDebugOut(( DEB_ITRACE, "CCISnapin::AddRef\n" ));
  1446. return InterlockedIncrement( &_uRefs );
  1447. }
  1448. //+-------------------------------------------------------------------------
  1449. //
  1450. // Method: CCISnapin::Release
  1451. //
  1452. // Synopsis: Deccrement ref count
  1453. //
  1454. // History: 26-Nov-1996 KyleP Created
  1455. //
  1456. //--------------------------------------------------------------------------
  1457. ULONG STDMETHODCALLTYPE CCISnapin::Release()
  1458. {
  1459. ciaDebugOut(( DEB_ITRACE, "CCISnapin::Release\n" ));
  1460. unsigned long uTmp = InterlockedDecrement( &_uRefs );
  1461. if ( 0 == uTmp )
  1462. delete this;
  1463. return(uTmp);
  1464. }
  1465. SCODE STDMETHODCALLTYPE CCISnapin::Initialize( IConsole * lpFrame )
  1466. {
  1467. ciaDebugOut(( DEB_ITRACE, "CCISnapin::Initialize\n" ));
  1468. //
  1469. // Parameter checking.
  1470. //
  1471. if ( 0 == lpFrame )
  1472. return E_INVALIDARG;
  1473. _pFrame = lpFrame;
  1474. _pFrame->AddRef();
  1475. SCODE sc;
  1476. do
  1477. {
  1478. //
  1479. // Collect interfaces
  1480. //
  1481. sc = _pFrame->QueryInterface( IID_IHeaderCtrl, (void **)&_pHeader );
  1482. if ( FAILED(sc) )
  1483. break;
  1484. sc = _pFrame->QueryInterface( IID_IResultData, (void **)&_pResultPane );
  1485. if ( FAILED(sc) )
  1486. break;
  1487. sc = _pFrame->QueryConsoleVerb( &_pConsoleVerb );
  1488. if ( FAILED(sc) )
  1489. break;
  1490. sc = _pFrame->QueryInterface( IID_IDisplayHelp, (void **)&_pDisplayHelp );
  1491. if ( FAILED(sc) )
  1492. break;
  1493. //
  1494. // Initialize resources
  1495. //
  1496. sc = _pFrame->QueryResultImageList( &_pImageList );
  1497. if ( FAILED(sc) )
  1498. break;
  1499. sc = _pFrame->GetMainWindow(&_hFrameWindow);
  1500. if ( FAILED(sc) )
  1501. break;
  1502. //
  1503. // Initialize catalogs
  1504. //
  1505. // _SnapinData.GetCatalogs().InitHeader( _pHeader );
  1506. }
  1507. while ( FALSE );
  1508. //
  1509. // Damage control
  1510. //
  1511. if ( FAILED(sc) )
  1512. {
  1513. if ( 0 != _pImageList )
  1514. {
  1515. _pImageList->Release();
  1516. _pImageList = 0;
  1517. }
  1518. if ( 0 != _pResultPane )
  1519. {
  1520. _pResultPane->Release();
  1521. _pResultPane = 0;
  1522. }
  1523. if ( 0 != _pConsoleVerb )
  1524. {
  1525. _pConsoleVerb->Release();
  1526. _pConsoleVerb = 0;
  1527. }
  1528. if ( 0 != _pHeader )
  1529. {
  1530. _pHeader->Release();
  1531. _pHeader = 0;
  1532. }
  1533. if ( 0 != _pFrame )
  1534. {
  1535. _pFrame->Release();
  1536. _pFrame = 0;
  1537. }
  1538. }
  1539. return sc;
  1540. }
  1541. SCODE STDMETHODCALLTYPE CCISnapin::Notify( IDataObject * pDataObject,
  1542. MMC_NOTIFY_TYPE event,
  1543. LPARAM arg,
  1544. LPARAM param )
  1545. {
  1546. ciaDebugOut(( DEB_ITRACE, "CCISnapin::Notify (pDO = 0x%x, event = 0x%x)\n",
  1547. pDataObject, event ));
  1548. CCIAdminDO * pDO = (CCIAdminDO *)pDataObject;
  1549. TRANSLATE_EXCEPTIONS;
  1550. SCODE sc = S_OK;
  1551. TRY
  1552. {
  1553. switch ( event )
  1554. {
  1555. case MMCN_SHOW:
  1556. ShowItem( pDO, // Cookie
  1557. (BOOL)arg, // TRUE --> Select, FALSE --> Deselect
  1558. (HSCOPEITEM)param ); // Scope item selected
  1559. break;
  1560. case MMCN_SELECT:
  1561. if ( (CCIAdminDO *) -2 != pDO )
  1562. EnableStandardVerbs( pDO );
  1563. break;
  1564. /*
  1565. case MMCN_COLUMN_CLICK:
  1566. // No need to sort on these columns in this view
  1567. sc = _pResultPane->Sort(arg, RSI_DESCENDING, 0);
  1568. break;
  1569. */
  1570. case MMCN_DBLCLICK:
  1571. if (pDO->Type() == CCT_SCOPE)
  1572. {
  1573. // This is an undocumented feature. Return S_FALSE and that will
  1574. // cause the appropriate node in the scope pane to automagically expand
  1575. // and select the right node. Figured this out after spending a couple of
  1576. // hours trying to find a documented way of doing this...
  1577. // Other components use this undocumented feature.
  1578. sc = S_FALSE;
  1579. }
  1580. else if (pDO->IsADirectory())
  1581. {
  1582. CScope * pScope = pDO->GetScope();
  1583. Win4Assert( 0 != pScope );
  1584. DialogBoxParam( ghInstance, // Application instance
  1585. MAKEINTRESOURCE( IDD_ADD_SCOPE ), // Dialog box
  1586. _hFrameWindow, // main window
  1587. ModifyScopeDlg, // Dialog box function
  1588. (LPARAM)pScope ); // User parameter
  1589. Refresh(); // Update all result pane(s)
  1590. }
  1591. else if (pDO->IsAProperty())
  1592. {
  1593. XPtr<CPropertyPropertySheet1> xPropSheet(
  1594. new CPropertyPropertySheet1( ghInstance,
  1595. _pSnapinData->NotifyHandle(),
  1596. pDO->GetProperty(),
  1597. pDO->GetCatalog()
  1598. ));
  1599. LPCPROPSHEETPAGE psp = xPropSheet->GetPropSheet();
  1600. PROPSHEETHEADER psh;
  1601. psh.dwSize = sizeof (PROPSHEETHEADER);
  1602. psh.dwFlags = PSH_PROPSHEETPAGE;
  1603. psh.hwndParent = _hFrameWindow;
  1604. psh.hInstance = ghInstance;
  1605. psh.pszIcon = NULL;
  1606. psh.pszCaption = pDO->GetProperty()->GetPropSet();
  1607. psh.nPages = 1;
  1608. psh.ppsp = psp;
  1609. PropertySheet(&psh);
  1610. xPropSheet.Acquire();
  1611. }
  1612. break;
  1613. case MMCN_PROPERTY_CHANGE:
  1614. {
  1615. PCIObjectType * pType = (PCIObjectType *)param;
  1616. if ( pType->Type() == PCIObjectType::Property )
  1617. {
  1618. ciaDebugOut(( DEB_ITRACE, "PROPERTY CHANGE\n" ));
  1619. HRESULTITEM hItem;
  1620. sc = _pResultPane->FindItemByLParam( param, &hItem );
  1621. if ( SUCCEEDED(sc) )
  1622. {
  1623. RESULTDATAITEM rdi;
  1624. ZeroMemory(&rdi, sizeof(rdi));
  1625. rdi.mask = RDI_IMAGE;
  1626. rdi.itemID = hItem;
  1627. rdi.nImage = ICON_MODIFIED_PROPERTY;
  1628. sc = _pResultPane->SetItem( &rdi );
  1629. }
  1630. }
  1631. break;
  1632. } // case
  1633. case MMCN_DELETE:
  1634. if ( pDO->IsACatalog() )
  1635. _pSnapinData->RemoveCatalog( pDO );
  1636. else
  1637. {
  1638. Win4Assert( pDO->IsADirectory() );
  1639. RemoveScope( pDO );
  1640. }
  1641. break;
  1642. case MMCN_HELP:
  1643. {
  1644. LPOLESTR lpHelpFile;
  1645. if ( S_OK == _pSnapinData->GetHelpTopic2(&lpHelpFile) )
  1646. _pDisplayHelp->ShowTopic(lpHelpFile);
  1647. }
  1648. break;
  1649. case MMCN_CONTEXTHELP:
  1650. {
  1651. LPOLESTR lpHelpFile;
  1652. if ( S_OK == _pSnapinData->GetHelpTopic2(&lpHelpFile) )
  1653. _pDisplayHelp->ShowTopic(lpHelpFile);
  1654. }
  1655. break;
  1656. case MMCN_SNAPINHELP:
  1657. {
  1658. LPOLESTR lpHelpFile;
  1659. if ( S_OK == _pSnapinData->GetHelpTopic2(&lpHelpFile) )
  1660. _pDisplayHelp->ShowTopic(lpHelpFile);
  1661. }
  1662. break;
  1663. } // switch
  1664. }
  1665. CATCH( CException, e )
  1666. {
  1667. ciaDebugOut(( DEB_ERROR, "Exception 0x%x in CCISnapin::Notify\n", e.GetErrorCode() ));
  1668. sc = E_UNEXPECTED;
  1669. }
  1670. END_CATCH
  1671. UNTRANSLATE_EXCEPTIONS;
  1672. return sc;
  1673. }
  1674. SCODE STDMETHODCALLTYPE CCISnapin::Destroy( MMC_COOKIE cookie )
  1675. {
  1676. ciaDebugOut(( DEB_ITRACE, "CCISnapin::Destroy\n" ));
  1677. if ( 0 != _pFrame )
  1678. {
  1679. _pFrame->Release();
  1680. _pFrame = 0;
  1681. _pHeader->Release();
  1682. _pHeader = 0;
  1683. _pResultPane->Release();
  1684. _pResultPane = 0;
  1685. _pImageList->Release();
  1686. _pImageList = 0;
  1687. _pConsoleVerb->Release();
  1688. _pConsoleVerb = 0;
  1689. _pDisplayHelp->Release();
  1690. _pDisplayHelp = 0;
  1691. }
  1692. return S_OK;
  1693. }
  1694. SCODE STDMETHODCALLTYPE CCISnapin::QueryDataObject( MMC_COOKIE cookie,
  1695. DATA_OBJECT_TYPES type,
  1696. IDataObject * * ppDataObject )
  1697. {
  1698. return _pSnapinData->QueryDataObject( cookie, type, ppDataObject );
  1699. }
  1700. SCODE STDMETHODCALLTYPE CCISnapin::GetResultViewType( MMC_COOKIE cookie,
  1701. BSTR * ppViewType,
  1702. long * pViewOptions )
  1703. {
  1704. ciaDebugOut(( DEB_ITRACE, "CCISnapin::GetResultViewType (cookie = 0x%x)\n", cookie ));
  1705. CIntermediate *pIntermediate = (CIntermediate *) cookie;
  1706. if ( 0 != pIntermediate &&
  1707. PCIObjectType::Intermediate_UnfilteredURL == pIntermediate->Type() )
  1708. {
  1709. Win4Assert(pIntermediate);
  1710. // To display a URL
  1711. WCHAR wszSysPath[MAX_PATH + 1];
  1712. WCHAR wszPath[MAX_PATH + 1];
  1713. GetSystemWindowsDirectory(wszSysPath, MAX_PATH);
  1714. wcscpy(wszPath, L"file://");
  1715. wcscat(wszPath, wszSysPath);
  1716. wcscat(wszPath, L"\\Help\\ciadmin.htm#machine=");
  1717. wcscat(wszPath, _pSnapinData->GetCatalogs().GetMachine());
  1718. wcscat(wszPath, L",catalog=");
  1719. wcscat(wszPath, pIntermediate->GetCatalog().GetCat(TRUE));
  1720. MakeOLESTR(ppViewType, wszPath);
  1721. *pViewOptions = MMC_VIEW_OPTIONS_NOLISTVIEWS ;
  1722. return S_OK;
  1723. }
  1724. else
  1725. {
  1726. //
  1727. // S_FALSE --> Use listview
  1728. //
  1729. return S_FALSE;
  1730. }
  1731. }
  1732. SCODE STDMETHODCALLTYPE CCISnapin::GetDisplayInfo( RESULTDATAITEM * pResult )
  1733. {
  1734. //ciaDebugOut(( DEB_ITRACE, "CCISnapin::GetDisplayInfo (itemID = 0x%x, bScopeItem = %s, lParam = 0x%x)\n",
  1735. // pResult->itemID, pResult->bScopeItem ? "TRUE" : "FALSE", pResult->lParam ));
  1736. if ( 0 == pResult )
  1737. return E_POINTER;
  1738. TRANSLATE_EXCEPTIONS;
  1739. SCODE sc = S_OK;
  1740. TRY
  1741. {
  1742. if ( pResult->mask & RDI_STR )
  1743. {
  1744. PCIObjectType * pType = (PCIObjectType *)pResult->lParam;
  1745. switch ( pType->Type() )
  1746. {
  1747. case PCIObjectType::RootNode:
  1748. {
  1749. switch ( pResult->nCol )
  1750. {
  1751. case 0:
  1752. pResult->str = (WCHAR *)_pSnapinData->GetRootDisplay();
  1753. break;
  1754. case 1:
  1755. pResult->str = (WCHAR *)_pSnapinData->GetType();
  1756. break;
  1757. case 2:
  1758. pResult->str = (WCHAR *)_pSnapinData->GetDescription();
  1759. break;
  1760. default:
  1761. Win4Assert(!"How did we get here?");
  1762. pResult->str = L"";
  1763. break;
  1764. }
  1765. if ( pResult->mask & RDI_IMAGE && 0 == pResult->nCol )
  1766. pResult->nImage = ICON_APP;
  1767. break;
  1768. }
  1769. case PCIObjectType::Catalog:
  1770. {
  1771. CCatalog * pCat = (CCatalog *)pResult->lParam;
  1772. pCat->GetDisplayInfo( pResult );
  1773. break;
  1774. }
  1775. case PCIObjectType::Directory:
  1776. {
  1777. CScope * pScope = (CScope *)pResult->lParam;
  1778. pScope->GetDisplayInfo( pResult );
  1779. break;
  1780. }
  1781. case PCIObjectType::Property:
  1782. {
  1783. CCachedProperty * pProperty = (CCachedProperty *)pResult->lParam;
  1784. pProperty->GetDisplayInfo( pResult );
  1785. break;
  1786. }
  1787. case PCIObjectType::Intermediate_Scope:
  1788. {
  1789. if ( 0 == pResult->nCol )
  1790. pResult->str = STRINGRESOURCE( srNodeDirectories );
  1791. else
  1792. pResult->str = L"";
  1793. if ( pResult->mask & RDI_IMAGE && 0 == pResult->nCol )
  1794. pResult->nImage = ICON_FOLDER;
  1795. break;
  1796. }
  1797. case PCIObjectType::Intermediate_Properties:
  1798. {
  1799. if ( 0 == pResult->nCol )
  1800. pResult->str = STRINGRESOURCE( srNodeProperties );
  1801. else
  1802. pResult->str = L"";
  1803. if ( pResult->mask & RDI_IMAGE && 0 == pResult->nCol )
  1804. pResult->nImage = ICON_FOLDER;
  1805. break;
  1806. }
  1807. case PCIObjectType::Intermediate_UnfilteredURL:
  1808. {
  1809. if ( 0 == pResult->nCol )
  1810. pResult->str = STRINGRESOURCE( srNodeUnfiltered );
  1811. else
  1812. pResult->str = L"";
  1813. if ( pResult->mask & RDI_IMAGE && 0 == pResult->nCol )
  1814. pResult->nImage = ICON_URL;
  1815. break;
  1816. }
  1817. }
  1818. }
  1819. else
  1820. sc = E_UNEXPECTED;
  1821. }
  1822. CATCH( CException, e )
  1823. {
  1824. ciaDebugOut(( DEB_ERROR, "Exception 0x%x in CCISnapinData::GetDisplayInfo\n", e.GetErrorCode() ));
  1825. sc = E_UNEXPECTED;
  1826. }
  1827. END_CATCH
  1828. UNTRANSLATE_EXCEPTIONS;
  1829. return sc;
  1830. }
  1831. SCODE STDMETHODCALLTYPE CCISnapin::CompareObjects( IDataObject * lpDataObjectA,
  1832. IDataObject * lpDataObjectB )
  1833. {
  1834. return _pSnapinData->CompareObjects( lpDataObjectA, lpDataObjectB );
  1835. }
  1836. SCODE STDMETHODCALLTYPE CCISnapin::CreatePropertyPages( IPropertySheetCallback * lpProvider,
  1837. LONG_PTR handle,
  1838. IDataObject * lpIDataObject )
  1839. {
  1840. return _pSnapinData->CreatePropertyPages( lpProvider, handle, lpIDataObject );
  1841. }
  1842. SCODE STDMETHODCALLTYPE CCISnapinData::CreatePropertyPages( IPropertySheetCallback * lpProvider,
  1843. LONG_PTR handle,
  1844. IDataObject * lpIDataObject )
  1845. {
  1846. SCODE sc = S_OK;
  1847. _notifHandle = handle;
  1848. TRY
  1849. {
  1850. CCIAdminDO * pDO = (CCIAdminDO *)lpIDataObject;
  1851. CCatalog * pCat = pDO->GetCatalog();
  1852. CScope * pScope = pDO->GetScope();
  1853. CCachedProperty * pProperty = pDO->GetProperty();
  1854. if ( pDO->Type() == CCT_SNAPIN_MANAGER )
  1855. {
  1856. ciaDebugOut(( DEB_ITRACE, "CCISnapin::CreatePropertyPages (object is Catalogs)\n" ));
  1857. XPtr<CIndexSrvPropertySheet0> xFoo( new CIndexSrvPropertySheet0( ghInstance, handle, &_Catalogs ));
  1858. if (S_OK == lpProvider->AddPage( xFoo->GetHandle()) )
  1859. xFoo.Acquire();
  1860. }
  1861. else if ( 0 != pProperty )
  1862. {
  1863. ciaDebugOut(( DEB_ITRACE, "CCISnapin::CreatePropertyPages (object is property %ws)\n",
  1864. pProperty->GetProperty() ));
  1865. XPtr<CPropertyPropertySheet1> xFoo( new CPropertyPropertySheet1( ghInstance, handle, pProperty, pCat ));
  1866. if ( S_OK == lpProvider->AddPage( xFoo->GetHandle()) )
  1867. xFoo.Acquire();
  1868. }
  1869. else if ( 0 != pScope )
  1870. {
  1871. ciaDebugOut(( DEB_ITRACE, "CCISnapin::CreatePropertyPages (object is scope %ws)\n",
  1872. pScope->GetPath() ));
  1873. }
  1874. //
  1875. // NOTE: The following has to be last, because you can derive a pCat from the
  1876. // preceding choices.
  1877. //
  1878. else if ( 0 != pCat )
  1879. {
  1880. ciaDebugOut(( DEB_ITRACE, "CCISnapin::CreatePropertyPages (object is catalog %ws)\n",
  1881. pCat->GetCat( TRUE ) ));
  1882. XPtr<CCatalogBasicPropertySheet> xCat1( new CCatalogBasicPropertySheet( ghInstance, handle, pCat ));
  1883. if (S_OK == lpProvider->AddPage( xCat1->GetHandle()) )
  1884. xCat1.Acquire();
  1885. XPtr<CIndexSrvPropertySheet2> xCP2( new CIndexSrvPropertySheet2( ghInstance, handle, pCat ));
  1886. if ( S_OK == lpProvider->AddPage( xCP2->GetHandle()) )
  1887. xCP2.Acquire();
  1888. XPtr<CIndexSrvPropertySheet1> xIS1( new CIndexSrvPropertySheet1( ghInstance, handle, pCat ));
  1889. if (S_OK == lpProvider->AddPage( xIS1->GetHandle()) )
  1890. xIS1.Acquire();
  1891. }
  1892. else if ( pDO->IsRoot() || pDO->IsStandAloneRoot() )
  1893. {
  1894. ciaDebugOut(( DEB_ITRACE, "CCISnapin::CreatePropertyPages (object is root)\n" ));
  1895. XPtr<CIndexSrvPropertySheet1> xIS1( new CIndexSrvPropertySheet1( ghInstance, handle, &_Catalogs) );
  1896. if (S_OK == lpProvider->AddPage( xIS1->GetHandle()) )
  1897. xIS1.Acquire();
  1898. XPtr<CIndexSrvPropertySheet2> xIS2( new CIndexSrvPropertySheet2( ghInstance, handle, &_Catalogs) );
  1899. if (S_OK == lpProvider->AddPage( xIS2->GetHandle()) )
  1900. xIS2.Acquire();
  1901. }
  1902. else
  1903. {
  1904. ciaDebugOut(( DEB_ITRACE, "CCISnapin::CreatePropertyPages. Invalid call. (cookie = 0x%x, type = 0x%x)\n",
  1905. ((CCIAdminDO *)lpIDataObject)->Cookie(),
  1906. ((CCIAdminDO *)lpIDataObject)->Type() ));
  1907. }
  1908. }
  1909. CATCH( CException, e )
  1910. {
  1911. ciaDebugOut(( DEB_ERROR, "CCISnapin::CreatePropertyPages: Caught error 0x%x\n", e.GetErrorCode() ));
  1912. sc = GetOleError( e );
  1913. }
  1914. END_CATCH
  1915. return sc;
  1916. }
  1917. SCODE STDMETHODCALLTYPE CCISnapin::QueryPagesFor( IDataObject * lpDataObject )
  1918. {
  1919. return _pSnapinData->QueryPagesFor( lpDataObject );
  1920. }
  1921. SCODE STDMETHODCALLTYPE CCISnapin::SetControlbar( LPCONTROLBAR pControlbar)
  1922. {
  1923. // Notes: This implementation is based on the MMC
  1924. // sample Step4.
  1925. if (0 == pControlbar)
  1926. {
  1927. _xControlbar.Free();
  1928. return S_OK;
  1929. }
  1930. SCODE sc = S_OK;
  1931. // cache the incoming pointer and AddRef it
  1932. _xControlbar.Set(pControlbar);
  1933. _xControlbar->AddRef();
  1934. // If we haven't yet created a toolbar, create now
  1935. if (0 == _xToolbar.GetPointer())
  1936. {
  1937. Win4Assert(0 == _xBmpToolbar.Get());
  1938. sc = pControlbar->Create(TOOLBAR, this, _xToolbar.GetIUPointer());
  1939. if (SUCCEEDED(sc))
  1940. {
  1941. _xBmpToolbar.Set(LoadBitmap(ghInstance, MAKEINTRESOURCE(BMP_TOOLBAR_SMALL)));
  1942. sc = (_xBmpToolbar.Get() ? S_OK : E_FAIL);
  1943. }
  1944. if (SUCCEEDED(sc))
  1945. sc = _xToolbar->AddBitmap(sizeof aContextButtons / sizeof aContextButtons[0],
  1946. _xBmpToolbar.Get(), 16, 16, RGB(255, 0, 255));
  1947. if (SUCCEEDED(sc))
  1948. sc = _xToolbar->AddButtons(sizeof aContextButtons / sizeof aContextButtons[0],
  1949. aContextButtons);
  1950. }
  1951. return sc;
  1952. }
  1953. SCODE STDMETHODCALLTYPE CCISnapin::ControlbarNotify( MMC_NOTIFY_TYPE event,
  1954. LPARAM arg,
  1955. LPARAM param)
  1956. {
  1957. Win4Assert(_xControlbar.GetPointer() &&
  1958. _xToolbar.GetPointer() &&
  1959. _xBmpToolbar.Get());
  1960. if (MMCN_SELECT == event && !((BOOL)LOWORD(arg)) && _pSnapinData->IsURLDeselected() )
  1961. return E_POINTER;
  1962. SCODE sc = S_OK;
  1963. BOOL fPaused = FALSE;
  1964. BOOL fStopped = FALSE;
  1965. BOOL fStarted = FALSE;
  1966. TRY
  1967. {
  1968. if (MMCN_SELECT == event)
  1969. {
  1970. LPDATAOBJECT pDataObject = (LPDATAOBJECT) param;
  1971. if( NULL == pDataObject )
  1972. return S_FALSE;
  1973. // Completely random MMC behavior (apparently).
  1974. if ( -2 == param )
  1975. return S_FALSE;
  1976. CCIAdminDO * pDO = (CCIAdminDO *)pDataObject;
  1977. BOOL bScope = (BOOL) LOWORD(arg);
  1978. BOOL bSelect = (BOOL) HIWORD(arg);
  1979. ciaDebugOut((DEB_ITRACE,
  1980. "select event: scope: %d, selection %d, lparam: 0x%x\n",
  1981. bScope, bSelect, param));
  1982. CMachineAdmin MachineAdmin( _pSnapinData->GetCatalogs().IsLocalMachine() ?
  1983. 0 : _pSnapinData->GetCatalogs().GetMachine() );
  1984. if (bScope) // scope item selected
  1985. {
  1986. if (pDO->IsRoot() || pDO->IsStandAloneRoot() )
  1987. {
  1988. sc = _xControlbar->Attach(TOOLBAR, _xToolbar.GetPointer());
  1989. if ( SUCCEEDED(sc) )
  1990. {
  1991. if ( MachineAdmin.IsCIStarted() )
  1992. fStarted = TRUE;
  1993. else if ( MachineAdmin.IsCIPaused() )
  1994. fPaused = TRUE;
  1995. else
  1996. {
  1997. Win4Assert( MachineAdmin.IsCIStopped() );
  1998. fStopped = TRUE;
  1999. }
  2000. }
  2001. }
  2002. else
  2003. {
  2004. sc = _xControlbar->Detach(_xToolbar.GetPointer());
  2005. // If the URL on scope pane is deselected, remember that
  2006. _pSnapinData->SetURLDeselected( pDO->IsURLIntermediate() && bSelect == FALSE );
  2007. }
  2008. }
  2009. // result list item selected
  2010. else
  2011. {
  2012. if ( pDO->IsACatalog() )
  2013. {
  2014. XPtr<CCatalogAdmin> xCat( MachineAdmin.QueryCatalogAdmin( pDO->GetCatalog()->GetCat(TRUE) ) );
  2015. if ( xCat->IsStarted() )
  2016. fStarted = TRUE;
  2017. else if ( xCat->IsPaused() )
  2018. fPaused = TRUE;
  2019. else
  2020. {
  2021. Win4Assert( xCat->IsStopped() );
  2022. fStopped = TRUE;
  2023. }
  2024. }
  2025. else if ( pDO->IsRoot() || pDO->IsStandAloneRoot() )
  2026. {
  2027. sc = _xControlbar->Attach(TOOLBAR, _xToolbar.GetPointer());
  2028. if ( SUCCEEDED(sc) )
  2029. {
  2030. if ( MachineAdmin.IsCIStarted() )
  2031. fStarted = TRUE;
  2032. else if ( MachineAdmin.IsCIPaused() )
  2033. fPaused = TRUE;
  2034. else
  2035. {
  2036. Win4Assert( MachineAdmin.IsCIStopped() );
  2037. fStopped = TRUE;
  2038. }
  2039. }
  2040. }
  2041. }
  2042. Win4Assert( _xToolbar.GetPointer() );
  2043. if (fStarted)
  2044. {
  2045. _xToolbar->SetButtonState(comidStartCITop, ENABLED, FALSE);
  2046. _xToolbar->SetButtonState(comidStopCITop, ENABLED, TRUE);
  2047. _xToolbar->SetButtonState(comidPauseCITop, ENABLED, TRUE);
  2048. }
  2049. else if (fStopped)
  2050. {
  2051. _xToolbar->SetButtonState(comidStartCITop, ENABLED, TRUE);
  2052. _xToolbar->SetButtonState(comidStopCITop, ENABLED, FALSE);
  2053. _xToolbar->SetButtonState(comidPauseCITop, ENABLED, FALSE);
  2054. }
  2055. else if (fPaused)
  2056. {
  2057. _xToolbar->SetButtonState(comidStartCITop, ENABLED, TRUE);
  2058. _xToolbar->SetButtonState(comidStopCITop, ENABLED, TRUE);
  2059. _xToolbar->SetButtonState(comidPauseCITop, ENABLED, FALSE);
  2060. }
  2061. }
  2062. else if (MMCN_BTN_CLICK == event)
  2063. {
  2064. Win4Assert( comidStartCITop == param ||
  2065. comidStopCITop == param ||
  2066. comidPauseCITop == param );
  2067. LPDATAOBJECT pDataObject = (LPDATAOBJECT) arg;
  2068. CCIAdminDO TempDO( 0, CCT_SCOPE, 0 );
  2069. if( NULL == pDataObject )
  2070. pDataObject = (LPDATAOBJECT)&TempDO;
  2071. return Command( (long)param, pDataObject );
  2072. }
  2073. }
  2074. CATCH( CException, e )
  2075. {
  2076. sc = E_FAIL;
  2077. }
  2078. END_CATCH
  2079. return sc;
  2080. }
  2081. SCODE STDMETHODCALLTYPE CCISnapinData::QueryPagesFor( IDataObject * lpDataObject )
  2082. {
  2083. if ( 0 == lpDataObject || _fURLDeselected )
  2084. return E_POINTER;
  2085. SCODE sc = S_OK;
  2086. TRY
  2087. {
  2088. // NOTE: Attempt to open the service and if that fails, we'll be unable to
  2089. // add property pages. That's expected behavior
  2090. XPtr<CMachineAdmin> xMachineAdmin(new CMachineAdmin( _Catalogs.GetMachine() ));
  2091. CCIAdminDO * pDO = (CCIAdminDO *)lpDataObject;
  2092. ciaDebugOut(( DEB_ITRACE, "CCISnapin::QueryPagesFor (cookie = 0x%x, type = 0x%x)\n",
  2093. pDO->Cookie(), pDO->Type() ));
  2094. if ( pDO->Type() == CCT_SNAPIN_MANAGER )
  2095. sc = S_OK;
  2096. if ( pDO->IsRoot() || pDO->IsStandAloneRoot() || pDO->IsACatalog() || pDO->IsAProperty())
  2097. {
  2098. sc = S_OK;
  2099. }
  2100. else
  2101. {
  2102. ciaDebugOut(( DEB_WARN, "No property pages for (cookie = 0x%x, type = 0x%x)\n",
  2103. pDO->Cookie(), pDO->Type() ));
  2104. sc = S_FALSE;
  2105. }
  2106. }
  2107. CATCH( CException, e )
  2108. {
  2109. ciaDebugOut(( DEB_ERROR, "CCISnapin::QueryPagesFor: Caught error 0x%x\n", e.GetErrorCode() ));
  2110. sc = GetOleError( e );
  2111. }
  2112. END_CATCH
  2113. return sc;
  2114. }
  2115. SCODE STDMETHODCALLTYPE CCISnapin::AddMenuItems( IDataObject * piDataObject,
  2116. IContextMenuCallback * piCallback,
  2117. long * pInsertionAllowed )
  2118. {
  2119. EnableStandardVerbs( piDataObject );
  2120. return _pSnapinData->AddMenuItems( piDataObject, piCallback, pInsertionAllowed );
  2121. }
  2122. SCODE STDMETHODCALLTYPE CCISnapin::Command( long lCommandID,
  2123. IDataObject * piDataObject )
  2124. {
  2125. return _pSnapinData->Command( lCommandID, piDataObject );
  2126. }
  2127. //
  2128. // ISnapinAbout methods
  2129. //
  2130. //+-------------------------------------------------------------------------
  2131. //
  2132. // Method: CCISnapinData::GetSnapinDescription
  2133. //
  2134. // Synopsis: Get description about indexing service.
  2135. //
  2136. // History: 02-Feb-1998 KrishanN Added Header
  2137. //
  2138. //--------------------------------------------------------------------------
  2139. SCODE STDMETHODCALLTYPE CCISnapinData::GetSnapinDescription(LPOLESTR *lpDescription)
  2140. {
  2141. WCHAR szStr[1024];
  2142. wsprintf(szStr, L"%s\r\n%s", STRINGRESOURCE( srProductDescription ),
  2143. STRINGRESOURCE( srVendorCopyright ));
  2144. return MakeOLESTR(lpDescription, szStr);
  2145. }
  2146. //+-------------------------------------------------------------------------
  2147. //
  2148. // Method: CCISnapinData::GetProvider
  2149. //
  2150. // Synopsis: Get provider of index server.
  2151. //
  2152. // History: 02-Feb-1998 KrishanN Added Header
  2153. //
  2154. //--------------------------------------------------------------------------
  2155. SCODE STDMETHODCALLTYPE CCISnapinData::GetProvider(LPOLESTR *lpName)
  2156. {
  2157. WCHAR szStr[1024];
  2158. wsprintf(szStr, L"%S, %s", VER_COMPANYNAME_STR, STRINGRESOURCE( srVendorName ));
  2159. return MakeOLESTR(lpName, szStr);
  2160. }
  2161. //+-------------------------------------------------------------------------
  2162. //
  2163. // Method: CCISnapinData::GetSnapinVersion
  2164. //
  2165. // Synopsis: Get version of index server.
  2166. //
  2167. // History: 02-Feb-1998 KrishanN Added Header
  2168. //
  2169. //--------------------------------------------------------------------------
  2170. SCODE STDMETHODCALLTYPE CCISnapinData::GetSnapinVersion(LPOLESTR *lpVersion)
  2171. {
  2172. WCHAR szStr[1024];
  2173. wsprintf(szStr, L"%S", VER_PRODUCTVERSION_STR);
  2174. return MakeOLESTR(lpVersion, szStr);
  2175. }
  2176. //+-------------------------------------------------------------------------
  2177. //
  2178. // Method: CCISnapinData::GetSnapinImage
  2179. //
  2180. // Synopsis: Get image of index server.
  2181. //
  2182. // History: 02-Feb-1998 KrishanN Added Header
  2183. //
  2184. //--------------------------------------------------------------------------
  2185. SCODE STDMETHODCALLTYPE CCISnapinData::GetSnapinImage(HICON *phAppIcon)
  2186. {
  2187. *phAppIcon = LoadIcon(ghInstance, MAKEINTRESOURCE(ICON_ABOUT));
  2188. return (NULL == *phAppIcon) ? E_FAIL : S_OK;
  2189. }
  2190. //+-------------------------------------------------------------------------
  2191. //
  2192. // Method: CCISnapinData::GetStaticFolderImage
  2193. //
  2194. // Synopsis: Get static folder images for use with Index Server.
  2195. //
  2196. // History: 02-Feb-1998 KrishanN Added Header
  2197. //
  2198. //--------------------------------------------------------------------------
  2199. SCODE STDMETHODCALLTYPE CCISnapinData::GetStaticFolderImage(
  2200. HBITMAP *hSmallImage,
  2201. HBITMAP *hSmallImageOpen,
  2202. HBITMAP *hLargeImage,
  2203. COLORREF *cMask)
  2204. {
  2205. *hSmallImage = *hSmallImageOpen = *hLargeImage = NULL;
  2206. *hSmallImage = LoadBitmap(ghInstance, MAKEINTRESOURCE(BMP_SMALL_CLOSED_FOLDER));
  2207. *hSmallImageOpen = LoadBitmap(ghInstance, MAKEINTRESOURCE(BMP_SMALL_OPEN_FOLDER));
  2208. *hLargeImage = LoadBitmap(ghInstance, MAKEINTRESOURCE(BMP_LARGE_CLOSED_FOLDER));
  2209. *cMask = RGB(255, 0, 255);
  2210. if (NULL == *hSmallImage || NULL == *hSmallImageOpen || NULL == *hLargeImage)
  2211. {
  2212. if (*hSmallImage)
  2213. DeleteObject(*hSmallImage);
  2214. if (*hSmallImageOpen)
  2215. DeleteObject(*hSmallImageOpen);
  2216. if (*hLargeImage)
  2217. DeleteObject(*hLargeImage);
  2218. return E_FAIL;
  2219. }
  2220. return S_OK;
  2221. }
  2222. //+-------------------------------------------------------------------------
  2223. //
  2224. // Method: CCISnapin::CCISnapin
  2225. //
  2226. // Synopsis: Constructor
  2227. //
  2228. // History: 26-Nov-1996 KyleP Created
  2229. //
  2230. //--------------------------------------------------------------------------
  2231. CCISnapin::CCISnapin( CCISnapinData & SnapinData, CCISnapin * pNext )
  2232. : _pFrame( 0 ),
  2233. _pHeader( 0 ),
  2234. _pResultPane( 0 ),
  2235. _pImageList( 0 ),
  2236. _pConsoleVerb( 0 ),
  2237. _pDisplayHelp( 0 ),
  2238. _CurrentView( CCISnapin::Nothing ),
  2239. _pSnapinData( & SnapinData ),
  2240. _pNext( pNext ),
  2241. _uRefs( 1 )
  2242. {
  2243. }
  2244. //+-------------------------------------------------------------------------
  2245. //
  2246. // Method: CCISnapin::~CCISnapin
  2247. //
  2248. // Synopsis: Destructor
  2249. //
  2250. // History: 26-Nov-1996 KyleP Created
  2251. //
  2252. //--------------------------------------------------------------------------
  2253. CCISnapin::~CCISnapin()
  2254. {
  2255. ciaDebugOut(( DEB_ITRACE, "CCISnapin::~CCISnapin\n" ));
  2256. if ( 0 != _pSnapinData )
  2257. {
  2258. if ( _pSnapinData->_pChild == this )
  2259. {
  2260. _pSnapinData->_pChild = _pNext;
  2261. }
  2262. else
  2263. {
  2264. for ( CCISnapin * pCurrent = _pSnapinData->_pChild;
  2265. 0 != pCurrent && 0 != pCurrent->Next();
  2266. pCurrent = pCurrent->Next() )
  2267. {
  2268. if ( pCurrent->Next() == this )
  2269. {
  2270. pCurrent->Link( pCurrent->Next()->Next() );
  2271. break;
  2272. }
  2273. }
  2274. }
  2275. }
  2276. Win4Assert( 0 == _pFrame );
  2277. Win4Assert( 0 == _pHeader );
  2278. Win4Assert( 0 == _pResultPane );
  2279. Win4Assert( 0 == _pImageList );
  2280. Win4Assert( 0 == _pConsoleVerb );
  2281. }
  2282. //+-------------------------------------------------------------------------
  2283. //
  2284. // Function: GetMachineName
  2285. //
  2286. // Synopsis: gets machine name to administer.
  2287. //
  2288. // Arguments: [pDO] -- dataobject pointer
  2289. // [pwszMachineName] -- out buffer
  2290. // [ cc ] -- buffer size in wchars
  2291. //
  2292. // Returns: none. throws upon fatal errors (out of memory).
  2293. //
  2294. // History: 01-Jul-1998 mohamedn created
  2295. // 31-Aug-1998 KyleP Support DNS names
  2296. //
  2297. //--------------------------------------------------------------------------
  2298. void GetMachineName(LPDATAOBJECT pDO, XGrowable<WCHAR,MAX_COMPUTERNAME_LENGTH> & xwszMachineName)
  2299. {
  2300. Win4Assert( pDO );
  2301. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL };
  2302. FORMATETC formatetc = { (CLIPFORMAT)CCIAdminDO::GetMachineNameCF(), NULL,
  2303. DVASPECT_CONTENT, -1, TYMED_HGLOBAL
  2304. };
  2305. // Allocate memory for the stream
  2306. //
  2307. // What if the computer name is > 512 bytes long?
  2308. //
  2309. stgmedium.hGlobal = GlobalAlloc(GMEM_SHARE, 512);
  2310. XGlobalAllocMem xhGlobal(stgmedium.hGlobal);
  2311. WCHAR * pwszTmpBuf = NULL;
  2312. // Attempt to get data from the object
  2313. do
  2314. {
  2315. if (stgmedium.hGlobal == NULL)
  2316. break;
  2317. if (FAILED(pDO->GetDataHere(&formatetc, &stgmedium)))
  2318. break;
  2319. pwszTmpBuf = (WCHAR *)stgmedium.hGlobal;
  2320. if ( pwszTmpBuf == NULL || *pwszTmpBuf == L'' )
  2321. {
  2322. xwszMachineName[0] = L'.';
  2323. xwszMachineName[1] = 0;
  2324. }
  2325. else
  2326. {
  2327. unsigned cc = wcslen(pwszTmpBuf) + 1;
  2328. xwszMachineName.SetSize( cc );
  2329. RtlCopyMemory( xwszMachineName.Get(), pwszTmpBuf, cc * sizeof(WCHAR) );
  2330. }
  2331. } while (FALSE);
  2332. }
  2333. //+-------------------------------------------------------------------------
  2334. //
  2335. // Method: CCISnapin::ShowFolder, private
  2336. //
  2337. // Synopsis: Called when folder is selected. Displays result in
  2338. // scope pane.
  2339. //
  2340. // History: 27-Nov-1996 KyleP Created
  2341. //
  2342. //--------------------------------------------------------------------------
  2343. void CCISnapinData::ShowFolder( CCIAdminDO * pDO, BOOL fExpanded, HSCOPEITEM hScopeItem )
  2344. {
  2345. ciaDebugOut(( DEB_ITRACE, "CCISnapinData::ShowFolder (fExpanded = %d, hScopeItem = 0x%x)\n",
  2346. fExpanded, hScopeItem ));
  2347. Win4Assert( pDO );
  2348. //
  2349. // Only do something on expansion
  2350. //
  2351. if ( fExpanded )
  2352. {
  2353. if ( !_fIsInitialized && pDO->IsStandAloneRoot() )
  2354. {
  2355. _fIsExtension = FALSE;
  2356. }
  2357. else if ( !_fIsInitialized )
  2358. {
  2359. _fIsExtension = TRUE;
  2360. }
  2361. //
  2362. // we're stand alone.
  2363. //
  2364. if ( !_fIsExtension )
  2365. {
  2366. _fIsInitialized = TRUE;
  2367. if ( pDO->IsStandAloneRoot() )
  2368. {
  2369. _Catalogs.DisplayScope( hScopeItem );
  2370. }
  2371. else if ( pDO->IsACatalog() )
  2372. {
  2373. pDO->GetCatalog()->DisplayIntermediate( _pScopePane );
  2374. }
  2375. }
  2376. else if ( _fIsExtension && !_fIsInitialized )
  2377. {
  2378. //
  2379. // we're an extension
  2380. //
  2381. XGrowable<WCHAR,MAX_COMPUTERNAME_LENGTH> xwcsMachine;
  2382. GetMachineName( pDO, xwcsMachine );
  2383. _Catalogs.SetMachine( xwcsMachine.Get() );
  2384. SetRootDisplay();
  2385. _rootNode.Display(hScopeItem);
  2386. _fIsInitialized = TRUE;
  2387. }
  2388. else if ( _fIsExtension && pDO->IsRoot() )
  2389. {
  2390. Win4Assert( _fIsInitialized );
  2391. _Catalogs.DisplayScope( _rootNode.GethScopeItem() );
  2392. }
  2393. else if ( _fIsExtension && pDO->IsACatalog() )
  2394. {
  2395. Win4Assert( _fIsInitialized );
  2396. pDO->GetCatalog()->DisplayIntermediate( _pScopePane );
  2397. }
  2398. }
  2399. }
  2400. //+-------------------------------------------------------------------------
  2401. //
  2402. // Method: CCISnapin::SetRootDisplay
  2403. //
  2404. // Synopsis: sets display name string, type string, and description string
  2405. // for static root node
  2406. //
  2407. // History: 7/1/98 mohamedn created
  2408. // 9/29/98 KrishnaN Added type and description.
  2409. //
  2410. //--------------------------------------------------------------------------
  2411. void CCISnapinData::SetRootDisplay()
  2412. {
  2413. if ( _fIsExtension )
  2414. {
  2415. unsigned cc = wcslen( STRINGRESOURCE(srIndexServerCmpManage) + 1 );
  2416. _xwcsTitle.SetSize(cc);
  2417. wcscpy( _xwcsTitle.Get(), STRINGRESOURCE(srIndexServerCmpManage) );
  2418. cc = wcslen( STRINGRESOURCE(srType) + 1);
  2419. _xwcsType.SetSize(cc);
  2420. wcscpy( _xwcsType.Get(), STRINGRESOURCE(srType) );
  2421. cc = wcslen( STRINGRESOURCE(srProductDescription) + 1);
  2422. _xwcsDescription.SetSize(cc);
  2423. wcscpy( _xwcsDescription.Get(), STRINGRESOURCE(srProductDescription) );
  2424. }
  2425. else
  2426. {
  2427. unsigned cc = wcslen( STRINGRESOURCE(srIndexServer) ) + 1;
  2428. _xwcsTitle.SetSize(cc);
  2429. wcscpy( _xwcsTitle.Get(), STRINGRESOURCE(srIndexServer) );
  2430. if ( _Catalogs.IsLocalMachine() )
  2431. {
  2432. cc += wcslen( STRINGRESOURCE(srLM) );
  2433. _xwcsTitle.SetSize( cc );
  2434. wcscat( _xwcsTitle.Get(), STRINGRESOURCE(srLM) );
  2435. }
  2436. else
  2437. {
  2438. cc += wcslen( _Catalogs.GetMachine() );
  2439. cc += 2; // the UNC slashes
  2440. _xwcsTitle.SetSize( cc );
  2441. wcscat( _xwcsTitle.Get(), L"\\\\" );
  2442. wcscat( _xwcsTitle.Get(), _Catalogs.GetMachine() );
  2443. }
  2444. _xwcsType.Free();
  2445. _xwcsDescription.Free();
  2446. }
  2447. }
  2448. void CCISnapin::EnableStandardVerbs( IDataObject * piDataObject )
  2449. {
  2450. SCODE sc = QueryPagesFor( piDataObject );
  2451. if ( S_OK == sc )
  2452. {
  2453. _pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  2454. }
  2455. else
  2456. _pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, HIDDEN, TRUE);
  2457. if (!_pSnapinData->IsURLDeselected() )
  2458. {
  2459. CCIAdminDO * pDO = (CCIAdminDO *)piDataObject;
  2460. if ( ( pDO->IsADirectory() && !pDO->GetScope()->IsVirtual() && !pDO->GetScope()->IsShadowAlias() ) ||
  2461. pDO->IsACatalog() )
  2462. {
  2463. _pConsoleVerb->SetVerbState(MMC_VERB_DELETE, ENABLED, TRUE);
  2464. }
  2465. else
  2466. {
  2467. _pConsoleVerb->SetVerbState(MMC_VERB_DELETE, HIDDEN, TRUE);
  2468. }
  2469. }
  2470. }
  2471. //+-------------------------------------------------------------------------
  2472. //
  2473. // Method: CCISnapin::ShowItem, private
  2474. //
  2475. // Synopsis: Called when folder is selected. Displays result in
  2476. // result pane.
  2477. //
  2478. // History: 27-Nov-1996 KyleP Created
  2479. //
  2480. //--------------------------------------------------------------------------
  2481. void CCISnapin::ShowItem( CCIAdminDO * pDO, BOOL fExpanded, HSCOPEITEM hScopeItem )
  2482. {
  2483. ciaDebugOut(( DEB_ITRACE, "CCISnapin::ShowItem (fExpanded = %d, hScopeItem = 0x%x)\n",
  2484. fExpanded, hScopeItem ));
  2485. if ( fExpanded )
  2486. {
  2487. SCODE sc = InitImageResources( _pImageList );
  2488. if ( FAILED(sc) )
  2489. {
  2490. ciaDebugOut(( DEB_ERROR, "InitImageResources returned 0x%x\n", sc ));
  2491. THROW( CException( sc ) );
  2492. }
  2493. if ( pDO->IsRoot() || pDO->IsStandAloneRoot() )
  2494. {
  2495. if ( !_CatalogsHeader.IsInitialized() )
  2496. {
  2497. _pSnapinData->GetCatalogs().InitHeader( _CatalogsHeader );
  2498. //
  2499. // Start background polling.
  2500. //
  2501. _pSnapinData->GetCatalogs().Display( TRUE );
  2502. }
  2503. _CatalogsHeader.Display( _pHeader );
  2504. _CurrentView = CCISnapin::Catalogs;
  2505. }
  2506. else if ( pDO->IsADirectoryIntermediate() )
  2507. {
  2508. CCatalog * pCat = pDO->GetCatalog();
  2509. if ( !_CatalogScopeHeader.IsInitialized() )
  2510. pCat->InitScopeHeader( _CatalogScopeHeader );
  2511. _CatalogScopeHeader.Display( _pHeader );
  2512. pCat->DisplayScopes( TRUE, _pResultPane );
  2513. _CurrentView = CCISnapin::Scopes;
  2514. _CurrentCatalog = pCat;
  2515. }
  2516. else if ( pDO->IsAPropertyIntermediate() )
  2517. {
  2518. CCatalog * pCat = pDO->GetCatalog();
  2519. if ( !_CatalogPropertyHeader.IsInitialized() )
  2520. pCat->InitPropertyHeader( _CatalogPropertyHeader );
  2521. _CatalogPropertyHeader.Display( _pHeader );
  2522. pCat->DisplayProperties( TRUE, _pResultPane );
  2523. _CurrentView = CCISnapin::Properties;
  2524. _CurrentCatalog = pCat;
  2525. }
  2526. else
  2527. _CurrentView = CCISnapin::Nothing;
  2528. }
  2529. else
  2530. {
  2531. switch ( _CurrentView )
  2532. {
  2533. case CCISnapin::Catalogs:
  2534. Win4Assert( pDO->IsRoot() || pDO->IsStandAloneRoot() );
  2535. _CatalogsHeader.Update( _pHeader );
  2536. break;
  2537. case CCISnapin::Scopes:
  2538. Win4Assert( pDO->IsADirectoryIntermediate() );
  2539. _CatalogScopeHeader.Update( _pHeader );
  2540. break;
  2541. case CCISnapin::Properties:
  2542. Win4Assert( pDO->IsAPropertyIntermediate() );
  2543. _CatalogPropertyHeader.Update( _pHeader );
  2544. break;
  2545. }
  2546. _CurrentView = CCISnapin::Nothing;
  2547. }
  2548. }
  2549. void CCISnapin::Refresh()
  2550. {
  2551. switch ( _CurrentView )
  2552. {
  2553. case CCISnapin::Scopes:
  2554. _CurrentCatalog->DisplayScopes( FALSE, _pResultPane );
  2555. break;
  2556. case CCISnapin::Properties:
  2557. _CurrentCatalog->DisplayProperties( FALSE, _pResultPane );
  2558. break;
  2559. case CCISnapin::Catalogs:
  2560. case CCISnapin::Nothing:
  2561. default:
  2562. break;
  2563. }
  2564. }
  2565. void CCISnapin::RemoveScope( CCIAdminDO * pDO )
  2566. {
  2567. Win4Assert( pDO->IsADirectory() && !pDO->GetScope()->IsVirtual() );
  2568. CScope * pScope = pDO->GetScope();
  2569. Win4Assert( 0 != pScope );
  2570. //
  2571. // Make sure the user wants to remove scope.
  2572. //
  2573. WCHAR awcMsg[MAX_PATH];
  2574. WCHAR awcTemp[2 * MAX_PATH];
  2575. LoadString( ghInstance, MSG_REMOVE_SCOPE, awcMsg, sizeof(awcMsg) / sizeof(WCHAR) );
  2576. wsprintf( awcTemp, awcMsg, pScope->GetPath() );
  2577. LoadString( ghInstance, MSG_REMOVE_SCOPE_TITLE, awcMsg, sizeof(awcMsg) / sizeof(WCHAR) );
  2578. int iResult;
  2579. SCODE sc = _pFrame->MessageBox( awcTemp,
  2580. awcMsg,
  2581. MB_YESNO | /* MB_HELP | */
  2582. MB_ICONWARNING | MB_DEFBUTTON2 |
  2583. MB_APPLMODAL,
  2584. &iResult );
  2585. if ( SUCCEEDED(sc) )
  2586. {
  2587. switch ( iResult )
  2588. {
  2589. case IDYES:
  2590. {
  2591. CCatalog & cat = pScope->GetCatalog();
  2592. cat.RemoveScope( pScope );
  2593. Refresh(); // Update all result pane(s)
  2594. break;
  2595. }
  2596. case IDNO:
  2597. // Do nothing.
  2598. break;
  2599. /* Help is not being used...
  2600. case IDHELP:
  2601. {
  2602. // NTRAID#DB-NTBUG9-83341-2000/07/31-dlee Need online help for several Indexing Service admin dialogs
  2603. DisplayHelp( _hFrameWindow, HIDD_REMOVE_SCOPE );
  2604. break;
  2605. }
  2606. */
  2607. default:
  2608. break;
  2609. }
  2610. }
  2611. }
  2612. void CCISnapinData::RemoveCatalog( CCIAdminDO * pDO )
  2613. {
  2614. CCatalog * pCat = pDO->GetCatalog();
  2615. Win4Assert( 0 != pCat );
  2616. //
  2617. // Make sure we can perform the operation right now.
  2618. //
  2619. CMachineAdmin MachineAdmin( _Catalogs.IsLocalMachine() ? 0 : _Catalogs.GetMachine() );
  2620. if ( MachineAdmin.IsCIStarted() )
  2621. {
  2622. int iResult;
  2623. SCODE sc = _pFrame->MessageBox( STRINGRESOURCE( srMsgCantDeleteCatalog ),
  2624. STRINGRESOURCE( srMsgDeleteCatalogTitle ),
  2625. MB_OK | /* MB_HELP | */
  2626. MB_ICONWARNING | MB_APPLMODAL,
  2627. &iResult );
  2628. if ( SUCCEEDED(sc) )
  2629. {
  2630. switch ( iResult )
  2631. {
  2632. case IDOK:
  2633. case IDCANCEL:
  2634. // Do nothing.
  2635. break;
  2636. /* Help is not being used
  2637. case IDHELP:
  2638. {
  2639. DisplayHelp( _hFrameWindow, HIDD_REMOVE_CATALOG );
  2640. break;
  2641. }
  2642. */
  2643. default:
  2644. break;
  2645. }
  2646. }
  2647. }
  2648. else
  2649. {
  2650. int iResult;
  2651. SCODE sc = _pFrame->MessageBox( STRINGRESOURCE( srMsgDeleteCatalog ),
  2652. STRINGRESOURCE( srMsgDeleteCatalogAsk ),
  2653. MB_YESNO | /* MB_HELP | */
  2654. MB_ICONWARNING | MB_DEFBUTTON2 |
  2655. MB_APPLMODAL,
  2656. &iResult );
  2657. if ( SUCCEEDED(sc) )
  2658. {
  2659. switch ( iResult )
  2660. {
  2661. case IDYES:
  2662. {
  2663. if ( FAILED(_Catalogs.RemoveCatalog( pCat )) )
  2664. _pFrame->MessageBox( STRINGRESOURCE( srMsgCatalogPartialDeletion ),
  2665. STRINGRESOURCE( srMsgDeleteCatalogTitle ),
  2666. MB_OK | /* MB_HELP | */
  2667. MB_ICONWARNING | MB_APPLMODAL,
  2668. &iResult);
  2669. Refresh(); // Update all result pane(s)
  2670. break;
  2671. }
  2672. case IDNO:
  2673. case IDCANCEL:
  2674. // Do nothing.
  2675. break;
  2676. /* Help is not being used...
  2677. case IDHELP:
  2678. {
  2679. DisplayHelp( _hFrameWindow, HIDD_REMOVE_CATALOG );
  2680. break;
  2681. }
  2682. */
  2683. default:
  2684. break;
  2685. }
  2686. }
  2687. }
  2688. }
  2689. SCODE STDMETHODCALLTYPE CCISnapinData::GetHelpTopic( LPOLESTR *lpCompiledHelpFile)
  2690. {
  2691. if (0 == lpCompiledHelpFile)
  2692. return E_POINTER;
  2693. WCHAR awc[ MAX_PATH + 1];
  2694. const UINT cwcMax = sizeof awc / sizeof WCHAR;
  2695. UINT cwc = GetSystemWindowsDirectory( awc, cwcMax );
  2696. if ( 0 == cwc || cwc > cwcMax )
  2697. return E_UNEXPECTED;
  2698. if ( L'\\' != awc[ cwc-1] )
  2699. wcscat( awc, L"\\" );
  2700. // ixhelp.hlp is placed in %windir%\help
  2701. wcscat( awc, L"help\\\\is.chm" );
  2702. return MakeOLESTR(lpCompiledHelpFile, awc);
  2703. }
  2704. SCODE STDMETHODCALLTYPE CCISnapinData::GetLinkedTopics( LPOLESTR *lpCompiledHelpFiles)
  2705. {
  2706. if (0 == lpCompiledHelpFiles)
  2707. return E_POINTER;
  2708. WCHAR awc[ MAX_PATH + 1];
  2709. const UINT cwcMax = sizeof awc / sizeof WCHAR;
  2710. UINT cwc = GetSystemWindowsDirectory( awc, cwcMax );
  2711. if ( 0 == cwc || cwc > cwcMax )
  2712. return E_UNEXPECTED;
  2713. if ( L'\\' != awc[ cwc-1] )
  2714. wcscat( awc, L"\\" );
  2715. wcscat( awc, L"help\\\\isconcepts.chm" );
  2716. return MakeOLESTR(lpCompiledHelpFiles, awc);
  2717. }
  2718. SCODE STDMETHODCALLTYPE CCISnapinData::GetHelpTopic2( LPOLESTR *lpCompiledHelpFile)
  2719. {
  2720. if (0 == lpCompiledHelpFile)
  2721. return E_POINTER;
  2722. WCHAR awc[ MAX_PATH + 1];
  2723. const UINT cwcMax = sizeof awc / sizeof WCHAR;
  2724. UINT cwc = GetSystemWindowsDirectory( awc, cwcMax );
  2725. if ( 0 == cwc || cwc > cwcMax )
  2726. return E_UNEXPECTED;
  2727. if ( L'\\' != awc[ cwc-1] )
  2728. wcscat( awc, L"\\" );
  2729. wcscat( awc, L"help\\\\isconcepts.chm::/sag_INDEXtopnode.htm" );
  2730. return MakeOLESTR(lpCompiledHelpFile, awc);
  2731. }
  2732. SCODE InitImageResources( IImageList * pImageList )
  2733. {
  2734. HBITMAP hbmpSmall = LoadBitmap( ghInstance, MAKEINTRESOURCE( BMP_SMALL_ICONS ) );
  2735. if ( 0 == hbmpSmall )
  2736. return E_FAIL;
  2737. HBITMAP hbmpLarge = LoadBitmap( ghInstance, MAKEINTRESOURCE( BMP_LARGE_ICONS ) );
  2738. if ( 0 == hbmpLarge )
  2739. {
  2740. DeleteObject( hbmpSmall );
  2741. return E_FAIL;
  2742. }
  2743. SCODE sc = pImageList->ImageListSetStrip( (LONG_PTR *)hbmpSmall,
  2744. (LONG_PTR *)hbmpLarge,
  2745. 0,
  2746. RGB( 255, 0, 255 ) );
  2747. DeleteObject( hbmpSmall );
  2748. DeleteObject( hbmpLarge );
  2749. return sc;
  2750. }
  2751. //+-------------------------------------------------------------------------
  2752. //
  2753. // Function: DisplayHelp
  2754. //
  2755. // Synopsis: Displays context sensitive help
  2756. //
  2757. // Arguments: [hwnd] -- The parent window handle
  2758. // [dwID] -- The help context identifier
  2759. //
  2760. // Returns: TRUE if successful
  2761. //
  2762. // History: 20-Sep-1997 dlee Created
  2763. // 14-Sep-1998 KrishnaN Handle only context sensitive help.
  2764. // Regular help is handled by MMC help.
  2765. // This fixes 214619.
  2766. //
  2767. //--------------------------------------------------------------------------
  2768. BOOL DisplayHelp( HWND hwnd, DWORD dwID )
  2769. {
  2770. if (0 != dwID) // Display context-sensitive help
  2771. return DisplayHelp( hwnd, dwID, HELP_CONTEXT );
  2772. else
  2773. return TRUE; // Don't display regular help
  2774. } //DisplayHelp
  2775. //+-------------------------------------------------------------------------
  2776. //
  2777. // Function: DisplayHelp
  2778. //
  2779. // Synopsis: Displays context sensitive help
  2780. //
  2781. // Arguments: [hwnd] -- The parent window handle
  2782. // [dwID] -- The help context identifier
  2783. //
  2784. // Returns: TRUE if successful
  2785. //
  2786. // History: 20-Sep-1997 dlee Created
  2787. //
  2788. //--------------------------------------------------------------------------
  2789. BOOL DisplayHelp( HWND hwnd, DWORD dwID, UINT uCommand )
  2790. {
  2791. WCHAR awc[ MAX_PATH ];
  2792. const UINT cwcMax = sizeof awc / sizeof WCHAR;
  2793. UINT cwc = GetSystemWindowsDirectory( awc, cwcMax );
  2794. if ( 0 == cwc || cwc > cwcMax )
  2795. return FALSE;
  2796. if ( L'\\' != awc[ cwc-1] )
  2797. wcscat( awc, L"\\" );
  2798. // ixhelp.hlp is placed in %windir%\help
  2799. wcscat( awc, L"help\\\\ixhelp.hlp" );
  2800. return WinHelp( hwnd, awc, uCommand, dwID );
  2801. } //DisplayHelp
  2802. //+-------------------------------------------------------------------------
  2803. //
  2804. // Function: DisplayPopupHelp
  2805. //
  2806. // Synopsis: Displays context sensitive help as a popup
  2807. //
  2808. // Arguments: [hwnd] -- The parent window handle
  2809. // [dwID] -- The help context identifier
  2810. //
  2811. // Returns: TRUE if successful
  2812. //
  2813. // History: 11-May-1998 KrishnaN Created
  2814. //
  2815. //--------------------------------------------------------------------------
  2816. BOOL DisplayPopupHelp( HWND hwnd, DWORD dwHelpType )
  2817. {
  2818. return DisplayHelp( hwnd, (DWORD) (DWORD_PTR) aIds, dwHelpType);
  2819. } //DisplayPopupHelp
  2820. SCODE MakeOLESTR(LPOLESTR *lpBuffer, WCHAR const * pwszText)
  2821. {
  2822. if (0 == lpBuffer)
  2823. return E_INVALIDARG;
  2824. ULONG uLen = wcslen(pwszText);
  2825. uLen++; // string terminator
  2826. uLen = sizeof(WCHAR) * uLen;
  2827. *lpBuffer = (LPOLESTR)CoTaskMemAlloc(uLen);
  2828. if (*lpBuffer)
  2829. {
  2830. RtlCopyMemory(*lpBuffer, pwszText, uLen);
  2831. return S_OK;
  2832. }
  2833. else
  2834. return E_OUTOFMEMORY;
  2835. }
  2836. //+-------------------------------------------------------------------------
  2837. //
  2838. // Method: CCISnapinData::MaybeEnableCI, private
  2839. //
  2840. // Synopsis: Prompt user to set service to automatic start
  2841. //
  2842. // Arguments: [MachineAdmin] -- Machine administration object
  2843. //
  2844. // History: 07-Jul-1998 KyleP Created
  2845. //
  2846. //--------------------------------------------------------------------------
  2847. void CCISnapinData::MaybeEnableCI( CMachineAdmin & MachineAdmin )
  2848. {
  2849. if ( _Catalogs.IsLocalMachine() && !_fTriedEnable )
  2850. {
  2851. //
  2852. // Have we tried before?
  2853. //
  2854. if ( MachineAdmin.IsCIEnabled() )
  2855. {
  2856. _fTriedEnable = TRUE;
  2857. }
  2858. else
  2859. {
  2860. WCHAR wcTemp[ (sizeof(wszSnapinPath) + sizeof(wszCISnapin)) / sizeof(WCHAR) + 1];
  2861. wcscpy( wcTemp, wszSnapinPath );
  2862. wcscat( wcTemp, wszCISnapin );
  2863. CWin32RegAccess reg( HKEY_LOCAL_MACHINE, wcTemp );
  2864. BOOL fTry = FALSE;
  2865. if ( reg.Ok() )
  2866. {
  2867. DWORD dwVal;
  2868. BOOL fOk = reg.Get( wszTriedEnable, dwVal );
  2869. if ( fOk )
  2870. {
  2871. fTry = (0 == dwVal);
  2872. }
  2873. else
  2874. {
  2875. if ( reg.GetLastError() == ERROR_FILE_NOT_FOUND )
  2876. fTry = TRUE;
  2877. }
  2878. }
  2879. if ( fTry )
  2880. {
  2881. int iResult;
  2882. SCODE sc = _pFrame->MessageBox( STRINGRESOURCE( srMsgEnableCI ),
  2883. STRINGRESOURCE( srMsgEnableCITitle ),
  2884. MB_YESNO | /* MB_HELP | */
  2885. MB_ICONQUESTION | MB_DEFBUTTON1 |
  2886. MB_APPLMODAL,
  2887. &iResult );
  2888. if ( SUCCEEDED(sc) )
  2889. {
  2890. switch ( iResult )
  2891. {
  2892. case IDYES:
  2893. MachineAdmin.EnableCI();
  2894. break;
  2895. default:
  2896. break;
  2897. }
  2898. Win4Assert( reg.Ok() );
  2899. reg.Set( wszTriedEnable, 1 );
  2900. _fTriedEnable = TRUE;
  2901. }
  2902. }
  2903. else
  2904. _fTriedEnable = TRUE;
  2905. }
  2906. }
  2907. }
  2908. void CCISnapinData::SetButtonState( int idCommand, MMC_BUTTON_STATE nState, BOOL bState )
  2909. {
  2910. for ( CCISnapin * pCurrent = _pChild;
  2911. 0 != pCurrent;
  2912. pCurrent = pCurrent->Next() )
  2913. {
  2914. if ( !pCurrent->_xToolbar.IsNull() )
  2915. pCurrent->_xToolbar->SetButtonState( idCommand, nState, bState );
  2916. }
  2917. }
  2918. //+-------------------------------------------------------------------------
  2919. //
  2920. // Function: StartMenu
  2921. //
  2922. // Synopsis: Sets context menu for service started state.
  2923. //
  2924. // Arguments: [piCallback] -- Context menu callback routine
  2925. // [fTop] -- TRUE if menu items should be on top of list
  2926. // in addition to under Task section.
  2927. //
  2928. // History: 07-Jul-1998 KyleP Created
  2929. //
  2930. //--------------------------------------------------------------------------
  2931. SCODE StartMenu( IContextMenuCallback * piCallback, BOOL fTop )
  2932. {
  2933. aContextMenus[comidStartCI].fFlags =
  2934. aContextMenus[comidStartCITop].fFlags = MF_GRAYED;
  2935. aContextMenus[comidStopCI].fFlags =
  2936. aContextMenus[comidStopCITop].fFlags = MF_ENABLED;
  2937. aContextMenus[comidPauseCI].fFlags =
  2938. aContextMenus[comidPauseCITop].fFlags = MF_ENABLED;
  2939. return SetStartStopMenu( piCallback, fTop );
  2940. }
  2941. //+-------------------------------------------------------------------------
  2942. //
  2943. // Function: StopMenu
  2944. //
  2945. // Synopsis: Sets context menu for service stopped state.
  2946. //
  2947. // Arguments: [piCallback] -- Context menu callback routine
  2948. // [fTop] -- TRUE if menu items should be on top of list
  2949. // in addition to under Task section.
  2950. //
  2951. // History: 07-Jul-1998 KyleP Created
  2952. //
  2953. //--------------------------------------------------------------------------
  2954. SCODE StopMenu( IContextMenuCallback * piCallback, BOOL fTop )
  2955. {
  2956. aContextMenus[comidStartCI].fFlags =
  2957. aContextMenus[comidStartCITop].fFlags = MF_ENABLED;
  2958. aContextMenus[comidStopCI].fFlags =
  2959. aContextMenus[comidStopCITop].fFlags = MF_GRAYED;
  2960. aContextMenus[comidPauseCI].fFlags =
  2961. aContextMenus[comidPauseCITop].fFlags = MF_GRAYED;
  2962. return SetStartStopMenu( piCallback, fTop );
  2963. }
  2964. //+-------------------------------------------------------------------------
  2965. //
  2966. // Function: PauseMenu
  2967. //
  2968. // Synopsis: Sets context menu for service paused state.
  2969. //
  2970. // Arguments: [piCallback] -- Context menu callback routine
  2971. // [fTop] -- TRUE if menu items should be on top of list
  2972. // in addition to under Task section.
  2973. //
  2974. // History: 07-Jul-1998 KyleP Created
  2975. //
  2976. //--------------------------------------------------------------------------
  2977. SCODE PauseMenu( IContextMenuCallback * piCallback, BOOL fTop )
  2978. {
  2979. aContextMenus[comidStartCI].fFlags =
  2980. aContextMenus[comidStartCITop].fFlags = MF_ENABLED;
  2981. aContextMenus[comidStopCI].fFlags =
  2982. aContextMenus[comidStopCITop].fFlags = MF_ENABLED;
  2983. aContextMenus[comidPauseCI].fFlags =
  2984. aContextMenus[comidPauseCITop].fFlags = MF_GRAYED;
  2985. return SetStartStopMenu( piCallback, fTop );
  2986. }
  2987. //+-------------------------------------------------------------------------
  2988. //
  2989. // Function: DisabledMenu
  2990. //
  2991. // Synopsis: Disables start/stop/pause menu items
  2992. //
  2993. // Arguments: [piCallback] -- Context menu callback routine
  2994. // [fTop] -- TRUE if menu items should be on top of list
  2995. // in addition to under Task section.
  2996. //
  2997. // History: 07-Jul-1998 KyleP Created
  2998. //
  2999. //--------------------------------------------------------------------------
  3000. SCODE DisabledMenu( IContextMenuCallback * piCallback, BOOL fTop )
  3001. {
  3002. aContextMenus[comidStartCI].fFlags =
  3003. aContextMenus[comidStartCITop].fFlags = MF_GRAYED;
  3004. aContextMenus[comidStopCI].fFlags =
  3005. aContextMenus[comidStopCITop].fFlags = MF_GRAYED;
  3006. aContextMenus[comidPauseCI].fFlags =
  3007. aContextMenus[comidPauseCITop].fFlags = MF_GRAYED;
  3008. return SetStartStopMenu( piCallback, fTop );
  3009. }
  3010. //+-------------------------------------------------------------------------
  3011. //
  3012. // Function: SetStartStopMenu, private
  3013. //
  3014. // Synopsis: Worker routine to call menu callback and set menu items.
  3015. //
  3016. // Arguments: [piCallback] -- Context menu callback routine
  3017. // [fTop] -- TRUE if menu items should be on top of list
  3018. // in addition to under Task section.
  3019. //
  3020. // History: 07-Jul-1998 KyleP Created
  3021. //
  3022. //--------------------------------------------------------------------------
  3023. SCODE SetStartStopMenu( IContextMenuCallback * piCallback, BOOL fTop )
  3024. {
  3025. SCODE sc = S_OK;
  3026. if (SUCCEEDED(sc) && fTop)
  3027. piCallback->AddItem( &aContextMenus[comidStartCITop] );
  3028. if (SUCCEEDED(sc) && fTop)
  3029. sc = piCallback->AddItem( &aContextMenus[comidStopCITop] );
  3030. if (SUCCEEDED(sc) && fTop)
  3031. sc = piCallback->AddItem( &aContextMenus[comidPauseCITop] );
  3032. if (SUCCEEDED(sc))
  3033. sc = piCallback->AddItem( &aContextMenus[comidStartCI] );
  3034. if (SUCCEEDED(sc))
  3035. sc = piCallback->AddItem( &aContextMenus[comidStopCI] );
  3036. if (SUCCEEDED(sc))
  3037. sc = piCallback->AddItem( &aContextMenus[comidPauseCI] );
  3038. return sc;
  3039. }