Leaked source code of windows server 2003
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.

621 lines
15 KiB

  1. /* File: C:\WACKER\TDLL\send_dlg.c (Created: 22-Dec-1993)
  2. * created from:
  3. * File: C:\WACKER\TDLL\genrcdlg.c (Created: 16-Ded-1993)
  4. * created from:
  5. * File: C:\HA5G\ha5g\genrcdlg.c (Created: 12-Sep-1990)
  6. *
  7. * Copyright 1990,1994 by Hilgraeve Inc. -- Monroe, MI
  8. * All rights reserved
  9. *
  10. * $Revision: 18 $
  11. * $Date: 7/08/02 6:46p $
  12. */
  13. #include <windows.h>
  14. #pragma hdrstop
  15. #include <time.h>
  16. #include "stdtyp.h"
  17. #include "mc.h"
  18. #include "tdll.h"
  19. #include "misc.h"
  20. #include <tdll\assert.h>
  21. #include <term\res.h>
  22. #include "session.h"
  23. #include "file_msc.h"
  24. #include "load_res.h"
  25. #include "open_msc.h"
  26. #include "errorbox.h"
  27. #include "globals.h"
  28. #include "cnct.h"
  29. #include "htchar.h"
  30. #include "xfer_msc.h"
  31. #include "xfer_msc.hh"
  32. #include <xfer\xfer.h>
  33. #include "hlptable.h"
  34. #if !defined(DlgParseCmd)
  35. #define DlgParseCmd(i,n,c,w,l) i=LOWORD(w);n=HIWORD(w);c=(HWND)l;
  36. #endif
  37. struct stSaveDlgStuff
  38. {
  39. /*
  40. * Put in whatever else you might need to access later
  41. */
  42. HSESSION hSession;
  43. TCHAR acDirectory[FNAME_LEN];
  44. };
  45. typedef struct stSaveDlgStuff SDS;
  46. #define IDC_TF_FILENAME 100
  47. #define FNAME_EDIT 101
  48. #define BROWSE_BTN 102
  49. #define IDC_TF_PROTOCOL 103
  50. #define PROTO_COMBO 104
  51. #define IDC_PB_CLOSE 105
  52. #define FOLDER_LABEL 106
  53. #define FOLDER_NAME 107
  54. #define IDC_PB_SEND 108
  55. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  56. * FUNCTION: TransferSendDlg
  57. *
  58. * DESCRIPTION: Dialog manager stub
  59. *
  60. * ARGUMENTS: Standard Windows dialog manager
  61. *
  62. * RETURNS: Standard Windows dialog manager
  63. *
  64. */
  65. INT_PTR CALLBACK TransferSendDlg(HWND hDlg, UINT wMsg, WPARAM wPar, LPARAM lPar)
  66. {
  67. INT nReturn = TRUE;
  68. HWND hwndChild;
  69. INT nId;
  70. INT nNtfy;
  71. SDS *pS;
  72. int nIndex;
  73. int nState;
  74. int nProto;
  75. int nChars = 0;
  76. int nXferSendReturn = 0;
  77. TCHAR acBuffer[FNAME_LEN];
  78. TCHAR acTitle[64];
  79. TCHAR acList[64];
  80. LPTSTR pszStr;
  81. LPTSTR *pszArray;
  82. LPTSTR pszRet;
  83. HCURSOR hCursor;
  84. XFR_PARAMS *pP;
  85. XFR_PROTOCOL *pX;
  86. HSESSION hSession;
  87. HXFER hXfer = NULL;
  88. XD_TYPE *pT = NULL;
  89. static DWORD aHlpTable[] = {FNAME_EDIT, IDH_TERM_SEND_FILENAME,
  90. IDC_TF_FILENAME, IDH_TERM_SEND_FILENAME,
  91. BROWSE_BTN, IDH_BROWSE,
  92. IDC_TF_PROTOCOL, IDH_TERM_SEND_PROTOCOL,
  93. PROTO_COMBO, IDH_TERM_SEND_PROTOCOL,
  94. IDC_PB_SEND, IDH_TERM_SEND_SEND,
  95. IDC_PB_CLOSE, IDH_OK,
  96. IDOK, IDH_OK,
  97. IDCANCEL, IDH_CANCEL,
  98. 0, 0};
  99. switch (wMsg)
  100. {
  101. case WM_INITDIALOG:
  102. {
  103. TCHAR achDirectory[MAX_PATH];
  104. DWORD dwStyle = SS_WORDELLIPSIS;
  105. hSession = (HSESSION)lPar;
  106. pS = (SDS *)malloc(sizeof(SDS));
  107. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pS);
  108. if (pS == (SDS *)0)
  109. {
  110. /* TODO: decide if we need to display an error here */
  111. EndDialog(hDlg, FALSE);
  112. break;
  113. }
  114. SendMessage(GetDlgItem(hDlg, FNAME_EDIT),
  115. EM_SETLIMITTEXT,
  116. FNAME_LEN, 0);
  117. pS->hSession = hSession;
  118. mscCenterWindowOnWindow(hDlg, GetParent(hDlg));
  119. pP = (XFR_PARAMS *)0;
  120. xfrQueryParameters(sessQueryXferHdl(hSession), (VOID **)&pP);
  121. assert(pP);
  122. /*
  123. * Load selections into the PROTOCOL COMBO box
  124. */
  125. nState = pP->nSndProtocol;
  126. nProto = 0;
  127. mscResetComboBox(GetDlgItem(hDlg, PROTO_COMBO));
  128. pX = (XFR_PROTOCOL *)0;
  129. xfrGetProtocols(hSession, &pX);
  130. assert(pX);
  131. if (pX != (XFR_PROTOCOL *)0)
  132. {
  133. for (nIndex = 0; pX[nIndex].nProtocol != 0; nIndex += 1)
  134. {
  135. if (nState == pX[nIndex].nProtocol)
  136. nProto = nIndex;
  137. //jmh 02-13-96 Use CB_ADDSTRING to sort entries as
  138. // they are added. CB_INSERTSTRING doesn't do this,
  139. // even if the combo-box has the CBS_SORT style.
  140. SendMessage(GetDlgItem(hDlg, PROTO_COMBO),
  141. CB_ADDSTRING,
  142. 0,
  143. (LPARAM)&pX[nIndex].acName[0]);
  144. }
  145. SendMessage(GetDlgItem(hDlg, PROTO_COMBO),
  146. CB_SELECTSTRING,
  147. 0,
  148. (LPARAM) &pX[nProto].acName[0]);
  149. free(pX);
  150. pX = NULL;
  151. }
  152. PostMessage(hDlg, WM_COMMAND,
  153. PROTO_COMBO,
  154. MAKELONG(GetDlgItem(hDlg, PROTO_COMBO),CBN_SELCHANGE));
  155. StrCharCopyN(pS->acDirectory,
  156. filesQuerySendDirectory(sessQueryFilesDirsHdl(hSession)), FNAME_LEN);
  157. // The send button should always be disabled when we start. It
  158. // will be enabled when the user types in a file name. - cab:12/06/96
  159. //
  160. EnableWindow(GetDlgItem(hDlg, IDC_PB_SEND), FALSE);
  161. // Initialize the folder name field.
  162. //
  163. if (GetWindowsMajorVersion() > 4)
  164. {
  165. dwStyle = SS_PATHELLIPSIS;
  166. }
  167. TCHAR_Fill(achDirectory, TEXT('\0'), MAX_PATH);
  168. StrCharCopyN(achDirectory, pS->acDirectory, MAX_PATH);
  169. mscModifyToFit(GetDlgItem(hDlg, FOLDER_NAME), achDirectory, dwStyle);
  170. SetDlgItemText(hDlg, FOLDER_NAME, achDirectory);
  171. /* Set the focus to the file name */
  172. SetFocus(GetDlgItem(hDlg, FNAME_EDIT));
  173. nReturn = FALSE;
  174. }
  175. break;
  176. case WM_DESTROY:
  177. mscResetComboBox(GetDlgItem(hDlg, PROTO_COMBO));
  178. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  179. if (pS)
  180. {
  181. free(pS);
  182. pS = NULL;
  183. }
  184. break;
  185. case WM_CONTEXTMENU:
  186. doContextHelp(aHlpTable, wPar, lPar, TRUE, TRUE);
  187. break;
  188. case WM_HELP:
  189. doContextHelp(aHlpTable, wPar, lPar, FALSE, FALSE);
  190. break;
  191. case WM_COMMAND:
  192. /*
  193. * Did we plan to put a macro in here to do the parsing ?
  194. */
  195. DlgParseCmd(nId, nNtfy, hwndChild, wPar, lPar);
  196. switch (nId)
  197. {
  198. case IDC_PB_SEND:
  199. case IDOK:
  200. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  201. assert(pS);
  202. if (pS == NULL)
  203. {
  204. break;
  205. }
  206. hSession = pS->hSession;
  207. assert(hSession);
  208. if (hSession == NULL)
  209. {
  210. break;
  211. }
  212. hXfer = sessQueryXferHdl(hSession);
  213. assert(hXfer);
  214. if (hXfer == NULL)
  215. {
  216. break;
  217. }
  218. //
  219. // See if a file transfer is currently in progress.
  220. //
  221. pT = (XD_TYPE *)hXfer;
  222. assert(pT);
  223. if (pT == (XD_TYPE *)0)
  224. {
  225. break;
  226. }
  227. else if (pT->nDirection != XFER_NONE)
  228. {
  229. nXferSendReturn = XFR_IN_PROGRESS;
  230. }
  231. else if(cnctQueryStatus(sessQueryCnctHdl(hSession))
  232. != CNCT_STATUS_TRUE && nId == IDC_PB_SEND)
  233. {
  234. //
  235. // We are currently not connected (loss of carrier),
  236. // so disable the Recieve button. REV: 9/7/2001
  237. //
  238. nXferSendReturn = XFR_NO_CARRIER;
  239. mscMessageBeep(MB_ICONHAND);
  240. EnableWindow(GetDlgItem(hDlg, IDC_PB_SEND), FALSE);
  241. }
  242. else
  243. {
  244. pP = (XFR_PARAMS *)0;
  245. xfrQueryParameters(hXfer, (VOID **)&pP);
  246. assert(pP);
  247. /*
  248. * Save selection from the PROTOCOL COMBO box
  249. */
  250. pX = (XFR_PROTOCOL *)0;
  251. xfrGetProtocols(hSession, &pX);
  252. assert(pX);
  253. if (pX != (XFR_PROTOCOL *)0)
  254. {
  255. GetDlgItemText(hDlg, PROTO_COMBO, acBuffer, FNAME_LEN);
  256. for (nIndex = 0; pX[nIndex].nProtocol != 0; nIndex += 1)
  257. {
  258. if (StrCharCmp(acBuffer, pX[nIndex].acName) == 0)
  259. {
  260. pP->nSndProtocol = pX[nIndex].nProtocol;
  261. break;
  262. }
  263. }
  264. free(pX);
  265. pX = NULL;
  266. }
  267. GetDlgItemText(hDlg, FNAME_EDIT, acBuffer, FNAME_LEN);
  268. fileFinalizeName(
  269. acBuffer,
  270. pS->acDirectory,
  271. acBuffer,
  272. FNAME_LEN);
  273. /* Split the name and the directory */
  274. pszStr = StrCharFindLast(acBuffer, TEXT('\\'));
  275. if (pszStr)
  276. {
  277. *pszStr++ = TEXT('\0');
  278. }
  279. if (nId == IDC_PB_SEND)
  280. {
  281. int nIdx = 0;
  282. hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  283. nIndex = 0;
  284. pszArray = NULL;
  285. fileBuildFileList((void **)&pszArray,
  286. &nIndex,
  287. pszStr,
  288. FALSE,
  289. acBuffer);
  290. nIdx = nIndex;
  291. if (nIndex == 0)
  292. {
  293. if (sessQuerySound(hSession))
  294. {
  295. mscMessageBeep(MB_ICONHAND);
  296. }
  297. LoadString(glblQueryDllHinst(),
  298. IDS_ER_XFER_NO_FILE,
  299. acBuffer,
  300. FNAME_LEN);
  301. TimedMessageBox(hDlg,
  302. acBuffer,
  303. NULL,
  304. MB_OK | MB_ICONEXCLAMATION,
  305. sessQueryTimeout(hSession)
  306. );
  307. if (pszArray)
  308. {
  309. free(pszArray);
  310. pszArray = NULL;
  311. }
  312. break;
  313. }
  314. while (nIndex-- > 0)
  315. {
  316. nXferSendReturn = xfrSendAddToList(hXfer, pszArray[nIndex]);
  317. free(pszArray[nIndex]);
  318. pszArray[nIndex] = NULL;
  319. if (nXferSendReturn == XFR_NO_MEMORY)
  320. {
  321. //
  322. // Make sure to free the rest of the file
  323. // list when a memory error is returned
  324. // from xfrSendAddToList(). REV: 2/4/2002
  325. //
  326. while (--nIndex >= 0)
  327. {
  328. if (pszArray[nIndex])
  329. {
  330. free(pszArray[nIndex]);
  331. pszArray[nIndex] = NULL;
  332. }
  333. }
  334. break;
  335. }
  336. }
  337. if (pszArray)
  338. {
  339. while (--nIdx >= 0)
  340. {
  341. if (pszArray[nIdx])
  342. {
  343. free(pszArray[nIdx]);
  344. pszArray[nIdx] = NULL;
  345. }
  346. }
  347. free(pszArray);
  348. pszArray = NULL;
  349. }
  350. if (nXferSendReturn == XFR_NO_MEMORY)
  351. {
  352. //
  353. // There was a memory error, so free the
  354. // file list and exit here.
  355. //
  356. XD_TYPE *pXD_Type;
  357. // pXD_Type = (XD_TYPE *)sessQueryXferHdl(hSession);
  358. pXD_Type = (XD_TYPE *)hXfer;
  359. if (pXD_Type != (XD_TYPE *)0)
  360. {
  361. /* Clear list */
  362. for (nIndex = pXD_Type->nSendListCount - 1; nIndex >=0; nIndex--)
  363. {
  364. if (pXD_Type->acSendNames[nIndex])
  365. {
  366. free(pXD_Type->acSendNames[nIndex]);
  367. pXD_Type->acSendNames[nIndex] = NULL;
  368. }
  369. pXD_Type->nSendListCount = nIndex;
  370. }
  371. free(pXD_Type->acSendNames);
  372. pXD_Type->acSendNames = NULL;
  373. pXD_Type->nSendListCount = 0;
  374. }
  375. break;
  376. }
  377. SetCursor(hCursor);
  378. nXferSendReturn = xfrSendListSend(hXfer);
  379. }
  380. }
  381. //
  382. // Don't save the settings if a file transfer is in
  383. // progress otherwise the current file transfer could
  384. // get corrupted. REV: 08/06/2001.
  385. //
  386. if (nXferSendReturn == XFR_IN_PROGRESS)
  387. {
  388. TCHAR acMessage[256];
  389. if (sessQuerySound(hSession))
  390. {
  391. mscMessageBeep(MB_ICONHAND);
  392. }
  393. LoadString(glblQueryDllHinst(),
  394. IDS_ER_XFER_SEND_IN_PROCESS,
  395. acMessage,
  396. sizeof(acMessage) / sizeof(TCHAR));
  397. TimedMessageBox(sessQueryHwnd(hSession),
  398. acMessage,
  399. NULL,
  400. MB_OK | MB_ICONEXCLAMATION,
  401. sessQueryTimeout(hSession));
  402. }
  403. else if(nXferSendReturn == XFR_NO_CARRIER)
  404. {
  405. //
  406. // We are currently not connected (loss of carrier),
  407. // so disable the Send button.
  408. //
  409. mscMessageBeep(MB_ICONHAND);
  410. EnableWindow(GetDlgItem(hDlg, IDC_PB_SEND), FALSE);
  411. }
  412. else
  413. {
  414. /*
  415. * Do whatever saving is necessary
  416. */
  417. xfrSetParameters(hXfer, (VOID *)pP);
  418. if (mscIsDirectory(acBuffer))
  419. {
  420. filesSetSendDirectory(sessQueryFilesDirsHdl(hSession),
  421. acBuffer);
  422. }
  423. /* Free the storeage */
  424. EndDialog(hDlg, TRUE);
  425. }
  426. break;
  427. case XFER_CNCT:
  428. if(nXferSendReturn == XFR_NO_CARRIER)
  429. {
  430. //
  431. // We are currently not connected (loss of carrier),
  432. // so disable the Send button.
  433. //
  434. mscMessageBeep(MB_ICONHAND);
  435. EnableWindow(GetDlgItem(hDlg, IDC_PB_SEND), FALSE);
  436. }
  437. else
  438. {
  439. EnableWindow(GetDlgItem(hDlg, IDC_PB_SEND), TRUE);
  440. }
  441. break;
  442. case FNAME_EDIT:
  443. // This dialog would crash if the user pressed 'Send' and no
  444. // filename was specified. Ideally, the 'Send' button should
  445. // be disabled until we have a filename. - cab:12/06/96
  446. //
  447. if ( nNtfy == EN_UPDATE )
  448. {
  449. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  450. hSession = pS->hSession;
  451. // Are we connected? If not, leave the send button disabled.
  452. //
  453. if ( cnctQueryStatus(sessQueryCnctHdl(hSession))
  454. == CNCT_STATUS_TRUE )
  455. {
  456. // Get the number of characters in the edit box.
  457. //
  458. nChars = (int)SendMessage(GetDlgItem(hDlg, FNAME_EDIT),
  459. EM_LINELENGTH, 0, 0);
  460. EnableWindow(GetDlgItem(hDlg, IDC_PB_SEND), nChars != 0);
  461. }
  462. }
  463. break;
  464. case IDCANCEL:
  465. EndDialog(hDlg, FALSE);
  466. break;
  467. case BROWSE_BTN:
  468. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  469. LoadString(glblQueryDllHinst(),
  470. IDS_SND_DLG_FILE,
  471. acTitle,
  472. sizeof(acTitle) / sizeof(TCHAR));
  473. resLoadFileMask(glblQueryDllHinst(),
  474. IDS_CMM_ALL_FILES1,
  475. 1,
  476. acList,
  477. sizeof(acList) / sizeof(TCHAR));
  478. pszRet = gnrcFindFileDialog(hDlg,
  479. acTitle,
  480. pS->acDirectory,
  481. acList);
  482. if (pszRet != NULL)
  483. {
  484. DWORD dwStyle = SS_WORDELLIPSIS;
  485. TCHAR achDirectory[MAX_PATH];
  486. TCHAR_Fill(achDirectory, TEXT('\0'), MAX_PATH);
  487. SetDlgItemText(hDlg, FNAME_EDIT, pszRet);
  488. mscStripName(pszRet);
  489. pszStr = StrCharLast(pszRet);
  490. // Remove the trailing backslash from the name
  491. // returned from mscStripName. Leave it on
  492. // in the case of a root directory specification.
  493. //
  494. if (pszStr > pszRet + (3 * sizeof(TCHAR)) )
  495. {
  496. if (pszStr && ( *pszStr == TEXT('\\') || *pszStr == TEXT('/')))
  497. *pszStr = TEXT('\0');
  498. }
  499. if (GetWindowsMajorVersion() > 4)
  500. {
  501. dwStyle = SS_PATHELLIPSIS;
  502. }
  503. mscModifyToFit(GetDlgItem(hDlg, FOLDER_NAME), pszRet, dwStyle);
  504. SetDlgItemText(hDlg, FOLDER_NAME, pszRet);
  505. free(pszRet);
  506. pszRet = NULL;
  507. }
  508. break;
  509. default:
  510. nReturn = FALSE;
  511. break;
  512. }
  513. break;
  514. default:
  515. nReturn = FALSE;
  516. break;
  517. }
  518. return nReturn;
  519. }