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.

196 lines
3.8 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. root.cpp
  7. Root node information (the root node is not displayed
  8. in the MMC framework but contains information such as
  9. all of the subnodes in this snapin).
  10. FILE HISTORY:
  11. */
  12. #include "stdafx.h"
  13. #include "root.h"
  14. #include "machine.h"
  15. #include "rtrdata.h" // CRouterDataObject
  16. /*---------------------------------------------------------------------------
  17. RootHandler implementation
  18. ---------------------------------------------------------------------------*/
  19. IMPLEMENT_ADDREF_RELEASE(RootHandler)
  20. DEBUG_DECLARE_INSTANCE_COUNTER(RootHandler)
  21. HRESULT RootHandler::QueryInterface(REFIID riid, LPVOID *ppv)
  22. {
  23. // Is the pointer bad?
  24. if (ppv == NULL)
  25. return E_INVALIDARG;
  26. // Place NULL in *ppv in case of failure
  27. *ppv = NULL;
  28. // This is the non-delegating IUnknown implementation
  29. if (riid == IID_IUnknown)
  30. *ppv = (LPVOID) this;
  31. else if (riid == IID_IPersistStreamInit)
  32. *ppv = (IPersistStreamInit *) this;
  33. // If we're going to return an interface, AddRef it first
  34. if (*ppv)
  35. {
  36. ((LPUNKNOWN) *ppv)->AddRef();
  37. return hrOK;
  38. }
  39. else
  40. return BaseRouterHandler::QueryInterface(riid, ppv);
  41. }
  42. RootHandler::RootHandler(ITFSComponentData *pCompData)
  43. : BaseRouterHandler(pCompData)
  44. {
  45. m_spTFSCompData.Set(pCompData);
  46. DEBUG_INCREMENT_INSTANCE_COUNTER(RootHandler)
  47. }
  48. HRESULT RootHandler::Init()
  49. {
  50. return hrOK;
  51. }
  52. /*!--------------------------------------------------------------------------
  53. RootHandler::ConstructNode
  54. Initializes the root node (sets it up).
  55. Author: KennT
  56. ---------------------------------------------------------------------------*/
  57. HRESULT RootHandler::ConstructNode(ITFSNode *pNode)
  58. {
  59. HRESULT hr = hrOK;
  60. if (pNode == NULL)
  61. return hrOK;
  62. COM_PROTECT_TRY
  63. {
  64. // Need to initialize the data for the root node
  65. pNode->SetData(TFS_DATA_IMAGEINDEX, IMAGE_IDX_FOLDER_CLOSED);
  66. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, IMAGE_IDX_FOLDER_OPEN);
  67. pNode->SetData(TFS_DATA_SCOPEID, 0);
  68. pNode->SetData(TFS_DATA_COOKIE, 0);
  69. }
  70. COM_PROTECT_CATCH
  71. return hr;
  72. }
  73. ///////////////////////////////////////////////////////////////////////////////
  74. //// IPersistStream interface members
  75. STDMETHODIMP RootHandler::GetClassID
  76. (
  77. CLSID *pClassID
  78. )
  79. {
  80. ASSERT(pClassID != NULL);
  81. // Copy the CLSID for this snapin
  82. *pClassID = CLSID_RouterSnapin;
  83. return hrOK;
  84. }
  85. STDMETHODIMP RootHandler::IsDirty()
  86. {
  87. SPITFSNode spNode;
  88. m_spTFSCompData->GetRootNode(&spNode);
  89. return (spNode->GetData(TFS_DATA_DIRTY) || GetConfigStream()->GetDirty()) ? hrOK : hrFalse;
  90. }
  91. STDMETHODIMP RootHandler::Load
  92. (
  93. IStream *pStm
  94. )
  95. {
  96. Assert(pStm);
  97. HRESULT hr = hrOK;
  98. CString st;
  99. BOOL fServer;
  100. COM_PROTECT_TRY
  101. {
  102. hr = GetConfigStream()->LoadFrom(pStm);
  103. }
  104. COM_PROTECT_CATCH;
  105. return hr;
  106. }
  107. STDMETHODIMP RootHandler::Save
  108. (
  109. IStream *pStm,
  110. BOOL fClearDirty
  111. )
  112. {
  113. HRESULT hr = S_OK;
  114. SPITFSNode spNode;
  115. Assert(pStm);
  116. COM_PROTECT_TRY
  117. {
  118. if (fClearDirty)
  119. {
  120. m_spTFSCompData->GetRootNode(&spNode);
  121. spNode->SetData(TFS_DATA_DIRTY, FALSE);
  122. }
  123. hr = GetConfigStream()->SaveTo(pStm);
  124. }
  125. COM_PROTECT_CATCH;
  126. return hr;
  127. }
  128. STDMETHODIMP RootHandler::GetSizeMax
  129. (
  130. ULARGE_INTEGER *pcbSize
  131. )
  132. {
  133. ULONG cbSize;
  134. HRESULT hr = hrOK;
  135. COM_PROTECT_TRY
  136. {
  137. hr = GetConfigStream()->GetSize(&cbSize);
  138. if (FHrSucceeded(hr))
  139. {
  140. pcbSize->HighPart = 0;
  141. pcbSize->LowPart = cbSize;
  142. }
  143. }
  144. COM_PROTECT_CATCH;
  145. return hr;
  146. }
  147. STDMETHODIMP RootHandler::InitNew()
  148. {
  149. HRESULT hr = hrOK;
  150. COM_PROTECT_TRY
  151. {
  152. hr = GetConfigStream()->InitNew();
  153. }
  154. COM_PROTECT_CATCH;
  155. return hr;
  156. }