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.

633 lines
18 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. TARGETWS.H
  5. Abstract:
  6. Show Target Workstation Configureation Dialog Box Procedures
  7. Author:
  8. Bob Watson (a-robw)
  9. Revision History:
  10. 17 Feb 94 Written
  11. --*/
  12. //
  13. // Windows Include Files
  14. //
  15. #include <windows.h>
  16. #include <stdio.h>
  17. #include <malloc.h>
  18. #include <tchar.h> // unicode macros
  19. //
  20. // app include files
  21. //
  22. #include "otnboot.h"
  23. #include "otnbtdlg.h"
  24. //
  25. // list of data items that correspond to entries in combo box
  26. // the combo box displays the text description and the entries in this
  27. // msz are the keys to refer to the selected item later.
  28. //
  29. static TCHAR mszNetcardKeyList[SMALL_BUFFER_SIZE];
  30. static TCHAR mszDirNameList[SMALL_BUFFER_SIZE];
  31. #ifdef JAPAN
  32. // fixed kkntbug #12382
  33. // NCAdmin:"[] Make Japanese startup disks" is not functioning.
  34. //
  35. // indicator for making DOS/V boot disks
  36. //
  37. BOOL bJpnDisk;
  38. #endif
  39. static
  40. VOID
  41. SetDialogState (
  42. IN HWND hwndDlg
  43. )
  44. /*++
  45. Routine Description:
  46. Enables/Disables the target workstation configuration items based
  47. on the target configuration. If target is a remote boot client
  48. then the protocol/card, etc items are not necessary, if the
  49. target is to have the network software loaded over the net, then
  50. the netcard, protocol, etc fields are enabled.
  51. Arguments:
  52. IN HWND hwndDlg
  53. Handle to the dialog box window
  54. Return Value:
  55. None
  56. --*/
  57. {
  58. EnableWindow (GetDlgItem (hwndDlg, NCDU_CLIENT_SOFTWARE_LIST), TRUE);
  59. EnableWindow (GetDlgItem (hwndDlg, NCDU_CLIENT_SOFTWARE_LIST_LABEL), TRUE);
  60. EnableWindow (GetDlgItem (hwndDlg, NCDU_NETCARD_COMBO_BOX), TRUE);
  61. EnableWindow (GetDlgItem (hwndDlg, NCDU_NETCARD_COMBO_BOX_LABEL), TRUE);
  62. }
  63. static
  64. LPCTSTR
  65. GetNameFromEntry (
  66. IN LPCTSTR szEntry
  67. )
  68. /*++
  69. Routine Description:
  70. Used to parse entries from the INF the format. returns the
  71. unquoted version of the first quoted string in the szEntry
  72. buffer
  73. Arguments:
  74. IN LPCTSTR szEntry
  75. entry to examine
  76. Return Value:
  77. pointer to entry or empty string if no matching items are found
  78. --*/
  79. {
  80. static TCHAR szReturnBuff[MAX_PATH];
  81. LPTSTR szSource, szDest;
  82. szSource = (LPTSTR)szEntry;
  83. szDest = &szReturnBuff[0];
  84. // find "=", then find first " after equals. Copy all chars after
  85. // first quote up to but not including the next " char.
  86. while ((*szSource != cEqual) && (*szSource != 0)) szSource++;
  87. // szSource is at "=" (or end)
  88. while ((*szSource != cDoubleQuote) && (*szSource != 0)) szSource++;
  89. // szSource is at first double quote (or end)
  90. szSource++;
  91. while ((*szSource != cDoubleQuote) && (*szSource != 0)) {
  92. *szDest++ = *szSource++;
  93. }
  94. *szDest = 0;
  95. return &szReturnBuff[0];
  96. }
  97. static
  98. VOID
  99. LoadNetCardAdapterList (
  100. IN HWND hwndDlg
  101. )
  102. /*++
  103. Routine Description:
  104. Loads the Network adapter card combo box using entries found in the
  105. inf file.
  106. Arguments:
  107. IN HWND hwndDlg
  108. Handle to dialog box window
  109. Return Value:
  110. none
  111. --*/
  112. {
  113. LPTSTR mszKeyList;
  114. LPTSTR szData;
  115. LPTSTR szInfName;
  116. LPTSTR szNetCardInf;
  117. LPTSTR szThisItem;
  118. int nEntry;
  119. int nMszElem;
  120. UINT nErrorMode;
  121. szInfName = (LPTSTR)GlobalAlloc(GPTR, MAX_PATH_BYTES);
  122. szNetCardInf = (LPTSTR)GlobalAlloc(GPTR, MAX_PATH_BYTES);
  123. if ((szInfName == NULL) || (szNetCardInf == NULL)) return;
  124. // clear dialog box contents
  125. SendDlgItemMessage (hwndDlg, NCDU_NETCARD_COMBO_BOX, CB_RESETCONTENT, 0, 0);
  126. szData = (LPTSTR)GlobalAlloc (GPTR, SMALL_BUFFER_SIZE * sizeof(TCHAR));
  127. mszKeyList = (LPTSTR)GlobalAlloc (GPTR, MEDIUM_BUFFER_SIZE * sizeof(TCHAR));
  128. if ((szData != NULL) && (mszKeyList != NULL)) {
  129. // disable windows error message popup
  130. nErrorMode = SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
  131. // make path to inf file
  132. lstrcpy (szInfName, pAppInfo->szDistPath);
  133. if (szInfName[lstrlen(szInfName)-1] != cBackslash) lstrcat (szInfName, cszBackslash);
  134. lstrcat (szInfName, cszOtnBootInf);
  135. // get location of inf that has net cards for floppy installation
  136. if (QuietGetPrivateProfileString (cszOtnInstall, cszClient, cszEmptyString,
  137. szData, SMALL_BUFFER_SIZE, szInfName) > 0) {
  138. lstrcpy (szNetCardInf, pAppInfo->szDistPath);
  139. if (szNetCardInf[lstrlen(szNetCardInf)-1] != cBackslash) lstrcat (szNetCardInf, cszBackslash);
  140. lstrcat (szNetCardInf, szData);
  141. if (szNetCardInf[lstrlen(szNetCardInf)-1] != cBackslash) lstrcat (szNetCardInf, cszBackslash);
  142. // save directory containing floppy net files
  143. lstrcpy(pAppInfo->piFloppyProtocol.szDir, szNetCardInf);
  144. if (QuietGetPrivateProfileString (cszOtnInstall, cszInf, cszEmptyString,
  145. szData, SMALL_BUFFER_SIZE, szInfName) > 0) {
  146. lstrcat (szNetCardInf, szData);
  147. }
  148. if (FileExists (szNetCardInf)) {
  149. // save the name of the file here
  150. lstrcpy (pAppInfo->niNetCard.szInf, szNetCardInf);
  151. // netcard inf file exists so fill up list box
  152. if (GetPrivateProfileSection (cszNetcard, mszKeyList,
  153. MEDIUM_BUFFER_SIZE, szNetCardInf) > 0) {
  154. nMszElem = 1;
  155. for (szThisItem = mszKeyList;
  156. *szThisItem != 0;
  157. szThisItem += (lstrlen(szThisItem)+1)) {
  158. // get name string from entry
  159. // load into combo box
  160. nEntry = (int)SendDlgItemMessage ( hwndDlg,
  161. NCDU_NETCARD_COMBO_BOX,
  162. CB_ADDSTRING, 0,
  163. (LPARAM)GetNameFromEntry(szThisItem));
  164. // get key from entry
  165. // update item data
  166. AddStringToMultiSz(mszNetcardKeyList,
  167. GetKeyFromEntry (szThisItem));
  168. SendDlgItemMessage (hwndDlg, NCDU_NETCARD_COMBO_BOX,
  169. CB_SETITEMDATA, (WPARAM)nEntry, (LPARAM)nMszElem);
  170. nMszElem++;
  171. } // end section key loop
  172. SendDlgItemMessage (hwndDlg, NCDU_NETCARD_COMBO_BOX,
  173. CB_SETCURSEL, 0, 0);
  174. }// else unable to read section
  175. } // else no such inf file
  176. } // else unable to read OTN data
  177. SetErrorMode (nErrorMode); // restore old error mode
  178. } // else unable to allocate memory
  179. // free memory
  180. FREE_IF_ALLOC (szData);
  181. FREE_IF_ALLOC (mszKeyList);
  182. FREE_IF_ALLOC (szInfName);
  183. FREE_IF_ALLOC (szNetCardInf);
  184. return;
  185. }
  186. static
  187. BOOL
  188. TargetWsDlg_WM_INITDIALOG (
  189. IN HWND hwndDlg,
  190. IN WPARAM wParam,
  191. IN LPARAM lParam
  192. )
  193. /*++
  194. Routine Description:
  195. processes the WM_INITDIALOG windows message. Initializes the dialog
  196. box to the current values in the app data structure
  197. Arguments:
  198. IN HWND hwndDlg
  199. Handle to the dialog box window
  200. IN WPARAM wParam
  201. Not Used
  202. IN LPARAM lParam
  203. Not Used
  204. Return Value:
  205. FALSE
  206. --*/
  207. {
  208. LONG lClientId;
  209. RemoveMaximizeFromSysMenu (hwndDlg);
  210. PositionWindow (hwndDlg);
  211. if (pAppInfo->mtBootDriveType == F3_1Pt44_512) {
  212. CheckDlgButton (hwndDlg, NCDU_35HD_DISK, CHECKED);
  213. } else {
  214. CheckDlgButton (hwndDlg, NCDU_525HD_DISK, CHECKED);
  215. }
  216. *(PDWORD)mszNetcardKeyList = 0; // clear first 4 bytes of string
  217. LoadNetCardAdapterList (hwndDlg);
  218. // set to current net card if any
  219. SendDlgItemMessage (hwndDlg, NCDU_NETCARD_COMBO_BOX, CB_SELECTSTRING,
  220. (WPARAM)0, (LPARAM)pAppInfo->niNetCard.szName);
  221. #ifdef JAPAN
  222. // fixed kkntbug #12382
  223. // NCAdmin:"[] Make Japanese startup disks" is not functioning.
  224. if (usLangID == LANG_JAPANESE) {
  225. bJpnDisk = TRUE;
  226. SendDlgItemMessage (hwndDlg, NCDU_DOSV_CHECK, BM_SETCHECK, (WPARAM)1, (LPARAM)0);
  227. } else {
  228. bJpnDisk = FALSE;
  229. ShowWindow(GetDlgItem(hwndDlg, NCDU_DOSV_CHECK), SW_HIDE);
  230. }
  231. #endif
  232. LoadClientList (hwndDlg, NCDU_CLIENT_SOFTWARE_LIST,
  233. pAppInfo->szDistPath, CLT_OTNBOOT_FLOPPY, mszDirNameList);
  234. lClientId = (LONG)SendDlgItemMessage (hwndDlg, NCDU_CLIENT_SOFTWARE_LIST,
  235. LB_FINDSTRING, 0, (LPARAM)&(pAppInfo->piTargetProtocol.szName[0]));
  236. if (lClientId == LB_ERR) lClientId = 0;
  237. SendDlgItemMessage (hwndDlg, NCDU_CLIENT_SOFTWARE_LIST,
  238. LB_SETCURSEL, (WPARAM)lClientId, 0);
  239. SetDialogState(hwndDlg);
  240. SetFocus (GetDlgItem(hwndDlg, IDOK));
  241. // clear old Dialog and register current
  242. PostMessage (GetParent(hwndDlg), NCDU_CLEAR_DLG, (WPARAM)hwndDlg, IDOK);
  243. PostMessage (GetParent(hwndDlg), NCDU_REGISTER_DLG,
  244. NCDU_TARGET_WS_DLG, (LPARAM)hwndDlg);
  245. SetCursor(LoadCursor(NULL, IDC_ARROW));
  246. return FALSE;
  247. }
  248. static
  249. BOOL
  250. TargetWsDlg_IDOK (
  251. IN HWND hwndDlg
  252. )
  253. /*++
  254. Routine Description:
  255. Processes the OK button press. validates the data in the dialog and
  256. updates the application data structure with the information.
  257. If all data is valid, then the dialog box is closed, otherwise
  258. an error message is displayed and focus is set to the offending
  259. control.
  260. Arguments:
  261. IN HWND hwndDlg
  262. Handle to the dialog box window
  263. Return Value:
  264. FALSE
  265. --*/
  266. {
  267. int nCancelResult;
  268. int nCbSelIndex;
  269. int nClientIndex;
  270. int nWarningIndex;
  271. LPTSTR szClientDir;
  272. LPTSTR szWfwMessage;
  273. DWORD dwKeyIndex;
  274. LPTSTR szFromPath;
  275. LPTSTR szClientDirKey;
  276. TCHAR szClientDirName[MAX_PATH];
  277. TCHAR szWarningText[MAX_PATH];
  278. TCHAR szWarningCaption[MAX_PATH];
  279. LPTSTR szNextMessage;
  280. TCHAR szWfwDirName[32];
  281. TCHAR szWin95DirName[32];
  282. TCHAR szWinNtDirName[32];
  283. #ifdef JAPAN
  284. TCHAR szWinntus[MAX_PATH];
  285. TCHAR szSetupCmdName[32];
  286. OFSTRUCT OpenBuff;
  287. #endif
  288. // save settings
  289. szFromPath = (LPTSTR)GlobalAlloc (GPTR, MAX_PATH_BYTES);
  290. if (szFromPath == NULL) {
  291. // mem alloc err.
  292. EndDialog (hwndDlg, IDCANCEL);
  293. return TRUE;
  294. }
  295. if (IsDlgButtonChecked(hwndDlg, NCDU_35HD_DISK) == CHECKED) {
  296. pAppInfo->mtBootDriveType = F3_1Pt44_512;
  297. } else {
  298. pAppInfo->mtBootDriveType = F5_1Pt2_512;
  299. }
  300. // MS Network client selected so save values
  301. // configure server settings
  302. //
  303. // see if a client that needs a "guilt" message displayed
  304. //
  305. // get client to install
  306. nClientIndex = (int)SendDlgItemMessage (hwndDlg, NCDU_CLIENT_SOFTWARE_LIST,
  307. LB_GETCURSEL, 0, 0);
  308. if (nClientIndex == LB_ERR) return FALSE;
  309. // save setup command for OTN setup
  310. lstrcpy (szFromPath, pAppInfo->szDistPath);
  311. if (szFromPath[lstrlen(szFromPath)-1] != cBackslash) lstrcat (szFromPath, cszBackslash);
  312. lstrcat (szFromPath, cszAppInfName);
  313. // copy the client key from the list box name list
  314. lstrcpy (szClientDirName, (LPTSTR)GetEntryInMultiSz (mszDirNameList, nClientIndex+1));
  315. lstrcat (szClientDirName, TEXT("_"));
  316. szClientDirKey = szClientDirName + lstrlen(szClientDirName);
  317. // see if a guilt message for this client should be displayed.
  318. lstrcpy (szClientDirKey, cszCaption);
  319. if (QuietGetPrivateProfileString (cszWarningClients,
  320. szClientDirName,
  321. cszEmptyString, szWarningCaption,
  322. sizeof(szWarningCaption)/sizeof(TCHAR), szFromPath) > 0) {
  323. // then a caption was found indicating a warning message should be
  324. // displayed.
  325. szWfwMessage = GlobalAlloc (GPTR, SMALL_BUFFER_SIZE * sizeof(TCHAR));
  326. if (szWfwMessage != NULL) {
  327. *szWfwMessage = 0;
  328. // so now get all the strings from the file and build
  329. // the display string
  330. for (nWarningIndex = 1, szNextMessage = szWfwMessage;
  331. _stprintf (szClientDirKey, TEXT("%d"), nWarningIndex),
  332. (QuietGetPrivateProfileString (cszWarningClients,
  333. szClientDirName,
  334. cszEmptyString, szWarningText,
  335. sizeof(szWarningText), szFromPath) > 0);
  336. nWarningIndex++) {
  337. szNextMessage += TranslateEscapeChars(szNextMessage, szWarningText);
  338. }
  339. nCancelResult = MessageBox (
  340. hwndDlg,
  341. szWfwMessage,
  342. szWarningCaption,
  343. MB_OKCANCEL_TASK_EXCL_DEF2);
  344. if (nCancelResult == IDCANCEL) {
  345. // they don't really want to do this
  346. SetFocus (GetDlgItem (hwndDlg, NCDU_CLIENT_SOFTWARE_LIST));
  347. return FALSE;
  348. } // else continue
  349. GlobalFree (szWfwMessage);
  350. } // else unable to allocate string buffer so continue
  351. } // else no warning message is necessary
  352. pAppInfo->bRemoteBootReqd = FALSE;
  353. // get netcard name and other information
  354. nCbSelIndex = (int)SendDlgItemMessage(hwndDlg, NCDU_NETCARD_COMBO_BOX,
  355. CB_GETCURSEL, 0, 0);
  356. SendDlgItemMessage (hwndDlg, NCDU_NETCARD_COMBO_BOX, CB_GETLBTEXT,
  357. (WPARAM)nCbSelIndex, (LPARAM)pAppInfo->niNetCard.szName);
  358. dwKeyIndex = (DWORD)SendDlgItemMessage (hwndDlg, NCDU_NETCARD_COMBO_BOX, CB_GETITEMDATA,
  359. (WPARAM)nCbSelIndex, 0);
  360. lstrcpy (pAppInfo->niNetCard.szInfKey, GetEntryInMultiSz(mszNetcardKeyList, dwKeyIndex));
  361. // get the rest of the netcard information.
  362. QuietGetPrivateProfileString (cszNetcard,
  363. pAppInfo->niNetCard.szInfKey,
  364. cszEmptyString,
  365. szFromPath, MAX_PATH,
  366. pAppInfo->niNetCard.szInf);
  367. lstrcpy (pAppInfo->niNetCard.szDeviceKey, GetItemFromEntry (szFromPath, 6));
  368. lstrcpy (pAppInfo->niNetCard.szNifKey, GetItemFromEntry (szFromPath, 7));
  369. if (_tcsnicmp(GetItemFromEntry(szFromPath,4), cszTokenRing, lstrlen(cszTokenRing)) == 0) {
  370. pAppInfo->niNetCard.bTokenRing = TRUE;
  371. } else {
  372. pAppInfo->niNetCard.bTokenRing = FALSE;
  373. }
  374. SendDlgItemMessage (hwndDlg, NCDU_CLIENT_SOFTWARE_LIST,
  375. LB_GETTEXT, (WPARAM)nClientIndex, (LPARAM)&(pAppInfo->piTargetProtocol.szName[0]));
  376. // get root dir of dist tree
  377. lstrcpy (szFromPath, pAppInfo->szDistPath);
  378. if (szFromPath[lstrlen(szFromPath)-1] != cBackslash) lstrcat (szFromPath, cszBackslash);
  379. // append client sw subdir
  380. szClientDir = (LPTSTR)GetEntryInMultiSz (mszDirNameList, nClientIndex+1);
  381. lstrcat (szFromPath, szClientDir);
  382. if (szFromPath[lstrlen(szFromPath)-1] != cBackslash) lstrcat (szFromPath, cszBackslash);
  383. // append name of Over the Net distribution dir
  384. lstrcat (szFromPath, cszNetsetup);
  385. // save protocol file path for OTN setup
  386. lstrcpy (pAppInfo->piTargetProtocol.szDir, szFromPath);
  387. // save setup command for OTN setup
  388. lstrcpy (szFromPath, pAppInfo->szDistPath);
  389. if (szFromPath[lstrlen(szFromPath)-1] != cBackslash) lstrcat (szFromPath, cszBackslash);
  390. lstrcat (szFromPath, cszAppInfName);
  391. #ifdef JAPAN
  392. // fixed kkntbug #12382
  393. // NCAdmin:"[] Make Japanese startup disks" is not functioning.
  394. lstrcpy(szSetupCmdName, szClientDir);
  395. if (!bJpnDisk) {
  396. wsprintf(szWinntus, TEXT("%s%s%s%s"), pAppInfo->szDistPath, szClientDir, cszBackslash, fmtWinntUs);
  397. if (HFILE_ERROR != OpenFile((LPCSTR)szWinntus, &OpenBuff, OF_EXIST))
  398. wsprintf(szSetupCmdName, TEXT("%s%s"), szClientDir, fmtAppendUs);
  399. }
  400. if (!QuietGetPrivateProfileString (cszSetupCmd, szSetupCmdName, cszEmptyString,
  401. pAppInfo->szTargetSetupCmd, MAX_PATH, szFromPath))
  402. #endif
  403. QuietGetPrivateProfileString (cszSetupCmd, szClientDir, cszEmptyString,
  404. pAppInfo->szTargetSetupCmd, MAX_PATH, szFromPath);
  405. PostMessage (GetParent(hwndDlg), NCDU_SHOW_SERVER_CFG_DLG, 0, 0);
  406. SetCursor(LoadCursor(NULL, IDC_WAIT));
  407. FREE_IF_ALLOC (szFromPath);
  408. return TRUE;
  409. }
  410. static
  411. BOOL
  412. TargetWsDlg_WM_COMMAND (
  413. IN HWND hwndDlg,
  414. IN WPARAM wParam,
  415. IN LPARAM lParam
  416. )
  417. /*++
  418. Routine Description:
  419. Processes WM_COMMAND windows message and dispatches the appropriate
  420. routine.
  421. Arguments:
  422. IN HWND hwndDlg
  423. handle to the dialog box window
  424. IN WPARAM wParam
  425. LOWORD has the ID of the Control issuing the message
  426. IN LPARAM lParam
  427. Not Used
  428. Return Value:
  429. TRUE if message is not processed by this routine otherwise
  430. FALSE or the value returned by the dispatched routine.
  431. --*/
  432. {
  433. switch (LOWORD(wParam)) {
  434. case IDCANCEL:
  435. PostMessage (GetParent(hwndDlg), NCDU_SHOW_SHARE_NET_SW_DLG, 0, 0);
  436. SetCursor(LoadCursor(NULL, IDC_WAIT));
  437. return TRUE;
  438. case IDOK: return TargetWsDlg_IDOK (hwndDlg);
  439. #ifdef JAPAN
  440. // fixed kkntbug #12382
  441. // NCAdmin:"[] Make Japanese startup disks" is not functioning.
  442. case NCDU_DOSV_CHECK:
  443. if (IsDlgButtonChecked(hwndDlg, NCDU_DOSV_CHECK) == 1)
  444. bJpnDisk = TRUE;
  445. else
  446. bJpnDisk = FALSE;
  447. return TRUE;
  448. #endif
  449. case NCDU_TARGET_WS_HELP:
  450. switch (HIWORD(wParam)) {
  451. case BN_CLICKED:
  452. // return ShowAppHelp (hwndDlg, LOWORD(wParam));
  453. return PostMessage (GetParent(hwndDlg), WM_HOTKEY,
  454. (WPARAM)NCDU_HELP_HOT_KEY, 0);
  455. default:
  456. return FALSE;
  457. }
  458. default: return FALSE;
  459. }
  460. }
  461. INT_PTR CALLBACK
  462. TargetWsDlgProc (
  463. IN HWND hwndDlg,
  464. IN UINT message,
  465. IN WPARAM wParam,
  466. IN LPARAM lParam
  467. )
  468. /*++
  469. Routine Description:
  470. Processes windows messages to this dialog box. The following messages
  471. are processed by this module:
  472. WM_INITDIALOG: dialog box initialization
  473. WM_COMMAND: user action
  474. all other messages are processed by the default dialog proc.
  475. Arguments:
  476. Standard WNDPROC args
  477. Return Value:
  478. FALSE if message is not processed by this module, otherwise the
  479. value returned by the dispatched routine.
  480. --*/
  481. {
  482. switch (message) {
  483. case WM_INITDIALOG: return (TargetWsDlg_WM_INITDIALOG (hwndDlg, wParam, lParam));
  484. case WM_COMMAND: return (TargetWsDlg_WM_COMMAND (hwndDlg, wParam, lParam));
  485. case WM_PAINT: return (Dlg_WM_PAINT (hwndDlg, wParam, lParam));
  486. case WM_MOVE: return (Dlg_WM_MOVE (hwndDlg, wParam, lParam));
  487. case WM_SYSCOMMAND: return (Dlg_WM_SYSCOMMAND (hwndDlg, wParam, lParam));
  488. default: return FALSE;
  489. }
  490. }