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.

492 lines
15 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright (C) 1995-1996 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Management Console and related
  7. // electronic documentation provided with the interfaces.
  8. // CSnapin.h : Declaration of the CSnapin
  9. #include "resource.h" // main symbols
  10. #ifndef __mmc_h__
  11. #include <mmc.h>
  12. #endif
  13. #include "objidl.h"
  14. #include "data.h"
  15. #include "gpedit.h"
  16. #include "csadmin.hxx"
  17. #include "iads.h"
  18. // Uncomment the following line to turn on machine app deplyoment (user app
  19. // deployment is always on)
  20. #define UGLY_SUBDIRECTORY_HACK 1
  21. // private notifications
  22. #define WM_USER_REFRESH WM_USER
  23. #define WM_USER_CLOSE (WM_USER + 1)
  24. // Note - This is the offset in my image list that represents the folder
  25. const FOLDER_IMAGE_IDX = 0;
  26. const OPEN_FOLDER_IMAGE_IDX = 5;
  27. extern HINSTANCE ghInstance;
  28. extern const CLSID CLSID_Snapin;
  29. extern CLSID CLSID_Temp;
  30. extern const wchar_t * szCLSID_Snapin;
  31. extern const CLSID CLSID_MachineSnapin;
  32. extern const wchar_t * szCLSID_MachineSnapin;
  33. extern const GUID cNodeType;
  34. extern const wchar_t* cszNodeType;
  35. typedef enum NEW_PACKAGE_BEHAVIORS
  36. {
  37. NP_WIZARD = 0,
  38. NP_PROPPAGE,
  39. NP_DISABLED,
  40. NP_PUBLISHED,
  41. NP_ASSIGNED
  42. } NEW_PACKAGE_BEHAVIOR;
  43. #define IMG_FOLDER 0
  44. #define IMG_DISABLED 1
  45. #define IMG_PUBLISHED 2
  46. #define IMG_ASSIGNED 3
  47. #define IMG_UPGRADE 4
  48. #define CFGFILE _T("ADE.CFG")
  49. //
  50. // MACROS for allocating and freeing memory via OLE's common allocator: IMalloc.
  51. //
  52. extern IMalloc * g_pIMalloc;
  53. // UNDONE - throw exception on failure
  54. //#define OLEALLOC(x) new char [x]
  55. #define OLEALLOC(x) g_pIMalloc->Alloc(x)
  56. //#define OLESAFE_DELETE(x) if (x) {delete x; x = NULL;}
  57. #define OLESAFE_DELETE(x) if (x) {g_pIMalloc->Free(x); x = NULL;}
  58. #define OLESAFE_COPYSTRING(szO, szI) {if (szI) {int i = wcslen(szI); szO=(OLECHAR *)OLEALLOC(sizeof(OLECHAR) * (i+1)); wcscpy(szO, szI);} else szO=NULL;}
  59. // Keys used in the CFG file.
  60. //
  61. // The CFG file is found in the Applications directory of the SysVol (which
  62. // is the same directory as the script files).
  63. //
  64. // The format of an entry in the CFG file is:
  65. //
  66. // %key%=%data%
  67. //
  68. // where %data% is either an integer or a string as appropriate.
  69. //
  70. // Order is not important and if a key is not present in the CFG file then
  71. // the default setting will be used. Some keys (iDebugLevel and
  72. // fShowPkgDetails) will only be saved in the CFG file if their values are
  73. // different from the default settings.
  74. //
  75. #define KEY_NPBehavior L"New Package Behavior"
  76. #define KEY_fAutoInstall L"Auto Install"
  77. #define KEY_UILevel L"UI Level"
  78. #define KEY_szStartPath L"Start Path"
  79. #define KEY_iDebugLevel L"Debug Level"
  80. #define KEY_fShowPkgDetails L"Package Details"
  81. typedef struct tagTOOL_DEFAULTS
  82. {
  83. NEW_PACKAGE_BEHAVIOR NPBehavior;
  84. BOOL fAutoInstall;
  85. INSTALLUILEVEL UILevel;
  86. CString szStartPath;
  87. int iDebugLevel;
  88. BOOL fShowPkgDetails;
  89. } TOOL_DEFAULTS;
  90. /////////////////////////////////////////////////////////////////////////////
  91. // Snapin
  92. typedef std::set<long> EXTLIST;
  93. INTERNAL* ExtractInternalFormat(LPDATAOBJECT lpDataObject);
  94. class CToolDefs;
  95. class CCatList;
  96. class CFileExt;
  97. class CComponentDataImpl:
  98. public IComponentData,
  99. public IExtendContextMenu,
  100. public IPersistStreamInit,
  101. public CComObjectRoot,
  102. public IExtendPropertySheet
  103. {
  104. friend class CSnapin;
  105. friend class CDataObject;
  106. public:
  107. CComponentDataImpl();
  108. ~CComponentDataImpl();
  109. protected:
  110. LPGPEINFORMATION m_pIGPEInformation; // Interface pointer to the GPT
  111. public:
  112. virtual IUnknown * GetMyUnknown() = 0;
  113. // IComponentData interface members
  114. STDMETHOD(Initialize)(LPUNKNOWN pUnknown);
  115. STDMETHOD(CreateComponent)(LPCOMPONENT* ppComponent);
  116. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, long arg, long param);
  117. STDMETHOD(Destroy)();
  118. STDMETHOD(QueryDataObject)(long cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject);
  119. STDMETHOD(GetDisplayInfo)(SCOPEDATAITEM* pScopeDataItem);
  120. STDMETHOD(CompareObjects)(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  121. // IExtendContextMenu
  122. public:
  123. STDMETHOD(AddMenuItems)(LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK pCallbackUnknown, LONG * pInsertionAllowed);
  124. STDMETHOD(Command)(long nCommandID, LPDATAOBJECT pDataObject);
  125. public:
  126. // IPersistStreamInit interface members
  127. STDMETHOD(GetClassID)(CLSID *pClassID);
  128. STDMETHOD(IsDirty)();
  129. STDMETHOD(Load)(IStream *pStm);
  130. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty);
  131. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize);
  132. STDMETHOD(InitNew)(VOID);
  133. // IExtendPropertySheet interface
  134. public:
  135. STDMETHOD(CreatePropertyPages)(LPPROPERTYSHEETCALLBACK lpProvider,
  136. long handle,
  137. LPDATAOBJECT lpIDataObject);
  138. STDMETHOD(QueryPagesFor)(LPDATAOBJECT lpDataObject);
  139. // Notify handler declarations
  140. private:
  141. HRESULT OnAdd(long cookie, long arg, long param);
  142. HRESULT OnDelete(long cookie, long arg, long param);
  143. HRESULT OnRename(long cookie, long arg, long param);
  144. HRESULT OnExpand(long cookie, long arg, long param);
  145. HRESULT OnSelect(long cookie, long arg, long param);
  146. HRESULT OnContextMenu(long cookie, long arg, long param);
  147. HRESULT OnProperties(long param);
  148. STDMETHOD(ChangePackageState)(APP_DATA & data, DWORD dwNewFlags, BOOL fShowUI);
  149. #if DBG==1
  150. public:
  151. ULONG InternalAddRef()
  152. {
  153. return CComObjectRoot::InternalAddRef();
  154. }
  155. ULONG InternalRelease()
  156. {
  157. return CComObjectRoot::InternalRelease();
  158. }
  159. #endif // DBG==1
  160. // Scope item creation helpers
  161. private:
  162. void DeleteList();
  163. void EnumerateScopePane(long cookie, HSCOPEITEM pParent);
  164. BOOL IsScopePaneNode(LPDATAOBJECT lpDataObject);
  165. HRESULT InitializeClassAdmin();
  166. HRESULT AddMSIPackage(LPCOLESTR szPackagePath,
  167. LPCOLESTR lpFileTitle);
  168. void GetUniquePackageName(CString &sz);
  169. HRESULT RemovePackage(long cookie);
  170. private:
  171. LPCONSOLENAMESPACE m_pScope; // My interface pointer to the scope pane
  172. LPCONSOLE m_pConsole;
  173. BOOL m_bIsDirty;
  174. IClassAdmin * m_pIClassAdmin;
  175. BOOL m_fExtension;
  176. BOOL m_fLoaded;
  177. // global property pages
  178. CToolDefs * m_pToolDefs;
  179. CCatList * m_pCatList;
  180. CFileExt * m_pFileExt;
  181. void SetDirty(BOOL b = TRUE) { m_bIsDirty = b; }
  182. void ClearDirty() { m_bIsDirty = FALSE; }
  183. BOOL ThisIsDirty() { return m_bIsDirty; }
  184. void AddScopeItemToResultPane(long cookie);
  185. UINT CreateNestedDirectory (LPTSTR lpPath, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
  186. HRESULT GetClassStore(void);
  187. void LoadToolDefaults();
  188. void SaveToolDefaults();
  189. HRESULT PopulateUpgradeLists();
  190. HRESULT InsertUpgradeEntry(long cookie, APP_DATA &data);
  191. HRESULT RemoveUpgradeEntry(long cookie, APP_DATA &data);
  192. HRESULT PopulateExtensions();
  193. HRESULT InsertExtensionEntry(long cookie, APP_DATA &data);
  194. HRESULT RemoveExtensionEntry(long cookie, APP_DATA &data);
  195. HRESULT PrepareExtensions(PACKAGEDETAIL &pd);
  196. CSnapin * m_pSnapin;
  197. public:
  198. CString m_szGPT_Path;
  199. CString m_szGPTRoot;
  200. CString m_szScriptRoot;
  201. CString m_szLDAP_Path;
  202. CString m_szFolderTitle;
  203. std::map <long, APP_DATA> m_AppData; // One entry for each
  204. // application in the class
  205. // store. Maps cookies to
  206. // application packages.
  207. std::map <CString, EXTLIST> m_Extensions; // Maps extensions to the
  208. // list of apps that support
  209. // them.
  210. std::map <CString, long> m_ScriptIndex; // Maps script names to the
  211. // apps that they belong to.
  212. TOOL_DEFAULTS m_ToolDefaults;
  213. BOOL m_fMachine;
  214. long m_lLastAllocated;
  215. };
  216. class CMachineComponentDataImpl:
  217. public CComponentDataImpl,
  218. public CComCoClass<CMachineComponentDataImpl, &CLSID_MachineSnapin>
  219. {
  220. public:
  221. DECLARE_REGISTRY(CSnapin, _T("AppManager.1"), _T("AppManager"), IDS_SNAPIN_DESC, THREADFLAGS_BOTH)
  222. BEGIN_COM_MAP(CMachineComponentDataImpl)
  223. COM_INTERFACE_ENTRY(IComponentData)
  224. COM_INTERFACE_ENTRY(IExtendContextMenu)
  225. COM_INTERFACE_ENTRY(IPersistStreamInit)
  226. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  227. END_COM_MAP()
  228. CMachineComponentDataImpl()
  229. {
  230. m_fMachine = TRUE;
  231. }
  232. virtual IUnknown * GetMyUnknown() {return GetUnknown();};
  233. };
  234. class CUserComponentDataImpl:
  235. public CComponentDataImpl,
  236. public CComCoClass<CUserComponentDataImpl, &CLSID_Snapin>
  237. {
  238. public:
  239. DECLARE_REGISTRY(CSnapin, _T("AppManager.1"), _T("AppManager"), IDS_SNAPIN_DESC, THREADFLAGS_BOTH)
  240. BEGIN_COM_MAP(CUserComponentDataImpl)
  241. COM_INTERFACE_ENTRY(IComponentData)
  242. COM_INTERFACE_ENTRY(IExtendContextMenu)
  243. COM_INTERFACE_ENTRY(IPersistStreamInit)
  244. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  245. END_COM_MAP()
  246. CUserComponentDataImpl()
  247. {
  248. m_fMachine = FALSE;
  249. }
  250. virtual IUnknown * GetMyUnknown() {return GetUnknown();};
  251. };
  252. class CSnapin :
  253. public IComponent,
  254. public IExtendContextMenu, // Step 3
  255. // public IExtendControlbar,
  256. public IExtendPropertySheet,
  257. public IResultDataCompare,
  258. public CComObjectRoot
  259. {
  260. public:
  261. CSnapin();
  262. ~CSnapin();
  263. BEGIN_COM_MAP(CSnapin)
  264. COM_INTERFACE_ENTRY(IComponent)
  265. COM_INTERFACE_ENTRY(IExtendContextMenu) // Step 3
  266. // COM_INTERFACE_ENTRY(IExtendControlbar)
  267. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  268. COM_INTERFACE_ENTRY(IResultDataCompare)
  269. END_COM_MAP()
  270. friend class CDataObject;
  271. static long lDataObjectRefCount;
  272. // IComponent interface members
  273. public:
  274. STDMETHOD(Initialize)(LPCONSOLE lpConsole);
  275. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, long arg, long param);
  276. STDMETHOD(Destroy)(long cookie);
  277. STDMETHOD(GetResultViewType)(long cookie, BSTR* ppViewType, LONG * pViewOptions);
  278. STDMETHOD(QueryDataObject)(long cookie, DATA_OBJECT_TYPES type,
  279. LPDATAOBJECT* ppDataObject);
  280. STDMETHOD(GetDisplayInfo)(RESULTDATAITEM* pResultDataItem);
  281. STDMETHOD(CompareObjects)(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  282. // IResultDataCompare
  283. STDMETHOD(Compare)(long lUserParam, long cookieA, long cookieB, int* pnResult);
  284. // IExtendControlbar
  285. // STDMETHOD(SetControlbar)(LPCONTROLBAR pControlbar);
  286. // STDMETHOD(ControlbarNotify)(MMC_NOTIFY_TYPE event, long arg, long param);
  287. // IExtendPropertySheet interface
  288. public:
  289. STDMETHOD(CreatePropertyPages)(LPPROPERTYSHEETCALLBACK lpProvider,
  290. long handle,
  291. LPDATAOBJECT lpIDataObject);
  292. STDMETHOD(QueryPagesFor)(LPDATAOBJECT lpDataObject);
  293. // Helpers for CSnapin
  294. public:
  295. void SetIComponentData(CComponentDataImpl* pData);
  296. #if DBG==1
  297. public:
  298. int dbg_cRef;
  299. ULONG InternalAddRef()
  300. {
  301. ++dbg_cRef;
  302. return CComObjectRoot::InternalAddRef();
  303. }
  304. ULONG InternalRelease()
  305. {
  306. --dbg_cRef;
  307. return CComObjectRoot::InternalRelease();
  308. }
  309. #endif // DBG==1
  310. // Notify event handlers
  311. protected:
  312. HRESULT OnFolder(long cookie, long arg, long param);
  313. HRESULT OnShow(long cookie, long arg, long param);
  314. HRESULT OnActivate(long cookie, long arg, long param);
  315. HRESULT OnMinimize(long cookie, long arg, long param);
  316. HRESULT OnSelect(DATA_OBJECT_TYPES type, long cookie, long arg, long param);
  317. HRESULT OnPropertyChange(long param); // Step 3
  318. HRESULT OnUpdateView(LPDATAOBJECT lpDataObject);
  319. HRESULT OnResultItemClkOrDblClk(long cookie, BOOL fDblClick);
  320. HRESULT OnAddImages(long cookie, long arg, long param);
  321. // IExtendContextMenu
  322. public:
  323. STDMETHOD(AddMenuItems)(LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK pCallbackUnknown, LONG * pInsertionAllowed);
  324. STDMETHOD(Command)(long nCommandID, LPDATAOBJECT pDataObject);
  325. // End step 3
  326. // Helper functions
  327. protected:
  328. BOOL IsEnumerating(LPDATAOBJECT lpDataObject);
  329. void Construct();
  330. void LoadResources();
  331. HRESULT InitializeHeaders(long cookie);
  332. void Enumerate(long cookie, HSCOPEITEM pParent);
  333. HRESULT InitializeBitmaps(long cookie);
  334. public:
  335. void EnumerateResultPane(long cookie);
  336. // Interface pointers
  337. protected:
  338. LPCONSOLE m_pConsole; // Console's IFrame interface
  339. LPHEADERCTRL m_pHeader; // Result pane's header control interface
  340. CComponentDataImpl * m_pComponentData;
  341. IPropertySheetProvider * m_pIPropertySheetProvider;
  342. LPCONSOLEVERB m_pConsoleVerb; // pointer the console verb
  343. LONG m_lViewMode; // View mode
  344. public:
  345. LPRESULTDATA m_pResult; // My interface pointer to the result pane
  346. LPIMAGELIST m_pImageResult; // My interface pointer to the result pane image list
  347. protected:
  348. // LPTOOLBAR m_pToolbar1; // Toolbar for view
  349. // LPTOOLBAR m_pToolbar2; // Toolbar for view
  350. // LPCONTROLBAR m_pControlbar; // control bar to hold my tool bars
  351. // CBitmap* m_pbmpToolbar1; // Imagelist for the first toolbar
  352. // CBitmap* m_pbmpToolbar2; // Imagelist for the first toolbar
  353. IClassAdmin * m_pIClassAdmin;
  354. // Header titles for each nodetype(s)
  355. protected:
  356. CString m_column1;
  357. CString m_column2;
  358. CString m_column3;
  359. CString m_column4;
  360. CString m_column5;
  361. CString m_column6;
  362. CString m_column7;
  363. CString m_column8;
  364. CString m_column9;
  365. CString m_column10;
  366. CString m_column11;
  367. CString m_szAddApp;
  368. CString m_szDelApp;
  369. CString m_szUpdateApp;
  370. CString m_szAddFromIe;
  371. CString m_szShowData;
  372. CString m_szAddAppDesc;
  373. CString m_szDelAppDesc;
  374. CString m_szUpdateAppDesc;
  375. CString m_szAddFromIeDesc;
  376. CString m_szShowDataDesc;
  377. CString m_szFolderTitle;
  378. CString m_szRefresh;
  379. CString m_szRefreshDesc;
  380. };
  381. inline void CSnapin::SetIComponentData(CComponentDataImpl* pData)
  382. {
  383. ASSERT(pData);
  384. ASSERT(m_pComponentData == NULL);
  385. LPUNKNOWN pUnk = pData->GetMyUnknown();
  386. HRESULT hr;
  387. LPCOMPONENTDATA lpcd;
  388. hr = pUnk->QueryInterface(IID_IComponentData, reinterpret_cast<void**>(&lpcd));
  389. ASSERT(hr == S_OK);
  390. m_pComponentData = dynamic_cast<CComponentDataImpl*>(lpcd);
  391. }
  392. #define FREE_INTERNAL(pInternal) \
  393. ASSERT(pInternal != NULL); \
  394. do { if (pInternal != NULL) \
  395. GlobalFree(pInternal); } \
  396. while(0);
  397. class CHourglass
  398. {
  399. private:
  400. HCURSOR m_hcurSaved;
  401. public:
  402. CHourglass()
  403. {
  404. m_hcurSaved = ::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT)));
  405. };
  406. ~CHourglass()
  407. {
  408. ::SetCursor(m_hcurSaved);
  409. };
  410. };
  411. #define ATOW(wsz, sz, cch) MultiByteToWideChar(CP_ACP, 0, sz, -1, wsz, cch)
  412. #define WTOA(sz, wsz, cch) WideCharToMultiByte(CP_ACP, 0, wsz, -1, sz, cch, NULL, NULL)
  413. #define ATOWLEN(sz) MultiByteToWideChar(CP_ACP, 0, sz, -1, NULL, 0)
  414. #define WTOALEN(wsz) WideCharToMultiByte(CP_ACP, 0, wsz, -1, NULL, 0, NULL, NULL)