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.

971 lines
25 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1995 - 1999
  3. All rights reserved.
  4. Module Name:
  5. drvsetup.cxx
  6. Abstract:
  7. Printer Driver Setup class. This class is used to do various
  8. types of printer driver installations.
  9. Author:
  10. Steve Kiraly (SteveKi) 01-Nov-1996
  11. Revision History:
  12. --*/
  13. #include "precomp.hxx"
  14. #pragma hdrstop
  15. #include "psetup.hxx"
  16. #include "drvver.hxx"
  17. #include "splapip.h"
  18. #include "compinfo.hxx"
  19. #include "drvsetup.hxx"
  20. /********************************************************************
  21. Printer Driver installation class.
  22. ********************************************************************/
  23. TPrinterDriverInstallation::
  24. TPrinterDriverInstallation(
  25. IN LPCTSTR pszServerName,
  26. IN HWND hwnd
  27. ) : _strServerName( pszServerName ),
  28. _bValid( FALSE ),
  29. _hwnd( hwnd ),
  30. _hSetupDrvSetupParams( INVALID_HANDLE_VALUE ),
  31. _hSelectedDrvInfo( INVALID_HANDLE_VALUE ),
  32. _pszServerName( NULL ),
  33. _dwDriverVersion( (DWORD)kDefault ),
  34. _dwInstallFlags( 0 )
  35. {
  36. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::ctor\n" ) );
  37. //
  38. // Initialize the os version info structure.
  39. //
  40. memset( &_OsVersionInfo, 0, sizeof( _OsVersionInfo ) );
  41. //
  42. // Check if the setup library is valid.
  43. //
  44. if( !VALID_OBJ( _PSetup ) || !VALID_OBJ( _strServerName ) )
  45. {
  46. return;
  47. }
  48. //
  49. // A null server name is the local machine.
  50. //
  51. if( pszServerName )
  52. {
  53. DBGMSG( DBG_WARN, ( "Remote machine specified.\n" ) );
  54. _pszServerName = const_cast<LPTSTR>( static_cast<LPCTSTR>( _strServerName ) );
  55. }
  56. //
  57. // Get the setup driver parameter handle.
  58. //
  59. _hSetupDrvSetupParams = _PSetup.PSetupCreatePrinterDeviceInfoList( _hwnd );
  60. if( _hSetupDrvSetupParams == INVALID_HANDLE_VALUE )
  61. {
  62. DBGMSG( DBG_WARN, ( "PSetup.PSetupCreatePrinterDeviceInfoList failed.\n" ) );
  63. return;
  64. }
  65. //
  66. // Get the current platform / driver version.
  67. //
  68. if( !bGetCurrentDriver( pszServerName, &_dwDriverVersion ) )
  69. {
  70. DBGMSG( DBG_WARN, ( "GetCurrentDriver failed with %d.\n", GetLastError() ) );
  71. //
  72. // If we are talking to a remote machine and the get current driver failed
  73. // then instead of failing construnction use this platforms driver version.
  74. //
  75. if( !pszServerName )
  76. {
  77. //
  78. // Unable to get the platform / driver version
  79. // from the local spooler.
  80. //
  81. return;
  82. }
  83. //
  84. // Try to get the driver version from the local spooler
  85. //
  86. if( !bGetCurrentDriver( NULL, &_dwDriverVersion ) )
  87. {
  88. DBGMSG( DBG_WARN, ( "GetCurrentDriver failed with %d.\n", GetLastError() ) );
  89. return;
  90. }
  91. }
  92. //
  93. // We have a valid object.
  94. //
  95. _bValid = TRUE;
  96. }
  97. TPrinterDriverInstallation::
  98. ~TPrinterDriverInstallation(
  99. VOID
  100. )
  101. {
  102. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::dtor\n" ) );
  103. //
  104. // Release the selected driver information.
  105. //
  106. vReleaseSelectedDriver();
  107. //
  108. // Release the driver setup parameter handle.
  109. //
  110. if( _hSetupDrvSetupParams != INVALID_HANDLE_VALUE )
  111. {
  112. _PSetup.PSetupDestroyPrinterDeviceInfoList( _hSetupDrvSetupParams );
  113. }
  114. }
  115. BOOL
  116. TPrinterDriverInstallation::
  117. bValid(
  118. VOID
  119. ) const
  120. {
  121. return _bValid;
  122. }
  123. TPrinterDriverInstallation::EStatusCode
  124. TPrinterDriverInstallation::
  125. ePromptForDriverSelection(
  126. VOID
  127. )
  128. {
  129. SPLASSERT( bValid() );
  130. TPrinterDriverInstallation::EStatusCode Retval = kError;
  131. //
  132. // Release any selected driver information.
  133. //
  134. vReleaseSelectedDriver();
  135. //
  136. // Display UI for the user to select a driver.
  137. //
  138. if( _PSetup.PSetupSelectDriver( _hSetupDrvSetupParams, _hwnd ) )
  139. {
  140. //
  141. // Refresh the driver name with the currently selected driver.
  142. //
  143. if( bGetSelectedDriver() )
  144. {
  145. DBGMSG( DBG_TRACE, ( "Selected Driver " TSTR "\n", (LPCTSTR)_strDriverName ) );
  146. Retval = kSuccess;
  147. }
  148. }
  149. else
  150. {
  151. //
  152. // Check if the user hit cancel, this is not
  153. // an error just normal cancel request.
  154. //
  155. if( GetLastError() == ERROR_CANCELLED )
  156. {
  157. DBGMSG( DBG_TRACE, ( "Select driver user cancel request.\n" ) );
  158. Retval = kCancel;
  159. }
  160. else
  161. {
  162. DBGMSG( DBG_TRACE, ( "PSetupSelectDriver failed %d\n", GetLastError() ) );
  163. Retval = kError;
  164. }
  165. }
  166. return Retval;
  167. }
  168. BOOL
  169. TPrinterDriverInstallation::
  170. bSetDriverName(
  171. IN const TString &strDriverName
  172. )
  173. {
  174. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bSetDriverName\n" ) );
  175. SPLASSERT( bValid() );
  176. return _strDriverName.bUpdate( strDriverName );
  177. }
  178. BOOL
  179. TPrinterDriverInstallation::
  180. bGetDriverName(
  181. IN TString &strDriverName
  182. ) const
  183. {
  184. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bGetDriverName\n" ) );
  185. SPLASSERT( bValid() );
  186. return strDriverName.bUpdate( _strDriverName );
  187. }
  188. BOOL
  189. TPrinterDriverInstallation::
  190. bIsDriverInstalled(
  191. IN const DWORD xdwDriverVersion,
  192. IN const BOOL bKernelModeCompatible
  193. ) const
  194. {
  195. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bIsDriverInstalled\n" ) );
  196. SPLASSERT( bValid() );
  197. TStatusB bStatus;
  198. PLATFORM DriverPlatform;
  199. DWORD dwDriverVersion;
  200. //
  201. // If the default was passed then then use the pre-fetched version value.
  202. //
  203. if( xdwDriverVersion == kDefault )
  204. {
  205. DriverPlatform = GetDriverPlatform( _dwDriverVersion );
  206. dwDriverVersion = GetDriverVersion( _dwDriverVersion );
  207. }
  208. else
  209. {
  210. DriverPlatform = GetDriverPlatform( xdwDriverVersion );
  211. dwDriverVersion = GetDriverVersion( xdwDriverVersion );
  212. }
  213. //
  214. // If we want to check if this a kernel mode compatible driver
  215. // then the printer setup api's will accept the kKernelModeDriver
  216. // value and do the compatiblity check. Note if the driver version is
  217. // less than version 2 the kernel mode compatibiltiy flag does not apply.
  218. //
  219. if( bKernelModeCompatible && ( _dwDriverVersion >= 2 ) )
  220. {
  221. dwDriverVersion = KERNEL_MODE_DRIVER_VERSION;
  222. }
  223. //
  224. // Check if the selected printer is currently installed.
  225. //
  226. bStatus DBGNOCHK = _PSetup.PSetupIsDriverInstalled( _pszServerName,
  227. _strDriverName,
  228. DriverPlatform,
  229. dwDriverVersion );
  230. return bStatus;
  231. }
  232. INT
  233. TPrinterDriverInstallation::
  234. IsDriverInstalledForInf(
  235. IN const DWORD xdwDriverVersion,
  236. IN const BOOL bKernelModeCompatible
  237. ) const
  238. {
  239. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::iIsDriverInstalledForInf\n" ) );
  240. SPLASSERT( bValid() );
  241. INT iReturn = DRIVER_MODEL_NOT_INSTALLED;
  242. DWORD dwDriverVersion = xdwDriverVersion == kDefault ? _dwDriverVersion : xdwDriverVersion;
  243. //
  244. // We must have a selected driver to call this API.
  245. //
  246. TStatusB bStatus;
  247. bStatus DBGCHK = bIsDriverSelected( );
  248. if( bStatus )
  249. {
  250. //
  251. // If we want to check if this a kernel mode compatible driver
  252. // then the printer setup api's will accept the kKernelModeDriver
  253. // value and do the compatiblity check. Note if the driver version is
  254. // less than version 2 the kernel mode compatibiltiy flag does not apply.
  255. //
  256. DWORD dwDriver = bKernelModeCompatible && ( dwDriverVersion >= 2 ) ? KERNEL_MODE_DRIVER_VERSION : GetDriverVersion( dwDriverVersion );
  257. //
  258. // Check if the selected printer is currently installed.
  259. //
  260. iReturn = _PSetup.PSetupIsTheDriverFoundInInfInstalled( _pszServerName,
  261. _hSelectedDrvInfo,
  262. GetDriverPlatform( dwDriverVersion ),
  263. GetDriverVersion( dwDriverVersion ),
  264. dwDriver );
  265. }
  266. return iReturn;
  267. }
  268. BOOL
  269. TPrinterDriverInstallation::
  270. bSetSourcePath(
  271. IN const LPCTSTR pszSourcePath,
  272. IN const BOOL bClearSourcePath
  273. )
  274. {
  275. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bSetSourcePath\n" ) );
  276. SPLASSERT( bValid() );
  277. DBGMSG( DBG_TRACE, ( "SourcePath " TSTR "\n", DBGSTR( pszSourcePath ) ) );
  278. if( bClearSourcePath )
  279. {
  280. return _strSourcePath.bUpdate( NULL );
  281. }
  282. return bValidateSourcePath( pszSourcePath ) && _strSourcePath.bUpdate( pszSourcePath );
  283. }
  284. VOID
  285. TPrinterDriverInstallation::
  286. SetInstallFlags(
  287. DWORD dwInstallFlags
  288. )
  289. {
  290. _dwInstallFlags = dwInstallFlags;
  291. }
  292. DWORD
  293. TPrinterDriverInstallation::
  294. GetInstallFlags(
  295. VOID
  296. ) const
  297. {
  298. return _dwInstallFlags;
  299. }
  300. BOOL
  301. TPrinterDriverInstallation::
  302. bInstallDriver(
  303. OUT TString *pstrNewDriverName,
  304. IN BOOL bOfferReplacement,
  305. IN const BOOL xInstallFromWeb,
  306. IN const HWND xhwnd,
  307. IN const DWORD xdwDriverVersion,
  308. IN const DWORD xdwAddDrvFlags,
  309. IN const BOOL xbUpdateDriver,
  310. IN const BOOL xbIgnoreSelectDriverFailure
  311. )
  312. {
  313. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bInstallDriver\n" ) );
  314. SPLASSERT( bValid() );
  315. SPLASSERT( !_strDriverName.bEmpty() );
  316. TStatus Status;
  317. TStatusB bStatus;
  318. DWORD dwDriverVersion = xdwDriverVersion == kDefault ? _dwDriverVersion : xdwDriverVersion;
  319. HWND hwnd = xhwnd == NULL ? _hwnd : xhwnd;
  320. BOOL bInstallFromWeb = xInstallFromWeb == kDefault ? FALSE : xInstallFromWeb;
  321. DWORD dwAddDrvFlags = xdwAddDrvFlags == kDefault ? APD_COPY_NEW_FILES : xdwAddDrvFlags;
  322. BOOL bUseDriverName = FALSE;
  323. //
  324. // Assume success.
  325. //
  326. bStatus DBGNOCHK = TRUE;
  327. //
  328. // This is an optimization. Since getting the selected driver actually parses
  329. // the inf file. In this routine we will execute the if statement the
  330. // caller has set the driver name without selecting a driver.
  331. //
  332. if( !bIsDriverSelected( ) && xbUpdateDriver == kDefault )
  333. {
  334. //
  335. // If a driver name was set then select a driver using this name.
  336. //
  337. BOOL bSelectFromName = _strDriverName.bEmpty() ? FALSE : TRUE;
  338. //
  339. // Select the driver.
  340. //
  341. bStatus DBGCHK = bSelectDriver( bSelectFromName );
  342. //
  343. // In the case the caller just wants to use the inf if one exists
  344. // if an inf does not exist for this driver then prompt them. If
  345. // the caller wants to prompt the user if an inf does not exist they
  346. // should set the bIgnoreSelectDriverFailure to true.
  347. //
  348. if (bStatus == FALSE && xbIgnoreSelectDriverFailure == TRUE)
  349. {
  350. bStatus DBGCHK = TRUE;
  351. bUseDriverName = TRUE;
  352. }
  353. }
  354. if( bStatus )
  355. {
  356. //
  357. // Get the driver architecture name.
  358. //
  359. TString strDrvArchName;
  360. bStatus DBGCHK = bGetArchName(dwDriverVersion, strDrvArchName );
  361. DBGMSG( DBG_TRACE, ( "Driver Architecture and version " TSTR "\n", static_cast<LPCTSTR>( strDrvArchName ) ) );
  362. if( bStatus )
  363. {
  364. LPCTSTR pszSourcePath = _strSourcePath.bEmpty() ? NULL : (LPCTSTR)_strSourcePath;
  365. if( bInstallFromWeb )
  366. {
  367. //
  368. // Install the specified printer driver.
  369. //
  370. Status DBGCHK = _PSetup.PSetupInstallPrinterDriverFromTheWeb( _hSetupDrvSetupParams,
  371. _hSelectedDrvInfo,
  372. GetDriverPlatform( dwDriverVersion ),
  373. _pszServerName,
  374. pGetOsVersionInfo(),
  375. hwnd,
  376. pszSourcePath );
  377. }
  378. else
  379. {
  380. HANDLE hDriverInfo = _hSelectedDrvInfo;
  381. LPCTSTR pszDriverName = _strDriverName;
  382. //
  383. // If we are not updating the driver then clear the driver name.
  384. //
  385. if( xbUpdateDriver == kDefault && bUseDriverName == FALSE )
  386. {
  387. pszDriverName = NULL;
  388. }
  389. else
  390. {
  391. hDriverInfo = NULL;
  392. }
  393. //
  394. // Install the specified printer driver.
  395. //
  396. Status DBGCHK = _PSetup.PSetupInstallPrinterDriver( _hSetupDrvSetupParams,
  397. hDriverInfo,
  398. pszDriverName,
  399. GetDriverPlatform( dwDriverVersion ),
  400. GetDriverVersion( dwDriverVersion ),
  401. _pszServerName,
  402. hwnd,
  403. strDrvArchName,
  404. pszSourcePath,
  405. _dwInstallFlags,
  406. dwAddDrvFlags,
  407. pstrNewDriverName,
  408. bOfferReplacement );
  409. }
  410. //
  411. // Set up the correct return value.
  412. //
  413. bStatus DBGNOCHK = Status == ERROR_SUCCESS ? TRUE : FALSE;
  414. if( !bStatus )
  415. {
  416. SetLastError( Status );
  417. }
  418. }
  419. }
  420. return bStatus;
  421. }
  422. VOID
  423. TPrinterDriverInstallation::
  424. vPrinterAdded(
  425. IN const TString &strFullPrinterName
  426. )
  427. {
  428. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::vPrinterAdded\n" ) );
  429. DBGMSG( DBG_TRACE, ( "strFullPrinterName " TSTR "\n", static_cast<LPCTSTR>( strFullPrinterName ) ) );
  430. TStatusB bStatus;
  431. bStatus DBGCHK = bIsDriverSelected( );
  432. if( bStatus )
  433. {
  434. _PSetup.PSetupProcessPrinterAdded( _hSetupDrvSetupParams,
  435. _hSelectedDrvInfo,
  436. strFullPrinterName,
  437. _hwnd );
  438. }
  439. }
  440. BOOL
  441. TPrinterDriverInstallation::
  442. bGetDriverSetupPage(
  443. IN OUT HPROPSHEETPAGE *pPage,
  444. IN LPCTSTR pszTitle,
  445. IN LPCTSTR pszSubTitle,
  446. IN LPCTSTR pszInstrn
  447. )
  448. {
  449. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bGetDriverSetupPage\n" ) );
  450. SPLASSERT( bValid() );
  451. //
  452. // Set the title and instructions if provided. Note that this function may fail
  453. //
  454. TStatusB bStatus;
  455. bStatus DBGCHK = bSetDriverSetupPageTitle(pszTitle, pszSubTitle, pszInstrn);
  456. if( bStatus )
  457. {
  458. //
  459. // Get the select device page handle.
  460. //
  461. *pPage = _PSetup.PSetupCreateDrvSetupPage(_hSetupDrvSetupParams, _hwnd);
  462. bStatus DBGCHK = ((*pPage) ? TRUE : FALSE);
  463. }
  464. return bStatus;
  465. }
  466. BOOL
  467. TPrinterDriverInstallation::
  468. bSetWebMode(
  469. IN BOOL bWebButtonOn
  470. )
  471. {
  472. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bSetWebMode\n" ) );
  473. SPLASSERT( bValid() );
  474. //
  475. // Set the web button state i.e. enabled|disbled, on the model manufacture dialog.
  476. //
  477. return _PSetup.PSetupSetWebMode( _hSetupDrvSetupParams, bWebButtonOn );
  478. }
  479. BOOL
  480. TPrinterDriverInstallation::
  481. bShowOem(
  482. IN BOOL bShowOem
  483. )
  484. {
  485. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bShowOem\n" ) );
  486. SPLASSERT( bValid() );
  487. //
  488. // Enable or Disable the have disk button.
  489. //
  490. return _PSetup.PSetupShowOem( _hSetupDrvSetupParams, bShowOem );
  491. }
  492. BOOL
  493. TPrinterDriverInstallation::
  494. bSetDriverSetupPageTitle(
  495. IN LPCTSTR pszTitle,
  496. IN LPCTSTR pszSubTitle,
  497. IN LPCTSTR pszInstrn
  498. )
  499. {
  500. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bSetDriverSetupPageTitle\n" ) );
  501. SPLASSERT( bValid() );
  502. BOOL bReturn = FALSE;
  503. //
  504. // Set the title and instructions if provided.
  505. //
  506. if( ( pszTitle && *pszTitle ) || ( pszInstrn && *pszInstrn ) || ( pszSubTitle && *pszSubTitle ) )
  507. {
  508. bReturn = _PSetup.PSetupSetSelectDevTitleAndInstructions( _hSetupDrvSetupParams, pszTitle, pszSubTitle, pszInstrn );
  509. }
  510. return bReturn;
  511. }
  512. BOOL
  513. TPrinterDriverInstallation::
  514. bGetSelectedDriver(
  515. const BOOL bForceReselection
  516. )
  517. {
  518. SPLASSERT( bValid() );
  519. TStatusB bStatus;
  520. BOOL bSelectFromName = FALSE;
  521. if( bForceReselection )
  522. {
  523. //
  524. // Release the selected driver
  525. //
  526. vReleaseSelectedDriver();
  527. //
  528. // Set the reselect flag.
  529. //
  530. bSelectFromName = _strDriverName.bEmpty() ? FALSE : TRUE;
  531. }
  532. //
  533. // Select the driver.
  534. //
  535. bStatus DBGCHK = bSelectDriver( bSelectFromName );
  536. bStatus DBGCHK = bIsDriverSelected( );
  537. if( bStatus )
  538. {
  539. if( !bSelectFromName )
  540. {
  541. //
  542. // Update the selected driver name.
  543. //
  544. bStatus DBGCHK = _PSetup.bGetSelectedDriverName( _hSelectedDrvInfo,
  545. _strDriverName,
  546. GetDriverPlatform( _dwDriverVersion ) );
  547. }
  548. }
  549. return bStatus;
  550. }
  551. BOOL
  552. TPrinterDriverInstallation::
  553. bSelectDriverFromInf(
  554. IN LPCTSTR pszInfName,
  555. IN BOOL bIsSingleInf
  556. )
  557. {
  558. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bInstallDriverFromInf\n" ) );
  559. SPLASSERT( bValid() );
  560. TStatusB bStatus;
  561. bStatus DBGNOCHK = TRUE;
  562. if( bStatus )
  563. {
  564. bStatus DBGCHK = _PSetup.PSetupBuildDriversFromPath( _hSetupDrvSetupParams, pszInfName, bIsSingleInf );
  565. }
  566. if( bStatus )
  567. {
  568. bStatus DBGCHK = _PSetup.PSetupPreSelectDriver( _hSetupDrvSetupParams, NULL, _strDriverName );
  569. }
  570. return bStatus;
  571. }
  572. //
  573. // Return:
  574. // TRUE CodeDownload is available, FALSE CodeDownload not available.
  575. //
  576. BOOL
  577. TPrinterDriverInstallation::
  578. bIsCodeDownLoadAvailable(
  579. VOID
  580. )
  581. {
  582. TLibrary Lib( gszCodeDownLoadDllName );
  583. if( VALID_OBJ( Lib ) )
  584. {
  585. pfDownloadIsInternetAvailable pDownloadAvailable = NULL;
  586. pDownloadAvailable = reinterpret_cast<pfDownloadIsInternetAvailable>( Lib.pfnGetProc( "DownloadIsInternetAvailable" ) );
  587. if( pDownloadAvailable )
  588. {
  589. return pDownloadAvailable();
  590. }
  591. }
  592. return FALSE;
  593. }
  594. //
  595. // Return the selected print processor name.
  596. //
  597. BOOL
  598. TPrinterDriverInstallation::
  599. bGetPrintProcessor(
  600. IN TString &strPrintProcessor
  601. ) const
  602. {
  603. TStatusB bStatus;
  604. bStatus DBGCHK = bIsDriverSelected( );
  605. if( bStatus )
  606. {
  607. bStatus DBGCHK = _PSetup.bGetSelectedPrintProcessorName( _hSelectedDrvInfo, strPrintProcessor, GetDriverPlatform( _dwDriverVersion ) );
  608. }
  609. return bStatus;
  610. }
  611. //
  612. // Return the selected inf file name.
  613. //
  614. BOOL
  615. TPrinterDriverInstallation::
  616. bGetSelectedInfName(
  617. IN TString &strInfName
  618. ) const
  619. {
  620. TStatusB bStatus;
  621. bStatus DBGCHK = bIsDriverSelected( );
  622. if( bStatus )
  623. {
  624. bStatus DBGCHK = _PSetup.bGetSelectedInfName( _hSelectedDrvInfo, strInfName, GetDriverPlatform( _dwDriverVersion ) );
  625. }
  626. return bStatus;
  627. }
  628. //
  629. // Return if the currently selected driver is an oem driver.
  630. //
  631. BOOL
  632. TPrinterDriverInstallation::
  633. bIsOemDriver(
  634. VOID
  635. ) const
  636. {
  637. TStatusB bStatus;
  638. bStatus DBGCHK = bIsDriverSelected( );
  639. BOOL bIsOemDriver = FALSE;
  640. if( bStatus )
  641. {
  642. (VOID)_PSetup.PSetupIsOemDriver( _hSetupDrvSetupParams, _hSelectedDrvInfo, &bIsOemDriver );
  643. }
  644. return (bStatus && bIsOemDriver);
  645. }
  646. //
  647. // Return the current driver encoding. This is useful because
  648. // getting the current driver encode is very expensive accross
  649. // a remote connetion, and this class only fetches the
  650. // version once per instantiation.
  651. //
  652. BOOL
  653. TPrinterDriverInstallation::
  654. bGetCurrentDriverEncode(
  655. IN DWORD *pdwEncode
  656. ) const
  657. {
  658. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bGetCurrentDriverEncode\n" ) );
  659. SPLASSERT( bValid() );
  660. //
  661. // The driver version should be initialized at this point.
  662. //
  663. SPLASSERT( _dwDriverVersion != (DWORD)kDefault );
  664. *pdwEncode = _dwDriverVersion;
  665. return TRUE;
  666. }
  667. //
  668. // Return the current driver version. This is useful because
  669. // getting the current driver encode is very expensive accross
  670. // a remote connetion. This class only fetches the
  671. // version once per instantiation.
  672. //
  673. DWORD
  674. TPrinterDriverInstallation::
  675. dwGetCurrentDriverVersion(
  676. ) const
  677. {
  678. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bGetCurrentDriverVersion\n" ) );
  679. SPLASSERT( bValid() );
  680. //
  681. // The driver version should be initialized at this point.
  682. //
  683. SPLASSERT( _dwDriverVersion != (DWORD)kDefault );
  684. return GetDriverVersion( _dwDriverVersion );
  685. }
  686. //
  687. // Restores the driver list to the default driver list.
  688. //
  689. BOOL
  690. TPrinterDriverInstallation::
  691. bRefreshDriverList(
  692. VOID
  693. )
  694. {
  695. return _PSetup.PSetupRefreshDriverList( _hSetupDrvSetupParams );
  696. }
  697. //
  698. // Expose the original hwnd, user of the class need this
  699. // to ensure they are using the same hwnd when displaying messages.
  700. //
  701. HWND
  702. TPrinterDriverInstallation::
  703. hGetHwnd(
  704. VOID
  705. ) const
  706. {
  707. return _hwnd;
  708. }
  709. /********************************************************************
  710. Private member functions.
  711. ********************************************************************/
  712. BOOL
  713. TPrinterDriverInstallation::
  714. bValidateSourcePath(
  715. IN LPCTSTR pszSourcePath
  716. ) const
  717. {
  718. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bValidateSourcePath\n" ) );
  719. SPLASSERT( bValid() );
  720. TStatusB bStatus;
  721. if( GetFileAttributes( pszSourcePath ) & FILE_ATTRIBUTE_DIRECTORY )
  722. {
  723. bStatus DBGNOCHK = TRUE;
  724. }
  725. else
  726. {
  727. SetLastError( ERROR_DIRECTORY );
  728. bStatus DBGNOCHK = FALSE;
  729. }
  730. return bStatus;
  731. }
  732. BOOL
  733. TPrinterDriverInstallation::
  734. bIsDriverSelected(
  735. VOID
  736. ) const
  737. {
  738. SPLASSERT( bValid() );
  739. return _hSelectedDrvInfo != INVALID_HANDLE_VALUE;
  740. }
  741. BOOL
  742. TPrinterDriverInstallation::
  743. bSelectDriver(
  744. IN BOOL bFromName
  745. )
  746. {
  747. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bGetSelectedDriverInfo\n" ) );
  748. SPLASSERT( bValid() );
  749. vReleaseSelectedDriver();
  750. if( bFromName )
  751. {
  752. _hSelectedDrvInfo = _PSetup.PSetupDriverInfoFromName( _hSetupDrvSetupParams, _strDriverName );
  753. }
  754. else
  755. {
  756. _hSelectedDrvInfo = _PSetup.PSetupGetSelectedDriverInfo( _hSetupDrvSetupParams );
  757. }
  758. BOOL bRetval;
  759. TStatusB bStatus;
  760. bStatus DBGCHK = bIsDriverSelected( );
  761. if( !bStatus )
  762. {
  763. DBGMSG( DBG_TRACE, ( "PSetupGetSelectedDriverInfo failed with %d\n", GetLastError() ) );
  764. bRetval = FALSE;
  765. }
  766. else
  767. {
  768. bRetval = TRUE;
  769. }
  770. return bRetval;
  771. }
  772. VOID
  773. TPrinterDriverInstallation::
  774. vReleaseSelectedDriver(
  775. VOID
  776. )
  777. {
  778. //
  779. // Release the selected driver information.
  780. //
  781. if( _hSelectedDrvInfo != INVALID_HANDLE_VALUE )
  782. {
  783. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::vReleaseSelectedDriverInfo\n" ) );
  784. _PSetup.PSetupDestroySelectedDriverInfo( _hSelectedDrvInfo );
  785. _hSelectedDrvInfo = INVALID_HANDLE_VALUE;
  786. }
  787. }
  788. //
  789. // Return the os version info structure.
  790. //
  791. OSVERSIONINFO *
  792. TPrinterDriverInstallation::
  793. pGetOsVersionInfo(
  794. VOID
  795. )
  796. {
  797. //
  798. // If the os version was not iniaitlized.
  799. //
  800. if( !_OsVersionInfo.dwOSVersionInfoSize )
  801. {
  802. //
  803. // Set the osversion info structure size.
  804. //
  805. _OsVersionInfo.dwOSVersionInfoSize = sizeof( _OsVersionInfo );
  806. //
  807. // Get the osversion info structure size
  808. //
  809. if( !SpoolerGetVersionEx( _pszServerName, &_OsVersionInfo ) )
  810. {
  811. //
  812. // Indicate a failure occured.
  813. //
  814. _OsVersionInfo.dwOSVersionInfoSize = 0;
  815. }
  816. }
  817. if( _OsVersionInfo.dwOSVersionInfoSize )
  818. {
  819. DBGMSG( DBG_TRACE, ("_OsVersionInfo.dwOSVersionInfoSize %d\n", _OsVersionInfo.dwOSVersionInfoSize ) );
  820. DBGMSG( DBG_TRACE, ("_OsVersionInfo.dwMajorVersion %d\n", _OsVersionInfo.dwMajorVersion ) );
  821. DBGMSG( DBG_TRACE, ("_OsVersionInfo.dwMinorVersion %d\n", _OsVersionInfo.dwMinorVersion ) );
  822. DBGMSG( DBG_TRACE, ("_OsVersionInfo.dwBuildNumber %d\n", _OsVersionInfo.dwBuildNumber ) );
  823. DBGMSG( DBG_TRACE, ("_OsVersionInfo.dwPlatformId %d\n", _OsVersionInfo.dwPlatformId ) );
  824. DBGMSG( DBG_TRACE, ("_OsVersionInfo.szCSDVersion "TSTR"\n", _OsVersionInfo.szCSDVersion ) );
  825. }
  826. return &_OsVersionInfo;
  827. }