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.

1021 lines
31 KiB

  1. /*===========================================================================*/
  2. /* Copyright (c) 1987 - 1988, Future Soft Engineering, Inc. */
  3. /* Houston, Texas */
  4. /*===========================================================================*/
  5. #define NOGDICAPMASKS TRUE
  6. #define NOICONS TRUE
  7. #define NOKEYSTATES TRUE
  8. #define NOSYSCOMMANDS TRUE
  9. #define NOATOM TRUE
  10. #define NOCLIPBOARD TRUE
  11. #define NODRAWTEXT TRUE
  12. #define NOMINMAX TRUE
  13. #define NOOPENFILE TRUE
  14. #define NOSCROLL TRUE
  15. #define NOHELP TRUE
  16. #define NOPROFILER TRUE
  17. #define NODEFERWINDOWPOS TRUE
  18. #define NOPEN TRUE
  19. #define NO_TASK_DEFINES TRUE
  20. #define NOLSTRING TRUE
  21. #define WIN31 TRUE
  22. #include <windows.h>
  23. #include <port1632.h>
  24. #include <dcrc.h> /* mbbx 2.00 ... */
  25. #include "commdlg.h"
  26. #include <dynacomm.h>
  27. #include <fileopen.h>
  28. #include "dlgs.h"
  29. #include <direct.h> /* adding this for chdir prototype -sdj*/
  30. /*---------------------------------------------------------------------------*/
  31. /* FileOpen() - [mbb] */
  32. /*---------------------------------------------------------------------------*/
  33. VOID NEAR PASCAL PoundToNull(LPSTR str)
  34. {
  35. while(*str)
  36. {
  37. if(*str == '#')
  38. *str = 0x00;
  39. str++;
  40. }
  41. }
  42. VOID NEAR PASCAL LoadFilterString(HANDLE hInst,WORD ResID,LPSTR szFilter,
  43. INT len,DWORD *FilterIndex)
  44. {
  45. switch(ResID)
  46. {
  47. case FO_DBSNDTEXT:
  48. case FO_DBRCVTEXT:
  49. LoadString(hInst,STR_FILTERALL,
  50. &szFilter[LoadString(hInst,STR_FILTERTXT,szFilter,len)],len);
  51. *FilterIndex = 1;
  52. break;
  53. case FO_DBSNDFILE:
  54. case FO_DBRCVFILE:
  55. LoadString(hInst,STR_FILTERALL,szFilter,len);
  56. *FilterIndex = 1;
  57. break;
  58. default:
  59. LoadString(hInst,STR_FILTERTRM,szFilter,len);
  60. *FilterIndex = 1;
  61. }
  62. PoundToNull(szFilter);
  63. }
  64. VOID NEAR PASCAL AddDirMod(CHAR *path)
  65. {
  66. INT len=0;
  67. while(path[len]){
  68. if(path[len] == '.')
  69. return;
  70. if(++len == (FO_MAXPATHLENGTH-1)){
  71. *path = 0;
  72. return;
  73. }
  74. }
  75. path[len] = '\\';
  76. path[len+1] = 0;
  77. }
  78. BOOL FileOpen(BYTE *filePath, BYTE *fileName1,BYTE *fileName2, BYTE *fileExt,BYTE * titleText,WORD wResID,DLGPROC lpFilter, WORD wMode)
  79. {
  80. BOOL FileOpen = FALSE;
  81. // -sdj was unreferenced local var: LPDTA saveDTA;
  82. BYTE savePath[FO_MAXPATHLENGTH];
  83. FILEOPENDATA FOData;
  84. // -sdj was unreferenced local var: BYTE work[80];
  85. HWND whichParent;
  86. CHAR szFilter[75]; /* default filter text/spec. for above */
  87. CHAR szFileName[STR255]; /* Fully qualified name of file */
  88. OPENFILENAME OFN;
  89. INT rc;
  90. #ifndef BUGBYPASS
  91. if (TRUE)
  92. #else
  93. if(setPath(filePath, FALSE, savePath))
  94. #endif
  95. {
  96. setFilePath(fileName1);
  97. strcpy(FOData.file1, fileName1);
  98. strcpy(FOData.file2, (fileName2 != NULL) ? fileName2 : NULL_STR);
  99. strcpy(FOData.extent, fileExt);
  100. strcpy(FOData.title, (titleText != NULL) ? titleText : NULL_STR);
  101. FOData.wResID = ((wResID != 0) ? wResID : (!(wMode & FO_PUTFILE) ? FO_DBFILEOPEN : FO_DBFILESAVE)); /* mbbx 1.10: CUA... */
  102. FOData.lpFilter = lpFilter;
  103. FOData.wMode = wMode;
  104. pFOData = &FOData;
  105. whichParent = GetActiveWindow();
  106. if ( (whichParent == NULL) || (!IsChild(hItWnd,whichParent)) )
  107. whichParent = hItWnd; /* jtf 3.15 */
  108. /* OFN structure intialization for common open dialog. 02/19/91*/
  109. LoadFilterString(hInst,FOData.wResID,szFilter,sizeof(szFilter),&OFN.nFilterIndex);
  110. szFileName[0] = '\0';
  111. OFN.lStructSize = sizeof(OPENFILENAME);
  112. OFN.lpstrTitle = NULL; /* Address later to whichever dialog*/
  113. OFN.lpstrCustomFilter = NULL;
  114. OFN.nMaxCustFilter = 0L;
  115. OFN.lpstrDefExt = NULL; /* ?? address later forcing trm. */
  116. OFN.lpstrInitialDir = NULL;
  117. OFN.lpstrFile = szFileName;
  118. OFN.nMaxFile = sizeof(szFileName);
  119. OFN.lpfnHook = dbFileOpen;
  120. OFN.lCustData = 0L;
  121. OFN.lpTemplateName = MAKEINTRESOURCE(FOData.wResID);
  122. OFN.hInstance = hInst;
  123. OFN.hwndOwner = whichParent;
  124. OFN.Flags = OFN_HIDEREADONLY|OFN_ENABLETEMPLATE|OFN_ENABLEHOOK;
  125. OFN.lpstrFileTitle = NULL;
  126. OFN.nMaxFileTitle = 0L;
  127. OFN.lpstrFilter = szFilter;
  128. if((FOData.wResID == FO_DBFILESAVE) ||
  129. (FOData.wResID == FO_DBRCVFILE) ||
  130. (FOData.wResID == FO_DBRCVTEXT))
  131. {
  132. FileOpen = GetSaveFileName(&OFN);
  133. }
  134. else
  135. {
  136. FileOpen = GetOpenFileName(&OFN);
  137. }
  138. if(rc = CommDlgExtendedError())
  139. {
  140. testBox(whichParent,-(MB_ICONHAND|MB_SYSTEMMODAL|MB_OK),STR_ERRCAPTION,NoMemStr);
  141. FileOpen = FALSE;
  142. }
  143. #ifdef ORGCODE
  144. _getcwd(filePath);
  145. #else
  146. _getcwd(filePath,PATHLEN);
  147. #endif
  148. if(FileOpen)
  149. {
  150. // sdj: the way this code is working right now, terminal
  151. // sdj: calls the commdlg fileopen with a dbFileOpen hook
  152. // sdj: function which saves FOData.file with just the name
  153. // sdj: part of the file, and the called of FileOpen does
  154. // sdj: the cat of getcwd with this filename. This is broken
  155. // sdj: in case where terminal sets chdir to c:\ and commdlg
  156. // sdj: while exiting sets the dir back to where it was so
  157. // sdj: instead of c:\boot.ini user views d:\...\boot.ini!
  158. // sdj: solution is to set filename1 to FileName part of szfilename
  159. // sdj: which is what comdlg gives as a FQN and set filePath to
  160. // sdj: the path part of this. it is very unlikely that commdlg
  161. // sdj: will return szFileName with no '\\' in it but if strrchr
  162. // sdj: fails, stick with the original pathrelated bug!
  163. if (strrchr(szFileName,'\\'))
  164. {
  165. strcpy(fileName1,(strrchr(szFileName,'\\')+1));
  166. *(strrchr(szFileName,'\\')) = 0;
  167. strcpy(filePath,szFileName);
  168. }
  169. else{
  170. switch(FOData.wResID)
  171. {
  172. case FO_DBRCVFILE:
  173. case FO_DBRCVTEXT:
  174. strcpy(fileName1, FOData.file);
  175. break;
  176. case FO_DBFILESAVE:
  177. strcpy(fileName1, szFileName);
  178. break;
  179. default:
  180. strcpy(fileName1, FOData.file1);
  181. break;
  182. }/* switch(resID) */
  183. }// end of if{!strrchr}else{sw:original stuff}
  184. if(fileName2 != NULL)
  185. strcpy(fileName2, FOData.file2);
  186. if(!OFN.nFileExtension)
  187. {
  188. if(!strchr(fileName1, '.'))
  189. strcat(fileName1, ".");
  190. }
  191. else if(FOData.wMode & FO_FORCEEXTENT)
  192. {
  193. if(strchr(fileExt, '.'))
  194. strcpy(fileExt, strchr(fileExt, '.') + 1);
  195. if(strchr(fileName1, '.'))
  196. {
  197. strcpy(strchr(fileName1, '.') + 1, fileExt);
  198. }
  199. else
  200. {
  201. strcat(fileName1, ".");
  202. strcat(fileName1, fileExt);
  203. }
  204. }
  205. else
  206. strcpy(fileExt, FOData.extent);
  207. if(wResID == FO_DBFILETYPE)
  208. FileOpen = FOData.nType;
  209. }
  210. setPath(savePath, FALSE, NULL);
  211. }
  212. SetFocus(hTermWnd);
  213. return(FileOpen);
  214. }
  215. /*---------------------------------------------------------------------------*/
  216. /* dbFileOpen() - [mbb] */
  217. /*---------------------------------------------------------------------------*/
  218. INT_PTR APIENTRY dbFileOpen(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  219. {
  220. BOOL result;
  221. BYTE OEMname[STR255]; /* jtf 3.20 */
  222. BYTE savePath[STR255]; /* rjs bugs 018 */
  223. updateTimer(); /* code specific to DynaComm!!! */
  224. switch(message)
  225. {
  226. case WM_INITDIALOG:
  227. // use the OFN stuct to set this
  228. if(*(pFOData->title) != 0)
  229. SetWindowText(hDlg, pFOData->title); /* jtf terminal */
  230. SendDlgItemMessage(hDlg, edt1, EM_LIMITTEXT, FO_MAXPATHLENGTH, 0L);
  231. SendDlgItemMessage(hDlg, edt1, EM_SETSEL, GET_EM_SETSEL_MPS(0, MAKELONG(0,32767)));
  232. if(pFOData->wResID == FO_DBFILETYPE) /* mbbx 1.10: CUA... */
  233. (*(pFOData->lpFilter)) (hDlg, message, wParam, lParam); /* mbbx 2.00: new FO hook scheme... */
  234. switch(pFOData->wResID) /* mbbx 2.00: new FO hook scheme... */
  235. {
  236. case FO_DBFILETYPE:
  237. break;
  238. case FO_DBSNDFILE:
  239. case FO_DBRCVFILE:
  240. ShowWindow(GetDlgItem(hDlg, FO_IDPROMPT2), SW_HIDE);
  241. ShowWindow(GetDlgItem(hDlg, FO_IDFILENAME2), SW_HIDE);
  242. SendDlgItemMessage(hDlg, FO_IDFILENAME2, EM_LIMITTEXT, FO_MAXPATHLENGTH, 0L);
  243. break;
  244. default:
  245. if(pFOData->lpFilter != NULL)
  246. (*(pFOData->lpFilter)) (hDlg, message, wParam, lParam);
  247. break;
  248. }
  249. if((pFOData->wMode & FO_PUTFILE) && !FO_SaveFileName(hDlg)) /* mbbx 2.00 ... */
  250. {
  251. SetDlgItemText(hDlg, edt1, pFOData->file1);
  252. strcpy(pFOData->title, pFOData->file1);
  253. }
  254. if(pFOData->lpFilter != NULL) /* jtf 3.22 */
  255. (*(pFOData->lpFilter)) (hDlg, message, wParam, lParam);
  256. return(TRUE); /* Bug 7115, let dlgmgr set focus. clarkc */
  257. case WM_COMMAND:
  258. switch(GET_WM_COMMAND_ID(wParam, lParam))
  259. {
  260. case IDOK:
  261. {
  262. HWND focus = GetFocus();
  263. if(focus == GetDlgItem(hDlg,edt1) ||
  264. focus == GetDlgItem(hDlg,lst1) ||
  265. focus == GetDlgItem(hDlg,IDOK))
  266. {
  267. if((pFOData->wMode & FO_GETFILENAME2) && (pFOData->wMode & FO_NONDOSFILE))
  268. {
  269. if(!GetDlgItemText(hDlg, edt1, pFOData->file2, FO_MAXPATHLENGTH))
  270. pFOData->wMode &= ~FO_GETFILENAME2;
  271. if(!GetDlgItemText(hDlg, FO_IDFILENAME2, pFOData->file, FO_MAXPATHLENGTH))
  272. strcpy(pFOData->file, (pFOData->wMode & FO_GETFILENAME2) ? pFOData->file2 : pFOData->file1);
  273. }
  274. else
  275. {
  276. if(!GetDlgItemText(hDlg, edt1, pFOData->file, FO_MAXPATHLENGTH))
  277. strcpy(pFOData->file, pFOData->file1);
  278. if(pFOData->wMode & FO_GETFILENAME2)
  279. if(!GetDlgItemText(hDlg, FO_IDFILENAME2, pFOData->file2, FO_MAXPATHLENGTH))
  280. pFOData->wMode &= ~FO_GETFILENAME2;
  281. }
  282. result = TRUE;
  283. break;
  284. }
  285. else
  286. return(FALSE);
  287. }
  288. case IDCANCEL:
  289. *(pFOData->file2) = 0;
  290. pFOData->wMode &= ~FO_GETFILENAME2;
  291. result = FALSE;
  292. break;
  293. case edt1:
  294. if(GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE)
  295. {
  296. if(!((pFOData->wMode & FO_BATCHMODE) && (pFOData->wMode & FO_PUTFILE))) /* mbbx 1.01: ymodem */
  297. EnableWindow(GetDlgItem(hDlg, IDOK), (BOOL)SendDlgItemMessage(hDlg, edt1, WM_GETTEXTLENGTH, 0, 0L));
  298. if(pFOData->wMode & FO_GETFILENAME2)
  299. {
  300. *(pFOData->file2) = 0;
  301. pFOData->wMode &= ~FO_GETFILENAME2;
  302. ShowWindow(GetDlgItem(hDlg, FO_IDPROMPT2), SW_HIDE);
  303. ShowWindow(GetDlgItem(hDlg, FO_IDFILENAME2), SW_HIDE);
  304. }
  305. if(pFOData->lpFilter != NULL) /* mbbx 2.00: new FO hook scheme... */
  306. (*(pFOData->lpFilter)) (hDlg, message, wParam, lParam);
  307. }
  308. return(FALSE);
  309. case lst1:
  310. if(GET_WM_COMMAND_CMD(wParam, lParam) == LBN_SELCHANGE)
  311. {
  312. FO_SetListItem(hDlg, lst1, FALSE);
  313. if(pFOData->lpFilter != NULL) /* mbbx 2.00: new FO hook scheme... */
  314. (*(pFOData->lpFilter)) (hDlg, message, wParam, lParam);
  315. return(FALSE);
  316. }
  317. result = TRUE;
  318. if(GET_WM_COMMAND_CMD(wParam, lParam) == LBN_DBLCLK)
  319. break;
  320. return(FALSE);
  321. break;
  322. default:
  323. switch(pFOData->wResID) /* mbbx 2.00: new FO hook scheme... */
  324. {
  325. case FO_DBFILETYPE: /* mbbx 1.10: CUA... */
  326. /* BUG BUG, what does this call, wParam/lParam may need fixing!*/
  327. if(!(*(pFOData->lpFilter)) (hDlg, message, wParam, lParam))
  328. {
  329. SetDlgItemText(hDlg, FO_IDFILENAME, pFOData->file1);
  330. }
  331. break;
  332. default:
  333. if(pFOData->lpFilter != NULL)
  334. (*(pFOData->lpFilter)) (hDlg, message, wParam, lParam);
  335. break;
  336. }
  337. return(FALSE);
  338. }
  339. break;
  340. default:
  341. return(FALSE);
  342. }
  343. if(result)
  344. {
  345. if(!setPath(pFOData->file, TRUE, savePath))
  346. {
  347. FO_ErrProc(STRDRIVEDIR, MB_OK | MB_ICONHAND, hDlg);
  348. return(FO_SetCtrlFocus(hDlg, GetFocus()));
  349. }
  350. if(!((pFOData->wMode & FO_BATCHMODE) && (GetKeyState(VK_CONTROL) & 0x8000))) /* mbbx 1.01: ymodem */
  351. {
  352. AnsiUpper(pFOData->file);
  353. strcpy(pFOData->file1, pFOData->file);
  354. if(FO_AddFileType(pFOData->file, pFOData->extent))
  355. return(FALSE);
  356. if(!FO_IsLegalDOSFN(pFOData->file)) /* mbbx 2.00: no forced extents... */
  357. {
  358. if(((pFOData->wMode & FO_NONDOSFILE) && (pFOData->wMode & FO_GETFILENAME2)) ||
  359. (!(pFOData->wMode & FO_NONDOSFILE) && !(pFOData->wMode & FO_GETFILENAME2)) ||
  360. !FO_IsLegalFN(pFOData->file))
  361. {
  362. FO_ErrProc(FO_STR_BADFILENAME, MB_OK | MB_ICONHAND,hDlg);
  363. return(FO_SetCtrlFocus(hDlg, GetFocus()));
  364. }
  365. else if(!(pFOData->wMode & FO_GETFILENAME2))
  366. {
  367. pFOData->wMode |= FO_GETFILENAME2;
  368. ShowWindow(GetDlgItem(hDlg, FO_IDPROMPT2), SW_SHOW);
  369. ShowWindow(GetDlgItem(hDlg, FO_IDFILENAME2), SW_SHOW);
  370. return(FO_SetCtrlFocus(hDlg, GetFocus()));
  371. }
  372. }
  373. if(!getFileType(pFOData->file, pFOData->extent)) /* mbbx 2.00 ... */
  374. {
  375. forceExtension(pFOData->file, pFOData->extent+2, FALSE); /* mbbx 2.00: no forced extents... */
  376. }
  377. // JYF -- replace these two lines with the below if() to remove the use of AnsiToOem()
  378. //
  379. //AnsiToOem(pFOData->file, (LPSTR) OEMname); /* jtf 3.20 */
  380. //if((pFOData->wMode & FO_FILEEXIST) && !fileExist(OEMname)) /* jtf 3.20 */
  381. if ((pFOData->wMode & FO_FILEEXIST) && !fileExist(pFOData->file))
  382. {
  383. /* rjs bugs 018 */
  384. if(!(pFOData->wMode & FO_PUTFILE)) /* mbbx 1.10: CUA... */
  385. DlgDirList(hDlg, pFOData->file, lst1, 0, FO_LBFILE);
  386. else
  387. strcpy(pFOData->file, pFOData->title);
  388. SetDlgItemText(hDlg, ((pFOData->wMode & FO_GETFILENAME2) && (pFOData->wMode & FO_NONDOSFILE)) ?
  389. FO_IDFILENAME2 : FO_IDFILENAME, pFOData->file);
  390. setFilePath(savePath);
  391. /* end of rjs bugs 018 */
  392. FO_ErrProc(FO_STR_FILENOTFOUND, MB_OK | MB_ICONHAND,hDlg);
  393. return(FO_SetCtrlFocus(hDlg, GetFocus()));
  394. }
  395. if((pFOData->wMode & FO_REMOTEFILE) && !(pFOData->wMode & FO_GETFILENAME2))
  396. {
  397. pFOData->wMode |= FO_GETFILENAME2;
  398. SetDlgItemText(hDlg, FO_IDFILENAME2, pFOData->file);
  399. ShowWindow(GetDlgItem(hDlg, FO_IDPROMPT2), SW_SHOW);
  400. ShowWindow(GetDlgItem(hDlg, FO_IDFILENAME2), SW_SHOW);
  401. return(FO_SetCtrlFocus(hDlg, GetDlgItem(hDlg, FO_IDFILENAME2)));
  402. }
  403. // JYF -- replace these two lines with following if() to remove the use of AnsiToOem()
  404. //
  405. //AnsiToOem(pFOData->file, (LPSTR) OEMname); /* jtf 3.20 */
  406. //if(((pFOData->wMode & (FO_PUTFILE | FO_FILEEXIST)) == FO_PUTFILE) && fileExist(OEMname)) /* jtf 3.20 */
  407. if (((pFOData->wMode & (FO_PUTFILE | FO_FILEEXIST)) == FO_PUTFILE) && fileExist(pFOData->file))
  408. {
  409. if(FO_ErrProc(FO_STR_REPLACEFILE, MB_YESNO | MB_ICONEXCLAMATION,hDlg) == IDNO)
  410. return(FO_SetCtrlFocus(hDlg, GetFocus()));
  411. }
  412. }
  413. AnsiUpper(pFOData->file); /* mbbx 2.00: new FO hook scheme... */
  414. strcpy(pFOData->file1, pFOData->file);
  415. AnsiUpper(pFOData->file2);
  416. }
  417. if(pFOData->lpFilter != NULL) /* mbbx 2.00: new FO hook scheme... */
  418. (*(pFOData->lpFilter)) (hDlg, WM_NULL, result, 0L);
  419. return(FALSE);
  420. }
  421. /*---------------------------------------------------------------------------*/
  422. /* FO_SaveFileName() - [mbb] */
  423. /*---------------------------------------------------------------------------*/
  424. BOOL NEAR FO_SaveFileName(HWND hDlg)
  425. {
  426. register BYTE *pch;
  427. GetDlgItemText(hDlg, ((pFOData->wMode & FO_GETFILENAME2) && (pFOData->wMode & FO_NONDOSFILE)) ?
  428. FO_IDFILENAME2 : edt1, pFOData->file, 32);
  429. for(pch = pFOData->file; *pch != 0; pch += 1)
  430. if((*pch == '*') || (*pch == '?') || (*pch == '\\') || (*pch == ':'))
  431. return(FALSE);
  432. strcpy(pFOData->title, pFOData->file);
  433. return(TRUE);
  434. }
  435. /*---------------------------------------------------------------------------*/
  436. /* FO_SetListItem() - [mbb] */
  437. /*---------------------------------------------------------------------------*/
  438. VOID NEAR FO_SetListItem(HWND hDlg,WORD wCtrlID,BOOL bSetSel)
  439. {
  440. if(bSetSel)
  441. SendDlgItemMessage(hDlg, wCtrlID, LB_SETCURSEL, 0, 0L);
  442. if(SendDlgItemMessage(hDlg, wCtrlID, LB_GETCURSEL, 0, 0L) != LB_ERR)
  443. {
  444. MDlgDirSelect(hDlg, pFOData->file, FO_MAXFILELENGTH, wCtrlID);
  445. if(wCtrlID == lst2)
  446. {
  447. FO_NewFilePath(hDlg, ((pFOData->wMode & FO_GETFILENAME2) && (pFOData->wMode & FO_NONDOSFILE)) ?
  448. FO_IDFILENAME2 : edt1, pFOData->file, pFOData->extent);
  449. }
  450. SetDlgItemText(hDlg, ((pFOData->wMode & FO_GETFILENAME2) && (pFOData->wMode & FO_NONDOSFILE)) ?
  451. FO_IDFILENAME2 : edt1, pFOData->file);
  452. }
  453. }
  454. /*---------------------------------------------------------------------------*/
  455. /* FO_NewFilePath() - [mbb] */
  456. /*---------------------------------------------------------------------------*/
  457. VOID NEAR FO_NewFilePath(HWND hDlg, WORD wCtrlID,BYTE *fileName,BYTE *fileExt)
  458. {
  459. register BYTE *pch;
  460. BOOL bWild;
  461. BYTE tempName[FO_MAXPATHLENGTH];
  462. GetDlgItemText(hDlg, wCtrlID, tempName, FO_MAXPATHLENGTH);
  463. pch = tempName+(strlen(tempName)-1);
  464. bWild = ((*pch == '*') || (*pch == ':'));
  465. while(pch > tempName)
  466. {
  467. pch--;
  468. if((*pch == '*') || (*pch == '?'))
  469. bWild = TRUE;
  470. if((*pch == '\\') || (*pch == ':'))
  471. {
  472. pch++;
  473. break;
  474. }
  475. }
  476. if(bWild)
  477. strcpy(fileName+strlen(fileName), pch);
  478. else
  479. strcpy(fileName+strlen(fileName), fileExt+1);
  480. }
  481. /*---------------------------------------------------------------------------*/
  482. /* FO_AddFileType() - [mbb] */
  483. /*---------------------------------------------------------------------------*/
  484. BOOL NEAR FO_AddFileType(BYTE *fileName, BYTE *fileExt)
  485. {
  486. register BYTE *pch;
  487. INT j;
  488. BOOL bWild;
  489. if((pch = fileName+strlen(fileName)) == fileName)
  490. j = 1;
  491. else if((pch == fileName+2) && (fileName[0] == '.') && (fileName[1] == '.'))
  492. j = 0;
  493. else
  494. {
  495. bWild = FALSE; /* mbbx 2.00: no forced extents... */
  496. while(--pch >= fileName)
  497. {
  498. if((*pch == '*') || (*pch == '?'))
  499. {
  500. bWild = TRUE;
  501. break;
  502. }
  503. }
  504. if(getFileType(fileName, fileExt))
  505. return(bWild);
  506. pch = fileName+strlen(fileName);
  507. j = ((*(pch-1) == '\\') ? 1 : (bWild ? 2 : 0));
  508. }
  509. //sdj: if the extention is "\*.*" which it would be if someone is doing
  510. //sdj: recvfile open with "test" as name, why add \*.* to test?
  511. //sdj: it is ok to do this for open/save/saveas where you can force .trm
  512. //sdj: not not in other cases of opening the file
  513. if (*fileExt == '\\' && *(fileExt+1) == '*' && *(fileExt+2) == '.')
  514. {
  515. return FALSE;
  516. }
  517. strcpy(pch, fileExt+j);
  518. return(TRUE);
  519. }
  520. /*---------------------------------------------------------------------------*/
  521. /* FO_StripFileType() - [mbb] */
  522. /*---------------------------------------------------------------------------*/
  523. VOID NEAR FO_StripFileType(BYTE *fileName)
  524. {
  525. register BYTE *pch;
  526. for(pch = fileName+(strlen(fileName)-1); pch > fileName; pch--)
  527. {
  528. if(*pch == '\\')
  529. {
  530. *pch = 0;
  531. break;
  532. }
  533. }
  534. }
  535. /*---------------------------------------------------------------------------*/
  536. /* FO_IsLegalDOSFN() - [mbb] */
  537. /*---------------------------------------------------------------------------*/
  538. #define FO_MAXDOSFILELEN FO_MAXFILELENGTH //-sdj bug#4587 fix
  539. // -sdj this was 8 to check for dosfilename length. with ntfs filenames
  540. // -sdj being >8 this test used to fail. made maxdosfilelen to fo_maxfilelength
  541. // -sdj which is 16 at present. This will let users use prefix name upto
  542. // -sdj 16 chars, but still force them to have .trm extension, AND by
  543. // -sdj restricting the name to FO_MAXFILELENGTH, ensure that no other
  544. // -sdj global buffer overflows (most of the buffers use this define)
  545. // -sdj eventually, right solution is to set fo_maxfilelength to ntfs max
  546. // -sdj name, but this is an intermediate solution which is safe, and still
  547. // -sdj allow users upto 16 chars of trmfilenames.
  548. // -sdj along with this change the other change needed is to increase
  549. // -sdj the termData element sizes to > 12 which was a pain! this define
  550. // -sdj in dynacomm.h is increased to 32 for the time being.
  551. #define FO_MAXDOSEXTLEN 3
  552. BOOL NEAR FO_IsLegalDOSFN(BYTE *fileName)
  553. {
  554. register INT i;
  555. INT j;
  556. for(i = 0; fileName[i] == ' '; i++);
  557. if(i > 0)
  558. strcpy(fileName, fileName+i);
  559. for(i = 0; fileName[i] != 0; i++)
  560. {
  561. if(fileName[i] == '.')
  562. {
  563. for(j = 1; fileName[i+j] != 0; j++)
  564. {
  565. if((j > FO_MAXDOSEXTLEN) || !FO_IsLegalDOSCH(fileName[i+j]) || (fileName[i+j]=='.') ) /* jtf 3.31 */
  566. return(FALSE);
  567. }
  568. break;
  569. }
  570. if((i >= FO_MAXDOSFILELEN) || !FO_IsLegalDOSCH(fileName[i]))
  571. return(FALSE);
  572. }
  573. return(i != 0);
  574. }
  575. /*---------------------------------------------------------------------------*/
  576. /* FO_IsLegalDOSCH() - */
  577. /*---------------------------------------------------------------------------*/
  578. #define FO_NONDOSFNCHARS "\\/[]:|<>+=;,\""
  579. BOOL NEAR FO_IsLegalDOSCH(BYTE ch)
  580. {
  581. register BYTE *pch;
  582. if(ch <= ' ')
  583. return(FALSE);
  584. for(pch = FO_NONDOSFNCHARS; *pch != '\0'; pch++)
  585. {
  586. if(*pch == ch)
  587. return(FALSE);
  588. }
  589. return(TRUE);
  590. }
  591. /*---------------------------------------------------------------------------*/
  592. /* FO_IsLegalFN() - [scf] */
  593. /*---------------------------------------------------------------------------*/
  594. BOOL NEAR FO_IsLegalFN(BYTE *fileName)
  595. {
  596. return(TRUE);
  597. }
  598. /*---------------------------------------------------------------------------*/
  599. /* FO_ErrProc() - */
  600. /*---------------------------------------------------------------------------*/
  601. INT NEAR FO_ErrProc(WORD errMess, WORD errType, HWND hDlg)
  602. {
  603. BYTE temp1[STR255];
  604. BYTE temp2[STR255];
  605. GetWindowText(hItWnd, temp1, 254); /* mbbx 2.00: new FO hook scheme... */
  606. sscanf(temp1, "%s", temp2);
  607. LoadString(hInst, (errType & MB_ICONHAND) ? FO_STR_ERRCAPTION : FO_STR_WARNCAPTION, temp1, 80);
  608. strcpy(temp2+strlen(temp2), temp1);
  609. LoadString(hInst, errMess, temp1, 254);
  610. MessageBeep(0);
  611. return(MessageBox(hDlg, temp1, temp2, errType)); /* jtf 3.14 */
  612. }
  613. /*---------------------------------------------------------------------------*/
  614. /* FO_SetCtrlFocus() - [mbb] */
  615. /*---------------------------------------------------------------------------*/
  616. BOOL NEAR FO_SetCtrlFocus(HWND hDlg, HWND hCtrl)
  617. {
  618. if(hCtrl == NULL) /* mbbx 2.00 ... */
  619. hCtrl = GetDlgItem(hDlg, (pFOData->wMode & FO_GETFILENAME2) ? FO_IDFILENAME2 : edt1);
  620. #ifdef ORGCODE
  621. switch(GetWindowWord(hCtrl, GWW_ID))
  622. #else
  623. switch(GetWindowLong(hCtrl, GWL_ID))
  624. #endif
  625. {
  626. case edt1:
  627. case FO_IDFILENAME2:
  628. SendMessage(hCtrl, EM_SETSEL, GET_EM_SETSEL_MPS(0, 0x7FFF));
  629. break;
  630. case lst2:
  631. break;
  632. case lst1:
  633. if(SendMessage(hCtrl, LB_GETCURSEL, 0, 0L) != LB_ERR)
  634. break;
  635. case IDOK:
  636. if(pFOData->wMode & FO_PUTFILE)
  637. {
  638. hCtrl = GetDlgItem(hDlg, (pFOData->wMode & FO_GETFILENAME2) ? FO_IDFILENAME2 : edt1);
  639. SendMessage(hCtrl, EM_SETSEL, GET_EM_SETSEL_MPS(0, 0x7FFF));
  640. }
  641. else
  642. {
  643. hCtrl = GetDlgItem(hDlg, lst1);
  644. if(SendMessage(hCtrl, LB_GETCOUNT, 0, 0L) > 0)
  645. FO_SetListItem(hDlg, lst1, TRUE);
  646. else
  647. hCtrl = GetDlgItem(hDlg, lst2); /* mbbx 1.10: CUA... */
  648. }
  649. break;
  650. }
  651. SetFocus(hCtrl);
  652. return(TRUE);
  653. }
  654. /*---------------------------------------------------------------------------*/
  655. /* setPath() - [mbb] */
  656. /*---------------------------------------------------------------------------*/
  657. BOOL setPath(BYTE *newPath, BOOL bFileName, BYTE *oldPath)
  658. {
  659. BYTE work[FO_MAXPATHLENGTH];
  660. DEBOUT("Enter setPath: with newpath=%lx\n",newPath);
  661. DEBOUT(" setPath: with bFileName=%lx\n",bFileName);
  662. DEBOUT(" setPath: with oldPath=%lx\n",oldPath);
  663. if(oldPath)
  664. #ifdef ORGCODE
  665. { _getcwd(oldPath); }
  666. #else
  667. {
  668. _getcwd(oldPath,PATHLEN);
  669. DEBOUT("setPath: getcwd returned %s\n",oldPath);
  670. }
  671. #endif
  672. if(bFileName)
  673. {
  674. if(!setFilePath(newPath)){
  675. DEBOUT("setPath: setFilePath(newPath) returned 0, calling sFP(%lx) and ret FALSE\n",oldPath);
  676. setFilePath(oldPath);
  677. return(FALSE);
  678. }
  679. }
  680. else
  681. {
  682. strcpy(work, newPath);
  683. DEBOUT("setPath: bFil=0,call setfp and chdir with work as %s\n",work);
  684. if(!setFilePath(work) || ((work[0] != 0) && (_chdir(work) == -1))){
  685. DEBOUT("setPath: setFP(work) ret0||somethingelse, calling sFP(%lx) and ret FALSE\n",oldPath);
  686. setFilePath(oldPath);
  687. return(FALSE);
  688. }
  689. }
  690. return(TRUE);
  691. }
  692. /*---------------------------------------------------------------------------*/
  693. /* setFilePath() - [mbb] */
  694. /*---------------------------------------------------------------------------*/
  695. BOOL setFilePath(BYTE *fileName)
  696. {
  697. INT ndx;
  698. BYTE temp[FO_MAXPATHLENGTH];
  699. //sdj: just added to debug if chdir is working BYTE tmpgetcwd[PATHLEN];
  700. DEBOUT("Enter setFilePath with filename=%lx\n",fileName);
  701. #ifdef ORGCODE
  702. #else
  703. if (!fileName)
  704. {
  705. DEBOUT("setFilePath: HACK %s\n","called with 0 as filename");
  706. DEBOUT("setFilePath: HACK %s\n","setting chdir to c:\\nt");
  707. _chdir("C:\\NT");
  708. return TRUE;
  709. }
  710. #endif
  711. ndx = strlen(fileName);
  712. #ifdef ORGCODE
  713. if((ndx >= 2) && (fileName[1] == ':')) /* mbbx 2.00 ... */
  714. {
  715. if(fileName[0] > 'Z')
  716. fileName[0] -= ' ';
  717. if(!setdrive(fileName[0]))
  718. return(FALSE);
  719. strcpy(fileName, fileName+2);
  720. ndx -= 2; /* mbbx 2.00 */
  721. }
  722. #else
  723. /* in NT there is no concept of currentdrive AND currentWorkDir -sdj
  724. so dont do any setdrive, and keep the fileName as a fully -sdj
  725. qualified path name including the drive letter -sdj*/
  726. #endif
  727. while(--ndx >= 0) /* mbbx 2.00 ... */
  728. {
  729. if(fileName[ndx] == '\\')
  730. break;
  731. }
  732. if(ndx >= 0)
  733. {
  734. // sdj: 11may93: FileOpen
  735. strcpy(temp, fileName+ndx+1);
  736. if(ndx == 0)
  737. ndx += 1;
  738. fileName[ndx] = '\0';
  739. // -sdj fix for readcmdline not opening .trm file 03jun92
  740. //
  741. // if filename was c:\scratch\foo.trm, do chdir(c:\) not chdir(c:)
  742. // if chdir(c:) is done,later getcwd will not give c:\ but something else
  743. if (fileName[ndx-1] == ':')
  744. {
  745. fileName[ndx] = '\\';
  746. fileName[ndx+1] = '\0';
  747. }
  748. // end of fix
  749. if(_chdir(fileName) == -1)
  750. return(FALSE);
  751. //getcwd(tmpgetcwd,PATHLEN);
  752. strcpy(fileName, temp);
  753. }
  754. return(TRUE);
  755. }
  756. /*---------------------------------------------------------------------------*/
  757. /* forceExtension() - [mbb] */
  758. /*---------------------------------------------------------------------------*/
  759. VOID forceExtension(BYTE *fileName, BYTE *fileExt, BOOL bReplace)
  760. {
  761. register BYTE *pch;
  762. WORD len;
  763. for(pch = fileName+((len = strlen(fileName))-1); pch > fileName; pch -= 1)
  764. {
  765. if((*pch == '.') || (*pch == '\\'))
  766. break;
  767. }
  768. if((pch <= fileName) || (*pch != '.'))
  769. pch = fileName + len;
  770. else if(!bReplace)
  771. return;
  772. strcpy(pch, fileExt);
  773. while(*(++pch) != 0)
  774. if((*pch == '*') || (*pch == '?'))
  775. {
  776. *pch = 0;
  777. break;
  778. }
  779. }
  780. /*---------------------------------------------------------------------------*/
  781. /* getFileType() - [mbb] */
  782. /*---------------------------------------------------------------------------*/
  783. BOOL getFileType(BYTE *fileName, BYTE *fileExt)
  784. {
  785. register BYTE *pch;
  786. for(pch = fileName+(strlen(fileName)-1); pch > fileName; pch -= 1)
  787. {
  788. if(*pch == '.')
  789. {
  790. AnsiUpper(pch);
  791. forceExtension(fileExt, pch, TRUE); /* mbbx 2.00: no forced extents */
  792. return(TRUE);
  793. }
  794. else if(*pch == '\\')
  795. break;
  796. }
  797. return(FALSE);
  798. }
  799. #ifdef ORGCODE
  800. #else
  801. BOOL fileExist(LPSTR lpfilename)
  802. {
  803. HANDLE hFile;
  804. CHAR chCurDir[FO_MAXPATHLENGTH+1];
  805. DWORD dwRc;
  806. dwRc = GetCurrentDirectory(FO_MAXPATHLENGTH,chCurDir);
  807. DEBOUT("Rc of getcdir = %lx\n",dwRc);
  808. DEBOUT("Current Dir in which file is being opened=%s\n",chCurDir);
  809. DEBOUT("Existence being checked for the file=%s\n",lpfilename);
  810. hFile = CreateFile(lpfilename,
  811. GENERIC_READ, /* no access desired please */
  812. FILE_SHARE_READ|FILE_SHARE_WRITE, /* dont be greedy */
  813. NULL, /* no security */
  814. OPEN_EXISTING, /* open only if existing */
  815. FILE_ATTRIBUTE_NORMAL, /* who cares what attr it is */
  816. NULL); /* why do we need template here */
  817. if( (hFile == (HANDLE)-1) || (hFile == NULL) )
  818. {
  819. /* cant open this one, so return false, looks like doesnt exist */
  820. DEBOUT("fileExist FALSE: %s does not exit\n",lpfilename);
  821. return FALSE;
  822. }
  823. DEBOUT("fileExist TRUE: %s does exit\n",lpfilename);
  824. CloseHandle(hFile);
  825. return TRUE;
  826. }
  827. #endif