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.

677 lines
18 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // File Name:
  7. // hal.c
  8. //
  9. // Description:
  10. // This file contains the dialog procedure for the hal files.
  11. // (IDD_HAL).
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "pch.h"
  15. #include "resource.h"
  16. #define HAL_FILE_EXTENSION _T("oem")
  17. static TCHAR* StrHalFiles;
  18. static TCHAR* StrAllFiles;
  19. static TCHAR g_szHalFileFilter[MAX_PATH + 1];
  20. //
  21. // This var keeps track of the path to the txtsetup.oem
  22. //
  23. static TCHAR szTxtSetupOemLocation[MAX_PATH];
  24. static BOOL bHasLoadedTxtSetupOem = FALSE;
  25. VOID LoadOriginalSettingsLowHalScsi(HWND hwnd,
  26. LPTSTR lpFileName,
  27. QUEUENUM dwWhichQueue);
  28. static VOID
  29. LoadHalFromTxtsetupOem( IN HWND hwnd,
  30. IN TCHAR *szTxtSetupOemPath );
  31. //----------------------------------------------------------------------------
  32. //
  33. // Function: OnHalInitDialog
  34. //
  35. // Purpose:
  36. //
  37. // Arguments: IN HWND hwnd - handle to the dialog box
  38. //
  39. // Returns: VOID
  40. //
  41. //----------------------------------------------------------------------------
  42. static VOID
  43. OnHalInitDialog( IN HWND hwnd )
  44. {
  45. HRESULT hrPrintf;
  46. //
  47. // Load the resource strings
  48. //
  49. StrHalFiles = MyLoadString( IDS_HAL_FILES );
  50. StrAllFiles = MyLoadString( IDS_ALL_FILES );
  51. //
  52. // Build the text file filter string
  53. //
  54. //
  55. // The question marks (?) are just placehoders for where the NULL char
  56. // will be inserted.
  57. //
  58. hrPrintf=StringCchPrintf( g_szHalFileFilter, AS(g_szHalFileFilter),
  59. _T("%s (*.oem)?*.oem?%s (*.*)?*.*?"),
  60. StrHalFiles,
  61. StrAllFiles );
  62. ConvertQuestionsToNull( g_szHalFileFilter );
  63. }
  64. //----------------------------------------------------------------------------
  65. //
  66. // Function: OnHalSetActive
  67. //
  68. // Purpose:
  69. //
  70. // Arguments: IN HWND hwnd - handle to the dialog box
  71. //
  72. // Returns: VOID
  73. //
  74. //----------------------------------------------------------------------------
  75. static VOID
  76. OnHalSetActive( IN HWND hwnd )
  77. {
  78. INT_PTR i;
  79. INT_PTR iListBoxCount;
  80. TCHAR szListBoxEntryText[MAX_STRING_LEN];
  81. //
  82. // If we are editing a script and haven't loaded the txtsetup.oem, then
  83. // populate the list box with the entries in the txtsetup.oem
  84. //
  85. if( ! WizGlobals.bNewScript && ! bHasLoadedTxtSetupOem ) {
  86. //
  87. // The OEM files path must be valid if we are going to use it to
  88. // read files.
  89. //
  90. AssertMsg( WizGlobals.OemFilesPath[0] != _T('\0'),
  91. "OEM files path is blank");
  92. //
  93. // Populate the list box with the HAL entries in txtsetup.oem
  94. //
  95. ConcatenatePaths( szTxtSetupOemLocation,
  96. WizGlobals.OemFilesPath,
  97. _T("Textmode"),
  98. NULL );
  99. LoadHalFromTxtsetupOem( hwnd, szTxtSetupOemLocation );
  100. //
  101. // Select the HAL
  102. //
  103. iListBoxCount = SendDlgItemMessage( hwnd,
  104. IDC_LB_HAL,
  105. LB_GETCOUNT,
  106. 0,
  107. 0 );
  108. //
  109. // Search the list box for the HAL to select
  110. //
  111. for( i = 0; i < iListBoxCount; i++ ) {
  112. SendDlgItemMessage( hwnd,
  113. IDC_LB_HAL,
  114. LB_GETTEXT,
  115. i,
  116. (LPARAM) szListBoxEntryText );
  117. if( lstrcmpi( szListBoxEntryText,
  118. GenSettings.szHalFriendlyName ) == 0 ) {
  119. SendDlgItemMessage( hwnd,
  120. IDC_LB_HAL,
  121. LB_SETCURSEL,
  122. i,
  123. 0 );
  124. break;
  125. }
  126. }
  127. }
  128. PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_BACK | PSWIZB_NEXT);
  129. }
  130. //----------------------------------------------------------------------------
  131. //
  132. // Function: ClearHalListBox
  133. //
  134. // Purpose: Deallocates memory for all the elements in the HAL list box and
  135. // clears it.
  136. //
  137. // Arguments: HWND hwnd - handle to the dialog box
  138. //
  139. // Returns: VOID
  140. //
  141. //----------------------------------------------------------------------------
  142. static VOID
  143. ClearHalListBox( IN HWND hwnd ) {
  144. INT_PTR i;
  145. INT_PTR iListBoxCount;
  146. TCHAR *pData;
  147. iListBoxCount = SendDlgItemMessage( hwnd,
  148. IDC_LB_HAL,
  149. LB_GETCOUNT,
  150. 0,
  151. 0 );
  152. for( i = 0; i < iListBoxCount; i++ ) {
  153. pData = (TCHAR *) SendDlgItemMessage( hwnd,
  154. IDC_LB_HAL,
  155. LB_GETITEMDATA,
  156. i,
  157. 0 );
  158. if( pData ) {
  159. free( pData );
  160. }
  161. }
  162. SendDlgItemMessage( hwnd,
  163. IDC_LB_HAL,
  164. LB_RESETCONTENT,
  165. 0,
  166. 0 );
  167. }
  168. //----------------------------------------------------------------------------
  169. //
  170. // Function: OnBrowseLoadHal
  171. //
  172. // Purpose: Creates a browse window for the user to select a txtsetup.oem
  173. // file and populate the list box.
  174. //
  175. // NOTE: the malloc call in here is arguably a bug (memory leak). I
  176. // malloc the memory but never free it. Every malloc they do will be
  177. // <= MAX_PATH and realistically they won't do that many. Once they do
  178. // a load, if they do another load, I free the old memory (see
  179. // ClearHalListBox) and allocate new memory. So, for the last load
  180. // they do, the memory never gets freed. To do it right,
  181. // we would free the memory at the end of the program but NT does this for
  182. // us anyways when the process gets killed. (so no need to free)
  183. //
  184. // Arguments: HWND hwnd - handle to the dialog box
  185. //
  186. // Returns: VOID
  187. //
  188. //----------------------------------------------------------------------------
  189. static VOID
  190. OnBrowseLoadHal( IN HWND hwnd ) {
  191. TCHAR PathBuffer[MAX_PATH];
  192. INT iRet;
  193. LPTSTR pFileName;
  194. BOOL bFileNotFound = TRUE;
  195. TCHAR szTxtSetupOemLocationAndFilename[MAX_PATH] = _T("");
  196. GetCurrentDirectory( MAX_PATH, PathBuffer );
  197. ConcatenatePaths( szTxtSetupOemLocationAndFilename,
  198. szTxtSetupOemLocation,
  199. OEM_TXTSETUP_NAME,
  200. NULL );
  201. //
  202. // Keep asking for a file until we either get a txtsetup.oem or the user
  203. // presses cancel.
  204. //
  205. while( bFileNotFound ) {
  206. iRet = ShowBrowseFolder( hwnd,
  207. g_szHalFileFilter,
  208. HAL_FILE_EXTENSION,
  209. OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,
  210. PathBuffer,
  211. szTxtSetupOemLocationAndFilename );
  212. if ( ! iRet )
  213. return; // user pressed cancel on the dialog
  214. pFileName = MyGetFullPath( szTxtSetupOemLocationAndFilename );
  215. if( pFileName && (LSTRCMPI( pFileName, OEM_TXTSETUP_NAME ) == 0) ) {
  216. bFileNotFound = FALSE; // we have found the file
  217. }
  218. else {
  219. // ISSUE-2002/02/28-stelo-
  220. /*
  221. ReportErrorId(hwnd,
  222. MSGTYPE_ERR | MSGTYPE_WIN32,
  223. ,
  224. GenSettings.lpszLogoBitmap, szLogoDestination);
  225. */
  226. }
  227. }
  228. ClearHalListBox( hwnd );
  229. //
  230. // Trim the file name off szTxtSetupOemLocation so it only provides
  231. // the path to the txtsetup.oem
  232. //
  233. {
  234. TCHAR *p = szTxtSetupOemLocationAndFilename;
  235. while( p != pFileName )
  236. {
  237. p++;
  238. }
  239. *p = _T('\0');
  240. }
  241. lstrcpyn( szTxtSetupOemLocation, szTxtSetupOemLocationAndFilename, AS(szTxtSetupOemLocation) );
  242. //
  243. // Read in from the file OEM file they specified in the browse box and
  244. // add the friendly-name entries to the list box
  245. //
  246. LoadHalFromTxtsetupOem( hwnd, szTxtSetupOemLocation );
  247. }
  248. //----------------------------------------------------------------------------
  249. //
  250. // Function: LoadHalFromTxtsetupOem
  251. //
  252. // Purpose: Reads the txtsetup.oem in the specified parameter and load the
  253. // HAL choices into the list box.
  254. //
  255. // Arguments: hwnd - handle to the dialog box
  256. // szTxtSetupOemPath - path to the txtsetup.oem
  257. //
  258. // Returns: VOID
  259. //
  260. //----------------------------------------------------------------------------
  261. static VOID
  262. LoadHalFromTxtsetupOem( IN HWND hwnd,
  263. IN TCHAR *szTxtSetupOemPath ) {
  264. INT_PTR iIndex;
  265. BOOL bKeepReading;
  266. HINF hHalOem = NULL;
  267. INFCONTEXT HalOemContext = { 0 };
  268. TCHAR szTxtSetupOemPathAndFilename[MAX_PATH] = _T("");
  269. TCHAR szHalFriendlyName[MAX_HAL_NAME_LENGTH] = _T("");
  270. ConcatenatePaths( szTxtSetupOemPathAndFilename,
  271. szTxtSetupOemPath,
  272. OEM_TXTSETUP_NAME,
  273. NULL );
  274. hHalOem = SetupOpenInfFile( szTxtSetupOemPathAndFilename,
  275. NULL,
  276. INF_STYLE_OLDNT | INF_STYLE_WIN4,
  277. NULL );
  278. if( hHalOem == INVALID_HANDLE_VALUE ) {
  279. // ISSUE-2002/02/28-stelo- alert an error that we couldn't open the file
  280. return;
  281. }
  282. //
  283. // Store the path to txtsetup.oem
  284. //
  285. GetCurrentDirectory( MAX_PATH, szTxtSetupOemPath );
  286. HalOemContext.Inf = hHalOem;
  287. HalOemContext.CurrentInf = hHalOem;
  288. bKeepReading = SetupFindFirstLine( hHalOem,
  289. _T("Computer"),
  290. NULL,
  291. &HalOemContext );
  292. //
  293. // For each HAL entry, add its friendly-name to the list box
  294. //
  295. while( bKeepReading ) {
  296. TCHAR szHalName[MAX_HAL_NAME_LENGTH];
  297. TCHAR *pHalName;
  298. SetupGetStringField( &HalOemContext,
  299. 0,
  300. szHalName,
  301. MAX_HAL_NAME_LENGTH,
  302. NULL );
  303. SetupGetStringField( &HalOemContext,
  304. 1,
  305. szHalFriendlyName,
  306. MAX_HAL_NAME_LENGTH,
  307. NULL );
  308. //
  309. // Don't allow the adding of a blank name (protection against a bad input file)
  310. //
  311. if( szHalFriendlyName[0] != _T('\0') ) {
  312. iIndex = SendDlgItemMessage( hwnd,
  313. IDC_LB_HAL,
  314. LB_ADDSTRING,
  315. 0,
  316. (LPARAM) szHalFriendlyName );
  317. pHalName = (TCHAR*) malloc( sizeof(szHalName) );
  318. if (pHalName == NULL)
  319. TerminateTheWizard(IDS_ERROR_OUTOFMEMORY);
  320. lstrcpyn( pHalName, szHalName, MAX_HAL_NAME_LENGTH );
  321. SendDlgItemMessage( hwnd,
  322. IDC_LB_HAL,
  323. LB_SETITEMDATA,
  324. iIndex,
  325. (LPARAM) pHalName );
  326. }
  327. //
  328. // move to the next line of the .oem file
  329. //
  330. bKeepReading = SetupFindNextLine( &HalOemContext, &HalOemContext );
  331. }
  332. SetupCloseInfFile( hHalOem );
  333. bHasLoadedTxtSetupOem = TRUE;
  334. }
  335. //----------------------------------------------------------------------------
  336. //
  337. // Function: OnWizNextHal
  338. //
  339. // Purpose:
  340. //
  341. // Arguments: IN HWND hwnd - handle to the dialog box
  342. //
  343. // Returns: VOID
  344. //
  345. //----------------------------------------------------------------------------
  346. VOID
  347. OnWizNextHal( IN HWND hwnd ) {
  348. INT_PTR iItemSelected;
  349. INT iFound;
  350. HINF hHalOem;
  351. INFCONTEXT HalOemContext;
  352. TCHAR *pHalName;
  353. TCHAR szHalName[MAX_HAL_NAME_LENGTH];
  354. TCHAR szHalSectionName[MAX_INILINE_LEN];
  355. TCHAR szTextmodePath[MAX_PATH] = _T("");
  356. TCHAR szOemFilePathAndName[MAX_PATH] = _T("");
  357. iItemSelected = SendDlgItemMessage( hwnd,
  358. IDC_LB_HAL,
  359. LB_GETCURSEL,
  360. 0,
  361. 0 );
  362. //
  363. // If there is no HAL selected just move to the next page
  364. //
  365. if( iItemSelected == LB_ERR ) {
  366. return;
  367. }
  368. //
  369. // If the user has not loaded a txtsetup.oem by clicking the browse
  370. // button (it was filled in because this is an edit) then don't copy
  371. // any files
  372. //
  373. if( bHasLoadedTxtSetupOem == FALSE ) {
  374. return;
  375. }
  376. //
  377. // Prepare to add the new drivers
  378. //
  379. GenSettings.szHalFriendlyName[0] = _T('\0');
  380. ResetNameList( &GenSettings.OemHalFiles );
  381. ConcatenatePaths( szTextmodePath,
  382. WizGlobals.OemFilesPath,
  383. _T("Textmode"),
  384. NULL );
  385. if ( ! EnsureDirExists( szTextmodePath ) )
  386. {
  387. ReportErrorId( hwnd,
  388. MSGTYPE_ERR | MSGTYPE_WIN32,
  389. IDS_ERR_CREATE_FOLDER,
  390. szTextmodePath );
  391. return;
  392. }
  393. ConcatenatePaths( szOemFilePathAndName,
  394. szTxtSetupOemLocation,
  395. OEM_TXTSETUP_NAME,
  396. NULL );
  397. //
  398. // Read the txtsetup.oem file into the txtsetup queue
  399. //
  400. LoadOriginalSettingsLowHalScsi(hwnd,
  401. szOemFilePathAndName,
  402. SETTING_QUEUE_TXTSETUP_OEM);
  403. hHalOem = SetupOpenInfFile( szOemFilePathAndName,
  404. NULL,
  405. INF_STYLE_OLDNT | INF_STYLE_WIN4,
  406. NULL );
  407. if( hHalOem == INVALID_HANDLE_VALUE ) {
  408. // ISSUE-2002/02/28-stelo- need to somehow alert an error
  409. return;
  410. }
  411. SendDlgItemMessage( hwnd,
  412. IDC_LB_HAL,
  413. LB_GETTEXT,
  414. iItemSelected,
  415. (LPARAM) GenSettings.szHalFriendlyName );
  416. HalOemContext.Inf = hHalOem;
  417. HalOemContext.CurrentInf = hHalOem;
  418. pHalName = (TCHAR *) SendDlgItemMessage( hwnd,
  419. IDC_LB_HAL,
  420. LB_GETITEMDATA,
  421. iItemSelected,
  422. 0 );
  423. //
  424. // Build up the section name
  425. //
  426. lstrcpyn( szHalSectionName, _T("Files.computer."), AS(szHalSectionName) );
  427. lstrcatn( szHalSectionName, pHalName, MAX_INILINE_LEN );
  428. iFound = SetupFindFirstLine( hHalOem,
  429. szHalSectionName,
  430. NULL,
  431. &HalOemContext );
  432. if( iFound ) {
  433. SetupGetStringField( &HalOemContext,
  434. 2,
  435. szHalName,
  436. MAX_HAL_NAME_LENGTH,
  437. NULL );
  438. //
  439. // Don't allow the adding of a blank name (protection against a bad
  440. // input file)
  441. //
  442. if( szHalName[0] != _T('\0') ) {
  443. AddNameToNameList( &GenSettings.OemHalFiles, szHalName );
  444. CopyFileToDistShare( hwnd,
  445. szTxtSetupOemLocation,
  446. szHalName,
  447. szTextmodePath );
  448. }
  449. }
  450. SetupCloseInfFile( hHalOem );
  451. }
  452. //----------------------------------------------------------------------------
  453. //
  454. // Function: DlgHalPage
  455. //
  456. // Purpose:
  457. //
  458. // Arguments: standard Win32 dialog proc arguments
  459. //
  460. // Returns: standard Win32 dialog proc return value -- whether the message
  461. // was handled or not
  462. //
  463. //----------------------------------------------------------------------------
  464. INT_PTR CALLBACK
  465. DlgHalPage( IN HWND hwnd,
  466. IN UINT uMsg,
  467. IN WPARAM wParam,
  468. IN LPARAM lParam ) {
  469. BOOL bStatus = TRUE;
  470. switch( uMsg ) {
  471. case WM_INITDIALOG:
  472. {
  473. OnHalInitDialog( hwnd );
  474. break;
  475. }
  476. case WM_COMMAND: {
  477. switch ( LOWORD(wParam) ) {
  478. case IDC_BUT_LOAD_HAL:
  479. if ( HIWORD(wParam) == BN_CLICKED )
  480. OnBrowseLoadHal( hwnd );
  481. break;
  482. default:
  483. bStatus = FALSE;
  484. break;
  485. }
  486. break;
  487. }
  488. case WM_NOTIFY: {
  489. LPNMHDR pnmh = (LPNMHDR)lParam;
  490. switch( pnmh->code ) {
  491. case PSN_QUERYCANCEL:
  492. CancelTheWizard(hwnd); break;
  493. case PSN_SETACTIVE: {
  494. OnHalSetActive( hwnd );
  495. break;
  496. }
  497. case PSN_WIZBACK:
  498. break;
  499. case PSN_WIZNEXT:
  500. OnWizNextHal( hwnd );
  501. break;
  502. default:
  503. break;
  504. }
  505. break;
  506. }
  507. default:
  508. bStatus = FALSE;
  509. break;
  510. }
  511. return( bStatus );
  512. }