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.

988 lines
27 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. SERVCONN.C
  5. Abstract:
  6. Show server connection configuration dialog box
  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 <stdlib.h>
  18. #include <time.h>
  19. #include <malloc.h>
  20. #include <tchar.h> // unicode macros
  21. #include <commdlg.h> // common dialog defines
  22. #include <lmcons.h> // lanman API constant definitions
  23. #include <lmserver.h> // server info API's
  24. //
  25. // app include files
  26. //
  27. #include "otnboot.h"
  28. #include "otnbtdlg.h"
  29. //
  30. #define IP_CHARLIMIT 15
  31. //
  32. #define NCDU_BROWSE_DEST_PATH (WM_USER + 101)
  33. //
  34. // Local data structures
  35. //
  36. typedef struct _NETWORK_PROTOCOL_NAMES {
  37. UINT nDisplayName;
  38. UINT nTransportName;
  39. DWORD dwTransportNameLength;
  40. BOOL bLoaded;
  41. int nListBoxEntry;
  42. } NETWORK_PROTOCOL_NAMES, *PNETWORK_PROTOCOL_NAMES;
  43. //
  44. // static data
  45. //
  46. static NETWORK_PROTOCOL_NAMES NetProtocolList[] = {
  47. {CSZ_NW_LINK_PROTOCOL, NCDU_NW_LINK_TRANSPORT, 0, FALSE, CB_ERR},
  48. {CSZ_TCP_IP_PROTOCOL, NCDU_TCP_IP_TRANSPORT, 0, FALSE, CB_ERR},
  49. {CSZ_NETBEUI_PROTOCOL, NCDU_NETBEUI_TRANSPORT, 0, FALSE, CB_ERR},
  50. // "terminating" entry in array
  51. {0, 0, 0, FALSE, CB_ERR}
  52. };
  53. static
  54. LPCTSTR
  55. GetDefaultDomain (
  56. )
  57. /*++
  58. Routine Description:
  59. Returns the domain the system is logged in to from the registry.
  60. Arguments:
  61. None
  62. Return Value:
  63. pointer to domain name string if successful or pointer to an
  64. empty strin if not.
  65. --*/
  66. {
  67. DWORD dwBufLen;
  68. DWORD dwDomainLen;
  69. static TCHAR szDomainName[32];
  70. TCHAR szUserName[MAX_USERNAME + 1];
  71. PSID pSid;
  72. SID_NAME_USE snu;
  73. szDomainName[0] = 0;
  74. dwBufLen = MAX_USERNAME;
  75. if (GetUserName(szUserName, &dwBufLen)) {
  76. pSid = (PSID)GlobalAlloc(GPTR, SMALL_BUFFER_SIZE);
  77. if (pSid != NULL) {
  78. dwBufLen = (DWORD)GlobalSize(pSid);
  79. dwDomainLen = sizeof (szDomainName) / sizeof(TCHAR);
  80. LookupAccountName (
  81. NULL, // Local system
  82. szUserName, // username to look up
  83. pSid, // SID buffer
  84. &dwBufLen, // SID buffer size
  85. szDomainName, // return buffer for domain name
  86. &dwDomainLen, // size of buffer
  87. &snu);
  88. FREE_IF_ALLOC(pSid);
  89. }
  90. }
  91. return szDomainName;
  92. }
  93. static
  94. LPCTSTR
  95. GetDefaultUsername (
  96. )
  97. /*++
  98. Routine Description:
  99. Returns the user name of the account running the app
  100. Arguments:
  101. None
  102. Return Value:
  103. pointer to user name string if successful or pointer to an empty
  104. string if not.
  105. --*/
  106. {
  107. DWORD dwBufLen;
  108. static TCHAR szUserName[32];
  109. szUserName[0] = 0;
  110. dwBufLen = sizeof(szUserName) / sizeof(TCHAR); // compute # of chars
  111. GetUserName(szUserName, &dwBufLen);
  112. return szUserName;
  113. }
  114. static
  115. LPCTSTR
  116. MakeIpAddrString (
  117. IN USHORT IpAddr[]
  118. )
  119. /*++
  120. Routine Description:
  121. formats integer array into an address string for display
  122. Arguments:
  123. IP Address info structure
  124. Return Value:
  125. pointer to formatted IP address string if successful or pointer to
  126. an empty string if not.
  127. --*/
  128. {
  129. static TCHAR szAddrBuffer[32];
  130. szAddrBuffer[0] = 0;
  131. _stprintf (szAddrBuffer, fmtIpAddr,
  132. IpAddr[0], IpAddr[1], IpAddr[2], IpAddr[3]);
  133. return szAddrBuffer;
  134. }
  135. static
  136. LONG
  137. ListNetworkTransports (
  138. IN HWND hwndDlg,
  139. IN LPTSTR szServerName
  140. )
  141. /*++
  142. Routine Description:
  143. reads the registry and builds a list of the network protocols that are
  144. supported on the selected server and loads the combo box with all
  145. possible transports.
  146. Arguments:
  147. IN HWND hwndDlg
  148. handle to dialog box window
  149. IN LPTSTR szServerName
  150. server to validate protocols on
  151. Return Value:
  152. ERROR_SUCCESS if successful or WIN32 error value if not
  153. --*/
  154. {
  155. DWORD dwIndex;
  156. BOOL bDefaultFound;
  157. DWORD dwSumOfEntries;
  158. DWORD dwEntriesRead;
  159. DWORD dwTotalEntries;
  160. DWORD dwResumeHandle;
  161. LONG lStatus = ERROR_SUCCESS;
  162. PNETWORK_PROTOCOL_NAMES pThisNetProtocol;
  163. PSERVER_TRANSPORT_INFO_0 pSrvrTransportInfo;
  164. PSERVER_TRANSPORT_INFO_0 pThisSrvrTransport;
  165. NET_API_STATUS netStatus;
  166. pSrvrTransportInfo = (PSERVER_TRANSPORT_INFO_0)GlobalAlloc(GPTR, MEDIUM_BUFFER_SIZE);
  167. if (pSrvrTransportInfo == NULL) {
  168. return ERROR_OUTOFMEMORY;
  169. }
  170. // initialize static data
  171. for (pThisNetProtocol = &NetProtocolList[0];
  172. pThisNetProtocol->nDisplayName != 0;
  173. pThisNetProtocol = &pThisNetProtocol[1]) {
  174. pThisNetProtocol->dwTransportNameLength =
  175. lstrlen (GetStringResource (pThisNetProtocol->nTransportName));
  176. pThisNetProtocol->bLoaded = FALSE;
  177. pThisNetProtocol->nListBoxEntry = CB_ERR;
  178. }
  179. // build list of available network transports on server
  180. dwEntriesRead = 0L;
  181. dwSumOfEntries = 0L;
  182. dwTotalEntries = 0xFFFFFFFF;
  183. dwResumeHandle = 0L;
  184. while (dwSumOfEntries != dwTotalEntries) {
  185. netStatus = NetServerTransportEnum (
  186. szServerName,
  187. 0L,
  188. (LPBYTE *)&pSrvrTransportInfo,
  189. MEDIUM_BUFFER_SIZE,
  190. &dwEntriesRead,
  191. &dwTotalEntries,
  192. &dwResumeHandle);
  193. if (netStatus == NO_ERROR) {
  194. dwSumOfEntries += dwEntriesRead;
  195. for (dwIndex = 0; dwIndex < dwEntriesRead; dwIndex++) {
  196. pThisSrvrTransport = &pSrvrTransportInfo[dwIndex];
  197. for (pThisNetProtocol = &NetProtocolList[0];
  198. pThisNetProtocol->nDisplayName != 0;
  199. pThisNetProtocol = &pThisNetProtocol[1]) {
  200. if (_tcsnicmp (GetStringResource(pThisNetProtocol->nTransportName),
  201. pThisSrvrTransport->svti0_transportname,
  202. pThisNetProtocol->dwTransportNameLength) == 0) {
  203. if (lstrcmp (pThisSrvrTransport->svti0_networkaddress,
  204. cszZeroNetAddress) != 0) {
  205. pThisNetProtocol->bLoaded = TRUE;
  206. break;
  207. }
  208. }
  209. }
  210. }
  211. } else {
  212. // bail out of loop if an error is encountered
  213. break;
  214. }
  215. }
  216. // so all the supported protocols have been identified here, now
  217. // reload the combo box.
  218. bDefaultFound = FALSE;
  219. dwIndex = 0;
  220. // empty the combo box
  221. SendDlgItemMessage (hwndDlg, NCDU_PROTOCOL_COMBO_BOX,
  222. CB_RESETCONTENT, 0, 0);
  223. for (pThisNetProtocol = &NetProtocolList[0];
  224. pThisNetProtocol->nDisplayName != 0;
  225. pThisNetProtocol = &pThisNetProtocol[1]) {
  226. // load combo box with each "transports"
  227. pThisNetProtocol->nListBoxEntry = (int)SendDlgItemMessage (hwndDlg,
  228. NCDU_PROTOCOL_COMBO_BOX, CB_ADDSTRING, (WPARAM)0,
  229. (LPARAM)GetStringResource (pThisNetProtocol->nDisplayName));
  230. if (!bDefaultFound) {
  231. if (pThisNetProtocol->bLoaded) {
  232. bDefaultFound = TRUE;
  233. dwIndex = (DWORD)pThisNetProtocol->nListBoxEntry;
  234. }
  235. }
  236. }
  237. // select default entry
  238. SendDlgItemMessage (hwndDlg, NCDU_PROTOCOL_COMBO_BOX,
  239. CB_SETCURSEL, (WPARAM)dwIndex, 0);
  240. FREE_IF_ALLOC(pSrvrTransportInfo);
  241. return lStatus;
  242. }
  243. static
  244. BOOL
  245. LoadIpAddrArray (
  246. IN LPCTSTR szIpString,
  247. OUT USHORT nAddrItem[]
  248. )
  249. /*++
  250. Routine Description:
  251. Parses the display string into the IP address array
  252. Arguments:
  253. IN LPCTSTR szIpString
  254. input string to parse
  255. OUT USHORT nAddrItem[]
  256. array to receive the address elements. Element 0 is the
  257. left-most element in the display string.
  258. Return Value:
  259. TRUE if parsed successfully
  260. FALSE if error
  261. --*/
  262. {
  263. int nArgs;
  264. int nThisArg;
  265. DWORD dw[4];
  266. nArgs = _stscanf (szIpString, fmtIpAddrParse,
  267. &dw[0], &dw[1], &dw[2], &dw[3]);
  268. if (nArgs == 4) {
  269. for (nThisArg = 0; nThisArg < nArgs; nThisArg++) {
  270. if (dw[nThisArg] > 255) {
  271. // bad value
  272. return FALSE;
  273. } else {
  274. // valid so copy the low byte of the value since that's
  275. // all that's allowed for an IP address or mask
  276. nAddrItem[nThisArg] = (USHORT)(dw[nThisArg] & 0x000000FF);
  277. }
  278. }
  279. } else {
  280. return FALSE;
  281. }
  282. return TRUE;
  283. }
  284. static
  285. VOID
  286. SetTcpIpWindowState (
  287. IN HWND hwndDlg
  288. )
  289. /*++
  290. Routine Description:
  291. enables the IP address fields when TCP/IP protocol is enabled and
  292. disabled the IP address fields when it is not selected.
  293. Arguments:
  294. IN HWND hwndDlg
  295. handle to the dialog box window
  296. Return Value:
  297. NONE
  298. --*/
  299. {
  300. LPTSTR szProtocol;
  301. int nComboItem;
  302. BOOL bFrameState, bAddrState;
  303. szProtocol = (LPTSTR)GlobalAlloc (GPTR, MAX_PATH_BYTES);
  304. if (szProtocol == NULL) return;
  305. nComboItem = (int)SendDlgItemMessage (hwndDlg, NCDU_PROTOCOL_COMBO_BOX,
  306. CB_GETCURSEL, 0, 0);
  307. SendDlgItemMessage (hwndDlg, NCDU_PROTOCOL_COMBO_BOX, CB_GETLBTEXT,
  308. (WPARAM)nComboItem, (LPARAM)szProtocol);
  309. if (_tcsnicmp(szProtocol, cszTcpKey, lstrlen(cszTcpKey)) == 0) {
  310. bFrameState = TRUE;
  311. if (IsDlgButtonChecked(hwndDlg, NCDU_USE_DHCP) == CHECKED) {
  312. bAddrState = FALSE;
  313. } else {
  314. bAddrState = TRUE;
  315. }
  316. } else {
  317. bFrameState = FALSE;
  318. bAddrState = FALSE;
  319. }
  320. EnableWindow (GetDlgItem(hwndDlg,NCDU_USE_DHCP), bFrameState);
  321. EnableWindow (GetDlgItem(hwndDlg,NCDU_FLOPPY_IP_ADDR_LABEL), bAddrState);
  322. EnableWindow (GetDlgItem(hwndDlg,NCDU_FLOPPY_IP_ADDR), bAddrState);
  323. EnableWindow (GetDlgItem(hwndDlg,NCDU_FLOPPY_SUBNET_LABEL), bAddrState);
  324. EnableWindow (GetDlgItem(hwndDlg,NCDU_FLOPPY_SUBNET_MASK), bAddrState);
  325. EnableWindow (GetDlgItem(hwndDlg,NCDU_DEFAULT_GATEWAY_LABEL), bFrameState);
  326. EnableWindow (GetDlgItem(hwndDlg,NCDU_DEFAULT_GATEWAY), bFrameState);
  327. EnableWindow (GetDlgItem(hwndDlg,NCDU_TCPIP_INFO_FRAME), bFrameState);
  328. FREE_IF_ALLOC (szProtocol);
  329. }
  330. static
  331. BOOL
  332. ComputeDefaultDefaultGateway (
  333. IN HWND hwndDlg
  334. )
  335. /*++
  336. Routine Description:
  337. Generates a default value for the default gateway using the
  338. IP address and Sub Net mask
  339. Arguments:
  340. Handle to the dialog box window
  341. Return Value:
  342. TRUE if a default value was entered,
  343. FALSE if not
  344. --*/
  345. {
  346. TCHAR szIpAddr[IP_CHARLIMIT+1];
  347. TCHAR szSubNet[IP_CHARLIMIT+1];
  348. TCHAR szDefGate[IP_CHARLIMIT+1];
  349. USHORT usIpArray[4], usSnArray[4], usDgArray[4];
  350. // if not initialized, then preset to
  351. // default value
  352. GetDlgItemText (hwndDlg, NCDU_FLOPPY_IP_ADDR, szIpAddr, IP_CHARLIMIT);
  353. if (LoadIpAddrArray(szIpAddr, &usIpArray[0])) {
  354. GetDlgItemText (hwndDlg, NCDU_FLOPPY_SUBNET_MASK, szSubNet, IP_CHARLIMIT);
  355. if (LoadIpAddrArray(szSubNet, &usSnArray[0])) {
  356. GetDlgItemText (hwndDlg, NCDU_DEFAULT_GATEWAY, szDefGate, IP_CHARLIMIT);
  357. if (LoadIpAddrArray(szDefGate, &usDgArray[0])) {
  358. if ((usDgArray[0] == 0) &&
  359. (usDgArray[1] == 0) &&
  360. (usDgArray[2] == 0) &&
  361. (usDgArray[3] == 0)) {
  362. usDgArray[0] = usIpArray[0] & usSnArray[0];
  363. usDgArray[1] = usIpArray[1] & usSnArray[1];
  364. usDgArray[2] = usIpArray[2] & usSnArray[2];
  365. usDgArray[3] = usIpArray[3] & usSnArray[3];
  366. SetDlgItemText (hwndDlg, NCDU_DEFAULT_GATEWAY,
  367. MakeIpAddrString(&usDgArray[0]));
  368. return TRUE; // value updated
  369. }
  370. }
  371. }
  372. }
  373. return FALSE; // value not updated
  374. }
  375. static
  376. BOOL
  377. ServerConnDlg_WM_INITDIALOG (
  378. IN HWND hwndDlg,
  379. IN WPARAM wParam,
  380. IN LPARAM lParam
  381. )
  382. /*++
  383. Routine Description:
  384. Processes the WM_INITDIALOG windows message by initializing the
  385. display fields in the dialog box and setting focus to the first
  386. entry field
  387. Arguments:
  388. IN HWND hwndDlg
  389. Handle to the dialog box window
  390. IN WPARAM wParam
  391. Not Used
  392. IN LPARAM lParam
  393. Not Used
  394. Return Value:
  395. FALSE
  396. --*/
  397. {
  398. LONG lProtocolNdx;
  399. LPTSTR szServerArg;
  400. LPTSTR szServerName;
  401. LPTSTR szPathOnServer;
  402. szServerName = (LPTSTR)GlobalAlloc (GPTR, MAX_PATH_BYTES);
  403. szPathOnServer = (LPTSTR)GlobalAlloc (GPTR, MAX_PATH_BYTES);
  404. if ((szServerName == NULL) ||
  405. (szPathOnServer == NULL)) {
  406. SetLastError (ERROR_OUTOFMEMORY);
  407. EndDialog (hwndDlg, (int)WM_CLOSE);
  408. return FALSE;
  409. }
  410. RemoveMaximizeFromSysMenu (hwndDlg);
  411. PositionWindow (hwndDlg);
  412. // get name of server with client tree
  413. lstrcpy (szServerName, cszDoubleBackslash);
  414. if (!GetNetPathInfo (pAppInfo->szDistPath,
  415. &szServerName[2], szPathOnServer)) {
  416. // unable to look up server, so use local path
  417. szServerArg = NULL;
  418. } else {
  419. szServerArg = szServerName;
  420. }
  421. ListNetworkTransports (hwndDlg, szServerArg);
  422. // select current protocol (if any)
  423. if (*pAppInfo->piFloppyProtocol.szName != 0) {
  424. lProtocolNdx = (LONG)SendDlgItemMessage (hwndDlg, NCDU_PROTOCOL_COMBO_BOX, CB_FINDSTRING,
  425. (WPARAM)0, (LPARAM)pAppInfo->piFloppyProtocol.szName);
  426. if (lProtocolNdx == CB_ERR) {
  427. // selection not found so apply default
  428. lProtocolNdx = 0;
  429. }
  430. SendDlgItemMessage (hwndDlg, NCDU_PROTOCOL_COMBO_BOX, CB_SETCURSEL,
  431. (WPARAM)lProtocolNdx, 0);
  432. }
  433. SendDlgItemMessage (hwndDlg, NCDU_FLOPPY_USERNAME, EM_LIMITTEXT, MAX_USERNAME, 0);
  434. if (pAppInfo->szUsername[0] == 0) {
  435. SetDlgItemText (hwndDlg, NCDU_FLOPPY_USERNAME, GetDefaultUsername());
  436. } else {
  437. SetDlgItemText (hwndDlg, NCDU_FLOPPY_USERNAME, pAppInfo->szUsername);
  438. }
  439. SendDlgItemMessage (hwndDlg, NCDU_FLOPPY_COMPUTER_NAME, EM_LIMITTEXT, MAX_COMPUTERNAME_LENGTH, 0);
  440. SetDlgItemText (hwndDlg, NCDU_FLOPPY_COMPUTER_NAME, pAppInfo->szComputerName);
  441. SendDlgItemMessage (hwndDlg, NCDU_FLOPPY_DOMAIN, EM_LIMITTEXT, MAX_DOMAINNAME, 0);
  442. if (pAppInfo->szDomain[0] == 0) {
  443. SetDlgItemText (hwndDlg, NCDU_FLOPPY_DOMAIN, GetDefaultDomain());
  444. } else {
  445. SetDlgItemText (hwndDlg, NCDU_FLOPPY_DOMAIN, pAppInfo->szDomain);
  446. }
  447. SendDlgItemMessage (hwndDlg, NCDU_FLOPPY_IP_ADDR, EM_LIMITTEXT, (WPARAM)IP_CHARLIMIT, 0);
  448. SendDlgItemMessage (hwndDlg, NCDU_FLOPPY_SUBNET_MASK, EM_LIMITTEXT, (WPARAM)IP_CHARLIMIT, 0);
  449. SetDlgItemText (hwndDlg, NCDU_FLOPPY_IP_ADDR, MakeIpAddrString(&pAppInfo->tiTcpIpInfo.IpAddr[0]));
  450. SetDlgItemText (hwndDlg, NCDU_FLOPPY_SUBNET_MASK, MakeIpAddrString(&pAppInfo->tiTcpIpInfo.SubNetMask[0]));
  451. SetDlgItemText (hwndDlg, NCDU_DEFAULT_GATEWAY, MakeIpAddrString(&pAppInfo->tiTcpIpInfo.DefaultGateway[0]));
  452. if (pAppInfo->bUseDhcp) {
  453. CheckDlgButton (hwndDlg, NCDU_USE_DHCP, CHECKED);
  454. } else {
  455. CheckDlgButton (hwndDlg, NCDU_USE_DHCP, UNCHECKED);
  456. }
  457. SendDlgItemMessage (hwndDlg, NCDU_TARGET_DRIVEPATH, EM_LIMITTEXT,
  458. (WPARAM)(MAX_PATH-1), (LPARAM)0);
  459. if (*pAppInfo->szBootFilesPath == 0) {
  460. SetDlgItemText (hwndDlg, NCDU_TARGET_DRIVEPATH, cszADriveRoot);
  461. } else {
  462. SetDlgItemText (hwndDlg, NCDU_TARGET_DRIVEPATH, pAppInfo->szBootFilesPath);
  463. }
  464. SetTcpIpWindowState (hwndDlg);
  465. SetFocus (GetDlgItem(hwndDlg, NCDU_FLOPPY_COMPUTER_NAME));
  466. // clear old Dialog and register current
  467. PostMessage (GetParent(hwndDlg), NCDU_CLEAR_DLG, (WPARAM)hwndDlg, IDOK);
  468. PostMessage (GetParent(hwndDlg), NCDU_REGISTER_DLG,
  469. NCDU_SERVER_CFG_DLG, (LPARAM)hwndDlg);
  470. FREE_IF_ALLOC(szServerName);
  471. FREE_IF_ALLOC(szPathOnServer);
  472. return FALSE;
  473. }
  474. static
  475. BOOL
  476. ServerConnDlg_IDOK (
  477. IN HWND hwndDlg
  478. )
  479. /*++
  480. Routine Description:
  481. Processes the OK button command by validating the entries and
  482. storing them in the global application data structure. If an
  483. invalid value is detected a message box is displayed and the
  484. focus is set to the offending field, otherwise, the dialog
  485. box is terminated.
  486. Arguments:
  487. IN HWND hwndDlg
  488. Handle to the dialog box window
  489. Return Value:
  490. FALSE
  491. --*/
  492. {
  493. int nComboItem;
  494. int nMbResult;
  495. TCHAR szIp[IP_CHARLIMIT*2];
  496. MEDIA_TYPE mtDest;
  497. BOOL bProtocolLoaded;
  498. PNETWORK_PROTOCOL_NAMES pThisNetProtocol;
  499. // save settings
  500. GetDlgItemText (hwndDlg, NCDU_FLOPPY_COMPUTER_NAME, pAppInfo->szComputerName, MAX_COMPUTERNAME_LENGTH);
  501. TrimSpaces (pAppInfo->szComputerName);
  502. // see if there is a string...signal if no entry
  503. if (lstrlen(pAppInfo->szComputerName) == 0) {
  504. DisplayMessageBox (
  505. hwndDlg,
  506. NCDU_INVALID_MACHINENAME,
  507. 0,
  508. MB_OK_TASK_EXCL);
  509. SetFocus (GetDlgItem (hwndDlg, NCDU_FLOPPY_COMPUTER_NAME));
  510. return TRUE;
  511. }
  512. GetDlgItemText (hwndDlg, NCDU_FLOPPY_USERNAME, pAppInfo->szUsername, MAX_USERNAME);
  513. TrimSpaces (pAppInfo->szUsername);
  514. GetDlgItemText (hwndDlg, NCDU_FLOPPY_DOMAIN, pAppInfo->szDomain, MAX_DOMAINNAME);
  515. TrimSpaces (pAppInfo->szDomain);
  516. nComboItem = (int)SendDlgItemMessage (hwndDlg, NCDU_PROTOCOL_COMBO_BOX,
  517. CB_GETCURSEL, 0, 0);
  518. SendDlgItemMessage (hwndDlg, NCDU_PROTOCOL_COMBO_BOX, CB_GETLBTEXT,
  519. (WPARAM)nComboItem, (LPARAM)pAppInfo->piFloppyProtocol.szName);
  520. // look up keyname from protocol name
  521. if (_tcsnicmp(pAppInfo->piFloppyProtocol.szName, cszTcpKey, lstrlen(cszTcpKey)) == 0) {
  522. lstrcpy(pAppInfo->piFloppyProtocol.szKey, cszTcpIpEntry);
  523. } else if (_tcsnicmp(pAppInfo->piFloppyProtocol.szName, cszNetbeuiKey, lstrlen(cszNetbeuiKey)) == 0) {
  524. AddMessageToExitList (pAppInfo, NCDU_NETBEUI_NOT_ROUT);
  525. lstrcpy(pAppInfo->piFloppyProtocol.szKey, cszNetbeuiEntry);
  526. } else if (_tcsnicmp(pAppInfo->piFloppyProtocol.szName, cszIpxKey, lstrlen(cszIpxKey)) == 0) {
  527. lstrcpy(pAppInfo->piFloppyProtocol.szKey, cszIpxEntry);
  528. } else {
  529. lstrcpy(pAppInfo->piFloppyProtocol.szKey, cszEmptyString);
  530. }
  531. // see if this protocol is supported by the server
  532. bProtocolLoaded = FALSE;
  533. for (pThisNetProtocol = &NetProtocolList[0];
  534. pThisNetProtocol->nDisplayName != 0;
  535. pThisNetProtocol = &pThisNetProtocol[1]) {
  536. // load combo box with "transports"
  537. if (pThisNetProtocol->nListBoxEntry == nComboItem) {
  538. if (pThisNetProtocol->bLoaded) {
  539. bProtocolLoaded = TRUE;
  540. }
  541. }
  542. }
  543. if (!bProtocolLoaded) {
  544. nMbResult = DisplayMessageBox (hwndDlg,
  545. NCDU_UNSUP_PROTOCOL,
  546. 0,
  547. MB_OKCANCEL_TASK_EXCL);
  548. if (nMbResult != IDOK) {
  549. return TRUE;
  550. }
  551. }
  552. //
  553. // Get target drive and path
  554. //
  555. GetDlgItemText (hwndDlg, NCDU_TARGET_DRIVEPATH, pAppInfo->szBootFilesPath, MAX_PATH);
  556. TrimSpaces (pAppInfo->szBootFilesPath);
  557. mtDest = GetDriveTypeFromPath(pAppInfo->szBootFilesPath);
  558. if (mtDest == Unknown) {
  559. nMbResult = DisplayMessageBox (
  560. hwndDlg,
  561. NCDU_NO_MEDIA,
  562. 0,
  563. MB_OKCANCEL_TASK_EXCL);
  564. switch (nMbResult) {
  565. case IDOK:
  566. break;
  567. case IDCANCEL:
  568. // they want to go back to the dialog and insert a disk so bail out
  569. return TRUE;
  570. }
  571. } else if (mtDest != pAppInfo->mtBootDriveType) {
  572. nMbResult = DisplayMessageBox (
  573. hwndDlg,
  574. NCDU_DEST_NOT_FLOPPY,
  575. 0,
  576. MB_OKCANCEL_TASK_EXCL);
  577. switch (nMbResult) {
  578. case IDOK:
  579. break;
  580. case IDCANCEL:
  581. // they want to go back to the dialog so bail out
  582. SetFocus (GetDlgItem(hwndDlg, NCDU_TARGET_DRIVEPATH));
  583. return TRUE;
  584. }
  585. }
  586. if (IsDlgButtonChecked(hwndDlg, NCDU_USE_DHCP) == CHECKED) {
  587. pAppInfo->bUseDhcp = TRUE;
  588. pAppInfo->tiTcpIpInfo.IpAddr[0] = 0;
  589. pAppInfo->tiTcpIpInfo.IpAddr[1] = 0;
  590. pAppInfo->tiTcpIpInfo.IpAddr[2] = 0;
  591. pAppInfo->tiTcpIpInfo.IpAddr[3] = 0;
  592. pAppInfo->tiTcpIpInfo.SubNetMask[0] = 0;
  593. pAppInfo->tiTcpIpInfo.SubNetMask[1] = 0;
  594. pAppInfo->tiTcpIpInfo.SubNetMask[2] = 0;
  595. pAppInfo->tiTcpIpInfo.SubNetMask[3] = 0;
  596. PostMessage (GetParent(hwndDlg), NCDU_SHOW_CONFIRM_DLG, 0, 0);
  597. } else {
  598. pAppInfo->bUseDhcp = FALSE;
  599. GetDlgItemText (hwndDlg, NCDU_FLOPPY_IP_ADDR, szIp, (IP_CHARLIMIT *2));
  600. if (LoadIpAddrArray(szIp, &pAppInfo->tiTcpIpInfo.IpAddr[0])) {
  601. GetDlgItemText (hwndDlg, NCDU_FLOPPY_SUBNET_MASK, szIp, (IP_CHARLIMIT *2));
  602. if (LoadIpAddrArray(szIp, &pAppInfo->tiTcpIpInfo.SubNetMask[0])) {
  603. GetDlgItemText (hwndDlg, NCDU_DEFAULT_GATEWAY, szIp, (IP_CHARLIMIT *2));
  604. if (LoadIpAddrArray(szIp, &pAppInfo->tiTcpIpInfo.DefaultGateway[0])) {
  605. PostMessage (GetParent(hwndDlg), NCDU_SHOW_CONFIRM_DLG, 0, 0);
  606. } else {
  607. // bad Default Gateway
  608. DisplayMessageBox (
  609. hwndDlg,
  610. NCDU_BAD_DEFAULT_GATEWAY,
  611. 0,
  612. MB_OK_TASK_EXCL);
  613. SetFocus (GetDlgItem (hwndDlg, NCDU_DEFAULT_GATEWAY));
  614. SendDlgItemMessage (hwndDlg, NCDU_DEFAULT_GATEWAY, EM_SETSEL, (WPARAM)0, (LPARAM)-1);
  615. }
  616. } else {
  617. // bad Subnet Mask
  618. DisplayMessageBox (
  619. hwndDlg,
  620. NCDU_BAD_SUBNET_MASK,
  621. 0,
  622. MB_OK_TASK_EXCL);
  623. SetFocus (GetDlgItem (hwndDlg, NCDU_FLOPPY_SUBNET_MASK));
  624. SendDlgItemMessage (hwndDlg, NCDU_FLOPPY_SUBNET_MASK, EM_SETSEL, (WPARAM)0, (LPARAM)-1);
  625. }
  626. } else {
  627. // bad IP
  628. DisplayMessageBox (
  629. hwndDlg,
  630. NCDU_BAD_IP_ADDR,
  631. 0,
  632. MB_OK_TASK_EXCL);
  633. SetFocus (GetDlgItem (hwndDlg, NCDU_FLOPPY_IP_ADDR));
  634. SendDlgItemMessage (hwndDlg, NCDU_FLOPPY_IP_ADDR, EM_SETSEL, (WPARAM)0, (LPARAM)-1);
  635. }
  636. }
  637. return FALSE;
  638. }
  639. static
  640. BOOL
  641. ServerConnDlg_WM_COMMAND (
  642. IN HWND hwndDlg,
  643. IN WPARAM wParam,
  644. IN LPARAM lParam
  645. )
  646. /*++
  647. Routine Description:
  648. Dispatches to the correct routine based on the user input.
  649. Enables/disables the TCP/IP address info fields when
  650. the Protocol is changed
  651. Ends the dialog box if Cancel is selected
  652. Dispatches to the IDOK function if OK selected.
  653. Arguments:
  654. IN HWND hwndDlg
  655. Handle to dialog box window
  656. IN WPARAM wParam
  657. LOWORD contains the ID of the control issuing the command
  658. IN LPARAM lParam
  659. Not used
  660. Return Value:
  661. FALSE if processed
  662. TRUE if not processed
  663. --*/
  664. {
  665. switch (LOWORD(wParam)) {
  666. case NCDU_USE_DHCP:
  667. case NCDU_PROTOCOL_COMBO_BOX:
  668. SetTcpIpWindowState (hwndDlg);
  669. return TRUE;
  670. case NCDU_BROWSE:
  671. PostMessage (hwndDlg, NCDU_BROWSE_DEST_PATH, 0, 0);
  672. return TRUE;
  673. case IDCANCEL:
  674. PostMessage (GetParent(hwndDlg), NCDU_SHOW_TARGET_WS_DLG, 0, 0);
  675. return TRUE;
  676. case NCDU_DEFAULT_GATEWAY:
  677. if (HIWORD(wParam) == EN_SETFOCUS) {
  678. ComputeDefaultDefaultGateway (hwndDlg);
  679. return TRUE;
  680. } else {
  681. return FALSE;
  682. }
  683. case IDOK: return ServerConnDlg_IDOK(hwndDlg);
  684. case NCDU_SERVER_CONN_CFG_HELP:
  685. switch (HIWORD(wParam)) {
  686. case BN_CLICKED:
  687. // return ShowAppHelp (hwndDlg, LOWORD(wParam));
  688. return PostMessage (GetParent(hwndDlg), WM_HOTKEY,
  689. (WPARAM)NCDU_HELP_HOT_KEY, 0);
  690. default:
  691. return FALSE;
  692. }
  693. default: return FALSE;
  694. }
  695. }
  696. static
  697. BOOL
  698. ServerConnDlg_NCDU_BROWSE_DEST_PATH (
  699. IN HWND hwndDlg,
  700. IN WPARAM wParam,
  701. IN LPARAM lParam
  702. )
  703. /*++
  704. Routine Description:
  705. Displays the file /dir browser to enter the destination path entry
  706. Arguments:
  707. IN HWND hwndDlg
  708. Handle to dialog box window
  709. IN WPARAM wParam
  710. Not Used
  711. IN LPARAM lParam
  712. Not Used
  713. Return Value:
  714. FALSE
  715. --*/
  716. {
  717. DB_DATA BrowseInfo;
  718. TCHAR szTempPath[MAX_PATH+1];
  719. GetDlgItemText (hwndDlg, NCDU_TARGET_DRIVEPATH, szTempPath, MAX_PATH);
  720. BrowseInfo.dwTitle = NCDU_BROWSE_COPY_DEST_PATH;
  721. BrowseInfo.szPath = szTempPath;
  722. BrowseInfo.Flags = PDB_FLAGS_NOCHECKDIR;
  723. if (DialogBoxParam (
  724. (HINSTANCE)GetWindowLongPtr(hwndDlg, GWLP_HINSTANCE),
  725. MAKEINTRESOURCE(NCDU_DIR_BROWSER),
  726. hwndDlg,
  727. DirBrowseDlgProc,
  728. (LPARAM)&BrowseInfo) == IDOK) {
  729. SetDlgItemText (hwndDlg, NCDU_TARGET_DRIVEPATH, szTempPath);
  730. }
  731. SetFocus( GetDlgItem(hwndDlg, NCDU_TARGET_DRIVEPATH));
  732. return TRUE;
  733. }
  734. static
  735. BOOL
  736. ServerConnDlg_NCDU_WM_NCDESTROY (
  737. IN HWND hwndDlg,
  738. IN WPARAM wParam,
  739. IN LPARAM lParam
  740. )
  741. {
  742. return TRUE;
  743. }
  744. INT_PTR CALLBACK
  745. ServerConnDlgProc (
  746. IN HWND hwndDlg,
  747. IN UINT message,
  748. IN WPARAM wParam,
  749. IN LPARAM lParam
  750. )
  751. /*++
  752. Routine Description:
  753. Dialog box procedure for the Server connection configuration dialog
  754. box. The following windows messages are processed by this
  755. function:
  756. WM_INITDIALOG: Dialog box initialization
  757. WM_COMMAND: user input
  758. WM_NCDESTROY: to free memory before leaving
  759. all other messages are sent to the default dialog box proc.
  760. Arguments:
  761. Standard WNDPROC arguments
  762. Return Value:
  763. FALSE if message not processed by this module, otherwise the
  764. value returned by the dispatched routine.
  765. --*/
  766. {
  767. switch (message) {
  768. case WM_INITDIALOG: return (ServerConnDlg_WM_INITDIALOG (hwndDlg, wParam, lParam));
  769. case WM_COMMAND: return (ServerConnDlg_WM_COMMAND (hwndDlg, wParam, lParam));
  770. case NCDU_BROWSE_DEST_PATH:
  771. return (ServerConnDlg_NCDU_BROWSE_DEST_PATH (hwndDlg, wParam, lParam));
  772. case WM_PAINT: return (Dlg_WM_PAINT (hwndDlg, wParam, lParam));
  773. case WM_MOVE: return (Dlg_WM_MOVE (hwndDlg, wParam, lParam));
  774. case WM_SYSCOMMAND: return (Dlg_WM_SYSCOMMAND (hwndDlg, wParam, lParam));
  775. case WM_NCDESTROY: return (ServerConnDlg_NCDU_WM_NCDESTROY (hwndDlg, wParam, lParam));
  776. default: return FALSE;
  777. }
  778. }