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