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

2602 lines
92 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  5. //
  6. // File: result.cpp
  7. //
  8. // Contents: implementation of the result pane
  9. //
  10. // Classes: CResultPane
  11. //
  12. // History: 03-14-1998 stevebl Created
  13. // 05-20-1998 RahulTh Added drag-n-drop support for adding
  14. // packages
  15. //
  16. //---------------------------------------------------------------------------
  17. #include "precomp.hxx"
  18. #include <atlimpl.cpp>
  19. #include <wbemcli.h>
  20. #include "rsoputil.h"
  21. #include <list>
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. long CResultPane::lDataObjectRefCount = 0;
  28. // Internal private format
  29. const wchar_t* SNAPIN_INTERNAL = L"APPMGR_INTERNAL";
  30. #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0]))
  31. //+--------------------------------------------------------------------------
  32. //
  33. // Function: ExtractInternalFormat
  34. //
  35. // Synopsis: Returns a pointer to our private object format given an
  36. // LPDATAOBJECT
  37. //
  38. // Arguments: [lpDataObject] - pointer to a DATAOBJECT, generally from a
  39. // MMC call.
  40. //
  41. // Returns: A pointer to INTERNAL, our internal object structure.
  42. // NULL - if the object doesn't contain one of our objects
  43. // (wasn't created by us)
  44. //
  45. // History: 3-13-1998 stevebl Commented
  46. //
  47. //---------------------------------------------------------------------------
  48. INTERNAL* ExtractInternalFormat(LPDATAOBJECT lpDataObject)
  49. {
  50. INTERNAL* internal = NULL;
  51. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL };
  52. FORMATETC formatetc = { (CLIPFORMAT)CDataObject::m_cfInternal, NULL,
  53. DVASPECT_CONTENT, -1, TYMED_HGLOBAL
  54. };
  55. if (!lpDataObject)
  56. return NULL;
  57. // Allocate memory for the stream
  58. stgmedium.hGlobal = GlobalAlloc(GMEM_SHARE, sizeof(INTERNAL));
  59. // Attempt to get data from the object
  60. do
  61. {
  62. if (stgmedium.hGlobal == NULL)
  63. break;
  64. if (FAILED(lpDataObject->GetDataHere(&formatetc, &stgmedium)))
  65. break;
  66. internal = reinterpret_cast<INTERNAL*>(stgmedium.hGlobal);
  67. if (internal == NULL)
  68. break;
  69. } while (FALSE);
  70. return internal;
  71. }
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CResultPane's IComponent implementation
  74. STDMETHODIMP CResultPane::GetResultViewType(MMC_COOKIE cookie, BSTR* ppViewType, LONG * pViewOptions)
  75. {
  76. // Use default view
  77. return S_FALSE;
  78. }
  79. STDMETHODIMP CResultPane::Initialize(LPCONSOLE lpConsole)
  80. {
  81. ASSERT(lpConsole != NULL);
  82. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  83. // Save the IConsole pointer
  84. m_pConsole = lpConsole;
  85. m_pConsole->AddRef();
  86. m_szFolderTitle.LoadString(IDS_FOLDER_TITLE);
  87. // QI for a IHeaderCtrl
  88. HRESULT hr = m_pConsole->QueryInterface(IID_IHeaderCtrl,
  89. reinterpret_cast<void**>(&m_pHeader));
  90. // Give the console the header control interface pointer
  91. if (SUCCEEDED(hr))
  92. m_pConsole->SetHeader(m_pHeader);
  93. m_pConsole->QueryInterface(IID_IResultData,
  94. reinterpret_cast<void**>(&m_pResult));
  95. m_pConsole->QueryInterface(IID_IDisplayHelp,
  96. reinterpret_cast<void**>(&m_pDisplayHelp));
  97. hr = m_pConsole->QueryConsoleVerb(&m_pConsoleVerb);
  98. ASSERT(hr == S_OK);
  99. return S_OK;
  100. }
  101. STDMETHODIMP CResultPane::Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  102. {
  103. HRESULT hr = S_OK;
  104. MMC_COOKIE cookie;
  105. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  106. if (event == MMCN_PROPERTY_CHANGE)
  107. {
  108. hr = OnPropertyChange(param);
  109. }
  110. else if (event == MMCN_VIEW_CHANGE)
  111. {
  112. hr = OnUpdateView(lpDataObject);
  113. }
  114. else
  115. {
  116. //kluge for drag-n-drop through explorer. To enable drag-n-drop
  117. //through explorer, the paste verb is always enabled. since
  118. //it is also hidden (see OnSelect), the user cannot use the
  119. //standard toolbar to paste. However, if the user uses CTRL-V
  120. //to paste when nothing has been cut, Notify gets invoked with
  121. //a negative lpDataObject value, therefore, in that particular
  122. //case, we simply return with an S_OK -RahulTh 5/20/1998
  123. if ((LONG_PTR)lpDataObject <= 0)
  124. return S_OK;
  125. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  126. if (pInternal == NULL)
  127. {
  128. return E_UNEXPECTED;
  129. }
  130. else
  131. {
  132. cookie = pInternal->m_cookie;
  133. }
  134. switch(event)
  135. {
  136. case MMCN_COLUMNS_CHANGED:
  137. break;
  138. case MMCN_ACTIVATE:
  139. hr = OnActivate(cookie, arg, param);
  140. break;
  141. case MMCN_CLICK:
  142. hr = OnResultItemClkOrDblClk(cookie, FALSE);
  143. break;
  144. case MMCN_DBLCLICK:
  145. if (pInternal->m_type == CCT_RESULT)
  146. hr = OnResultItemClkOrDblClk(cookie, TRUE);
  147. else
  148. hr = S_FALSE;
  149. break;
  150. case MMCN_ADD_IMAGES:
  151. hr = OnAddImages(cookie, arg, param);
  152. break;
  153. case MMCN_SHOW:
  154. hr = OnShow(cookie, arg, param);
  155. break;
  156. case MMCN_MINIMIZED:
  157. hr = OnMinimize(cookie, arg, param);
  158. break;
  159. case MMCN_SELECT:
  160. hr = OnSelect(pInternal->m_type, cookie, arg, param);
  161. break;
  162. case MMCN_COLUMN_CLICK:
  163. // retain column number and sort option flags so we can pass
  164. // them in to sort in the event we need to trigger a resort of
  165. // the result pane
  166. m_nSortColumn = arg;
  167. m_dwSortOptions = param;
  168. break;
  169. case MMCN_DELETE:
  170. hr = Command(IDM_DEL_APP, lpDataObject);
  171. break;
  172. case MMCN_REFRESH:
  173. hr = Command(IDM_REFRESH, lpDataObject);
  174. break;
  175. case MMCN_QUERY_PASTE:
  176. //always return S_OK here because there is no way we can check
  177. //for the validity of the dragged objects here, so we simply
  178. //give the green signal and wait for the MMCN_PASTE notification
  179. //to see if the objects being dragged are valid at all.
  180. hr = S_OK;
  181. break;
  182. case MMCN_PASTE:
  183. if (arg > 0) //better be safe than sorry
  184. OnFileDrop ((LPDATAOBJECT)arg);
  185. hr = S_OK;
  186. break;
  187. case MMCN_CONTEXTHELP:
  188. if (m_pDisplayHelp)
  189. {
  190. if (m_pScopePane->m_fRSOP)
  191. {
  192. SHELLEXECUTEINFO ShellInfo;
  193. WCHAR pszHelpFilePath[ MAX_PATH ];
  194. memset( &ShellInfo, 0, sizeof( ShellInfo ) );
  195. ExpandEnvironmentStringsW (
  196. L"%SystemRoot%\\Help\\RSOPsnp.chm",
  197. pszHelpFilePath, MAX_PATH);
  198. ShellInfo.cbSize = sizeof( ShellInfo );
  199. ShellInfo.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_DOENVSUBST;
  200. ShellInfo.lpVerb = L"open";
  201. ShellInfo.lpFile = L"%SystemRoot%\\hh.exe";
  202. ShellInfo.lpParameters = pszHelpFilePath;
  203. ShellInfo.nShow = SW_SHOWNORMAL;
  204. (void) ShellExecuteEx( &ShellInfo );
  205. }
  206. else
  207. {
  208. m_pDisplayHelp->ShowTopic (L"gpedit.chm::/ADE.htm");
  209. }
  210. }
  211. break;
  212. // Note - Future expansion of notify types possible
  213. default:
  214. hr = E_UNEXPECTED;
  215. break;
  216. }
  217. FREE_INTERNAL(pInternal);
  218. }
  219. return hr;
  220. }
  221. STDMETHODIMP CResultPane::Destroy(MMC_COOKIE cookie)
  222. {
  223. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  224. DebugMsg((DM_VERBOSE, TEXT("CResultPane::Destroy this=%08x cookie=%u"), this, cookie));
  225. // Release the interfaces that we QI'ed
  226. if (m_pConsole != NULL)
  227. {
  228. // Tell the console to release the header control interface
  229. m_pConsole->SetHeader(NULL);
  230. SAFE_RELEASE(m_pHeader);
  231. SAFE_RELEASE(m_pResult);
  232. SAFE_RELEASE(m_pConsoleVerb);
  233. SAFE_RELEASE(m_pDisplayHelp);
  234. SAFE_RELEASE(m_pToolbar);
  235. SAFE_RELEASE(m_pControlbar);
  236. // Release the IConsole interface last
  237. SAFE_RELEASE(m_pConsole);
  238. if (m_pScopePane)
  239. {
  240. m_pScopePane->RemoveResultPane(this);
  241. ((IComponentData*)m_pScopePane)->Release(); // QI'ed in IComponentDataImpl::CreateComponent
  242. m_pScopePane = NULL;
  243. }
  244. }
  245. return S_OK;
  246. }
  247. STDMETHODIMP CResultPane::QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  248. LPDATAOBJECT* ppDataObject)
  249. {
  250. // Delegate it to the IComponentData
  251. ASSERT(m_pScopePane != NULL);
  252. return m_pScopePane->QueryDataObject(cookie, type, ppDataObject);
  253. }
  254. /////////////////////////////////////////////////////////////////////////////
  255. // CResultPane's implementation specific members
  256. DEBUG_DECLARE_INSTANCE_COUNTER(CResultPane);
  257. CResultPane::CResultPane()
  258. {
  259. #if DBG
  260. dbg_cRef = 0;
  261. #endif
  262. DEBUG_INCREMENT_INSTANCE_COUNTER(CResultPane);
  263. DebugMsg((DM_VERBOSE, TEXT("CResultPane::CResultPane this=%08x ref=%u"), this, dbg_cRef));
  264. CResultPane::lDataObjectRefCount = 0;
  265. m_pDisplayHelp = NULL;
  266. m_lViewMode = LVS_REPORT;
  267. BOOL _fVisible = FALSE;
  268. m_nSortColumn = 0;
  269. m_dwSortOptions = 0;
  270. Construct();
  271. }
  272. CResultPane::~CResultPane()
  273. {
  274. #if DBG
  275. ASSERT(dbg_cRef == 0);
  276. #endif
  277. DebugMsg((DM_VERBOSE, TEXT("CResultPane::~CResultPane this=%08x ref=%u"), this, dbg_cRef));
  278. DEBUG_DECREMENT_INSTANCE_COUNTER(CResultPane);
  279. // Make sure the interfaces have been released
  280. ASSERT(m_pConsole == NULL);
  281. ASSERT(m_pHeader == NULL);
  282. Construct();
  283. ASSERT(CResultPane::lDataObjectRefCount == 0);
  284. }
  285. void CResultPane::Construct()
  286. {
  287. #if DBG
  288. dbg_cRef = 0;
  289. #endif
  290. m_pConsole = NULL;
  291. m_pHeader = NULL;
  292. m_pResult = NULL;
  293. m_pScopePane = NULL;
  294. m_pControlbar = NULL;
  295. m_pToolbar = NULL;
  296. }
  297. CString szExtension;
  298. CString szFilter;
  299. HRESULT CResultPane::InitializeHeaders(MMC_COOKIE cookie)
  300. {
  301. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  302. HRESULT hr = S_OK;
  303. ASSERT(m_pHeader);
  304. CString sz;
  305. sz.LoadString(IDS_NAME);
  306. if (m_pScopePane->m_fRSOP)
  307. {
  308. // in RSOP mode the name follows the name for the view
  309. }
  310. int n = 0;
  311. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, 150); // name
  312. sz.LoadString(IDS_VERSION);
  313. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, 50); // version
  314. sz.LoadString(IDS_STATE);
  315. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, 100); // state
  316. sz.LoadString(IDS_AUTOINST);
  317. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN /*75*/); // auto-inst
  318. sz.LoadString(IDS_SOURCE);
  319. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, 200); // source
  320. sz.LoadString(IDS_MODS);
  321. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN); // mods
  322. sz.LoadString(IDS_LOC);
  323. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN); // loc
  324. sz.LoadString(IDS_OOSUNINST);
  325. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN);
  326. sz.LoadString(IDS_SHOWARP);
  327. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN);
  328. sz.LoadString(IDS_UITYPE);
  329. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN);
  330. sz.LoadString(IDS_IGNORELOC);
  331. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN);
  332. sz.LoadString(IDS_REMPREV);
  333. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN);
  334. sz.LoadString(IDS_PRODCODE);
  335. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN);
  336. sz.LoadString(IDS_STAGE);
  337. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN); // stage
  338. sz.LoadString(IDS_RELATION);
  339. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN); // Upgrading
  340. sz.LoadString(IDS_UPGRADEDBY);
  341. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN);
  342. sz.LoadString(IDS_SCRIPT);
  343. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN);
  344. sz.LoadString(IDS_MACH);
  345. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN);
  346. sz.LoadString(IDS_X86ONWIN64);
  347. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN);
  348. sz.LoadString(IDS_FULLINSTALL);
  349. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN);
  350. if (m_pScopePane->m_fRSOP)
  351. {
  352. sz.LoadString(IDS_ORIGIN);
  353. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, 150); // origin
  354. sz.LoadString(IDS_SOM);
  355. m_pHeader->InsertColumn(n++, sz, LVCFMT_LEFT, HIDE_COLUMN); // origin
  356. }
  357. return hr;
  358. }
  359. /////////////////////////////////////////////////////////////////////////////
  360. // IExtendContextMenu Implementation
  361. STDMETHODIMP CResultPane::AddMenuItems(LPDATAOBJECT pDataObject,
  362. LPCONTEXTMENUCALLBACK pContextMenuCallback, LONG * pInsertionAllowed)
  363. {
  364. return m_pScopePane->
  365. AddMenuItems(pDataObject, pContextMenuCallback, pInsertionAllowed);
  366. }
  367. STDMETHODIMP CResultPane::Command(long nCommandID, LPDATAOBJECT pDataObject)
  368. {
  369. if (m_pScopePane)
  370. return m_pScopePane->
  371. Command(nCommandID, pDataObject);
  372. else
  373. return S_OK;
  374. }
  375. HRESULT CResultPane::OnAddImages(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  376. {
  377. if (arg == 0)
  378. {
  379. return E_INVALIDARG;
  380. }
  381. // add the images for the scope tree
  382. CBitmap bmp16x16;
  383. CBitmap bmp32x32;
  384. LPIMAGELIST lpScopeImage = (LPIMAGELIST)arg;
  385. // Load the bitmaps from the dll
  386. bmp16x16.LoadBitmap(IDB_16x16);
  387. bmp32x32.LoadBitmap(IDB_32x32);
  388. // Set the images
  389. lpScopeImage->ImageListSetStrip(reinterpret_cast<LONG_PTR *>(static_cast<HBITMAP>(bmp16x16)),
  390. reinterpret_cast<LONG_PTR *>(static_cast<HBITMAP>(bmp32x32)),
  391. 0, RGB(255,0,255));
  392. return S_OK;
  393. }
  394. /////////////////////////////////////////////////////////////////////////////
  395. // IExtendPropertySheet Implementation
  396. // Result item property pages:
  397. STDMETHODIMP CResultPane::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  398. LONG_PTR handle,
  399. LPDATAOBJECT lpIDataObject)
  400. {
  401. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  402. INTERNAL* pInternal = ExtractInternalFormat(lpIDataObject);
  403. if (pInternal && (m_pScopePane->m_fRSOP || m_pScopePane->m_pIClassAdmin))
  404. {
  405. HRESULT hr = S_OK;
  406. MMC_COOKIE cookie = pInternal->m_cookie;
  407. CAppData & data = m_pScopePane->m_AppData[cookie];
  408. FREE_INTERNAL(pInternal);
  409. HPROPSHEETPAGE hSecurity = NULL;
  410. LPSECURITYINFO pSI = NULL;
  411. //
  412. // make sure we have an up-to-date categories list
  413. //
  414. m_pScopePane->ClearCategories();
  415. if (m_pScopePane->m_fRSOP)
  416. {
  417. m_pScopePane->GetRSoPCategories();
  418. }
  419. else
  420. {
  421. hr = CsGetAppCategories(&m_pScopePane->m_CatList);
  422. if (FAILED(hr))
  423. {
  424. // report it
  425. LogADEEvent(EVENTLOG_ERROR_TYPE, EVENT_ADE_GETCATEGORIES_ERROR, hr, NULL);
  426. // Since failure only means the categories list will be
  427. // empty, we'll proceed as if nothing happened.
  428. hr = S_OK;
  429. }
  430. }
  431. //
  432. // prepare the security property page
  433. //
  434. // check to make sure that we have access to this object
  435. if (m_pScopePane->m_fRSOP)
  436. {
  437. pSI = new CRSOPSecurityInfo(&data);
  438. }
  439. else
  440. {
  441. CString szPath;
  442. hr = m_pScopePane->GetPackageDSPath(szPath, data.m_pDetails->pszPackageName);
  443. if (SUCCEEDED(hr))
  444. {
  445. hr = DSCreateISecurityInfoObject(szPath,
  446. NULL,
  447. 0,
  448. &pSI,
  449. NULL,
  450. NULL,
  451. 0);
  452. }
  453. }
  454. if (FAILED(hr))
  455. {
  456. // we don't have access to this object (probably due to permissions)
  457. DebugMsg((DM_WARNING, TEXT("DSCreateISecurityInfoObject failed with 0x%x"), hr));
  458. // force a refresh
  459. hr = Command(IDM_REFRESH, lpIDataObject);
  460. // DON'T quit just because we couldn't create the security page!
  461. // return S_FALSE;
  462. }
  463. if (pSI)
  464. {
  465. hSecurity = CreateSecurityPage(pSI);
  466. pSI->Release();
  467. if (hSecurity == NULL)
  468. return E_UNEXPECTED;
  469. }
  470. // we have access
  471. //
  472. // Create the Product property page
  473. //
  474. data.m_pProduct = new CProduct();
  475. data.m_pProduct->m_ppThis = &data.m_pProduct;
  476. data.m_pProduct->m_pData = &data;
  477. data.m_pProduct->m_cookie = cookie;
  478. data.m_pProduct->m_hConsoleHandle = handle;
  479. data.m_pProduct->m_pScopePane = m_pScopePane;
  480. data.m_pProduct->m_pAppData = &m_pScopePane->m_AppData;
  481. data.m_pProduct->m_pIGPEInformation = m_pScopePane->m_pIGPEInformation;
  482. data.m_pProduct->m_fMachine = m_pScopePane->m_fMachine;
  483. data.m_pProduct->m_fRSOP = m_pScopePane->m_fRSOP;
  484. // no longer need to marshal, just set it
  485. if (!m_pScopePane->m_fRSOP)
  486. {
  487. data.m_pProduct->m_pIClassAdmin = m_pScopePane->m_pIClassAdmin;
  488. data.m_pProduct->m_pIClassAdmin->AddRef();
  489. }
  490. else
  491. data.m_pProduct->m_pIClassAdmin = NULL;
  492. hr = SetPropPageToDeleteOnClose(&data.m_pProduct->m_psp);
  493. if (SUCCEEDED(hr))
  494. {
  495. HPROPSHEETPAGE hProduct = CreateThemedPropertySheetPage(&data.m_pProduct->m_psp);
  496. if (hProduct == NULL)
  497. return E_UNEXPECTED;
  498. lpProvider->AddPage(hProduct);
  499. }
  500. //
  501. // Create the Depeployment property page
  502. //
  503. data.m_pDeploy = new CDeploy();
  504. data.m_pDeploy->m_ppThis = &data.m_pDeploy;
  505. data.m_pDeploy->m_pData = &data;
  506. data.m_pDeploy->m_cookie = cookie;
  507. data.m_pDeploy->m_hConsoleHandle = handle;
  508. data.m_pDeploy->m_fMachine = m_pScopePane->m_fMachine;
  509. data.m_pDeploy->m_fRSOP = m_pScopePane->m_fRSOP;
  510. data.m_pDeploy->m_pScopePane = m_pScopePane;
  511. #if 0
  512. data.m_pDeploy->m_pIGPEInformation = m_pScopePane->m_pIGPEInformation;
  513. #endif
  514. // no longer need to marsahl this interface, just set it
  515. if (!m_pScopePane->m_fRSOP)
  516. {
  517. data.m_pDeploy->m_pIClassAdmin = m_pScopePane->m_pIClassAdmin;
  518. data.m_pDeploy->m_pIClassAdmin->AddRef();
  519. }
  520. else
  521. data.m_pDeploy->m_pIClassAdmin = NULL;
  522. hr = SetPropPageToDeleteOnClose(&data.m_pDeploy->m_psp);
  523. if (SUCCEEDED(hr))
  524. {
  525. HPROPSHEETPAGE hDeploy = CreateThemedPropertySheetPage(&data.m_pDeploy->m_psp);
  526. if (hDeploy == NULL)
  527. {
  528. return E_UNEXPECTED;
  529. }
  530. lpProvider->AddPage(hDeploy);
  531. }
  532. if (data.m_pDetails->pInstallInfo->PathType != SetupNamePath)
  533. {
  534. //
  535. // Create the upgrades property page
  536. //
  537. data.m_pUpgradeList = new CUpgradeList();
  538. data.m_pUpgradeList->m_ppThis = &data.m_pUpgradeList;
  539. data.m_pUpgradeList->m_pData = &data;
  540. data.m_pUpgradeList->m_cookie = cookie;
  541. data.m_pUpgradeList->m_hConsoleHandle = handle;
  542. data.m_pUpgradeList->m_pScopePane = m_pScopePane;
  543. data.m_pUpgradeList->m_fMachine = m_pScopePane->m_fMachine;
  544. data.m_pUpgradeList->m_fRSOP = m_pScopePane->m_fRSOP;
  545. #if 0
  546. data.m_pUpgradeList->m_pIGPEInformation = m_pScopePane->m_pIGPEInformation;
  547. #endif
  548. // no longer need to marshal this interface, just set it
  549. if (!m_pScopePane->m_fRSOP)
  550. {
  551. data.m_pUpgradeList->m_pIClassAdmin = m_pScopePane->m_pIClassAdmin;
  552. data.m_pUpgradeList->m_pIClassAdmin->AddRef();
  553. }
  554. else
  555. data.m_pUpgradeList->m_pIClassAdmin = NULL;
  556. hr = SetPropPageToDeleteOnClose(&data.m_pUpgradeList->m_psp);
  557. if (SUCCEEDED(hr))
  558. {
  559. HPROPSHEETPAGE hUpgradeList = CreateThemedPropertySheetPage(&data.m_pUpgradeList->m_psp);
  560. if (hUpgradeList == NULL)
  561. {
  562. return E_UNEXPECTED;
  563. }
  564. lpProvider->AddPage(hUpgradeList);
  565. }
  566. }
  567. //
  568. // Create the Category property page
  569. //
  570. if ( ! m_pScopePane->m_fRSOP || ( IDM_ARP == m_pScopePane->m_iViewState ) )
  571. {
  572. data.m_pCategory = new CCategory();
  573. data.m_pCategory->m_ppThis = &data.m_pCategory;
  574. data.m_pCategory->m_pData = &data;
  575. data.m_pCategory->m_cookie = cookie;
  576. data.m_pCategory->m_hConsoleHandle = handle;
  577. data.m_pCategory->m_pCatList = &m_pScopePane->m_CatList;
  578. data.m_pCategory->m_fRSOP = m_pScopePane->m_fRSOP;
  579. // no longer need to marshal this interface, just set it
  580. if (!m_pScopePane->m_fRSOP)
  581. {
  582. data.m_pCategory->m_pIClassAdmin = m_pScopePane->m_pIClassAdmin;
  583. data.m_pCategory->m_pIClassAdmin->AddRef();
  584. }
  585. else
  586. data.m_pCategory->m_pIClassAdmin = NULL;
  587. hr = SetPropPageToDeleteOnClose(&data.m_pCategory->m_psp);
  588. if (SUCCEEDED(hr))
  589. {
  590. HPROPSHEETPAGE hCategory = CreateThemedPropertySheetPage(&data.m_pCategory->m_psp);
  591. if (hCategory == NULL)
  592. {
  593. return E_UNEXPECTED;
  594. }
  595. lpProvider->AddPage(hCategory);
  596. }
  597. }
  598. if (data.m_pDetails->pInstallInfo->PathType != SetupNamePath)
  599. {
  600. //
  601. // Create the Xforms property page
  602. //
  603. data.m_pXforms = new CXforms();
  604. data.m_pXforms->m_ppThis = &data.m_pXforms;
  605. data.m_pXforms->m_pData = &data;
  606. data.m_pXforms->m_cookie = cookie;
  607. data.m_pXforms->m_hConsoleHandle = handle;
  608. data.m_pXforms->m_pScopePane = m_pScopePane;
  609. // marshal the IClassAdmin interface to the page
  610. if (!m_pScopePane->m_fRSOP)
  611. {
  612. data.m_pXforms->m_pIClassAdmin = m_pScopePane->m_pIClassAdmin;
  613. data.m_pXforms->m_pIClassAdmin->AddRef();
  614. }
  615. else
  616. data.m_pXforms->m_pIClassAdmin = NULL;
  617. hr = SetPropPageToDeleteOnClose(&data.m_pXforms->m_psp);
  618. if (SUCCEEDED(hr))
  619. {
  620. HPROPSHEETPAGE hXforms = CreateThemedPropertySheetPage(&data.m_pXforms->m_psp);
  621. if (hXforms == NULL)
  622. {
  623. return E_UNEXPECTED;
  624. }
  625. lpProvider->AddPage(hXforms);
  626. }
  627. }
  628. //
  629. // Add the security property page
  630. //
  631. if (hSecurity)
  632. {
  633. lpProvider->AddPage(hSecurity);
  634. }
  635. if (m_pScopePane->m_fRSOP)
  636. {
  637. // add precedence pane
  638. data.m_pPrecedence = new CPrecedence();
  639. data.m_pPrecedence->m_ppThis = &data.m_pPrecedence;
  640. data.m_pPrecedence->m_szRSOPNamespace = m_pScopePane->m_szRSOPNamespace;
  641. data.m_pPrecedence->m_pData = &data;
  642. data.m_pPrecedence->m_iViewState = m_pScopePane->m_iViewState;
  643. hr = SetPropPageToDeleteOnClose(&data.m_pPrecedence->m_psp);
  644. if (SUCCEEDED(hr))
  645. {
  646. HPROPSHEETPAGE hPrecedence = CreateThemedPropertySheetPage(&data.m_pPrecedence->m_psp);
  647. if (hPrecedence == NULL)
  648. {
  649. return E_UNEXPECTED;
  650. }
  651. lpProvider->AddPage(hPrecedence);
  652. }
  653. if (m_pScopePane->m_iViewState != IDM_ARP)
  654. {
  655. // add Cause pane
  656. data.m_pCause = new CCause();
  657. data.m_pCause->m_ppThis = &data.m_pCause;
  658. data.m_pCause->m_pData = &data;
  659. data.m_pCause->m_fRemovedView = IDM_REMOVED == m_pScopePane->m_iViewState;
  660. hr = SetPropPageToDeleteOnClose(&data.m_pCause->m_psp);
  661. if (SUCCEEDED(hr))
  662. {
  663. HPROPSHEETPAGE hCause = CreateThemedPropertySheetPage(&data.m_pCause->m_psp);
  664. if (hCause == NULL)
  665. {
  666. return E_UNEXPECTED;
  667. }
  668. lpProvider->AddPage(hCause);
  669. }
  670. }
  671. // check for failed settings and add the error pane if necessary
  672. if (data.m_nStatus == 3)
  673. {
  674. data.m_pErrorInfo = new CErrorInfo();
  675. data.m_pErrorInfo->m_ppThis = &data.m_pErrorInfo;
  676. data.m_pErrorInfo->m_pData = &data;
  677. hr = SetPropPageToDeleteOnClose(&data.m_pErrorInfo->m_psp);
  678. if (SUCCEEDED(hr))
  679. {
  680. HPROPSHEETPAGE hErrorInfo = CreateThemedPropertySheetPage(&data.m_pErrorInfo->m_psp);
  681. if (hErrorInfo == NULL)
  682. {
  683. return E_UNEXPECTED;
  684. }
  685. lpProvider->AddPage(hErrorInfo);
  686. }
  687. }
  688. }
  689. if (m_pScopePane->m_ToolDefaults.fShowPkgDetails)
  690. {
  691. //
  692. // Create the Package Details page (debug only)
  693. //
  694. data.m_pPkgDetails = new CPackageDetails();
  695. data.m_pPkgDetails->m_ppThis = &data.m_pPkgDetails;
  696. data.m_pPkgDetails->m_hConsoleHandle = handle;
  697. data.m_pPkgDetails->m_pData = &data;
  698. hr = SetPropPageToDeleteOnClose(&data.m_pPkgDetails->m_psp);
  699. if (SUCCEEDED(hr))
  700. {
  701. HPROPSHEETPAGE hDetails = CreateThemedPropertySheetPage(&data.m_pPkgDetails->m_psp);
  702. if (hDetails == NULL)
  703. return E_UNEXPECTED;
  704. lpProvider->AddPage(hDetails);
  705. }
  706. }
  707. }
  708. else
  709. return S_FALSE;
  710. return S_OK;
  711. }
  712. // Result items property pages:
  713. STDMETHODIMP CResultPane::QueryPagesFor(LPDATAOBJECT lpDataObject)
  714. {
  715. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  716. // Look at the data object and see if it an item that we want to have a property sheet
  717. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  718. if (pInternal)
  719. {
  720. if (CCT_RESULT == pInternal->m_type)
  721. {
  722. FREE_INTERNAL(pInternal);
  723. return S_OK;
  724. }
  725. FREE_INTERNAL(pInternal);
  726. }
  727. return S_FALSE;
  728. }
  729. STDMETHODIMP CResultPane::CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB)
  730. {
  731. if (lpDataObjectA == NULL || lpDataObjectB == NULL)
  732. return E_POINTER;
  733. // Make sure both data object are mine
  734. INTERNAL* pA;
  735. INTERNAL* pB;
  736. HRESULT hr = S_FALSE;
  737. pA = ExtractInternalFormat(lpDataObjectA);
  738. pB = ExtractInternalFormat(lpDataObjectB);
  739. if (pA != NULL && pB != NULL)
  740. hr = ((pA->m_type == pB->m_type) && (pA->m_cookie == pB->m_cookie)) ? S_OK : S_FALSE;
  741. FREE_INTERNAL(pA);
  742. FREE_INTERNAL(pB);
  743. return hr;
  744. }
  745. STDMETHODIMP CResultPane::SetControlbar(LPCONTROLBAR pControlbar)
  746. {
  747. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  748. HRESULT hr = S_OK;
  749. if (m_pToolbar)
  750. {
  751. SAFE_RELEASE(m_pToolbar);
  752. }
  753. if (m_pControlbar)
  754. {
  755. SAFE_RELEASE(m_pControlbar);
  756. }
  757. if (pControlbar && m_pScopePane->m_fRSOP)
  758. {
  759. m_pControlbar = pControlbar;
  760. m_pControlbar->AddRef();
  761. hr = m_pControlbar->Create(TOOLBAR,
  762. dynamic_cast<IExtendControlbar *>(this),
  763. reinterpret_cast<IUnknown **>(&m_pToolbar));
  764. DebugReportFailure(hr, (DM_WARNING, TEXT("SetControlBar: Create failed with 0x%x"), hr));
  765. if (FAILED(hr))
  766. {
  767. return hr;
  768. }
  769. m_pToolbar->AddRef();
  770. // add the bitmap
  771. CBitmap bmp;
  772. if (!bmp.LoadBitmap(IDB_TOOLBAR1))
  773. {
  774. DebugReportFailure(hr, (DM_WARNING, TEXT("SetControlBar: LoadBitmap failed with 0x%x"), GetLastError()));
  775. return E_FAIL;
  776. }
  777. hr = m_pToolbar->AddBitmap(3,
  778. bmp,
  779. 16,
  780. 16,
  781. RGB(255, 0, 255));
  782. DebugReportFailure(hr, (DM_WARNING, TEXT("SetControlBar: AddBitmap failed with 0x%x"), hr));
  783. if (FAILED(hr))
  784. {
  785. return hr;
  786. }
  787. // add the buttons depending upon our state
  788. CString szText;
  789. CString szTooltipText;
  790. int i = 0;
  791. MMCBUTTON stButton;
  792. stButton.nBitmap = 0;
  793. stButton.idCommand = IDM_WINNER;
  794. stButton.fsState = TBSTATE_ENABLED | ( m_pScopePane->m_iViewState == IDM_WINNER ? TBSTATE_PRESSED : 0 );
  795. stButton.fsType = BTNS_GROUP;
  796. szText.LoadString(IDS_WIN_TEXT);
  797. szTooltipText.LoadString(IDS_WIN_TOOLTEXT);
  798. stButton.lpButtonText = (LPOLESTR)((LPCWSTR) szText);
  799. stButton.lpTooltipText = (LPOLESTR)((LPCWSTR) szTooltipText);
  800. hr = m_pToolbar->InsertButton(i++, &stButton);
  801. DebugReportFailure(hr, (DM_WARNING, TEXT("SetControlBar: InsertButton failed with 0x%x"), hr));
  802. if ((m_pScopePane->m_dwRSOPFlags & RSOP_INFO_FLAG_DIAGNOSTIC_MODE) == RSOP_INFO_FLAG_DIAGNOSTIC_MODE)
  803. {
  804. // removed packages only apply in diagnostic mode
  805. stButton.nBitmap = 1;
  806. stButton.idCommand = IDM_REMOVED;
  807. stButton.fsState = TBSTATE_ENABLED | ( m_pScopePane->m_iViewState == IDM_REMOVED ? TBSTATE_PRESSED : 0 );;
  808. szText.LoadString(IDS_REM_TEXT);
  809. szTooltipText.LoadString(IDS_REM_TOOLTEXT);
  810. stButton.lpButtonText = (LPOLESTR)((LPCWSTR) szText);
  811. stButton.lpTooltipText = (LPOLESTR)((LPCWSTR) szTooltipText);
  812. hr = m_pToolbar->InsertButton(i++, &stButton);
  813. DebugReportFailure(hr, (DM_WARNING, TEXT("SetControlBar: InsertButton failed with 0x%x"), hr));
  814. }
  815. if (!m_pScopePane->m_fMachine)
  816. {
  817. // ARP packages only apply to users
  818. stButton.nBitmap = 2;
  819. stButton.idCommand = IDM_ARP;
  820. stButton.fsState = TBSTATE_ENABLED | ( m_pScopePane->m_iViewState == IDM_ARP ? TBSTATE_PRESSED : 0 );;
  821. szText.LoadString(IDS_ARP_TEXT);
  822. szTooltipText.LoadString(IDS_ARP_TOOLTEXT);
  823. stButton.lpButtonText = (LPOLESTR)((LPCWSTR) szText);
  824. stButton.lpTooltipText = (LPOLESTR)((LPCWSTR) szTooltipText);
  825. hr = m_pToolbar->InsertButton(i++, &stButton);
  826. DebugReportFailure(hr, (DM_WARNING, TEXT("SetControlBar: InsertButton failed with 0x%x"), hr));
  827. }
  828. }
  829. return hr;
  830. }
  831. STDMETHODIMP CResultPane::ControlbarNotify(MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  832. {
  833. HRESULT hr = S_OK;
  834. if (m_pControlbar)
  835. {
  836. if (event == MMCN_SELECT)
  837. {
  838. if (HIWORD(arg)) // is it selected or not
  839. {
  840. hr = m_pControlbar->Attach(TOOLBAR,
  841. m_pToolbar);
  842. DebugReportFailure(hr, (DM_WARNING, TEXT("ControlBarNotify: Attach failed with 0x%x"), hr));
  843. }
  844. else if ( (BOOL) LOWORD(arg) )
  845. {
  846. hr = m_pControlbar->Detach(m_pToolbar);
  847. DebugReportFailure(hr, (DM_WARNING, TEXT("ControlBarNotify: Detach failed with 0x%x"), hr));
  848. }
  849. }
  850. else if (event == MMCN_BTN_CLICK)
  851. {
  852. hr = Command(param, reinterpret_cast<IDataObject *>(arg));
  853. DebugReportFailure(hr, (DM_WARNING, TEXT("ControlBarNotify: Command failed with 0x%x"), hr));
  854. }
  855. }
  856. return hr;
  857. }
  858. STDMETHODIMP CResultPane::Compare(LPARAM lUserParam, MMC_COOKIE cookieA, MMC_COOKIE cookieB, int* pnResult)
  859. {
  860. if (pnResult == NULL)
  861. {
  862. ASSERT(FALSE);
  863. return E_POINTER;
  864. }
  865. // check col range
  866. int nCol = *pnResult;
  867. *pnResult = 0;
  868. CAppData & dataA = m_pScopePane->m_AppData[cookieA];
  869. CAppData & dataB = m_pScopePane->m_AppData[cookieB];
  870. // compare the two based on column and the cookies
  871. CString szA, szB;
  872. switch (nCol)
  873. {
  874. case 0:
  875. szA = dataA.m_pDetails->pszPackageName;
  876. szB = dataB.m_pDetails->pszPackageName;
  877. break;
  878. case 1:
  879. dataA.GetSzVersion(szA);
  880. dataB.GetSzVersion(szB);
  881. break;
  882. case 2:
  883. dataA.GetSzDeployment(szA);
  884. dataB.GetSzDeployment(szB);
  885. break;
  886. case 3:
  887. dataA.GetSzAutoInstall(szA);
  888. dataB.GetSzAutoInstall(szB);
  889. break;
  890. case 4:
  891. dataA.GetSzSource(szA);
  892. dataB.GetSzSource(szB);
  893. break;
  894. case 5:
  895. dataA.GetSzMods(szA);
  896. dataB.GetSzMods(szB);
  897. break;
  898. case 6:
  899. dataA.GetSzLocale(szA);
  900. dataB.GetSzLocale(szB);
  901. break;
  902. case 7:
  903. dataA.GetSzOOSUninstall(szA);
  904. dataB.GetSzOOSUninstall(szB);
  905. break;
  906. case 8:
  907. dataA.GetSzShowARP(szA);
  908. dataB.GetSzShowARP(szB);
  909. break;
  910. case 9:
  911. dataA.GetSzUIType(szA);
  912. dataB.GetSzUIType(szB);
  913. break;
  914. case 10:
  915. dataA.GetSzIgnoreLoc(szA);
  916. dataB.GetSzIgnoreLoc(szB);
  917. break;
  918. case 11:
  919. dataA.GetSzRemovePrev(szA);
  920. dataB.GetSzRemovePrev(szB);
  921. break;
  922. case 12:
  923. dataA.GetSzProductCode(szA);
  924. dataB.GetSzProductCode(szB);
  925. break;
  926. case 13:
  927. dataA.GetSzStage(szA);
  928. dataB.GetSzStage(szB);
  929. break;
  930. case 14:
  931. dataA.GetSzUpgrades(szA, m_pScopePane);
  932. dataB.GetSzUpgrades(szB, m_pScopePane);
  933. break;
  934. case 15:
  935. dataA.GetSzUpgradedBy(szA, m_pScopePane);
  936. dataB.GetSzUpgradedBy(szB, m_pScopePane);
  937. break;
  938. case 16:
  939. szA = dataA.m_pDetails->pInstallInfo->pszScriptPath;
  940. szB = dataB.m_pDetails->pInstallInfo->pszScriptPath;
  941. break;
  942. case 17:
  943. dataA.GetSzPlatform(szA);
  944. dataB.GetSzPlatform(szB);
  945. break;
  946. case 18:
  947. dataA.GetSzX86OnWin64(szA);
  948. dataB.GetSzX86OnWin64(szB);
  949. break;
  950. case 19:
  951. dataA.GetSzFullInstall(szA);
  952. dataB.GetSzFullInstall(szB);
  953. break;
  954. case 20: // only valid in rsop
  955. dataA.GetSzOrigin(szA);
  956. dataB.GetSzOrigin(szB);
  957. break;
  958. case 21: // only valid in rsop
  959. dataA.GetSzSOM(szA);
  960. dataB.GetSzSOM(szB);
  961. break;
  962. }
  963. *pnResult = szA.CompareNoCase(szB);
  964. return S_OK;
  965. }
  966. STDMETHODIMP CResultPane::GetDisplayInfo(LPRESULTDATAITEM pResult)
  967. {
  968. static CString sz;
  969. ASSERT(pResult != NULL);
  970. if (pResult)
  971. {
  972. if (pResult->lParam == -1)
  973. {
  974. switch (pResult->nCol)
  975. {
  976. case 0:
  977. pResult->str = (unsigned short *)((LPCOLESTR)m_szFolderTitle);
  978. break;
  979. default:
  980. pResult->str = (BSTR)_T("");
  981. break;
  982. }
  983. }
  984. else
  985. {
  986. map<MMC_COOKIE, CAppData>::iterator i = m_pScopePane->m_AppData.find(pResult->lParam);
  987. if (i != m_pScopePane->m_AppData.end())
  988. {
  989. CAppData & data = i->second;
  990. switch (pResult->nCol)
  991. {
  992. case 0:
  993. sz = data.m_pDetails->pszPackageName;
  994. break;
  995. case 1:
  996. data.GetSzVersion(sz);
  997. break;
  998. case 2:
  999. data.GetSzDeployment(sz);
  1000. break;
  1001. case 3:
  1002. data.GetSzAutoInstall(sz);
  1003. break;
  1004. case 4:
  1005. data.GetSzSource(sz);
  1006. break;
  1007. case 5:
  1008. data.GetSzMods(sz);
  1009. break;
  1010. case 6:
  1011. data.GetSzLocale(sz);
  1012. break;
  1013. case 7:
  1014. data.GetSzOOSUninstall(sz);
  1015. break;
  1016. case 8:
  1017. data.GetSzShowARP(sz);
  1018. break;
  1019. case 9:
  1020. data.GetSzUIType(sz);
  1021. break;
  1022. case 10:
  1023. data.GetSzIgnoreLoc(sz);
  1024. break;
  1025. case 11:
  1026. data.GetSzRemovePrev(sz);
  1027. break;
  1028. case 12:
  1029. data.GetSzProductCode(sz);
  1030. break;
  1031. case 13:
  1032. data.GetSzStage(sz);
  1033. break;
  1034. case 14:
  1035. data.GetSzUpgrades(sz, m_pScopePane);
  1036. break;
  1037. case 15:
  1038. data.GetSzUpgradedBy(sz, m_pScopePane);
  1039. break;
  1040. case 16:
  1041. sz = data.m_pDetails->pInstallInfo->pszScriptPath;
  1042. break;
  1043. case 17:
  1044. data.GetSzPlatform(sz);
  1045. break;
  1046. case 18:
  1047. data.GetSzX86OnWin64(sz);
  1048. break;
  1049. case 19:
  1050. data.GetSzFullInstall(sz);
  1051. break;
  1052. case 20:
  1053. data.GetSzOrigin(sz);
  1054. break;
  1055. case 21:
  1056. data.GetSzSOM(sz);
  1057. break;
  1058. default:
  1059. sz = "";
  1060. break;
  1061. }
  1062. pResult->str = (unsigned short *)((LPCOLESTR)sz);
  1063. }
  1064. }
  1065. }
  1066. return S_OK;
  1067. }
  1068. HRESULT CResultPane::OnFolder(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  1069. {
  1070. ASSERT(FALSE);
  1071. return S_OK;
  1072. }
  1073. HRESULT CResultPane::OnShow(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  1074. {
  1075. HRESULT hr = S_OK;
  1076. _fVisible = (BOOL)arg;
  1077. // Note - arg is TRUE when it is time to enumerate
  1078. if (arg == TRUE)
  1079. {
  1080. // Show the headers for this nodetype
  1081. ASSERT(m_pScopePane != NULL);
  1082. InitializeHeaders(cookie);
  1083. m_pResult->SetViewMode(m_lViewMode);
  1084. if (m_pScopePane->m_fRSOP || m_pScopePane->m_pIClassAdmin)
  1085. {
  1086. // if there's no IClassAdmin then there's nothing to enumerate
  1087. // unless we're in RSOP mode
  1088. Enumerate(cookie, param);
  1089. }
  1090. }
  1091. else
  1092. {
  1093. m_pResult->GetViewMode(&m_lViewMode);
  1094. }
  1095. return hr;
  1096. }
  1097. HRESULT CResultPane::OnActivate(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  1098. {
  1099. return S_OK;
  1100. }
  1101. HRESULT CResultPane::OnResultItemClkOrDblClk(MMC_COOKIE cookie, BOOL fDblClick)
  1102. {
  1103. return S_FALSE;
  1104. }
  1105. HRESULT CResultPane::OnMinimize(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  1106. {
  1107. return S_OK;
  1108. }
  1109. HRESULT CResultPane::OnSelect(DATA_OBJECT_TYPES type, MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  1110. {
  1111. if (m_pConsoleVerb)
  1112. {
  1113. // If it's in the result pane then "properties" should be the
  1114. // default action. Otherwise "open" should be the default action.
  1115. if (type == CCT_RESULT)
  1116. {
  1117. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_PROPERTIES);
  1118. // Enable the delete verb.
  1119. // (UI review - we're NOT going to enable
  1120. // the delete verb after all.)
  1121. // m_pConsoleVerb->SetVerbState(MMC_VERB_DELETE, ENABLED, TRUE);
  1122. // Enable the properties verb.
  1123. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  1124. }
  1125. else
  1126. {
  1127. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_OPEN);
  1128. if (!m_pScopePane->m_fRSOP)
  1129. {
  1130. // Enable the properties verb.
  1131. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  1132. }
  1133. }
  1134. // Set the default verb to open
  1135. // Enable the refresh verb.
  1136. if (!m_pScopePane->m_fRSOP)
  1137. {
  1138. m_pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, ENABLED, TRUE);
  1139. }
  1140. // Enable the paste verb and hide. due to the weird way in which
  1141. // MMC handles drag-n-drop scenarios, the only way to enable drag-n-drop
  1142. // from explorer is to keep the paste verb enabled forever.
  1143. // But do this only if we are not in RSoP because PASTE is meaningless
  1144. // for RSoP which is Read-Only.
  1145. if (!m_pScopePane->m_fRSOP)
  1146. {
  1147. m_pConsoleVerb->SetVerbState(MMC_VERB_PASTE, ENABLED, TRUE);
  1148. m_pConsoleVerb->SetVerbState(MMC_VERB_PASTE, HIDDEN, TRUE);
  1149. }
  1150. else
  1151. {
  1152. m_pConsoleVerb->SetVerbState(MMC_VERB_PASTE, ENABLED, FALSE);
  1153. m_pConsoleVerb->SetVerbState(MMC_VERB_PASTE, HIDDEN, TRUE);
  1154. }
  1155. }
  1156. return S_OK;
  1157. }
  1158. HRESULT CResultPane::OnPropertyChange(LPARAM param) // param is the cookie of the item that changed
  1159. {
  1160. HRESULT hr = S_OK;
  1161. if(m_pScopePane->m_AppData[param].m_fVisible)
  1162. {
  1163. RESULTDATAITEM rd;
  1164. memset(&rd, 0, sizeof(rd));
  1165. rd.mask = RDI_IMAGE;
  1166. rd.itemID = m_pScopePane->m_AppData[param].m_itemID;
  1167. rd.nImage = m_pScopePane->m_AppData[param].GetImageIndex(m_pScopePane);
  1168. m_pResult->SetItem(&rd);
  1169. m_pResult->Sort(m_nSortColumn, m_dwSortOptions, -1);
  1170. }
  1171. return hr;
  1172. }
  1173. HRESULT CResultPane::OnUpdateView(LPDATAOBJECT lpDataObject)
  1174. {
  1175. return S_OK;
  1176. }
  1177. void CResultPane::Enumerate(MMC_COOKIE cookie, HSCOPEITEM pParent)
  1178. {
  1179. EnumerateResultPane(cookie);
  1180. }
  1181. HRESULT GetFailedSettings(IWbemServices * pNamespace,
  1182. CAppData &data,
  1183. IWbemClassObject * pInst)
  1184. {
  1185. VARIANT var;
  1186. HRESULT hr = S_OK;
  1187. VariantInit(&var);
  1188. BSTR strLanguage = SysAllocString(TEXT("WQL"));
  1189. if (strLanguage)
  1190. {
  1191. CString szRelPath;
  1192. hr = GetParameter(pInst,
  1193. TEXT("__RELPATH"),
  1194. szRelPath);
  1195. DebugReportFailure(hr, (DM_WARNING, L"GetFailedSettings: GetParameter(\"__RELPATH\") failed with 0x%x", hr));
  1196. if (SUCCEEDED(hr))
  1197. {
  1198. // build the proper query
  1199. CString szQuery = TEXT("ASSOCIATORS OF {");
  1200. szQuery += szRelPath;
  1201. szQuery += TEXT("} WHERE ResultClass=RSOP_PolicySettingStatus");
  1202. BSTR strQuery = SysAllocString(szQuery);
  1203. if (strQuery)
  1204. {
  1205. IEnumWbemClassObject * pEnum = NULL;
  1206. // execute the query
  1207. hr = pNamespace->ExecQuery(strLanguage,
  1208. strQuery,
  1209. WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
  1210. NULL,
  1211. &pEnum);
  1212. DebugReportFailure(hr, (DM_WARNING, L"GetFailedSettings: pNamespace->ExecQuery failed with 0x%x", hr));
  1213. if (SUCCEEDED(hr))
  1214. {
  1215. IWbemClassObject * pObj = NULL;
  1216. ULONG n = 0;
  1217. // get the result (only care about the first entry)
  1218. hr = pEnum->Next(WBEM_INFINITE,
  1219. 1,
  1220. &pObj,
  1221. &n);
  1222. DebugReportFailure(hr, (DM_WARNING, L"GetFailedSettings: pEnum->Next failed with 0x%x", hr));
  1223. if (SUCCEEDED(hr) && n > 0)
  1224. {
  1225. hr = GetParameter(pObj, TEXT("EventSource"), data.m_szEventSource);
  1226. DebugReportFailure(hr, (DM_WARNING, L"GetFailedSettings: GetParameter(\"EventSource\") failed with 0x%x", hr));
  1227. hr = GetParameter(pObj, TEXT("EventLogName"), data.m_szEventLogName);
  1228. DebugReportFailure(hr, (DM_WARNING, L"GetFailedSettings: GetParameter(\"EventLogName\") failed with 0x%x", hr));
  1229. hr = GetParameter(pObj, TEXT("EventID"), data.m_dwEventID);
  1230. DebugReportFailure(hr, (DM_WARNING, L"GetFailedSettings: GetParameter(\"EventId\") failed with 0x%x", hr));
  1231. BSTR bstrTime = NULL;
  1232. hr = GetParameterBSTR(pObj, TEXT("EventTime"),bstrTime);
  1233. DebugReportFailure(hr, (DM_WARNING, L"GetFailedSettings: GetParameter(\"EventTime\") failed with 0x%x", hr));
  1234. if (SUCCEEDED(hr))
  1235. {
  1236. data.m_szEventTime = bstrTime;
  1237. if (bstrTime)
  1238. SysFreeString(bstrTime);
  1239. }
  1240. hr = GetParameter(pObj, TEXT("ErrorCode"), data.m_hrErrorCode);
  1241. DebugReportFailure(hr, (DM_WARNING, L"GetFailedSettings: GetParameter(\"ErrorCode\") failed with 0x%x", hr));
  1242. hr = GetParameter(pObj, TEXT("Status"), data.m_nStatus);
  1243. DebugReportFailure(hr, (DM_WARNING, L"GetFailedSettings: GetParameter(\"Status\") failed with 0x%x", hr));
  1244. }
  1245. pEnum->Release();
  1246. }
  1247. SysFreeString(strQuery);
  1248. }
  1249. else
  1250. {
  1251. DebugMsg((DM_WARNING, L"GetFailedSettings: SysAllocString failed with %u", GetLastError()));
  1252. }
  1253. }
  1254. SysFreeString(strLanguage);
  1255. }
  1256. VariantClear(&var);
  1257. return hr;
  1258. }
  1259. HRESULT
  1260. GetUniqueUpgradeName(
  1261. IWbemServices * pNamespace,
  1262. BSTR strLanguage,
  1263. CString& szGPOID,
  1264. CString szGPOName,
  1265. CString& szUpgradeName)
  1266. {
  1267. HRESULT hr;
  1268. CString GpoName;
  1269. hr = S_OK;
  1270. if ( pNamespace )
  1271. {
  1272. LPTSTR pszGPOName = NULL;
  1273. hr = GetGPOFriendlyName(pNamespace,
  1274. (LPTSTR)((LPCTSTR) szGPOID),
  1275. strLanguage,
  1276. &pszGPOName);
  1277. GpoName = pszGPOName;
  1278. DebugReportFailure(hr, (DM_WARNING, L"GetUniqueUpgradeName: GetGPOFriendlyName failed with 0x%x", hr));
  1279. OLESAFE_DELETE(pszGPOName);
  1280. }
  1281. else
  1282. {
  1283. GpoName = szGPOName;
  1284. }
  1285. if (SUCCEEDED(hr))
  1286. {
  1287. szUpgradeName += TEXT(" (");
  1288. szUpgradeName += GpoName;
  1289. szUpgradeName += TEXT(")");
  1290. }
  1291. return hr;
  1292. }
  1293. HRESULT GetRsopFriendlyAppName(
  1294. IWbemServices * pNamespace,
  1295. CAppData &data)
  1296. {
  1297. VARIANT var;
  1298. HRESULT hr = S_OK;
  1299. VariantInit(&var);
  1300. CString szGPO;
  1301. BSTR strLanguage = SysAllocString(TEXT("WQL"));
  1302. if (strLanguage)
  1303. {
  1304. if (SUCCEEDED(hr))
  1305. {
  1306. // build the proper query
  1307. CString szQuery = TEXT("SELECT Name, GPOID FROM RSOP_ApplicationManagementPolicySetting WHERE EntryType=1");
  1308. szQuery += TEXT(" AND ApplicationId=\"");
  1309. szQuery += data.m_szRemovingApplication;
  1310. szQuery +=L'\"';
  1311. BSTR strQuery = SysAllocString(szQuery);
  1312. if (strQuery)
  1313. {
  1314. IEnumWbemClassObject * pEnum = NULL;
  1315. // execute the query
  1316. hr = pNamespace->ExecQuery(strLanguage,
  1317. strQuery,
  1318. WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
  1319. NULL,
  1320. &pEnum);
  1321. DebugReportFailure(hr, (DM_WARNING, L"GetRsopFriendlyAppName: pNamespace->ExecQuery failed with 0x%x", hr));
  1322. if (SUCCEEDED(hr))
  1323. {
  1324. IWbemClassObject * pObj = NULL;
  1325. ULONG n = 0;
  1326. // get the result (only care about the first entry)
  1327. hr = pEnum->Next(WBEM_INFINITE,
  1328. 1,
  1329. &pObj,
  1330. &n);
  1331. DebugReportFailure(hr, (DM_WARNING, L"GetRsopFriendlyAppName: pEnum->Next failed with 0x%x", hr));
  1332. if (SUCCEEDED(hr) && n > 0)
  1333. {
  1334. hr = GetParameter(pObj, TEXT("Name"), data.m_szRemovingApplicationName);
  1335. DebugReportFailure(hr, (DM_WARNING, L"GetRsopFriendlyAppName: GetParameter(\"Name\") failed with 0x%x", hr));
  1336. }
  1337. if (SUCCEEDED(hr) && n > 0)
  1338. {
  1339. hr = GetParameter(pObj,
  1340. TEXT("GPOID"),
  1341. szGPO);
  1342. DebugReportFailure(hr, (DM_WARNING, L"GetRsopFriendlyAppName: GetParameter(\"GPOID\") failed with 0x%x", hr));
  1343. }
  1344. if ( SUCCEEDED(hr) )
  1345. {
  1346. hr = GetUniqueUpgradeName(
  1347. pNamespace,
  1348. strLanguage,
  1349. szGPO,
  1350. TEXT(""),
  1351. data.m_szRemovingApplicationName);
  1352. }
  1353. pEnum->Release();
  1354. }
  1355. DebugReportFailure(hr, (DM_WARNING, L"GetRsopFriendlyAppName: GetUniqueUpgradeName failed with 0x%x", hr));
  1356. SysFreeString(strQuery);
  1357. }
  1358. else
  1359. {
  1360. DebugMsg((DM_WARNING, L"GetRsopFriendlyAppName: SysAllocString failed with %u", GetLastError()));
  1361. }
  1362. }
  1363. SysFreeString(strLanguage);
  1364. }
  1365. VariantClear(&var);
  1366. return hr;
  1367. }
  1368. HRESULT GetRSOPUpgrades(IWbemServices * pNamespace,
  1369. TCHAR * szGPOID,
  1370. IWbemClassObject * pInst,
  1371. TCHAR * szParam,
  1372. set <CString> &s)
  1373. {
  1374. VARIANT var;
  1375. HRESULT hr = S_OK;
  1376. VariantInit(&var);
  1377. BSTR strLanguage = SysAllocString(TEXT("WQL"));
  1378. if (strLanguage)
  1379. {
  1380. CString EntryType;
  1381. hr = pInst->Get(szParam, 0, &var, 0, 0);
  1382. DebugReportFailure(hr, (DM_WARNING, L"GetRSOPUpgrades: pInst->Get(\"%s\") failed with 0x%x", szParam, hr));
  1383. if ( SUCCEEDED(hr) )
  1384. {
  1385. VARIANT varEntryType;
  1386. VariantInit( &varEntryType );
  1387. hr = pInst->Get( L"EntryType", 0, &varEntryType, 0, 0 );
  1388. if ( SUCCEEDED(hr) )
  1389. {
  1390. if ( VT_I4 == varEntryType.vt )
  1391. {
  1392. EntryType.Format( TEXT("%d"), varEntryType.lVal );
  1393. }
  1394. else
  1395. {
  1396. hr = E_INVALIDARG;
  1397. }
  1398. }
  1399. VariantClear( &varEntryType );
  1400. }
  1401. if (SUCCEEDED(hr) && var.vt == (VT_ARRAY | VT_BSTR))
  1402. {
  1403. CString sz;
  1404. SAFEARRAY * parray = var.parray;
  1405. BSTR * rgData = (BSTR *)parray->pvData;
  1406. UINT ui = parray->rgsabound[0].cElements;
  1407. while (ui--)
  1408. {
  1409. sz = rgData[ui];
  1410. // Find the app that this guid matches
  1411. // first build the proper query
  1412. CString szQuery = TEXT("SELECT Name, GPOID FROM RSOP_ApplicationManagementPolicySetting WHERE EntryType=");
  1413. szQuery += EntryType;
  1414. szQuery += TEXT(" AND ApplicationId=");
  1415. szQuery +=L'\"';
  1416. szQuery += sz;
  1417. szQuery +=L'\"';
  1418. BSTR strQuery = SysAllocString(szQuery);
  1419. if (strQuery)
  1420. {
  1421. IEnumWbemClassObject * pEnum = NULL;
  1422. // execute the query
  1423. hr = pNamespace->ExecQuery(strLanguage,
  1424. strQuery,
  1425. WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
  1426. NULL,
  1427. &pEnum);
  1428. DebugReportFailure(hr, (DM_WARNING, L"GetRSOPUpgrades: pNamespace->ExecQuery failed with 0x%x", hr));
  1429. if (SUCCEEDED(hr))
  1430. {
  1431. IWbemClassObject * pObj = NULL;
  1432. ULONG n;
  1433. // get the result (only care about the first entry)
  1434. hr = pEnum->Next(WBEM_INFINITE,
  1435. 1,
  1436. &pObj,
  1437. &n);
  1438. DebugReportFailure(hr, (DM_WARNING, L"GetRSOPUpgrades: pEnum->Next failed with 0x%x", hr));
  1439. if (SUCCEEDED(hr) && n > 0)
  1440. {
  1441. // get the PackageName
  1442. hr = GetParameter(pObj,
  1443. TEXT("Name"),
  1444. sz);
  1445. DebugReportFailure(hr, (DM_WARNING, L"GetRSOPUpgrades: GetParameter(\"Name\") failed with 0x%x", hr));
  1446. // get the GPOID
  1447. CString szGPO;
  1448. hr = GetParameter(pObj,
  1449. TEXT("GPOID"),
  1450. szGPO);
  1451. DebugReportFailure(hr, (DM_WARNING, L"GetRSOPUpgrades: GetParameter(\"GPOID\") failed with 0x%x", hr));
  1452. hr = GetUniqueUpgradeName(pNamespace,
  1453. strLanguage,
  1454. szGPO,
  1455. TEXT(""),
  1456. sz);
  1457. DebugReportFailure(hr, (DM_WARNING, L"GetRSOPUpgrades: GetUniqueUpgradeName failed with 0x%x", hr));
  1458. // insert the name
  1459. s.insert(sz);
  1460. pObj->Release();
  1461. }
  1462. pEnum->Release();
  1463. }
  1464. SysFreeString(strQuery);
  1465. }
  1466. }
  1467. }
  1468. SysFreeString(strLanguage);
  1469. }
  1470. VariantClear(&var);
  1471. return hr;
  1472. }
  1473. HRESULT
  1474. GetRSOPUpgradedBy( map<MMC_COOKIE, CAppData>* pAppData )
  1475. {
  1476. map<MMC_COOKIE, CAppData>::iterator AppIterator;
  1477. CString UpgradeId;
  1478. CString AppId;
  1479. BSTR strLanguage = SysAllocString(TEXT("WQL"));
  1480. if ( ! strLanguage )
  1481. {
  1482. return E_OUTOFMEMORY;
  1483. }
  1484. HRESULT hr;
  1485. hr = S_OK;
  1486. //
  1487. // For each app, retrieve the set of apps that it upgrades
  1488. //
  1489. for ( AppIterator = pAppData->begin(); AppIterator != pAppData->end(); AppIterator++)
  1490. {
  1491. {
  1492. CAppData& AppData = AppIterator->second;
  1493. AppId = AppData.m_pDetails->pszPackageName;
  1494. hr = GetUniqueUpgradeName(
  1495. NULL,
  1496. strLanguage,
  1497. AppData.m_szGPOID,
  1498. AppData.m_szGPOName,
  1499. AppId);
  1500. if ( FAILED(hr) )
  1501. {
  1502. break;
  1503. }
  1504. //
  1505. // Iterate through each upgrade to see if
  1506. // we can find the upgrade in the list of apps
  1507. //
  1508. set <CString>::iterator CurrentUpgrade;
  1509. for (
  1510. CurrentUpgrade = AppData.m_setUpgrade.begin();
  1511. CurrentUpgrade != AppData.m_setUpgrade.end();
  1512. CurrentUpgrade++)
  1513. {
  1514. map<MMC_COOKIE, CAppData>::iterator UpgradeIterator;
  1515. for (
  1516. UpgradeIterator = pAppData->begin();
  1517. pAppData->end() != UpgradeIterator;
  1518. UpgradeIterator++)
  1519. {
  1520. UpgradeId = UpgradeIterator->second.m_pDetails->pszPackageName;
  1521. hr = GetUniqueUpgradeName(
  1522. NULL,
  1523. strLanguage,
  1524. UpgradeIterator->second.m_szGPOID,
  1525. UpgradeIterator->second.m_szGPOName,
  1526. UpgradeId);
  1527. if ( FAILED(hr) )
  1528. {
  1529. break;
  1530. }
  1531. //
  1532. // See if this potential upgrade corresponds to the current upgrade
  1533. // listed in the current app -- if so, mark the upgraded app as being
  1534. // upgraded by the current app
  1535. //
  1536. if ( *CurrentUpgrade == UpgradeId )
  1537. {
  1538. UpgradeIterator->second.m_setUpgradedBy.insert( AppId );
  1539. }
  1540. }
  1541. }
  1542. if (SUCCEEDED(hr))
  1543. {
  1544. for (
  1545. CurrentUpgrade = AppData.m_setReplace.begin();
  1546. CurrentUpgrade != AppData.m_setReplace.end();
  1547. CurrentUpgrade++)
  1548. {
  1549. map<MMC_COOKIE, CAppData>::iterator UpgradeIterator;
  1550. for (
  1551. UpgradeIterator = pAppData->begin();
  1552. pAppData->end() != UpgradeIterator;
  1553. UpgradeIterator++)
  1554. {
  1555. UpgradeId = UpgradeIterator->second.m_pDetails->pszPackageName;
  1556. hr = GetUniqueUpgradeName(
  1557. NULL,
  1558. strLanguage,
  1559. UpgradeIterator->second.m_szGPOID,
  1560. UpgradeIterator->second.m_szGPOName,
  1561. UpgradeId);
  1562. if ( FAILED(hr) )
  1563. {
  1564. break;
  1565. }
  1566. //
  1567. // See if this potential upgrade corresponds to the current upgrade
  1568. // listed in the current app -- if so, mark the upgraded app as being
  1569. // upgraded by the current app
  1570. //
  1571. if ( *CurrentUpgrade == UpgradeId )
  1572. {
  1573. UpgradeIterator->second.m_setUpgradedBy.insert( AppId );
  1574. }
  1575. }
  1576. }
  1577. }
  1578. if ( FAILED(hr) )
  1579. {
  1580. break;
  1581. }
  1582. }
  1583. if ( FAILED( hr) )
  1584. {
  1585. break;
  1586. }
  1587. }
  1588. SysFreeString(strLanguage);
  1589. return hr;
  1590. }
  1591. HRESULT CResultPane::EnumerateRSoPData(void)
  1592. {
  1593. HRESULT hr = S_OK;
  1594. IWbemLocator * pLocator = NULL;
  1595. IWbemServices * pNamespace = NULL;
  1596. IWbemClassObject * pObj = NULL;
  1597. IEnumWbemClassObject * pEnum = NULL;
  1598. BSTR strQueryLanguage = SysAllocString(TEXT("WQL"));
  1599. BSTR strQuery = NULL;
  1600. CString szText;
  1601. m_pScopePane->m_AppData.erase(m_pScopePane->m_AppData.begin(), m_pScopePane->m_AppData.end());
  1602. switch (m_pScopePane->m_iViewState)
  1603. {
  1604. case IDM_WINNER:
  1605. strQuery = SysAllocString(TEXT("SELECT * FROM RSOP_ApplicationManagementPolicySetting WHERE EntryType=1"));
  1606. szText.LoadString(IDS_WIN_TEXT);
  1607. break;
  1608. case IDM_REMOVED:
  1609. strQuery = SysAllocString(TEXT("SELECT * FROM RSOP_ApplicationManagementPolicySetting WHERE EntryType=2"));
  1610. szText.LoadString(IDS_REM_TEXT);
  1611. break;
  1612. case IDM_ARP:
  1613. strQuery = SysAllocString(TEXT("SELECT * FROM RSOP_ApplicationManagementPolicySetting WHERE EntryType=3"));
  1614. szText.LoadString(IDS_ARP_TEXT);
  1615. break;
  1616. }
  1617. // set text of first column to match the view state
  1618. m_pHeader->SetColumnText(0, szText);
  1619. BSTR strNamespace = SysAllocString(m_pScopePane->m_szRSOPNamespace);
  1620. hr = CoCreateInstance(CLSID_WbemLocator,
  1621. 0,
  1622. CLSCTX_INPROC_SERVER,
  1623. IID_IWbemLocator,
  1624. (LPVOID *) & pLocator);
  1625. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: CoCreateInstance failed with 0x%x", hr));
  1626. if (FAILED(hr))
  1627. {
  1628. goto cleanup;
  1629. }
  1630. hr = pLocator->ConnectServer(strNamespace,
  1631. NULL,
  1632. NULL,
  1633. NULL,
  1634. 0,
  1635. NULL,
  1636. NULL,
  1637. &pNamespace);
  1638. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: pLocator->ConnectServer failed with 0x%x", hr));
  1639. if (FAILED(hr))
  1640. {
  1641. goto cleanup;
  1642. }
  1643. // Set the proper security to encrypt the data
  1644. hr = CoSetProxyBlanket(pNamespace,
  1645. RPC_C_AUTHN_DEFAULT,
  1646. RPC_C_AUTHZ_DEFAULT,
  1647. COLE_DEFAULT_PRINCIPAL,
  1648. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  1649. RPC_C_IMP_LEVEL_IMPERSONATE,
  1650. NULL,
  1651. 0);
  1652. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: CoSetProxyBlanket failed with 0x%x", hr));
  1653. if (FAILED(hr))
  1654. {
  1655. goto cleanup;
  1656. }
  1657. hr = pNamespace->ExecQuery(strQueryLanguage,
  1658. strQuery,
  1659. WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
  1660. NULL,
  1661. &pEnum);
  1662. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: pNamespace->ExecQuery failed with 0x%x", hr));
  1663. if (FAILED(hr))
  1664. {
  1665. goto cleanup;
  1666. }
  1667. ULONG uEnumIndex = 0;
  1668. do
  1669. {
  1670. hr = pEnum->Next(WBEM_INFINITE, 1, &pObj, &uEnumIndex);
  1671. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: pEnum->Next failed with 0x%x", hr));
  1672. if (FAILED(hr))
  1673. {
  1674. goto cleanup;
  1675. }
  1676. if (uEnumIndex > 0)
  1677. {
  1678. // prepare the data entry and populate all the fields
  1679. CAppData data;
  1680. data.m_fRSoP = TRUE;
  1681. BOOL fDemandInstallable = FALSE;
  1682. int iLossOfScopeAction = 0;
  1683. BOOL fDisplayInARP = FALSE;
  1684. BOOL fIgnoreLanguage = FALSE;
  1685. BOOL fUpgradeSettingsMandatory = FALSE;
  1686. BOOL fUninstallUnmanaged = FALSE;
  1687. BOOL fAllowX86OnWin64 = FALSE;
  1688. int iAssignmentType = 0;
  1689. UINT uiDeploymentType = 0;
  1690. WCHAR * szPackageLocation = NULL;
  1691. UINT nTransforms = 0;
  1692. WCHAR ** rgszTransforms = NULL;
  1693. PACKAGEDETAIL * pd = new PACKAGEDETAIL;
  1694. ACTIVATIONINFO * pa = (ACTIVATIONINFO *)OLEALLOC(sizeof(ACTIVATIONINFO));
  1695. PLATFORMINFO * pp = (PLATFORMINFO *)OLEALLOC(sizeof(PLATFORMINFO));
  1696. INSTALLINFO * pi = (INSTALLINFO *)OLEALLOC(sizeof(INSTALLINFO));
  1697. if (pd && pa && pi && pp)
  1698. {
  1699. memset(pi, 0, sizeof(INSTALLINFO));
  1700. memset(pp, 0, sizeof(PLATFORMINFO));
  1701. memset(pa, 0, sizeof(ACTIVATIONINFO));
  1702. memset(pd, 0, sizeof(PACKAGEDETAIL));
  1703. pd->pActInfo = pa;
  1704. pd->pPlatformInfo = pp;
  1705. pd->pInstallInfo = pi;
  1706. }
  1707. else
  1708. {
  1709. // out of memory
  1710. if (pd)
  1711. {
  1712. delete pd;
  1713. }
  1714. if (pa)
  1715. {
  1716. OLESAFE_DELETE(pa);
  1717. }
  1718. if (pi)
  1719. {
  1720. OLESAFE_DELETE(pi);
  1721. }
  1722. if (pp)
  1723. {
  1724. OLESAFE_DELETE(pp);
  1725. }
  1726. hr = E_OUTOFMEMORY;
  1727. goto cleanup;
  1728. }
  1729. hr = GetParameter(pObj,
  1730. TEXT("Name"),
  1731. pd->pszPackageName);
  1732. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"Name\") failed with 0x%x", hr));
  1733. DWORD dwPrecedence;
  1734. hr = GetParameter(pObj,
  1735. TEXT("Precedence"),
  1736. dwPrecedence);
  1737. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"Precedence\") failed with 0x%x", hr));
  1738. if ((1 != dwPrecedence) && (IDM_REMOVED != m_pScopePane->m_iViewState))
  1739. {
  1740. data.m_fHide = TRUE;
  1741. }
  1742. hr = GetParameter(pObj,
  1743. TEXT("VersionNumberLo"),
  1744. pi->dwVersionLo);
  1745. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"VersionNumberLo\") failed with 0x%x", hr));
  1746. hr = GetParameter(pObj,
  1747. TEXT("VersionNumberHi"),
  1748. pi->dwVersionHi);
  1749. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"VersionNumberHi\") failed with 0x%x", hr));
  1750. hr = GetParameter(pObj,
  1751. TEXT("Publisher"),
  1752. pd->pszPublisher);
  1753. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"Publisher\") failed with 0x%x", hr));
  1754. hr = GetParameter(pObj,
  1755. TEXT("ProductId"),
  1756. pi->ProductCode);
  1757. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"ProductId\") failed with 0x%x", hr));
  1758. hr = GetParameter(pObj,
  1759. TEXT("ScriptFile"),
  1760. pi->pszScriptPath);
  1761. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"ScriptFile\") failed with 0x%x", hr));
  1762. hr = GetParameter(pObj,
  1763. TEXT("SupportURL"),
  1764. pi->pszUrl);
  1765. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"SupportURL\") failed with 0x%x", hr));
  1766. pp->prgLocale = (LCID *) OLEALLOC(sizeof(LCID));
  1767. if (!pp->prgLocale)
  1768. {
  1769. hr = E_OUTOFMEMORY;
  1770. goto cleanup;
  1771. }
  1772. pp->cLocales = 1;
  1773. hr = GetParameter(pObj,
  1774. TEXT("LanguageID"),
  1775. pp->prgLocale[0]);
  1776. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"LanguageID\") failed with 0x%x", hr));
  1777. hr = GetParameter(pObj,
  1778. TEXT("MachineArchitectures"),
  1779. pp->cPlatforms,
  1780. pp->prgPlatform);
  1781. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"MachineArchitectures\") failed with 0x%x", hr));
  1782. hr = GetParameter(pObj,
  1783. TEXT("DeploymentType"),
  1784. uiDeploymentType);
  1785. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"DeploymentType\") failed with 0x%x", hr));
  1786. hr = GetParameter(pObj,
  1787. TEXT("InstallationUI"),
  1788. pi->InstallUiLevel);
  1789. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"InstallationUI\") failed with 0x%x", hr));
  1790. if (pi->InstallUiLevel == 2)
  1791. {
  1792. pi->InstallUiLevel = INSTALLUILEVEL_FULL;
  1793. }
  1794. else
  1795. {
  1796. pi->InstallUiLevel = INSTALLUILEVEL_BASIC;
  1797. }
  1798. hr = GetParameter(pObj,
  1799. TEXT("RedeployCount"),
  1800. pi->dwRevision);
  1801. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"RedeployCount\") failed with 0x%x", hr));
  1802. hr = GetParameter(pObj,
  1803. TEXT("DemandInstallable"),
  1804. fDemandInstallable);
  1805. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"DemandInstallable\") failed with 0x%x", hr));
  1806. hr = GetParameter(pObj,
  1807. TEXT("LossOfScopeAction"),
  1808. iLossOfScopeAction);
  1809. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"LossOfScopeAction\") failed with 0x%x", hr));
  1810. hr = GetParameter(pObj,
  1811. TEXT("DisplayInARP"),
  1812. fDisplayInARP);
  1813. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"DisplayInARP\") failed with 0x%x", hr));
  1814. hr = GetParameter(pObj,
  1815. TEXT("IgnoreLanguage"),
  1816. fIgnoreLanguage);
  1817. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"IgnoreLanguage\") failed with 0x%x", hr));
  1818. hr = GetParameter(pObj,
  1819. TEXT("UninstallUnmanaged"),
  1820. fUninstallUnmanaged);
  1821. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"UninstallUnmanaged\") failed with 0x%x", hr));
  1822. hr = GetParameter(pObj,
  1823. TEXT("AssignmentType"),
  1824. iAssignmentType);
  1825. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"AssignmentType\") failed with 0x%x", hr));
  1826. hr = GetParameter(pObj,
  1827. TEXT("AllowX86OnIA64"),
  1828. fAllowX86OnWin64);
  1829. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"AllowX86OnIA64\") failed with 0x%x", hr));
  1830. // build proper flags
  1831. pi->dwActFlags = (uiDeploymentType == 2 ? ACTFLG_Published : ACTFLG_Assigned)
  1832. | (fDemandInstallable ? ACTFLG_OnDemandInstall : 0)
  1833. | (iLossOfScopeAction == 1 ? ACTFLG_UninstallOnPolicyRemoval : ACTFLG_OrphanOnPolicyRemoval)
  1834. | (fDisplayInARP ? ACTFLG_UserInstall : 0)
  1835. | (fUninstallUnmanaged ? ACTFLG_UninstallUnmanaged : 0)
  1836. | (fIgnoreLanguage ? ACTFLG_IgnoreLanguage : 0)
  1837. | (iAssignmentType == 3 ? ACTFLG_InstallUserAssign : 0);
  1838. {
  1839. int nArch = pp->cPlatforms;
  1840. while (nArch--)
  1841. {
  1842. if (pp->prgPlatform[nArch].dwProcessorArch == PROCESSOR_ARCHITECTURE_INTEL)
  1843. {
  1844. if (!fAllowX86OnWin64)
  1845. {
  1846. pi->dwActFlags |= ACTFLG_ExcludeX86OnWin64;
  1847. }
  1848. }
  1849. }
  1850. }
  1851. hr = GetParameter(pObj,
  1852. TEXT("UpgradeSettingsMandatory"),
  1853. fUpgradeSettingsMandatory);
  1854. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"UpgradeSettingsMandatory\") failed with 0x%x", hr));
  1855. if (fUpgradeSettingsMandatory)
  1856. {
  1857. pi->dwActFlags |= ACTFLG_ForceUpgrade;
  1858. }
  1859. hr = GetParameter(pObj,
  1860. TEXT("PackageLocation"),
  1861. szPackageLocation);
  1862. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"PackageLocation\") failed with 0x%x", hr));
  1863. hr = GetParameter(pObj,
  1864. TEXT("transforms"),
  1865. nTransforms,
  1866. rgszTransforms
  1867. );
  1868. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"transforms\") failed with 0x%x", hr));
  1869. pd->pszSourceList = (TCHAR **)OLEALLOC(sizeof(TCHAR *) * (nTransforms + 1));
  1870. if (!pd->pszSourceList)
  1871. {
  1872. hr = E_OUTOFMEMORY;
  1873. goto cleanup;
  1874. }
  1875. pd->cSources = nTransforms + 1;
  1876. if (NULL != pd->pszSourceList)
  1877. {
  1878. pd->pszSourceList[0] = szPackageLocation;
  1879. UINT n = nTransforms;
  1880. while (n--)
  1881. {
  1882. pd->pszSourceList[1 + n] = rgszTransforms[n];
  1883. }
  1884. OLESAFE_DELETE(rgszTransforms);
  1885. }
  1886. /* UNDONE
  1887. hr = GetParameter(pObj,
  1888. TEXT("localeMatchType"),
  1889. );
  1890. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"LocaleMatchType\") failed with 0x%x", hr));
  1891. */
  1892. hr = GetParameter(pObj,
  1893. TEXT("categories"),
  1894. pd->cCategories,
  1895. pd->rpCategory
  1896. );
  1897. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"categories\") failed with 0x%x", hr));
  1898. data.m_pDetails = pd;
  1899. data.InitializeExtraInfo();
  1900. hr = GetParameter(pObj,
  1901. TEXT("GPOID"),
  1902. data.m_szGPOID);
  1903. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"GPOID\") failed with 0x%x", hr));
  1904. LPTSTR pszGPOName = NULL;
  1905. hr = GetGPOFriendlyName(pNamespace,
  1906. (LPTSTR)((LPCTSTR) data.m_szGPOID),
  1907. strQueryLanguage,
  1908. &pszGPOName);
  1909. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetGPOFriendlyName failed with 0x%x", hr));
  1910. if (SUCCEEDED(hr))
  1911. {
  1912. data.m_szGPOName = pszGPOName;
  1913. OLESAFE_DELETE(pszGPOName);
  1914. }
  1915. hr = GetParameter(pObj,
  1916. TEXT("Id"),
  1917. data.m_szDeploymentGroupID);
  1918. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"Id\") failed with 0x%x", hr));
  1919. hr = GetParameter(pObj,
  1920. TEXT("SOMID"),
  1921. data.m_szSOMID);
  1922. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"SOMID\") failed with 0x%x", hr));
  1923. hr = GetParameter(pObj,
  1924. TEXT("SecurityDescriptor"),
  1925. data.m_psd);
  1926. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"SecurityDescriptor\") failed with 0x%x", hr));
  1927. hr = GetRSOPUpgrades(pNamespace,
  1928. 0,
  1929. pObj,
  1930. TEXT("UpgradeableApplications"),
  1931. data.m_setUpgrade);
  1932. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetRSOPUpgrades(\"UpgradeableApplications\") failed with 0x%x", hr));
  1933. hr = GetRSOPUpgrades(pNamespace,
  1934. 0,
  1935. pObj,
  1936. TEXT("ReplaceableApplications"),
  1937. data.m_setReplace);
  1938. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetRSOPUpgrades(\"ReplaceableApplications\") failed with 0x%x", hr));
  1939. hr = GetParameter(pObj,
  1940. TEXT("ApplyCause"),
  1941. data.m_dwApplyCause);
  1942. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"ApplyCause\") failed with 0x%x", hr));
  1943. hr = GetParameter(pObj,
  1944. TEXT("LanguageMatch"),
  1945. data.m_dwLanguageMatch);
  1946. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"LanguageMatch\") failed with 0x%x", hr));
  1947. hr = GetParameter(pObj,
  1948. TEXT("OnDemandFileExtension"),
  1949. data.m_szOnDemandFileExtension);
  1950. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"OnDemandFileExtension\") failed with 0x%x", hr));
  1951. hr = GetParameter(pObj,
  1952. TEXT("OnDemandClsid"),
  1953. data.m_szOnDemandClsid);
  1954. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"OnDemandClsid\") failed with 0x%x", hr));
  1955. hr = GetParameter(pObj,
  1956. TEXT("OnDemandProgid"),
  1957. data.m_szOnDemandProgid);
  1958. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"OnDemandProgid\") failed with 0x%x", hr));
  1959. hr = GetParameter(pObj,
  1960. TEXT("RemovalCause"),
  1961. data.m_dwRemovalCause);
  1962. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"RemovalCause\") failed with 0x%x", hr));
  1963. hr = GetParameter(pObj,
  1964. TEXT("RemovalType"),
  1965. data.m_dwRemovalType);
  1966. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"RemovalType\") failed with 0x%x", hr));
  1967. hr = GetParameter(pObj,
  1968. TEXT("RemovingApplication"),
  1969. data.m_szRemovingApplication);
  1970. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetParameter(\"RemovingType\") failed with 0x%x", hr));
  1971. if ( SUCCEEDED(hr) )
  1972. {
  1973. hr = GetRsopFriendlyAppName(
  1974. pNamespace,
  1975. data);
  1976. }
  1977. hr = GetFailedSettings(pNamespace,
  1978. data,
  1979. pObj);
  1980. if (SUCCEEDED(hr))
  1981. {
  1982. LPOLESTR lpText;
  1983. hr = this->m_pScopePane->m_pIRSOPInformation->GetEventLogEntryText((LPOLESTR)(LPCOLESTR)data.m_szEventSource,
  1984. (LPOLESTR)(LPCOLESTR)data.m_szEventLogName,
  1985. (LPOLESTR)(LPCOLESTR)data.m_szEventTime,
  1986. data.m_dwEventID,
  1987. &lpText);
  1988. DebugReportFailure(hr, (DM_WARNING, L"EnumerateRSoPData: GetEventLogEntryText failed with 0x%x", hr));
  1989. if (SUCCEEDED(hr))
  1990. {
  1991. data.m_szEventLogText = lpText;
  1992. CoTaskMemFree(lpText);
  1993. }
  1994. }
  1995. // insert the entry in the list
  1996. m_pScopePane->m_AppData[++m_pScopePane->m_lLastAllocated] = data;
  1997. m_pScopePane->m_UpgradeIndex[GetUpgradeIndex(data.m_pDetails->pInstallInfo->PackageGuid)] = m_pScopePane->m_lLastAllocated;
  1998. // prepare for the next itteration
  1999. if (pObj)
  2000. {
  2001. pObj->Release();
  2002. pObj = NULL;
  2003. }
  2004. }
  2005. } while (uEnumIndex > 0);
  2006. hr = GetRSOPUpgradedBy( &(m_pScopePane->m_AppData) );
  2007. cleanup:
  2008. SysFreeString(strQuery);
  2009. SysFreeString(strQueryLanguage);
  2010. SysFreeString(strNamespace);
  2011. if (pObj)
  2012. {
  2013. pObj->Release();
  2014. }
  2015. if (pEnum)
  2016. {
  2017. pEnum->Release();
  2018. }
  2019. if (pNamespace)
  2020. {
  2021. pNamespace->Release();
  2022. }
  2023. if (pLocator)
  2024. {
  2025. pLocator->Release();
  2026. }
  2027. return hr;
  2028. }
  2029. void CResultPane::EnumerateResultPane(MMC_COOKIE cookie)
  2030. {
  2031. // put up an hourglass (this could take a while)
  2032. CHourglass hourglass;
  2033. if (m_pScopePane) // make sure we've been initialized before we do any of this.
  2034. {
  2035. ASSERT(m_pResult != NULL); // make sure we QI'ed for the interface
  2036. RESULTDATAITEM resultItem;
  2037. memset(&resultItem, 0, sizeof(RESULTDATAITEM));
  2038. // Right now we only have one folder and it only
  2039. // contains a list of application packages so this is really simple.
  2040. if ( ( m_pScopePane->m_AppData.begin() == m_pScopePane->m_AppData.end() ) ||
  2041. m_pScopePane->m_fRSOP ) // test to see if the data has been initialized
  2042. {
  2043. HRESULT hr = S_OK;
  2044. if (m_pScopePane->m_fRSOP)
  2045. {
  2046. // get the data from RSOP database
  2047. hr = EnumerateRSoPData();
  2048. }
  2049. else
  2050. {
  2051. // get the data from ClassStore
  2052. ASSERT(m_pScopePane->m_pIClassAdmin != NULL);
  2053. IClassAdmin * pICA = m_pScopePane->m_pIClassAdmin;
  2054. CSPLATFORM csPlatform;
  2055. memset(&csPlatform, 0, sizeof(CSPLATFORM));
  2056. IEnumPackage * pIPE = NULL;
  2057. hr = pICA->EnumPackages(
  2058. NULL,
  2059. NULL,
  2060. APPQUERY_ADMINISTRATIVE,
  2061. NULL,
  2062. NULL,
  2063. &pIPE);
  2064. if (SUCCEEDED(hr))
  2065. {
  2066. PACKAGEDISPINFO * pi = new PACKAGEDISPINFO;
  2067. if (pi)
  2068. {
  2069. hr = pIPE->Reset();
  2070. while (SUCCEEDED(hr))
  2071. {
  2072. ULONG nceltFetched;
  2073. hr = pIPE->Next(1, pi, &nceltFetched);
  2074. if (nceltFetched)
  2075. {
  2076. PACKAGEDETAIL * pd = new PACKAGEDETAIL;
  2077. HRESULT hrPackageDetail = pICA->GetPackageDetails(pi->pszPackageName, pd);
  2078. _DebugMsg(DM_VERBOSE, TEXT("EnumerateResultPane: GetPackageDetails returned with 0x%x"), hrPackageDetail);
  2079. if (SUCCEEDED(hrPackageDetail))
  2080. {
  2081. _DebugMsg(DM_VERBOSE, TEXT("EnumerateResultPane: GetPackageDetails succeeded with installinfo pointer value with 0x%x"), pd->pInstallInfo);
  2082. CAppData data;
  2083. data.m_pDetails = pd;
  2084. data.InitializeExtraInfo();
  2085. m_pScopePane->m_AppData[++m_pScopePane->m_lLastAllocated] = data;
  2086. m_pScopePane->m_UpgradeIndex[GetUpgradeIndex(data.m_pDetails->pInstallInfo->PackageGuid)] = m_pScopePane->m_lLastAllocated;
  2087. }
  2088. else
  2089. {
  2090. DebugMsg((DM_WARNING, TEXT("GetPackageDetails failed with 0x%x"), hrPackageDetail));
  2091. delete pd;
  2092. }
  2093. }
  2094. else
  2095. {
  2096. break;
  2097. }
  2098. ReleasePackageInfo(pi);
  2099. }
  2100. delete pi;
  2101. }
  2102. SAFE_RELEASE(pIPE);
  2103. }
  2104. }
  2105. if (SUCCEEDED(hr))
  2106. {
  2107. hr = m_pScopePane->PopulateExtensions();
  2108. if (SUCCEEDED(hr))
  2109. {
  2110. hr = m_pScopePane->PopulateUpgradeLists();
  2111. }
  2112. }
  2113. }
  2114. if (_fVisible)
  2115. {
  2116. map<MMC_COOKIE, CAppData>::iterator i = m_pScopePane->m_AppData.begin();
  2117. while (i != m_pScopePane->m_AppData.end())
  2118. {
  2119. if (!i->second.m_fHide)
  2120. {
  2121. resultItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  2122. resultItem.str = MMC_CALLBACK;
  2123. resultItem.nImage = i->second.GetImageIndex(m_pScopePane);
  2124. resultItem.lParam = i->first;
  2125. m_pResult->InsertItem(&resultItem);
  2126. i->second.m_fVisible = TRUE;
  2127. i->second.m_itemID = resultItem.itemID;
  2128. }
  2129. i++;
  2130. }
  2131. m_pResult->Sort(m_nSortColumn, m_dwSortOptions, -1);
  2132. }
  2133. }
  2134. }
  2135. //+--------------------------------------------------------------------------
  2136. //
  2137. // Member: CResultPane::OnFileDrop
  2138. //
  2139. // Synopsis: this functions handles files dropped into the MMC snapin
  2140. //
  2141. // Arguments:
  2142. // [in] lpDataObject : the data object being dropped
  2143. //
  2144. // Returns:
  2145. // TRUE - all the dropped objects were successfully added
  2146. // FALSE - at least some of the dropped objects could not be added
  2147. //
  2148. // History: 5/20/1998 RahulTh created
  2149. //
  2150. // Notes: The dropped files are required to have a .msi extension
  2151. //
  2152. //---------------------------------------------------------------------------
  2153. BOOL CResultPane::OnFileDrop (LPDATAOBJECT lpDataObject)
  2154. {
  2155. AFX_MANAGE_STATE (AfxGetStaticModuleState());
  2156. ASSERT (lpDataObject);
  2157. int nFiles, index, nRequired, iSlashPos;
  2158. STGMEDIUM medium;
  2159. HDROP hDrop;
  2160. TCHAR* szFileName;
  2161. UINT cbSize;
  2162. FORMATETC fe = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  2163. CString szDisplayName;
  2164. CString szSource;
  2165. CString szExt;
  2166. BOOL fRetVal = TRUE;
  2167. BOOL fOneDropSucceeded = FALSE; //at least one file drop succeeded
  2168. HRESULT hr;
  2169. // always fail if we're in RSOP mode (we're read-only in this mode)
  2170. if (m_pScopePane->m_fRSOP)
  2171. {
  2172. return FALSE;
  2173. }
  2174. //check if the dropped items support HDROP
  2175. //for files dragged from explorer, this is always supported
  2176. if (FAILED(hr = lpDataObject->GetData(&fe, &medium)))
  2177. {
  2178. return FALSE;
  2179. }
  2180. //the data object supports HDROP.
  2181. //this means that files are being dragged & dropped from explorer.
  2182. //crack open the data object to get the names of the files being dropped.
  2183. hDrop = (HDROP)medium.hGlobal;
  2184. //start with MAX_PATH, will work for most cases.
  2185. //if not, we will increase buffer size based on need.
  2186. //but we start with MAX_PATH in an attempt to minimize re-allocations
  2187. szFileName = new TCHAR [cbSize = MAX_PATH];
  2188. nFiles = ::DragQueryFile (hDrop, 0xFFFFFFFF, NULL, 0);
  2189. for (index = 0; index < nFiles; index++)
  2190. {
  2191. //find out the size of the buffer required (including the terminating
  2192. //NULL)
  2193. nRequired = ::DragQueryFile (hDrop, index, NULL, 0) + 1;
  2194. //expand the buffer if necessary. Note that we never contract it.
  2195. //Saves code and time
  2196. if (nRequired > cbSize)
  2197. {
  2198. delete [] szFileName;
  2199. szFileName = new TCHAR [cbSize = nRequired];
  2200. }
  2201. //get the full filename of the file being dropped.
  2202. ::DragQueryFile (hDrop, index, szFileName, cbSize);
  2203. #if 0
  2204. // stevebl - gonna let any file through at this point. If it isn't
  2205. // a valid darwin file, AddMSIPackage will catch it and display an
  2206. // appropriate error.
  2207. //check the file extension
  2208. if (!(GetCapitalizedExt(szFileName, szExt) && TEXT("MSI") == szExt))
  2209. {
  2210. //do we put up an error message here?
  2211. fRetVal = FALSE; //failed for this file. wrong extension
  2212. continue;
  2213. }
  2214. #endif
  2215. //try to get a UNC path
  2216. hr = GetUNCPath (szFileName, szSource);
  2217. if (FAILED(hr))
  2218. {
  2219. CString sz;
  2220. sz.LoadString (IDS_NO_UNIVERSAL_NAME);
  2221. if (IDYES != ::MessageBox (m_pScopePane->m_hwndMainWindow, sz, szSource, MB_YESNO | MB_ICONEXCLAMATION))
  2222. continue;
  2223. }
  2224. //now get the display name for the file.
  2225. iSlashPos = szSource.ReverseFind ('\\');
  2226. if (-1 == iSlashPos)
  2227. szDisplayName = szSource;
  2228. else
  2229. szDisplayName = szSource.Mid (iSlashPos + 1);
  2230. //check the file extension to see if it's a ZAP file
  2231. if (GetCapitalizedExt(szFileName, szExt) && TEXT("ZAP") == szExt)
  2232. {
  2233. if (m_pScopePane->m_fMachine)
  2234. {
  2235. CString szText;
  2236. CString szTitle;
  2237. szText.LoadString(IDS_NO_ZAPS_ALLOWED);
  2238. // only allow ZAP files to be deployed to users
  2239. ::MessageBox(m_pScopePane->m_hwndMainWindow,
  2240. szText,
  2241. szTitle,
  2242. MB_OK | MB_ICONEXCLAMATION);
  2243. hr = E_FAIL;
  2244. }
  2245. else
  2246. {
  2247. hr = m_pScopePane->AddZAPPackage (szSource, szDisplayName);
  2248. }
  2249. }
  2250. else
  2251. {
  2252. hr = m_pScopePane->AddMSIPackage (szSource, szDisplayName);
  2253. }
  2254. if (SUCCEEDED(hr))
  2255. fOneDropSucceeded = TRUE;
  2256. }
  2257. //notify the clients
  2258. if (fOneDropSucceeded && m_pScopePane->m_pIGPEInformation)
  2259. {
  2260. if (FAILED(m_pScopePane->m_pIGPEInformation->PolicyChanged (m_pScopePane->m_fMachine,
  2261. TRUE, &guidExtension,
  2262. m_pScopePane->m_fMachine ? &guidMachSnapin
  2263. : &guidUserSnapin)))
  2264. {
  2265. ReportPolicyChangedError(m_pScopePane->m_hwndMainWindow);
  2266. }
  2267. }
  2268. //keep the environment clean. Pick up your litter.
  2269. delete [] szFileName;
  2270. return fRetVal;
  2271. }
  2272. // This code is needed to ensure that property pages get cleaned up properly.
  2273. // This ensures that when the property sheet is closed all my of property
  2274. // pages that are associated with that property sheet will get deleted.
  2275. LPFNPSPCALLBACK _MMCHookProp;
  2276. UINT CALLBACK HookPropertySheetProp(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp)
  2277. {
  2278. UINT i = _MMCHookProp(hwnd, uMsg, ppsp);
  2279. switch (uMsg)
  2280. {
  2281. case PSPCB_RELEASE:
  2282. delete (CPropertyPage *) ppsp->lParam;
  2283. return TRUE;
  2284. default:
  2285. break;
  2286. }
  2287. return i;
  2288. }
  2289. LRESULT SetPropPageToDeleteOnClose(void * vpsp)
  2290. {
  2291. HRESULT hr = MMCPropPageCallback(vpsp);
  2292. if (SUCCEEDED(hr))
  2293. {
  2294. if (vpsp == NULL)
  2295. return E_POINTER;
  2296. LPPROPSHEETPAGE psp = (LPPROPSHEETPAGE)vpsp;
  2297. if ((void*)psp->pfnCallback == (void*)HookPropertySheetProp)
  2298. return E_UNEXPECTED;
  2299. _MMCHookProp = psp->pfnCallback;
  2300. psp->pfnCallback = HookPropertySheetProp;
  2301. }
  2302. return hr;
  2303. }