1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: getnames.c 1498 2010-01-18 00:57:01Z gyoung $
|
---|
5 |
|
---|
6 | Directory containers
|
---|
7 |
|
---|
8 | Copyright (c) 1993-98 M. Kimes
|
---|
9 | Copyright (c) 2006, 2010 Steven H. Levine
|
---|
10 |
|
---|
11 | 23 Aug 06 SHL Comments
|
---|
12 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
13 | 08 Mar 09 GKY Removed variable aurguments from docopyf and unlinkf (not used)
|
---|
14 | 28 Jun 09 GKY Added AddBackslashToPath() to remove repeatative code.
|
---|
15 | 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
|
---|
16 |
|
---|
17 | ***********************************************************************/
|
---|
18 |
|
---|
19 | #include <string.h>
|
---|
20 | #include <ctype.h>
|
---|
21 |
|
---|
22 | #define INCL_DOS
|
---|
23 | #define INCL_WIN
|
---|
24 | #define INCL_LONGLONG
|
---|
25 |
|
---|
26 | #include "fm3dll.h"
|
---|
27 | #include "fm3dll2.h" // #define's for UM_*, control id's, etc.
|
---|
28 | #include "notebook.h" // Data declaration(s)
|
---|
29 | #include "info.h" // Data declaration(s)
|
---|
30 | #include "init.h" // Data declaration(s)
|
---|
31 | #include "mainwnd.h" // Data declaration(s)
|
---|
32 | #include "fm3dlg.h"
|
---|
33 | #include "fm3str.h"
|
---|
34 | #include "errutil.h" // Dos_Error...
|
---|
35 | #include "strutil.h" // GetPString
|
---|
36 | #include "getnames.h"
|
---|
37 | #include "walkem.h" // load_udirs, remove_udir
|
---|
38 | #include "valid.h" // MakeFullName
|
---|
39 | #include "copyf.h" // unlinkf
|
---|
40 | #include "misc.h" // PaintRecessedWindow
|
---|
41 | #include "wrappers.h" // xDosFindFirst
|
---|
42 | #include "pathutil.h" // AddBackslashToPath
|
---|
43 |
|
---|
44 | #pragma data_seg(DATA1)
|
---|
45 |
|
---|
46 | MRESULT EXPENTRY CustomFileDlg(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
47 | {
|
---|
48 | switch (msg) {
|
---|
49 | case WM_INITDLG:
|
---|
50 | if (!loadedudirs)
|
---|
51 | load_udirs();
|
---|
52 | { /* fill user list box */
|
---|
53 | ULONG ulDriveNum, ulDriveMap;
|
---|
54 | ULONG ulSearchCount;
|
---|
55 | FILEFINDBUF3L findbuf;
|
---|
56 | HDIR hDir;
|
---|
57 | APIRET rc;
|
---|
58 | LINKDIRS *info, *temp;
|
---|
59 |
|
---|
60 | DosError(FERR_DISABLEHARDERR);
|
---|
61 | DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
---|
62 | info = udirhead;
|
---|
63 | while (info) {
|
---|
64 | if (IsFullName(info->path) &&
|
---|
65 | !(driveflags[toupper(*info->path) - 'A'] &
|
---|
66 | (DRIVE_IGNORE | DRIVE_INVALID))) {
|
---|
67 | DosError(FERR_DISABLEHARDERR);
|
---|
68 | hDir = HDIR_CREATE;
|
---|
69 | ulSearchCount = 1L;
|
---|
70 | if (!IsRoot(info->path))
|
---|
71 | rc = xDosFindFirst(info->path, &hDir, FILE_DIRECTORY |
|
---|
72 | MUST_HAVE_DIRECTORY | FILE_READONLY |
|
---|
73 | FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
|
---|
74 | &findbuf, sizeof(FILEFINDBUF3L),
|
---|
75 | &ulSearchCount, FIL_STANDARDL);
|
---|
76 | else {
|
---|
77 | rc = 0;
|
---|
78 | findbuf.attrFile = FILE_DIRECTORY;
|
---|
79 | }
|
---|
80 | if (!rc) {
|
---|
81 | if (!IsRoot(info->path))
|
---|
82 | DosFindClose(hDir);
|
---|
83 | if (findbuf.attrFile & FILE_DIRECTORY)
|
---|
84 | WinSendDlgItemMsg(hwnd, FDLG_USERDIRS, LM_INSERTITEM,
|
---|
85 | MPFROM2SHORT(LIT_SORTASCENDING, 0),
|
---|
86 | MPFROMP(info->path));
|
---|
87 | else {
|
---|
88 | temp = info->next;
|
---|
89 | remove_udir(info->path);
|
---|
90 | info = temp;
|
---|
91 | continue;
|
---|
92 | }
|
---|
93 | }
|
---|
94 | else if (!(ulDriveMap & (1L << (toupper(*info->path) - 'A')))) {
|
---|
95 | temp = info->next;
|
---|
96 | remove_udir(info->path);
|
---|
97 | info = temp;
|
---|
98 | continue;
|
---|
99 | }
|
---|
100 | }
|
---|
101 | info = info->next;
|
---|
102 | }
|
---|
103 | }
|
---|
104 | break;
|
---|
105 |
|
---|
106 | case WM_ADJUSTWINDOWPOS:
|
---|
107 | PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
|
---|
108 | break;
|
---|
109 |
|
---|
110 | case UM_SETDIR:
|
---|
111 | PaintRecessedWindow(WinWindowFromID(hwnd, FDLG_HELP),
|
---|
112 | (HPS) 0, FALSE, TRUE);
|
---|
113 | return 0;
|
---|
114 |
|
---|
115 | case WM_CONTROL:
|
---|
116 | switch (SHORT1FROMMP(mp1)) {
|
---|
117 | case 260: /* drives dropdown list */
|
---|
118 | switch (SHORT2FROMMP(mp1)) {
|
---|
119 | case CBN_SHOWLIST:
|
---|
120 | WinSetDlgItemText(hwnd,
|
---|
121 | FDLG_HELP, (CHAR *) GetPString(IDS_CLICKDRIVEHELPTEXT));
|
---|
122 | break;
|
---|
123 | }
|
---|
124 | break;
|
---|
125 |
|
---|
126 | case 258: /* name entry field */
|
---|
127 | switch (SHORT2FROMMP(mp1)) {
|
---|
128 | case EN_SETFOCUS:
|
---|
129 | WinSetDlgItemText(hwnd,
|
---|
130 | FDLG_HELP, (CHAR *) GetPString(IDS_ENTERFILEORMASKHELPTEXT));
|
---|
131 | break;
|
---|
132 | case EN_KILLFOCUS:
|
---|
133 | WinSetDlgItemText(hwnd, FDLG_HELP, (CHAR *) GetPString(IDS_NAMEDEFHELPTEXT));
|
---|
134 | break;
|
---|
135 | }
|
---|
136 | break;
|
---|
137 |
|
---|
138 | case 264: /* dirs listbox */
|
---|
139 | switch (SHORT2FROMMP(mp1)) {
|
---|
140 | case LN_SETFOCUS:
|
---|
141 | WinSetDlgItemText(hwnd,
|
---|
142 | FDLG_HELP, (CHAR *) GetPString(IDS_DBLCLKDIRSWITCHHELPTEXT));
|
---|
143 | break;
|
---|
144 | case LN_KILLFOCUS:
|
---|
145 | WinSetDlgItemText(hwnd, FDLG_HELP, (CHAR *) GetPString(IDS_NAMEDEFHELPTEXT));
|
---|
146 | break;
|
---|
147 | }
|
---|
148 | break;
|
---|
149 |
|
---|
150 | case 266: /* files listbox */
|
---|
151 | switch (SHORT2FROMMP(mp1)) {
|
---|
152 | case LN_SETFOCUS:
|
---|
153 | WinSetDlgItemText(hwnd, FDLG_HELP,
|
---|
154 | (CHAR *) GetPString(IDS_DBLCLKFILEUSEHELPTEXT));
|
---|
155 | break;
|
---|
156 | case LN_KILLFOCUS:
|
---|
157 | WinSetDlgItemText(hwnd, FDLG_HELP, (CHAR *) GetPString(IDS_NAMEDEFHELPTEXT));
|
---|
158 | break;
|
---|
159 | }
|
---|
160 | break;
|
---|
161 |
|
---|
162 | case FDLG_USERDIRS:
|
---|
163 | switch (SHORT2FROMMP(mp1)) {
|
---|
164 | case CBN_SHOWLIST:
|
---|
165 | WinSetDlgItemText(hwnd,
|
---|
166 | FDLG_HELP, (CHAR *) GetPString(IDS_DBLCLKDIRSWITCHHELPTEXT));
|
---|
167 | break;
|
---|
168 | case CBN_ENTER:
|
---|
169 | {
|
---|
170 | SHORT sSelect;
|
---|
171 | CHAR szBuffer[CCHMAXPATH], szTemp[CCHMAXPATH], *p;
|
---|
172 |
|
---|
173 | sSelect = (USHORT) WinSendDlgItemMsg(hwnd,
|
---|
174 | FDLG_USERDIRS,
|
---|
175 | LM_QUERYSELECTION,
|
---|
176 | MPVOID, MPVOID);
|
---|
177 | *szBuffer = 0;
|
---|
178 | if (sSelect >= 0) {
|
---|
179 | WinSendDlgItemMsg(hwnd,
|
---|
180 | FDLG_USERDIRS,
|
---|
181 | LM_QUERYITEMTEXT,
|
---|
182 | MPFROM2SHORT(sSelect,
|
---|
183 | CCHMAXPATH), MPFROMP(szBuffer));
|
---|
184 | if (*szBuffer) {
|
---|
185 | AddBackslashToPath(szBuffer);
|
---|
186 | //if (szBuffer[strlen(szBuffer) - 1] != '\\')
|
---|
187 | // strcat(szBuffer, "\\");
|
---|
188 | *szTemp = 0;
|
---|
189 | WinQueryDlgItemText(hwnd, 258, CCHMAXPATH, szTemp);
|
---|
190 | p = strrchr(szTemp, '\\');
|
---|
191 | if (!p)
|
---|
192 | p = szTemp;
|
---|
193 | else
|
---|
194 | p++;
|
---|
195 | if (*p)
|
---|
196 | strcat(szBuffer, p);
|
---|
197 | if (!strchr(szBuffer, '?') && !strchr(szBuffer, '*'))
|
---|
198 | strcat(szBuffer, "*");
|
---|
199 | WinSetDlgItemText(hwnd, 258, szBuffer);
|
---|
200 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
|
---|
201 | }
|
---|
202 | }
|
---|
203 | }
|
---|
204 | break;
|
---|
205 | default:
|
---|
206 | break;
|
---|
207 | }
|
---|
208 | break;
|
---|
209 | }
|
---|
210 | break;
|
---|
211 |
|
---|
212 | case WM_HELP:
|
---|
213 | if (hwndHelp) {
|
---|
214 | WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
|
---|
215 | MPFROM2SHORT(HELP_FILEDLG, 0), MPFROMSHORT(HM_RESOURCEID));
|
---|
216 | return 0;
|
---|
217 | }
|
---|
218 | break;
|
---|
219 | }
|
---|
220 | return WinDefFileDlgProc(hwnd, msg, mp1, mp2);
|
---|
221 | }
|
---|
222 |
|
---|
223 | BOOL insert_filename(HWND hwnd, CHAR * filename, INT loadit, BOOL newok)
|
---|
224 | {
|
---|
225 | FILEDLG fdlg;
|
---|
226 | FILESTATUS3 fsa;
|
---|
227 | CHAR drive[3], *pdrive = drive, *p;
|
---|
228 | APIRET rc;
|
---|
229 | static CHAR lastfilename[CCHMAXPATH] = "";
|
---|
230 |
|
---|
231 | if (!filename)
|
---|
232 | return FALSE;
|
---|
233 | memset(&fdlg, 0, sizeof(FILEDLG));
|
---|
234 | fdlg.cbSize = (ULONG) sizeof(FILEDLG);
|
---|
235 | fdlg.fl = FDS_CENTER | FDS_OPEN_DIALOG;
|
---|
236 | if (!loadit) {
|
---|
237 | fdlg.pszTitle = (PSZ)GetPString(IDS_ENTERFILEINSERTTEXT);
|
---|
238 | fdlg.pszOKButton = (PSZ)GetPString(IDS_INSERTTEXT);
|
---|
239 | }
|
---|
240 | else if (loadit == TRUE) {
|
---|
241 | fdlg.pszTitle = (PSZ)GetPString(IDS_ENTERFILELOADTEXT);
|
---|
242 | fdlg.pszOKButton = (PSZ)GetPString(IDS_LOADTEXT);
|
---|
243 | }
|
---|
244 | else {
|
---|
245 | fdlg.pszTitle = (PSZ)GetPString(IDS_ENTERFILETEXT);
|
---|
246 | fdlg.pszOKButton = (PSZ)GetPString(IDS_OKAYTEXT);
|
---|
247 | }
|
---|
248 | if (IsFullName(filename)) {
|
---|
249 | *drive = *filename;
|
---|
250 | drive[1] = ':';
|
---|
251 | drive[2] = 0;
|
---|
252 | fdlg.pszIDrive = pdrive;
|
---|
253 | }
|
---|
254 | else if (*lastfilename) {
|
---|
255 | *drive = *lastfilename;
|
---|
256 | drive[1] = ':';
|
---|
257 | drive[2] = 0;
|
---|
258 | fdlg.pszIDrive = pdrive;
|
---|
259 | }
|
---|
260 |
|
---|
261 | if (!*filename) {
|
---|
262 | if (*lastfilename) {
|
---|
263 | strcpy(fdlg.szFullFile, lastfilename);
|
---|
264 | p = strrchr(fdlg.szFullFile, '\\');
|
---|
265 | if (p) {
|
---|
266 | p++;
|
---|
267 | *p = 0;
|
---|
268 | }
|
---|
269 | }
|
---|
270 | if (!loadit || loadit == TRUE)
|
---|
271 | strcat(fdlg.szFullFile, PCSZ_STARDOTTXT);
|
---|
272 | else
|
---|
273 | strcat(fdlg.szFullFile, "*");
|
---|
274 | }
|
---|
275 | else
|
---|
276 | strcpy(fdlg.szFullFile, filename);
|
---|
277 |
|
---|
278 | if (fCustomFileDlg) {
|
---|
279 | fdlg.fl |= FDS_HELPBUTTON | FDS_CUSTOM;
|
---|
280 | fdlg.pfnDlgProc = (PFNWP) CustomFileDlg;
|
---|
281 | fdlg.hMod = FM3ModHandle;
|
---|
282 | fdlg.usDlgId = FDLG_FRAME;
|
---|
283 | }
|
---|
284 |
|
---|
285 | if (WinFileDlg(HWND_DESKTOP, hwnd, &fdlg)) {
|
---|
286 | if (fdlg.lReturn != DID_CANCEL && !fdlg.lSRC)
|
---|
287 | strcpy(filename, fdlg.szFullFile);
|
---|
288 | else
|
---|
289 | return FALSE;
|
---|
290 | }
|
---|
291 | else
|
---|
292 | return FALSE;
|
---|
293 | MakeFullName(filename);
|
---|
294 | if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, sizeof(fsa))) {
|
---|
295 | if (fsa.attrFile & FILE_DIRECTORY) {
|
---|
296 | /* device or directory */
|
---|
297 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
|
---|
298 | hwnd, filename, GetPString(IDS_EXISTSBUTNOTFILETEXT), filename);
|
---|
299 | return FALSE;
|
---|
300 | }
|
---|
301 | else if (fsa.cbFile == 0) {
|
---|
302 | saymsg(MB_CANCEL,
|
---|
303 | hwnd, filename, GetPString(IDS_ISZEROLENGTHTEXT), filename);
|
---|
304 | return FALSE;
|
---|
305 | }
|
---|
306 | }
|
---|
307 | else if (!newok) {
|
---|
308 | saymsg(MB_CANCEL,
|
---|
309 | hwnd, filename, GetPString(IDS_DOESNTEXISTTEXT), filename);
|
---|
310 | return FALSE;
|
---|
311 | }
|
---|
312 | else {
|
---|
313 | rc = saymsg(MB_YESNOCANCEL,
|
---|
314 | hwnd, filename, GetPString(IDS_CREATENEWTEXT));
|
---|
315 | if (rc != MBID_YES)
|
---|
316 | return FALSE;
|
---|
317 | }
|
---|
318 | p = filename;
|
---|
319 | while (*p) {
|
---|
320 | if (*p == '/')
|
---|
321 | *p = '\\';
|
---|
322 | p++;
|
---|
323 | }
|
---|
324 | if (*filename)
|
---|
325 | strcpy(lastfilename, filename);
|
---|
326 | return TRUE;
|
---|
327 | }
|
---|
328 |
|
---|
329 | BOOL export_filename(HWND hwnd, CHAR * filename, INT overwrite)
|
---|
330 | {
|
---|
331 | FILEDLG fdlg;
|
---|
332 | FILESTATUS3 fsa;
|
---|
333 | CHAR drive[3], *pdrive = drive, *p;
|
---|
334 | static CHAR lastfilename[CCHMAXPATH] = "";
|
---|
335 |
|
---|
336 | if (!filename)
|
---|
337 | return FALSE;
|
---|
338 | memset(&fdlg, 0, sizeof(FILEDLG));
|
---|
339 | fdlg.cbSize = sizeof(FILEDLG);
|
---|
340 | fdlg.fl = FDS_CENTER | FDS_OPEN_DIALOG;
|
---|
341 | fdlg.pszTitle = (PSZ)GetPString(IDS_EXPORTNAMETITLETEXT);
|
---|
342 | fdlg.pszOKButton = (PSZ)GetPString(IDS_OKAYTEXT);
|
---|
343 | if (IsFullName(filename)) {
|
---|
344 | *drive = *filename;
|
---|
345 | drive[1] = ':';
|
---|
346 | drive[2] = 0;
|
---|
347 | fdlg.pszIDrive = pdrive;
|
---|
348 | }
|
---|
349 | else if (*lastfilename) {
|
---|
350 | *drive = *lastfilename;
|
---|
351 | drive[1] = ':';
|
---|
352 | drive[2] = 0;
|
---|
353 | fdlg.pszIDrive = pdrive;
|
---|
354 | }
|
---|
355 | if (!*filename) {
|
---|
356 | if (*lastfilename) {
|
---|
357 | strcpy(fdlg.szFullFile, lastfilename);
|
---|
358 | p = strrchr(fdlg.szFullFile, '\\');
|
---|
359 | if (p) {
|
---|
360 | p++;
|
---|
361 | *p = 0;
|
---|
362 | }
|
---|
363 | }
|
---|
364 | strcat(fdlg.szFullFile, PCSZ_STARDOTTXT);
|
---|
365 | }
|
---|
366 | else
|
---|
367 | strcpy(fdlg.szFullFile, filename);
|
---|
368 |
|
---|
369 | if (fCustomFileDlg) {
|
---|
370 | fdlg.fl |= FDS_HELPBUTTON | FDS_CUSTOM;
|
---|
371 | fdlg.pfnDlgProc = (PFNWP) CustomFileDlg;
|
---|
372 | fdlg.hMod = FM3ModHandle;
|
---|
373 | fdlg.usDlgId = FDLG_FRAME;
|
---|
374 | }
|
---|
375 |
|
---|
376 | if (WinFileDlg(HWND_DESKTOP, hwnd, &fdlg)) {
|
---|
377 | if (fdlg.lReturn != DID_CANCEL && !fdlg.lSRC)
|
---|
378 | strcpy(filename, fdlg.szFullFile);
|
---|
379 | else
|
---|
380 | return FALSE;
|
---|
381 | }
|
---|
382 | else
|
---|
383 | return FALSE;
|
---|
384 | MakeFullName(filename);
|
---|
385 | if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, sizeof(fsa))) {
|
---|
386 | if (fsa.attrFile & FILE_DIRECTORY) { /* device or directory */
|
---|
387 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
|
---|
388 | hwnd, filename, GetPString(IDS_EXISTSBUTNOTFILETEXT), filename);
|
---|
389 | return FALSE;
|
---|
390 | }
|
---|
391 | else if (overwrite && fsa.cbFile != 0) {
|
---|
392 | if (saymsg(MB_YESNO,
|
---|
393 | hwnd,
|
---|
394 | filename,
|
---|
395 | GetPString(IDS_EXISTSERASETEXT), filename) == MBID_YES)
|
---|
396 | unlinkf(filename);
|
---|
397 | }
|
---|
398 | }
|
---|
399 | p = filename;
|
---|
400 | while (*p) {
|
---|
401 | if (*p == '/')
|
---|
402 | *p = '\\';
|
---|
403 | p++;
|
---|
404 | }
|
---|
405 | if (*filename)
|
---|
406 | strcpy(lastfilename, filename);
|
---|
407 | return TRUE;
|
---|
408 | }
|
---|
409 |
|
---|
410 | #pragma alloc_text(GETNAMES,insert_filename,export_filename,CustomFileDlg)
|
---|