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.

921 lines
22 KiB

  1. // Driver.cpp : Implementation of CDriverPackage
  2. #include "stdafx.h"
  3. #include "DevCon2.h"
  4. #include "Driver.h"
  5. #include "Device.h"
  6. #include "DrvSearchSet.h"
  7. #include "xStrings.h"
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CDriverPackage
  10. CDriverPackage::~CDriverPackage()
  11. {
  12. if(pDrvSearchSet) {
  13. pDrvSearchSet->Release();
  14. }
  15. }
  16. HRESULT CDriverPackage::Init(CDrvSearchSet *pSet,PSP_DRVINFO_DATA pDrvInfoData)
  17. {
  18. if(pDrvSearchSet) {
  19. pDrvSearchSet->Release();
  20. }
  21. pDrvSearchSet = NULL;
  22. if(!pSet) {
  23. return E_UNEXPECTED;
  24. }
  25. pSet->AddRef();
  26. pDrvSearchSet = pSet;
  27. if(pDrvInfoData) {
  28. DrvInfoData = *pDrvInfoData;
  29. } else {
  30. DrvInfoData.cbSize = 0;
  31. }
  32. return S_OK;
  33. }
  34. STDMETHODIMP CDriverPackage::get_Description(BSTR *pVal)
  35. {
  36. *pVal = SysAllocString(DrvInfoData.Description);
  37. if(!*pVal) {
  38. return E_OUTOFMEMORY;
  39. }
  40. return S_OK;
  41. }
  42. STDMETHODIMP CDriverPackage::get_Manufacturer(BSTR *pVal)
  43. {
  44. *pVal = SysAllocString(DrvInfoData.MfgName);
  45. if(!*pVal) {
  46. return E_OUTOFMEMORY;
  47. }
  48. return S_OK;
  49. }
  50. STDMETHODIMP CDriverPackage::get_Provider(BSTR *pVal)
  51. {
  52. *pVal = SysAllocString(DrvInfoData.ProviderName);
  53. if(!*pVal) {
  54. return E_OUTOFMEMORY;
  55. }
  56. return S_OK;
  57. }
  58. STDMETHODIMP CDriverPackage::get_Date(DATE *pVal)
  59. {
  60. //
  61. // work out ticks to translate to Dec 30 1899
  62. //
  63. SYSTEMTIME sysTime;
  64. FILETIME ref_zero;
  65. FILETIME ref_one;
  66. ULARGE_INTEGER i_zero;
  67. ULARGE_INTEGER i_one;
  68. ULARGE_INTEGER i_act;
  69. sysTime.wYear = 1899;
  70. sysTime.wMonth = 12;
  71. sysTime.wDayOfWeek = 0;
  72. sysTime.wDay = 30;
  73. sysTime.wHour = 0;
  74. sysTime.wMinute = 0;
  75. sysTime.wSecond = 0;
  76. sysTime.wMilliseconds = 0;
  77. if(!SystemTimeToFileTime(&sysTime,&ref_zero)) {
  78. return E_UNEXPECTED;
  79. }
  80. i_zero.LowPart = ref_zero.dwLowDateTime;
  81. i_zero.HighPart = ref_zero.dwHighDateTime;
  82. sysTime.wYear = 1899;
  83. sysTime.wMonth = 12;
  84. sysTime.wDay = 31;
  85. if(!SystemTimeToFileTime(&sysTime,&ref_one)) {
  86. return E_UNEXPECTED;
  87. }
  88. i_one.LowPart = ref_one.dwLowDateTime;
  89. i_one.HighPart = ref_one.dwHighDateTime;
  90. i_one.QuadPart -= i_zero.QuadPart;
  91. //
  92. // now the real FILETIME
  93. //
  94. i_act.LowPart = DrvInfoData.DriverDate.dwLowDateTime;
  95. i_act.HighPart = DrvInfoData.DriverDate.dwHighDateTime;
  96. double dbl = (double)(__int64)i_act.QuadPart;
  97. dbl -= (double)(__int64)i_zero.QuadPart;
  98. dbl /= (double)(__int64)i_one.QuadPart;
  99. *pVal = dbl;
  100. return S_OK;
  101. }
  102. STDMETHODIMP CDriverPackage::get_Version(BSTR *pVal)
  103. {
  104. WCHAR fmt[64];
  105. ULARGE_INTEGER i;
  106. i.QuadPart = DrvInfoData.DriverVersion;
  107. swprintf(fmt,L"%u.%u.%u.%u",
  108. HIWORD(i.HighPart),
  109. LOWORD(i.HighPart),
  110. HIWORD(i.LowPart),
  111. LOWORD(i.LowPart));
  112. *pVal = SysAllocString(fmt);
  113. if(!*pVal) {
  114. return E_OUTOFMEMORY;
  115. }
  116. return S_OK;
  117. }
  118. STDMETHODIMP CDriverPackage::get_ScriptName(BSTR *pVal)
  119. {
  120. SP_DRVINFO_DETAIL_DATA detail;
  121. detail.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
  122. if(!SetupDiGetDriverInfoDetail(pDrvSearchSet->GetDevInfoSet(),
  123. pDrvSearchSet->GetDevInfoData(),
  124. &DrvInfoData,
  125. &detail,
  126. sizeof(detail),
  127. NULL)) {
  128. DWORD Err = GetLastError();
  129. if(Err != ERROR_INSUFFICIENT_BUFFER) {
  130. return HRESULT_FROM_SETUPAPI(Err);
  131. }
  132. }
  133. HINF hInf = SetupOpenInfFile(detail.InfFileName,
  134. NULL,
  135. INF_STYLE_WIN4|INF_STYLE_OLDNT,
  136. NULL);
  137. if(hInf == INVALID_HANDLE_VALUE) {
  138. DWORD Err = GetLastError();
  139. return HRESULT_FROM_SETUPAPI(Err);
  140. }
  141. WCHAR buf[LINE_LEN];
  142. if(!SetupDiGetActualSectionToInstall(hInf,detail.SectionName,buf,LINE_LEN,NULL,NULL)) {
  143. SetupCloseInfFile(hInf);
  144. return E_UNEXPECTED;
  145. }
  146. *pVal = SysAllocString(buf);
  147. if(!*pVal) {
  148. return E_OUTOFMEMORY;
  149. }
  150. return S_OK;
  151. }
  152. STDMETHODIMP CDriverPackage::get_ScriptFile(BSTR *pVal)
  153. {
  154. SP_DRVINFO_DETAIL_DATA detail;
  155. detail.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
  156. if(!SetupDiGetDriverInfoDetail(pDrvSearchSet->GetDevInfoSet(),
  157. pDrvSearchSet->GetDevInfoData(),
  158. &DrvInfoData,
  159. &detail,
  160. sizeof(detail),
  161. NULL)) {
  162. DWORD Err = GetLastError();
  163. if(Err != ERROR_INSUFFICIENT_BUFFER) {
  164. return HRESULT_FROM_SETUPAPI(Err);
  165. }
  166. }
  167. *pVal = SysAllocString(detail.InfFileName);
  168. if(!*pVal) {
  169. return E_OUTOFMEMORY;
  170. }
  171. return S_OK;
  172. }
  173. STDMETHODIMP CDriverPackage::get_HardwareIds(LPDISPATCH *pVal)
  174. {
  175. PSP_DRVINFO_DETAIL_DATA pDetail;
  176. LPBYTE buffer = NULL;
  177. DWORD memsz = 8192;
  178. HRESULT hr;
  179. DWORD Err;
  180. for(;;) {
  181. buffer = new BYTE[memsz+sizeof(WCHAR)*2];
  182. if(!buffer) {
  183. return E_OUTOFMEMORY;
  184. }
  185. pDetail = (PSP_DRVINFO_DETAIL_DATA)buffer;
  186. ZeroMemory(pDetail,memsz+sizeof(WCHAR)*2);
  187. pDetail->cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
  188. if(!SetupDiGetDriverInfoDetail(pDrvSearchSet->GetDevInfoSet(),
  189. pDrvSearchSet->GetDevInfoData(),
  190. &DrvInfoData,
  191. pDetail,
  192. memsz,
  193. &memsz)) {
  194. Err = GetLastError();
  195. if(Err != ERROR_INSUFFICIENT_BUFFER) {
  196. delete [] buffer;
  197. return HRESULT_FROM_SETUPAPI(Err);
  198. }
  199. } else {
  200. break;
  201. }
  202. delete [] buffer;
  203. }
  204. if(pDetail->CompatIDsLength) {
  205. pDetail->HardwareID[pDetail->CompatIDsOffset] = L'\0';
  206. }
  207. //
  208. // now build multisz of hardware ID's
  209. //
  210. CComObject<CStrings> *strings;
  211. hr = CComObject<CStrings>::CreateInstance(&strings);
  212. if(FAILED(hr)) {
  213. delete [] buffer;
  214. return hr;
  215. }
  216. strings->AddRef();
  217. hr = strings->FromMultiSz(pDetail->HardwareID);
  218. delete [] buffer;
  219. if(FAILED(hr)) {
  220. strings->Release();
  221. return hr;
  222. }
  223. *pVal = strings;
  224. return S_OK;
  225. }
  226. STDMETHODIMP CDriverPackage::get_CompatibleIds(LPDISPATCH *pVal)
  227. {
  228. PSP_DRVINFO_DETAIL_DATA pDetail;
  229. LPBYTE buffer = NULL;
  230. DWORD memsz = 8192;
  231. HRESULT hr;
  232. DWORD Err;
  233. for(;;) {
  234. buffer = new BYTE[memsz+sizeof(WCHAR)*2];
  235. if(!buffer) {
  236. return E_OUTOFMEMORY;
  237. }
  238. pDetail = (PSP_DRVINFO_DETAIL_DATA)buffer;
  239. ZeroMemory(pDetail,memsz+sizeof(WCHAR)*2);
  240. pDetail->cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
  241. if(!SetupDiGetDriverInfoDetail(pDrvSearchSet->GetDevInfoSet(),
  242. pDrvSearchSet->GetDevInfoData(),
  243. &DrvInfoData,
  244. pDetail,
  245. memsz,
  246. &memsz)) {
  247. Err = GetLastError();
  248. if(Err != ERROR_INSUFFICIENT_BUFFER) {
  249. delete [] buffer;
  250. return HRESULT_FROM_SETUPAPI(Err);
  251. }
  252. } else {
  253. break;
  254. }
  255. delete [] buffer;
  256. }
  257. //
  258. // now build multisz of hardware ID's
  259. //
  260. CComObject<CStrings> *strings;
  261. hr = CComObject<CStrings>::CreateInstance(&strings);
  262. if(FAILED(hr)) {
  263. delete [] buffer;
  264. return hr;
  265. }
  266. strings->AddRef();
  267. if(pDetail->CompatIDsLength) {
  268. hr = strings->FromMultiSz(pDetail->HardwareID+pDetail->CompatIDsOffset);
  269. } else {
  270. hr = S_OK;
  271. }
  272. delete [] buffer;
  273. if(FAILED(hr)) {
  274. strings->Release();
  275. return hr;
  276. }
  277. *pVal = strings;
  278. return S_OK;
  279. }
  280. STDMETHODIMP CDriverPackage::get_DriverDescription(BSTR *pVal)
  281. {
  282. SP_DRVINFO_DETAIL_DATA detail;
  283. detail.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
  284. if(!SetupDiGetDriverInfoDetail(pDrvSearchSet->GetDevInfoSet(),
  285. pDrvSearchSet->GetDevInfoData(),
  286. &DrvInfoData,
  287. &detail,
  288. sizeof(detail),
  289. NULL)) {
  290. DWORD Err = GetLastError();
  291. if(Err != ERROR_INSUFFICIENT_BUFFER) {
  292. return HRESULT_FROM_SETUPAPI(Err);
  293. }
  294. }
  295. *pVal = SysAllocString(detail.DrvDescription);
  296. if(!*pVal) {
  297. return E_OUTOFMEMORY;
  298. }
  299. return S_OK;
  300. }
  301. UINT CDriverPackage::GetDriverListCallback(PVOID Context,UINT Notification,UINT_PTR Param1,UINT_PTR Param2)
  302. {
  303. DriverListCallbackContext *pContext = (DriverListCallbackContext *)Context;
  304. LPTSTR file = (LPTSTR)Param1;
  305. pContext->hr = pContext->pList->InternalAdd(file,lstrlen(file));
  306. return FAILED(pContext->hr) ? ERROR_NO_MORE_ITEMS : NO_ERROR;
  307. }
  308. STDMETHODIMP CDriverPackage::DriverFiles(LPDISPATCH *pDriverFiles)
  309. {
  310. //
  311. // if we were to install this driver, where would the files go?
  312. //
  313. SP_DEVINSTALL_PARAMS deviceInstallParams;
  314. HSPFILEQ queueHandle = INVALID_HANDLE_VALUE;
  315. DWORD scanResult;
  316. DWORD Err;
  317. HRESULT hr;
  318. HDEVINFO hDevInfo = pDrvSearchSet->GetDevInfoSet();
  319. PSP_DEVINFO_DATA pDevInfoData = pDrvSearchSet->GetDevInfoData();
  320. ZeroMemory(&deviceInstallParams, sizeof(deviceInstallParams));
  321. deviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
  322. if(!SetupDiGetDeviceInstallParams(hDevInfo, pDevInfoData, &deviceInstallParams)) {
  323. Err = GetLastError();
  324. return HRESULT_FROM_SETUPAPI(Err);
  325. }
  326. //
  327. // select this driver (expect this to last only as long as this call)
  328. //
  329. if(!SetupDiSetSelectedDriver(hDevInfo, pDevInfoData, &DrvInfoData)) {
  330. Err = GetLastError();
  331. return HRESULT_FROM_SETUPAPI(Err);
  332. }
  333. //
  334. // now 'instigate' an install, obtaining all files to be copied into
  335. // a file queue
  336. //
  337. queueHandle = SetupOpenFileQueue();
  338. if ( queueHandle == (HSPFILEQ)INVALID_HANDLE_VALUE ) {
  339. Err = GetLastError();
  340. return HRESULT_FROM_SETUPAPI(Err);
  341. }
  342. deviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
  343. if ( !SetupDiGetDeviceInstallParams(hDevInfo, pDevInfoData, &deviceInstallParams) ) {
  344. Err = GetLastError();
  345. SetupCloseFileQueue(queueHandle);
  346. return HRESULT_FROM_SETUPAPI(Err);
  347. }
  348. //
  349. // we want to add the files to the file queue, not install them!
  350. //
  351. deviceInstallParams.FileQueue = queueHandle;
  352. deviceInstallParams.Flags |= DI_NOVCP;
  353. if ( !SetupDiSetDeviceInstallParams(hDevInfo, pDevInfoData, &deviceInstallParams) ) {
  354. Err = GetLastError();
  355. SetupCloseFileQueue(queueHandle);
  356. return HRESULT_FROM_SETUPAPI(Err);
  357. }
  358. //
  359. // do it
  360. //
  361. if ( !SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES, hDevInfo, pDevInfoData) ) {
  362. Err = GetLastError();
  363. SetupCloseFileQueue(queueHandle);
  364. return HRESULT_FROM_SETUPAPI(Err);
  365. }
  366. //
  367. // clear settings
  368. //
  369. deviceInstallParams.FileQueue = NULL;
  370. deviceInstallParams.Flags &= ~DI_NOVCP;
  371. SetupDiSetDeviceInstallParams(hDevInfo, pDevInfoData, &deviceInstallParams);
  372. //
  373. // we now have a list of delete/rename/copy files
  374. //
  375. DriverListCallbackContext context;
  376. CComObject<CStrings> *strings;
  377. hr = CComObject<CStrings>::CreateInstance(&strings);
  378. if(FAILED(hr)) {
  379. SetupCloseFileQueue(queueHandle);
  380. return hr;
  381. }
  382. strings->AddRef();
  383. context.pList = strings;
  384. context.hr = S_OK;
  385. if(!SetupScanFileQueue(queueHandle,SPQ_SCAN_USE_CALLBACK,NULL,GetDriverListCallback,&context,&scanResult)) {
  386. Err = GetLastError();
  387. SetupCloseFileQueue(queueHandle);
  388. strings->Release();
  389. if(FAILED(context.hr)) {
  390. return context.hr;
  391. } else {
  392. return HRESULT_FROM_SETUPAPI(Err);
  393. }
  394. }
  395. SetupCloseFileQueue(queueHandle);
  396. *pDriverFiles = strings;
  397. return S_OK;
  398. }
  399. UINT CDriverPackage::GetManifestCallback(PVOID Context,UINT Notification,UINT_PTR Param1,UINT_PTR Param2)
  400. {
  401. DriverListCallbackContext *pContext = (DriverListCallbackContext *)Context;
  402. FILEPATHS *pFileInfo = (FILEPATHS *)Param1;
  403. pContext->hr = pContext->pList->InternalAdd(pFileInfo->Source,lstrlen(pFileInfo->Source));
  404. return FAILED(pContext->hr) ? ERROR_NO_MORE_ITEMS : NO_ERROR;
  405. }
  406. STDMETHODIMP CDriverPackage::Manifest(LPDISPATCH *pManifest)
  407. {
  408. //
  409. // source files
  410. //
  411. SP_DEVINSTALL_PARAMS deviceInstallParams;
  412. HSPFILEQ queueHandle = INVALID_HANDLE_VALUE;
  413. DWORD scanResult;
  414. DWORD Err;
  415. HRESULT hr;
  416. HDEVINFO hDevInfo = pDrvSearchSet->GetDevInfoSet();
  417. PSP_DEVINFO_DATA pDevInfoData = pDrvSearchSet->GetDevInfoData();
  418. ZeroMemory(&deviceInstallParams, sizeof(deviceInstallParams));
  419. deviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
  420. if(!SetupDiGetDeviceInstallParams(hDevInfo, pDevInfoData, &deviceInstallParams)) {
  421. Err = GetLastError();
  422. return HRESULT_FROM_SETUPAPI(Err);
  423. }
  424. //
  425. // select this driver (expect this to last only as long as this call)
  426. //
  427. if(!SetupDiSetSelectedDriver(hDevInfo, pDevInfoData, &DrvInfoData)) {
  428. Err = GetLastError();
  429. return HRESULT_FROM_SETUPAPI(Err);
  430. }
  431. //
  432. // now 'instigate' an install, obtaining all files to be copied into
  433. // a file queue
  434. //
  435. queueHandle = SetupOpenFileQueue();
  436. if ( queueHandle == (HSPFILEQ)INVALID_HANDLE_VALUE ) {
  437. Err = GetLastError();
  438. return HRESULT_FROM_SETUPAPI(Err);
  439. }
  440. deviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
  441. if ( !SetupDiGetDeviceInstallParams(hDevInfo, pDevInfoData, &deviceInstallParams) ) {
  442. Err = GetLastError();
  443. SetupCloseFileQueue(queueHandle);
  444. return HRESULT_FROM_SETUPAPI(Err);
  445. }
  446. //
  447. // we want to add the files to the file queue, not install them!
  448. //
  449. deviceInstallParams.FileQueue = queueHandle;
  450. deviceInstallParams.Flags |= DI_NOVCP;
  451. if ( !SetupDiSetDeviceInstallParams(hDevInfo, pDevInfoData, &deviceInstallParams) ) {
  452. Err = GetLastError();
  453. SetupCloseFileQueue(queueHandle);
  454. return HRESULT_FROM_SETUPAPI(Err);
  455. }
  456. //
  457. // do it
  458. //
  459. if ( !SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES, hDevInfo, pDevInfoData) ) {
  460. Err = GetLastError();
  461. SetupCloseFileQueue(queueHandle);
  462. return HRESULT_FROM_SETUPAPI(Err);
  463. }
  464. //
  465. // clear settings
  466. //
  467. deviceInstallParams.FileQueue = NULL;
  468. deviceInstallParams.Flags &= ~DI_NOVCP;
  469. SetupDiSetDeviceInstallParams(hDevInfo, pDevInfoData, &deviceInstallParams);
  470. //
  471. // we now have a list of delete/rename/copy files
  472. //
  473. DriverListCallbackContext context;
  474. CComObject<CStrings> *strings;
  475. hr = CComObject<CStrings>::CreateInstance(&strings);
  476. if(FAILED(hr)) {
  477. SetupCloseFileQueue(queueHandle);
  478. return hr;
  479. }
  480. strings->AddRef();
  481. context.pList = strings;
  482. context.hr = S_OK;
  483. //
  484. // WinXP has a perf option (no signing check) if these two flags are combined
  485. // if it doesn't work, fall back to Win2k method
  486. //
  487. if(!SetupScanFileQueue(queueHandle,SPQ_SCAN_USE_CALLBACKEX|SPQ_SCAN_FILE_PRESENCE,NULL,GetManifestCallback,&context,&scanResult) &&
  488. (FAILED(context.hr) ||
  489. !SetupScanFileQueue(queueHandle,SPQ_SCAN_USE_CALLBACKEX,NULL,GetManifestCallback,&context,&scanResult))) {
  490. Err = GetLastError();
  491. SetupCloseFileQueue(queueHandle);
  492. strings->Release();
  493. if(FAILED(context.hr)) {
  494. return context.hr;
  495. } else {
  496. return HRESULT_FROM_SETUPAPI(Err);
  497. }
  498. }
  499. SetupCloseFileQueue(queueHandle);
  500. *pManifest = strings;
  501. return S_OK;
  502. }
  503. BOOL CDriverPackage::IsSame(PSP_DRVINFO_DATA pInfo)
  504. {
  505. if(pInfo->Reserved == DrvInfoData.Reserved) {
  506. return TRUE;
  507. }
  508. return FALSE;
  509. }
  510. STDMETHODIMP CDriverPackage::get_Reject(VARIANT_BOOL *pVal)
  511. {
  512. DWORD Err;
  513. SP_DRVINSTALL_PARAMS params;
  514. ZeroMemory(&params,sizeof(params));
  515. params.cbSize = sizeof(params);
  516. if(!SetupDiGetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  517. pDrvSearchSet->GetDevInfoData(),
  518. &DrvInfoData,
  519. &params)) {
  520. Err = GetLastError();
  521. return HRESULT_FROM_SETUPAPI(Err);
  522. }
  523. *pVal = (params.Flags & DNF_BAD_DRIVER) ? VARIANT_TRUE : VARIANT_FALSE;
  524. return S_OK;
  525. }
  526. STDMETHODIMP CDriverPackage::put_Reject(VARIANT_BOOL newVal)
  527. {
  528. DWORD Err;
  529. SP_DRVINSTALL_PARAMS params;
  530. ZeroMemory(&params,sizeof(params));
  531. params.cbSize = sizeof(params);
  532. if(!SetupDiGetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  533. pDrvSearchSet->GetDevInfoData(),
  534. &DrvInfoData,
  535. &params)) {
  536. Err = GetLastError();
  537. return HRESULT_FROM_SETUPAPI(Err);
  538. }
  539. DWORD newflags = (params.Flags & ~DNF_BAD_DRIVER) | (newVal ? DNF_BAD_DRIVER : 0);
  540. if(params.Flags != newflags) {
  541. if(!SetupDiSetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  542. pDrvSearchSet->GetDevInfoData(),
  543. &DrvInfoData,
  544. &params)) {
  545. Err = GetLastError();
  546. return HRESULT_FROM_SETUPAPI(Err);
  547. }
  548. }
  549. return S_OK;
  550. }
  551. STDMETHODIMP CDriverPackage::get_IsClassDriver(VARIANT_BOOL *pVal)
  552. {
  553. DWORD Err;
  554. SP_DRVINSTALL_PARAMS params;
  555. ZeroMemory(&params,sizeof(params));
  556. params.cbSize = sizeof(params);
  557. if(!SetupDiGetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  558. pDrvSearchSet->GetDevInfoData(),
  559. &DrvInfoData,
  560. &params)) {
  561. Err = GetLastError();
  562. return HRESULT_FROM_SETUPAPI(Err);
  563. }
  564. *pVal = (params.Flags & DNF_CLASS_DRIVER) ? VARIANT_TRUE : VARIANT_FALSE;
  565. return S_OK;
  566. }
  567. STDMETHODIMP CDriverPackage::get_IsCompatibleDriver(VARIANT_BOOL *pVal)
  568. {
  569. DWORD Err;
  570. SP_DRVINSTALL_PARAMS params;
  571. ZeroMemory(&params,sizeof(params));
  572. params.cbSize = sizeof(params);
  573. if(!SetupDiGetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  574. pDrvSearchSet->GetDevInfoData(),
  575. &DrvInfoData,
  576. &params)) {
  577. Err = GetLastError();
  578. return HRESULT_FROM_SETUPAPI(Err);
  579. }
  580. *pVal = (params.Flags & DNF_COMPATIBLE_DRIVER) ? VARIANT_TRUE : VARIANT_FALSE;
  581. return S_OK;
  582. }
  583. STDMETHODIMP CDriverPackage::get_DescriptionIsDuplicate(VARIANT_BOOL *pVal)
  584. {
  585. DWORD Err;
  586. SP_DRVINSTALL_PARAMS params;
  587. ZeroMemory(&params,sizeof(params));
  588. params.cbSize = sizeof(params);
  589. if(!SetupDiGetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  590. pDrvSearchSet->GetDevInfoData(),
  591. &DrvInfoData,
  592. &params)) {
  593. Err = GetLastError();
  594. return HRESULT_FROM_SETUPAPI(Err);
  595. }
  596. *pVal = (params.Flags & DNF_DUPDESC) ? VARIANT_TRUE : VARIANT_FALSE;
  597. return S_OK;
  598. }
  599. STDMETHODIMP CDriverPackage::get_ProviderIsDuplicate(VARIANT_BOOL *pVal)
  600. {
  601. DWORD Err;
  602. SP_DRVINSTALL_PARAMS params;
  603. ZeroMemory(&params,sizeof(params));
  604. params.cbSize = sizeof(params);
  605. if(!SetupDiGetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  606. pDrvSearchSet->GetDevInfoData(),
  607. &DrvInfoData,
  608. &params)) {
  609. Err = GetLastError();
  610. return HRESULT_FROM_SETUPAPI(Err);
  611. }
  612. *pVal = (params.Flags & DNF_DUPPROVIDER) ? VARIANT_TRUE : VARIANT_FALSE;
  613. return S_OK;
  614. }
  615. STDMETHODIMP CDriverPackage::get_ExcludeFromList(VARIANT_BOOL *pVal)
  616. {
  617. DWORD Err;
  618. SP_DRVINSTALL_PARAMS params;
  619. ZeroMemory(&params,sizeof(params));
  620. params.cbSize = sizeof(params);
  621. if(!SetupDiGetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  622. pDrvSearchSet->GetDevInfoData(),
  623. &DrvInfoData,
  624. &params)) {
  625. Err = GetLastError();
  626. return HRESULT_FROM_SETUPAPI(Err);
  627. }
  628. *pVal = (params.Flags & DNF_EXCLUDEFROMLIST) ? VARIANT_TRUE : VARIANT_FALSE;
  629. return S_OK;
  630. }
  631. STDMETHODIMP CDriverPackage::put_ExcludeFromList(VARIANT_BOOL newVal)
  632. {
  633. DWORD Err;
  634. SP_DRVINSTALL_PARAMS params;
  635. ZeroMemory(&params,sizeof(params));
  636. params.cbSize = sizeof(params);
  637. if(!SetupDiGetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  638. pDrvSearchSet->GetDevInfoData(),
  639. &DrvInfoData,
  640. &params)) {
  641. Err = GetLastError();
  642. return HRESULT_FROM_SETUPAPI(Err);
  643. }
  644. DWORD newflags = (params.Flags & ~DNF_EXCLUDEFROMLIST) | (newVal ? DNF_EXCLUDEFROMLIST : 0);
  645. if(params.Flags != newflags) {
  646. if(!SetupDiSetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  647. pDrvSearchSet->GetDevInfoData(),
  648. &DrvInfoData,
  649. &params)) {
  650. Err = GetLastError();
  651. return HRESULT_FROM_SETUPAPI(Err);
  652. }
  653. }
  654. return S_OK;
  655. }
  656. STDMETHODIMP CDriverPackage::get_FromInternet(VARIANT_BOOL *pVal)
  657. {
  658. DWORD Err;
  659. SP_DRVINSTALL_PARAMS params;
  660. ZeroMemory(&params,sizeof(params));
  661. params.cbSize = sizeof(params);
  662. if(!SetupDiGetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  663. pDrvSearchSet->GetDevInfoData(),
  664. &DrvInfoData,
  665. &params)) {
  666. Err = GetLastError();
  667. return HRESULT_FROM_SETUPAPI(Err);
  668. }
  669. *pVal = (params.Flags & DNF_INET_DRIVER) ? VARIANT_TRUE : VARIANT_FALSE;
  670. return S_OK;
  671. }
  672. STDMETHODIMP CDriverPackage::get_NoDriver(VARIANT_BOOL *pVal)
  673. {
  674. DWORD Err;
  675. SP_DRVINSTALL_PARAMS params;
  676. ZeroMemory(&params,sizeof(params));
  677. params.cbSize = sizeof(params);
  678. if(!SetupDiGetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  679. pDrvSearchSet->GetDevInfoData(),
  680. &DrvInfoData,
  681. &params)) {
  682. Err = GetLastError();
  683. return HRESULT_FROM_SETUPAPI(Err);
  684. }
  685. *pVal = (params.Flags & DNF_NODRIVER) ? VARIANT_TRUE : VARIANT_FALSE;
  686. return S_OK;
  687. }
  688. STDMETHODIMP CDriverPackage::get_OldDriver(VARIANT_BOOL *pVal)
  689. {
  690. DWORD Err;
  691. SP_DRVINSTALL_PARAMS params;
  692. ZeroMemory(&params,sizeof(params));
  693. params.cbSize = sizeof(params);
  694. if(!SetupDiGetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  695. pDrvSearchSet->GetDevInfoData(),
  696. &DrvInfoData,
  697. &params)) {
  698. Err = GetLastError();
  699. return HRESULT_FROM_SETUPAPI(Err);
  700. }
  701. *pVal = (params.Flags & DNF_OLDDRIVER) ? VARIANT_TRUE : VARIANT_FALSE;
  702. return S_OK;
  703. }
  704. STDMETHODIMP CDriverPackage::get_OldInternetDriver(VARIANT_BOOL *pVal)
  705. {
  706. DWORD Err;
  707. SP_DRVINSTALL_PARAMS params;
  708. ZeroMemory(&params,sizeof(params));
  709. params.cbSize = sizeof(params);
  710. if(!SetupDiGetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  711. pDrvSearchSet->GetDevInfoData(),
  712. &DrvInfoData,
  713. &params)) {
  714. Err = GetLastError();
  715. return HRESULT_FROM_SETUPAPI(Err);
  716. }
  717. *pVal = (params.Flags & DNF_OLD_INET_DRIVER) ? VARIANT_TRUE : VARIANT_FALSE;
  718. return S_OK;
  719. }
  720. STDMETHODIMP CDriverPackage::get_Rank(long *pVal)
  721. {
  722. DWORD Err;
  723. SP_DRVINSTALL_PARAMS params;
  724. ZeroMemory(&params,sizeof(params));
  725. params.cbSize = sizeof(params);
  726. if(!SetupDiGetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  727. pDrvSearchSet->GetDevInfoData(),
  728. &DrvInfoData,
  729. &params)) {
  730. Err = GetLastError();
  731. return HRESULT_FROM_SETUPAPI(Err);
  732. }
  733. *pVal = params.Rank & 0xffff;
  734. *pVal = (params.Flags & DNF_COMPATIBLE_DRIVER) ? VARIANT_TRUE : VARIANT_FALSE;
  735. return S_OK;
  736. }
  737. STDMETHODIMP CDriverPackage::put_Rank(long newVal)
  738. {
  739. DWORD Err;
  740. SP_DRVINSTALL_PARAMS params;
  741. ZeroMemory(&params,sizeof(params));
  742. params.cbSize = sizeof(params);
  743. if(!SetupDiGetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  744. pDrvSearchSet->GetDevInfoData(),
  745. &DrvInfoData,
  746. &params)) {
  747. Err = GetLastError();
  748. return HRESULT_FROM_SETUPAPI(Err);
  749. }
  750. DWORD newrank = newVal & 0xffff;
  751. if(params.Rank != newrank) {
  752. if(!SetupDiSetDriverInstallParams(pDrvSearchSet->GetDevInfoSet(),
  753. pDrvSearchSet->GetDevInfoData(),
  754. &DrvInfoData,
  755. &params)) {
  756. Err = GetLastError();
  757. return HRESULT_FROM_SETUPAPI(Err);
  758. }
  759. }
  760. return S_OK;
  761. }