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.

1074 lines
35 KiB

  1. /*
  2. +-------------------------------------------------------------------------+
  3. | File Operations |
  4. +-------------------------------------------------------------------------+
  5. | (c) Copyright 1994 |
  6. | Microsoft Corp. |
  7. | All rights reserved |
  8. | |
  9. | Program : [FileDLG.c] |
  10. | Programmer : Arthur Hanson |
  11. | Original Program Date : [Feb 10, 1994] |
  12. | Last Update : [Jun 16, 1994] |
  13. | |
  14. | Version: 1.00 |
  15. | |
  16. | Description: |
  17. | |
  18. | History: |
  19. | arth Feb 10, 1994 1.00 Original Version. |
  20. | |
  21. +-------------------------------------------------------------------------+
  22. */
  23. #include "globals.h"
  24. #include "convapi.h"
  25. #include "filedlg.h"
  26. #include "ntnetapi.h"
  27. #include "nwnetapi.h"
  28. #include "columnlb.h"
  29. static SOURCE_SERVER_BUFFER *SServ;
  30. static DEST_SERVER_BUFFER *DServ;
  31. static FILE_OPTIONS *FileOptions;
  32. static SHARE_LIST *ShareList;
  33. static SHARE_BUFFER *SList;
  34. static SHARE_BUFFER *CurrentShare;
  35. static SHARE_BUFFER *CurrentDShare;
  36. static int SelectType;
  37. static int NewShareType;
  38. #define SELECT_TYPE_MODIFY 1
  39. #define SELECT_TYPE_ADD 2
  40. static BOOL ConvertFiles = TRUE;
  41. void FileSelect_Do(HWND hDlg, SOURCE_SERVER_BUFFER *SourceServ, SHARE_BUFFER *CShare);
  42. BOOL MapShare(SHARE_BUFFER *Share, DEST_SERVER_BUFFER *DServ);
  43. /*+-------------------------------------------------------------------------+
  44. | FileOptionsDefaultsSet()
  45. |
  46. +-------------------------------------------------------------------------+*/
  47. void FileOptionsDefaultsSet(void *tfo) {
  48. FILE_OPTIONS *fo = tfo;
  49. if (fo->TransferFileInfo)
  50. ConvertFiles = TRUE;
  51. else
  52. ConvertFiles = FALSE;
  53. } // FileOptionsDefaultsSet
  54. /*+-------------------------------------------------------------------------+
  55. | FileOptionsDefaultsReset()
  56. |
  57. +-------------------------------------------------------------------------+*/
  58. void FileOptionsDefaultsReset() {
  59. ConvertFiles = TRUE;
  60. } // FileOptionsDefaultsReset
  61. /*+-------------------------------------------------------------------------+
  62. | FileOptionsInit()
  63. |
  64. +-------------------------------------------------------------------------+*/
  65. void FileOptionsInit(void **lpfo) {
  66. FILE_OPTIONS *fo;
  67. fo = (FILE_OPTIONS *) *lpfo;
  68. // if we need to allocate space, do so
  69. if (fo == NULL)
  70. fo = AllocMemory(sizeof(FILE_OPTIONS));
  71. // make sure it was allocated
  72. if (fo == NULL)
  73. return;
  74. memset(fo, 0, sizeof(FILE_OPTIONS));
  75. fo->TransferFileInfo = ConvertFiles;
  76. *lpfo = (void *) fo;
  77. } // FileOptionsInit
  78. /*+-------------------------------------------------------------------------+
  79. | FileOptionsLoad()
  80. |
  81. +-------------------------------------------------------------------------+*/
  82. void FileOptionsLoad(HANDLE hFile, void **lpfo) {
  83. FILE_OPTIONS *fo;
  84. DWORD wrote;
  85. fo = (FILE_OPTIONS *) *lpfo;
  86. // if we need to allocate space, do so
  87. if (fo == NULL)
  88. fo = AllocMemory(sizeof(FILE_OPTIONS));
  89. // make sure it was allocated
  90. if (fo == NULL)
  91. return;
  92. ReadFile(hFile, fo, sizeof(FILE_OPTIONS), &wrote, NULL);
  93. *lpfo = (void *) fo;
  94. } // FileOptionsLoad
  95. /*+-------------------------------------------------------------------------+
  96. | FileOptionsSave()
  97. |
  98. +-------------------------------------------------------------------------+*/
  99. void FileOptionsSave(HANDLE hFile, void *fo) {
  100. DWORD wrote;
  101. WriteFile(hFile, fo, sizeof(FILE_OPTIONS), &wrote, NULL);
  102. } // FileOptionsSave
  103. /*+-------------------------------------------------------------------------+
  104. | Share Modify/Create Dialog Routines |
  105. +-------------------------------------------------------------------------+*/
  106. /*+-------------------------------------------------------------------------+
  107. | ShareNewPathValidate()
  108. |
  109. +-------------------------------------------------------------------------+*/
  110. BOOL ShareNewPathValidate(HWND hWnd, LPTSTR Path, DRIVE_BUFFER **pDrive) {
  111. VIRTUAL_SHARE_BUFFER *VShare;
  112. DRIVE_BUFFER *DList;
  113. ULONG i;
  114. TCHAR Drive[2];
  115. // must be long enough to hold drive, colon and path
  116. if (lstrlen(Path) < 3)
  117. goto ShareNewValidateFail;
  118. if (Path[1] != TEXT(':'))
  119. goto ShareNewValidateFail;
  120. if (Path[2] != TEXT('\\'))
  121. goto ShareNewValidateFail;
  122. if (DServ->DriveList == NULL)
  123. return FALSE;
  124. // Scan drive list looking for match to share path
  125. Drive[1] = TEXT('\0');
  126. DList = DServ->DriveList->DList;
  127. for (i = 0; i < DServ->DriveList->Count; i++) {
  128. // Get first char from path - should be drive letter
  129. Drive[0] = Path[0];
  130. if (!lstrcmpi(Drive, DList[i].Drive)) {
  131. // Found match
  132. *pDrive = &DList[i];
  133. if (NewShareType == SELECT_TYPE_MODIFY)
  134. if (CurrentDShare->VFlag) {
  135. VShare = (VIRTUAL_SHARE_BUFFER *) CurrentDShare;
  136. VShare->Drive = &DList[i];
  137. } else
  138. CurrentDShare->Drive = &DList[i];
  139. return TRUE;
  140. }
  141. }
  142. ShareNewValidateFail:
  143. MessageBox(hWnd, Lids(IDS_E_3), Lids(IDS_E_2), MB_OK);
  144. return FALSE;
  145. } // ShareNewPathValidate
  146. /*+-------------------------------------------------------------------------+
  147. | ShareNewShareValidate()
  148. |
  149. +-------------------------------------------------------------------------+*/
  150. BOOL ShareNewShareValidate(HWND hWnd, LPTSTR ShareName) {
  151. ULONG i;
  152. VIRTUAL_SHARE_BUFFER *VShare;
  153. SHARE_BUFFER *VList;
  154. // Loop through share list seeing if the share already exists (same name)
  155. if (DServ->ShareList != NULL) {
  156. VList = DServ->ShareList->SList;
  157. for (i = 0; i < DServ->ShareList->Count; i++)
  158. if (!lstrcmpi(VList[i].Name, ShareName))
  159. goto ShareNewShareVFail;
  160. }
  161. // Now do the same for the virtual share list
  162. VShare = DServ->VShareStart;
  163. while (VShare) {
  164. if (!lstrcmpi(VShare->Name, ShareName))
  165. goto ShareNewShareVFail;
  166. VShare = VShare->next;
  167. }
  168. return TRUE;
  169. ShareNewShareVFail:
  170. MessageBox(hWnd, Lids(IDS_E_4), Lids(IDS_E_2), MB_OK);
  171. return FALSE;
  172. } // ShareNewShareValidate
  173. /*+-------------------------------------------------------------------------+
  174. | NWShareNew()
  175. |
  176. +-------------------------------------------------------------------------+*/
  177. LRESULT CALLBACK NWShareNew(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
  178. HWND hCtrl;
  179. BOOL Enable;
  180. int wmId, wmEvent;
  181. TCHAR Path[MAX_PATH + 1];
  182. TCHAR NewShare[MAX_SHARE_NAME_LEN + 1];
  183. VIRTUAL_SHARE_BUFFER *VShare;
  184. DRIVE_BUFFER *Drive;
  185. BOOL ok;
  186. switch (message) {
  187. case WM_INITDIALOG:
  188. // Center the dialog over the application window
  189. CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
  190. hCtrl = GetDlgItem(hDlg, IDC_EDIT1);
  191. PostMessage(hCtrl, EM_LIMITTEXT, (WPARAM) MAX_SHARE_NAME_LEN, 0);
  192. hCtrl = GetDlgItem(hDlg, IDC_EDIT2);
  193. PostMessage(hCtrl, EM_LIMITTEXT, (WPARAM) MAX_PATH, 0);
  194. if (NewShareType == SELECT_TYPE_MODIFY) {
  195. SendMessage(hDlg, WM_SETTEXT, (WPARAM) 0, (LPARAM) Lids(IDS_D_5));
  196. hCtrl = GetDlgItem(hDlg, IDC_EDIT1);
  197. EnableWindow(hCtrl, FALSE);
  198. ShowWindow(hCtrl, SW_HIDE);
  199. hCtrl = GetDlgItem(hDlg, IDC_SHARENAME);
  200. if (CurrentDShare->VFlag) {
  201. VShare = (VIRTUAL_SHARE_BUFFER *) CurrentDShare;
  202. SendMessage(hCtrl, WM_SETTEXT, (WPARAM) 0, (LPARAM) VShare->Name);
  203. } else
  204. SendMessage(hCtrl, WM_SETTEXT, (WPARAM) 0, (LPARAM) CurrentDShare->Name);
  205. } else {
  206. hCtrl = GetDlgItem(hDlg, IDC_SHARENAME);
  207. EnableWindow(hCtrl, FALSE);
  208. ShowWindow(hCtrl, SW_HIDE);
  209. hCtrl = GetDlgItem(hDlg, IDOK);
  210. EnableWindow(hCtrl, FALSE);
  211. }
  212. PostMessage(hDlg, WM_COMMAND, ID_INIT, 0L);
  213. return (TRUE);
  214. case WM_COMMAND:
  215. wmId = LOWORD(wParam);
  216. wmEvent = HIWORD(wParam);
  217. switch (wmId) {
  218. case IDOK:
  219. ok = TRUE;
  220. if (NewShareType == SELECT_TYPE_ADD) {
  221. hCtrl = GetDlgItem(hDlg, IDC_EDIT1);
  222. * (WORD *)NewShare = sizeof(NewShare);
  223. SendMessage(hCtrl, EM_GETLINE, 0, (LPARAM) NewShare);
  224. if (!ShareNewShareValidate(hDlg, NewShare))
  225. ok = FALSE;
  226. }
  227. if (ok) {
  228. hCtrl = GetDlgItem(hDlg, IDC_EDIT2);
  229. * (WORD *)Path = sizeof(Path);
  230. SendMessage(hCtrl, EM_GETLINE, 0, (LPARAM) Path);
  231. if (!ShareNewPathValidate(hDlg, Path, &Drive))
  232. ok = FALSE;
  233. }
  234. if (ok) {
  235. if (NewShareType == SELECT_TYPE_ADD) {
  236. // If we are in ADD - then we might have added a virtual
  237. // share when we did the match, if so get rid of it...
  238. if ((CurrentShare !=NULL) && (CurrentShare->DestShare != NULL))
  239. if (CurrentShare->Virtual) {
  240. VShare = (VIRTUAL_SHARE_BUFFER *) CurrentShare->DestShare;
  241. VShareListDelete(DServ, VShare);
  242. CurrentShare->DestShare = NULL;
  243. }
  244. // Got rid of old one, now need to create new one.
  245. CurrentShare->Virtual = TRUE;
  246. VShare = VShareListAdd(DServ, NewShare, Path);
  247. VShare->Drive = Drive;
  248. VShare->UseCount++;
  249. CurrentShare->DestShare = (SHARE_BUFFER *) VShare;
  250. CurrentDShare = (SHARE_BUFFER *) VShare;
  251. } else
  252. // Modify so update the values of the path/drive with
  253. // the new stuff.
  254. if ((CurrentShare !=NULL) && (CurrentShare->DestShare != NULL))
  255. if (CurrentShare->Virtual) {
  256. VShare = (VIRTUAL_SHARE_BUFFER *) CurrentShare->DestShare;
  257. lstrcpy(VShare->Path, Path);
  258. VShare->Drive = Drive;
  259. }
  260. EndDialog(hDlg, 0);
  261. }
  262. break;
  263. case IDCANCEL:
  264. EndDialog(hDlg, 0);
  265. break;
  266. case IDHELP:
  267. if (NewShareType == SELECT_TYPE_MODIFY)
  268. WinHelp(hDlg, HELP_FILE, HELP_CONTEXT, (DWORD) IDC_HELP_SHAREPROP);
  269. else
  270. WinHelp(hDlg, HELP_FILE, HELP_CONTEXT, (DWORD) IDC_HELP_SHARENEW);
  271. break;
  272. case ID_INIT:
  273. // Modify should only be for a virtual share
  274. if (NewShareType == SELECT_TYPE_MODIFY) {
  275. hCtrl = GetDlgItem(hDlg, IDC_EDIT2);
  276. if (CurrentDShare->VFlag) {
  277. VShare = (VIRTUAL_SHARE_BUFFER *) CurrentDShare;
  278. SendMessage(hCtrl, WM_SETTEXT, (WPARAM) 0, (LPARAM) VShare->Path);
  279. }
  280. }
  281. case IDC_EDIT1:
  282. case IDC_EDIT2:
  283. if (wmEvent == EN_CHANGE) {
  284. Enable = TRUE;
  285. hCtrl = GetDlgItem(hDlg, IDC_EDIT1);
  286. if (NewShareType == SELECT_TYPE_ADD)
  287. if (!SendMessage(hCtrl, EM_LINELENGTH, 0, 0))
  288. Enable = FALSE;
  289. hCtrl = GetDlgItem(hDlg, IDC_EDIT2);
  290. if (SendMessage(hCtrl, EM_LINELENGTH, 0, 0) < 3)
  291. Enable = FALSE;
  292. hCtrl = GetDlgItem(hDlg, IDOK);
  293. EnableWindow(hCtrl, Enable);
  294. }
  295. break;
  296. }
  297. return TRUE;
  298. }
  299. return (FALSE); // Didn't process the message
  300. lParam;
  301. } // NWShareNew
  302. /*+-------------------------------------------------------------------------+
  303. | NWShareNew_Do()
  304. |
  305. +-------------------------------------------------------------------------+*/
  306. void NWShareNew_Do(HWND hDlg) {
  307. DLGPROC lpfnDlg;
  308. lpfnDlg = MakeProcInstance( (DLGPROC) NWShareNew, hInst);
  309. DialogBox(hInst, TEXT("NWShareAdd"), hDlg, lpfnDlg) ;
  310. FreeProcInstance(lpfnDlg);
  311. } // NWShareNew_Do
  312. /*+-------------------------------------------------------------------------+
  313. | Add / Modify Share Selection Dialog Routines |
  314. +-------------------------------------------------------------------------+*/
  315. /*+-------------------------------------------------------------------------+
  316. | FixShare()
  317. |
  318. +-------------------------------------------------------------------------+*/
  319. void FixShare(LPTSTR OrigShare, LPTSTR ServName, LPTSTR DestShare) {
  320. LPTSTR pShare = OrigShare;
  321. lstrcpy(DestShare, TEXT(""));
  322. // Assume it is in the form \\server\share
  323. // Skip over leading double-back for server
  324. if ((pShare[0] == '\\') && (pShare[1] == '\\'))
  325. pShare+= 2;
  326. // Now skip over the server name
  327. while (*pShare && (*pShare != '\\'))
  328. pShare++;
  329. // pShare should point to the share-name, append this to the server-name
  330. if (*ServName != '\\')
  331. lstrcat(DestShare, TEXT("\\\\"));
  332. lstrcat(DestShare, ServName);
  333. lstrcat(DestShare, pShare);
  334. } // FixShare
  335. /*+-------------------------------------------------------------------------+
  336. | NTShareListFill()
  337. |
  338. +-------------------------------------------------------------------------+*/
  339. void NTShareListFill(HWND hDlg) {
  340. HWND hCtrl;
  341. SHARE_LIST *ShareList = NULL;
  342. SHARE_BUFFER *SList;
  343. DWORD_PTR i, dwIndex;
  344. BOOL Match = FALSE;
  345. VIRTUAL_SHARE_BUFFER *VShare;
  346. // Clear it out
  347. hCtrl = GetDlgItem(hDlg, IDC_COMBO2);
  348. SendMessage(hCtrl, CB_RESETCONTENT, 0, 0L);
  349. // First enum all the regular shares
  350. ShareList = DServ->ShareList;
  351. if (ShareList != NULL) {
  352. SList = ShareList->SList;
  353. for (i = 0; i < ShareList->Count; i++) {
  354. dwIndex = SendMessage(hCtrl, CB_ADDSTRING, (WPARAM) 0, (LPARAM) SList[i].Name);
  355. SendMessage(hCtrl, CB_SETITEMDATA, (WPARAM) dwIndex, (LPARAM) &SList[i]);
  356. }
  357. }
  358. // Now enum all the virtual shares
  359. VShare = DServ->VShareStart;
  360. while (VShare) {
  361. dwIndex = SendMessage(hCtrl, CB_ADDSTRING, (WPARAM) 0, (LPARAM) VShare->Name);
  362. SendMessage(hCtrl, CB_SETITEMDATA, (WPARAM) dwIndex, (LPARAM) VShare);
  363. VShare = VShare->next;
  364. }
  365. // Match the combo-box to the given share
  366. if (CurrentShare->DestShare != NULL)
  367. if (CurrentShare->Virtual) {
  368. VShare = (VIRTUAL_SHARE_BUFFER *) CurrentShare->DestShare;
  369. SendMessage(hCtrl, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) VShare->Name);
  370. } else
  371. SendMessage(hCtrl, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) CurrentShare->DestShare->Name);
  372. } // NTShareListFill
  373. /*+-------------------------------------------------------------------------+
  374. | NWShareSelect()
  375. |
  376. +-------------------------------------------------------------------------+*/
  377. LRESULT CALLBACK NWShareSelect(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
  378. static TCHAR ServName[MAX_UNC_PATH+1];
  379. VIRTUAL_SHARE_BUFFER *VShare;
  380. SHARE_BUFFER *OrigShare = NULL;
  381. SHARE_BUFFER *NewShare;
  382. HWND hCtrl;
  383. DWORD_PTR dwData,dwIndex;
  384. int wmId, wmEvent;
  385. ULONG i;
  386. switch (message) {
  387. case WM_INITDIALOG:
  388. // Center the dialog over the application window
  389. CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
  390. if (SelectType == SELECT_TYPE_MODIFY) {
  391. SendMessage(hDlg, WM_SETTEXT, (WPARAM) 0, (LPARAM) Lids(IDS_D_6));
  392. // Disable Source combo box...
  393. hCtrl = GetDlgItem(hDlg, IDC_COMBO1);
  394. EnableWindow(hCtrl, FALSE);
  395. ShowWindow(hCtrl, SW_HIDE);
  396. OrigShare = CurrentShare->DestShare;
  397. }
  398. hCtrl = GetDlgItem(hDlg, IDC_FSERVER);
  399. lstrcpy(ServName, Lids(IDS_D_7));
  400. lstrcat(ServName, SServ->Name);
  401. SendMessage(hCtrl, WM_SETTEXT, (WPARAM) 0, (LPARAM) ServName);
  402. hCtrl = GetDlgItem(hDlg, IDC_TSERVER);
  403. lstrcpy(ServName, Lids(IDS_D_8));
  404. lstrcat(ServName, DServ->Name);
  405. SendMessage(hCtrl, WM_SETTEXT, (WPARAM) 0, (LPARAM) ServName);
  406. PostMessage(hDlg, WM_COMMAND, ID_INIT, 0L);
  407. hCtrl = GetDlgItem(hDlg, IDC_EDIT1);
  408. PostMessage(hCtrl, EM_LIMITTEXT, (WPARAM) MAX_PATH, 0);
  409. if (SelectType == SELECT_TYPE_MODIFY)
  410. SendMessage(hCtrl, WM_SETTEXT, (WPARAM) 0, (LPARAM) CurrentShare->SubDir);
  411. return (TRUE);
  412. case WM_COMMAND:
  413. wmId = LOWORD(wParam);
  414. wmEvent = HIWORD(wParam);
  415. switch (wmId) {
  416. case IDOK:
  417. CurrentShare->Convert = TRUE; // only really needed for add
  418. hCtrl = GetDlgItem(hDlg, IDC_COMBO2);
  419. dwIndex = SendMessage(hCtrl, CB_GETCURSEL, 0, 0L);
  420. if (dwIndex != CB_ERR) {
  421. dwData = SendMessage(hCtrl, CB_GETITEMDATA, dwIndex, 0L);
  422. NewShare = (SHARE_BUFFER *) dwData;
  423. if (OrigShare != NewShare) {
  424. CurrentShare->DestShare = NewShare;
  425. // this is actually a flag for the destination share
  426. CurrentShare->Virtual = NewShare->VFlag;
  427. }
  428. }
  429. hCtrl = GetDlgItem(hDlg, IDC_EDIT1);
  430. * (WORD *)CurrentShare->SubDir = sizeof(CurrentShare->SubDir);
  431. SendMessage(hCtrl, EM_GETLINE, 0, (LPARAM) CurrentShare->SubDir);
  432. EndDialog(hDlg, 0);
  433. break;
  434. case IDCANCEL:
  435. if (SelectType == SELECT_TYPE_ADD) {
  436. // If we are in ADD - then we might have added a virtual
  437. // share when we did the match, if so get rid of it...
  438. if ((CurrentShare !=NULL) && (CurrentShare->DestShare != NULL))
  439. if (CurrentShare->Virtual) {
  440. VShare = (VIRTUAL_SHARE_BUFFER *) CurrentShare->DestShare;
  441. VShareListDelete(DServ, VShare);
  442. CurrentShare->DestShare = NULL;
  443. }
  444. CurrentShare = NULL;
  445. }
  446. EndDialog(hDlg, 0);
  447. break;
  448. case IDHELP:
  449. if (SelectType == SELECT_TYPE_MODIFY)
  450. WinHelp(hDlg, HELP_FILE, HELP_CONTEXT, (DWORD) IDC_HELP_SHAREMOD);
  451. else
  452. WinHelp(hDlg, HELP_FILE, HELP_CONTEXT, (DWORD) IDC_HELP_SHAREADD);
  453. break;
  454. case IDC_NEWSHARE:
  455. CurrentDShare = NULL;
  456. NewShareType = SELECT_TYPE_ADD;
  457. NWShareNew_Do(hDlg);
  458. // Match the combo-box to the given share
  459. NTShareListFill(hDlg);
  460. PostMessage(hDlg, WM_COMMAND, ID_UPDATECOMBO, 0L);
  461. break;
  462. case IDC_PROPERTIES:
  463. NewShareType = SELECT_TYPE_MODIFY;
  464. hCtrl = GetDlgItem(hDlg, IDC_COMBO2);
  465. dwIndex = SendMessage(hCtrl, CB_GETCURSEL, 0, 0L);
  466. if (dwIndex != CB_ERR) {
  467. dwData = SendMessage(hCtrl, CB_GETITEMDATA, dwIndex, 0L);
  468. CurrentDShare = (SHARE_BUFFER *) dwData;
  469. NWShareNew_Do(hDlg);
  470. }
  471. break;
  472. case ID_INIT:
  473. if (SelectType == SELECT_TYPE_ADD) {
  474. hCtrl = GetDlgItem(hDlg, IDC_COMBO1);
  475. if (ShareList == NULL)
  476. break;
  477. CurrentShare = NULL;
  478. for (i = 0; i < ShareList->Count; i++)
  479. if (!SList[i].Convert) {
  480. if (CurrentShare == NULL)
  481. CurrentShare = &SList[i];
  482. dwIndex = SendMessage(hCtrl, CB_ADDSTRING, (WPARAM) 0, (LPARAM) SList[i].Name);
  483. SendMessage(hCtrl, CB_SETITEMDATA, (WPARAM) dwIndex, (LPARAM) &SList[i]);
  484. }
  485. if (CurrentShare != NULL) {
  486. SendMessage(hCtrl, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) CurrentShare->Name);
  487. MapShare(CurrentShare, DServ);
  488. }
  489. } else {
  490. // Display the static text
  491. hCtrl = GetDlgItem(hDlg, IDC_VOLUME);
  492. EnableWindow(hCtrl, TRUE);
  493. ShowWindow(hCtrl, SW_SHOW);
  494. SendMessage(hCtrl, WM_SETTEXT, (WPARAM) 0, (LPARAM) CurrentShare->Name);
  495. }
  496. NTShareListFill(hDlg);
  497. PostMessage(hDlg, WM_COMMAND, ID_UPDATECOMBO, 0L);
  498. break;
  499. // Used to update which volume we are pointing at
  500. case ID_UPDATELIST:
  501. // We might have added a virtual share when we did the
  502. // match, if so get rid of it...
  503. if ((CurrentShare !=NULL) && (CurrentShare->DestShare != NULL))
  504. if (CurrentShare->Virtual) {
  505. VShare = (VIRTUAL_SHARE_BUFFER *) CurrentShare->DestShare;
  506. VShareListDelete(DServ, VShare);
  507. CurrentShare->DestShare = NULL;
  508. }
  509. hCtrl = GetDlgItem(hDlg, IDC_COMBO1);
  510. dwIndex = SendMessage(hCtrl, CB_GETCURSEL, 0, 0L);
  511. if (dwIndex != CB_ERR) {
  512. dwData = SendMessage(hCtrl, CB_GETITEMDATA, dwIndex, 0L);
  513. CurrentShare = (SHARE_BUFFER *) dwData;
  514. // Now need to map this to a new share
  515. if (CurrentShare != NULL) {
  516. MapShare(CurrentShare, DServ);
  517. // Match the combo-box to the given share
  518. NTShareListFill(hDlg);
  519. }
  520. }
  521. break;
  522. // updateded the share list selection
  523. case ID_UPDATECOMBO:
  524. hCtrl = GetDlgItem(hDlg, IDC_COMBO2);
  525. dwIndex = SendMessage(hCtrl, CB_GETCURSEL, 0, 0L);
  526. if (dwIndex != CB_ERR) {
  527. dwData = SendMessage(hCtrl, CB_GETITEMDATA, dwIndex, 0L);
  528. CurrentDShare = (SHARE_BUFFER *) dwData;
  529. hCtrl = GetDlgItem(hDlg, IDC_PROPERTIES);
  530. if (CurrentDShare->VFlag) {
  531. EnableWindow(hCtrl, TRUE);
  532. } else {
  533. EnableWindow(hCtrl, FALSE);
  534. }
  535. }
  536. break;
  537. case IDC_COMBO1:
  538. if (wmEvent == CBN_SELCHANGE)
  539. PostMessage(hDlg, WM_COMMAND, ID_UPDATELIST, 0L);
  540. break;
  541. case IDC_COMBO2:
  542. if (wmEvent == CBN_SELCHANGE)
  543. PostMessage(hDlg, WM_COMMAND, ID_UPDATECOMBO, 0L);
  544. break;
  545. }
  546. return TRUE;
  547. }
  548. return (FALSE); // Didn't process the message
  549. lParam;
  550. } // NWShareSelect
  551. /*+-------------------------------------------------------------------------+
  552. | ShareSelect_Do()
  553. |
  554. +-------------------------------------------------------------------------+*/
  555. void NWShareSelect_Do(HWND hDlg) {
  556. DLGPROC lpfnDlg;
  557. lpfnDlg = MakeProcInstance((DLGPROC)NWShareSelect, hInst);
  558. DialogBox(hInst, TEXT("NWShareSelect"), hDlg, lpfnDlg) ;
  559. FreeProcInstance(lpfnDlg);
  560. } // NWShareSelect_Do
  561. /*+-------------------------------------------------------------------------+
  562. | Main File Options Dialog Routines |
  563. +-------------------------------------------------------------------------+*/
  564. /*+-------------------------------------------------------------------------+
  565. | FileOptionsToggleControls()
  566. |
  567. +-------------------------------------------------------------------------+*/
  568. void FileOptionsToggleControls(HWND hDlg, BOOL Toggle) {
  569. HWND hCtrl;
  570. hCtrl = GetDlgItem(hDlg, IDC_DELETE);
  571. EnableWindow(hCtrl, Toggle);
  572. hCtrl = GetDlgItem(hDlg, IDC_MODIFY);
  573. EnableWindow(hCtrl, Toggle);
  574. hCtrl = GetDlgItem(hDlg, IDC_FILES);
  575. EnableWindow(hCtrl, Toggle);
  576. } // FileOptionsToggleControls
  577. /*+-------------------------------------------------------------------------+
  578. | FileDialogToggle()
  579. |
  580. +-------------------------------------------------------------------------+*/
  581. void FileDialogToggle(HWND hDlg, BOOL Toggle) {
  582. HWND hCtrl;
  583. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  584. EnableWindow(hCtrl, Toggle);
  585. FileOptionsToggleControls(hDlg, Toggle);
  586. hCtrl = GetDlgItem(hDlg, IDC_ADD);
  587. if (Toggle == FALSE)
  588. EnableWindow(hCtrl, FALSE);
  589. else
  590. if (ShareList && ShareList->Count != ShareList->ConvertCount)
  591. EnableWindow(hCtrl, TRUE);
  592. else
  593. EnableWindow(hCtrl, FALSE);
  594. } // FileDialogToggle
  595. /*+-------------------------------------------------------------------------+
  596. | DlgFileOptions_Save()
  597. |
  598. +-------------------------------------------------------------------------+*/
  599. void DlgFileOptions_Save(HWND hDlg) {
  600. HWND hCtrl;
  601. hCtrl = GetDlgItem(hDlg, IDC_CHKFILES);
  602. if (SendMessage(hCtrl, BM_GETCHECK, 0, 0) == 1)
  603. FileOptions->TransferFileInfo = TRUE;
  604. else
  605. FileOptions->TransferFileInfo = FALSE;
  606. } // DlgFileOptions_Save
  607. /*+-------------------------------------------------------------------------+
  608. | DlgFileOptions_Setup()
  609. |
  610. +-------------------------------------------------------------------------+*/
  611. void DlgFileOptions_Setup(HWND hDlg) {
  612. HWND hCtrl;
  613. hCtrl = GetDlgItem(hDlg, IDC_CHKFILES);
  614. if (FileOptions->TransferFileInfo) {
  615. SendMessage(hCtrl, BM_SETCHECK, 1, 0);
  616. FileDialogToggle(hDlg, TRUE);
  617. } else {
  618. SendMessage(hCtrl, BM_SETCHECK, 0, 0);
  619. FileDialogToggle(hDlg, FALSE);
  620. }
  621. } // DlgFileOptions_Setup
  622. /*+-------------------------------------------------------------------------+
  623. | DlgFileOptions_ListboxAdd()
  624. |
  625. +-------------------------------------------------------------------------+*/
  626. void DlgFileOptions_ListboxAdd(HWND hDlg, SHARE_BUFFER *CurrentShare, DWORD *wItem, BOOL Insert ) {
  627. HWND hCtrl;
  628. static TCHAR AddLine[256];
  629. VIRTUAL_SHARE_BUFFER *VShare;
  630. DWORD wItemNum;
  631. wItemNum = *wItem;
  632. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  633. if (CurrentShare->Virtual) {
  634. VShare = (VIRTUAL_SHARE_BUFFER *) CurrentShare->DestShare;
  635. wsprintf(AddLine, TEXT("%s\\%s:\t\\\\%s\\%s\t"), SServ->Name, CurrentShare->Name, DServ->Name, VShare->Name);
  636. } else
  637. wsprintf(AddLine, TEXT("%s\\%s:\t\\\\%s\\%s\t"), SServ->Name, CurrentShare->Name, DServ->Name, CurrentShare->DestShare->Name);
  638. if (Insert)
  639. ColumnLB_InsertString(hCtrl, wItemNum, AddLine);
  640. else
  641. wItemNum = ColumnLB_AddString(hCtrl, AddLine);
  642. ColumnLB_SetItemData(hCtrl, wItemNum, (DWORD_PTR) CurrentShare);
  643. *wItem = wItemNum;
  644. } // DlgFileOptions_ListboxAdd
  645. /*+-------------------------------------------------------------------------+
  646. | DlgFileOptions()
  647. |
  648. +-------------------------------------------------------------------------+*/
  649. LRESULT CALLBACK DlgFileOptions(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
  650. HWND hCtrl;
  651. DWORD wItemNum;
  652. DWORD_PTR dwData;
  653. static short FilesTab, FileOptionsTab;
  654. int wmId, wmEvent;
  655. ULONG i;
  656. SHARE_BUFFER *pShare;
  657. VIRTUAL_SHARE_BUFFER *VShare;
  658. RECT rc;
  659. int TabStop;
  660. switch (message) {
  661. case WM_INITDIALOG:
  662. // Center the dialog over the application window
  663. CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
  664. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  665. GetClientRect(hCtrl, &rc);
  666. // Size is half width of listbox - vertical scrollbar
  667. TabStop = (((rc.right - rc.left) - GetSystemMetrics(SM_CXVSCROLL)) / 2);
  668. ColumnLB_SetNumberCols(hCtrl, 2);
  669. ColumnLB_SetColTitle(hCtrl, 0, Lids(IDS_D_9));
  670. ColumnLB_SetColTitle(hCtrl, 1, Lids(IDS_D_10));
  671. ColumnLB_SetColWidth(hCtrl, 0, TabStop);
  672. // Calculate 2nd this way instead of just using TabStop to get rid of roundoff
  673. ColumnLB_SetColWidth(hCtrl, 1, (rc.right - rc.left) - TabStop);
  674. DlgFileOptions_Setup(hDlg);
  675. // Fill listbox and set selection (is assumed there is always a selection)...
  676. PostMessage(hDlg, WM_COMMAND, ID_INIT, 0L);
  677. return (TRUE);
  678. case WM_COMMAND:
  679. wmId = LOWORD(wParam);
  680. wmEvent = HIWORD(wParam);
  681. switch (wmId) {
  682. case IDOK:
  683. DlgFileOptions_Save(hDlg);
  684. FileOptionsDefaultsSet(FileOptions);
  685. EndDialog(hDlg, 0);
  686. return (TRUE);
  687. case IDCANCEL:
  688. EndDialog(hDlg, 0);
  689. return (TRUE);
  690. case IDHELP:
  691. WinHelp(hDlg, HELP_FILE, HELP_CONTEXT, (DWORD) IDC_HELP_FILE);
  692. return (TRUE);
  693. case IDC_CHKFILES:
  694. hCtrl = GetDlgItem(hDlg, IDC_CHKFILES);
  695. if (SendMessage(hCtrl, BM_GETCHECK, 0, 0) == 1)
  696. FileDialogToggle(hDlg, TRUE);
  697. else
  698. FileDialogToggle(hDlg, FALSE);
  699. return (TRUE);
  700. case IDC_ADD:
  701. SelectType = SELECT_TYPE_ADD;
  702. CurrentShare = NULL;
  703. NWShareSelect_Do(hDlg);
  704. if (CurrentShare != NULL) {
  705. DlgFileOptions_ListboxAdd(hDlg, CurrentShare, &wItemNum, FALSE );
  706. // Check if Add button needs to be disabled
  707. ShareList->ConvertCount++;
  708. if (ShareList->Count == ShareList->ConvertCount) {
  709. hCtrl = GetDlgItem(hDlg, IDC_ADD);
  710. EnableWindow(hCtrl, FALSE);
  711. }
  712. // Buttons need to be re-enabled
  713. FileOptionsToggleControls(hDlg, TRUE);
  714. // Now make sure focus is set
  715. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  716. ColumnLB_SetCurSel(hCtrl, wItemNum);
  717. wItemNum = ColumnLB_GetCurSel(hCtrl);
  718. if (wItemNum == LB_ERR)
  719. ColumnLB_SetCurSel(hCtrl, 0);
  720. };
  721. return (TRUE);
  722. case IDC_DELETE:
  723. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  724. wItemNum = ColumnLB_GetCurSel(hCtrl);
  725. if (wItemNum != LB_ERR) {
  726. dwData = ColumnLB_GetItemData(hCtrl, wItemNum);
  727. pShare = (SHARE_BUFFER *)dwData;
  728. pShare->Convert = FALSE;
  729. ShareList->ConvertCount--;
  730. // Now need to delete dest share, or reduce use count
  731. if (pShare->DestShare != NULL)
  732. if (pShare->Virtual) {
  733. VShare = (VIRTUAL_SHARE_BUFFER *) pShare->DestShare;
  734. VShareListDelete(DServ, VShare);
  735. pShare->DestShare = NULL;
  736. }
  737. ColumnLB_DeleteString(hCtrl, wItemNum);
  738. }
  739. if (!ShareList->ConvertCount)
  740. FileOptionsToggleControls(hDlg, FALSE);
  741. else {
  742. wItemNum = ColumnLB_GetCurSel(hCtrl);
  743. if (wItemNum == LB_ERR)
  744. ColumnLB_SetCurSel(hCtrl, 0);
  745. }
  746. if (ShareList->Count != ShareList->ConvertCount) {
  747. hCtrl = GetDlgItem(hDlg, IDC_ADD);
  748. EnableWindow(hCtrl, TRUE);
  749. }
  750. return (TRUE);
  751. case IDC_MODIFY:
  752. SelectType = SELECT_TYPE_MODIFY;
  753. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  754. wItemNum = ColumnLB_GetCurSel(hCtrl);
  755. if (wItemNum != LB_ERR) {
  756. dwData = ColumnLB_GetItemData(hCtrl, wItemNum);
  757. CurrentShare = (SHARE_BUFFER *)dwData;
  758. NWShareSelect_Do(hDlg);
  759. // Now update listbox to reflect any changes
  760. ColumnLB_DeleteString(hCtrl, wItemNum);
  761. DlgFileOptions_ListboxAdd(hDlg, CurrentShare, &wItemNum, TRUE );
  762. // now reset focus back to this item
  763. ColumnLB_SetCurSel(hCtrl, wItemNum);
  764. }
  765. return (TRUE);
  766. case IDC_FILES:
  767. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  768. wItemNum = ColumnLB_GetCurSel(hCtrl);
  769. if (wItemNum != LB_ERR) {
  770. dwData = ColumnLB_GetItemData(hCtrl, wItemNum);
  771. CurrentShare = (SHARE_BUFFER *)dwData;
  772. FileSelect_Do(hDlg, SServ, CurrentShare);
  773. }
  774. return (TRUE);
  775. case IDC_FOPTIONS:
  776. return (TRUE);
  777. case ID_INIT:
  778. if (ShareList != NULL) {
  779. SList = ShareList->SList;
  780. for (i = 0; i < ShareList->Count; i++)
  781. if (SList[i].Convert) {
  782. DlgFileOptions_ListboxAdd(hDlg, &SList[i], &wItemNum, FALSE );
  783. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  784. ColumnLB_SetCurSel(hCtrl, 0);
  785. }
  786. if (ShareList->Count == ShareList->ConvertCount) {
  787. hCtrl = GetDlgItem(hDlg, IDC_ADD);
  788. EnableWindow(hCtrl, FALSE);
  789. }
  790. if (!ShareList->ConvertCount)
  791. FileOptionsToggleControls(hDlg, FALSE);
  792. } else
  793. FileOptionsToggleControls(hDlg, FALSE);
  794. return (TRUE);
  795. case IDC_LIST1:
  796. switch (wmEvent) {
  797. case LBN_DBLCLK:
  798. PostMessage(hDlg, WM_COMMAND, IDC_MODIFY, 0L);
  799. break;
  800. case LBN_SELCHANGE:
  801. if (!ShareList || !ShareList->ConvertCount)
  802. FileOptionsToggleControls(hDlg, TRUE);
  803. break;
  804. }
  805. break;
  806. }
  807. break;
  808. }
  809. return (FALSE); // Didn't process the message
  810. lParam;
  811. } // DlgFileOptions
  812. /*+-------------------------------------------------------------------------+
  813. | FileOptions_Do()
  814. |
  815. +-------------------------------------------------------------------------+*/
  816. void FileOptions_Do(HWND hDlg, void *ConvOptions, SOURCE_SERVER_BUFFER *SourceServer, DEST_SERVER_BUFFER *DestServer) {
  817. DLGPROC lpfnDlg;
  818. SServ = SourceServer;
  819. DServ = DestServer;
  820. NWServerFree();
  821. NWServerSet(SourceServer->Name);
  822. NTServerSet(DestServer->Name);
  823. FileOptions = (FILE_OPTIONS *) ConvOptions;
  824. ShareList = SServ->ShareList;
  825. lpfnDlg = MakeProcInstance((DLGPROC)DlgFileOptions, hInst);
  826. DialogBox(hInst, TEXT("FileMain"), hDlg, lpfnDlg) ;
  827. FreeProcInstance(lpfnDlg);
  828. } // FileOptions_Do