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.

1155 lines
34 KiB

  1. /*
  2. +-------------------------------------------------------------------------+
  3. | Server Browsing Dialog Routines |
  4. +-------------------------------------------------------------------------+
  5. | (c) Copyright 1993-1994 |
  6. | Microsoft Corp. |
  7. | All rights reserved |
  8. | |
  9. | Program : [sbrowse.c] |
  10. | Programmer : Arthur Hanson |
  11. | Original Program Date : [Dec 01, 1993] |
  12. | Last Update : [Jun 16, 1994] |
  13. | |
  14. | Version: 1.00 |
  15. | |
  16. | Description: |
  17. | |
  18. | History: |
  19. | arth Jun 16, 1994 1.00 Original Version. |
  20. | |
  21. +-------------------------------------------------------------------------+
  22. */
  23. #include "globals.h"
  24. #include <math.h>
  25. #include "nwconv.h"
  26. #include "hierdraw.h"
  27. #include "convapi.h"
  28. #include "ntnetapi.h"
  29. #include "nwnetapi.h"
  30. #define SERVER_TYPE_NT 0
  31. #define SERVER_TYPE_NW 1
  32. extern BOOL IsNetWareBrowse;
  33. static int BrowseType;
  34. TCHAR NetProvider[30];
  35. // Internal defines
  36. VOID DlgServSel_OnDrawItem(HWND hwnd, DRAWITEMSTRUCT FAR* lpDrawItem);
  37. BOOL DlgServSel_OnCommand(HWND hDlg, WPARAM wParam, LPARAM lParam);
  38. VOID DlgServSel_ActionItem(HWND hWndList, DWORD_PTR dwData, WORD wItemNum);
  39. LRESULT CALLBACK DlgServSel(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  40. BOOL EnumServs(HWND hDlg);
  41. #define ROWS 2
  42. #define COLS 3
  43. HEIRDRAWSTRUCT HierDrawStruct;
  44. static HWND hEdit;
  45. static HWND hParent;
  46. static SERVER_BROWSE_LIST *ServList = NULL;
  47. static TCHAR SourceServer[256];
  48. static TCHAR DestServer[256];
  49. static DEST_SERVER_BUFFER *DServ = NULL;
  50. static SOURCE_SERVER_BUFFER *SServ = NULL;
  51. BOOL DlgOk;
  52. /*+-------------------------------------------------------------------------+
  53. | BrowseListCompare()
  54. |
  55. +-------------------------------------------------------------------------+*/
  56. int __cdecl BrowseListCompare(const void *arg1, const void *arg2) {
  57. SERVER_BROWSE_BUFFER *SLarg1, *SLarg2;
  58. SLarg1 = (SERVER_BROWSE_BUFFER *) arg1;
  59. SLarg2 = (SERVER_BROWSE_BUFFER *) arg2;
  60. // This works as the first item of the structure is the string
  61. return lstrcmpi( SLarg1->Name, SLarg2->Name);
  62. } // BrowseListCompare
  63. /*+-------------------------------------------------------------------------+
  64. | BrowseListInit()
  65. |
  66. +-------------------------------------------------------------------------+*/
  67. void BrowseListInit(HWND hDlg, int ServerType) {
  68. SERVER_BROWSE_BUFFER *SList;
  69. DWORD Status;
  70. DWORD Count;
  71. DWORD Index;
  72. DWORD i;
  73. HWND hCtrl;
  74. switch (BrowseType) {
  75. case BROWSE_TYPE_NT:
  76. Status = NTServerEnum(NULL, &ServList);
  77. break;
  78. case BROWSE_TYPE_NW:
  79. Status = NWServerEnum(NULL, &ServList);
  80. break;
  81. }
  82. if (ServList) {
  83. Count = ServList->Count;
  84. SList = ServList->SList;
  85. // Sort the server list before putting it in the dialog
  86. qsort((void *) SList, (size_t) Count, sizeof(SERVER_BROWSE_BUFFER), BrowseListCompare);
  87. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  88. for (i = 0; i < Count; i++) {
  89. Index = i;
  90. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) Index);
  91. }
  92. }
  93. } // BrowseListInit
  94. /*+-------------------------------------------------------------------------+
  95. | BrowseListFree()
  96. |
  97. +-------------------------------------------------------------------------+*/
  98. void BrowseListFree(SERVER_BROWSE_LIST *ServList) {
  99. DWORD i;
  100. DWORD Count;
  101. SERVER_BROWSE_BUFFER *SList;
  102. if (!ServList)
  103. return;
  104. SList = ServList->SList;
  105. Count = ServList->Count;
  106. for (i = 0; i < Count; i++)
  107. if (SList[i].child)
  108. FreeMemory((LPBYTE) SList[i].child);
  109. FreeMemory((LPBYTE) ServList);
  110. ServList = NULL;
  111. } // BrowseListFree
  112. /*+-------------------------------------------------------------------------+
  113. | DlgServSel_Do()
  114. |
  115. +-------------------------------------------------------------------------+*/
  116. int DlgServSel_Do(int BType, HWND hwndOwner) {
  117. int result;
  118. DLGPROC lpfndp;
  119. BrowseType = BType;
  120. // Init the Hier Draw stuff - Need to do this here so we have a value
  121. // for WM_MEASUREITEM which is sent before the WM_INITDIALOG message
  122. HierDraw_DrawInit(hInst, IDR_LISTICONS, ROWS, COLS, FALSE, &HierDrawStruct, TRUE );
  123. lpfndp = (DLGPROC)MakeProcInstance((FARPROC)DlgServSel, hInst);
  124. result = (int) DialogBox(hInst, TEXT("DlgServSel"), hwndOwner, lpfndp) ;
  125. FreeProcInstance((FARPROC)lpfndp);
  126. HierDraw_DrawTerm(&HierDrawStruct);
  127. return result;
  128. } // DlgServSel_Do
  129. /*+-------------------------------------------------------------------------+
  130. | BrowseListFind()
  131. |
  132. +-------------------------------------------------------------------------+*/
  133. SERVER_BROWSE_BUFFER *BrowseListFind(DWORD_PTR dwData) {
  134. DWORD ContainerNum;
  135. DWORD Index = 0;
  136. SERVER_BROWSE_LIST *ServerSubList;
  137. Index = LOWORD(dwData);
  138. ContainerNum = HIWORD(dwData);
  139. if (!ContainerNum)
  140. return(&ServList->SList[Index]);
  141. else {
  142. ContainerNum--; // Adjust for 0 index
  143. ServerSubList = (SERVER_BROWSE_LIST *) ServList->SList[ContainerNum].child;
  144. return(&ServerSubList->SList[Index]);
  145. }
  146. } // BrowseListFind
  147. /*+-------------------------------------------------------------------------+
  148. | DlgServSel_OnDrawItem()
  149. |
  150. +-------------------------------------------------------------------------+*/
  151. VOID DlgServSel_OnDrawItem(HWND hwnd, DRAWITEMSTRUCT FAR* lpDrawItem) {
  152. TCHAR szText[MAX_PATH + 1];
  153. DWORD_PTR dwData;
  154. int nLevel = 0;
  155. int nRow = 0;
  156. int nColumn = 0;
  157. DWORD dwConnectLevel = 0;
  158. SERVER_BROWSE_BUFFER *SList;
  159. // if there is nothing to browse then don't need to draw anything.
  160. if (ServList == NULL)
  161. return;
  162. dwData = lpDrawItem->itemData;
  163. SList = BrowseListFind(dwData);
  164. // if there is a double back-slash then trim it off...
  165. if ((SList->Name[0] == TEXT('\\')) && (SList->Name[1] == TEXT('\\')))
  166. lstrcpy(szText, &(SList->Name[2]));
  167. else
  168. lstrcpy(szText, SList->Name);
  169. // Select the correct icon, open folder, closed folder, or document.
  170. switch(BrowseType) {
  171. case BROWSE_TYPE_NT:
  172. break;
  173. case BROWSE_TYPE_NW:
  174. nRow = 1;
  175. break;
  176. }
  177. // Can this item be opened ?
  178. if (SList->Container) {
  179. // Is it open ?
  180. if ( HierDraw_IsOpened(&HierDrawStruct, dwData) )
  181. nColumn = 1;
  182. else
  183. nColumn = 0;
  184. }
  185. else {
  186. if (!IsNetWareBrowse)
  187. nLevel = 1;
  188. nColumn = 2;
  189. }
  190. // All set to call drawing function.
  191. HierDraw_OnDrawItem(hwnd, lpDrawItem, nLevel, dwConnectLevel, szText, nRow, nColumn, &HierDrawStruct);
  192. return;
  193. } // DlgServSel_OnDrawItem
  194. /*+-------------------------------------------------------------------------+
  195. | DlgServSel_OnCommand()
  196. |
  197. +-------------------------------------------------------------------------+*/
  198. BOOL DlgServSel_OnCommand(HWND hDlg, WPARAM wParam, LPARAM lParam) {
  199. int wmId, wmEvent;
  200. WORD wItemNum;
  201. DWORD_PTR dwData;
  202. HWND hCtrl;
  203. TCHAR ServerName[MAX_NW_OBJECT_NAME_LEN + 1];
  204. HWND hParent;
  205. SERVER_BROWSE_BUFFER *SList;
  206. wmId = LOWORD(wParam);
  207. wmEvent = HIWORD(wParam);
  208. switch (wmId) {
  209. case IDOK:
  210. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  211. wItemNum = (WORD) SendMessage(hCtrl, LB_GETCURSEL, 0, 0L);
  212. if (wItemNum != (WORD) LB_ERR) {
  213. dwData = (DWORD) SendMessage(hCtrl, LB_GETITEMDATA, wItemNum, 0L);
  214. if (dwData != LB_ERR)
  215. DlgServSel_ActionItem(hCtrl, dwData, (WORD) wItemNum);
  216. }
  217. break;
  218. case IDC_ALTOK:
  219. hCtrl = GetDlgItem(hDlg, IDC_EDIT1);
  220. * (WORD *)ServerName = sizeof(ServerName);
  221. SendMessage(hCtrl, EM_GETLINE, 0, (LPARAM) ServerName);
  222. CanonServerName((LPTSTR) ServerName);
  223. hParent = GetWindow (hDlg, GW_OWNER);
  224. if (IsNetWareBrowse)
  225. hCtrl = GetDlgItem(hParent, IDC_EDITNWSERV);
  226. else
  227. hCtrl = GetDlgItem(hParent, IDC_EDITNTSERV);
  228. SendMessage(hCtrl, WM_SETTEXT, (WPARAM) 0, (LPARAM) ServerName);
  229. EndDialog(hDlg, 0);
  230. break;
  231. case ID_INIT:
  232. SetFocus(GetDlgItem(hDlg, IDC_EDIT1));
  233. break;
  234. case IDCANCEL:
  235. EndDialog(hDlg, 0);
  236. break;
  237. case IDHELP:
  238. switch (BrowseType) {
  239. case BROWSE_TYPE_NT:
  240. WinHelp(hDlg, HELP_FILE, HELP_CONTEXT, (DWORD) IDC_HELP_BROWSENT);
  241. break;
  242. case BROWSE_TYPE_NW:
  243. WinHelp(hDlg, HELP_FILE, HELP_CONTEXT, (DWORD) IDC_HELP_BROWSENW);
  244. break;
  245. }
  246. break;
  247. case IDC_CHKUSERS:
  248. break;
  249. case IDC_LOADNWSERV:
  250. BrowseListInit(hDlg, SERVER_TYPE_NW);
  251. break;
  252. case IDC_LOADNTSERV:
  253. BrowseListInit(hDlg, SERVER_TYPE_NT);
  254. break;
  255. case IDC_LOADDOMAIN:
  256. BrowseListInit(hDlg, SERVER_TYPE_NT);
  257. break;
  258. case ID_SETSEL:
  259. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  260. wItemNum = (WORD) SendMessage(hCtrl, LB_GETCURSEL, 0, 0L);
  261. if (wItemNum != (WORD) LB_ERR) {
  262. dwData = (DWORD) SendMessage(hCtrl, LB_GETITEMDATA, wItemNum, 0L);
  263. if (dwData != LB_ERR) {
  264. SList = BrowseListFind(dwData);
  265. // Is this an item or folder
  266. if (!SList->Container) {
  267. // is a server - so put it up in edit box
  268. if (SList->Name[0] == TEXT('\\') && SList->Name[1] == TEXT('\\'))
  269. SendMessage(hEdit, WM_SETTEXT, (WPARAM) 0, (LPARAM) &SList->Name[2]);
  270. else
  271. SendMessage(hEdit, WM_SETTEXT, (WPARAM) 0, (LPARAM) SList->Name);
  272. hCtrl = GetDlgItem(hDlg, IDC_ALTOK);
  273. EnableWindow(hCtrl, TRUE);
  274. } else {
  275. SendMessage(hEdit, WM_SETTEXT, (WPARAM) 0, (LPARAM) TEXT(""));
  276. hCtrl = GetDlgItem(hDlg, IDC_ALTOK);
  277. EnableWindow(hCtrl, FALSE);
  278. }
  279. }
  280. }
  281. break;
  282. case IDC_LIST1:
  283. switch (wmEvent) {
  284. case LBN_DBLCLK:
  285. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  286. wItemNum = (WORD) SendMessage(hCtrl, LB_GETCURSEL, 0, 0L);
  287. if (wItemNum != (WORD) LB_ERR) {
  288. dwData = (DWORD) SendMessage(hCtrl, LB_GETITEMDATA, wItemNum, 0L);
  289. if (dwData != LB_ERR)
  290. DlgServSel_ActionItem(hCtrl, dwData, wItemNum);
  291. }
  292. break;
  293. case LBN_SELCHANGE:
  294. PostMessage(hDlg, WM_COMMAND, (WPARAM) ID_SETSEL, 0L);
  295. break;
  296. }
  297. break;
  298. case IDC_EDIT1:
  299. if (wmEvent == EN_CHANGE) {
  300. hCtrl = GetDlgItem(hDlg, IDC_EDIT1);
  301. if (SendMessage(hCtrl, EM_LINELENGTH, 0, 0)) {
  302. hCtrl = GetDlgItem(hDlg, IDC_ALTOK);
  303. EnableWindow(hCtrl, TRUE);
  304. } else {
  305. hCtrl = GetDlgItem(hDlg, IDC_ALTOK);
  306. EnableWindow(hCtrl, FALSE);
  307. }
  308. }
  309. break;
  310. default:
  311. return FALSE;
  312. }
  313. return TRUE;
  314. } // DlgServSel_OnCommand
  315. /*+-------------------------------------------------------------------------+
  316. | DlgServSel_ActionItem()
  317. |
  318. +-------------------------------------------------------------------------+*/
  319. VOID DlgServSel_ActionItem(HWND hWndList, DWORD_PTR dwData, WORD wItemNum) {
  320. DWORD_PTR dwIncr;
  321. DWORD Parent;
  322. DWORD Status;
  323. DWORD Count;
  324. SERVER_BROWSE_BUFFER *SList;
  325. SERVER_BROWSE_LIST *SubList;
  326. DWORD wItem, wCount, dwAddItem;
  327. if (dwData == LB_ERR)
  328. return;
  329. SList = BrowseListFind(dwData);
  330. // Is this an item or folder
  331. if (!SList->Container) {
  332. // is a server - so put it up in edit box
  333. if (SList->Name[0] == TEXT('\\') && SList->Name[1] == TEXT('\\'))
  334. SendMessage(hEdit, WM_SETTEXT, (WPARAM) 0, (LPARAM) &SList->Name[2]);
  335. else
  336. SendMessage(hEdit, WM_SETTEXT, (WPARAM) 0, (LPARAM) SList->Name);
  337. PostMessage(hParent, WM_COMMAND, (WPARAM) IDC_ALTOK, (LPARAM) 0);
  338. }
  339. else {
  340. SendMessage(hEdit, WM_SETTEXT, (WPARAM) 0, (LPARAM) TEXT(""));
  341. // Is it open ?
  342. if ( HierDraw_IsOpened(&HierDrawStruct, dwData) ) {
  343. // It's open ... Close it
  344. HierDraw_CloseItem(&HierDrawStruct, dwData);
  345. // Remove the child items. Close any children that are
  346. // open on the way.
  347. // wItem can stay constant as we are moveing stuff up in the listbox as we
  348. // are deleting.
  349. wItemNum++;
  350. dwIncr = SendMessage(hWndList, LB_GETITEMDATA, wItemNum, 0L);
  351. SList = BrowseListFind(dwIncr);
  352. while (!SList->Container) {
  353. SendMessage(hWndList, LB_DELETESTRING, wItemNum, 0L);
  354. dwIncr = SendMessage(hWndList, LB_GETITEMDATA, wItemNum, 0L);
  355. SList = BrowseListFind(dwIncr);
  356. }
  357. Parent = HIWORD(dwIncr);
  358. if (Parent) {
  359. Parent--;
  360. SList = BrowseListFind(Parent);
  361. FreeMemory((LPBYTE) SList->child);
  362. SList->child = NULL;
  363. }
  364. }
  365. else {
  366. // It's closed ... Open it
  367. HierDraw_OpenItem(&HierDrawStruct, dwData);
  368. SendMessage(hWndList, WM_SETREDRAW, FALSE, 0L); // Disable redrawing.
  369. CursorHourGlass();
  370. // Enumerate the servers in this container (domain)
  371. Status = NTServerEnum(SList->Name, (SERVER_BROWSE_LIST **) &SList->child);
  372. if (!Status) {
  373. Parent = LOWORD(dwData);
  374. SubList = (SERVER_BROWSE_LIST *) SList->child;
  375. Count = SubList->Count;
  376. SList = SubList->SList;
  377. // Sort the server list before putting it in the dialog
  378. qsort((void *) SList, (size_t) Count, sizeof(SERVER_BROWSE_BUFFER), BrowseListCompare);
  379. for (wItem = wItemNum, wCount = 0, wItem++;
  380. wCount < SubList->Count; wItem++, wCount++) {
  381. dwAddItem = ((Parent + 1) << 16) + wCount;
  382. SendMessage(hWndList, LB_INSERTSTRING, wItem, dwAddItem);
  383. }
  384. }
  385. // Make sure as many child items as possible are showing
  386. HierDraw_ShowKids(&HierDrawStruct, hWndList, (WORD) wItemNum, (WORD) SubList->Count );
  387. CursorNormal();
  388. SendMessage(hWndList, WM_SETREDRAW, TRUE, 0L); // Enable redrawing.
  389. InvalidateRect(hWndList, NULL, TRUE); // Force redraw
  390. }
  391. }
  392. } // DlgServSel_ActionItem
  393. /*+-------------------------------------------------------------------------+
  394. | ServerListScan()
  395. |
  396. | Given a key, scans the list of servers to find a matching first
  397. | letter in the server name.
  398. |
  399. +-------------------------------------------------------------------------+*/
  400. WORD ServerListScan(HWND hWnd, DWORD dwData, TCHAR Key) {
  401. BOOL Found = FALSE;
  402. WORD wItemNum;
  403. DWORD dwFindItem;
  404. DWORD dwData2;
  405. DWORD ContainerNum;
  406. WORD Index = 0;
  407. DWORD Count = 0;
  408. SERVER_BROWSE_LIST *ptrServList;
  409. SERVER_BROWSE_BUFFER *SList;
  410. Index = LOWORD(dwData);
  411. ContainerNum = HIWORD(dwData);
  412. // Get the head of the Server list for the current item
  413. if (!ContainerNum)
  414. ptrServList = ServList;
  415. else {
  416. ptrServList = (SERVER_BROWSE_LIST *) ServList->SList[ContainerNum-1].child;
  417. }
  418. // Now iterate down through the list trying to find the key...
  419. SList = ptrServList->SList;
  420. while ((!Found) && (Count < ptrServList->Count)) {
  421. if (SList[Count].Name[0] == Key) {
  422. dwFindItem = Count;
  423. Found = TRUE;
  424. } else
  425. Count++;
  426. }
  427. // If we found the key now have to find the appropriate index value
  428. if (Found && (Index != Count)) {
  429. // Fix up the new item data to find
  430. if (ContainerNum)
  431. dwFindItem += (ContainerNum << 16);
  432. wItemNum = (WORD) SendMessage(hWnd, LB_GETCURSEL, 0, 0L);
  433. Found = FALSE;
  434. if (Index < Count) {
  435. // search forward in list
  436. dwData2 = 0;
  437. while ((dwData2 != LB_ERR) && !Found) {
  438. dwData2 = (DWORD) SendMessage(hWnd, LB_GETITEMDATA, wItemNum, 0L);
  439. if (dwData2 == dwFindItem)
  440. Found = TRUE;
  441. else
  442. wItemNum++;
  443. }
  444. } else {
  445. // search backwards in list
  446. Count = Index;
  447. while ((wItemNum > 0) && !Found) {
  448. wItemNum--;
  449. dwData2 = (DWORD) SendMessage(hWnd, LB_GETITEMDATA, wItemNum, 0L);
  450. Count--;
  451. if (dwData2 == dwFindItem)
  452. Found = TRUE;
  453. }
  454. }
  455. } else
  456. return (Index);
  457. if (Found)
  458. return(wItemNum);
  459. else
  460. return (Index);
  461. } // ServerListScan
  462. static WNDPROC _wpOrigWndProc;
  463. #define LISTBOX_COUNT 13
  464. /*+-------------------------------------------------------------------------+
  465. | ListSubClassProc()
  466. |
  467. | Handles key processing for the hierarchical listbox. Specifically
  468. | the up/down arrow keys and the letter keys.
  469. |
  470. +-------------------------------------------------------------------------+*/
  471. LRESULT CALLBACK ListSubClassProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
  472. LRESULT lResult = 0;
  473. BOOL fCallOrigProc = TRUE;
  474. DWORD wItemNum;
  475. DWORD wNewNum;
  476. DWORD dwData;
  477. switch (message) {
  478. case WM_KEYDOWN:
  479. wItemNum = (DWORD) SendMessage(hWnd, LB_GETCURSEL, 0, 0L);
  480. if (wItemNum != (DWORD) LB_ERR)
  481. dwData = (DWORD) SendMessage(hWnd, LB_GETITEMDATA, (WPARAM) wItemNum, 0L);
  482. else {
  483. wItemNum = 0;
  484. SendMessage(hWnd, LB_SETCURSEL, (WPARAM) 0, 0L);
  485. dwData = (DWORD) SendMessage(hWnd, LB_GETITEMDATA, (WPARAM) wItemNum, 0L);
  486. if ((dwData == LB_ERR) || (dwData == LB_ERR))
  487. break;
  488. }
  489. fCallOrigProc = FALSE;
  490. switch (LOWORD(wParam)) {
  491. case VK_PRIOR:
  492. if (wItemNum > LISTBOX_COUNT)
  493. wNewNum = wItemNum - LISTBOX_COUNT;
  494. else
  495. wNewNum = 0;
  496. PostMessage(hWnd, LB_SETCURSEL, (WPARAM) wNewNum, 0L);
  497. PostMessage(hParent, WM_COMMAND, (WPARAM) ID_SETSEL, 0L);
  498. break;
  499. case VK_NEXT:
  500. wItemNum = wItemNum + LISTBOX_COUNT;
  501. wNewNum = (WORD) SendMessage(hWnd, LB_GETCOUNT, (WPARAM) 0, 0L);
  502. if (wItemNum < wNewNum)
  503. PostMessage(hWnd, LB_SETCURSEL, (WPARAM) wItemNum, 0L);
  504. else
  505. PostMessage(hWnd, LB_SETCURSEL, (WPARAM) (wNewNum - 1), 0L);
  506. PostMessage(hParent, WM_COMMAND, (WPARAM) ID_SETSEL, 0L);
  507. break;
  508. case VK_END:
  509. wItemNum = (WORD) SendMessage(hWnd, LB_GETCOUNT, (WPARAM) 0, 0L);
  510. if (wItemNum != LB_ERR)
  511. PostMessage(hWnd, LB_SETCURSEL, (WPARAM) (wItemNum - 1), 0L);
  512. PostMessage(hParent, WM_COMMAND, (WPARAM) ID_SETSEL, 0L);
  513. break;
  514. case VK_HOME:
  515. PostMessage(hWnd, LB_SETCURSEL, (WPARAM) 0, 0L);
  516. PostMessage(hParent, WM_COMMAND, (WPARAM) ID_SETSEL, 0L);
  517. break;
  518. case VK_UP:
  519. if (wItemNum > 0) {
  520. wItemNum--;
  521. PostMessage(hWnd, LB_SETCURSEL, (WPARAM) wItemNum, 0L);
  522. }
  523. PostMessage(hParent, WM_COMMAND, (WPARAM) ID_SETSEL, 0L);
  524. break;
  525. case VK_DOWN:
  526. wItemNum++;
  527. PostMessage(hWnd, LB_SETCURSEL, (WPARAM) wItemNum, 0L);
  528. PostMessage(hParent, WM_COMMAND, (WPARAM) ID_SETSEL, 0L);
  529. break;
  530. case VK_F1:
  531. fCallOrigProc = TRUE;
  532. break;
  533. default:
  534. wItemNum = ServerListScan(hWnd, dwData, (TCHAR) wParam);
  535. PostMessage(hWnd, LB_SETCURSEL, (WPARAM) wItemNum, 0L);
  536. PostMessage(hParent, WM_COMMAND, (WPARAM) ID_SETSEL, 0L);
  537. break;
  538. }
  539. break;
  540. }
  541. if (fCallOrigProc)
  542. lResult = CallWindowProc(_wpOrigWndProc, hWnd, message, wParam, lParam);
  543. return (lResult);
  544. } // ListSubClassProc
  545. /*+-------------------------------------------------------------------------+
  546. | DlgServSel()
  547. |
  548. +-------------------------------------------------------------------------+*/
  549. LRESULT CALLBACK DlgServSel(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
  550. HWND hCtrl;
  551. switch (message) {
  552. case WM_INITDIALOG:
  553. // Center the dialog over the application window
  554. CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
  555. hParent = hDlg;
  556. // Disable the Add button until server is selected
  557. hCtrl = GetDlgItem(hDlg, IDC_ALTOK);
  558. EnableWindow(hCtrl, FALSE);
  559. // subclass listbox handler
  560. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  561. _wpOrigWndProc = SubclassWindow(hCtrl, ListSubClassProc);
  562. switch (BrowseType) {
  563. case BROWSE_TYPE_NT:
  564. PostMessage(hDlg, WM_COMMAND, IDC_LOADNTSERV, 0);
  565. lstrcpy( NetProvider, NT_PROVIDER);
  566. hCtrl = GetDlgItem(hDlg, IDC_EDIT1);
  567. PostMessage(hCtrl, EM_LIMITTEXT, (WPARAM) MAX_NT_SERVER_NAME_LEN, 0);
  568. break;
  569. case BROWSE_TYPE_NW:
  570. lstrcpy( NetProvider, NW_PROVIDER);
  571. SetWindowText(hDlg, Lids(IDS_S_35));
  572. PostMessage(hDlg, WM_COMMAND, IDC_LOADNWSERV, 0);
  573. hCtrl = GetDlgItem(hDlg, IDC_EDIT1);
  574. PostMessage(hCtrl, EM_LIMITTEXT, (WPARAM) MAX_NW_OBJECT_NAME_LEN, 0);
  575. break;
  576. }
  577. hEdit = GetDlgItem(hDlg, IDC_EDIT1);
  578. PostMessage(hDlg, WM_COMMAND, ID_INIT, 0);
  579. return (TRUE);
  580. case WM_DESTROY:
  581. BrowseListFree(ServList);
  582. break;
  583. case WM_SETFONT:
  584. // Set the text height
  585. HierDraw_DrawSetTextHeight(GetDlgItem(hDlg, IDC_LIST1), (HFONT)wParam, &HierDrawStruct);
  586. break;
  587. case WM_COMMAND:
  588. return DlgServSel_OnCommand(hDlg, wParam, lParam);
  589. case WM_DRAWITEM:
  590. DlgServSel_OnDrawItem(hDlg, (DRAWITEMSTRUCT FAR*)(lParam));
  591. return TRUE;
  592. break;
  593. case WM_MEASUREITEM:
  594. HierDraw_OnMeasureItem(hDlg, (MEASUREITEMSTRUCT FAR*)(lParam), &HierDrawStruct);
  595. return TRUE;
  596. break;
  597. }
  598. return (FALSE);
  599. lParam;
  600. } // DlgServSel
  601. /*+-------------------------------------------------------------------------+
  602. | DlgGetServ_OnInitDialog()
  603. |
  604. +-------------------------------------------------------------------------+*/
  605. BOOL DlgGetServ_OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lParam) {
  606. HWND hCtrl;
  607. // Center the dialog over the application window
  608. CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
  609. // Disable the Add button until both servers are selected
  610. hCtrl = GetDlgItem(hDlg, IDOK);
  611. EnableWindow(hCtrl, FALSE);
  612. hCtrl = GetDlgItem(hDlg, IDC_EDITNWSERV);
  613. PostMessage(hCtrl, EM_LIMITTEXT, (WPARAM) MAX_NW_OBJECT_NAME_LEN, 0);
  614. hCtrl = GetDlgItem(hDlg, IDC_EDITNTSERV);
  615. PostMessage(hCtrl, EM_LIMITTEXT, (WPARAM) MAX_NT_SERVER_NAME_LEN, 0);
  616. PostMessage(hDlg, WM_COMMAND, ID_INIT, 0);
  617. return (TRUE);
  618. } // DlgGetServ_OnInitDialog
  619. /*+-------------------------------------------------------------------------+
  620. | MapShare()
  621. |
  622. +-------------------------------------------------------------------------+*/
  623. // CODEWORK: This routine can be condensed - all the virtual add share stuff
  624. // can be compacted to a subroutine
  625. BOOL MapShare(SHARE_BUFFER *Share, DEST_SERVER_BUFFER *DServ) {
  626. static TCHAR Path[MAX_PATH + 1];
  627. SHARE_LIST *ShareList;
  628. SHARE_BUFFER *SList;
  629. SHARE_BUFFER *MatchShare;
  630. VIRTUAL_SHARE_BUFFER *VShare;
  631. DRIVE_BUFFER *DList;
  632. DRIVE_BUFFER *MaxNTFS = NULL;
  633. DRIVE_BUFFER *MaxFAT = NULL;
  634. BOOL Match = FALSE;
  635. BOOL NTFS = FALSE;
  636. BOOL Virtual = FALSE;
  637. DWORD i;
  638. // First see if there is a 1:1 share correspondence already in existance
  639. // the normal shares first...
  640. ShareList = DServ->ShareList;
  641. SList = ShareList->SList;
  642. if (ShareList != NULL)
  643. for (i = 0; ((i < ShareList->Count) && (!Match)); i++) {
  644. if (!lstrcmpi(SList[i].Name, Share->Name)) {
  645. MatchShare = &SList[i];
  646. Match = TRUE;
  647. }
  648. } // match normal share 1:1
  649. if (!Match) {
  650. VShare = DServ->VShareStart;
  651. while(VShare && !Match) {
  652. if (!lstrcmpi(VShare->Name, Share->Name)) {
  653. // will use VShare to point to matched share
  654. Virtual = TRUE;
  655. Match = TRUE;
  656. } else
  657. VShare = VShare->next;
  658. }
  659. } // match VShare 1:1
  660. if (!Match) {
  661. // No match so make share name the same - try to find NTFS drive with
  662. // enough room to put it on.
  663. DList = DServ->DriveList->DList;
  664. if (DList != NULL)
  665. for (i = 0; ((i < DServ->DriveList->Count) && (!Match)); i++) {
  666. if (DList[i].Type == DRIVE_TYPE_NTFS) {
  667. // Find our Max NTFS
  668. if (!MaxNTFS)
  669. MaxNTFS = &DList[i];
  670. else
  671. if ( (MaxNTFS->FreeSpace - MaxNTFS->AllocSpace) < (DList[i].FreeSpace - DList[i].AllocSpace) )
  672. MaxNTFS = &DList[i];
  673. // Is an NTFS Drive - check for space
  674. if ((DList[i].FreeSpace - DList[i].AllocSpace) > Share->Size) {
  675. // Checks out - create a new virutal share for this
  676. Match = TRUE;
  677. Virtual = TRUE;
  678. wsprintf(Path, TEXT("%s:\\%s"), DList[i].Drive, Share->Name);
  679. VShare = VShareListAdd(DServ, Share->Name, Path);
  680. VShare->Drive = &DList[i];
  681. }
  682. }
  683. }
  684. } // match new NTFS share
  685. if (!Match) {
  686. // No NTFS drive so try other drives...
  687. DList = DServ->DriveList->DList;
  688. if (DList != NULL)
  689. for (i = 0; ((i < DServ->DriveList->Count) && (!Match)); i++) {
  690. if (DList[i].Type != DRIVE_TYPE_NTFS) {
  691. // Find our Max FAT
  692. if (!MaxFAT)
  693. MaxFAT = &DList[i];
  694. else
  695. if ( (MaxFAT->FreeSpace - MaxFAT->AllocSpace) < (DList[i].FreeSpace - DList[i].AllocSpace) )
  696. MaxFAT = &DList[i];
  697. // Is an other Drive - check for space
  698. if ((DList[i].FreeSpace - DList[i].AllocSpace) > Share->Size) {
  699. // Checks out - create a new virutal share for this
  700. Match = TRUE;
  701. Virtual = TRUE;
  702. wsprintf(Path, TEXT("%s:\\%s"), DList[i].Drive, Share->Name);
  703. VShare = VShareListAdd(DServ, Share->Name, Path);
  704. VShare->Drive = &DList[i];
  705. }
  706. }
  707. }
  708. } // match new FAT share
  709. if (!Match) {
  710. // we are going to assign some virtual share for this
  711. Virtual = TRUE;
  712. // use max space for NTFS else FAT
  713. if (MaxNTFS) {
  714. // if also have some fat partitions if they have more space use them
  715. if (!(MaxFAT && ( (MaxNTFS->FreeSpace - MaxNTFS->AllocSpace) < (MaxFAT->FreeSpace - MaxFAT->AllocSpace) ))) {
  716. Match = TRUE;
  717. wsprintf(Path, TEXT("%s:\\%s"), MaxNTFS->Drive, Share->Name);
  718. VShare = VShareListAdd(DServ, Share->Name, Path);
  719. VShare->Drive = MaxNTFS;
  720. }
  721. }
  722. // if we couldn't match with NTFS then use other drive types
  723. if (!Match) {
  724. Match = TRUE;
  725. wsprintf(Path, TEXT("%s:\\%s"), MaxFAT->Drive, Share->Name);
  726. VShare = VShareListAdd(DServ, Share->Name, Path);
  727. VShare->Drive = MaxFAT;
  728. }
  729. } // match anything!!!
  730. if (Match) {
  731. // Have the match so adjust the params
  732. if (!Virtual) {
  733. Share->Virtual = FALSE;
  734. Share->DestShare = MatchShare;
  735. // if there is no drive specified (can be the case if the share points
  736. // to an invalid drive - like a floppy) then we skip out and ignore it
  737. // for right now. We will alert the user when they try to do the
  738. // transfer.
  739. if (MatchShare->Drive == NULL)
  740. return TRUE;
  741. MatchShare->Drive->AllocSpace += Share->Size;
  742. #ifdef DEBUG
  743. dprintf(TEXT("Matched Share: %s -> %s\n"), Share->Name, MatchShare->Name);
  744. #endif
  745. } else {
  746. Share->Virtual = TRUE;
  747. Share->DestShare = (SHARE_BUFFER *) VShare;
  748. VShare->Drive->AllocSpace += Share->Size;
  749. VShare->UseCount++;
  750. #ifdef DEBUG
  751. dprintf(TEXT("Matched Virtual Share: %s -> %s\n"), Share->Name, VShare->Path);
  752. #endif
  753. }
  754. return TRUE;
  755. } else {
  756. #ifdef DEBUG
  757. dprintf(TEXT("Couldn't Map Share: %s\n"), Share->Name);
  758. #endif
  759. // Bad news - the destination server just can't handle this!
  760. return FALSE;
  761. }
  762. } // MapShare
  763. /*+-------------------------------------------------------------------------+
  764. | ShareListInit()
  765. |
  766. +-------------------------------------------------------------------------+*/
  767. void ShareListInit(SHARE_LIST *ShareList, DEST_SERVER_BUFFER *DServ) {
  768. SHARE_BUFFER *SList;
  769. DWORD i;
  770. // Mark that we want to convert all the shares
  771. if (ShareList != NULL) {
  772. SList = ShareList->SList;
  773. ShareList->ConvertCount = ShareList->Count;
  774. for (i = 0; i < ShareList->Count; i++) {
  775. if (MapShare(&SList[i], DServ))
  776. SList[i].Convert = TRUE;
  777. }
  778. }
  779. } // ShareListInit
  780. /*+-------------------------------------------------------------------------+
  781. | DlgGetServ_OnCommand()
  782. |
  783. +-------------------------------------------------------------------------+*/
  784. BOOL DlgGetServ_OnCommand(HWND hDlg, int wmId, HWND hwndCtl, UINT wmEvent) {
  785. HWND hCtrl;
  786. BOOL Enable = FALSE;
  787. switch (wmId) {
  788. case IDOK:
  789. hCtrl = GetDlgItem(hDlg, IDC_EDITNWSERV);
  790. * (WORD *)SourceServer = sizeof(SourceServer);
  791. * (WORD *)DestServer = sizeof(DestServer);
  792. SendMessage(hCtrl, EM_GETLINE, 0, (LPARAM) SourceServer);
  793. hCtrl = GetDlgItem(hDlg, IDC_EDITNTSERV);
  794. SendMessage(hCtrl, EM_GETLINE, 0, (LPARAM) DestServer);
  795. CanonServerName(SourceServer);
  796. CanonServerName(DestServer);
  797. if ( NWServerValidate(hDlg, SourceServer, TRUE) ) {
  798. if ( NTServerValidate(hDlg, DestServer) ) {
  799. // Check if we need to add server to server list
  800. DServ = DServListFind(DestServer);
  801. if (DServ == NULL) {
  802. DServ = DServListAdd(DestServer);
  803. NTServerInfoSet(hDlg, DestServer, DServ);
  804. } else
  805. DServ->UseCount++;
  806. SServ = SServListFind(SourceServer);
  807. if (SServ == NULL) {
  808. SServ = SServListAdd(SourceServer);
  809. NWServerInfoSet(SourceServer, SServ);
  810. ShareListInit(SServ->ShareList, DServ);
  811. }
  812. DlgOk = TRUE;
  813. EndDialog(hDlg, 0);
  814. } else {
  815. // Clean up connections that the Validation routines made
  816. NWUseDel(SourceServer);
  817. NTUseDel(DestServer);
  818. hCtrl = GetDlgItem(hDlg, IDC_EDITNTSERV);
  819. SetFocus(hCtrl);
  820. }
  821. } else {
  822. // Clean up use validation routine made
  823. NWUseDel(SourceServer);
  824. hCtrl = GetDlgItem(hDlg, IDC_EDITNWSERV);
  825. SetFocus(hCtrl);
  826. }
  827. return (TRUE);
  828. case ID_INIT:
  829. SetFocus(GetDlgItem(hDlg, IDC_EDITNWSERV));
  830. break;
  831. case IDCANCEL:
  832. EndDialog(hDlg, 0);
  833. DlgOk = FALSE;
  834. return (TRUE);
  835. break;
  836. case IDHELP:
  837. WinHelp(hDlg, HELP_FILE, HELP_CONTEXT, (DWORD) IDC_HELP_ADD);
  838. return (TRUE);
  839. break;
  840. case IDC_NWBROWSE:
  841. IsNetWareBrowse = TRUE;
  842. DlgServSel_Do(BROWSE_TYPE_NW, hDlg);
  843. return (TRUE);
  844. break;
  845. case IDC_NTBROWSE:
  846. IsNetWareBrowse = FALSE;
  847. DlgServSel_Do(BROWSE_TYPE_NT, hDlg);
  848. return (TRUE);
  849. break;
  850. case IDC_EDITNWSERV:
  851. case IDC_EDITNTSERV:
  852. if (wmEvent == EN_CHANGE) {
  853. hCtrl = GetDlgItem(hDlg, IDC_EDITNWSERV);
  854. if (SendMessage(hCtrl, EM_LINELENGTH, 0, 0)) {
  855. hCtrl = GetDlgItem(hDlg, IDC_EDITNTSERV);
  856. if (SendMessage(hCtrl, EM_LINELENGTH, 0, 0))
  857. Enable = TRUE;
  858. }
  859. hCtrl = GetDlgItem(hDlg, IDOK);
  860. if (Enable)
  861. EnableWindow(hCtrl, TRUE);
  862. else
  863. EnableWindow(hCtrl, FALSE);
  864. }
  865. break;
  866. }
  867. return FALSE;
  868. } // DlgGetServ_OnCommand
  869. /*+-------------------------------------------------------------------------+
  870. | DlgGetServ()
  871. |
  872. +-------------------------------------------------------------------------+*/
  873. LRESULT CALLBACK DlgGetServ(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
  874. switch (msg) {
  875. HANDLE_MSG(hDlg, WM_INITDIALOG, DlgGetServ_OnInitDialog);
  876. HANDLE_MSG(hDlg, WM_COMMAND, DlgGetServ_OnCommand);
  877. }
  878. return (FALSE); // Didn't process the message
  879. lParam;
  880. } // DlgGetServ
  881. /*+-------------------------------------------------------------------------+
  882. | DialogGetServ()
  883. |
  884. +-------------------------------------------------------------------------+*/
  885. DWORD DialogServerBrowse(HINSTANCE hInst, HWND hDlg, SOURCE_SERVER_BUFFER **lpSourceServer, DEST_SERVER_BUFFER **lpDestServer) {
  886. DLGPROC lpfnDlg;
  887. SServListCurrent = NULL;
  888. DServListCurrent = NULL;
  889. SServ = NULL;
  890. DServ = NULL;
  891. lpfnDlg = MakeProcInstance((DLGPROC)DlgGetServ, hInst);
  892. DialogBox(hInst, TEXT("DlgGetServ"), hDlg, lpfnDlg) ;
  893. FreeProcInstance(lpfnDlg);
  894. if (DlgOk) {
  895. *lpSourceServer = SServ;
  896. *lpDestServer = DServ;
  897. return 0;
  898. } else
  899. return 1;
  900. } // DialogServerBrowse