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.

1100 lines
36 KiB

  1. /****************************************************************************/
  2. /* */
  3. /* WFDLGS.C - */
  4. /* */
  5. /* Windows File System Dialog procedures */
  6. /* */
  7. /****************************************************************************/
  8. #include "winfile.h"
  9. #include "winnet.h"
  10. #include "wnetcaps.h" // WNetGetCaps()
  11. #include "lfn.h"
  12. #include "wfcopy.h"
  13. /*--------------------------------------------------------------------------*/
  14. /* */
  15. /* ChooseDriveDlgProc() - */
  16. /* */
  17. /*--------------------------------------------------------------------------*/
  18. INT_PTR
  19. APIENTRY
  20. ChooseDriveDlgProc(
  21. register HWND hDlg,
  22. UINT wMsg,
  23. WPARAM wParam,
  24. LPARAM lParam
  25. )
  26. {
  27. CHAR szDrive[5];
  28. switch (wMsg) {
  29. case WM_INITDIALOG:
  30. {
  31. INT i;
  32. HWND hwndLB;
  33. lstrcpy(szDrive, "A:");
  34. hwndLB = GetDlgItem(hDlg, IDD_DRIVE);
  35. switch (wSuperDlgMode) {
  36. case IDM_SYSDISK:
  37. case IDM_DISKCOPY:
  38. FillFloppies:
  39. for (i = 0; i < cDrives; i++) {
  40. if (IsRemovableDrive(rgiDrive[i])) {
  41. szDrive[0] = (CHAR)('A'+rgiDrive[i]);
  42. SendMessage(hwndLB, CB_ADDSTRING, 0, (LPARAM)szDrive);
  43. }
  44. }
  45. if (wSuperDlgMode == IDM_DISKCOPY && hwndLB == GetDlgItem(hDlg, IDD_DRIVE)) {
  46. SendMessage(hwndLB, CB_SETCURSEL, 0, 0L);
  47. hwndLB = GetDlgItem(hDlg, IDD_DRIVE1);
  48. goto FillFloppies;
  49. }
  50. break;
  51. case IDM_DISCONNECT:
  52. for (i=0; i < cDrives; i++) {
  53. wParam = rgiDrive[i];
  54. if (!IsCDRomDrive((WORD)wParam)) {
  55. CHAR szTemp[80];
  56. szTemp[0] = (CHAR)('A' + wParam);
  57. szTemp[1] = ':';
  58. szTemp[2] = 0;
  59. lstrcpy(szDrive,szTemp);
  60. szTemp[2] = ' ';
  61. if (WFGetConnection(szDrive, szTemp+3, FALSE) != WN_SUCCESS)
  62. continue;
  63. SendMessage(hwndLB, LB_ADDSTRING, 0, (LPARAM)szTemp);
  64. }
  65. }
  66. SendMessage(hwndLB,LB_SETCURSEL,0,0L);
  67. return TRUE;
  68. }
  69. SendMessage(hwndLB, CB_SETCURSEL, 0, 0L);
  70. break;
  71. }
  72. case WM_COMMAND:
  73. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  74. case IDD_HELP:
  75. goto DoHelp;
  76. case IDOK:
  77. {
  78. CHAR szTemp[80];
  79. if (wSuperDlgMode == IDM_DISCONNECT) {
  80. SendDlgItemMessage(hDlg, IDD_DRIVE, LB_GETTEXT,
  81. (WPARAM)SendDlgItemMessage(hDlg, IDD_DRIVE,
  82. WM_COMMAND,
  83. GET_WM_COMMAND_MPS(LB_GETCURSEL,0,0)),
  84. (LPARAM)szTemp);
  85. } else
  86. GetDlgItemText(hDlg, IDD_DRIVE, szTemp, sizeof(szTemp) - 1);
  87. iFormatDrive = (INT)(szTemp[0] - 'A');
  88. if (wSuperDlgMode == IDM_DISKCOPY) {
  89. GetDlgItemText(hDlg, IDD_DRIVE1, szTemp, sizeof(szTemp) - 1);
  90. iCurrentDrive = (INT)(szTemp[0] - 'A');
  91. }
  92. EndDialog(hDlg, TRUE);
  93. break;
  94. }
  95. case IDCANCEL:
  96. EndDialog(hDlg, FALSE);
  97. break;
  98. default:
  99. return FALSE;
  100. }
  101. break;
  102. default:
  103. if (wMsg == wHelpMessage) {
  104. DoHelp:
  105. WFHelp(hDlg);
  106. return TRUE;
  107. } else
  108. return FALSE;
  109. }
  110. return TRUE;
  111. }
  112. /*--------------------------------------------------------------------------*/
  113. /* */
  114. /* DiskLabelDlgProc() - */
  115. /* */
  116. /*--------------------------------------------------------------------------*/
  117. INT_PTR
  118. APIENTRY
  119. DiskLabelDlgProc(
  120. register HWND hDlg,
  121. UINT wMsg,
  122. WPARAM wParam,
  123. LPARAM lParam
  124. )
  125. {
  126. CHAR szOldVol[13];
  127. CHAR szNewVol[13];
  128. switch (wMsg) {
  129. case WM_INITDIALOG:
  130. /* Get the current volume label */
  131. szNewVol[0] = (CHAR)(GetSelectedDrive() + 'A');
  132. szNewVol[1] = ':';
  133. szNewVol[2] = '\0';
  134. if (!IsTheDiskReallyThere(hDlg, szNewVol, FUNC_LABEL)) {
  135. EndDialog(hDlg, FALSE);
  136. break;
  137. }
  138. GetVolumeLabel(szNewVol[0]-'A', szOldVol, FALSE);
  139. OemToAnsi(szOldVol, szOldVol);
  140. /* Display the current volume label. */
  141. SetDlgItemText(hDlg, IDD_NAME, szOldVol);
  142. SendDlgItemMessage(hDlg, IDD_NAME, EM_LIMITTEXT, sizeof(szNewVol)-2, 0L);
  143. break;
  144. case WM_COMMAND:
  145. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  146. case IDD_HELP:
  147. goto DoHelp;
  148. case IDCANCEL:
  149. EndDialog(hDlg, FALSE);
  150. break;
  151. case IDOK:
  152. {
  153. HWND hwnd;
  154. BOOL bOldVolExists;
  155. GetVolumeLabel(GetSelectedDrive(), szOldVol, FALSE);
  156. bOldVolExists = (szOldVol[0] != TEXT('\0'));
  157. GetDlgItemText(hDlg, IDD_NAME, szNewVol, sizeof(szNewVol));
  158. if (MySetVolumeLabel(GetSelectedDrive(), bOldVolExists, szNewVol)) {
  159. GetWindowText(hDlg, szTitle, sizeof(szTitle));
  160. LoadString(hAppInstance, IDS_LABELDISKERR, szMessage, sizeof(szMessage));
  161. MessageBox(hDlg, szMessage, szTitle, MB_OK | MB_ICONSTOP);
  162. EndDialog(hDlg, FALSE);
  163. break;
  164. }
  165. for (hwnd = GetWindow(hwndMDIClient, GW_CHILD);
  166. hwnd;
  167. hwnd = GetWindow(hwnd, GW_HWNDNEXT)) {
  168. // refresh windows on this drive
  169. if ((LONG)GetSelectedDrive() == GetWindowLong(hwnd, GWL_TYPE))
  170. SendMessage(hwnd, FS_CHANGEDRIVES, 0, 0L);
  171. }
  172. EndDialog(hDlg, TRUE);
  173. break;
  174. }
  175. default:
  176. return FALSE;
  177. }
  178. break;
  179. default:
  180. if (wMsg == wHelpMessage) {
  181. DoHelp:
  182. WFHelp(hDlg);
  183. return TRUE;
  184. } else
  185. return FALSE;
  186. }
  187. return TRUE;
  188. }
  189. INT
  190. APIENTRY
  191. FormatDiskette(
  192. HWND hwnd
  193. )
  194. {
  195. WNDPROC lpfnDialog;
  196. INT res;
  197. DWORD dwSave;
  198. // in case current drive is on floppy
  199. GetSystemDirectory(szMessage, sizeof(szMessage));
  200. SheChangeDir(szMessage);
  201. dwSave = dwContext;
  202. dwContext = IDH_FORMAT;
  203. res = (int)DialogBox(hAppInstance, MAKEINTRESOURCE(FORMATDLG), hwnd, FormatDlgProc);
  204. dwContext = dwSave;
  205. return res;
  206. }
  207. WORD fFormatFlags = 0;
  208. WORD nLastDriveInd = 0;
  209. VOID
  210. FillDriveCapacity(
  211. HWND hDlg,
  212. INT nDrive
  213. )
  214. {
  215. INT count, cap;
  216. SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_RESETCONTENT, 0, 0L);
  217. cap = (INT)GetDriveCapacity((WORD)nDrive);
  218. count = 0; // index of each string, since we are inserting at the end
  219. // 3.5 (720 1.44 2.88
  220. if ((cap >= 3) && (cap <= 5)) {
  221. // 1.44
  222. LoadString(hAppInstance, IDS_144MB, szTitle, sizeof(szTitle));
  223. SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_INSERTSTRING, count, (LPARAM)szTitle);
  224. SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_SETITEMDATA, count++, MAKELONG(IDS_144MB,0));
  225. // 720
  226. LoadString(hAppInstance, IDS_720KB, szTitle, sizeof(szTitle));
  227. SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_INSERTSTRING, count, (LPARAM)szTitle);
  228. SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_SETITEMDATA, count++, MAKELONG(IDS_720KB,0));
  229. if (cap == 5) { // 2.88
  230. LoadString(hAppInstance, IDS_288MB, szTitle, sizeof(szTitle));
  231. SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_INSERTSTRING, count, (LPARAM)szTitle);
  232. SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_SETITEMDATA, count++, MAKELONG(IDS_288MB,0));
  233. }
  234. } else if ((cap >= 1) && (cap <= 2)) {
  235. // 1.2
  236. LoadString(hAppInstance, IDS_12MB, szTitle, sizeof(szTitle));
  237. SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_INSERTSTRING, count, (LPARAM)szTitle);
  238. SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_SETITEMDATA, count++, MAKELONG(IDS_12MB,0));
  239. // 360
  240. LoadString(hAppInstance, IDS_360KB, szTitle, sizeof(szTitle));
  241. SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_INSERTSTRING, count, (LPARAM)szTitle);
  242. SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_SETITEMDATA, count++, MAKELONG(IDS_360KB,0));
  243. } else {
  244. // device cap
  245. LoadString(hAppInstance, IDS_DEVICECAP, szTitle, sizeof(szTitle));
  246. SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_INSERTSTRING, count, (LPARAM)szTitle);
  247. SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_SETITEMDATA, count, MAKELONG(IDS_DEVICECAP, 0));
  248. }
  249. SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_SETCURSEL, FF_CAPMASK & fFormatFlags, 0L);
  250. }
  251. /*--------------------------------------------------------------------------*/
  252. /* */
  253. /* FormatDlgProc() - */
  254. /* */
  255. /*--------------------------------------------------------------------------*/
  256. INT_PTR
  257. APIENTRY
  258. FormatDlgProc(
  259. register HWND hDlg,
  260. UINT wMsg,
  261. WPARAM wParam,
  262. LPARAM lParam
  263. )
  264. {
  265. CHAR szLabel[13];
  266. CHAR szBuf[128];
  267. INT i, iCap, iDrive;
  268. WORD count;
  269. UNREFERENCED_PARAMETER(lParam);
  270. switch (wMsg) {
  271. case WM_INITDIALOG:
  272. // fill drives combo
  273. count = 0;
  274. LoadString(hAppInstance, IDS_DRIVETEMP, szTitle, sizeof(szTitle));
  275. for (i=0; i < cDrives; i++) {
  276. if (IsRemovableDrive(rgiDrive[i])) {
  277. wsprintf(szMessage, szTitle, (CHAR)('A'+rgiDrive[i]), ' ');
  278. if (count == (WORD)nLastDriveInd)
  279. iDrive = i;
  280. SendDlgItemMessage(hDlg, IDD_DRIVE, CB_INSERTSTRING, count, (LPARAM)szMessage);
  281. SendDlgItemMessage(hDlg, IDD_DRIVE, CB_SETITEMDATA, count++, MAKELONG(rgiDrive[i], 0));
  282. }
  283. }
  284. SendDlgItemMessage(hDlg, IDD_NAME, EM_LIMITTEXT, sizeof(szLabel)-2, 0L);
  285. if (fFormatFlags & FF_SAVED) {
  286. CheckDlgButton(hDlg, IDD_VERIFY, fFormatFlags & FF_QUICK);
  287. CheckDlgButton(hDlg, IDD_MAKESYS, fFormatFlags & FF_MAKESYS);
  288. }
  289. SendDlgItemMessage(hDlg, IDD_DRIVE, CB_SETCURSEL, nLastDriveInd, 0L);
  290. FillDriveCapacity(hDlg, rgiDrive[iDrive]);
  291. break;
  292. case WM_COMMAND:
  293. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  294. case IDD_HELP:
  295. goto DoHelp;
  296. case IDD_DRIVE:
  297. switch (GET_WM_COMMAND_CMD(wParam, lParam)) {
  298. case CBN_SELCHANGE:
  299. i = (INT)SendDlgItemMessage(hDlg, IDD_DRIVE, CB_GETCURSEL, 0, 0L);
  300. i = (INT)SendDlgItemMessage(hDlg, IDD_DRIVE, CB_GETITEMDATA, i, 0L);
  301. fFormatFlags &= ~FF_CAPMASK;
  302. FillDriveCapacity(hDlg, i);
  303. break;
  304. }
  305. break;
  306. case IDCANCEL:
  307. EndDialog(hDlg, FALSE);
  308. break;
  309. case IDOK:
  310. nLastDriveInd = (WORD)SendDlgItemMessage(hDlg, IDD_DRIVE, CB_GETCURSEL, 0, 0L);
  311. iFormatDrive = (INT)SendDlgItemMessage(hDlg, IDD_DRIVE, CB_GETITEMDATA, nLastDriveInd, 0L);
  312. i = (INT)SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_GETCURSEL, 0, 0L);
  313. fFormatFlags &= ~FF_CAPMASK; // clear any previous bits
  314. fFormatFlags |= (WORD)i; // save last selection as default
  315. if (i >= 0)
  316. iCap = (INT)SendDlgItemMessage(hDlg, IDD_HIGHCAP, CB_GETITEMDATA, i, 0L);
  317. else
  318. iCap = IDS_DEVICECAP;
  319. if (iCap == IDS_DEVICECAP)
  320. iCap = -1;
  321. else
  322. iCap -= IDS_DRIVEBASE; // normalize down to
  323. // indexes into bpbList[]
  324. fFormatFlags |= FF_SAVED;
  325. if (IsDlgButtonChecked(hDlg, IDD_MAKESYS))
  326. fFormatFlags |= FF_MAKESYS;
  327. else
  328. fFormatFlags &= ~FF_MAKESYS;
  329. if (IsDlgButtonChecked(hDlg, IDD_VERIFY))
  330. fFormatFlags |= FF_QUICK;
  331. else
  332. fFormatFlags &= ~FF_QUICK;
  333. GetDlgItemText(hDlg, IDD_NAME, szLabel, sizeof(szLabel));
  334. if (bConfirmFormat) {
  335. LoadString(hAppInstance, IDS_FORMATCONFIRMTITLE, szTitle, sizeof(szTitle));
  336. LoadString(hAppInstance, IDS_FORMATCONFIRM, szBuf, sizeof(szBuf));
  337. wsprintf(szMessage, szBuf, (CHAR)('A'+iFormatDrive));
  338. if (MessageBox(hDlg, szMessage, szTitle, MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON1) != IDYES)
  339. break;
  340. }
  341. if (FormatFloppy(hDlg, (WORD)iFormatDrive, iCap, (fFormatFlags & FF_MAKESYS), (fFormatFlags & FF_QUICK))) {
  342. if (szLabel[0])
  343. MySetVolumeLabel(iFormatDrive, FALSE, szLabel);
  344. if (fFormatFlags & FF_ONLYONE) {
  345. fFormatFlags &= ~FF_ONLYONE; // clear the flag
  346. EndDialog(hDlg, TRUE);
  347. } else {
  348. SetDlgItemText(hDlg, IDD_NAME, szNULL); // clear it
  349. LoadString(hAppInstance, IDS_FORMATCOMPLETE, szTitle, sizeof(szTitle));
  350. LoadString(hAppInstance, IDS_FORMATANOTHER, szMessage, sizeof(szMessage));
  351. wsprintf(szBuf, szMessage, GetTotalDiskSpace((WORD)iFormatDrive), GetFreeDiskSpace((WORD)iFormatDrive));
  352. if (MessageBox(hDlg, szBuf, szTitle, MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2) != IDYES) {
  353. EndDialog(hDlg, TRUE);
  354. }
  355. }
  356. #if 0
  357. // this doesn't work quite right
  358. // refresh all windows open on this drive
  359. for (hwnd = GetWindow(hwndMDIClient, GW_CHILD);
  360. hwnd;
  361. hwnd = GetWindow(hwnd, GW_HWNDNEXT)) {
  362. // refresh windows on this drive
  363. if (iFormatDrive == (INT)GetWindowLong(hwnd, GWL_TYPE))
  364. SendMessage(hwnd, FS_CHANGEDRIVES, 0, 0L);
  365. }
  366. #endif
  367. }
  368. break;
  369. default:
  370. return FALSE;
  371. }
  372. break;
  373. default:
  374. if (wMsg == wHelpMessage) {
  375. DoHelp:
  376. WFHelp(hDlg);
  377. return TRUE;
  378. } else
  379. return FALSE;
  380. }
  381. return TRUE;
  382. }
  383. /*--------------------------------------------------------------------------*/
  384. /* */
  385. /* ProgressDlgProc() - */
  386. /* */
  387. /*--------------------------------------------------------------------------*/
  388. INT_PTR
  389. APIENTRY
  390. ProgressDlgProc(
  391. register HWND hDlg,
  392. UINT wMsg,
  393. WPARAM wParam,
  394. LPARAM lParam
  395. )
  396. {
  397. switch (wMsg) {
  398. case WM_INITDIALOG:
  399. /* Check if this is the dialog for DISKCOPY */
  400. if (GetDlgItem(hDlg, IDD_DRIVE)) {
  401. /* Yes! Then, tell the user the drive we are copying from. */
  402. LoadString(hAppInstance, IDS_DRIVETEMP, szTitle, sizeof(szTitle));
  403. wsprintf(szMessage, szTitle, (CHAR)('A' + iCurrentDrive), '.');
  404. SetDlgItemText(hDlg, IDD_DRIVE, szMessage);
  405. }
  406. break;
  407. case WM_COMMAND:
  408. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  409. case IDCANCEL:
  410. bUserAbort = TRUE;
  411. break;
  412. default:
  413. return FALSE;
  414. }
  415. break;
  416. default:
  417. return FALSE;
  418. }
  419. return TRUE;
  420. }
  421. // update all the windows and things after drives have been connected
  422. // or disconnected.
  423. VOID
  424. APIENTRY
  425. UpdateConnections()
  426. {
  427. HWND hwnd, hwndNext;
  428. INT i, iDrive;
  429. HCURSOR hCursor;
  430. hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  431. ShowCursor(TRUE);
  432. cDrives = UpdateDriveList(); // updates rgiDrive[]
  433. InitDriveBitmaps();
  434. // close all windows that have the current drive set to
  435. // the one we just disconnected
  436. for (hwnd = GetWindow(hwndMDIClient, GW_CHILD); hwnd; hwnd = hwndNext) {
  437. hwndNext = GetWindow(hwnd, GW_HWNDNEXT);
  438. // ignore the titles and search window
  439. if (GetWindow(hwnd, GW_OWNER) || hwnd == hwndSearch)
  440. continue;
  441. iDrive = GetWindowLong(hwnd, GWL_TYPE);
  442. if (IsValidDisk(iDrive)) {
  443. // refresh drive bar only
  444. SendMessage(hwnd, FS_CHANGEDRIVES, 0, 0L);
  445. } else {
  446. // this drive has gone away
  447. if (IsLastWindow()) {
  448. // disconecting the last drive
  449. // set this guy to the first non floppy
  450. for (i = 0; i < cDrives; i++) {
  451. if (!IsRemovableDrive(rgiDrive[i])) {
  452. SendMessage(HasDrivesWindow(hwnd), FS_SETDRIVE, i, 0L);
  453. break;
  454. }
  455. }
  456. } else
  457. SendMessage(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0L);
  458. }
  459. }
  460. ShowCursor(FALSE);
  461. SetCursor(hCursor);
  462. }
  463. BOOL
  464. DisconnectDrive(
  465. HWND hDlg,
  466. INT iDrive
  467. )
  468. {
  469. CHAR szTemp[MAXPATHLEN];
  470. CHAR szDrive[5];
  471. INT ret, nIsNet;
  472. // don't allow disconnecting from the system directory
  473. GetSystemDirectory(szTemp, sizeof(szTemp));
  474. SheChangeDir(szTemp); // to fix confused lanman
  475. if (iDrive == (INT)(*szTemp - 'A')) {
  476. LoadString(hAppInstance, IDS_NETERR, szTitle, sizeof(szTitle));
  477. LoadString(hAppInstance, IDS_NETDISCONWINERR, szMessage, sizeof(szMessage));
  478. MessageBox(hDlg, szMessage, szTitle, MB_OK | MB_ICONSTOP);
  479. return FALSE;
  480. }
  481. lstrcpy(szDrive, "A:");
  482. szDrive[0] = (CHAR)('A'+iDrive);
  483. nIsNet = IsNetDrive((WORD)iDrive);
  484. ret = WNetCancelConnection(szDrive, FALSE); // don't force this
  485. // remove from the permanent connection list (even in error case)
  486. WriteProfileString(szNetwork, szDrive, szNULL);
  487. if (nIsNet != 2 && ret != WN_SUCCESS && ret != WN_NOT_CONNECTED) {
  488. LoadString(hAppInstance, IDS_NETERR, szTitle, sizeof(szTitle));
  489. if (ret == WN_OPEN_FILES)
  490. LoadString(hAppInstance, (UINT)IDS_NETDISCONOPEN, szMessage, sizeof(szMessage));
  491. else
  492. WNetErrorText((WORD)ret, szMessage, sizeof(szMessage));
  493. MessageBox(hDlg, szMessage, szTitle, MB_OK | MB_ICONSTOP);
  494. return FALSE;
  495. }
  496. return TRUE;
  497. }
  498. VOID
  499. FillDrives(
  500. HWND hDlg
  501. )
  502. {
  503. INT i, iDrive, count = 0;
  504. CHAR szDrive[4];
  505. CHAR szTemp[120];
  506. HWND hwndLB, hwndCB;
  507. hwndLB = GetDlgItem(hDlg, IDD_DRIVE1);
  508. hwndCB = GetDlgItem(hDlg, IDD_DRIVE);
  509. SendMessage(hwndCB, CB_RESETCONTENT, 0, 0L);
  510. SendMessage(hwndLB, LB_RESETCONTENT, 0, 0L);
  511. // fill the list of drives to connect to...
  512. lstrcpy(szDrive, "A:");
  513. iDrive = 0;
  514. for (i = 0; i < 26; i++) {
  515. if (rgiDrive[iDrive] == i) {
  516. iDrive++;
  517. } else {
  518. if (i == 1)
  519. continue; // skip B:?
  520. szDrive[0] = (CHAR)('A'+i);
  521. // WN_BAD_LOCALNAME means the drive is not sutable for
  522. // making a connection to (lastdrive limit, etc).
  523. if (WFGetConnection(szDrive, szTemp, TRUE) == WN_BAD_LOCALNAME)
  524. continue;
  525. SendMessage(hwndCB, CB_INSERTSTRING, -1, (LPARAM)szDrive);
  526. }
  527. }
  528. SendMessage(hwndCB, CB_SETCURSEL, 0, 0L);
  529. SendMessage(hwndLB, WM_SETREDRAW, FALSE, 0L);
  530. for (i = 0; i < cDrives; i++) {
  531. if (IsRemoteDrive(rgiDrive[i])) {
  532. szTemp[0] = (CHAR)('A' + rgiDrive[i]);
  533. szTemp[1] = ':';
  534. szTemp[2] = 0;
  535. lstrcpy(szDrive,szTemp);
  536. szTemp[2] = ' ';
  537. if (WFGetConnection(szDrive, szTemp+3, FALSE) != WN_SUCCESS)
  538. continue;
  539. count++;
  540. SendMessage(hwndLB, LB_INSERTSTRING, -1, (LPARAM)szTemp);
  541. }
  542. }
  543. SendMessage(hwndLB, WM_SETREDRAW, TRUE, 0L);
  544. InvalidateRect(hwndLB, NULL, TRUE);
  545. SendMessage(hwndLB, LB_SETCURSEL, 0, 0L);
  546. EnableWindow(GetDlgItem(hDlg, IDD_DISCONNECT), count);
  547. }
  548. LPSTR pszPrevPath;
  549. /*--------------------------------------------------------------------------*/
  550. /* */
  551. /* ConnectDlgProc() - */
  552. /* */
  553. /*--------------------------------------------------------------------------*/
  554. INT_PTR
  555. APIENTRY
  556. ConnectDlgProc(
  557. register HWND hDlg,
  558. UINT wMsg,
  559. WPARAM wParam,
  560. LPARAM lParam
  561. )
  562. {
  563. BOOL bPrevs;
  564. CHAR szDrive[4];
  565. CHAR szPath[WNBD_MAX_LENGTH], szPathSave[WNBD_MAX_LENGTH];
  566. CHAR szPassword[32];
  567. HCURSOR hCursor;
  568. switch (wMsg) {
  569. case WM_INITDIALOG:
  570. hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  571. ShowCursor(TRUE);
  572. FillDrives(hDlg);
  573. if (!(WNetGetCaps(WNNC_CONNECTION) & WNNC_CON_BROWSEDIALOG))
  574. EnableWindow(GetDlgItem(hDlg, IDD_NETBROWSE), FALSE);
  575. SendDlgItemMessage(hDlg, IDD_PATH, EM_LIMITTEXT, sizeof(szPath)-1, 0L);
  576. SendDlgItemMessage(hDlg, IDD_PASSWORD, EM_LIMITTEXT, sizeof(szPassword)-1, 0L);
  577. /* Are there any Previous connections? */
  578. bPrevs = (GetPrivateProfileString(szPrevious, NULL, szNULL,
  579. szPath, sizeof(szPath)-1, szTheINIFile) != 0);
  580. EnableWindow(GetDlgItem(hDlg, IDD_PREV), bPrevs);
  581. ShowCursor(FALSE);
  582. SetCursor(hCursor);
  583. break;
  584. case WM_COMMAND:
  585. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  586. case IDD_HELP:
  587. goto DoHelp;
  588. case IDOK:
  589. {
  590. HCURSOR hCursor;
  591. LPSTR p;
  592. UINT id;
  593. hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  594. ShowCursor(TRUE);
  595. GetDlgItemText(hDlg, IDD_DRIVE, szDrive, sizeof(szDrive));
  596. GetDlgItemText(hDlg, IDD_PATH, szPath, sizeof(szPath));
  597. GetDlgItemText(hDlg, IDD_PASSWORD, szPassword, sizeof(szPassword));
  598. lstrcpy(szPathSave, szPath); // may have comments
  599. // support saving extra stuff after the first double space
  600. // put a NULL in at the first double space
  601. p = szPath;
  602. while (*p && *p != ' ')
  603. p = AnsiNext(p);
  604. if (*(p + 1) == ' ')
  605. *p = 0;
  606. if ((id = WNetAddConnection(szPath, szPassword, szDrive)) != WN_SUCCESS) {
  607. ShowCursor(FALSE);
  608. SetCursor(hCursor);
  609. LoadString(hAppInstance, IDS_NETERR, szTitle, sizeof(szTitle));
  610. WNetErrorText(id, szMessage, sizeof(szMessage));
  611. MessageBox(hDlg, szMessage, szTitle, MB_OK | MB_ICONSTOP);
  612. break;
  613. }
  614. UpdateConnections();
  615. InvalidateVolTypes();
  616. FillDrives(hDlg);
  617. SetDlgItemText(hDlg, IDD_PATH, szNULL);
  618. SetDlgItemText(hDlg, IDD_PASSWORD, szNULL);
  619. // always add to previous...
  620. WritePrivateProfileString(szPrevious, szPathSave, szNULL, szTheINIFile);
  621. // store the connection in win.ini for reconect at
  622. // startup if the winnet driver does not support this
  623. // itself
  624. //
  625. // allow SHIFT to make the connection not permenent
  626. if (!(WNetGetCaps(WNNC_CONNECTION) & WNNC_CON_RESTORECONNECTION) &&
  627. (GetKeyState(VK_SHIFT) >= 0))
  628. WriteProfileString(szNetwork, szDrive, szPath);
  629. ShowCursor(FALSE);
  630. SetCursor(hCursor);
  631. break;
  632. }
  633. case IDCANCEL:
  634. EndDialog(hDlg, TRUE);
  635. break;
  636. case IDD_NETBROWSE:
  637. // if (WNetBrowseDialog(hDlg, WNBD_CONN_DISKTREE, szPath) == WN_SUCCESS)
  638. // SetDlgItemText(hDlg, IDD_PATH, szPath);
  639. break;
  640. case IDD_DISCONNECT:
  641. hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  642. ShowCursor(TRUE);
  643. wParam = (WPARAM)SendDlgItemMessage(hDlg, IDD_DRIVE1, LB_GETCURSEL, 0, 0L);
  644. SendDlgItemMessage(hDlg, IDD_DRIVE1, LB_GETTEXT, wParam, (LPARAM)szPath);
  645. if (DisconnectDrive(hDlg, (INT)(szPath[0] - 'A'))) {
  646. SendDlgItemMessage(hDlg, IDD_DRIVE1, LB_DELETESTRING, wParam, 0L);
  647. UpdateConnections();
  648. FillDrives(hDlg);
  649. SendMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlg, IDD_PATH), 1L);
  650. }
  651. ShowCursor(FALSE);
  652. SetCursor(hCursor);
  653. break;
  654. case IDD_PREV:
  655. {
  656. DWORD dwSave = dwContext;
  657. dwContext = IDH_DLG_PREV;
  658. pszPrevPath = szPath;
  659. if (DialogBox(hAppInstance, MAKEINTRESOURCE(PREVIOUSDLG), hDlg, PreviousDlgProc) > 0) {
  660. SetDlgItemText(hDlg, IDD_PATH, pszPrevPath);
  661. GetPrivateProfileString(szPrevious, pszPrevPath, szNULL, szPassword, 12, szTheINIFile);
  662. SetDlgItemText(hDlg, IDD_PASSWORD, szNULL);
  663. SendMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlg, IDD_PASSWORD), 1L);
  664. }
  665. dwContext = dwSave;
  666. break;
  667. }
  668. case IDD_DRIVE:
  669. if (GET_WM_COMMAND_CMD(wParam, lParam) == CBN_SELCHANGE) {
  670. if (GetDlgItemText(hDlg,IDD_DRIVE,szDrive,3)) {
  671. if (WFGetConnection(szDrive,szPath,FALSE) == WN_SUCCESS)
  672. SetDlgItemText(hDlg,IDD_PATH,szPath);
  673. }
  674. }
  675. break;
  676. case IDD_PATH:
  677. if (!(wParam = GetDlgItemText(hDlg,IDD_PATH,szPath,64)) &&
  678. GetFocus()==GetDlgItem(hDlg, IDOK))
  679. SendMessage(hDlg, WM_NEXTDLGCTL,
  680. (WPARAM)GetDlgItem(hDlg, IDCANCEL), 1L);
  681. EnableWindow(GetDlgItem(hDlg,IDOK),wParam ? TRUE : FALSE);
  682. SendMessage(hDlg, DM_SETDEFID, wParam ? IDOK : IDCANCEL, 0L);
  683. break;
  684. default:
  685. return FALSE;
  686. }
  687. break;
  688. default:
  689. if (wMsg == wHelpMessage) {
  690. DoHelp:
  691. WFHelp(hDlg);
  692. return TRUE;
  693. } else
  694. return FALSE;
  695. }
  696. return TRUE;
  697. }
  698. INT_PTR
  699. APIENTRY
  700. DrivesDlgProc(
  701. HWND hDlg,
  702. UINT wMsg,
  703. WPARAM wParam,
  704. LPARAM lParam
  705. )
  706. {
  707. INT nDrive, iSel;
  708. HWND hwndDrives, hwndActive;
  709. CHAR szTemp[MAXPATHLEN];
  710. CHAR szVolShare[MAXPATHLEN];
  711. UNREFERENCED_PARAMETER(lParam);
  712. switch (wMsg) {
  713. case WM_INITDIALOG:
  714. {
  715. INT nCurDrive;
  716. INT nIndex;
  717. nCurDrive = GetSelectedDrive();
  718. nIndex = 0;
  719. for (nDrive=0; nDrive < cDrives; nDrive++) {
  720. if (IsRemovableDrive(rgiDrive[nDrive])) // avoid flopies
  721. szVolShare[0] = (CHAR)NULL;
  722. else
  723. GetVolShare((WORD)rgiDrive[nDrive], szVolShare);
  724. if (nCurDrive == rgiDrive[nDrive])
  725. nIndex = nDrive;
  726. wsprintf(szTemp, "%c: %s", rgiDrive[nDrive] + 'A', (LPSTR)szVolShare);
  727. SendDlgItemMessage(hDlg, IDD_DRIVE, LB_ADDSTRING, 0, (LPARAM)szTemp);
  728. }
  729. SendDlgItemMessage(hDlg, IDD_DRIVE, LB_SETCURSEL, nIndex, 0L);
  730. break;
  731. }
  732. case WM_COMMAND:
  733. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  734. case IDD_HELP:
  735. goto DoHelp;
  736. case IDD_DRIVE:
  737. if (GET_WM_COMMAND_CMD(wParam, lParam) != LBN_DBLCLK)
  738. break;
  739. // fall through
  740. case IDOK:
  741. iSel = (INT)SendDlgItemMessage(hDlg, IDD_DRIVE, LB_GETCURSEL, 0, 0L);
  742. EndDialog(hDlg, TRUE);
  743. hwndActive = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  744. if (hwndDrives = HasDrivesWindow(hwndActive)) {
  745. SendMessage(hwndDrives, FS_SETDRIVE, iSel, 0L);
  746. }
  747. break;
  748. case IDCANCEL:
  749. EndDialog(hDlg, FALSE);
  750. break;
  751. }
  752. break;
  753. default:
  754. if (wMsg == wHelpMessage) {
  755. DoHelp:
  756. WFHelp(hDlg);
  757. return TRUE;
  758. } else
  759. return FALSE;
  760. }
  761. return TRUE;
  762. }
  763. /*--------------------------------------------------------------------------*/
  764. /* */
  765. /* PreviousDlgProc() - */
  766. /* */
  767. /*--------------------------------------------------------------------------*/
  768. INT_PTR
  769. APIENTRY
  770. PreviousDlgProc(
  771. register HWND hDlg,
  772. UINT wMsg,
  773. WPARAM wParam,
  774. LPARAM lParam
  775. )
  776. {
  777. HWND hwndLB;
  778. INT iSel;
  779. CHAR szTemp[64];
  780. hwndLB = GetDlgItem(hDlg, IDD_PREV);
  781. switch (wMsg) {
  782. case WM_INITDIALOG:
  783. {
  784. WORD nSize;
  785. LPSTR pstrT;
  786. LPSTR szBuffer;
  787. /*** FIX30: We should be able to process a partial buffer here. ***/
  788. /* Get the connections out of WINFILE.INI. */
  789. nSize = 256;
  790. if (!(szBuffer = (LPSTR)LocalAlloc(LPTR, nSize))) {
  791. PreviousDlgExit:
  792. EndDialog(hDlg, FALSE);
  793. break;
  794. }
  795. while ((INT)GetPrivateProfileString(szPrevious,
  796. NULL, szNULL,
  797. szBuffer, nSize,
  798. szTheINIFile) == (INT)nSize-2) {
  799. nSize += 512;
  800. LocalFree((HANDLE)szBuffer);
  801. if (!(szBuffer = (LPSTR)LocalAlloc(LPTR, nSize)))
  802. goto PreviousDlgExit;
  803. }
  804. /* Put the connections into the list box. */
  805. pstrT = szBuffer;
  806. while (*pstrT) {
  807. SendMessage(hwndLB, LB_ADDSTRING, 0, (LPARAM)pstrT);
  808. while (*pstrT)
  809. pstrT++;
  810. pstrT++;
  811. }
  812. LocalFree((HANDLE)szBuffer);
  813. SendMessage(hwndLB, LB_SETCURSEL, 0, 0L);
  814. break;
  815. }
  816. case WM_COMMAND:
  817. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  818. case IDD_HELP:
  819. goto DoHelp;
  820. case IDD_DELETE:
  821. iSel = (INT)SendMessage(hwndLB, LB_GETCURSEL, 0, 0L);
  822. if (iSel == LB_ERR)
  823. break;
  824. SendMessage(hwndLB, LB_GETTEXT, iSel, (LPARAM)szTemp);
  825. SendMessage(hwndLB, LB_DELETESTRING, iSel, 0L);
  826. SendMessage(hwndLB, LB_SETCURSEL, 0, 0L);
  827. WritePrivateProfileString(szPrevious, szTemp, NULL, szTheINIFile);
  828. break;
  829. case IDD_PREV:
  830. if (GET_WM_COMMAND_CMD(wParam, lParam) != LBN_DBLCLK)
  831. return FALSE;
  832. /*** FALL THRU ***/
  833. case IDOK:
  834. // return the selection through this global
  835. *pszPrevPath = TEXT('\0');
  836. iSel = (INT)SendMessage(hwndLB, LB_GETCURSEL, 0, 0L);
  837. if (iSel != LB_ERR)
  838. SendMessage(hwndLB, LB_GETTEXT, iSel, (LPARAM)pszPrevPath);
  839. EndDialog(hDlg, TRUE);
  840. break;
  841. case IDCANCEL:
  842. EndDialog(hDlg, FALSE);
  843. break;
  844. default:
  845. return FALSE;
  846. }
  847. break;
  848. default:
  849. if (wMsg == wHelpMessage) {
  850. DoHelp:
  851. WFHelp(hDlg);
  852. return TRUE;
  853. } else
  854. return FALSE;
  855. }
  856. return TRUE;
  857. }