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.

307 lines
8.3 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. UserSettings.cpp
  5. Abstract:
  6. This file contains the implementation of the CPCHUserSettings class,
  7. that contains the user's settings on the service side.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 04/15/2000
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. ////////////////////////////////////////////////////////////////////////////////
  14. CPCHUserSettings::CPCHUserSettings()
  15. {
  16. m_fAttached = false; // bool m_fAttached;
  17. // Taxonomy::Settings m_ts;
  18. }
  19. CPCHUserSettings::~CPCHUserSettings()
  20. {
  21. Passivate();
  22. }
  23. void CPCHUserSettings::Passivate()
  24. {
  25. if(m_fAttached)
  26. {
  27. (void)Taxonomy::InstalledInstanceStore::s_GLOBAL->InUse_Unlock( m_ts );
  28. m_fAttached = false;
  29. }
  30. }
  31. HRESULT CPCHUserSettings::InitUserSettings( /*[out]*/ Taxonomy::HelpSet& ths )
  32. {
  33. MPC::SmartLock<_ThreadModel> lock( this );
  34. ths = m_ts;
  35. return S_OK;
  36. }
  37. ////////////////////////////////////////
  38. HRESULT CPCHUserSettings::get_SKU( /*[in]*/ bool fMachine, /*[out, retval]*/ IPCHSetOfHelpTopics* *pVal )
  39. {
  40. __HCP_FUNC_ENTRY( "CPCHUserSettings::get_SKU" );
  41. HRESULT hr;
  42. MPC::SmartLock<_ThreadModel> lock( this );
  43. Taxonomy::LockingHandle handle;
  44. Taxonomy::InstalledInstanceIter it;
  45. bool fFound;
  46. __MPC_PARAMCHECK_BEGIN(hr)
  47. __MPC_PARAMCHECK_POINTER_AND_SET(pVal,NULL);
  48. __MPC_PARAMCHECK_END();
  49. __MPC_EXIT_IF_METHOD_FAILS(hr, Taxonomy::InstalledInstanceStore::s_GLOBAL->GrabControl( handle ));
  50. __MPC_EXIT_IF_METHOD_FAILS(hr, Taxonomy::InstalledInstanceStore::s_GLOBAL->SKU_Find ( fMachine ? Taxonomy::HelpSet() : m_ts, fFound, it ));
  51. if(fFound)
  52. {
  53. CComPtr<CPCHSetOfHelpTopics> pObj;
  54. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pObj ));
  55. __MPC_EXIT_IF_METHOD_FAILS(hr, pObj->Init( it->m_inst ));
  56. *pVal = pObj.Detach();
  57. }
  58. else
  59. {
  60. if(fMachine)
  61. {
  62. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_FILE_NOT_FOUND);
  63. }
  64. __MPC_EXIT_IF_METHOD_FAILS(hr, get_SKU( true, pVal ));
  65. }
  66. hr = S_OK;
  67. __HCP_FUNC_CLEANUP;
  68. __HCP_FUNC_EXIT(hr);
  69. }
  70. STDMETHODIMP CPCHUserSettings::get_CurrentSKU( /*[out, retval]*/ IPCHSetOfHelpTopics* *pVal )
  71. {
  72. return get_SKU( false, pVal );
  73. }
  74. STDMETHODIMP CPCHUserSettings::get_MachineSKU( /*[out, retval]*/ IPCHSetOfHelpTopics* *pVal )
  75. {
  76. return get_SKU( true, pVal );
  77. }
  78. ////////////////////
  79. STDMETHODIMP CPCHUserSettings::get_HelpLocation( /*[out, retval]*/ BSTR *pVal )
  80. {
  81. __HCP_BEGIN_PROPERTY_GET("CPCHUserSettings::get_HelpLocation",hr,pVal);
  82. Taxonomy::LockingHandle handle;
  83. Taxonomy::InstalledInstanceIter it;
  84. bool fFound;
  85. __MPC_EXIT_IF_METHOD_FAILS(hr, Taxonomy::InstalledInstanceStore::s_GLOBAL->GrabControl( handle ));
  86. __MPC_EXIT_IF_METHOD_FAILS(hr, Taxonomy::InstalledInstanceStore::s_GLOBAL->SKU_Find ( m_ts, fFound, it ));
  87. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( fFound ? it->m_inst.m_strHelpFiles.c_str() : HC_HELPSVC_HELPFILES_DEFAULT, pVal ));
  88. __HCP_END_PROPERTY(hr);
  89. }
  90. STDMETHODIMP CPCHUserSettings::get_DatabaseDir( /*[out, retval]*/ BSTR *pVal )
  91. {
  92. __HCP_BEGIN_PROPERTY_GET("CPCHUserSettings::get_IndexFile",hr,pVal);
  93. MPC::wstring strRES;
  94. __MPC_EXIT_IF_METHOD_FAILS(hr, m_ts.DatabaseDir( strRES ));
  95. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( strRES.c_str(), pVal ));
  96. __HCP_END_PROPERTY(hr);
  97. }
  98. STDMETHODIMP CPCHUserSettings::get_DatabaseFile( /*[out, retval]*/ BSTR *pVal )
  99. {
  100. __HCP_BEGIN_PROPERTY_GET("CPCHUserSettings::get_IndexFile",hr,pVal);
  101. MPC::wstring strRES;
  102. __MPC_EXIT_IF_METHOD_FAILS(hr, m_ts.DatabaseFile( strRES ));
  103. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( strRES.c_str(), pVal ));
  104. __HCP_END_PROPERTY(hr);
  105. }
  106. STDMETHODIMP CPCHUserSettings::get_IndexFile( /*[in,optional]*/ VARIANT vScope, /*[out, retval]*/ BSTR *pVal )
  107. {
  108. __HCP_BEGIN_PROPERTY_GET("CPCHUserSettings::get_IndexFile",hr,pVal);
  109. MPC::wstring strLocation;
  110. MPC::wstring strDisplayName;
  111. if(vScope.vt == VT_BSTR)
  112. {
  113. JetBlue::SessionHandle handle;
  114. JetBlue::Database* db;
  115. Taxonomy::Updater updater;
  116. __MPC_EXIT_IF_METHOD_FAILS(hr, m_ts.GetDatabase( handle, db, /*fReadOnly*/true ));
  117. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.Init( m_ts, db ));
  118. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.GetIndexInfo( strLocation, strDisplayName, vScope.bstrVal ));
  119. }
  120. else
  121. {
  122. __MPC_EXIT_IF_METHOD_FAILS(hr, m_ts.IndexFile( strLocation ));
  123. }
  124. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( strLocation.c_str(), pVal ));
  125. __HCP_END_PROPERTY(hr);
  126. }
  127. STDMETHODIMP CPCHUserSettings::get_IndexDisplayName( /*[in,optional]*/ VARIANT vScope, /*[out, retval]*/ BSTR *pVal )
  128. {
  129. __HCP_BEGIN_PROPERTY_GET("CPCHUserSettings::get_IndexDisplayName",hr,pVal);
  130. MPC::wstring strLocation;
  131. MPC::wstring strDisplayName;
  132. if(vScope.vt == VT_BSTR)
  133. {
  134. JetBlue::SessionHandle handle;
  135. JetBlue::Database* db;
  136. Taxonomy::Updater updater;
  137. __MPC_EXIT_IF_METHOD_FAILS(hr, m_ts.GetDatabase( handle, db, /*fReadOnly*/true ));
  138. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.Init( m_ts, db ));
  139. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.GetIndexInfo( strLocation, strDisplayName, vScope.bstrVal ));
  140. }
  141. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( strDisplayName.c_str(), pVal ));
  142. __HCP_END_PROPERTY(hr);
  143. }
  144. STDMETHODIMP CPCHUserSettings::get_LastUpdated( /*[out, retval]*/ DATE *pVal )
  145. {
  146. __HCP_BEGIN_PROPERTY_GET("CPCHUserSettings::get_LastUpdated",hr,pVal);
  147. Taxonomy::LockingHandle handle;
  148. Taxonomy::InstalledInstanceIter it;
  149. bool fFound;
  150. __MPC_EXIT_IF_METHOD_FAILS(hr, Taxonomy::InstalledInstanceStore::s_GLOBAL->GrabControl( handle ));
  151. __MPC_EXIT_IF_METHOD_FAILS(hr, Taxonomy::InstalledInstanceStore::s_GLOBAL->SKU_Find ( m_ts, fFound, it ));
  152. if(fFound) *pVal = it->m_inst.m_dLastUpdated;
  153. __HCP_END_PROPERTY(hr);
  154. }
  155. ////////////////////////////////////////
  156. STDMETHODIMP CPCHUserSettings::get_AreHeadlinesEnabled( /*[out, retval]*/ VARIANT_BOOL *pVal )
  157. {
  158. __HCP_BEGIN_PROPERTY_GET2__NOLOCK("CPCHUserSettings::get_AreHeadlinesEnabled",hr,pVal,VARIANT_FALSE);
  159. News::Main m;
  160. __MPC_EXIT_IF_METHOD_FAILS(hr, m.get_Headlines_Enabled( pVal ));
  161. __HCP_END_PROPERTY(hr);
  162. }
  163. //
  164. // Don't lock during this method, it takes a long time to execute.
  165. //
  166. STDMETHODIMP CPCHUserSettings::get_News( /*[out, retval]*/ IUnknown* *pVal )
  167. {
  168. __HCP_BEGIN_PROPERTY_GET__NOLOCK("CPCHUserSettings::get_News",hr,pVal);
  169. News::Main m;
  170. __MPC_EXIT_IF_METHOD_FAILS(hr, m.get_News( m_ts.GetLanguage(), CComBSTR( m_ts.GetSKU() ), pVal ));
  171. __HCP_END_PROPERTY(hr);
  172. }
  173. ////////////////////////////////////////
  174. STDMETHODIMP CPCHUserSettings::Select( /*[in]*/ BSTR bstrSKU, /*[in]*/ long lLCID )
  175. {
  176. __HCP_FUNC_ENTRY( "CPCHUserSettings::Select" );
  177. HRESULT hr;
  178. MPC::SmartLock<_ThreadModel> lock( this );
  179. Passivate();
  180. {
  181. Taxonomy::HelpSet ths;
  182. Taxonomy::LockingHandle handle;
  183. Taxonomy::InstalledInstanceIter it;
  184. bool fFound;
  185. __MPC_EXIT_IF_METHOD_FAILS(hr, ths.Initialize( bstrSKU, lLCID ));
  186. __MPC_EXIT_IF_METHOD_FAILS(hr, Taxonomy::InstalledInstanceStore::s_GLOBAL->GrabControl( handle ));
  187. __MPC_EXIT_IF_METHOD_FAILS(hr, Taxonomy::InstalledInstanceStore::s_GLOBAL->SKU_Find ( ths, fFound, it ));
  188. if(fFound == false)
  189. {
  190. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_FILE_NOT_FOUND);
  191. }
  192. m_ts = it->m_inst.m_ths;
  193. }
  194. //
  195. // Mark the SKU as in-use and signal the SystemMonitor to load the cache.
  196. //
  197. m_fAttached = true;
  198. __MPC_EXIT_IF_METHOD_FAILS(hr, Taxonomy::InstalledInstanceStore::s_GLOBAL->InUse_Lock ( m_ts ));
  199. __MPC_EXIT_IF_METHOD_FAILS(hr, Taxonomy::Cache ::s_GLOBAL->PrepareToLoad( m_ts ));
  200. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHSystemMonitor ::s_GLOBAL->LoadCache ( ));
  201. hr = S_OK;
  202. __HCP_FUNC_CLEANUP;
  203. __HCP_FUNC_EXIT(hr);
  204. }