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.

360 lines
8.7 KiB

  1. #include "settings.h"
  2. #include "setenum.h"
  3. #include "dtctreg.h"
  4. #include "svcsync.h"
  5. #include "sfstr.h"
  6. #include "cmmn.h"
  7. #include "misc.h"
  8. #include <shlwapi.h>
  9. #include "tfids.h"
  10. #include "dbg.h"
  11. #define ARRAYSIZE(a) (sizeof((a))/sizeof((a)[0]))
  12. HRESULT _GetEventHandlerHelper(LPCWSTR pszDeviceID, LPCWSTR pszEventType,
  13. LPWSTR pszEventHandler, DWORD cchEventHandler)
  14. {
  15. CHWDeviceInst* phwdevinst;
  16. CNamedElem* pelemToRelease;
  17. HRESULT hr = _GetHWDeviceInstFromDeviceOrVolumeIntfID(pszDeviceID,
  18. &phwdevinst, &pelemToRelease);
  19. if (SUCCEEDED(hr) && (S_FALSE != hr))
  20. {
  21. WCHAR szDeviceHandler[MAX_DEVICEHANDLER];
  22. hr = _GetDeviceHandler(phwdevinst, szDeviceHandler,
  23. ARRAYSIZE(szDeviceHandler));
  24. if (SUCCEEDED(hr) && (S_FALSE != hr))
  25. {
  26. hr = _GetEventHandlerFromDeviceHandler(szDeviceHandler,
  27. pszEventType, pszEventHandler, cchEventHandler);
  28. }
  29. pelemToRelease->RCRelease();
  30. }
  31. return hr;
  32. }
  33. HRESULT CAutoplayHandlerImpl::_Init(LPCWSTR pszDeviceID, LPCWSTR pszEventType)
  34. {
  35. HRESULT hr = _GetDeviceID(pszDeviceID, _szDeviceIDReal,
  36. ARRAYSIZE(_szDeviceIDReal));
  37. if (SUCCEEDED(hr))
  38. {
  39. hr = _GetEventHandlerHelper(_szDeviceIDReal, pszEventType,
  40. _szEventHandler, ARRAYSIZE(_szEventHandler));
  41. if (SUCCEEDED(hr))
  42. {
  43. if (S_FALSE != hr)
  44. {
  45. _fInited = TRUE;
  46. }
  47. else
  48. {
  49. hr = E_FAIL;
  50. }
  51. }
  52. else
  53. {
  54. TRACE(TF_SHHWDTCTDTCTREG,
  55. TEXT("_Init, _GetEventHandlerHelper FAILED or S_FALSE'd: 0x%08X"),
  56. hr);
  57. }
  58. }
  59. else
  60. {
  61. TRACE(TF_SHHWDTCTDTCTREG, TEXT("_Init, _GetDeviceID FAILED: 0x%08X"),
  62. hr);
  63. }
  64. return hr;
  65. }
  66. STDMETHODIMP CAutoplayHandlerImpl::Init(LPCWSTR pszDeviceID,
  67. LPCWSTR pszEventType)
  68. {
  69. return _Init(pszDeviceID, pszEventType);
  70. }
  71. STDMETHODIMP CAutoplayHandlerImpl::InitWithContent(LPCWSTR pszDeviceID,
  72. LPCWSTR /*pszEventType*/, LPCWSTR pszContentTypeHandler)
  73. {
  74. HRESULT hr = _GetDeviceID(pszDeviceID, _szDeviceIDReal,
  75. ARRAYSIZE(_szDeviceIDReal));
  76. if (SUCCEEDED(hr))
  77. {
  78. if (!lstrcmpi(pszContentTypeHandler, TEXT("CDAudioContentHandler")))
  79. {
  80. hr = SafeStrCpyN(_szEventHandler, TEXT("PlayCDAudioOnArrival"), ARRAYSIZE(_szEventHandler));
  81. }
  82. else if (!lstrcmpi(pszContentTypeHandler, TEXT("DVDMovieContentHandler")))
  83. {
  84. hr = SafeStrCpyN(_szEventHandler, TEXT("PlayDVDMovieOnArrival"), ARRAYSIZE(_szEventHandler));
  85. }
  86. else if (!lstrcmpi(pszContentTypeHandler, TEXT("BlankCDContentHandler")))
  87. {
  88. hr = SafeStrCpyN(_szEventHandler, TEXT("HandleCDBurningOnArrival"), ARRAYSIZE(_szEventHandler));
  89. }
  90. else if (!lstrcmpi(pszContentTypeHandler, TEXT("MusicFilesContentHandler")))
  91. {
  92. hr = SafeStrCpyN(_szEventHandler, TEXT("PlayMusicFilesOnArrival"), ARRAYSIZE(_szEventHandler));
  93. }
  94. else if (!lstrcmpi(pszContentTypeHandler, TEXT("PicturesContentHandler")))
  95. {
  96. hr = SafeStrCpyN(_szEventHandler, TEXT("ShowPicturesOnArrival"), ARRAYSIZE(_szEventHandler));
  97. }
  98. else if (!lstrcmpi(pszContentTypeHandler, TEXT("VideoFilesContentHandler")))
  99. {
  100. hr = SafeStrCpyN(_szEventHandler, TEXT("PlayVideoFilesOnArrival"), ARRAYSIZE(_szEventHandler));
  101. }
  102. else if (!lstrcmpi(pszContentTypeHandler, TEXT("MixedContentHandler")))
  103. {
  104. hr = SafeStrCpyN(_szEventHandler, TEXT("MixedContentOnArrival"), ARRAYSIZE(_szEventHandler));
  105. }
  106. else
  107. {
  108. hr = E_FAIL;
  109. }
  110. if (SUCCEEDED(hr))
  111. {
  112. _fInited = TRUE;
  113. }
  114. }
  115. else
  116. {
  117. TRACE(TF_SHHWDTCTDTCTREG, TEXT("_Init, _GetDeviceID FAILED: 0x%08X"),
  118. hr);
  119. }
  120. return hr;
  121. }
  122. STDMETHODIMP CAutoplayHandlerImpl::GetDefaultHandler(LPWSTR* ppszHandler)
  123. {
  124. HRESULT hr;
  125. TRACE(TF_SHHWDTCTDTCTREG, TEXT("Entered CAutoplayHandlerImpl"));
  126. if (ppszHandler)
  127. {
  128. *ppszHandler = NULL;
  129. if (_fInited)
  130. {
  131. WCHAR szHandler[MAX_HANDLER];
  132. hr = _GetUserDefaultHandler(_szDeviceIDReal, _szEventHandler,
  133. szHandler, ARRAYSIZE(szHandler), GUH_IMPERSONATEUSER);
  134. if (SUCCEEDED(hr))
  135. {
  136. if (S_FALSE != hr)
  137. {
  138. // Watch out! The hr from _GetUserDefaultHandler is more
  139. // than just S_OK/S_FALSE. Keep its value, unless we fail!
  140. HRESULT hrTmp = _CoTaskMemCopy(szHandler, ppszHandler);
  141. if (FAILED(hrTmp))
  142. {
  143. hr = hrTmp;
  144. }
  145. }
  146. else
  147. {
  148. hr = E_FAIL;
  149. }
  150. }
  151. }
  152. else
  153. {
  154. hr = E_FAIL;
  155. }
  156. }
  157. else
  158. {
  159. hr = E_POINTER;
  160. }
  161. return hr;
  162. }
  163. #define SOFTPREFIX TEXT("[soft]")
  164. STDMETHODIMP CAutoplayHandlerImpl::SetDefaultHandler(LPCWSTR pszHandler)
  165. {
  166. HRESULT hr;
  167. if (_fInited)
  168. {
  169. if (pszHandler && *pszHandler)
  170. {
  171. if (StrNCmp(SOFTPREFIX, pszHandler, (ARRAYSIZE(SOFTPREFIX) - 1)))
  172. {
  173. hr = _SetUserDefaultHandler(_szDeviceIDReal, _szEventHandler,
  174. pszHandler);
  175. }
  176. else
  177. {
  178. hr = _SetSoftUserDefaultHandler(_szDeviceIDReal,
  179. _szEventHandler, pszHandler + ARRAYSIZE(SOFTPREFIX) - 1);
  180. }
  181. }
  182. else
  183. {
  184. hr = E_INVALIDARG;
  185. }
  186. }
  187. else
  188. {
  189. hr = E_FAIL;
  190. }
  191. return hr;
  192. }
  193. STDMETHODIMP CAutoplayHandlerImpl::EnumHandlers(IEnumAutoplayHandler** ppenum)
  194. {
  195. HRESULT hr;
  196. *ppenum = NULL;
  197. if (_fInited)
  198. {
  199. CEnumAutoplayHandler* penum = new CEnumAutoplayHandler(NULL);
  200. if (penum)
  201. {
  202. hr = penum->_Init(_szEventHandler);
  203. if (SUCCEEDED(hr))
  204. {
  205. *ppenum = penum;
  206. }
  207. else
  208. {
  209. delete penum;
  210. }
  211. }
  212. else
  213. {
  214. hr = E_OUTOFMEMORY;
  215. }
  216. }
  217. else
  218. {
  219. hr = E_FAIL;
  220. }
  221. return hr;
  222. }
  223. CAutoplayHandlerImpl::CAutoplayHandlerImpl() : _fInited(FALSE)
  224. {
  225. _CompleteShellHWDetectionInitialization();
  226. }
  227. //
  228. CAutoplayHandlerPropertiesImpl::CAutoplayHandlerPropertiesImpl() : _fInited(FALSE)
  229. {
  230. _CompleteShellHWDetectionInitialization();
  231. }
  232. STDMETHODIMP CAutoplayHandlerPropertiesImpl::Init(LPCWSTR pszHandler)
  233. {
  234. HRESULT hr;
  235. if (pszHandler && *pszHandler)
  236. {
  237. if (!_fInited)
  238. {
  239. hr = SafeStrCpyN(_szHandler, pszHandler, ARRAYSIZE(_szHandler));
  240. if (SUCCEEDED(hr))
  241. {
  242. _fInited = TRUE;
  243. }
  244. }
  245. else
  246. {
  247. hr = E_UNEXPECTED;
  248. }
  249. }
  250. else
  251. {
  252. hr = E_INVALIDARG;
  253. }
  254. return hr;
  255. }
  256. STDMETHODIMP CAutoplayHandlerPropertiesImpl::GetInvokeProgIDAndVerb(
  257. LPWSTR* ppszInvokeProgID, LPWSTR* ppszInvokeVerb)
  258. {
  259. HRESULT hr;
  260. if (ppszInvokeProgID && ppszInvokeVerb)
  261. {
  262. *ppszInvokeProgID = NULL;
  263. *ppszInvokeVerb = NULL;
  264. if (_fInited)
  265. {
  266. WCHAR szInvokeProgID[MAX_INVOKEPROGID];
  267. hr = _GetInvokeProgIDFromHandler(_szHandler, szInvokeProgID,
  268. ARRAYSIZE(szInvokeProgID));
  269. if (SUCCEEDED(hr) && (S_FALSE != hr))
  270. {
  271. WCHAR szInvokeVerb[MAX_INVOKEVERB];
  272. hr = _GetInvokeVerbFromHandler(_szHandler, szInvokeVerb,
  273. ARRAYSIZE(szInvokeVerb));
  274. if (SUCCEEDED(hr) && (S_FALSE != hr))
  275. {
  276. hr = _CoTaskMemCopy(szInvokeProgID, ppszInvokeProgID);
  277. if (SUCCEEDED(hr))
  278. {
  279. hr = _CoTaskMemCopy(szInvokeVerb, ppszInvokeVerb);
  280. if (FAILED(hr))
  281. {
  282. if (*ppszInvokeProgID)
  283. {
  284. CoTaskMemFree((PVOID)*ppszInvokeProgID);
  285. *ppszInvokeProgID = NULL;
  286. }
  287. }
  288. }
  289. }
  290. }
  291. if (S_FALSE == hr)
  292. {
  293. hr = E_FAIL;
  294. }
  295. }
  296. else
  297. {
  298. hr = E_UNEXPECTED;
  299. }
  300. }
  301. else
  302. {
  303. hr = E_INVALIDARG;
  304. }
  305. return hr;
  306. }