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.

387 lines
9.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. HRESULT hr;
  70. if (pszDeviceID && *pszDeviceID && pszEventType && *pszEventType)
  71. {
  72. hr = _Init(pszDeviceID, pszEventType);
  73. }
  74. else
  75. {
  76. hr = E_INVALIDARG;
  77. }
  78. return hr;
  79. }
  80. STDMETHODIMP CAutoplayHandlerImpl::InitWithContent(LPCWSTR pszDeviceID,
  81. LPCWSTR /*pszEventType*/, LPCWSTR pszContentTypeHandler)
  82. {
  83. HRESULT hr;
  84. if (pszDeviceID && *pszDeviceID && pszContentTypeHandler && *pszContentTypeHandler)
  85. {
  86. hr = _GetDeviceID(pszDeviceID, _szDeviceIDReal,
  87. ARRAYSIZE(_szDeviceIDReal));
  88. if (SUCCEEDED(hr))
  89. {
  90. if (!lstrcmpi(pszContentTypeHandler, TEXT("CDAudioContentHandler")))
  91. {
  92. hr = SafeStrCpyN(_szEventHandler, TEXT("PlayCDAudioOnArrival"), ARRAYSIZE(_szEventHandler));
  93. }
  94. else if (!lstrcmpi(pszContentTypeHandler, TEXT("DVDMovieContentHandler")))
  95. {
  96. hr = SafeStrCpyN(_szEventHandler, TEXT("PlayDVDMovieOnArrival"), ARRAYSIZE(_szEventHandler));
  97. }
  98. else if (!lstrcmpi(pszContentTypeHandler, TEXT("BlankCDContentHandler")))
  99. {
  100. hr = SafeStrCpyN(_szEventHandler, TEXT("HandleCDBurningOnArrival"), ARRAYSIZE(_szEventHandler));
  101. }
  102. else if (!lstrcmpi(pszContentTypeHandler, TEXT("MusicFilesContentHandler")))
  103. {
  104. hr = SafeStrCpyN(_szEventHandler, TEXT("PlayMusicFilesOnArrival"), ARRAYSIZE(_szEventHandler));
  105. }
  106. else if (!lstrcmpi(pszContentTypeHandler, TEXT("PicturesContentHandler")))
  107. {
  108. hr = SafeStrCpyN(_szEventHandler, TEXT("ShowPicturesOnArrival"), ARRAYSIZE(_szEventHandler));
  109. }
  110. else if (!lstrcmpi(pszContentTypeHandler, TEXT("VideoFilesContentHandler")))
  111. {
  112. hr = SafeStrCpyN(_szEventHandler, TEXT("PlayVideoFilesOnArrival"), ARRAYSIZE(_szEventHandler));
  113. }
  114. else if (!lstrcmpi(pszContentTypeHandler, TEXT("MixedContentHandler")))
  115. {
  116. hr = SafeStrCpyN(_szEventHandler, TEXT("MixedContentOnArrival"), ARRAYSIZE(_szEventHandler));
  117. }
  118. else
  119. {
  120. hr = E_FAIL;
  121. }
  122. if (SUCCEEDED(hr))
  123. {
  124. _fInited = TRUE;
  125. }
  126. }
  127. else
  128. {
  129. TRACE(TF_SHHWDTCTDTCTREG, TEXT("_Init, _GetDeviceID FAILED: 0x%08X"),
  130. hr);
  131. }
  132. }
  133. else
  134. {
  135. hr = E_INVALIDARG;
  136. }
  137. return hr;
  138. }
  139. STDMETHODIMP CAutoplayHandlerImpl::GetDefaultHandler(LPWSTR* ppszHandler)
  140. {
  141. HRESULT hr;
  142. TRACE(TF_SHHWDTCTDTCTREG, TEXT("Entered CAutoplayHandlerImpl"));
  143. if (ppszHandler)
  144. {
  145. *ppszHandler = NULL;
  146. if (_fInited)
  147. {
  148. WCHAR szHandler[MAX_HANDLER];
  149. hr = _GetUserDefaultHandler(_szDeviceIDReal, _szEventHandler,
  150. szHandler, ARRAYSIZE(szHandler), GUH_IMPERSONATEUSER);
  151. if (SUCCEEDED(hr))
  152. {
  153. if (S_FALSE != hr)
  154. {
  155. // Watch out! The hr from _GetUserDefaultHandler is more
  156. // than just S_OK/S_FALSE. Keep its value, unless we fail!
  157. HRESULT hrTmp = _CoTaskMemCopy(szHandler, ppszHandler);
  158. if (FAILED(hrTmp))
  159. {
  160. hr = hrTmp;
  161. }
  162. }
  163. else
  164. {
  165. hr = E_FAIL;
  166. }
  167. }
  168. }
  169. else
  170. {
  171. hr = E_FAIL;
  172. }
  173. }
  174. else
  175. {
  176. hr = E_POINTER;
  177. }
  178. return hr;
  179. }
  180. #define SOFTPREFIX TEXT("[soft]")
  181. STDMETHODIMP CAutoplayHandlerImpl::SetDefaultHandler(LPCWSTR pszHandler)
  182. {
  183. HRESULT hr;
  184. if (_fInited)
  185. {
  186. if (pszHandler && *pszHandler)
  187. {
  188. if (StrNCmp(SOFTPREFIX, pszHandler, (ARRAYSIZE(SOFTPREFIX) - 1)))
  189. {
  190. hr = _SetUserDefaultHandler(_szDeviceIDReal, _szEventHandler,
  191. pszHandler);
  192. }
  193. else
  194. {
  195. hr = _SetSoftUserDefaultHandler(_szDeviceIDReal,
  196. _szEventHandler, pszHandler + ARRAYSIZE(SOFTPREFIX) - 1);
  197. }
  198. }
  199. else
  200. {
  201. hr = E_INVALIDARG;
  202. }
  203. }
  204. else
  205. {
  206. hr = E_FAIL;
  207. }
  208. return hr;
  209. }
  210. STDMETHODIMP CAutoplayHandlerImpl::EnumHandlers(IEnumAutoplayHandler** ppenum)
  211. {
  212. HRESULT hr;
  213. if (ppenum)
  214. {
  215. *ppenum = NULL;
  216. if (_fInited)
  217. {
  218. CEnumAutoplayHandler* penum = new CEnumAutoplayHandler(NULL);
  219. if (penum)
  220. {
  221. hr = penum->_Init(_szEventHandler);
  222. if (SUCCEEDED(hr))
  223. {
  224. *ppenum = penum;
  225. }
  226. else
  227. {
  228. delete penum;
  229. }
  230. }
  231. else
  232. {
  233. hr = E_OUTOFMEMORY;
  234. }
  235. }
  236. else
  237. {
  238. hr = E_FAIL;
  239. }
  240. }
  241. else
  242. {
  243. hr = E_INVALIDARG;
  244. }
  245. return hr;
  246. }
  247. CAutoplayHandlerImpl::CAutoplayHandlerImpl() : _fInited(FALSE)
  248. {
  249. _CompleteShellHWDetectionInitialization();
  250. }
  251. //
  252. CAutoplayHandlerPropertiesImpl::CAutoplayHandlerPropertiesImpl() : _fInited(FALSE)
  253. {
  254. _CompleteShellHWDetectionInitialization();
  255. }
  256. STDMETHODIMP CAutoplayHandlerPropertiesImpl::Init(LPCWSTR pszHandler)
  257. {
  258. HRESULT hr;
  259. if (pszHandler && *pszHandler)
  260. {
  261. if (!_fInited)
  262. {
  263. hr = SafeStrCpyN(_szHandler, pszHandler, ARRAYSIZE(_szHandler));
  264. if (SUCCEEDED(hr))
  265. {
  266. _fInited = TRUE;
  267. }
  268. }
  269. else
  270. {
  271. hr = E_UNEXPECTED;
  272. }
  273. }
  274. else
  275. {
  276. hr = E_INVALIDARG;
  277. }
  278. return hr;
  279. }
  280. STDMETHODIMP CAutoplayHandlerPropertiesImpl::GetInvokeProgIDAndVerb(
  281. LPWSTR* ppszInvokeProgID, LPWSTR* ppszInvokeVerb)
  282. {
  283. HRESULT hr;
  284. if (ppszInvokeProgID && ppszInvokeVerb)
  285. {
  286. *ppszInvokeProgID = NULL;
  287. *ppszInvokeVerb = NULL;
  288. if (_fInited)
  289. {
  290. WCHAR szInvokeProgID[MAX_INVOKEPROGID];
  291. hr = _GetInvokeProgIDFromHandler(_szHandler, szInvokeProgID,
  292. ARRAYSIZE(szInvokeProgID));
  293. if (SUCCEEDED(hr) && (S_FALSE != hr))
  294. {
  295. WCHAR szInvokeVerb[MAX_INVOKEVERB];
  296. hr = _GetInvokeVerbFromHandler(_szHandler, szInvokeVerb,
  297. ARRAYSIZE(szInvokeVerb));
  298. if (SUCCEEDED(hr) && (S_FALSE != hr))
  299. {
  300. hr = _CoTaskMemCopy(szInvokeProgID, ppszInvokeProgID);
  301. if (SUCCEEDED(hr))
  302. {
  303. hr = _CoTaskMemCopy(szInvokeVerb, ppszInvokeVerb);
  304. if (FAILED(hr))
  305. {
  306. if (*ppszInvokeProgID)
  307. {
  308. CoTaskMemFree((PVOID)*ppszInvokeProgID);
  309. *ppszInvokeProgID = NULL;
  310. }
  311. }
  312. }
  313. }
  314. }
  315. if (S_FALSE == hr)
  316. {
  317. hr = E_FAIL;
  318. }
  319. }
  320. else
  321. {
  322. hr = E_UNEXPECTED;
  323. }
  324. }
  325. else
  326. {
  327. hr = E_INVALIDARG;
  328. }
  329. return hr;
  330. }