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.

392 lines
11 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. case ERROR_INSTALL_PLATFORM_UNSUPPORTED:
  191. {
  192. UINT nMsgID = 0;
  193. switch ( dwEncode )
  194. {
  195. case DRIVER_IA64_3 : nMsgID = IDS_REF_DIFF_PLATFORM_DRIVER_IA64_XP_NET; break;
  196. case DRIVER_WIN95 : nMsgID = IDS_REF_DIFF_PLATFORM_DRIVER_X86_95_98_ME; break;
  197. case DRIVER_X86_2 : nMsgID = IDS_REF_DIFF_PLATFORM_DRIVER_X86_NT4; break;
  198. case DRIVER_X86_3 : nMsgID = IDS_REF_DIFF_PLATFORM_DRIVER_X86_W2K_XP_NET; break;
  199. }
  200. iMessage( _hDlg,
  201. IDS_DRIVER_WIZ_TITLE,
  202. nMsgID,
  203. MB_OK|MB_ICONHAND,
  204. kMsgNone,
  205. NULL );
  206. }
  207. break;
  208. default:
  209. {
  210. TString strArch;
  211. TString strVersion;
  212. (VOID)_ArchLV.bEncodeToArchAndVersion( dwEncode, strArch, strVersion );
  213. //
  214. // An error occurred installing a printer driver.
  215. //
  216. iMessage( _hDlg,
  217. IDS_ADDITIONAL_DRIVER_TITLE,
  218. IDS_ERR_ALL_DRIVER_NOT_INSTALLED,
  219. MB_OK|MB_ICONHAND,
  220. kMsgGetLastError,
  221. NULL,
  222. static_cast<LPCTSTR>( _strDriverName ),
  223. static_cast<LPCTSTR>( strArch ),
  224. static_cast<LPCTSTR>( strVersion ) );
  225. }
  226. break;
  227. }
  228. }
  229. }
  230. }
  231. }
  232. //
  233. // If something failed and more than one driver was installed
  234. // refresh the view to show the newly installed drivers.
  235. //
  236. if( !bStatus && nInstallCount )
  237. {
  238. //
  239. // Refresh the architecture list.
  240. //
  241. (VOID)_ArchLV.bRefreshListView( _strServerName.bEmpty() ? NULL : static_cast<LPCTSTR>(_strServerName), _strDriverName );
  242. }
  243. }
  244. return bStatus;
  245. }
  246. BOOL
  247. TAdditionalDrivers::
  248. IsNonInstalledItemSelected(
  249. VOID
  250. )
  251. {
  252. BOOL bInstalled = FALSE;
  253. DWORD dwEncode = 0;
  254. //
  255. // Get the selected item count.
  256. //
  257. UINT cSelectedCount = _ArchLV.uGetCheckedItemCount();
  258. //
  259. // Traverse the selected item list.
  260. //
  261. for( UINT i = 0; i < cSelectedCount; i++ )
  262. {
  263. //
  264. // Get the checked items.
  265. //
  266. if( _ArchLV.bGetCheckedItems( i, &bInstalled, &dwEncode ) )
  267. {
  268. if( !bInstalled )
  269. {
  270. break;
  271. }
  272. }
  273. }
  274. return !bInstalled;
  275. }
  276. BOOL
  277. TAdditionalDrivers::
  278. bHandleMessage(
  279. IN UINT uMsg,
  280. IN WPARAM wParam,
  281. IN LPARAM lParam
  282. )
  283. {
  284. BOOL bStatus = TRUE;
  285. switch (uMsg)
  286. {
  287. case WM_INITDIALOG:
  288. bSetUI();
  289. break;
  290. //
  291. // Handle help and context help.
  292. //
  293. case WM_HELP:
  294. case WM_CONTEXTMENU:
  295. bStatus = PrintUIHelp( uMsg, _hDlg, wParam, lParam );
  296. break;
  297. case WM_COMMAND:
  298. switch ( LOWORD( wParam ) )
  299. {
  300. case IDOK:
  301. if( bInstallSelectedDrivers() )
  302. {
  303. EndDialog( _hDlg, LOWORD( wParam ) );
  304. }
  305. break;
  306. case IDCANCEL:
  307. EndDialog( _hDlg, LOWORD( wParam ) );
  308. break;
  309. case kSingleClick:
  310. EnableWindow( GetDlgItem( _hDlg, IDOK ), IsNonInstalledItemSelected() );
  311. break;
  312. case kDoubleClick:
  313. EnableWindow( GetDlgItem( _hDlg, IDOK ), IsNonInstalledItemSelected() );
  314. break;
  315. default:
  316. bStatus = FALSE;
  317. break;
  318. }
  319. break;
  320. //
  321. // Handle notify for this dialog.
  322. //
  323. case WM_NOTIFY:
  324. _ArchLV.bHandleNotifyMessage( WM_NOTIFY, wParam, lParam );
  325. break;
  326. default:
  327. bStatus = FALSE;
  328. break;
  329. }
  330. return bStatus;
  331. }