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.

310 lines
9.4 KiB

  1. #ifndef BackupSnap_h
  2. #define BackupSnap_h
  3. #include "Backup.h"
  4. #include <winver.h>
  5. #include <objidl.h>
  6. #include <atlsnap.h>
  7. //////////////////////////////////////////////////////////////////////////////////
  8. //
  9. // CBackupSnapNode
  10. //
  11. //////////////////////////////////////////////////////////////////////////////////
  12. class CBackupSnapNode : public CSnapInItemImpl<CBackupSnapNode>
  13. {
  14. public:
  15. static const GUID* m_NODETYPE;
  16. static const OLECHAR* m_SZNODETYPE;
  17. static const OLECHAR* m_SZDISPLAY_NAME;
  18. static const CLSID* m_SNAPIN_CLASSID;
  19. CComPtr<IControlbar> m_spControlBar;
  20. BEGIN_SNAPINCOMMAND_MAP(CBackupSnapNode, FALSE)
  21. END_SNAPINCOMMAND_MAP()
  22. CBackupSnapNode();
  23. virtual ~CBackupSnapNode()
  24. {
  25. }
  26. STDMETHOD(QueryPagesFor)(DATA_OBJECT_TYPES type)
  27. {
  28. if ( type == CCT_SCOPE || type == CCT_RESULT )
  29. return S_OK;
  30. return S_FALSE;
  31. }
  32. STDMETHOD(GetScopePaneInfo)(SCOPEDATAITEM *pScopeDataItem);
  33. STDMETHOD(GetResultPaneInfo)(RESULTDATAITEM *pResultDataItem);
  34. STDMETHOD(Notify)( MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param, IComponentData* pComponentData, IComponent* pComponent, DATA_OBJECT_TYPES type );
  35. LPOLESTR GetResultPaneColInfo(int nCol);
  36. STDMETHOD(GetClassID)(CLSID* pID);
  37. };
  38. class CBackupSnapData;
  39. /////////////////////////////////////////////////////////////////////////////////
  40. //
  41. // CBackupSnapComponent
  42. //
  43. ////////////////////////////////////////////////////////////////////////////////
  44. class CBackupSnapComponent : public CComObjectRootEx<CComSingleThreadModel>,
  45. public CSnapInObjectRoot<2, CBackupSnapData>,
  46. public IComponentImpl<CBackupSnapComponent>
  47. {
  48. public:
  49. BEGIN_COM_MAP(CBackupSnapComponent)
  50. COM_INTERFACE_ENTRY(IComponent)
  51. END_COM_MAP()
  52. public:
  53. CBackupSnapComponent();
  54. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  55. {
  56. if ( lpDataObject != NULL )
  57. {
  58. return IComponentImpl<CBackupSnapComponent>::Notify(lpDataObject, event, arg, param);
  59. }
  60. else if ( event == MMCN_PROPERTY_CHANGE )
  61. {
  62. return S_OK;
  63. }
  64. return E_NOTIMPL;
  65. }
  66. HRESULT GetClassID(CLSID* pID);
  67. STDMETHOD(GetResultViewType)(MMC_COOKIE cookie, LPOLESTR* ppViewType, long* pViewOptions);
  68. };
  69. //////////////////////////////////////////////////////////////////////////////////////////////////
  70. //
  71. // CBackupSnapData
  72. //
  73. /////////////////////////////////////////////////////////////////////////////////////////////////
  74. class CBackupSnapData :
  75. public CComObjectRootEx<CComSingleThreadModel>,
  76. public CSnapInObjectRoot<1, CBackupSnapData>,
  77. public IComponentDataImpl<CBackupSnapData, CBackupSnapComponent>,
  78. public CComCoClass<CBackupSnapData, &CLSID_BackupSnap>,
  79. public ISnapinHelp2
  80. {
  81. public:
  82. CBackupSnapData()
  83. {
  84. // Has to be done in the constructor (Templated Class requires it)
  85. m_pNode = new CBackupSnapNode;
  86. _ASSERT(m_pNode != NULL);
  87. m_pComponentData = this;
  88. }
  89. virtual ~CBackupSnapData()
  90. {
  91. if( m_pNode )
  92. {
  93. delete m_pNode;
  94. m_pNode = NULL;
  95. }
  96. }
  97. BEGIN_COM_MAP(CBackupSnapData)
  98. COM_INTERFACE_ENTRY(IComponentData)
  99. COM_INTERFACE_ENTRY(ISnapinHelp2)
  100. END_COM_MAP()
  101. DECLARE_NOT_AGGREGATABLE(CBackupSnapData)
  102. STDMETHOD(Initialize)(LPUNKNOWN pUnknown);
  103. static void WINAPI ObjectMain(bool bStarting)
  104. {
  105. if ( bStarting )
  106. CSnapInItem::Init();
  107. }
  108. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  109. {
  110. if ( lpDataObject != NULL )
  111. return IComponentDataImpl<CBackupSnapData, CBackupSnapComponent>::Notify(lpDataObject, event, arg, param);
  112. return E_NOTIMPL;
  113. }
  114. STDMETHOD(GetClassID)(CLSID* pID)
  115. {
  116. if( m_pNode )
  117. {
  118. return static_cast<CBackupSnapNode*>(m_pNode)->GetClassID(pID);
  119. }
  120. return E_FAIL;
  121. }
  122. // ISnapinHelp2
  123. STDMETHOD(GetHelpTopic)(LPOLESTR* ppszHelpFile);
  124. STDMETHOD(GetLinkedTopics)(LPOLESTR* ppszHelpFiles);
  125. // Class registration method
  126. static HRESULT WINAPI UpdateRegistry(BOOL bRegister);
  127. };
  128. //////////////////////////////////////////////////////////////////////////////////////////////////////
  129. //
  130. // CBackupSnapAbout
  131. //
  132. /////////////////////////////////////////////////////////////////////////////////////////////////////
  133. class ATL_NO_VTABLE CBackupSnapAbout : public ISnapinAbout,
  134. public CComObjectRoot,
  135. public CComCoClass< CBackupSnapAbout, &CLSID_BackupSnapAbout>
  136. {
  137. public:
  138. DECLARE_REGISTRY(CBackupSnapAbout, _T("BackupSnapAbout.1"), _T("BackupSnapAbout.1"), IDS_BackupSNAP_DESC, THREADFLAGS_BOTH);
  139. HICON m_hIcon;
  140. BEGIN_COM_MAP(CBackupSnapAbout)
  141. COM_INTERFACE_ENTRY(ISnapinAbout)
  142. END_COM_MAP()
  143. CBackupSnapAbout()
  144. {
  145. m_hIcon = NULL;
  146. }
  147. STDMETHOD(GetSnapinDescription)(LPOLESTR *lpDescription)
  148. {
  149. if( !lpDescription ) return E_POINTER;
  150. USES_CONVERSION;
  151. tstring strDescription = StrLoadString(IDS_BackupSNAP_DESC);
  152. if( strDescription.empty() ) return E_FAIL;
  153. *lpDescription = (LPOLESTR)CoTaskMemAlloc((strDescription.length() + 1) * sizeof(OLECHAR));
  154. if ( *lpDescription == NULL ) return E_OUTOFMEMORY;
  155. ocscpy(*lpDescription, T2OLE((LPTSTR)strDescription.c_str()));
  156. return S_OK;
  157. }
  158. STDMETHOD(GetProvider)(LPOLESTR *lpName)
  159. {
  160. if( !lpName ) return E_POINTER;
  161. USES_CONVERSION;
  162. tstring strProvider = StrLoadString(IDS_BackupSNAP_PROVIDER);
  163. if( strProvider.empty() ) return E_FAIL;
  164. *lpName = (LPOLESTR)CoTaskMemAlloc((strProvider.length() + 1) * sizeof(OLECHAR));
  165. if ( *lpName == NULL ) return E_OUTOFMEMORY;
  166. ocscpy( *lpName, T2OLE((LPTSTR)strProvider.c_str()) );
  167. return S_OK;
  168. }
  169. STDMETHOD(GetSnapinVersion)(LPOLESTR *lpVersion)
  170. {
  171. if( !lpVersion ) return E_INVALIDARG;
  172. USES_CONVERSION;
  173. // Get the Module Filename
  174. TCHAR szBuf[MAX_PATH+1] = {0};
  175. DWORD dwLen = GetModuleFileName( _Module.GetModuleInstance(), szBuf, MAX_PATH );
  176. if( (dwLen <= 0) || (dwLen > MAX_PATH) ) return E_FAIL;
  177. // Get the Size and Translation of the file
  178. LPDWORD pTranslation = NULL;
  179. UINT uNumTranslation = 0;
  180. DWORD dwHandle = NULL;
  181. DWORD dwSize = GetFileVersionInfoSize(szBuf, &dwHandle);
  182. if( !dwSize ) return E_FAIL;
  183. BYTE* pVersionInfo = new BYTE[dwSize];
  184. if( !pVersionInfo ) return E_OUTOFMEMORY;
  185. if (!GetFileVersionInfo( szBuf, dwHandle, dwSize, pVersionInfo ) ||
  186. !VerQueryValue( (const LPVOID)pVersionInfo, _T("\\VarFileInfo\\Translation"), (LPVOID*)&pTranslation, &uNumTranslation ) ||
  187. !pTranslation )
  188. {
  189. delete [] pVersionInfo;
  190. pVersionInfo = NULL;
  191. pTranslation = NULL;
  192. uNumTranslation = 0;
  193. return E_FAIL;
  194. }
  195. uNumTranslation /= sizeof(DWORD);
  196. tstring strQuery = _T("\\StringFileInfo\\");
  197. // 8 characters for the language/char-set,
  198. // 1 for the slash,
  199. // 1 for terminating NULL
  200. TCHAR szTranslation[128] = {0};
  201. _sntprintf( szTranslation, 127, _T("%04x%04x\\"), LOWORD(*pTranslation), HIWORD(*pTranslation));
  202. strQuery += szTranslation;
  203. strQuery += _T("FileVersion");
  204. LPBYTE lpVerValue = NULL;
  205. UINT uSize = 0;
  206. if (!VerQueryValue(pVersionInfo, (LPTSTR)strQuery.c_str(), (LPVOID *)&lpVerValue, &uSize))
  207. {
  208. delete [] pVersionInfo;
  209. return E_FAIL;
  210. }
  211. // check the version
  212. _tcsncpy( szBuf, (LPTSTR)lpVerValue, MAX_PATH-1 );
  213. delete [] pVersionInfo;
  214. *lpVersion = (LPOLESTR)CoTaskMemAlloc((lstrlen(szBuf) + 1) * sizeof(OLECHAR));
  215. if( *lpVersion == NULL ) return E_OUTOFMEMORY;
  216. ocscpy( *lpVersion, T2OLE(szBuf) );
  217. return S_OK;
  218. }
  219. STDMETHOD(GetSnapinImage)(HICON* phAppIcon)
  220. {
  221. if( !phAppIcon ) return E_POINTER;
  222. if( !m_hIcon )
  223. {
  224. m_hIcon = LoadIcon(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDI_Icon));
  225. }
  226. *phAppIcon = m_hIcon;
  227. return S_OK;
  228. }
  229. STDMETHOD(GetStaticFolderImage)(HBITMAP* phSmallImage,
  230. HBITMAP* phSmallImageOpen,
  231. HBITMAP* phLargeImage,
  232. COLORREF* pcMask)
  233. {
  234. if( !phSmallImage || !phSmallImageOpen || !phLargeImage || !pcMask ) return E_POINTER;
  235. *phSmallImage = LoadBitmap(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_Small));
  236. *phSmallImageOpen = LoadBitmap(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_Small));
  237. *phLargeImage = LoadBitmap(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_Large));
  238. *pcMask = RGB(255,0,255);
  239. return S_OK;
  240. }
  241. };
  242. #endif