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.

450 lines
14 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. Settings.cpp
  5. Abstract:
  6. Handles interaction between a generic user configuration and the related DB.
  7. Revision History:
  8. ******************************************************************************/
  9. #include "stdafx.h"
  10. #include <utility.h>
  11. ////////////////////////////////////////////////////////////////////////////////
  12. HRESULT Taxonomy::Settings::SplitNodePath( /*[in]*/ LPCWSTR szNodeStr ,
  13. /*[out]*/ MPC::WStringVector& vec )
  14. {
  15. __HCP_FUNC_ENTRY( "Taxonomy::Settings::SplitNodePath" );
  16. HRESULT hr;
  17. MPC::wstring strFull( L"<ROOT>" );
  18. if(STRINGISPRESENT(szNodeStr))
  19. {
  20. strFull += L"/";
  21. strFull += szNodeStr;
  22. }
  23. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::SplitAtDelimiter( vec, strFull.c_str(), L"/" ));
  24. hr = S_OK;
  25. __HCP_FUNC_CLEANUP;
  26. __HCP_FUNC_EXIT(hr);
  27. }
  28. ////////////////////////////////////////////////////////////////////////////////
  29. Taxonomy::Settings::Settings( /*[in]*/ LPCWSTR szSKU, /*[in]*/ long lLCID ) : HelpSet( szSKU, lLCID )
  30. {
  31. }
  32. Taxonomy::Settings::Settings( /*[in]*/ const HelpSet& ths )
  33. {
  34. *(HelpSet*)this = ths;
  35. }
  36. ////////////////////////////////////////////////////////////////////////////////
  37. HRESULT Taxonomy::Settings::BaseDir( /*[out]*/ MPC::wstring& strRES, /*[in]*/ bool fExpand ) const
  38. {
  39. __HCP_FUNC_ENTRY( "Taxonomy::Settings::DatabaseFile" );
  40. HRESULT hr;
  41. strRES = HC_HELPSET_ROOT;
  42. if(IsMachineHelp() == false)
  43. {
  44. WCHAR rgDir[MAX_PATH]; _snwprintf( rgDir, MAXSTRLEN(rgDir), L"%s\\%s_%04lx\\", HC_HELPSET_SUB_INSTALLEDSKUS, m_strSKU.c_str(), m_lLCID );
  45. strRES.append( rgDir );
  46. }
  47. if(fExpand)
  48. {
  49. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::SubstituteEnvVariables( strRES ));
  50. }
  51. hr = S_OK;
  52. __HCP_FUNC_CLEANUP;
  53. __HCP_FUNC_EXIT(hr);
  54. }
  55. HRESULT Taxonomy::Settings::HelpFilesDir( /*[out]*/ MPC::wstring& strRES, /*[in]*/ bool fExpand, /*[in]*/ bool fMUI ) const
  56. {
  57. __HCP_FUNC_ENTRY( "Taxonomy::Settings::DatabaseFile" );
  58. HRESULT hr;
  59. WCHAR rgDir[MAX_PATH];
  60. if(IsMachineHelp())
  61. {
  62. strRES = HC_HELPSVC_HELPFILES_DEFAULT;
  63. }
  64. else if(fMUI)
  65. {
  66. _snwprintf( rgDir, MAXSTRLEN(rgDir), L"%s\\MUI\\%04lx", HC_HELPSVC_HELPFILES_DEFAULT, m_lLCID );
  67. strRES = rgDir;
  68. }
  69. else
  70. {
  71. __MPC_EXIT_IF_METHOD_FAILS(hr, BaseDir( strRES, fExpand ));
  72. strRES.append( HC_HELPSET_SUB_HELPFILES );
  73. }
  74. if(fExpand)
  75. {
  76. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::SubstituteEnvVariables( strRES ));
  77. }
  78. hr = S_OK;
  79. __HCP_FUNC_CLEANUP;
  80. __HCP_FUNC_EXIT(hr);
  81. }
  82. HRESULT Taxonomy::Settings::DatabaseDir( /*[out]*/ MPC::wstring& strRES ) const
  83. {
  84. __HCP_FUNC_ENTRY( "Taxonomy::Settings::DatabaseDir" );
  85. HRESULT hr;
  86. __MPC_EXIT_IF_METHOD_FAILS(hr, BaseDir( strRES ));
  87. strRES.append( HC_HELPSET_SUB_DATABASE L"\\" );
  88. hr = S_OK;
  89. __HCP_FUNC_CLEANUP;
  90. __HCP_FUNC_EXIT(hr);
  91. }
  92. HRESULT Taxonomy::Settings::DatabaseFile( /*[out]*/ MPC::wstring& strRES ) const
  93. {
  94. __HCP_FUNC_ENTRY( "Taxonomy::Settings::DatabaseFile" );
  95. HRESULT hr;
  96. __MPC_EXIT_IF_METHOD_FAILS(hr, DatabaseDir( strRES ));
  97. strRES.append( HC_HELPSET_SUBSUB_DATABASEFILE );
  98. hr = S_OK;
  99. __HCP_FUNC_CLEANUP;
  100. __HCP_FUNC_EXIT(hr);
  101. }
  102. HRESULT Taxonomy::Settings::IndexFile( /*[out]*/ MPC::wstring& strRES, /*[in]*/ long lScoped ) const
  103. {
  104. __HCP_FUNC_ENTRY( "Taxonomy::Settings::IndexFile" );
  105. HRESULT hr;
  106. __MPC_EXIT_IF_METHOD_FAILS(hr, BaseDir( strRES ));
  107. if(lScoped == -1)
  108. {
  109. strRES.append( HC_HELPSET_SUB_INDEX L"\\" HC_HELPSET_SUBSUB_INDEXFILE );
  110. }
  111. else
  112. {
  113. WCHAR rgDir[MAX_PATH];
  114. _snwprintf( rgDir, MAXSTRLEN(rgDir), HC_HELPSET_SUB_INDEX L"\\scoped_%ld.hhk", lScoped );
  115. strRES.append( rgDir );
  116. }
  117. hr = S_OK;
  118. __HCP_FUNC_CLEANUP;
  119. __HCP_FUNC_EXIT(hr);
  120. }
  121. HRESULT Taxonomy::Settings::GetDatabase( /*[out]*/ JetBlue::SessionHandle& handle ,
  122. /*[out]*/ JetBlue::Database*& db ,
  123. /*[in ]*/ bool fReadOnly ) const
  124. {
  125. __HCP_FUNC_ENTRY( "Taxonomy::Settings::GetDatabase" );
  126. USES_CONVERSION;
  127. HRESULT hr;
  128. MPC::wstring strDB;
  129. db = NULL;
  130. __MPC_EXIT_IF_METHOD_FAILS(hr, DatabaseFile( strDB ));
  131. for(int pass=0; pass<2; pass++)
  132. {
  133. if(SUCCEEDED(hr = JetBlue::SessionPool::s_GLOBAL->GetSession( handle )) &&
  134. SUCCEEDED(hr = handle->GetDatabase ( W2A( strDB.c_str() ), db, /*fReadOnly*/fReadOnly, /*fCreate*/false, /*fRepair*/false )) )
  135. {
  136. break;
  137. }
  138. handle.Release();
  139. db = NULL;
  140. if(pass == 1) __MPC_SET_ERROR_AND_EXIT(hr, hr);
  141. //
  142. // Try to recreate DB...
  143. //
  144. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHSetOfHelpTopics::RebuildSKU( *this ));
  145. }
  146. hr = S_OK;
  147. __HCP_FUNC_CLEANUP;
  148. __HCP_FUNC_EXIT(hr);
  149. }
  150. ////////////////////////////////////////////////////////////////////////////////
  151. ////////////////////////////////////////////////////////////////////////////////
  152. HRESULT Taxonomy::Settings::LookupNode( /*[in]*/ LPCWSTR szNodeStr ,
  153. /*[in]*/ CPCHQueryResultCollection* pColl ) const
  154. {
  155. __HCP_FUNC_ENTRY( "Taxonomy::Settings::LookupNode" );
  156. HRESULT hr;
  157. JetBlue::SessionHandle handle;
  158. JetBlue::Database* db;
  159. Taxonomy::Updater updater;
  160. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::LookupNode - start : %s", SAFEWSTR( szNodeStr ) );
  161. __MPC_EXIT_IF_METHOD_FAILS(hr, GetDatabase ( handle, db, /*fReadOnly*/true ));
  162. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.Init( *this, db, Taxonomy::Cache::s_GLOBAL ));
  163. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.LookupNode( szNodeStr, pColl ));
  164. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::LookupNode - done" );
  165. hr = S_OK;
  166. __HCP_FUNC_CLEANUP;
  167. __HCP_FUNC_EXIT(hr);
  168. }
  169. HRESULT Taxonomy::Settings::LookupSubNodes( /*[in]*/ LPCWSTR szNodeStr ,
  170. /*[in]*/ bool fVisibleOnly ,
  171. /*[in]*/ CPCHQueryResultCollection* pColl ) const
  172. {
  173. __HCP_FUNC_ENTRY( "Taxonomy::Settings::LookupSubNodes" );
  174. HRESULT hr;
  175. JetBlue::SessionHandle handle;
  176. JetBlue::Database* db;
  177. Taxonomy::Updater updater;
  178. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::LookupSubNodes - start : %s", SAFEWSTR( szNodeStr ) );
  179. __MPC_EXIT_IF_METHOD_FAILS(hr, GetDatabase ( handle, db, /*fReadOnly*/true ));
  180. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.Init( *this, db, Taxonomy::Cache::s_GLOBAL ));
  181. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.LookupSubNodes( szNodeStr, fVisibleOnly, pColl ));
  182. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::LookupSubNodes - done" );
  183. hr = S_OK;
  184. __HCP_FUNC_CLEANUP;
  185. __HCP_FUNC_EXIT(hr);
  186. }
  187. HRESULT Taxonomy::Settings::LookupNodesAndTopics( /*[in]*/ LPCWSTR szNodeStr ,
  188. /*[in]*/ bool fVisibleOnly ,
  189. /*[in]*/ CPCHQueryResultCollection* pColl ) const
  190. {
  191. __HCP_FUNC_ENTRY( "Taxonomy::Settings::LookupNodesAndTopics" );
  192. HRESULT hr;
  193. JetBlue::SessionHandle handle;
  194. JetBlue::Database* db;
  195. Taxonomy::Updater updater;
  196. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::LookupNodesAndTopics - start : %s", SAFEWSTR( szNodeStr ) );
  197. __MPC_EXIT_IF_METHOD_FAILS(hr, GetDatabase ( handle, db, /*fReadOnly*/true ));
  198. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.Init( *this, db, Taxonomy::Cache::s_GLOBAL ));
  199. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.LookupNodesAndTopics( szNodeStr, fVisibleOnly, pColl ));
  200. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::LookupNodesAndTopics - done" );
  201. hr = S_OK;
  202. __HCP_FUNC_CLEANUP;
  203. __HCP_FUNC_EXIT(hr);
  204. }
  205. HRESULT Taxonomy::Settings::LookupTopics( /*[in]*/ LPCWSTR szNodeStr ,
  206. /*[in]*/ bool fVisibleOnly ,
  207. /*[in]*/ CPCHQueryResultCollection* pColl ) const
  208. {
  209. __HCP_FUNC_ENTRY( "Taxonomy::Settings::LookupTopics" );
  210. HRESULT hr;
  211. JetBlue::SessionHandle handle;
  212. JetBlue::Database* db;
  213. Taxonomy::Updater updater;
  214. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::LookupTopics - start : %s", SAFEWSTR( szNodeStr ) );
  215. __MPC_EXIT_IF_METHOD_FAILS(hr, GetDatabase ( handle, db, /*fReadOnly*/true ));
  216. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.Init( *this, db, Taxonomy::Cache::s_GLOBAL ));
  217. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.LookupTopics( szNodeStr, fVisibleOnly, pColl ));
  218. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::LookupTopics - done" );
  219. hr = S_OK;
  220. __HCP_FUNC_CLEANUP;
  221. __HCP_FUNC_EXIT(hr);
  222. }
  223. HRESULT Taxonomy::Settings::KeywordSearch( /*[in]*/ LPCWSTR szQueryStr ,
  224. /*[in]*/ LPCWSTR szSubSite ,
  225. /*[in]*/ CPCHQueryResultCollection* pColl ,
  226. /*[in]*/ MPC::WStringList* lst ) const
  227. {
  228. __HCP_FUNC_ENTRY( "Taxonomy::Settings::KeywordSearch" );
  229. HRESULT hr;
  230. JetBlue::SessionHandle handle;
  231. JetBlue::Database* db;
  232. Taxonomy::Updater updater;
  233. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::KeywordSearch - start : '%s' # %s", SAFEWSTR( szQueryStr ), SAFEWSTR( szSubSite ) );
  234. __MPC_EXIT_IF_METHOD_FAILS(hr, GetDatabase ( handle, db, /*fReadOnly*/true ));
  235. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.Init( *this, db, Taxonomy::Cache::s_GLOBAL ));
  236. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.KeywordSearch( szQueryStr, szSubSite, pColl, lst ));
  237. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::KeywordSearch - done" );
  238. hr = S_OK;
  239. __HCP_FUNC_CLEANUP;
  240. __HCP_FUNC_EXIT(hr);
  241. }
  242. HRESULT Taxonomy::Settings::LocateContext( /*[in]*/ LPCWSTR szURL ,
  243. /*[in]*/ LPCWSTR szSubSite ,
  244. /*[in]*/ CPCHQueryResultCollection* pColl ) const
  245. {
  246. __HCP_FUNC_ENTRY( "Taxonomy::Settings::LocateContext" );
  247. HRESULT hr;
  248. JetBlue::SessionHandle handle;
  249. JetBlue::Database* db;
  250. Taxonomy::Updater updater;
  251. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::LocateContext - start : %s # %s", SAFEWSTR( szURL ), SAFEWSTR( szSubSite ) );
  252. __MPC_EXIT_IF_METHOD_FAILS(hr, GetDatabase ( handle, db, /*fReadOnly*/true ));
  253. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.Init( *this, db, Taxonomy::Cache::s_GLOBAL ));
  254. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.LocateContext( szURL, szSubSite, pColl ));
  255. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::LocateContext - done" );
  256. hr = S_OK;
  257. __HCP_FUNC_CLEANUP;
  258. __HCP_FUNC_EXIT(hr);
  259. }
  260. HRESULT Taxonomy::Settings::GatherNodes( /*[in]*/ LPCWSTR szNodeStr ,
  261. /*[in]*/ bool fVisibleOnly ,
  262. /*[in]*/ CPCHQueryResultCollection* pColl ) const
  263. {
  264. __HCP_FUNC_ENTRY( "Taxonomy::Settings::GatherNodes" );
  265. HRESULT hr;
  266. JetBlue::SessionHandle handle;
  267. JetBlue::Database* db;
  268. Taxonomy::Updater updater;
  269. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::GatherNodes - start : %s", SAFEWSTR( szNodeStr ) );
  270. __MPC_EXIT_IF_METHOD_FAILS(hr, GetDatabase ( handle, db, /*fReadOnly*/true ));
  271. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.Init( *this, db, Taxonomy::Cache::s_GLOBAL ));
  272. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.GatherNodes( szNodeStr, fVisibleOnly, pColl ));
  273. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::GatherNodes - done" );
  274. hr = S_OK;
  275. __HCP_FUNC_CLEANUP;
  276. __HCP_FUNC_EXIT(hr);
  277. }
  278. HRESULT Taxonomy::Settings::GatherTopics( /*[in]*/ LPCWSTR szNodeStr ,
  279. /*[in]*/ bool fVisibleOnly ,
  280. /*[in]*/ CPCHQueryResultCollection* pColl ) const
  281. {
  282. __HCP_FUNC_ENTRY( "Taxonomy::Settings::GatherTopics" );
  283. HRESULT hr;
  284. JetBlue::SessionHandle handle;
  285. JetBlue::Database* db;
  286. Taxonomy::Updater updater;
  287. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::GatherTopics - start : %s", SAFEWSTR( szNodeStr ) );
  288. __MPC_EXIT_IF_METHOD_FAILS(hr, GetDatabase ( handle, db, /*fReadOnly*/true ));
  289. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.Init( *this, db, Taxonomy::Cache::s_GLOBAL ));
  290. __MPC_EXIT_IF_METHOD_FAILS(hr, updater.GatherTopics( szNodeStr, fVisibleOnly, pColl ));
  291. DEBUG_AppendPerf( DEBUG_PERF_QUERIES, L"Taxonomy::Settings::GatherTopics - done" );
  292. hr = S_OK;
  293. __HCP_FUNC_CLEANUP;
  294. __HCP_FUNC_EXIT(hr);
  295. }