Source code of Windows XP (NT5)
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.

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