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.

373 lines
11 KiB

  1. #include "stdafx.h"
  2. #include "BackupSnap.h"
  3. #include "Backup.h"
  4. /////////////////////////////////////////////////////////////////////////////
  5. /////////////////////////////////////////////////////////////////////////////
  6. //
  7. // CBackupSnapNode
  8. //
  9. /////////////////////////////////////////////////////////////////////////////
  10. /////////////////////////////////////////////////////////////////////////////
  11. static const GUID CBackupSnapGUID_NODETYPE =
  12. { 0x3fa55cce, 0x7d0a, 0x4b5c, { 0x90, 0xe9, 0x6e, 0x8c, 0xcb, 0x77, 0x5b, 0x23 } };
  13. const GUID* CBackupSnapNode::m_NODETYPE = &CBackupSnapGUID_NODETYPE;
  14. const OLECHAR* CBackupSnapNode::m_SZNODETYPE = OLESTR("3FA55CCE-7D0A-4b5c-90E9-6E8CCB775B23");
  15. const OLECHAR* CBackupSnapNode::m_SZDISPLAY_NAME = OLESTR("");
  16. const CLSID* CBackupSnapNode::m_SNAPIN_CLASSID = &CLSID_BackupSnap;
  17. CBackupSnapNode::CBackupSnapNode()
  18. {
  19. // Initialize Scope Data Information
  20. memset(&m_scopeDataItem, 0, sizeof(m_scopeDataItem));
  21. m_scopeDataItem.mask = SDI_STR | SDI_IMAGE | SDI_OPENIMAGE | SDI_PARAM;
  22. m_scopeDataItem.displayname = L"";
  23. m_scopeDataItem.nImage = 0;
  24. m_scopeDataItem.nOpenImage = 0;
  25. m_scopeDataItem.lParam = (LPARAM) this;
  26. // Initialize Result Data Information
  27. memset(&m_resultDataItem, 0, sizeof(m_resultDataItem));
  28. m_resultDataItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  29. m_resultDataItem.str = L"";
  30. m_resultDataItem.nImage = 0;
  31. m_resultDataItem.lParam = (LPARAM) this;
  32. // Load the Snap-In Display Name
  33. tstring strTemp = StrLoadString( IDS_SnapinName );
  34. m_bstrDisplayName = strTemp.c_str();
  35. if( m_bstrDisplayName.m_str )
  36. {
  37. m_SZDISPLAY_NAME = m_bstrDisplayName.m_str;
  38. }
  39. }
  40. HRESULT CBackupSnapNode::GetScopePaneInfo(SCOPEDATAITEM *pScopeDataItem)
  41. {
  42. if( !pScopeDataItem ) return E_POINTER;
  43. if( pScopeDataItem->mask & SDI_STR )
  44. pScopeDataItem->displayname = m_bstrDisplayName;
  45. if( pScopeDataItem->mask & SDI_IMAGE )
  46. pScopeDataItem->nImage = m_scopeDataItem.nImage;
  47. if( pScopeDataItem->mask & SDI_OPENIMAGE )
  48. pScopeDataItem->nOpenImage = m_scopeDataItem.nOpenImage;
  49. if( pScopeDataItem->mask & SDI_PARAM )
  50. pScopeDataItem->lParam = m_scopeDataItem.lParam;
  51. if( pScopeDataItem->mask & SDI_STATE )
  52. pScopeDataItem->nState = m_scopeDataItem.nState;
  53. return S_OK;
  54. }
  55. HRESULT CBackupSnapNode::GetResultPaneInfo(RESULTDATAITEM *pResultDataItem)
  56. {
  57. if( !pResultDataItem ) return E_POINTER;
  58. if( pResultDataItem->bScopeItem )
  59. {
  60. if( pResultDataItem->mask & RDI_STR )
  61. {
  62. pResultDataItem->str = L"";
  63. }
  64. if( pResultDataItem->mask & RDI_IMAGE )
  65. {
  66. pResultDataItem->nImage = m_scopeDataItem.nImage;
  67. }
  68. if( pResultDataItem->mask & RDI_PARAM )
  69. {
  70. pResultDataItem->lParam = m_scopeDataItem.lParam;
  71. }
  72. return S_OK;
  73. }
  74. if( pResultDataItem->mask & RDI_STR )
  75. {
  76. pResultDataItem->str = L"";
  77. }
  78. if( pResultDataItem->mask & RDI_IMAGE )
  79. {
  80. pResultDataItem->nImage = m_resultDataItem.nImage;
  81. }
  82. if( pResultDataItem->mask & RDI_PARAM )
  83. {
  84. pResultDataItem->lParam = m_resultDataItem.lParam;
  85. }
  86. if( pResultDataItem->mask & RDI_INDEX )
  87. {
  88. pResultDataItem->nIndex = m_resultDataItem.nIndex;
  89. }
  90. return S_OK;
  91. }
  92. HRESULT CBackupSnapNode::GetClassID(CLSID* pID)
  93. {
  94. if( !pID ) return E_POINTER;
  95. pID = (CLSID*)m_SNAPIN_CLASSID;
  96. return S_OK;
  97. }
  98. HRESULT CBackupSnapNode::Notify( MMC_NOTIFY_TYPE event,
  99. LPARAM arg,
  100. LPARAM param,
  101. IComponentData* pComponentData,
  102. IComponent* pComponent,
  103. DATA_OBJECT_TYPES type)
  104. {
  105. HRESULT hr = S_FALSE;
  106. _ASSERT( pComponentData || pComponent );
  107. CComPtr<IConsole> spConsole = NULL;
  108. if( pComponentData )
  109. {
  110. spConsole = ((CBackupSnapData*)pComponentData)->m_spConsole;
  111. }
  112. else if ( pComponent )
  113. {
  114. spConsole = ((CBackupSnapComponent*)pComponent)->m_spConsole;
  115. }
  116. if( !spConsole ) return E_INVALIDARG;
  117. switch( event )
  118. {
  119. case MMCN_SHOW:
  120. {
  121. hr = S_OK;
  122. // configure the ocx message in the result pane
  123. IMessageView* pIMessageView = NULL;
  124. LPUNKNOWN pIUnk = NULL;
  125. hr = spConsole->QueryResultView(&pIUnk);
  126. if( SUCCEEDED(hr) )
  127. {
  128. hr = pIUnk->QueryInterface(_uuidof(IMessageView), reinterpret_cast<void**>(&pIMessageView));
  129. }
  130. if( SUCCEEDED(hr) )
  131. {
  132. hr = pIMessageView->SetIcon(Icon_Information);
  133. }
  134. if( SUCCEEDED(hr) )
  135. {
  136. tstring strTitle = StrLoadString( IDS_SnapinName );
  137. hr = pIMessageView->SetTitleText( strTitle.c_str() );
  138. }
  139. if( SUCCEEDED(hr) )
  140. {
  141. tstring strMessage = StrLoadString( IDS_WARNING );
  142. hr = pIMessageView->SetBodyText( strMessage.c_str() );
  143. }
  144. if( pIMessageView )
  145. {
  146. pIMessageView->Release();
  147. pIMessageView = NULL;
  148. }
  149. break;
  150. }
  151. case MMCN_EXPAND:
  152. {
  153. hr = S_OK;
  154. break;
  155. }
  156. case MMCN_ADD_IMAGES:
  157. {
  158. IImageList* pImageList = (IImageList*)arg;
  159. if( !pImageList ) return E_INVALIDARG;
  160. hr = LoadImages(pImageList);
  161. break;
  162. }
  163. case MMCN_SELECT:
  164. {
  165. // if selecting node
  166. if( HIWORD(arg) )
  167. {
  168. hr = S_OK;
  169. // get the verb interface and enable rename
  170. CComPtr<IConsoleVerb> spConsVerb;
  171. if( spConsole->QueryConsoleVerb(&spConsVerb) == S_OK )
  172. {
  173. hr = spConsVerb->SetVerbState(MMC_VERB_RENAME, ENABLED, FALSE);
  174. if( FAILED(hr) ) return hr;
  175. spConsVerb->SetVerbState(MMC_VERB_RENAME, HIDDEN, TRUE);
  176. if( FAILED(hr) ) return hr;
  177. }
  178. }
  179. break;
  180. }
  181. case MMCN_CONTEXTHELP:
  182. {
  183. hr = S_OK;
  184. TCHAR szWindowsDir[MAX_PATH+1] = {0};
  185. tstring strHelpFile = _T("");
  186. tstring strHelpFileName = StrLoadString(IDS_HELPFILE);
  187. tstring strHelpTopicName = StrLoadString(IDS_HELPTOPIC);
  188. if( strHelpFileName.empty() || strHelpTopicName.empty() )
  189. {
  190. return E_FAIL;
  191. }
  192. // Build path to %systemroot%\help
  193. UINT nSize = GetSystemWindowsDirectory( szWindowsDir, MAX_PATH );
  194. if( nSize == 0 || nSize > MAX_PATH )
  195. {
  196. return E_FAIL;
  197. }
  198. strHelpFile = szWindowsDir; // D:\windows
  199. strHelpFile += _T("\\Help\\"); // \help
  200. strHelpFile += strHelpFileName; // \filename.chm
  201. strHelpFile += _T("::/"); // ::/
  202. strHelpFile += strHelpTopicName; // index.htm
  203. // Show the Help topic
  204. CComQIPtr<IDisplayHelp> spHelp = spConsole;
  205. if( !spHelp ) return E_NOINTERFACE;
  206. hr = spHelp->ShowTopic( (LPTSTR)strHelpFile.c_str() );
  207. break;
  208. }
  209. }// switch
  210. return hr;
  211. }
  212. ////////////////////////////////////////////////////////////////////////////////////////////////////
  213. //////////////////////////////////////////////////////////////////////////////////////////////////
  214. //
  215. // CBackupSnapData
  216. //
  217. //////////////////////////////////////////////////////////////////////////////////////////////////
  218. ////////////////////////////////////////////////////////////////////////////////////////////////////
  219. HRESULT CBackupSnapData::Initialize(LPUNKNOWN pUnknown)
  220. {
  221. if( !pUnknown ) return E_POINTER;
  222. HRESULT hr = IComponentDataImpl<CBackupSnapData, CBackupSnapComponent >::Initialize(pUnknown);
  223. if( FAILED(hr) ) return hr;
  224. CComPtr<IImageList> spImageList;
  225. if( m_spConsole->QueryScopeImageList(&spImageList) != S_OK )
  226. {
  227. ATLTRACE(_T("IConsole::QueryScopeImageList failed\n"));
  228. return E_UNEXPECTED;
  229. }
  230. hr = LoadImages(spImageList);
  231. return hr;
  232. }
  233. HRESULT WINAPI CBackupSnapData::UpdateRegistry(BOOL bRegister)
  234. {
  235. // Load snap-in name
  236. tstring strSnapinName = StrLoadString(IDS_SnapinName);
  237. // Specify the substitution parameters for IRegistrar.
  238. _ATL_REGMAP_ENTRY rgEntries[] =
  239. {
  240. {TEXT("SNAPIN_NAME"), strSnapinName.c_str()},
  241. {NULL, NULL},
  242. };
  243. // Register the component data object
  244. return _Module.UpdateRegistryFromResource(IDR_BackupSNAP, bRegister, rgEntries);
  245. }
  246. HRESULT CBackupSnapData::GetHelpTopic(LPOLESTR* ppszHelpFile)
  247. {
  248. if( !ppszHelpFile ) return E_POINTER;
  249. USES_CONVERSION;
  250. *ppszHelpFile = NULL;
  251. tstring strHelpFileName = StrLoadString(IDS_HELPFILE);
  252. if( strHelpFileName.empty() ) return E_FAIL;
  253. // Build path to %systemroot%\help
  254. TCHAR szWindowsDir[MAX_PATH+1] = {0};
  255. UINT nSize = GetSystemWindowsDirectory( szWindowsDir, MAX_PATH );
  256. if( (nSize == 0) || (nSize > MAX_PATH) ) return E_FAIL;
  257. tstring strHelpFile = szWindowsDir; // D:\windows
  258. strHelpFile += _T("\\Help\\"); // \help
  259. strHelpFile += strHelpFileName; // \filename.chm
  260. // Show the Help topic
  261. // Form file path in allocated buffer
  262. int nLen = strHelpFile.length() + 1;
  263. *ppszHelpFile = (LPOLESTR)CoTaskMemAlloc(nLen * sizeof(OLECHAR));
  264. if( !*ppszHelpFile ) return E_OUTOFMEMORY;
  265. // Copy into allocated buffer
  266. ocscpy( *ppszHelpFile, T2OLE((LPTSTR)strHelpFile.c_str()) );
  267. return S_OK;
  268. }
  269. HRESULT CBackupSnapData::GetLinkedTopics(LPOLESTR* ppszLinkedFiles)
  270. {
  271. if( !ppszLinkedFiles ) return E_POINTER;
  272. // no linked files
  273. *ppszLinkedFiles = NULL;
  274. return S_FALSE;
  275. }
  276. ////////////////////////////////////////////////////////////////////////////////////////////
  277. //////////////////////////////////////////////////////////////////////////////////////////////
  278. //
  279. // CBackupSnapComponent
  280. //
  281. //////////////////////////////////////////////////////////////////////////////////////////////
  282. //////////////////////////////////////////////////////////////////////////////////////////////
  283. CBackupSnapComponent::CBackupSnapComponent()
  284. {
  285. }
  286. HRESULT CBackupSnapComponent::GetClassID(CLSID* pID)
  287. {
  288. return m_pComponentData->GetClassID(pID);
  289. }
  290. HRESULT CBackupSnapComponent::GetResultViewType( MMC_COOKIE cookie, LPOLESTR* ppViewType, long* pViewOptions )
  291. {
  292. if( !ppViewType ) return E_POINTER;
  293. // show standard MMC OCX with message in the result pane
  294. HRESULT hr = StringFromCLSID(CLSID_MessageView, ppViewType);
  295. return hr;
  296. }