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.

328 lines
6.2 KiB

  1. // GuideStore2.cpp : Implementation of CGuideStore
  2. #include "stdafx.h"
  3. #include "GuideStore2.h"
  4. #include "Property.h"
  5. #include "Service.h"
  6. #include "Program.h"
  7. #include "ScheduleEntry.h"
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CGuideStore
  10. HRESULT CGuideStore::OpenDB(const TCHAR *szDBName)
  11. {
  12. HRESULT hr = E_FAIL;
  13. if (m_pdb == NULL)
  14. {
  15. m_pdb = NewComObject(CGuideDB);
  16. if (m_pdb == NULL)
  17. return E_OUTOFMEMORY;
  18. }
  19. hr = m_pdb->OpenDB(this, szDBName);
  20. return hr;
  21. }
  22. STDMETHODIMP CGuideStore::get_Objects(IObjects **ppobjs)
  23. {
  24. ENTER_API
  25. {
  26. ValidateOutPtr<IObjects>(ppobjs, NULL);
  27. if (m_pobjs == NULL)
  28. {
  29. HRESULT hr;
  30. CComPtr<IObjects> pobjs;
  31. hr = m_pdb->get_ObjectsWithType(__uuidof(IUnknown), &pobjs);
  32. if (FAILED(hr))
  33. return hr;
  34. m_pobjs = pobjs;
  35. }
  36. *ppobjs = m_pobjs;
  37. if (*ppobjs != NULL)
  38. (*ppobjs)->AddRef();
  39. return S_OK;
  40. }
  41. LEAVE_API
  42. }
  43. STDMETHODIMP CGuideStore::get_ActiveGuideDataProvider(IGuideDataProvider **ppdataprovider)
  44. {
  45. ENTER_API
  46. {
  47. ValidateOutPtr<IGuideDataProvider>(ppdataprovider, NULL);
  48. return m_pdb->get_GuideDataProvider(ppdataprovider);
  49. }
  50. LEAVE_API
  51. }
  52. STDMETHODIMP CGuideStore::putref_ActiveGuideDataProvider(IGuideDataProvider *pdataprovider)
  53. {
  54. ENTER_API
  55. {
  56. ValidateInPtr_NULL_OK<IGuideDataProvider>(pdataprovider);
  57. return m_pdb->putref_GuideDataProvider(pdataprovider);
  58. }
  59. LEAVE_API
  60. }
  61. STDMETHODIMP CGuideStore::get_GuideDataProviders(IGuideDataProviders **ppdataproviders)
  62. {
  63. ENTER_API
  64. {
  65. ValidateOutPtr<IGuideDataProviders>(ppdataproviders, NULL);
  66. if (m_pdataproviders == NULL)
  67. {
  68. HRESULT hr;
  69. CComPtr<IObjects> pobjs;
  70. hr = m_pdb->get_ObjectsWithType(CLSID_GuideDataProvider, &pobjs);
  71. if (FAILED(hr))
  72. return hr;
  73. hr = pobjs->QueryInterface(__uuidof(IGuideDataProviders), (void **)&m_pdataproviders);
  74. if (FAILED(hr))
  75. return hr;
  76. }
  77. (*ppdataproviders = m_pdataproviders)->AddRef();
  78. return S_OK;
  79. }
  80. LEAVE_API
  81. }
  82. STDMETHODIMP CGuideStore::get_Services(IServices **ppservices)
  83. {
  84. ENTER_API
  85. {
  86. ValidateOutPtr<IServices>(ppservices, NULL);
  87. if (m_pservices == NULL)
  88. {
  89. HRESULT hr;
  90. CComPtr<IObjects> pobjs;
  91. hr = m_pdb->get_ObjectsWithType(CLSID_Service, &pobjs);
  92. if (FAILED(hr))
  93. return hr;
  94. hr = pobjs->QueryInterface(__uuidof(IServices), (void **)&m_pservices);
  95. if (FAILED(hr))
  96. return hr;
  97. }
  98. (*ppservices = m_pservices)->AddRef();
  99. return S_OK;
  100. }
  101. LEAVE_API
  102. }
  103. STDMETHODIMP CGuideStore::get_Programs(IPrograms **ppprograms)
  104. {
  105. ENTER_API
  106. {
  107. ValidateOutPtr<IPrograms>(ppprograms, NULL);
  108. if (m_pprograms == NULL)
  109. {
  110. HRESULT hr;
  111. CComPtr<IObjects> pobjs;
  112. hr = m_pdb->get_ObjectsWithType(CLSID_Program, &pobjs);
  113. if (FAILED(hr))
  114. return hr;
  115. hr = pobjs->QueryInterface(__uuidof(IPrograms), (void **)&m_pprograms);
  116. if (FAILED(hr))
  117. return hr;
  118. }
  119. (*ppprograms = m_pprograms)->AddRef();
  120. return S_OK;
  121. }
  122. LEAVE_API
  123. }
  124. STDMETHODIMP CGuideStore::get_ScheduleEntries(IScheduleEntries **ppschedentries)
  125. {
  126. ENTER_API
  127. {
  128. ValidateOutPtr<IScheduleEntries>(ppschedentries, NULL);
  129. if (m_pschedentries == NULL)
  130. {
  131. HRESULT hr;
  132. CComPtr<IObjects> pobjs;
  133. hr = m_pdb->get_ObjectsWithType(CLSID_ScheduleEntry, &pobjs);
  134. if (FAILED(hr))
  135. return hr;
  136. hr = pobjs->QueryInterface(__uuidof(IScheduleEntries), (void **)&m_pschedentries);
  137. if (FAILED(hr))
  138. return hr;
  139. }
  140. (*ppschedentries = m_pschedentries)->AddRef();
  141. return S_OK;
  142. }
  143. LEAVE_API
  144. }
  145. STDMETHODIMP CGuideStore::get_ChannelLineups(IChannelLineups **ppchanlineups)
  146. {
  147. ENTER_API
  148. {
  149. ValidateOutPtr<IChannelLineups>(ppchanlineups, NULL);
  150. CComPtr<IServices> pservices;
  151. HRESULT hr;
  152. hr = get_Services(&pservices);
  153. if (FAILED(hr))
  154. return hr;
  155. return pservices->get_ChannelLineups(ppchanlineups);
  156. }
  157. LEAVE_API
  158. }
  159. STDMETHODIMP CGuideStore::get_Channels(IChannels **ppchans)
  160. {
  161. ENTER_API
  162. {
  163. ValidateOutPtr<IChannels>(ppchans, NULL);
  164. if (m_pchans == NULL)
  165. {
  166. HRESULT hr;
  167. CComPtr<IObjects> pobjs;
  168. hr = m_pdb->get_ObjectsWithType(CLSID_Channel, &pobjs);
  169. if (FAILED(hr))
  170. return hr;
  171. hr = pobjs->QueryInterface(__uuidof(IChannels), (void **)&m_pchans);
  172. if (FAILED(hr))
  173. return hr;
  174. }
  175. (*ppchans = m_pchans)->AddRef();
  176. return S_OK;
  177. }
  178. LEAVE_API
  179. }
  180. STDMETHODIMP CGuideStore::get_MetaPropertySets(IMetaPropertySets **pppropsets)
  181. {
  182. ENTER_API
  183. {
  184. ValidateOutPtr<IMetaPropertySets>(pppropsets, NULL);
  185. if (m_ppropsets == NULL)
  186. {
  187. CComPtr<CMetaPropertySets> ppropsets = NewComObject(CMetaPropertySets);
  188. if (ppropsets == NULL)
  189. return E_OUTOFMEMORY;
  190. if (m_pdb == NULL)
  191. return E_FAIL;
  192. ppropsets->Init(m_pdb);
  193. ppropsets->Load();
  194. m_ppropsets = ppropsets;
  195. }
  196. (*pppropsets = m_ppropsets)->AddRef();
  197. return S_OK;
  198. }
  199. LEAVE_API
  200. }
  201. STDMETHODIMP CGuideStore::Open(BSTR bstrNameIn)
  202. {
  203. ENTER_API
  204. {
  205. ValidateIn(bstrNameIn);
  206. _bstr_t bstrName(bstrNameIn);
  207. // Name is NULL... look in the registry for the default file.
  208. if (bstrName.length() == 0)
  209. {
  210. HKEY hkey;
  211. long lErr;
  212. lErr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\GuideStore"),
  213. 0, KEY_READ, &hkey);
  214. if (lErr == ERROR_SUCCESS)
  215. {
  216. OLECHAR szPath[MAX_PATH];
  217. DWORD cb = sizeof(szPath);
  218. DWORD regtype;
  219. lErr = RegQueryValueEx(hkey, _T("Path"), 0, &regtype, (LPBYTE) szPath, &cb);
  220. RegCloseKey(hkey);
  221. if ((lErr == ERROR_SUCCESS) && (regtype == REG_SZ))
  222. bstrName = szPath;
  223. }
  224. }
  225. // Name not found in the registry... use default location
  226. if (bstrName.length() == 0)
  227. {
  228. HKEY hkey;
  229. long lErr;
  230. lErr = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  231. _T("Software\\Microsoft\\Windows\\CurrentVersion"),
  232. 0, KEY_READ, &hkey);
  233. if (lErr != ERROR_SUCCESS)
  234. return E_FAIL;
  235. OLECHAR szPath[MAX_PATH];
  236. DWORD cb = sizeof(szPath);
  237. DWORD regtype;
  238. lErr = RegQueryValueEx(hkey, _T("MediaPath"), 0, &regtype, (LPBYTE) szPath, &cb);
  239. RegCloseKey(hkey);
  240. if ((lErr != ERROR_SUCCESS) || (regtype != REG_SZ))
  241. GetSystemDirectoryW(szPath, cb);
  242. wcscat(szPath, L"\\guidestore.mgs");
  243. bstrName = szPath;
  244. }
  245. HRESULT hr;
  246. hr = OpenDB(bstrName);
  247. if (FAILED(hr))
  248. return hr;
  249. // Make sure the property sets are all loaded.
  250. CComPtr<IMetaPropertySets> ppropsets;
  251. get_MetaPropertySets(&ppropsets);
  252. // Make sure the object types are all loaded.
  253. CObjectTypes *pobjtypes;
  254. m_pdb->get_ObjectTypes(&pobjtypes);
  255. return S_OK;
  256. }
  257. LEAVE_API
  258. }