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.

938 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 the current driver encoding. This is useful because
  630. // getting the current driver encode is very expensive accross
  631. // a remote connetion, and this class only fetches the
  632. // version once per instantiation.
  633. //
  634. BOOL
  635. TPrinterDriverInstallation::
  636. bGetCurrentDriverEncode(
  637. IN DWORD *pdwEncode
  638. ) const
  639. {
  640. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bGetCurrentDriverEncode\n" ) );
  641. SPLASSERT( bValid() );
  642. //
  643. // The driver version should be initialized at this point.
  644. //
  645. SPLASSERT( _dwDriverVersion != (DWORD)kDefault );
  646. *pdwEncode = _dwDriverVersion;
  647. return TRUE;
  648. }
  649. //
  650. // Return the current driver version. This is useful because
  651. // getting the current driver encode is very expensive accross
  652. // a remote connetion. This class only fetches the
  653. // version once per instantiation.
  654. //
  655. DWORD
  656. TPrinterDriverInstallation::
  657. dwGetCurrentDriverVersion(
  658. ) const
  659. {
  660. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bGetCurrentDriverVersion\n" ) );
  661. SPLASSERT( bValid() );
  662. //
  663. // The driver version should be initialized at this point.
  664. //
  665. SPLASSERT( _dwDriverVersion != (DWORD)kDefault );
  666. return GetDriverVersion( _dwDriverVersion );
  667. }
  668. //
  669. // Expose the original hwnd, user of the class need this
  670. // to ensure they are using the same hwnd when displaying messages.
  671. //
  672. HWND
  673. TPrinterDriverInstallation::
  674. hGetHwnd(
  675. VOID
  676. ) const
  677. {
  678. return _hwnd;
  679. }
  680. /********************************************************************
  681. Private member functions.
  682. ********************************************************************/
  683. BOOL
  684. TPrinterDriverInstallation::
  685. bValidateSourcePath(
  686. IN LPCTSTR pszSourcePath
  687. ) const
  688. {
  689. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bValidateSourcePath\n" ) );
  690. SPLASSERT( bValid() );
  691. TStatusB bStatus;
  692. if( GetFileAttributes( pszSourcePath ) & FILE_ATTRIBUTE_DIRECTORY )
  693. {
  694. bStatus DBGNOCHK = TRUE;
  695. }
  696. else
  697. {
  698. SetLastError( ERROR_DIRECTORY );
  699. bStatus DBGNOCHK = FALSE;
  700. }
  701. return bStatus;
  702. }
  703. BOOL
  704. TPrinterDriverInstallation::
  705. bIsDriverSelected(
  706. VOID
  707. ) const
  708. {
  709. SPLASSERT( bValid() );
  710. return _hSelectedDrvInfo != INVALID_HANDLE_VALUE;
  711. }
  712. BOOL
  713. TPrinterDriverInstallation::
  714. bSelectDriver(
  715. IN BOOL bFromName
  716. )
  717. {
  718. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::bGetSelectedDriverInfo\n" ) );
  719. SPLASSERT( bValid() );
  720. vReleaseSelectedDriver();
  721. if( bFromName )
  722. {
  723. _hSelectedDrvInfo = _PSetup.PSetupDriverInfoFromName( _hSetupDrvSetupParams, _strDriverName );
  724. }
  725. else
  726. {
  727. _hSelectedDrvInfo = _PSetup.PSetupGetSelectedDriverInfo( _hSetupDrvSetupParams );
  728. }
  729. BOOL bRetval;
  730. TStatusB bStatus;
  731. bStatus DBGCHK = bIsDriverSelected( );
  732. if( !bStatus )
  733. {
  734. DBGMSG( DBG_TRACE, ( "PSetupGetSelectedDriverInfo failed with %d\n", GetLastError() ) );
  735. bRetval = FALSE;
  736. }
  737. else
  738. {
  739. bRetval = TRUE;
  740. }
  741. return bRetval;
  742. }
  743. VOID
  744. TPrinterDriverInstallation::
  745. vReleaseSelectedDriver(
  746. VOID
  747. )
  748. {
  749. //
  750. // Release the selected driver information.
  751. //
  752. if( _hSelectedDrvInfo != INVALID_HANDLE_VALUE )
  753. {
  754. DBGMSG( DBG_TRACE, ( "TPrinterDriverInstallation::vReleaseSelectedDriverInfo\n" ) );
  755. _PSetup.PSetupDestroySelectedDriverInfo( _hSelectedDrvInfo );
  756. _hSelectedDrvInfo = INVALID_HANDLE_VALUE;
  757. }
  758. }
  759. //
  760. // Return the os version info structure.
  761. //
  762. OSVERSIONINFO *
  763. TPrinterDriverInstallation::
  764. pGetOsVersionInfo(
  765. VOID
  766. )
  767. {
  768. //
  769. // If the os version was not iniaitlized.
  770. //
  771. if( !_OsVersionInfo.dwOSVersionInfoSize )
  772. {
  773. //
  774. // Set the osversion info structure size.
  775. //
  776. _OsVersionInfo.dwOSVersionInfoSize = sizeof( _OsVersionInfo );
  777. //
  778. // Get the osversion info structure size
  779. //
  780. if( !SpoolerGetVersionEx( _pszServerName, &_OsVersionInfo ) )
  781. {
  782. //
  783. // Indicate a failure occured.
  784. //
  785. _OsVersionInfo.dwOSVersionInfoSize = 0;
  786. }
  787. }
  788. if( _OsVersionInfo.dwOSVersionInfoSize )
  789. {
  790. DBGMSG( DBG_TRACE, ("_OsVersionInfo.dwOSVersionInfoSize %d\n", _OsVersionInfo.dwOSVersionInfoSize ) );
  791. DBGMSG( DBG_TRACE, ("_OsVersionInfo.dwMajorVersion %d\n", _OsVersionInfo.dwMajorVersion ) );
  792. DBGMSG( DBG_TRACE, ("_OsVersionInfo.dwMinorVersion %d\n", _OsVersionInfo.dwMinorVersion ) );
  793. DBGMSG( DBG_TRACE, ("_OsVersionInfo.dwBuildNumber %d\n", _OsVersionInfo.dwBuildNumber ) );
  794. DBGMSG( DBG_TRACE, ("_OsVersionInfo.dwPlatformId %d\n", _OsVersionInfo.dwPlatformId ) );
  795. DBGMSG( DBG_TRACE, ("_OsVersionInfo.szCSDVersion "TSTR"\n", _OsVersionInfo.szCSDVersion ) );
  796. }
  797. return &_OsVersionInfo;
  798. }