source: trunk/dll/walkem.c@ 864

Last change on this file since 864 was 864, checked in by Gregg Young, 18 years ago

Cancel in walk directory dialog now directly closes dialog even if directory path text has changed (Ticket 85)

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