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.

371 lines
9.2 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1996 - 1999
  3. All rights reserved.
  4. Module Name:
  5. Instarch.cxx
  6. Abstract:
  7. Installs alternate drivers for other architectures.
  8. Author:
  9. Steve Kiraly (SteveKi) 18-Jan-1996
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "psetup.hxx"
  15. #include "drvsetup.hxx"
  16. #include "drvver.hxx"
  17. #include "instarch.hxx"
  18. /********************************************************************
  19. Additional Drivers Dialog.
  20. ********************************************************************/
  21. TAdditionalDrivers::
  22. TAdditionalDrivers(
  23. IN HWND hwnd,
  24. IN LPCTSTR pszServerName,
  25. IN LPCTSTR pszPrinterName,
  26. IN LPCTSTR pszDriverName,
  27. IN BOOL bAdministrator
  28. ) : _hwnd( hwnd ),
  29. _bValid( FALSE ),
  30. _strServerName( pszServerName ),
  31. _strPrinterName( pszPrinterName ),
  32. _strDriverName( pszDriverName ),
  33. _bAdministrator( bAdministrator )
  34. {
  35. if( VALID_OBJ( _strServerName ) &&
  36. VALID_OBJ( _strPrinterName ) &&
  37. VALID_OBJ( _strDriverName ) &&
  38. VALID_OBJ( _ArchLV ) )
  39. {
  40. _bValid = TRUE;
  41. }
  42. }
  43. TAdditionalDrivers::
  44. ~TAdditionalDrivers(
  45. VOID
  46. )
  47. {
  48. }
  49. BOOL
  50. TAdditionalDrivers::
  51. bValid(
  52. VOID
  53. )
  54. {
  55. return _bValid;
  56. }
  57. BOOL
  58. TAdditionalDrivers::
  59. bDoModal(
  60. VOID
  61. )
  62. {
  63. return (BOOL)DialogBoxParam( ghInst,
  64. MAKEINTRESOURCE( DLG_ADDITIONAL_DRIVERS ),
  65. _hwnd,
  66. MGenericDialog::SetupDlgProc,
  67. (LPARAM)this );
  68. }
  69. BOOL
  70. TAdditionalDrivers::
  71. bSetUI(
  72. VOID
  73. )
  74. {
  75. TStatusB bStatus;
  76. //
  77. // Set the architecture list view UI.
  78. //
  79. bStatus DBGCHK = _ArchLV.bSetUI( _hDlg, kSingleClick, kDoubleClick );
  80. //
  81. // Refresh the architecture list.
  82. //
  83. bStatus DBGCHK = _ArchLV.bRefreshListView( _strServerName.bEmpty() ? NULL : static_cast<LPCTSTR>(_strServerName), _strDriverName );
  84. //
  85. // Select the first item in the list view.
  86. //
  87. _ArchLV.vSelectItem( 0 );
  88. //
  89. // If we are not an administrator do not allow the user to
  90. // check a driver to install.
  91. //
  92. if( !_bAdministrator )
  93. {
  94. _ArchLV.vNoItemCheck();
  95. }
  96. //
  97. // Disable the ok button if we are not an administator.
  98. //
  99. if( !_bAdministrator )
  100. {
  101. vEnableCtl( _hDlg, IDOK, FALSE );
  102. }
  103. //
  104. // The install button is initialy disabled.
  105. //
  106. EnableWindow( GetDlgItem( _hDlg, IDOK ), FALSE );
  107. return bStatus;
  108. }
  109. BOOL
  110. TAdditionalDrivers::
  111. bInstallSelectedDrivers(
  112. VOID
  113. )
  114. {
  115. TStatusB bStatus;
  116. bStatus DBGNOCHK = TRUE;
  117. if( _bAdministrator )
  118. {
  119. //
  120. // Initialize the driver install count.
  121. //
  122. UINT nInstallCount = 0;
  123. //
  124. // Create the printer driver installation class.
  125. //
  126. TPrinterDriverInstallation Di( _strServerName.bEmpty() ? NULL : static_cast<LPCTSTR>(_strServerName), _hDlg );
  127. if( VALID_OBJ( Di ) && Di.bSetDriverName( _strDriverName ) )
  128. {
  129. //
  130. // Do not copy any INFs during this installation process
  131. //
  132. Di.SetInstallFlags( DRVINST_DONOTCOPY_INF );
  133. //
  134. // Get the selected item count.
  135. //
  136. UINT cSelectedCount = _ArchLV.uGetCheckedItemCount();
  137. //
  138. // Install the selected drivers.
  139. //
  140. for( UINT i = 0; i < cSelectedCount; i++ )
  141. {
  142. BOOL bInstalled;
  143. DWORD dwEncode;
  144. //
  145. // Get the checked items.
  146. //
  147. bStatus DBGCHK = _ArchLV.bGetCheckedItems( i, &bInstalled, &dwEncode );
  148. if( bStatus && !bInstalled )
  149. {
  150. //
  151. // Turn on the wait cursor.
  152. //
  153. TWaitCursor *pCur = new TWaitCursor;
  154. //
  155. // Install the printer driver.
  156. //
  157. BOOL bOfferReplacementDriver = FALSE;
  158. bStatus DBGCHK = Di.bInstallDriver( NULL,
  159. bOfferReplacementDriver,
  160. FALSE,
  161. _hDlg,
  162. dwEncode,
  163. TPrinterDriverInstallation::kDefault,
  164. TPrinterDriverInstallation::kDefault,
  165. TRUE);
  166. //
  167. // Release the wait cursor.
  168. //
  169. delete pCur;
  170. if( bStatus )
  171. {
  172. nInstallCount++;
  173. }
  174. else
  175. {
  176. switch( GetLastError() )
  177. {
  178. case ERROR_CANCELLED:
  179. break;
  180. case ERROR_UNKNOWN_PRINTER_DRIVER:
  181. {
  182. iMessage( _hDlg,
  183. IDS_ERR_ADD_PRINTER_TITLE,
  184. IDS_ERROR_UNKNOWN_DRIVER,
  185. MB_OK | MB_ICONSTOP,
  186. kMsgNone,
  187. NULL );
  188. }
  189. break;
  190. default:
  191. {
  192. TString strArch;
  193. TString strVersion;
  194. (VOID)_ArchLV.bEncodeToArchAndVersion( dwEncode, strArch, strVersion );
  195. //
  196. // An error occurred installing a printer driver.
  197. //
  198. iMessage( _hDlg,
  199. IDS_ADDITIONAL_DRIVER_TITLE,
  200. IDS_ERR_ALL_DRIVER_NOT_INSTALLED,
  201. MB_OK|MB_ICONHAND,
  202. kMsgGetLastError,
  203. NULL,
  204. static_cast<LPCTSTR>( _strDriverName ),
  205. static_cast<LPCTSTR>( strArch ),
  206. static_cast<LPCTSTR>( strVersion ) );
  207. }
  208. break;
  209. }
  210. }
  211. }
  212. }
  213. }
  214. //
  215. // If something failed and more than one driver was installed
  216. // refresh the view to show the newly installed drivers.
  217. //
  218. if( !bStatus && nInstallCount )
  219. {
  220. //
  221. // Refresh the architecture list.
  222. //
  223. (VOID)_ArchLV.bRefreshListView( _strServerName.bEmpty() ? NULL : static_cast<LPCTSTR>(_strServerName), _strDriverName );
  224. }
  225. }
  226. return bStatus;
  227. }
  228. BOOL
  229. TAdditionalDrivers::
  230. IsNonInstalledItemSelected(
  231. VOID
  232. )
  233. {
  234. BOOL bInstalled = FALSE;
  235. DWORD dwEncode = 0;
  236. //
  237. // Get the selected item count.
  238. //
  239. UINT cSelectedCount = _ArchLV.uGetCheckedItemCount();
  240. //
  241. // Traverse the selected item list.
  242. //
  243. for( UINT i = 0; i < cSelectedCount; i++ )
  244. {
  245. //
  246. // Get the checked items.
  247. //
  248. if( _ArchLV.bGetCheckedItems( i, &bInstalled, &dwEncode ) )
  249. {
  250. if( !bInstalled )
  251. {
  252. break;
  253. }
  254. }
  255. }
  256. return !bInstalled;
  257. }
  258. BOOL
  259. TAdditionalDrivers::
  260. bHandleMessage(
  261. IN UINT uMsg,
  262. IN WPARAM wParam,
  263. IN LPARAM lParam
  264. )
  265. {
  266. BOOL bStatus = TRUE;
  267. switch (uMsg)
  268. {
  269. case WM_INITDIALOG:
  270. bSetUI();
  271. break;
  272. //
  273. // Handle help and context help.
  274. //
  275. case WM_HELP:
  276. case WM_CONTEXTMENU:
  277. bStatus = PrintUIHelp( uMsg, _hDlg, wParam, lParam );
  278. break;
  279. case WM_COMMAND:
  280. switch ( LOWORD( wParam ) )
  281. {
  282. case IDOK:
  283. if( bInstallSelectedDrivers() )
  284. {
  285. EndDialog( _hDlg, LOWORD( wParam ) );
  286. }
  287. break;
  288. case IDCANCEL:
  289. EndDialog( _hDlg, LOWORD( wParam ) );
  290. break;
  291. case kSingleClick:
  292. EnableWindow( GetDlgItem( _hDlg, IDOK ), IsNonInstalledItemSelected() );
  293. break;
  294. case kDoubleClick:
  295. EnableWindow( GetDlgItem( _hDlg, IDOK ), IsNonInstalledItemSelected() );
  296. break;
  297. default:
  298. bStatus = FALSE;
  299. break;
  300. }
  301. break;
  302. //
  303. // Handle notify for this dialog.
  304. //
  305. case WM_NOTIFY:
  306. _ArchLV.bHandleNotifyMessage( WM_NOTIFY, wParam, lParam );
  307. break;
  308. default:
  309. bStatus = FALSE;
  310. break;
  311. }
  312. return bStatus;
  313. }