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.

1008 lines
28 KiB

  1. /******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 2000
  4. *
  5. * TITLE: Util.cpp
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: KeisukeT
  10. *
  11. * DATE: 27 Mar, 2000
  12. *
  13. * DESCRIPTION:
  14. * Utility function for WIA class installer.
  15. *
  16. * NOTE:
  17. * All of string buffers dealt in these functions must have at least
  18. * MAX_DESCRIPTION size. Since it doesn't have size check of buffer, it assumes
  19. * all string size is unfer MAX_DESCRIPTION, which must be OK to be used only
  20. * for WIA class installer.
  21. *
  22. *******************************************************************************/
  23. //
  24. // Precompiled header
  25. //
  26. #include "precomp.h"
  27. #pragma hdrstop
  28. //
  29. // Include
  30. //
  31. #include "sti_ci.h"
  32. #include "stiregi.h"
  33. #include <regstr.h>
  34. #include <cfgmgr32.h>
  35. //
  36. // Extern
  37. //
  38. extern HINSTANCE g_hDllInstance;
  39. //
  40. // Function
  41. //
  42. BOOL
  43. GetInfInforamtionFromSelectedDevice(
  44. HDEVINFO hDevInfo,
  45. LPTSTR pInfFileName,
  46. LPTSTR pInfSectionName
  47. )
  48. {
  49. BOOL bRet;
  50. SP_DEVINFO_DATA DeviceInfoData;
  51. SP_DRVINFO_DATA DriverInfoData;
  52. SP_DRVINFO_DETAIL_DATA DriverInfoDetailData;
  53. HINF hInf;
  54. TCHAR szInfFileName[MAX_DESCRIPTION];
  55. TCHAR szInfSectionName[MAX_DESCRIPTION];
  56. DebugTrace(TRACE_PROC_ENTER,(("GetInfInforamtionFromSelectedDevice: Enter... \r\n")));
  57. hInf = INVALID_HANDLE_VALUE;
  58. bRet = FALSE;
  59. //
  60. // Check arguments.
  61. //
  62. if( (NULL == hDevInfo)
  63. || (NULL == pInfFileName)
  64. || (NULL == pInfSectionName) )
  65. {
  66. DebugTrace(TRACE_ERROR,(("GetInfInforamtionFromSelectedDevice: ERROR!! Invalid argument. \r\n")));
  67. bRet = FALSE;
  68. goto GetInfInforamtionFromSelectedDevice_return;
  69. }
  70. //
  71. // Initialize locals.
  72. //
  73. memset (&DeviceInfoData, 0, sizeof(SP_DEVINFO_DATA));
  74. memset (&DriverInfoData, 0, sizeof(SP_DRVINFO_DATA));
  75. memset (&DriverInfoDetailData, 0, sizeof(SP_DRVINFO_DETAIL_DATA));
  76. memset (szInfFileName, 0, sizeof(szInfFileName));
  77. memset (szInfSectionName, 0, sizeof(szInfSectionName));
  78. DriverInfoData.cbSize = sizeof(SP_DRVINFO_DATA);
  79. DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
  80. DriverInfoDetailData.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
  81. //
  82. // Get selected device element.
  83. //
  84. if (!SetupDiGetSelectedDevice (hDevInfo, &DeviceInfoData)) {
  85. DebugTrace(TRACE_ERROR,(("GetInfInforamtionFromSelectedDevice: ERROR!! SetupDiGetSelectedDevice Failed. Err=0x%lX\r\n"), GetLastError()));
  86. bRet = FALSE;
  87. goto GetInfInforamtionFromSelectedDevice_return;
  88. }
  89. //
  90. // Get selected device driver information.
  91. //
  92. if (!SetupDiGetSelectedDriver(hDevInfo, &DeviceInfoData, &DriverInfoData)) {
  93. DebugTrace(TRACE_ERROR,(("GetInfInforamtionFromSelectedDevice: ERROR!! SetupDiGetSelectedDriver Failed. Err=0x%lX\r\n"), GetLastError()));
  94. bRet = FALSE;
  95. goto GetInfInforamtionFromSelectedDevice_return;
  96. }
  97. //
  98. // Get detailed data of selected device driver.
  99. //
  100. if(!SetupDiGetDriverInfoDetail(hDevInfo,
  101. &DeviceInfoData,
  102. &DriverInfoData,
  103. &DriverInfoDetailData,
  104. sizeof(DriverInfoDetailData),
  105. NULL) )
  106. {
  107. DebugTrace(TRACE_ERROR,(("GetInfInforamtionFromSelectedDevice: ERROR!! SetupDiGetDriverInfoDetail Failed.Er=0x%lX\r\n"),GetLastError()));
  108. bRet = FALSE;
  109. goto GetInfInforamtionFromSelectedDevice_return;
  110. }
  111. //
  112. // Copy INF filename.
  113. //
  114. _tcsncpy(szInfFileName, DriverInfoDetailData.InfFileName, sizeof(szInfFileName)/sizeof(TCHAR));
  115. //
  116. // Open INF file of selected driver.
  117. //
  118. hInf = SetupOpenInfFile(szInfFileName,
  119. NULL,
  120. INF_STYLE_WIN4,
  121. NULL);
  122. if (hInf == INVALID_HANDLE_VALUE) {
  123. DebugTrace(TRACE_ERROR,(("GetInfInforamtionFromSelectedDevice: ERROR!! SetupOpenInfFile Failed.Er=0x%lX\r\n"),GetLastError()));
  124. bRet = FALSE;
  125. goto GetInfInforamtionFromSelectedDevice_return;
  126. }
  127. //
  128. // Get actual INF section name to be installed.
  129. //
  130. if (!SetupDiGetActualSectionToInstall(hInf,
  131. DriverInfoDetailData.SectionName,
  132. szInfSectionName,
  133. sizeof(szInfSectionName)/sizeof(TCHAR),
  134. NULL,
  135. NULL) )
  136. {
  137. DebugTrace(TRACE_ERROR,(("GetInfInforamtionFromSelectedDevice: ERROR!! SetupDiGetActualSectionToInstall Failed.Er=0x%lX\r\n"),GetLastError()));
  138. bRet = FALSE;
  139. goto GetInfInforamtionFromSelectedDevice_return;
  140. }
  141. //
  142. // Copy strings to given buffer.
  143. //
  144. _tcsncpy(pInfFileName, szInfFileName, sizeof(szInfFileName)/sizeof(TCHAR));
  145. _tcsncpy(pInfSectionName, szInfSectionName, sizeof(szInfSectionName)/sizeof(TCHAR));
  146. //
  147. // Operation succeeded.
  148. //
  149. bRet = TRUE;
  150. GetInfInforamtionFromSelectedDevice_return:
  151. if(INVALID_HANDLE_VALUE != hInf){
  152. SetupCloseInfFile(hInf);
  153. }
  154. DebugTrace(TRACE_PROC_LEAVE,(("GetInfInforamtionFromSelectedDevice: Leaving... Ret=0x%x\n"), bRet));
  155. return bRet;
  156. }
  157. BOOL
  158. GetStringFromRegistry(
  159. HKEY hkRegistry,
  160. LPCTSTR szValueName,
  161. LPTSTR pBuffer
  162. )
  163. {
  164. BOOL bRet;
  165. LONG lError;
  166. DWORD dwSize;
  167. DWORD dwType;
  168. TCHAR szString[MAX_DESCRIPTION];
  169. //
  170. // Initialize local.
  171. //
  172. bRet = FALSE;
  173. lError = ERROR_SUCCESS;
  174. dwSize = sizeof(szString);
  175. memset(szString, 0, sizeof(szString));
  176. //
  177. // Check arguments.
  178. //
  179. if( (NULL == hkRegistry)
  180. || (NULL == szValueName)
  181. || (NULL == pBuffer) )
  182. {
  183. DebugTrace(TRACE_ERROR,(("GetStringFromRegistry: ERROR!! Invalid argument\r\n")));
  184. bRet = FALSE;
  185. goto GetStringFromRegistry_return;
  186. }
  187. //
  188. // Get specified string from registry.
  189. //
  190. lError = RegQueryValueEx(hkRegistry,
  191. szValueName,
  192. NULL,
  193. &dwType,
  194. (LPBYTE)szString,
  195. &dwSize);
  196. if(ERROR_SUCCESS != lError){
  197. DebugTrace(TRACE_WARNING,(("GetStringFromRegistry: WARNING!! RegQueryValueEx failed. Err=0x%x.\r\n"), GetLastError()));
  198. bRet = FALSE;
  199. goto GetStringFromRegistry_return;
  200. }
  201. //
  202. // Make sure NULL termination.
  203. //
  204. szString[ARRAYSIZE(szString)-1] = TEXT('\0');
  205. //
  206. // Copy acquired string to given buffer. This function assume max-string/bufer size is MAX_DESCRIPTION.
  207. //
  208. _tcsncpy(pBuffer, szString, MAX_DESCRIPTION);
  209. //
  210. // Operation succeeded.
  211. //
  212. bRet = TRUE;
  213. GetStringFromRegistry_return:
  214. return bRet;
  215. }
  216. BOOL
  217. GetDwordFromRegistry(
  218. HKEY hkRegistry,
  219. LPCTSTR szValueName,
  220. LPDWORD pdwValue
  221. )
  222. {
  223. BOOL bRet;
  224. LONG lError;
  225. DWORD dwSize;
  226. DWORD dwType;
  227. DWORD dwValue;
  228. //
  229. // Initialize local.
  230. //
  231. bRet = FALSE;
  232. lError = ERROR_SUCCESS;
  233. dwSize = sizeof(dwValue);
  234. dwValue = 0;
  235. //
  236. // Check arguments.
  237. //
  238. if( (NULL == hkRegistry)
  239. || (NULL == szValueName)
  240. || (NULL == pdwValue) )
  241. {
  242. DebugTrace(TRACE_ERROR,(("GetDwordFromRegistry: ERROR!! Invalid argument\r\n")));
  243. bRet = FALSE;
  244. goto GetDwordFromRegistry_return;
  245. }
  246. //
  247. // Get specified string from registry.
  248. //
  249. lError = RegQueryValueEx(hkRegistry,
  250. szValueName,
  251. NULL,
  252. &dwType,
  253. (LPBYTE)&dwValue,
  254. &dwSize);
  255. if(ERROR_SUCCESS != lError){
  256. DebugTrace(TRACE_WARNING,(("GetDwordFromRegistry: WARNING!! RegQueryValueEx failed. Err=0x%x. Size=0x%x, Type=0x%x\r\n"), lError, dwSize, dwType));
  257. bRet = FALSE;
  258. goto GetDwordFromRegistry_return;
  259. }
  260. //
  261. // Copy acquired DWORD value to given buffer.
  262. //
  263. *pdwValue = dwValue;
  264. //
  265. // Operation succeeded.
  266. //
  267. bRet = TRUE;
  268. GetDwordFromRegistry_return:
  269. return bRet;
  270. } // GetDwordFromRegistry
  271. VOID
  272. SetRunonceKey(
  273. LPTSTR szValue,
  274. LPTSTR szData
  275. )
  276. {
  277. HKEY hkRun;
  278. LONG lResult;
  279. CString csData;
  280. //
  281. // Initialize local.
  282. //
  283. hkRun = NULL;
  284. lResult = ERROR_SUCCESS;
  285. csData = szData;
  286. //
  287. // Get RUNONCE regkey.
  288. //
  289. lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  290. REGSTR_PATH_RUNONCE,
  291. 0,
  292. KEY_READ | KEY_WRITE,
  293. &hkRun);
  294. if(ERROR_SUCCESS == lResult){
  295. csData.Store(hkRun, szValue);
  296. RegCloseKey(hkRun);
  297. } // if(ERROR_SUCCESS == lResult)
  298. } // SetRunonceKey()
  299. VOID
  300. ShowInstallerMessage(
  301. DWORD dwMessageId
  302. )
  303. {
  304. CString csTitle;
  305. CString csText;
  306. csTitle.FromTable (MessageTitle);
  307. csText.FromTable ((unsigned)dwMessageId);
  308. if( !csTitle.IsEmpty() && !csText.IsEmpty()){
  309. MessageBox (GetActiveWindow(),
  310. csText,
  311. csTitle,
  312. MB_ICONINFORMATION | MB_OK);
  313. } // if(csTitle.IsEmpty() || csText.IsEmpty())
  314. } // ShowInstallerMessage()
  315. BOOL
  316. IsWindowsFile(
  317. LPTSTR szFileName
  318. )
  319. {
  320. BOOL bRet;
  321. DWORD dwNumberOfChar;
  322. TCHAR szLayoutInfpath[MAX_PATH+1];
  323. TCHAR szReturnBuffer[MAX_PATH];
  324. TCHAR *pszFileNameWithoutPath;
  325. DWORD Idx;
  326. DebugTrace(TRACE_PROC_ENTER,("IsWindowsFile: Enter... Checking %ws.\r\n", szFileName));
  327. //
  328. // Initialize local.
  329. //
  330. bRet = FALSE;
  331. dwNumberOfChar = 0;
  332. Idx = 0;
  333. pszFileNameWithoutPath = NULL;
  334. memset(szLayoutInfpath, 0, sizeof(szLayoutInfpath));
  335. //
  336. // Get INF filename without path.
  337. //
  338. while(TEXT('\0') != szFileName[Idx]){
  339. if(TEXT('\\') == szFileName[Idx]){
  340. pszFileNameWithoutPath = &(szFileName[Idx+1]);
  341. } // if('\\' == szFileName[Idx])
  342. Idx++;
  343. } // while('\0' != szFileName[Idx])
  344. //
  345. // Get system directory.
  346. //
  347. if(0 == GetWindowsDirectory(szLayoutInfpath, sizeof(szLayoutInfpath)/sizeof(TCHAR))){
  348. DebugTrace(TRACE_ERROR,("IsWindowsFile: ERROR!! GetWindowsDirectory failed. Err=0x%x.\r\n", GetLastError()));
  349. bRet = FALSE;
  350. goto IsWindowsFile_return;
  351. } // if(0 == GetWindowsDirectory(szSystemDir, sizeof(szSystemDir)/sizeof(TCHAR)))
  352. //
  353. // Create fullpath of layout.inf.
  354. //
  355. lstrcat(szLayoutInfpath, LAYOUT_INF_PATH);
  356. DebugTrace(TRACE_STATUS,("IsWindowsFile: Looking for \'%ws\' in %ws.\r\n", pszFileNameWithoutPath, szLayoutInfpath));
  357. //
  358. // See if provided filename is in layout.inf.
  359. //
  360. dwNumberOfChar = GetPrivateProfileString(SOURCEDISKFILES,
  361. pszFileNameWithoutPath,
  362. NULL,
  363. szReturnBuffer,
  364. sizeof(szReturnBuffer) / sizeof(TCHAR),
  365. szLayoutInfpath);
  366. if(0 == dwNumberOfChar){
  367. //
  368. // Filename doesn't exist in layout.inf.
  369. //
  370. bRet = FALSE;
  371. goto IsWindowsFile_return;
  372. } // if(0 == dwNumberOfChar)
  373. //
  374. // This filename exists in layout.inf.
  375. //
  376. bRet = TRUE;
  377. IsWindowsFile_return:
  378. DebugTrace(TRACE_PROC_LEAVE,("IsWindowsFile: Leaving... Ret=0x%x\n", bRet));
  379. return bRet;
  380. } // IsWindowsFile()
  381. BOOL
  382. IsProviderMs(
  383. LPTSTR szInfName
  384. )
  385. {
  386. BOOL bRet;
  387. DWORD dwSize;
  388. TCHAR szProvider[MAX_PATH+1];
  389. PSP_INF_INFORMATION pspInfInfo;
  390. DebugTrace(TRACE_PROC_ENTER,("IsProviderMs: Enter... Checking %ws.\r\n", szInfName));
  391. //
  392. // Initialize local.
  393. //
  394. bRet = FALSE;
  395. dwSize = 0;
  396. pspInfInfo = NULL;
  397. memset(szProvider, 0, sizeof(szProvider));
  398. //
  399. // Get INF information size.
  400. //
  401. SetupGetInfInformation(szInfName,
  402. INFINFO_INF_NAME_IS_ABSOLUTE,
  403. NULL,
  404. 0,
  405. &dwSize);
  406. if(0 == dwSize){
  407. DebugTrace(TRACE_ERROR,(("IsProviderMs: ERROR!! Enable to get required size for INF info. Err=0x%x.\r\n"), GetLastError()));
  408. bRet = FALSE;
  409. goto IsProviderMs_return;
  410. } // if(0 == dwSize)
  411. //
  412. // Allocate buffer for INF information.
  413. //
  414. pspInfInfo = (PSP_INF_INFORMATION) new char[dwSize];
  415. if(NULL == pspInfInfo){
  416. DebugTrace(TRACE_ERROR,(("IsProviderMs: ERROR!! Insuffisient memory.\r\n")));
  417. bRet = FALSE;
  418. goto IsProviderMs_return;
  419. } // if(NULL == pspInfInfo)
  420. //
  421. // Get actual INF informaton.
  422. //
  423. if(!SetupGetInfInformation(szInfName,
  424. INFINFO_INF_NAME_IS_ABSOLUTE,
  425. pspInfInfo,
  426. dwSize,
  427. &dwSize))
  428. {
  429. DebugTrace(TRACE_ERROR,(("IsProviderMs: ERROR!! Unable to get Inf info. Err=0x%x.\r\n"), GetLastError()));
  430. bRet = FALSE;
  431. goto IsProviderMs_return;
  432. } // if(!SetupGetInflnformation()
  433. //
  434. // Query "Provider" of given INF.
  435. //
  436. if(!SetupQueryInfVersionInformation(pspInfInfo,
  437. 0,
  438. PROVIDER,
  439. szProvider,
  440. ARRAYSIZE(szProvider)-1,
  441. &dwSize))
  442. {
  443. DebugTrace(TRACE_ERROR,(("IsProviderMs: ERROR!! SetupQueryInfVersionInformation() failed. Err=0x%x.\r\n"), GetLastError()));
  444. bRet = FALSE;
  445. goto IsProviderMs_return;
  446. } // if(!SetupGetInflnformation()
  447. //
  448. // See if provider is "Microsoft"
  449. //
  450. DebugTrace(TRACE_STATUS,(("IsProviderMs: Provider = \'%ws\'.\r\n"), szProvider));
  451. if(0 == MyStrCmpi(szProvider, MICROSOFT)){
  452. //
  453. // This INF file has 'Provider = "Microsoft"'
  454. //
  455. bRet = TRUE;
  456. } // if(0 == lstrcmp(szProvider, MICROSOFT))
  457. IsProviderMs_return:
  458. if(NULL != pspInfInfo){
  459. delete[] pspInfInfo;
  460. } // if(NULL != pspInfInfo)
  461. DebugTrace(TRACE_PROC_LEAVE,("IsProviderMs: Leaving... Ret=0x%x\n", bRet));
  462. return bRet;
  463. } // IsProviderMs()
  464. BOOL
  465. IsIhvAndInboxExisting(
  466. HDEVINFO hDevInfo,
  467. PSP_DEVINFO_DATA pDevInfoData
  468. )
  469. {
  470. BOOL bRet;
  471. BOOL bIhvExists;
  472. BOOL bInboxExists;
  473. DWORD dwLastError;
  474. DWORD dwSize;
  475. DWORD Idx;
  476. SP_DRVINSTALL_PARAMS spDriverInstallParams;
  477. SP_DRVINFO_DATA spDriverInfoData;
  478. PSP_DRVINFO_DETAIL_DATA pspDriverInfoDetailData;
  479. //
  480. // Initialize local.
  481. //
  482. bRet = FALSE;
  483. bIhvExists = FALSE;
  484. bInboxExists = FALSE;
  485. dwSize = 0;
  486. Idx = 0;
  487. dwLastError = ERROR_SUCCESS;
  488. pspDriverInfoDetailData = NULL;
  489. memset(&spDriverInstallParams, 0, sizeof(spDriverInstallParams));
  490. //
  491. // Get driver info.
  492. //
  493. memset(&spDriverInfoData, 0, sizeof(spDriverInfoData));
  494. spDriverInfoData.cbSize = sizeof(SP_DRVINFO_DATA);
  495. for(Idx = 0; SetupDiEnumDriverInfo(hDevInfo, pDevInfoData, SPDIT_COMPATDRIVER, Idx, &spDriverInfoData); Idx++){
  496. //
  497. // Get driver install params.
  498. //
  499. memset(&spDriverInstallParams, 0, sizeof(spDriverInstallParams));
  500. spDriverInstallParams.cbSize = sizeof(SP_DRVINSTALL_PARAMS);
  501. if(!SetupDiGetDriverInstallParams(hDevInfo, pDevInfoData, &spDriverInfoData, &spDriverInstallParams)){
  502. DebugTrace(TRACE_ERROR,("IsIhvAndInboxExisting: ERROR!! SetupDiGetDriverInstallParams() failed LastError=0x%x.\r\n", GetLastError()));
  503. goto IsIhvAndInboxExisting_return;
  504. } // if(!SetupDiGetDriverInstallParams(hDevInfo, pDevInfoData, &spDriverInfoData, &spDriverInstallParams))
  505. //
  506. // Get buffer size required for driver derail data.
  507. //
  508. dwSize = 0;
  509. SetupDiGetDriverInfoDetail(hDevInfo,
  510. pDevInfoData,
  511. &spDriverInfoData,
  512. NULL,
  513. 0,
  514. &dwSize);
  515. dwLastError = GetLastError();
  516. if(ERROR_INSUFFICIENT_BUFFER != dwLastError){
  517. DebugTrace(TRACE_ERROR,(("IsIhvAndInboxExisting: ERROR!! SetupDiGetDriverInfoDetail() doesn't return required size.Er=0x%x\r\n"),dwLastError));
  518. goto IsIhvAndInboxExisting_return;
  519. } // if(ERROR_INSUFFICIENT_BUFFER != dwLastError)
  520. //
  521. // Allocate required size of buffer for driver detailed data.
  522. //
  523. pspDriverInfoDetailData = (PSP_DRVINFO_DETAIL_DATA)new char[dwSize];
  524. if(NULL == pspDriverInfoDetailData){
  525. DebugTrace(TRACE_ERROR,(("IsIhvAndInboxExisting: ERROR!! Unable to allocate driver detailed info buffer.\r\n")));
  526. goto IsIhvAndInboxExisting_return;
  527. } // if(NULL == pspDriverInfoDetailData)
  528. //
  529. // Initialize allocated buffer.
  530. //
  531. memset(pspDriverInfoDetailData, 0, dwSize);
  532. pspDriverInfoDetailData->cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
  533. //
  534. // Get detailed data of selected device driver.
  535. //
  536. if(!SetupDiGetDriverInfoDetail(hDevInfo,
  537. pDevInfoData,
  538. &spDriverInfoData,
  539. pspDriverInfoDetailData,
  540. dwSize,
  541. NULL) )
  542. {
  543. DebugTrace(TRACE_ERROR,("IsIhvAndInboxExisting: ERROR!! SetupDiGetDriverInfoDetail() failed LastError=0x%x.\r\n", GetLastError()));
  544. delete[] pspDriverInfoDetailData;
  545. pspDriverInfoDetailData = NULL;
  546. continue;
  547. } // if(NULL == pspDriverInfoDetailData)
  548. //
  549. // See if INF filename is valid.
  550. //
  551. if(NULL == pspDriverInfoDetailData->InfFileName){
  552. DebugTrace(TRACE_ERROR,("IsIhvAndInboxExisting: ERROR!! SetupDiGetDriverInfoDetail() returned invalid INF name.\r\n"));
  553. delete[] pspDriverInfoDetailData;
  554. pspDriverInfoDetailData = NULL;
  555. continue;
  556. } // if(NULL == pspDriverInfoDetailData->InfFileName)
  557. //
  558. // If it's Inbox driver, lower the lank.
  559. //
  560. if( IsWindowsFile(pspDriverInfoDetailData->InfFileName)
  561. && IsProviderMs(pspDriverInfoDetailData->InfFileName ) )
  562. {
  563. //
  564. // This is inbox INF.
  565. //
  566. bInboxExists = TRUE;
  567. } else { // if(IsWindowsFilw() && IsProviderMs())
  568. //
  569. // This is IHV INF.
  570. //
  571. bIhvExists = TRUE;
  572. }
  573. //
  574. // Clean up.
  575. //
  576. delete[] pspDriverInfoDetailData;
  577. pspDriverInfoDetailData = NULL;
  578. } // for(Idx = 0; SetupDiEnumDriverInfo(hDevInfo, pDevInfoData, SPDIT_COMPATDRIVER, Idx, &spDriverInfoData), Idx++)
  579. IsIhvAndInboxExisting_return:
  580. if( (TRUE == bInboxExists)
  581. && (TRUE == bIhvExists) )
  582. {
  583. bRet = TRUE;
  584. } else { // if(bInboxExists && bIhvExists)
  585. bRet = FALSE;
  586. } // else // if(bInboxExists && bIhvExists)
  587. DebugTrace(TRACE_PROC_LEAVE,("IsIhvAndInboxExisting: Leaving... Ret=0x%x\n", bRet));
  588. return bRet;
  589. } // IsProviderMs()
  590. CInstallerMutex::CInstallerMutex(
  591. HANDLE* phMutex,
  592. LPTSTR szMutexName,
  593. DWORD dwTimeout
  594. )
  595. {
  596. m_bSucceeded = FALSE;
  597. m_phMutex = phMutex;
  598. _try {
  599. *m_phMutex = CreateMutex(NULL, FALSE, szMutexName);
  600. if(NULL != *m_phMutex){
  601. //
  602. // Wait until ownership is acquired.
  603. //
  604. switch(WaitForSingleObject(*m_phMutex, dwTimeout)){
  605. case WAIT_ABANDONED:
  606. DebugTrace(TRACE_ERROR, ("CInstallerMutex: ERROR!! Wait abandoned.\r\n"));
  607. m_bSucceeded = TRUE;
  608. break;
  609. case WAIT_OBJECT_0:
  610. DebugTrace(TRACE_STATUS, ("CInstallerMutex: Mutex acquired.\r\n"));
  611. m_bSucceeded = TRUE;
  612. break;
  613. case WAIT_TIMEOUT:
  614. DebugTrace(TRACE_WARNING, ("CInstallerMutex: WARNING!! Mutex acquisition timeout.\r\n"));
  615. break;
  616. default:
  617. DebugTrace(TRACE_ERROR, ("CInstallerMutex: ERROR!! Unexpected error from WaitForSingleObjecct().\r\n"));
  618. break;
  619. } // switch(dwReturn)
  620. } // if(NULL != *m_phMutex)
  621. }
  622. _except (EXCEPTION_EXECUTE_HANDLER) {
  623. DebugTrace(TRACE_ERROR, ("CInstallerMutex: ERROR!! Unexpected exception.\r\n"));
  624. }
  625. } // CInstallerMutex::CInstallerMutex()
  626. CInstallerMutex::~CInstallerMutex(
  627. )
  628. {
  629. if (m_bSucceeded) {
  630. ReleaseMutex(*m_phMutex);
  631. DebugTrace(TRACE_STATUS, ("CInstallerMutex: Mutex released.\r\n"));
  632. }
  633. if(NULL != *m_phMutex){
  634. CloseHandle(*m_phMutex);
  635. } // if(NULL != *m_phMutex)
  636. } // CInstallerMutex::~CInstallerMutex(
  637. HFONT
  638. GetIntroFont(
  639. HWND hwnd
  640. )
  641. {
  642. static HFONT _hfontIntro = NULL;
  643. static int iDevCap = 0;
  644. if ( !_hfontIntro ){
  645. TCHAR szBuffer[64];
  646. NONCLIENTMETRICS ncm = { 0 };
  647. LOGFONT lf;
  648. CString csSize;
  649. HDC hDC = (HDC)NULL;
  650. hDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
  651. if(NULL != hDC){
  652. iDevCap = GetDeviceCaps(hDC, LOGPIXELSY);
  653. ncm.cbSize = sizeof(ncm);
  654. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
  655. lf = ncm.lfMessageFont;
  656. if(0 != LoadString(g_hDllInstance, IDS_TITLEFONTNAME, lf.lfFaceName, (sizeof(lf.lfFaceName)/sizeof(TCHAR)))){
  657. lf.lfWeight = FW_BOLD;
  658. if(0 != LoadString(g_hDllInstance, IDS_TITLEFONTSIZE, szBuffer, (sizeof(szBuffer)/sizeof(TCHAR)))){
  659. csSize = szBuffer;
  660. lf.lfHeight = 0 - (iDevCap * (DWORD)csSize.Decode() / 72);
  661. _hfontIntro = CreateFontIndirect(&lf);
  662. } // if(0 != LoadString(g_hDllInstance, IDS_TITLEFONTSIZE, szBuffer, (sizeof(szBuffer)/sizeof(TCHAR))))
  663. } // if(0 != LoadString(g_hDllInstance, IDS_TITLEFONTNAME, lf.lfFaceName, (sizeof(lf.lfFaceName)/sizeof(TCHAR))))
  664. DeleteDC(hDC);
  665. } else { // if(NULL != hDC)
  666. DebugTrace(TRACE_ERROR, ("GetIntroFont: ERROR!! Unable to create DC.Err=0x%x.\r\n",GetLastError()));
  667. } // else(NULL != hDC)
  668. }
  669. return _hfontIntro;
  670. } // GetIntroFont()
  671. BOOL
  672. IsDeviceRootEnumerated(
  673. IN HDEVINFO hDevInfo,
  674. IN PSP_DEVINFO_DATA pDevInfoData
  675. )
  676. {
  677. CONFIGRET cmRetCode;
  678. BOOL bRet;
  679. ULONG ulStatus;
  680. ULONG ulProblem;
  681. DebugTrace(TRACE_PROC_ENTER,("IsDeviceRootEnumerated: Enter... \r\n"));
  682. //
  683. // Initialize local.
  684. //
  685. cmRetCode = CR_SUCCESS;
  686. bRet = FALSE;
  687. ulStatus = 0;
  688. ulProblem = 0;
  689. //
  690. // Devnode Status.
  691. //
  692. cmRetCode = CM_Get_DevNode_Status(&ulStatus,
  693. &ulProblem,
  694. pDevInfoData->DevInst,
  695. 0);
  696. if(CR_SUCCESS != cmRetCode){
  697. //
  698. // Unable to get devnode status.
  699. //
  700. DebugTrace(TRACE_ERROR,("IsDeviceRootEnumerated: ERROR!! Unable to get Devnode status. CR=0x%x.\r\n", cmRetCode));
  701. bRet = FALSE;
  702. goto IsDeviceRootEnumerated_return;
  703. } // if(CD_SUCCESS != cmRetCode)
  704. //
  705. // See if it's root-enumerated.
  706. //
  707. if(DN_ROOT_ENUMERATED & ulStatus){
  708. //
  709. // This devnode is root-enumerated.
  710. //
  711. bRet = TRUE;
  712. } // if(DN_ROOT_ENUMERATED & ulStatus)
  713. IsDeviceRootEnumerated_return:
  714. DebugTrace(TRACE_PROC_LEAVE,("IsDeviceRootEnumerated: Leaving... Ret=0x%x.\r\n", bRet));
  715. return bRet;
  716. } // IsDeviceRootEnumerated()
  717. int
  718. MyStrCmpi(
  719. LPCTSTR str1,
  720. LPCTSTR str2
  721. )
  722. {
  723. int iRet;
  724. //
  725. // Initialize local.
  726. //
  727. iRet = 0;
  728. //
  729. // Compare string.
  730. //
  731. if(CSTR_EQUAL == CompareString(LOCALE_INVARIANT,
  732. NORM_IGNORECASE,
  733. str1,
  734. -1,
  735. str2,
  736. -1) )
  737. {
  738. iRet = 0;
  739. } else {
  740. iRet = -1;
  741. }
  742. return iRet;
  743. } // MyStrCmpi()
  744. VOID
  745. LogSystemEvent(
  746. WORD wEventType,
  747. DWORD dwEventID,
  748. WORD wNumberOfString,
  749. LPTSTR szMsg[]
  750. )
  751. {
  752. HANDLE hSystemEvent;
  753. DebugTrace(TRACE_PROC_ENTER,("LogSystemEvent: Enter...\r\n"));
  754. //
  755. // Initialize local.
  756. //
  757. hSystemEvent = NULL;
  758. //
  759. // Get handle to System event log.
  760. //
  761. hSystemEvent = RegisterEventSource(NULL, STILLIMAGE);
  762. if(NULL == hSystemEvent){
  763. //
  764. // Unable to open System log.
  765. //
  766. DebugTrace(TRACE_ERROR,("LogSystemEvent: ERROR!! Unable to get handle to system log. Err=0x%x.\r\n", GetLastError()));
  767. goto LogSystemEvent_return;
  768. } // if (NULL == hSystemEvent)
  769. if(!ReportEvent(hSystemEvent,
  770. wEventType,
  771. 0,
  772. dwEventID,
  773. NULL,
  774. wNumberOfString,
  775. 0,
  776. (LPCTSTR *)szMsg,
  777. (LPVOID)NULL) )
  778. {
  779. DebugTrace(TRACE_ERROR,("LogSystemEvent: ERROR!! Unable to log to system log. Err=0x%x.\r\n", GetLastError()));
  780. goto LogSystemEvent_return;
  781. }
  782. LogSystemEvent_return:
  783. if(IS_VALID_HANDLE(hSystemEvent)){
  784. DeregisterEventSource(hSystemEvent);
  785. hSystemEvent = NULL;
  786. } // if(IS_VALID_HANDLE())
  787. DebugTrace(TRACE_PROC_LEAVE,("LogSystemEvent: Leaving... Ret=VOID.\r\n"));
  788. return;
  789. } // LogSystemEvent()