source: trunk/dll/walkem.c@ 1077

Last change on this file since 1077 was 1077, checked in by Steven Levine, 17 years ago

Enhance Fortify infrastructure
Add Fortify_SetOwner Fortify_ChangeOwner Fortify_ChangeScope
Add FORTIFY_VERBOSE_SCOPE_ENTER_EXIT support
Add more fm/2 Fortify tooling and rework existing tooling for correct nesting
Still lots to do for cross-thread allocations
Add misc.h
Add walkem.h

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 42.8 KB
Line 
1
2/***********************************************************************
3
4 $Id: walkem.c 1077 2008-07-18 18:11:54Z stevenhl $
5
6 Misc persistent lists support
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2005, 2007 Steven H. Levine
10
11 01 Aug 04 SHL Rework lstrip/rstrip usage
12 05 Jun 05 SHL Use QWL_USER
13 13 Aug 05 SHL Run through indent
14 13 Aug 05 SHL remove_udir - avoid corrupting last dirs list
15 17 Jul 06 SHL Use Runtime_Error
16 29 Jul 06 SHL Use xfgets
17 20 Oct 06 SHL Correct . .. check
18 06 Nov 06 SHL Oops - need to allow .. here
19 14 Nov 06 SHL Correct FillPathListBox regression
20 22 Mar 07 GKY Use QWL_USER
21 20 Apr 07 SHL Avoid spurious add_udir error reports
22 16 Aug 07 SHL Update add_setups for ticket# 109
23 19 Aug 07 SHL Correct load_setups error reporting
24 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
25 25 Aug 07 SHL Correct #pragma alloc_text typos
26 11 Nov 07 GKY Cancel now directly closes dialog even if directory path text has changed
27 20 Jan 08 GKY Walk & walk2 dialogs now save and restore size and position
28 19 Feb 08 JBS Add "State at last FM/2 close" to the states combo box
29 29 Feb 08 GKY Use xfree where appropriate
30 29 Feb 08 GKY Refactor global command line variables to notebook.h
31 19 Jun 08 JBS Ticket 227: Allow temporary saving/deleting of the shutdown state of directory containers
32 22 Jun 08 GKY Add free_?dir for fortify testing
33
34***********************************************************************/
35
36#include <stdlib.h>
37#include <string.h>
38#include <ctype.h>
39#include <share.h>
40
41#define INCL_WIN
42#define INCL_DOS
43#define INCL_DOSERRORS
44#define INCL_SHLERRORS // PMERR_NOT_IN_IDX
45#define INCL_LONGLONG
46
47#include "fm3dlg.h"
48#include "fm3str.h"
49#include "errutil.h" // Dos_Error...
50#include "strutil.h" // GetPString
51#include "notebook.h" // targetdirectory
52#include "fm3dll.h"
53#include "fortify.h"
54#include "walkem.h"
55
56#pragma data_seg(DATA1)
57
58static PSZ pszSrcFile = __FILE__;
59
60
61typedef struct
62{
63 USHORT size;
64 USHORT changed;
65 BOOL nounwriteable;
66 CHAR szCurrentPath[CCHMAXPATH];
67 CHAR *szReturnPath;
68}
69WALKER;
70
71static CHAR WalkFont[CCHMAXPATH] = "";
72static ULONG WalkFontSize = sizeof(WalkFont);
73
74/**
75 * States names management
76 */
77
78static BOOL fSetupsLoaded;
79static LINKDIRS *pFirstSetup;
80static const PSZ pszLastSetups = "LastSetups";
81// 18 Aug 07 SHL fixme to stop supporting old style 1 year from now?
82static const ULONG ulOldSetupsBytes = 100 * 13; // Prior to 3.0.7
83
84/**
85 * Fill States drop down list with known state names
86 */
87
88VOID fill_setups_list(VOID)
89{
90 WinSendMsg(hwndStatelist, LM_DELETEALL, MPVOID, MPVOID);
91 if (fUserComboBox) {
92 LINKDIRS *pld;
93 load_setups();
94 for (pld = pFirstSetup; pld; pld = pld->next) {
95 // DbgMsg(pszSrcFile, __LINE__, "Inserted %s", pld->path);
96 WinSendMsg(hwndStatelist,
97 LM_INSERTITEM,
98 MPFROM2SHORT(LIT_SORTASCENDING, 0),
99 MPFROMP(pld->path));
100 }
101 WinSetWindowText(hwndStatelist, GetPString(IDS_STATETEXT));
102 }
103}
104
105/**
106 * Lookup setup and do requested action
107 * @param - action, Support old/new style storage method
108 * @return 1 if found and action OK, 0 if not found and action OK, -1 if error during action
109 */
110
111#define LS_FIND 0
112#define LS_ADD 1
113#define LS_DELETE 2
114
115static INT lookup_setup(PSZ name, UINT action)
116{
117 LINKDIRS *pld;
118 LINKDIRS *pldLast = NULL;
119
120 if (!name || !*name) {
121 Runtime_Error(pszSrcFile, __LINE__, "no data");
122 return -1;
123 }
124
125 load_setups();
126
127 for (pld = pFirstSetup; pld; pld = pld->next) {
128 if (!stricmp(pld->path, name)) {
129 if (action == LS_DELETE) {
130 if (pldLast)
131 pldLast->next = pld->next;
132 else
133 pFirstSetup = pld->next;
134 xfree(pld->path, pszSrcFile, __LINE__);
135 free(pld);
136 }
137 return 1; // Found or added
138 }
139 pldLast = pld; // In case deleting
140 } // for
141
142 // Not found
143 if (action == LS_ADD) {
144 pld = xmalloc(sizeof(LINKDIRS), pszSrcFile, __LINE__);
145 if (!pld)
146 return -1;
147 pld->path = xstrdup(name, pszSrcFile, __LINE__);
148 if (!pld->path) {
149 free(pld);
150 return -1;
151 }
152 // Insert at front of list - drop down will sort
153 pld->next = pFirstSetup;
154 pFirstSetup = pld;
155 return 0;
156 }
157
158 return FALSE; // Not found
159}
160
161/**
162 * Load state names from ini
163 * Support old/new style storage method
164 */
165
166VOID load_setups(VOID)
167{
168 ULONG ulDataBytes;
169 ULONG l;
170 PSZ pszBuf;
171 PSZ psz;
172 LINKDIRS *pld;
173
174 if (fSetupsLoaded)
175 return;
176
177 if (!PrfQueryProfileSize(fmprof, FM3Str, pszLastSetups, &ulDataBytes)) {
178 // fixme to use generic hab
179 ERRORID eid = WinGetLastError((HAB)0);
180 if ((eid & 0xffff) != PMERR_NOT_IN_IDX) {
181 // Get error info back
182 PrfQueryProfileSize(fmprof, FM3Str, pszLastSetups, &ulDataBytes);
183 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__, "PrfQueryProfileSize");
184 }
185 else
186 fSetupsLoaded = TRUE; // Nothing saved
187 return;
188 }
189
190 if (ulDataBytes == 0) {
191 Runtime_Error(pszSrcFile, __LINE__, "PrfQueryProfileSize reported 0 bytes");
192 return;
193 }
194
195 pszBuf = xmalloc(ulDataBytes + 1, pszSrcFile, __LINE__); // One extra for end marker
196 if (!pszBuf)
197 return;
198 l = ulDataBytes;
199 if (!PrfQueryProfileData(fmprof, FM3Str, pszLastSetups, pszBuf, &l)) {
200 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__, "PrfQueryProfileData");
201 free(pszBuf);
202 return;
203 }
204
205 if (ulDataBytes != l) {
206 Runtime_Error(pszSrcFile, __LINE__, "PrfQueryProfileData reported %u expected %u", l, ulDataBytes);
207 free(pszBuf);
208 return;
209 }
210
211 *(pszBuf + ulDataBytes) = 0; // Insert end marker
212
213 psz = pszBuf;
214 if (!*psz && ulDataBytes == ulOldSetupsBytes)
215 psz += 13; // Rarely used 1st fixed width entry prior to 3.0.7
216
217 while (*psz) {
218 pld = xmalloc(sizeof(LINKDIRS), pszSrcFile, __LINE__);
219 if (!pld) {
220 free(pszBuf);
221 return;
222 }
223 pld->path = xstrdup(psz, pszSrcFile, __LINE__);
224 if (!pld->path) {
225 free(pszBuf);
226 free(pld);
227 return;
228 }
229
230 // Insert at front of list - drop down will sort
231 pld->next = pFirstSetup;
232 pFirstSetup = pld;
233 // DbgMsg(pszSrcFile, __LINE__, "Inserted %s", pld->path);
234
235 if (ulDataBytes == ulOldSetupsBytes)
236 psz += 13; // Buffers fixed width prior to 3.0.7
237 else
238 psz += strlen(psz) + 1;
239 } // while
240
241 free(pszBuf);
242
243 fSetupsLoaded = TRUE;
244}
245
246VOID save_setups(VOID)
247{
248 ULONG ulBufBytes;
249 ULONG ulFillBytes;
250 ULONG l;
251 PSZ pszBuf;
252 PSZ psz;
253 LINKDIRS *pld;
254
255 if (!fSetupsLoaded)
256 return;
257
258 ulBufBytes = 0;
259 for (pld = pFirstSetup; pld; pld = pld->next) {
260 ulBufBytes += strlen(pld->path) + 1;
261 } // for
262
263 if (!ulBufBytes)
264 pszBuf = NULL;
265 else {
266 // Ensure different than size prior to 3.0.7
267 ulFillBytes = ulBufBytes == ulOldSetupsBytes ? 1 : 0;
268 pszBuf = xmalloc(ulBufBytes + ulFillBytes, pszSrcFile, __LINE__);
269 if (!pszBuf)
270 return;
271
272 psz = pszBuf;
273 for (pld = pFirstSetup; pld; pld = pld->next) {
274 l = strlen(pld->path) + 1;
275 memcpy(psz, pld->path, l);
276 psz += l;
277 } // for
278 if (ulFillBytes)
279 *psz = 0;
280 }
281
282 if (!PrfWriteProfileData(fmprof,
283 FM3Str,
284 pszLastSetups, pszBuf, ulBufBytes)) {
285 // Win_Error(pszSrcFile, __LINE__, HWND_DESKTOP, HWND_DESKTOP, "PrfWriteProfileData");
286 ERRORID eid = WinGetLastError((HAB)0);
287 if ((eid & 0xffff) != PMERR_NOT_IN_IDX)
288 Runtime_Error(pszSrcFile, __LINE__, "PrfWriteProfileData returned %u", eid);
289 }
290
291 // Delete obsolete INI entry
292 PrfWriteProfileData(fmprof, FM3Str, "LastSetup", NULL, 0);
293}
294
295/**
296 * Add named state to setups list
297 * @return same as lookup_setup
298 */
299
300INT add_setup(PSZ name)
301{
302 return lookup_setup(name, LS_ADD);
303}
304
305/**
306 * Delete named state from setups list
307 * @return same as lookup_setup
308 */
309
310INT remove_setup(PSZ name)
311{
312 return lookup_setup(name, LS_DELETE);
313}
314
315#ifdef FORTIFY
316
317VOID free_setups(VOID)
318{
319 LINKDIRS *pld = pFirstSetup;
320 while (pld) {
321 LINKDIRS *next = pld->next;
322 free(pld->path);
323 free(pld);
324 pld = next;
325 }
326 pFirstSetup = NULL;
327}
328
329#endif // FORTIFY
330
331VOID load_udirs(VOID)
332{
333 /* load linked list of user directories from USERDIRS.DAT file */
334
335 FILE *fp;
336 LINKDIRS *info;
337 LINKDIRS *last = NULL;
338 CHAR s[CCHMAXPATH + 24];
339
340 if (udirhead)
341 free_udirs();
342 loadedudirs = TRUE;
343 fUdirsChanged = FALSE;
344 save_dir2(s);
345 if (s[strlen(s) - 1] != '\\')
346 strcat(s, "\\");
347 strcat(s, "USERDIRS.DAT");
348 fp = _fsopen(s, "r", SH_DENYWR);
349 if (fp) {
350 while (!feof(fp)) {
351 if (!xfgets(s, CCHMAXPATH + 24, fp, pszSrcFile, __LINE__))
352 break;
353 s[CCHMAXPATH] = 0;
354 bstripcr(s);
355 if (*s && *s != ';') {
356 info = xmalloc(sizeof(LINKDIRS), pszSrcFile, __LINE__);
357 if (info) {
358 info->path = xstrdup(s, pszSrcFile, __LINE__);
359 if (!info->path)
360 free(info);
361 else {
362 info->next = NULL;
363 if (!udirhead)
364 udirhead = info;
365 else
366 last->next = info;
367 last = info;
368 }
369 }
370 }
371 }
372 fclose(fp);
373 }
374}
375
376VOID save_udirs(VOID)
377{
378 FILE *fp;
379 LINKDIRS *info;
380 CHAR s[CCHMAXPATH + 14];
381
382 if (loadedudirs) {
383 fUdirsChanged = FALSE;
384 if (udirhead) {
385 save_dir2(s);
386 if (s[strlen(s) - 1] != '\\')
387 strcat(s, "\\");
388 strcat(s, "USERDIRS.DAT");
389 fp = xfopen(s, "w", pszSrcFile, __LINE__);
390 if (fp) {
391 fputs(GetPString(IDS_USERDEFDIRSTEXT), fp);
392 info = udirhead;
393 while (info) {
394 fprintf(fp, "%0.*s\n", CCHMAXPATH, info->path);
395 info = info->next;
396 }
397 fclose(fp);
398 }
399 }
400 }
401}
402
403/**
404 * Add path to user directory list or last used directory list.
405 * Callers need to check fUdirsChanged to know if user dirs change occured.
406 * Callers need to check return code to know if last dirs change occured.
407 * @param userdirs TRUE to process user directory list. Otherwise last used list.
408 * @return TRUE if added, FALSE if already in list or error.
409 */
410
411BOOL add_udir(BOOL userdirs, CHAR *inpath)
412{
413 CHAR path[CCHMAXPATH];
414 LINKDIRS *info;
415 LINKDIRS *last = NULL;
416 LINKDIRS *temp;
417
418 if (inpath && *inpath) {
419 if (DosQueryPathInfo(inpath, FIL_QUERYFULLNAME, path, sizeof(path)))
420 strcpy(path, inpath);
421 if (!userdirs && IsRoot(path))
422 return FALSE;
423 if (IsFullName(path)) {
424 if (!loadedudirs)
425 load_udirs();
426 // Search user dir list first unless doing last dirs
427 info = userdirs ? udirhead : ldirhead;
428 while (info) {
429 if (!stricmp(info->path, path))
430 return FALSE; // Already in list
431 last = info; // Remember append to location
432 info = info->next;
433 }
434 // Search last dir list unless doing just last dirs
435 if (!userdirs) {
436 info = udirhead;
437 while (info) {
438 if (!stricmp(info->path, path))
439 return FALSE;
440 info = info->next;
441 }
442 }
443 else {
444 /* if adding manual directory, remove from auto list if present */
445 info = ldirhead;
446 temp = NULL;
447 while (info) {
448 if (!stricmp(info->path, path)) {
449 if (temp)
450 temp->next = info->next;
451 else
452 ldirhead = info->next;
453 xfree(info->path, pszSrcFile, __LINE__);
454 free(info);
455 break;
456 }
457 temp = info;
458 info = info->next;
459 }
460 }
461 // Append entry to end of user dirs list
462 info = xmalloc(sizeof(LINKDIRS), pszSrcFile, __LINE__);
463 if (info) {
464 info->path = xstrdup(path, pszSrcFile, __LINE__);
465 if (!info->path)
466 free(info);
467 else {
468 info->next = NULL;
469 if (userdirs) {
470 fUdirsChanged = TRUE;
471 if (!udirhead)
472 udirhead = info;
473 else
474 last->next = info;
475 }
476 else {
477 if (!ldirhead)
478 ldirhead = info;
479 else
480 last->next = info;
481 }
482 return TRUE;
483 }
484 }
485 }
486 }
487 return FALSE;
488}
489
490//=== remove_udir - remove path from user dir list or last directory list ===
491
492BOOL remove_udir(CHAR * path)
493{
494 LINKDIRS *info;
495 LINKDIRS *last = NULL;
496
497 if (path && *path) {
498 if (!loadedudirs)
499 load_udirs();
500 info = udirhead;
501 while (info) {
502 if (!stricmp(info->path, path)) {
503 if (last)
504 last->next = info->next;
505 else
506 udirhead = info->next;
507 xfree(info->path, pszSrcFile, __LINE__);
508 free(info);
509 fUdirsChanged = TRUE;
510 return TRUE;
511 }
512 last = info;
513 info = info->next;
514 }
515
516 info = ldirhead;
517 last = NULL;
518 while (info) {
519 if (!stricmp(info->path, path)) {
520 if (last)
521 last->next = info->next;
522 else
523 ldirhead = info->next;
524 xfree(info->path, pszSrcFile, __LINE__);
525 free(info);
526 return TRUE;
527 }
528 last = info;
529 info = info->next;
530 }
531 }
532 return FALSE;
533}
534
535BOOL remove_ldir(CHAR * path)
536{
537 LINKDIRS *info;
538 LINKDIRS *last = NULL;
539
540 if (path && *path) {
541 info = ldirhead;
542 while (info) {
543 if (!stricmp(info->path, path)) {
544 if (last)
545 last->next = info->next;
546 else
547 ldirhead = info->next;
548 xfree(info->path, pszSrcFile, __LINE__);
549 free(info);
550 return TRUE;
551 }
552 last = info;
553 info = info->next;
554 }
555 }
556 return FALSE;
557}
558
559VOID free_ldir(VOID)
560{
561 LINKDIRS *info, *next;
562
563 info = ldirhead;
564 while (info) {
565 next = info->next;
566 xfree(info->path, pszSrcFile, __LINE__);
567 free(info);
568 info = next;
569 }
570 ldirhead = NULL;
571}
572
573VOID free_udirs(VOID)
574{
575 LINKDIRS *info, *next;
576
577 info = udirhead;
578 while (info) {
579 next = info->next;
580 xfree(info->path, pszSrcFile, __LINE__);
581 free(info);
582 info = next;
583 }
584 udirhead = NULL;
585}
586
587VOID FillPathListBox(HWND hwnd, HWND hwnddrive, HWND hwnddir, CHAR * pszPath,
588 BOOL nounwriteable)
589{
590 /*
591 * this function fills one or two list boxes with drive and directory
592 * information showing all available drives and all directories off of
593 * the directory represented by path. This works independently of the
594 * current directory.
595 */
596
597 CHAR szDrive[] = " :", szTemp[1032];
598 FILEFINDBUF3 findbuf;
599 HDIR hDir = HDIR_CREATE;
600 SHORT sDrive;
601 ULONG ulDriveNum, ulSearchCount = 1, ulDriveMap;
602
603 DosError(FERR_DISABLEHARDERR);
604 DosQCurDisk(&ulDriveNum, &ulDriveMap);
605 if (hwnddrive)
606 WinSendMsg(hwnddrive, LM_DELETEALL, MPVOID, MPVOID);
607 if (hwnddrive != hwnddir && hwnddir)
608 WinSendMsg(hwnddir, LM_DELETEALL, MPVOID, MPVOID);
609
610 if (hwnddrive) {
611 // Fill drive listbox
612 for (sDrive = 0; sDrive < 26; sDrive++) {
613 if (ulDriveMap & (1 << sDrive)) {
614 *szDrive = (CHAR) (sDrive + 'A');
615 if ((!nounwriteable || !(driveflags[sDrive] & DRIVE_NOTWRITEABLE)) &&
616 !(driveflags[sDrive] & (DRIVE_IGNORE | DRIVE_INVALID)))
617 WinSendMsg(hwnddrive, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0),
618 MPFROMP(szDrive));
619 }
620 }
621 if (hwnddrive != hwnddir && pszPath && isalpha(*pszPath)
622 && pszPath[1] == ':') {
623 *szDrive = toupper(*pszPath);
624 WinSetWindowText(hwnddrive, szDrive);
625 }
626 }
627
628 if (hwnddir) {
629 // Fill directory listbox
630 sprintf(szTemp,
631 "%s%s*",
632 pszPath, (pszPath[strlen(pszPath) - 1] == '\\') ? "" : "\\");
633 DosError(FERR_DISABLEHARDERR);
634 if (!DosFindFirst(szTemp,
635 &hDir,
636 FILE_DIRECTORY | MUST_HAVE_DIRECTORY |
637 FILE_READONLY | FILE_ARCHIVED | FILE_SYSTEM |
638 FILE_HIDDEN,
639 &findbuf,
640 sizeof(FILEFINDBUF3), &ulSearchCount, FIL_STANDARD)) {
641 do {
642 if (findbuf.attrFile & FILE_DIRECTORY) {
643 // Skip .. unless full path supplied
644 if (strcmp(findbuf.achName, "..") ||
645 strlen(pszPath) > 3 || pszPath[1] != ':') {
646 // Skip . allow ..
647 if (findbuf.achName[0] != '.' || findbuf.achName[1]) {
648 WinSendMsg(hwnddir,
649 LM_INSERTITEM,
650 MPFROM2SHORT(LIT_SORTASCENDING, 0),
651 MPFROMP(findbuf.achName));
652 }
653 }
654 }
655 ulSearchCount = 1;
656 } while (!DosFindNext(hDir,
657 &findbuf, sizeof(FILEFINDBUF3), &ulSearchCount));
658 DosFindClose(hDir);
659 }
660 DosError(FERR_DISABLEHARDERR);
661 }
662}
663
664MRESULT EXPENTRY TextSubProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
665{
666 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
667
668 switch (msg) {
669 case WM_CHAR:
670 if (SHORT1FROMMP(mp1) & KC_KEYUP) {
671 if ((SHORT1FROMMP(mp1) & KC_VIRTUALKEY) &&
672 (SHORT1FROMMP(mp2) & 255) == '\r')
673 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
674 MPFROM2SHORT(DID_OK, 0), MPVOID);
675 }
676 break;
677 }
678 return oldproc(hwnd, msg, mp1, mp2);
679}
680
681MRESULT EXPENTRY WalkDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
682{
683 WALKER *wa;
684 CHAR szBuff[CCHMAXPATH + 1], szBuffer[CCHMAXPATH + 1], *p;
685 SHORT sSelect;
686 static BOOL okay; /* avoid combobox selecting as filled */
687 static CHAR lastdir[CCHMAXPATH + 1];
688
689 switch (msg) {
690 case UM_SETUP2:
691 case WM_INITDLG:
692 okay = FALSE;
693 *lastdir = 0;
694 if (!mp2) {
695 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
696 WinDismissDlg(hwnd, 0);
697 break;
698 }
699 wa = xmallocz(sizeof(WALKER), pszSrcFile, __LINE__);
700 if (!wa) {
701 WinDismissDlg(hwnd, 0);
702 break;
703 }
704 wa->size = (USHORT) sizeof(WALKER);
705 WinSetWindowPtr(hwnd, QWL_USER, (PVOID) wa);
706 wa->szReturnPath = (CHAR *)mp2;
707 {
708 PFNWP oldproc;
709
710 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, WALK_PATH),
711 (PFNWP) TextSubProc);
712 if (oldproc)
713 WinSetWindowPtr(WinWindowFromID(hwnd, WALK_PATH),
714 QWL_USER, (PVOID) oldproc);
715 WinSendDlgItemMsg(WinWindowFromID(hwnd, WALK_RECENT),
716 CBID_EDIT,
717 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
718 WinSendDlgItemMsg(WinWindowFromID(hwnd, WALK_RECENT),
719 CBID_EDIT,
720 EM_SETREADONLY, MPFROM2SHORT(TRUE, 0), MPVOID);
721 }
722 {
723 SWP swp;
724 ULONG size = sizeof(SWP);
725
726 PrfQueryProfileData(fmprof, FM3Str, "WalkDir.Position", (PVOID) &swp, &size);
727 WinSetWindowPos(hwnd,
728 HWND_TOP,
729 swp.x,
730 swp.y,
731 swp.cx,
732 swp.cy,
733 swp.fl);
734 }
735 PosOverOkay(hwnd);
736 if (msg == UM_SETUP2)
737 wa->nounwriteable = FALSE;
738 else
739 wa->nounwriteable = TRUE;
740 if (!*wa->szReturnPath)
741 save_dir2(wa->szCurrentPath);
742 else {
743 strcpy(wa->szCurrentPath, wa->szReturnPath);
744 MakeFullName(wa->szCurrentPath);
745 }
746 if (wa->nounwriteable &&
747 (driveflags[toupper(*wa->szCurrentPath) - 'A'] &
748 DRIVE_NOTWRITEABLE)) {
749
750 ULONG bd;
751
752 strcpy(wa->szCurrentPath, "C:\\");
753 if (DosQuerySysInfo(QSV_BOOT_DRIVE,
754 QSV_BOOT_DRIVE,
755 (PVOID) & bd, (ULONG) sizeof(ULONG)))
756 bd = 3;
757 *wa->szCurrentPath = (CHAR) bd + '@';
758 }
759 WinSendDlgItemMsg(hwnd,
760 WALK_PATH,
761 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
762 WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath);
763 if (!loadedudirs)
764 load_udirs();
765 { /* fill user list box */
766 ULONG ulDriveNum, ulDriveMap;
767 ULONG ulSearchCount;
768 FILEFINDBUF3 findbuf;
769 HDIR hDir;
770 APIRET rc;
771 LINKDIRS *info, *temp;
772
773 DosError(FERR_DISABLEHARDERR);
774 DosQCurDisk(&ulDriveNum, &ulDriveMap);
775 info = udirhead;
776 while (info) {
777 if (IsFullName(info->path) &&
778 !(driveflags[toupper(*info->path) - 'A'] &
779 (DRIVE_IGNORE | DRIVE_INVALID))) {
780 DosError(FERR_DISABLEHARDERR);
781 hDir = HDIR_CREATE;
782 ulSearchCount = 1;
783 if (!IsRoot(info->path))
784 rc = DosFindFirst(info->path, &hDir, FILE_DIRECTORY |
785 MUST_HAVE_DIRECTORY | FILE_READONLY |
786 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
787 &findbuf, sizeof(FILEFINDBUF3),
788 &ulSearchCount, FIL_STANDARD);
789 else {
790 rc = 0;
791 findbuf.attrFile = FILE_DIRECTORY;
792 }
793 if (!rc) {
794 if (!IsRoot(info->path))
795 DosFindClose(hDir);
796 if (findbuf.attrFile & FILE_DIRECTORY)
797 WinSendDlgItemMsg(hwnd, WALK_USERLIST, LM_INSERTITEM,
798 MPFROM2SHORT(LIT_SORTASCENDING, 0),
799 MPFROMP(info->path));
800 else {
801 temp = info->next;
802 remove_udir(info->path);
803 info = temp;
804 continue;
805 }
806 }
807 else if (!(ulDriveMap & (1 << (toupper(*info->path) - 'A')))) {
808 temp = info->next;
809 remove_udir(info->path);
810 info = temp;
811 continue;
812 }
813 }
814 info = info->next;
815 }
816 info = ldirhead;
817 while (info) {
818 if (IsFullName(info->path) &&
819 !(driveflags[toupper(*info->path) - 'A'] &
820 (DRIVE_IGNORE | DRIVE_INVALID))) {
821 DosError(FERR_DISABLEHARDERR);
822 hDir = HDIR_CREATE;
823 ulSearchCount = 1;
824 if (!IsRoot(info->path))
825 rc = DosFindFirst(info->path, &hDir, FILE_DIRECTORY |
826 MUST_HAVE_DIRECTORY | FILE_READONLY |
827 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
828 &findbuf, sizeof(FILEFINDBUF3),
829 &ulSearchCount, FIL_STANDARD);
830 else {
831 rc = 0;
832 findbuf.attrFile = FILE_DIRECTORY;
833 }
834 if (!rc) {
835 if (!IsRoot(info->path))
836 DosFindClose(hDir);
837 if (findbuf.attrFile & FILE_DIRECTORY)
838 WinSendDlgItemMsg(hwnd, WALK_RECENT, LM_INSERTITEM,
839 MPFROM2SHORT(LIT_SORTASCENDING, 0),
840 MPFROMP(info->path));
841 else {
842 temp = info->next;
843 remove_ldir(info->path);
844 info = temp;
845 continue;
846 }
847 WinSetDlgItemText(hwnd, WALK_RECENT,
848 GetPString(IDS_WALKRECENTDIRSTEXT));
849 }
850 else if (!(ulDriveMap & (1 << (toupper(*info->path) - 'A')))) {
851 temp = info->next;
852 remove_ldir(info->path);
853 info = temp;
854 continue;
855 }
856 }
857 info = info->next;
858 }
859 }
860 FillPathListBox(hwnd,
861 WinWindowFromID(hwnd, WALK_DRIVELIST),
862 WinWindowFromID(hwnd, WALK_DIRLIST),
863 wa->szCurrentPath, wa->nounwriteable);
864 if (!PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID))
865 okay = TRUE;
866 {
867 MRESULT ret;
868
869 ret = WinDefDlgProc(hwnd, WM_INITDLG, mp1, mp2);
870 WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
871 WinInvalidateRect(WinWindowFromID(hwnd, WALK_PATH), NULL, TRUE);
872 return ret;
873 }
874
875 case UM_SETUP4:
876 okay = TRUE;
877 return 0;
878
879 case WM_ADJUSTWINDOWPOS:
880 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
881 break;
882
883 case UM_SETDIR:
884 PaintRecessedWindow(WinWindowFromID(hwnd, WALK_HELP), (HPS) 0, FALSE,
885 TRUE);
886 return 0;
887
888 case WM_PRESPARAMCHANGED:
889 {
890 ULONG AttrFound, AttrValue[64], cbRetLen;
891
892 cbRetLen = WinQueryPresParam(hwnd, (ULONG) mp1, 0, &AttrFound,
893 (ULONG) sizeof(AttrValue), &AttrValue, 0);
894 if (cbRetLen) {
895 switch (AttrFound) {
896 case PP_FONTNAMESIZE:
897 PrfWriteProfileData(fmprof,
898 appname,
899 "WalkFont", (PVOID) AttrValue, cbRetLen);
900 *WalkFont = 0;
901 WalkFontSize = sizeof(WalkFont);
902 WinInvalidateRect(WinWindowFromID(hwnd, WALK_PATH), NULL, TRUE);
903 break;
904 }
905 }
906 }
907 break;
908
909 case UM_SETUP3:
910 save_udirs();
911 if (hwndMain)
912 PostMsg(hwndMain, UM_FILLUSERLIST, MPVOID, MPVOID);
913 return 0;
914
915 case UM_SETUP:
916 {
917 INT x;
918 USHORT id[] = { WALK_PATH, WALK_DIRLIST, WALK_USERLIST,
919 WALK_RECENT, 0
920 };
921
922 if (*WalkFont ||
923 (PrfQueryProfileData(fmprof,
924 appname,
925 "WalkFont",
926 (PVOID) WalkFont,
927 &WalkFontSize) && WalkFontSize)) {
928 for (x = 0; id[x]; x++)
929 WinSetPresParam(WinWindowFromID(hwnd, id[x]),
930 PP_FONTNAMESIZE, WalkFontSize, (PVOID) WalkFont);
931 }
932 }
933 return 0;
934
935 case UM_CONTROL:
936 case WM_CONTROL:
937 wa = WinQueryWindowPtr(hwnd, QWL_USER);
938 if (SHORT1FROMMP(mp1) == WALK_DRIVELIST ||
939 SHORT1FROMMP(mp1) == WALK_DIRLIST ||
940 SHORT1FROMMP(mp1) == WALK_USERLIST ||
941 SHORT1FROMMP(mp1) == WALK_RECENT) {
942 sSelect = (USHORT) WinSendDlgItemMsg(hwnd,
943 SHORT1FROMMP(mp1),
944 LM_QUERYSELECTION, MPVOID, MPVOID);
945 *szBuffer = 0;
946 if (sSelect >= 0)
947 WinSendDlgItemMsg(hwnd, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
948 MPFROM2SHORT(sSelect, CCHMAXPATH),
949 MPFROMP(szBuffer));
950 }
951 switch (SHORT1FROMMP(mp1)) {
952 case WALK_PATH:
953 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
954 WinSetDlgItemText(hwnd, WALK_HELP, GetPString(IDS_WALKCURRDIRTEXT));
955 else if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
956 WinSetDlgItemText(hwnd, WALK_HELP,
957 GetPString(IDS_WALKDEFAULTHELPTEXT));
958 break;
959
960 case WALK_RECENT:
961 if (okay && SHORT2FROMMP(mp1) == CBN_LBSELECT) {
962
963 ULONG ulSearchCount;
964 FILEFINDBUF3 findbuf;
965 HDIR hDir;
966 APIRET rc;
967
968 // *szBuffer = 0;
969 // WinQueryDlgItemText(hwnd,WALK_RECENT,CCHMAXPATH,szBuffer);
970 if (!*szBuffer)
971 break;
972 DosError(FERR_DISABLEHARDERR);
973 hDir = HDIR_CREATE;
974 ulSearchCount = 1;
975 if (!IsRoot(szBuffer)) {
976 rc = DosFindFirst(szBuffer, &hDir, FILE_DIRECTORY |
977 MUST_HAVE_DIRECTORY | FILE_READONLY |
978 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
979 &findbuf, sizeof(FILEFINDBUF3),
980 &ulSearchCount, FIL_STANDARD);
981 if (!rc)
982 DosFindClose(hDir);
983 }
984 else {
985 findbuf.attrFile = FILE_DIRECTORY;
986 rc = 0;
987 }
988 if (rc)
989 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
990 "xDosFindFirst");
991 else if (~findbuf.attrFile & FILE_DIRECTORY)
992 Runtime_Error(pszSrcFile, __LINE__, "not a directory");
993 else {
994 strcpy(wa->szCurrentPath, szBuffer);
995 WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath);
996 WinSetDlgItemText(hwnd, WALK_RECENT, wa->szCurrentPath);
997 FillPathListBox(hwnd,
998 WinWindowFromID(hwnd, WALK_DRIVELIST),
999 WinWindowFromID(hwnd, WALK_DIRLIST),
1000 wa->szCurrentPath, FALSE);
1001 }
1002 }
1003 else if (SHORT2FROMMP(mp1) == CBN_ENTER)
1004 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
1005 else if (SHORT2FROMMP(mp1) == CBN_SHOWLIST)
1006 WinSetDlgItemText(hwnd, WALK_HELP,
1007 GetPString(IDS_WALKRECENTDIRSHELPTEXT));
1008 break;
1009
1010 case WALK_USERLIST:
1011 if (okay && *szBuffer && SHORT2FROMMP(mp1) == LN_SELECT) {
1012
1013 ULONG ulSearchCount;
1014 FILEFINDBUF3 findbuf;
1015 HDIR hDir;
1016 APIRET rc;
1017
1018 DosError(FERR_DISABLEHARDERR);
1019 hDir = HDIR_CREATE;
1020 ulSearchCount = 1;
1021 if (!IsRoot(szBuffer)) {
1022 rc = DosFindFirst(szBuffer,
1023 &hDir,
1024 FILE_DIRECTORY |
1025 MUST_HAVE_DIRECTORY | FILE_READONLY |
1026 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
1027 &findbuf,
1028 sizeof(FILEFINDBUF3),
1029 &ulSearchCount, FIL_STANDARD);
1030 if (!rc)
1031 DosFindClose(hDir);
1032 }
1033 else {
1034 findbuf.attrFile = FILE_DIRECTORY;
1035 rc = 0;
1036 }
1037 if (rc)
1038 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
1039 "xDosFindFirst");
1040 else if (~findbuf.attrFile & FILE_DIRECTORY)
1041 Runtime_Error(pszSrcFile, __LINE__, "not a directory");
1042 else {
1043 strcpy(wa->szCurrentPath, szBuffer);
1044 WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath);
1045 FillPathListBox(hwnd,
1046 WinWindowFromID(hwnd, WALK_DRIVELIST),
1047 WinWindowFromID(hwnd, WALK_DIRLIST),
1048 wa->szCurrentPath, FALSE);
1049 }
1050 }
1051 else if (SHORT2FROMMP(mp1) == LN_ENTER)
1052 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
1053 else if (SHORT2FROMMP(mp1) == LN_SETFOCUS)
1054 WinSetDlgItemText(hwnd,
1055 WALK_HELP, GetPString(IDS_WALKUSERDIRSHELPTEXT));
1056 else if (SHORT2FROMMP(mp1) == LN_KILLFOCUS)
1057 WinSetDlgItemText(hwnd,
1058 WALK_HELP, GetPString(IDS_WALKDEFAULTHELPTEXT));
1059 break;
1060
1061 case WALK_DRIVELIST:
1062 if (okay && *szBuffer && SHORT2FROMMP(mp1) == LN_ENTER) {
1063
1064 ULONG ulDirLen = CCHMAXPATH;
1065 APIRET rc;
1066
1067 rc = DosQCurDir(toupper(*szBuffer) - '@', &szBuff[3], &ulDirLen);
1068 if (!rc) {
1069 strcpy(wa->szCurrentPath, "C:\\");
1070 *wa->szCurrentPath = toupper(*szBuffer);
1071 WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath);
1072 FillPathListBox(hwnd,
1073 WinWindowFromID(hwnd, WALK_DRIVELIST),
1074 WinWindowFromID(hwnd, WALK_DIRLIST),
1075 wa->szCurrentPath, FALSE);
1076 }
1077 }
1078 else if (SHORT2FROMMP(mp1) == LN_SETFOCUS)
1079 WinSetDlgItemText(hwnd, WALK_HELP,
1080 GetPString(IDS_WALKDRIVELISTHELPTEXT));
1081 else if (SHORT2FROMMP(mp1) == LN_KILLFOCUS)
1082 WinSetDlgItemText(hwnd, WALK_HELP,
1083 GetPString(IDS_WALKDEFAULTHELPTEXT));
1084 break;
1085
1086 case WALK_DIRLIST:
1087 if (okay && SHORT2FROMMP(mp1) == LN_ENTER) {
1088
1089 ULONG ulSearchCount;
1090 FILEFINDBUF3 findbuf;
1091 HDIR hDir;
1092 APIRET rc;
1093
1094 bstrip(szBuffer);
1095 if (*szBuffer) {
1096 strcpy(szBuff, wa->szCurrentPath);
1097 if (szBuff[strlen(szBuff) - 1] != '\\')
1098 strcat(szBuff, "\\");
1099 strcat(szBuff, szBuffer);
1100 MakeFullName(szBuff);
1101 DosError(FERR_DISABLEHARDERR);
1102 hDir = HDIR_CREATE;
1103 ulSearchCount = 1;
1104 if (!IsRoot(szBuff)) {
1105 rc = DosFindFirst(szBuff,
1106 &hDir,
1107 FILE_DIRECTORY |
1108 MUST_HAVE_DIRECTORY | FILE_READONLY |
1109 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
1110 &findbuf,
1111 sizeof(FILEFINDBUF3),
1112 &ulSearchCount, FIL_STANDARD);
1113 if (!rc)
1114 DosFindClose(hDir);
1115 }
1116 else {
1117 findbuf.attrFile = FILE_DIRECTORY;
1118 rc = 0;
1119 }
1120 if (!rc && (findbuf.attrFile & FILE_DIRECTORY)) {
1121 strcpy(wa->szCurrentPath, szBuff);
1122 WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath);
1123 FillPathListBox(hwnd,
1124 WinWindowFromID(hwnd, WALK_DRIVELIST),
1125 WinWindowFromID(hwnd, WALK_DIRLIST),
1126 wa->szCurrentPath, FALSE);
1127 }
1128 }
1129 }
1130 else if (SHORT2FROMMP(mp1) == LN_SETFOCUS)
1131 WinSetDlgItemText(hwnd, WALK_HELP,
1132 GetPString(IDS_WALKDIRLISTHELPTEXT));
1133 else if (SHORT2FROMMP(mp1) == LN_KILLFOCUS)
1134 WinSetDlgItemText(hwnd, WALK_HELP,
1135 GetPString(IDS_WALKDEFAULTHELPTEXT));
1136 break;
1137 }
1138 return 0;
1139
1140 case WM_COMMAND:
1141 wa = WinQueryWindowPtr(hwnd, QWL_USER);
1142 if (!wa)
1143 WinDismissDlg(hwnd, 0);
1144 *szBuff = 0;
1145 WinQueryDlgItemText(hwnd, WALK_PATH, CCHMAXPATH, szBuff);
1146 bstrip(szBuff);
1147 while ((p = strchr(szBuff, '/')) != NULL)
1148 *p = '\\';
1149 while (strlen(szBuff) > 3 && szBuff[strlen(szBuff) - 1] == '\\')
1150 szBuff[strlen(szBuff) - 1] = 0;
1151 MakeFullName(szBuff);
1152 if (*szBuff && stricmp(szBuff, wa->szCurrentPath) && SHORT1FROMMP(mp1) != DID_CANCEL) {
1153 if (!SetDir(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
1154 QW_OWNER), hwnd, szBuff, 0))
1155 strcpy(wa->szCurrentPath, szBuff);
1156 else
1157 return 0;
1158 }
1159 WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath);
1160 switch (SHORT1FROMMP(mp1)) {
1161 case WALK_ADD:
1162 *szBuff = 0;
1163 WinQueryDlgItemText(hwnd, WALK_PATH, CCHMAXPATH, szBuff);
1164 bstrip(szBuff);
1165 while ((p = strchr(szBuff, '/')) != NULL)
1166 *p = '\\';
1167 if (*szBuff && !IsFile(szBuff)) {
1168 MakeFullName(szBuff);
1169 add_udir(TRUE, szBuff);
1170 if (fUdirsChanged) {
1171 WinSendDlgItemMsg(hwnd,
1172 WALK_USERLIST,
1173 LM_INSERTITEM,
1174 MPFROM2SHORT(LIT_SORTASCENDING, 0),
1175 MPFROMP(szBuff));
1176 wa->changed = 1;
1177 }
1178 }
1179 break;
1180
1181 case WALK_DELETE:
1182 *szBuff = 0;
1183 WinQueryDlgItemText(hwnd, WALK_PATH, CCHMAXPATH, szBuff);
1184 bstrip(szBuff);
1185 while ((p = strchr(szBuff, '/')) != NULL)
1186 *p = '\\';
1187 if (*szBuff && !IsFile(szBuff)) {
1188 MakeFullName(szBuff);
1189 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
1190 WALK_USERLIST,
1191 LM_SEARCHSTRING,
1192 MPFROM2SHORT(0, LIT_FIRST),
1193 MPFROMP(szBuff));
1194 if (sSelect >= 0) {
1195 WinSendDlgItemMsg(hwnd,
1196 WALK_USERLIST,
1197 LM_DELETEITEM, MPFROM2SHORT(sSelect, 0), MPVOID);
1198 remove_udir(szBuff);
1199 wa->changed = 1;
1200 }
1201 }
1202 break;
1203
1204 case DID_OK:
1205 if (*wa->szCurrentPath) {
1206 strcpy(wa->szReturnPath, wa->szCurrentPath);
1207 MakeValidDir(wa->szReturnPath);
1208 if (fAutoAddAllDirs)
1209 add_udir(FALSE, wa->szReturnPath);
1210 if (fChangeTarget) {
1211 strcpy(targetdir, wa->szReturnPath);
1212 PrfWriteProfileString(fmprof, appname, "Targetdir", targetdir);
1213 }
1214 }
1215 {
1216 SWP swp;
1217 ULONG size = sizeof(SWP);
1218
1219 WinQueryWindowPos(hwnd, &swp);
1220 PrfWriteProfileData(fmprof, FM3Str, "WalkDir.Position", (PVOID) &swp,
1221 size);
1222 }
1223 if (wa->changed)
1224 WinSendMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
1225 WinDismissDlg(hwnd, 1);
1226 break;
1227
1228 case IDM_HELP:
1229 if (hwndHelp)
1230 WinSendMsg(hwndHelp,
1231 HM_DISPLAY_HELP,
1232 MPFROM2SHORT(HELP_WALKEM, 0), MPFROMSHORT(HM_RESOURCEID));
1233 break;
1234
1235 case DID_CANCEL:
1236 {
1237 SWP swp;
1238 ULONG size = sizeof(SWP);
1239
1240 WinQueryWindowPos(hwnd, &swp);
1241 PrfWriteProfileData(fmprof, FM3Str, "WalkDir.Position", (PVOID) &swp,
1242 size);
1243 }
1244 if (wa->changed)
1245 WinSendMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
1246 free(wa);
1247 WinDismissDlg(hwnd, 0);
1248 break;
1249 }
1250 return 0;
1251
1252 case WM_CLOSE:
1253 break;
1254 }
1255 return WinDefDlgProc(hwnd, msg, mp1, mp2);
1256}
1257
1258MRESULT EXPENTRY WalkAllDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1259{
1260 switch (msg) {
1261 case WM_INITDLG:
1262 return WalkDlgProc(hwnd, UM_SETUP2, mp1, mp2);
1263 }
1264 return WalkDlgProc(hwnd, msg, mp1, mp2);
1265}
1266
1267MRESULT EXPENTRY WalkCopyDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1268{
1269 switch (msg) {
1270 case WM_INITDLG:
1271 WinSetWindowText(hwnd, GetPString(IDS_WALKCOPYDLGTEXT));
1272 return WalkDlgProc(hwnd, UM_SETUP2, mp1, mp2);
1273 }
1274 return WalkDlgProc(hwnd, msg, mp1, mp2);
1275}
1276
1277MRESULT EXPENTRY WalkMoveDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1278{
1279 switch (msg) {
1280 case WM_INITDLG:
1281 WinSetWindowText(hwnd, GetPString(IDS_WALKMOVEDLGTEXT));
1282 return WalkDlgProc(hwnd, UM_SETUP2, mp1, mp2);
1283 }
1284 return WalkDlgProc(hwnd, msg, mp1, mp2);
1285}
1286
1287MRESULT EXPENTRY WalkExtractDlgProc(HWND hwnd, ULONG msg, MPARAM mp1,
1288 MPARAM mp2)
1289{
1290 switch (msg) {
1291 case WM_INITDLG:
1292 WinSetWindowText(hwnd, GetPString(IDS_WALKEXTRACTDLGTEXT));
1293 return WalkDlgProc(hwnd, UM_SETUP2, mp1, mp2);
1294 }
1295 return WalkDlgProc(hwnd, msg, mp1, mp2);
1296}
1297
1298MRESULT EXPENTRY WalkTargetDlgProc(HWND hwnd, ULONG msg, MPARAM mp1,
1299 MPARAM mp2)
1300{
1301 switch (msg) {
1302 case WM_INITDLG:
1303 {
1304 char s[CCHMAXPATH + 32];
1305
1306 sprintf(s,
1307 GetPString(IDS_WALKTARGETDLGTEXT),
1308 (*targetdir) ?
1309 NullStr :
1310 " (",
1311 (*targetdir) ?
1312 NullStr : GetPString(IDS_NONE), (*targetdir) ? NullStr : ")");
1313 WinSetWindowText(hwnd, s);
1314 }
1315 return WalkDlgProc(hwnd, UM_SETUP2, mp1, mp2);
1316 }
1317 return WalkDlgProc(hwnd, msg, mp1, mp2);
1318}
1319
1320MRESULT EXPENTRY WalkTwoDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1321{
1322 WALK2 *wa;
1323 CHAR szBuff[CCHMAXPATH + 1], szBuffer[CCHMAXPATH + 1], *p;
1324 SHORT sSelect;
1325 static BOOL okay; /* avoid combobox selecting as filled */
1326
1327 switch (msg) {
1328 case UM_SETUP2:
1329 case WM_INITDLG:
1330 okay = FALSE;
1331 if (!mp2) {
1332 WinDismissDlg(hwnd, 0);
1333 break;
1334 }
1335 WinSetWindowPtr(hwnd, QWL_USER, mp2);
1336 wa = mp2;
1337 {
1338 PFNWP oldproc;
1339
1340 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, WALK_PATH),
1341 (PFNWP) TextSubProc);
1342 if (oldproc)
1343 WinSetWindowPtr(WinWindowFromID(hwnd, WALK_PATH),
1344 QWL_USER, (PVOID) oldproc);
1345 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, WALK2_PATH),
1346 (PFNWP) TextSubProc);
1347 if (oldproc)
1348 WinSetWindowPtr(WinWindowFromID(hwnd, WALK2_PATH),
1349 QWL_USER, (PVOID) oldproc);
1350 }
1351 {
1352 SWP swp;
1353 ULONG size = sizeof(SWP);
1354
1355 PrfQueryProfileData(fmprof, FM3Str, "WalkDir2.Position", (PVOID) &swp, &size);
1356 WinSetWindowPos(hwnd,
1357 HWND_TOP,
1358 swp.x,
1359 swp.y,
1360 swp.cx,
1361 swp.cy,
1362 swp.fl);
1363 }
1364 if (!*wa->szCurrentPath1)
1365 save_dir2(wa->szCurrentPath1);
1366 MakeFullName(wa->szCurrentPath1);
1367 if (!*wa->szCurrentPath2)
1368 save_dir2(wa->szCurrentPath2);
1369 MakeFullName(wa->szCurrentPath2);
1370 WinSendDlgItemMsg(hwnd,
1371 WALK_PATH,
1372 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
1373 WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath1);
1374 WinSendDlgItemMsg(hwnd, WALK2_PATH, EM_SETTEXTLIMIT,
1375 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
1376 WinSetDlgItemText(hwnd, WALK2_PATH, wa->szCurrentPath2);
1377 FillPathListBox(hwnd,
1378 WinWindowFromID(hwnd, WALK_DRIVELIST),
1379 WinWindowFromID(hwnd, WALK_DIRLIST),
1380 wa->szCurrentPath1, FALSE);
1381 FillPathListBox(hwnd,
1382 WinWindowFromID(hwnd, WALK2_DRIVELIST),
1383 WinWindowFromID(hwnd, WALK2_DIRLIST),
1384 wa->szCurrentPath2, FALSE);
1385 if (!PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID))
1386 okay = TRUE;
1387 {
1388 MRESULT ret;
1389
1390 ret = WinDefDlgProc(hwnd, WM_INITDLG, mp1, mp2);
1391 WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
1392 WinInvalidateRect(WinWindowFromID(hwnd, WALK_PATH), NULL, TRUE);
1393 WinInvalidateRect(WinWindowFromID(hwnd, WALK2_PATH), NULL, TRUE);
1394 return ret;
1395 }
1396
1397 case UM_SETUP4:
1398 okay = TRUE;
1399 return 0;
1400
1401 case WM_PRESPARAMCHANGED:
1402 {
1403 ULONG AttrFound, AttrValue[64], cbRetLen;
1404
1405 cbRetLen = WinQueryPresParam(hwnd, (ULONG) mp1, 0, &AttrFound,
1406 (ULONG) sizeof(AttrValue), &AttrValue, 0);
1407 if (cbRetLen) {
1408 switch (AttrFound) {
1409 case PP_FONTNAMESIZE:
1410 PrfWriteProfileData(fmprof,
1411 appname,
1412 "WalkFont", (PVOID) AttrValue, cbRetLen);
1413 *WalkFont = 0;
1414 WalkFontSize = sizeof(WalkFont);
1415 WinInvalidateRect(WinWindowFromID(hwnd, WALK_PATH), NULL, TRUE);
1416 break;
1417 }
1418 }
1419 }
1420 break;
1421
1422 case UM_SETUP:
1423 {
1424 INT x;
1425 USHORT id[] = { WALK_PATH, WALK_DIRLIST,
1426 WALK2_PATH, WALK2_DIRLIST, 0
1427 };
1428
1429 if (*WalkFont ||
1430 (PrfQueryProfileData(fmprof,
1431 appname,
1432 "WalkFont",
1433 (PVOID) WalkFont,
1434 &WalkFontSize) && WalkFontSize)) {
1435 for (x = 0; id[x]; x++)
1436 WinSetPresParam(WinWindowFromID(hwnd, id[x]),
1437 PP_FONTNAMESIZE, WalkFontSize, (PVOID) WalkFont);
1438 }
1439 }
1440 return 0;
1441
1442 case UM_CONTROL:
1443 case WM_CONTROL:
1444 wa = WinQueryWindowPtr(hwnd, QWL_USER);
1445 if (SHORT1FROMMP(mp1) == WALK_DRIVELIST ||
1446 SHORT1FROMMP(mp1) == WALK_DIRLIST ||
1447 SHORT1FROMMP(mp1) == WALK2_DRIVELIST ||
1448 SHORT1FROMMP(mp1) == WALK2_DIRLIST) {
1449 sSelect = (USHORT) WinSendDlgItemMsg(hwnd,
1450 SHORT1FROMMP(mp1),
1451 LM_QUERYSELECTION, MPVOID, MPVOID);
1452 *szBuffer = 0;
1453 if (sSelect >= 0)
1454 WinSendDlgItemMsg(hwnd, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
1455 MPFROM2SHORT(sSelect, CCHMAXPATH),
1456 MPFROMP(szBuffer));
1457 }
1458 switch (SHORT1FROMMP(mp1)) {
1459 case WALK_DRIVELIST:
1460 if (okay && *szBuffer && SHORT2FROMMP(mp1) == LN_ENTER) {
1461
1462 ULONG ulDirLen = CCHMAXPATH;
1463 APIRET rc;
1464
1465 rc = DosQCurDir(toupper(*szBuffer) - '@', &szBuff[3], &ulDirLen);
1466 if (!rc) {
1467 strcpy(wa->szCurrentPath1, "C:\\");
1468 *wa->szCurrentPath1 = toupper(*szBuffer);
1469 WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath1);
1470 FillPathListBox(hwnd,
1471 WinWindowFromID(hwnd, WALK_DRIVELIST),
1472 WinWindowFromID(hwnd, WALK_DIRLIST),
1473 wa->szCurrentPath1, FALSE);
1474 }
1475 }
1476 break;
1477
1478 case WALK_DIRLIST:
1479 if (okay && SHORT2FROMMP(mp1) == LN_ENTER) {
1480
1481 ULONG ulSearchCount;
1482 FILEFINDBUF3 findbuf;
1483 HDIR hDir;
1484 APIRET rc;
1485
1486 bstrip(szBuffer);
1487 if (*szBuffer) {
1488 strcpy(szBuff, wa->szCurrentPath1);
1489 if (szBuff[strlen(szBuff) - 1] != '\\')
1490 strcat(szBuff, "\\");
1491 strcat(szBuff, szBuffer);
1492 MakeFullName(szBuff);
1493 DosError(FERR_DISABLEHARDERR);
1494 hDir = HDIR_CREATE;
1495 ulSearchCount = 1;
1496 if (!IsRoot(szBuff)) {
1497 rc = DosFindFirst(szBuff,
1498 &hDir,
1499 FILE_DIRECTORY |
1500 MUST_HAVE_DIRECTORY | FILE_READONLY |
1501 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
1502 &findbuf,
1503 sizeof(FILEFINDBUF3),
1504 &ulSearchCount, FIL_STANDARD);
1505 if (!rc)
1506 DosFindClose(hDir);
1507 }
1508 else {
1509 findbuf.attrFile = FILE_DIRECTORY;
1510 rc = 0;
1511 }
1512 if (!rc && (findbuf.attrFile & FILE_DIRECTORY)) {
1513 strcpy(wa->szCurrentPath1, szBuff);
1514 WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath1);
1515 FillPathListBox(hwnd,
1516 WinWindowFromID(hwnd, WALK_DRIVELIST),
1517 WinWindowFromID(hwnd, WALK_DIRLIST),
1518 wa->szCurrentPath1, FALSE);
1519 }
1520 }
1521 }
1522 break;
1523
1524 case WALK2_DRIVELIST:
1525 if (okay && *szBuffer && SHORT2FROMMP(mp1) == LN_ENTER) {
1526
1527 ULONG ulDirLen = CCHMAXPATH;
1528 APIRET rc;
1529
1530 rc = DosQCurDir(toupper(*szBuffer) - '@', &szBuff[3], &ulDirLen);
1531 if (!rc) {
1532 strcpy(wa->szCurrentPath2, "C:\\");
1533 *wa->szCurrentPath2 = toupper(*szBuffer);
1534 WinSetDlgItemText(hwnd, WALK2_PATH, wa->szCurrentPath2);
1535 FillPathListBox(hwnd,
1536 WinWindowFromID(hwnd, WALK2_DRIVELIST),
1537 WinWindowFromID(hwnd, WALK2_DIRLIST),
1538 wa->szCurrentPath2, FALSE);
1539 }
1540 }
1541 break;
1542
1543 case WALK2_DIRLIST:
1544 if (okay && SHORT2FROMMP(mp1) == LN_ENTER) {
1545
1546 ULONG ulSearchCount;
1547 FILEFINDBUF3 findbuf;
1548 HDIR hDir;
1549 APIRET rc;
1550
1551 bstrip(szBuffer);
1552 if (*szBuffer) {
1553 strcpy(szBuff, wa->szCurrentPath2);
1554 if (szBuff[strlen(szBuff) - 1] != '\\')
1555 strcat(szBuff, "\\");
1556 strcat(szBuff, szBuffer);
1557 MakeFullName(szBuff);
1558 DosError(FERR_DISABLEHARDERR);
1559 hDir = HDIR_CREATE;
1560 ulSearchCount = 1;
1561 if (!IsRoot(szBuff)) {
1562 rc = DosFindFirst(szBuff,
1563 &hDir,
1564 FILE_DIRECTORY |
1565 MUST_HAVE_DIRECTORY | FILE_READONLY |
1566 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
1567 &findbuf,
1568 sizeof(FILEFINDBUF3),
1569 &ulSearchCount, FIL_STANDARD);
1570 if (!rc)
1571 DosFindClose(hDir);
1572 }
1573 else {
1574 findbuf.attrFile = FILE_DIRECTORY;
1575 rc = 0;
1576 }
1577 if (!rc && (findbuf.attrFile & FILE_DIRECTORY)) {
1578 strcpy(wa->szCurrentPath2, szBuff);
1579 WinSetDlgItemText(hwnd, WALK2_PATH, wa->szCurrentPath2);
1580 FillPathListBox(hwnd,
1581 WinWindowFromID(hwnd, WALK2_DRIVELIST),
1582 WinWindowFromID(hwnd, WALK2_DIRLIST),
1583 wa->szCurrentPath2, FALSE);
1584 }
1585 }
1586 }
1587 break;
1588 }
1589 return 0;
1590
1591 case WM_COMMAND:
1592 wa = WinQueryWindowPtr(hwnd, QWL_USER);
1593 if (!wa)
1594 WinDismissDlg(hwnd, 0);
1595 *szBuff = 0;
1596 WinQueryDlgItemText(hwnd, WALK_PATH, CCHMAXPATH, szBuff);
1597 bstrip(szBuff);
1598 while ((p = strchr(szBuff, '/')) != NULL)
1599 *p = '\\';
1600 while (strlen(szBuff) > 3 && szBuff[strlen(szBuff) - 1] == '\\')
1601 szBuff[strlen(szBuff) - 1] = 0;
1602 MakeFullName(szBuff);
1603 if (*szBuff && stricmp(szBuff, wa->szCurrentPath1) && SHORT1FROMMP(mp1) != DID_CANCEL) {
1604 if (!SetDir(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
1605 QW_OWNER), hwnd, szBuff, 0))
1606 strcpy(wa->szCurrentPath1, szBuff);
1607 else
1608 return 0;
1609 }
1610 WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath1);
1611 *szBuff = 0;
1612 WinQueryDlgItemText(hwnd, WALK2_PATH, CCHMAXPATH, szBuff);
1613 bstrip(szBuff);
1614 while ((p = strchr(szBuff, '/')) != NULL)
1615 *p = '\\';
1616 while (strlen(szBuff) > 3 && szBuff[strlen(szBuff) - 1] == '\\')
1617 szBuff[strlen(szBuff) - 1] = 0;
1618 MakeFullName(szBuff);
1619 if (*szBuff && stricmp(szBuff, wa->szCurrentPath2) && SHORT1FROMMP(mp1) != DID_CANCEL) {
1620 if (!SetDir(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
1621 QW_OWNER), hwnd, szBuff, 0))
1622 strcpy(wa->szCurrentPath2, szBuff);
1623 else
1624 return 0;
1625 }
1626 WinSetDlgItemText(hwnd, WALK2_PATH, wa->szCurrentPath2);
1627 switch (SHORT1FROMMP(mp1)) {
1628 case DID_OK:
1629 {
1630 SWP swp;
1631 ULONG size = sizeof(SWP);
1632
1633 WinQueryWindowPos(hwnd, &swp);
1634 PrfWriteProfileData(fmprof, FM3Str, "WalkDir2.Position", (PVOID) &swp,
1635 size);
1636 }
1637 WinDismissDlg(hwnd, 1);
1638 break;
1639
1640 case IDM_HELP:
1641 if (hwndHelp)
1642 WinSendMsg(hwndHelp,
1643 HM_DISPLAY_HELP,
1644 MPFROM2SHORT(HELP_WALKEM2, 0), MPFROMSHORT(HM_RESOURCEID));
1645 break;
1646
1647 case DID_CANCEL:
1648 {
1649 SWP swp;
1650 ULONG size = sizeof(SWP);
1651
1652 WinQueryWindowPos(hwnd, &swp);
1653 PrfWriteProfileData(fmprof, FM3Str, "WalkDir2.Position", (PVOID) &swp,
1654 size);
1655 }
1656 WinDismissDlg(hwnd, 0);
1657 break;
1658 }
1659 return 0;
1660
1661 case WM_CLOSE:
1662 break;
1663 }
1664 return WinDefDlgProc(hwnd, msg, mp1, mp2);
1665}
1666
1667MRESULT EXPENTRY WalkTwoCmpDlgProc(HWND hwnd, ULONG msg, MPARAM mp1,
1668 MPARAM mp2)
1669{
1670 switch (msg) {
1671 case WM_INITDLG:
1672 WinSetWindowText(hwnd, GetPString(IDS_WALKCOMPAREDLGTEXT));
1673 return WalkTwoDlgProc(hwnd, UM_SETUP2, mp1, mp2);
1674 }
1675 return WalkTwoDlgProc(hwnd, msg, mp1, mp2);
1676}
1677
1678MRESULT EXPENTRY WalkTwoSetDlgProc(HWND hwnd, ULONG msg, MPARAM mp1,
1679 MPARAM mp2)
1680{
1681 switch (msg) {
1682 case WM_INITDLG:
1683 WinSetWindowText(hwnd, GetPString(IDS_WALKSETDIRSDLGTEXT));
1684 return WalkTwoDlgProc(hwnd, UM_SETUP2, mp1, mp2);
1685 }
1686 return WalkTwoDlgProc(hwnd, msg, mp1, mp2);
1687}
1688
1689#pragma alloc_text(WALKER,FillPathListBox,WalkDlgProc,TextSubProc)
1690#pragma alloc_text(WALKER,WalkAllDlgProc,WalkCopyDlgProc)
1691#pragma alloc_text(WALKER,WalkMoveDlgProc,WalkExtractDlgProc,WalkTargetDlgProc)
1692#pragma alloc_text(WALK2,WalkTwoDlgProc,WalkTwoCmpDlgProc,WalkTwoSetDlgProc)
1693#pragma alloc_text(UDIRS,add_udir,remove_udir,remove_ldir,load_udirs)
1694#pragma alloc_text(UDIRS,save_udirs,load_setups,save_setups,add_setups)
1695#pragma alloc_text(UDIRS,remove_setup)
Note: See TracBrowser for help on using the repository browser.