1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: filter.c 1185 2008-09-10 21:57:10Z jbs $
|
---|
5 |
|
---|
6 | Filter mask select dialog
|
---|
7 |
|
---|
8 | Copyright (c) 1993-98 M. Kimes
|
---|
9 | Copyright (c) 2004, 2007 Steven H.Levine
|
---|
10 |
|
---|
11 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
---|
12 | 22 Jul 06 SHL Check more run time errors
|
---|
13 | 29 Jul 06 SHL Use xfgets_bstripcr
|
---|
14 | 22 Mar 07 GKY Use QWL_USER
|
---|
15 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
16 | 29 Feb 08 GKY Use xfree where appropriate
|
---|
17 | 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory and use BldFullPathName
|
---|
18 | 24 Aug 08 GKY Warn full drive on save of .DAT file; prevent loss of existing file
|
---|
19 |
|
---|
20 | ***********************************************************************/
|
---|
21 |
|
---|
22 | #include <stdlib.h>
|
---|
23 | #include <string.h>
|
---|
24 | #include <share.h>
|
---|
25 |
|
---|
26 | #define INCL_WIN
|
---|
27 | #define INCL_DOS
|
---|
28 | #define INCL_LONGLONG // dircnrs.h
|
---|
29 |
|
---|
30 | #include "fm3dll.h"
|
---|
31 | #include "fm3dlg.h"
|
---|
32 | #include "fm3str.h"
|
---|
33 | #include "errutil.h" // Dos_Error...
|
---|
34 | #include "strutil.h" // GetPString
|
---|
35 | #include "pathutil.h" // BldFullPathName
|
---|
36 | #include "filter.h"
|
---|
37 | #include "select.h" // SetMask
|
---|
38 | #include "literal.h" // wildcard
|
---|
39 | #include "strips.h" // bstrip
|
---|
40 | #include "misc.h" // CheckDriveSpaceAvail
|
---|
41 | #include "wrappers.h" // xfgets_bstripcr
|
---|
42 | #include "dirs.h" // save_dir2
|
---|
43 | #include "fortify.h"
|
---|
44 |
|
---|
45 | #pragma data_seg(FILTER_DATA)
|
---|
46 |
|
---|
47 | static PSZ pszSrcFile = __FILE__;
|
---|
48 |
|
---|
49 | #define MAXNUMMASKS 50
|
---|
50 |
|
---|
51 | typedef struct LINKMASKS
|
---|
52 | {
|
---|
53 | CHAR *mask;
|
---|
54 | struct LINKMASKS *next;
|
---|
55 | }
|
---|
56 | LINKMASKS;
|
---|
57 |
|
---|
58 | static LINKMASKS *maskhead = NULL;
|
---|
59 | static BOOL loadedmasks = FALSE;
|
---|
60 |
|
---|
61 | static VOID save_masks(VOID);
|
---|
62 |
|
---|
63 | INT APIENTRY Filter(PMINIRECORDCORE rmini, PVOID arg)
|
---|
64 | {
|
---|
65 |
|
---|
66 | MASK *mask = (MASK *) arg;
|
---|
67 | PCNRITEM r;
|
---|
68 | register INT x;
|
---|
69 | INT ret = FALSE;
|
---|
70 | CHAR *file;
|
---|
71 |
|
---|
72 | if (mask) {
|
---|
73 | r = (PCNRITEM) rmini;
|
---|
74 | if (!(*(r->pszFileName + 3))
|
---|
75 | || (mask->fShowDirs && (r->attrFile & FILE_DIRECTORY)))
|
---|
76 | return TRUE;
|
---|
77 | if ((!(mask->attrFile & FILE_HIDDEN) && (r->attrFile & FILE_HIDDEN)) ||
|
---|
78 | (!(mask->attrFile & FILE_SYSTEM) && (r->attrFile & FILE_SYSTEM)) ||
|
---|
79 | (!(mask->attrFile & FILE_READONLY) && (r->attrFile & FILE_READONLY))
|
---|
80 | || (!(mask->attrFile & FILE_ARCHIVED)
|
---|
81 | && (r->attrFile & FILE_ARCHIVED))
|
---|
82 | || (!(mask->attrFile & FILE_DIRECTORY)
|
---|
83 | && (r->attrFile & FILE_DIRECTORY)))
|
---|
84 | return FALSE;
|
---|
85 | if (((mask->antiattr & FILE_HIDDEN) && !(r->attrFile & FILE_HIDDEN)) ||
|
---|
86 | ((mask->antiattr & FILE_SYSTEM) && !(r->attrFile & FILE_SYSTEM)) ||
|
---|
87 | ((mask->antiattr & FILE_READONLY) && !(r->attrFile & FILE_READONLY))
|
---|
88 | || ((mask->antiattr & FILE_ARCHIVED)
|
---|
89 | && !(r->attrFile & FILE_ARCHIVED))
|
---|
90 | || ((mask->antiattr & FILE_DIRECTORY)
|
---|
91 | && !(r->attrFile & FILE_DIRECTORY)))
|
---|
92 | return FALSE;
|
---|
93 | if (*mask->szMask) {
|
---|
94 | file = strrchr(r->pszFileName, '\\');
|
---|
95 | if (!file)
|
---|
96 | file = strrchr(r->pszFileName, ':');
|
---|
97 | if (file)
|
---|
98 | file++;
|
---|
99 | else
|
---|
100 | file = r->pszFileName;
|
---|
101 | if (mask->pszMasks[1]) {
|
---|
102 | for (x = 0; mask->pszMasks[x]; x++) {
|
---|
103 | if (*mask->pszMasks[x]) {
|
---|
104 | if (*mask->pszMasks[x] != '/') {
|
---|
105 | if (wildcard((strchr(mask->pszMasks[x], '\\') ||
|
---|
106 | strchr(mask->pszMasks[x], ':')) ?
|
---|
107 | r->pszFileName : file, mask->pszMasks[x], FALSE))
|
---|
108 | ret = TRUE;
|
---|
109 | }
|
---|
110 | else {
|
---|
111 | if (wildcard((strchr(mask->pszMasks[x], '\\') ||
|
---|
112 | strchr(mask->pszMasks[x], ':')) ?
|
---|
113 | r->pszFileName : file, mask->pszMasks[x] + 1,
|
---|
114 | FALSE)) {
|
---|
115 | ret = FALSE;
|
---|
116 | break;
|
---|
117 | }
|
---|
118 | }
|
---|
119 | }
|
---|
120 | }
|
---|
121 | }
|
---|
122 | else {
|
---|
123 | if (wildcard((strchr(mask->szMask, '\\') ||
|
---|
124 | strchr(mask->szMask, ':')) ?
|
---|
125 | r->pszFileName : file, mask->szMask, FALSE))
|
---|
126 | ret = TRUE;
|
---|
127 | }
|
---|
128 | }
|
---|
129 | else
|
---|
130 | ret = TRUE;
|
---|
131 | }
|
---|
132 | else
|
---|
133 | ret = TRUE;
|
---|
134 | return ret;
|
---|
135 | }
|
---|
136 |
|
---|
137 | VOID load_masks(VOID)
|
---|
138 | {
|
---|
139 |
|
---|
140 | /* load linked list of filter masks from FILTERS.DAT file */
|
---|
141 |
|
---|
142 | FILE *fp;
|
---|
143 | LINKMASKS *info, *last = NULL;
|
---|
144 | CHAR s[CCHMAXPATH + 24];
|
---|
145 |
|
---|
146 | loadedmasks = TRUE;
|
---|
147 | BldFullPathName(s, pFM2SaveDirectory, "FILTER.DAT");
|
---|
148 | fp = _fsopen(s, "r", SH_DENYWR);
|
---|
149 | if (fp) {
|
---|
150 | while (!feof(fp)) {
|
---|
151 | if (!xfgets_bstripcr(s, sizeof(s), fp, pszSrcFile, __LINE__))
|
---|
152 | break;
|
---|
153 | if (*s && *s != ';') {
|
---|
154 | info = xmalloc(sizeof(LINKMASKS), pszSrcFile, __LINE__);
|
---|
155 | if (info) {
|
---|
156 | info->mask = xstrdup(s, pszSrcFile, __LINE__);
|
---|
157 | if (info->mask) {
|
---|
158 | info->next = NULL;
|
---|
159 | if (!maskhead)
|
---|
160 | maskhead = info;
|
---|
161 | else
|
---|
162 | last->next = info;
|
---|
163 | last = info;
|
---|
164 | }
|
---|
165 | else
|
---|
166 | free(info);
|
---|
167 | }
|
---|
168 | }
|
---|
169 | } //while
|
---|
170 | fclose(fp);
|
---|
171 | }
|
---|
172 | }
|
---|
173 |
|
---|
174 | VOID save_masks(VOID)
|
---|
175 | {
|
---|
176 |
|
---|
177 | /* save linked list of filter masks to FILTERS.DAT file */
|
---|
178 |
|
---|
179 | LINKMASKS *info;
|
---|
180 | FILE *fp;
|
---|
181 | CHAR s[CCHMAXPATH + 14];
|
---|
182 |
|
---|
183 | if (!loadedmasks)
|
---|
184 | return;
|
---|
185 | if (maskhead) {
|
---|
186 | BldFullPathName(s, pFM2SaveDirectory, "FILTER.DAT");
|
---|
187 | if (CheckDriveSpaceAvail(s, ullDATFileSpaceNeeded, 1) == 2)
|
---|
188 | return; //already gave error msg
|
---|
189 | fp = xfopen(s, "w", pszSrcFile, __LINE__);
|
---|
190 | if (fp) {
|
---|
191 | fputs(GetPString(IDS_FILTERFILETEXT), fp);
|
---|
192 | info = maskhead;
|
---|
193 | while (info) {
|
---|
194 | fprintf(fp, "%0.*s\n", CCHMAXPATH, info->mask);
|
---|
195 | info = info->next;
|
---|
196 | }
|
---|
197 | fclose(fp);
|
---|
198 | }
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | VOID add_mask(CHAR * mask)
|
---|
203 | {
|
---|
204 |
|
---|
205 | LINKMASKS *info, *last = NULL;
|
---|
206 |
|
---|
207 | if (!mask || !*mask)
|
---|
208 | return;
|
---|
209 | if (!loadedmasks)
|
---|
210 | load_masks();
|
---|
211 | info = maskhead;
|
---|
212 | while (info) {
|
---|
213 | if (!stricmp(info->mask, mask))
|
---|
214 | return;
|
---|
215 | last = info;
|
---|
216 | info = info->next;
|
---|
217 | }
|
---|
218 | info = xmalloc(sizeof(LINKMASKS), pszSrcFile, __LINE__);
|
---|
219 | if (info) {
|
---|
220 | info->mask = xstrdup(mask, pszSrcFile, __LINE__);
|
---|
221 | if (info->mask) {
|
---|
222 | info->next = NULL;
|
---|
223 | if (!maskhead)
|
---|
224 | maskhead = info;
|
---|
225 | else
|
---|
226 | last->next = info;
|
---|
227 | }
|
---|
228 | else
|
---|
229 | free(info);
|
---|
230 | }
|
---|
231 | }
|
---|
232 |
|
---|
233 | VOID remove_mask(CHAR * mask)
|
---|
234 | {
|
---|
235 |
|
---|
236 | LINKMASKS *info, *last = NULL;
|
---|
237 |
|
---|
238 | if (!mask || !*mask)
|
---|
239 | return;
|
---|
240 | if (!loadedmasks)
|
---|
241 | load_masks();
|
---|
242 | info = maskhead;
|
---|
243 | while (info) {
|
---|
244 | if (!stricmp(info->mask, mask)) {
|
---|
245 | if (last)
|
---|
246 | last->next = info->next;
|
---|
247 | else
|
---|
248 | maskhead = info->next;
|
---|
249 | xfree(info->mask, pszSrcFile, __LINE__);
|
---|
250 | free(info);
|
---|
251 | break;
|
---|
252 | }
|
---|
253 | last = info;
|
---|
254 | info = info->next;
|
---|
255 | }
|
---|
256 | }
|
---|
257 |
|
---|
258 | MRESULT EXPENTRY PickMaskDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
259 | {
|
---|
260 |
|
---|
261 | switch (msg) {
|
---|
262 | case WM_INITDLG:
|
---|
263 | WinSendDlgItemMsg(hwnd, MSK_MASK, EM_SETTEXTLIMIT,
|
---|
264 | MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
|
---|
265 | if (!mp2) {
|
---|
266 | WinDismissDlg(hwnd, 0);
|
---|
267 | break;
|
---|
268 | }
|
---|
269 | if (!loadedmasks)
|
---|
270 | load_masks();
|
---|
271 | WinSetWindowPtr(hwnd, QWL_USER, mp2);
|
---|
272 | { /* fill list box */
|
---|
273 | LINKMASKS *info;
|
---|
274 |
|
---|
275 | info = maskhead;
|
---|
276 | while (info) {
|
---|
277 | WinSendDlgItemMsg(hwnd, MSK_LISTBOX, LM_INSERTITEM,
|
---|
278 | MPFROM2SHORT(LIT_SORTASCENDING, 0),
|
---|
279 | MPFROMP(info->mask));
|
---|
280 | info = info->next;
|
---|
281 | }
|
---|
282 | }
|
---|
283 | {
|
---|
284 | MASK *mask = (MASK *) mp2;
|
---|
285 |
|
---|
286 | if (mask->fNoAttribs) {
|
---|
287 | WinEnableWindow(WinWindowFromID(hwnd, MSK_SYSTEM), FALSE);
|
---|
288 | WinEnableWindow(WinWindowFromID(hwnd, MSK_HIDDEN), FALSE);
|
---|
289 | WinEnableWindow(WinWindowFromID(hwnd, MSK_READONLY), FALSE);
|
---|
290 | WinEnableWindow(WinWindowFromID(hwnd, MSK_ARCHIVED), FALSE);
|
---|
291 | WinEnableWindow(WinWindowFromID(hwnd, MSK_DIRECTORY), FALSE);
|
---|
292 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTSYSTEM), FALSE);
|
---|
293 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTHIDDEN), FALSE);
|
---|
294 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTREADONLY), FALSE);
|
---|
295 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTARCHIVED), FALSE);
|
---|
296 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTDIRECTORY), FALSE);
|
---|
297 | WinEnableWindow(WinWindowFromID(hwnd, MSK_SHOWDIRS), FALSE);
|
---|
298 | }
|
---|
299 | else {
|
---|
300 | WinCheckButton(hwnd, MSK_SYSTEM, (mask->attrFile & FILE_SYSTEM) != 0);
|
---|
301 | WinCheckButton(hwnd, MSK_HIDDEN, (mask->attrFile & FILE_HIDDEN) != 0);
|
---|
302 | WinCheckButton(hwnd, MSK_READONLY,
|
---|
303 | (mask->attrFile & FILE_READONLY) != 0);
|
---|
304 | WinCheckButton(hwnd, MSK_ARCHIVED,
|
---|
305 | (mask->attrFile & FILE_ARCHIVED) != 0);
|
---|
306 | WinCheckButton(hwnd, MSK_DIRECTORY,
|
---|
307 | (mask->attrFile & FILE_DIRECTORY) != 0);
|
---|
308 | WinCheckButton(hwnd, MSK_MUSTSYSTEM,
|
---|
309 | (mask->antiattr & FILE_SYSTEM) != 0);
|
---|
310 | WinCheckButton(hwnd, MSK_MUSTHIDDEN,
|
---|
311 | (mask->antiattr & FILE_HIDDEN) != 0);
|
---|
312 | WinCheckButton(hwnd, MSK_MUSTREADONLY,
|
---|
313 | (mask->antiattr & FILE_READONLY) != 0);
|
---|
314 | WinCheckButton(hwnd, MSK_MUSTARCHIVED,
|
---|
315 | (mask->antiattr & FILE_ARCHIVED) != 0);
|
---|
316 | WinCheckButton(hwnd, MSK_MUSTDIRECTORY,
|
---|
317 | (mask->antiattr & FILE_DIRECTORY) != 0);
|
---|
318 | if (mask->fNoDirs)
|
---|
319 | WinEnableWindow(WinWindowFromID(hwnd, MSK_SHOWDIRS), FALSE);
|
---|
320 | else
|
---|
321 | WinCheckButton(hwnd, MSK_SHOWDIRS, (mask->fShowDirs != FALSE));
|
---|
322 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTSYSTEM),
|
---|
323 | (mask->attrFile & FILE_SYSTEM) != 0);
|
---|
324 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTHIDDEN),
|
---|
325 | (mask->attrFile & FILE_HIDDEN) != 0);
|
---|
326 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTARCHIVED),
|
---|
327 | (mask->attrFile & FILE_ARCHIVED) != 0);
|
---|
328 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTREADONLY),
|
---|
329 | (mask->attrFile & FILE_READONLY) != 0);
|
---|
330 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTDIRECTORY),
|
---|
331 | (mask->attrFile & FILE_DIRECTORY) != 0);
|
---|
332 | }
|
---|
333 | if (*mask->szMask) {
|
---|
334 |
|
---|
335 | CHAR s[CCHMAXPATH], *p;
|
---|
336 |
|
---|
337 | strcpy(s, mask->szMask);
|
---|
338 | if (!strchr(mask->szMask, '?') && !strchr(mask->szMask, '*')) {
|
---|
339 | p = strrchr(mask->szMask, '.');
|
---|
340 | if (p && *(p + 1)) {
|
---|
341 | *s = '*';
|
---|
342 | strcpy(s + 1, p);
|
---|
343 | }
|
---|
344 | }
|
---|
345 | WinSetDlgItemText(hwnd, MSK_MASK, s);
|
---|
346 | WinSendDlgItemMsg(hwnd, MSK_MASK, EM_SETSEL,
|
---|
347 | MPFROM2SHORT(0, CCHMAXPATH), MPVOID);
|
---|
348 | // *mask->szMask = 0;
|
---|
349 | PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
|
---|
350 | }
|
---|
351 | if (mask->fIsTree) {
|
---|
352 | WinCheckButton(hwnd, MSK_DIRECTORY, TRUE);
|
---|
353 | WinCheckButton(hwnd, MSK_SHOWDIRS, FALSE);
|
---|
354 | WinEnableWindow(WinWindowFromID(hwnd, MSK_DIRECTORY), FALSE);
|
---|
355 | WinEnableWindow(WinWindowFromID(hwnd, MSK_SHOWDIRS), FALSE);
|
---|
356 | }
|
---|
357 | if (mask->fIsSeeAll) {
|
---|
358 | WinCheckButton(hwnd, MSK_DIRECTORY, FALSE);
|
---|
359 | WinCheckButton(hwnd, MSK_MUSTDIRECTORY, FALSE);
|
---|
360 | WinCheckButton(hwnd, MSK_SHOWDIRS, FALSE);
|
---|
361 | WinEnableWindow(WinWindowFromID(hwnd, MSK_DIRECTORY), FALSE);
|
---|
362 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTDIRECTORY), FALSE);
|
---|
363 | WinEnableWindow(WinWindowFromID(hwnd, MSK_SHOWDIRS), FALSE);
|
---|
364 | }
|
---|
365 | if (*mask->prompt)
|
---|
366 | WinSetWindowText(hwnd, mask->prompt);
|
---|
367 | if (!PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID))
|
---|
368 | WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
|
---|
369 | }
|
---|
370 | break;
|
---|
371 |
|
---|
372 | case UM_SETUP:
|
---|
373 | {
|
---|
374 | MASK *mask = WinQueryWindowPtr(hwnd, QWL_USER);
|
---|
375 |
|
---|
376 | if (mask && mask->fText) {
|
---|
377 |
|
---|
378 | SWP swpD, swpL, swpE;
|
---|
379 | LONG cyScreen;
|
---|
380 |
|
---|
381 | cyScreen = SysVal(SV_CYSCREEN);
|
---|
382 | WinQueryWindowPos(hwnd, &swpD);
|
---|
383 | if (!WinQueryWindowPos(WinWindowFromID(hwnd, MSK_MASK), &swpE))
|
---|
384 | swpE.cy = 18;
|
---|
385 | swpE.cy -= 4;
|
---|
386 | WinQueryWindowPos(WinWindowFromID(hwnd, MSK_LISTBOX), &swpL);
|
---|
387 | WinSetWindowPos(hwnd, HWND_TOP, swpD.x, swpD.y, swpD.cx,
|
---|
388 | swpD.cy + swpE.cy + 10, SWP_SIZE);
|
---|
389 | WinQueryWindowPos(hwnd, &swpD);
|
---|
390 | if (cyScreen && swpD.y + swpD.cy > cyScreen) {
|
---|
391 | swpD.y = (swpD.y + swpD.cy) - cyScreen;
|
---|
392 | WinSetWindowPos(hwnd, HWND_TOP, swpD.x, swpD.y, swpD.cx,
|
---|
393 | swpD.cy, SWP_MOVE);
|
---|
394 | }
|
---|
395 | if (!WinCreateWindow(hwnd,
|
---|
396 | WC_STATIC,
|
---|
397 | GetPString(IDS_TEXTTITLETEXT),
|
---|
398 | SS_TEXT |
|
---|
399 | DT_VCENTER | DT_RIGHT,
|
---|
400 | swpL.x,
|
---|
401 | swpL.y + swpL.cy + 4,
|
---|
402 | 50,
|
---|
403 | swpE.cy, hwnd, HWND_TOP, 65535, NULL, NULL)) {
|
---|
404 | Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
|
---|
405 | }
|
---|
406 | if (!WinCreateWindow(hwnd,
|
---|
407 | WC_ENTRYFIELD,
|
---|
408 | NULL,
|
---|
409 | ES_AUTOSCROLL |
|
---|
410 | ES_MARGIN | WS_GROUP | WS_TABSTOP,
|
---|
411 | swpL.x + 54,
|
---|
412 | swpL.y + swpL.cy + 4,
|
---|
413 | swpL.cx - 54,
|
---|
414 | swpE.cy, hwnd, HWND_TOP, MSK_TEXT, NULL, NULL)) {
|
---|
415 | Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
|
---|
416 | }
|
---|
417 | WinSendDlgItemMsg(hwnd,
|
---|
418 | MSK_TEXT,
|
---|
419 | EM_SETTEXTLIMIT, MPFROM2SHORT(256, 0), MPVOID);
|
---|
420 | if (mask->szText) {
|
---|
421 | WinSetDlgItemText(hwnd, MSK_TEXT, mask->szText);
|
---|
422 | WinSendDlgItemMsg(hwnd,
|
---|
423 | MSK_TEXT,
|
---|
424 | EM_SETSEL, MPFROM2SHORT(0, 256), MPVOID);
|
---|
425 | }
|
---|
426 | }
|
---|
427 | *mask->szText = 0;
|
---|
428 | }
|
---|
429 | WinShowWindow(hwnd, TRUE);
|
---|
430 | return 0;
|
---|
431 |
|
---|
432 | case UM_SETDIR:
|
---|
433 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, MSK_MASK));
|
---|
434 | return 0;
|
---|
435 |
|
---|
436 | case WM_CONTROL:
|
---|
437 | switch (SHORT1FROMMP(mp1)) {
|
---|
438 | case MSK_SYSTEM:
|
---|
439 | case MSK_HIDDEN:
|
---|
440 | case MSK_ARCHIVED:
|
---|
441 | case MSK_READONLY:
|
---|
442 | case MSK_DIRECTORY:
|
---|
443 | case MSK_MUSTSYSTEM:
|
---|
444 | case MSK_MUSTHIDDEN:
|
---|
445 | case MSK_MUSTARCHIVED:
|
---|
446 | case MSK_MUSTREADONLY:
|
---|
447 | case MSK_MUSTDIRECTORY:
|
---|
448 | if (WinQueryButtonCheckstate(hwnd, MSK_SYSTEM))
|
---|
449 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTSYSTEM), TRUE);
|
---|
450 | else {
|
---|
451 | WinCheckButton(hwnd, MSK_MUSTSYSTEM, FALSE);
|
---|
452 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTSYSTEM), FALSE);
|
---|
453 | }
|
---|
454 | if (WinQueryButtonCheckstate(hwnd, MSK_HIDDEN))
|
---|
455 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTHIDDEN), TRUE);
|
---|
456 | else {
|
---|
457 | WinCheckButton(hwnd, MSK_MUSTHIDDEN, FALSE);
|
---|
458 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTHIDDEN), FALSE);
|
---|
459 | }
|
---|
460 | if (WinQueryButtonCheckstate(hwnd, MSK_ARCHIVED))
|
---|
461 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTARCHIVED), TRUE);
|
---|
462 | else {
|
---|
463 | WinCheckButton(hwnd, MSK_MUSTARCHIVED, FALSE);
|
---|
464 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTARCHIVED), FALSE);
|
---|
465 | }
|
---|
466 | if (WinQueryButtonCheckstate(hwnd, MSK_READONLY))
|
---|
467 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTREADONLY), TRUE);
|
---|
468 | else {
|
---|
469 | WinCheckButton(hwnd, MSK_MUSTREADONLY, FALSE);
|
---|
470 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTREADONLY), FALSE);
|
---|
471 | }
|
---|
472 | if (WinQueryButtonCheckstate(hwnd, MSK_DIRECTORY)) {
|
---|
473 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTDIRECTORY), TRUE);
|
---|
474 | WinEnableWindow(WinWindowFromID(hwnd, MSK_SHOWDIRS), TRUE);
|
---|
475 | }
|
---|
476 | else {
|
---|
477 | WinCheckButton(hwnd, MSK_MUSTDIRECTORY, FALSE);
|
---|
478 | WinCheckButton(hwnd, MSK_SHOWDIRS, FALSE);
|
---|
479 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTDIRECTORY), FALSE);
|
---|
480 | WinEnableWindow(WinWindowFromID(hwnd, MSK_SHOWDIRS), FALSE);
|
---|
481 | }
|
---|
482 | {
|
---|
483 | MASK *mask = INSTDATA(hwnd);
|
---|
484 |
|
---|
485 | if (mask) {
|
---|
486 | if (mask->fIsTree) {
|
---|
487 | WinCheckButton(hwnd, MSK_DIRECTORY, TRUE);
|
---|
488 | WinCheckButton(hwnd, MSK_SHOWDIRS, FALSE);
|
---|
489 | WinEnableWindow(WinWindowFromID(hwnd, MSK_DIRECTORY), FALSE);
|
---|
490 | WinEnableWindow(WinWindowFromID(hwnd, MSK_SHOWDIRS), FALSE);
|
---|
491 | }
|
---|
492 | }
|
---|
493 | }
|
---|
494 | break;
|
---|
495 |
|
---|
496 | case MSK_LISTBOX:
|
---|
497 | switch (SHORT2FROMMP(mp1)) {
|
---|
498 | case LN_SELECT:
|
---|
499 | {
|
---|
500 | SHORT sSelect;
|
---|
501 | CHAR tempmask[CCHMAXPATH];
|
---|
502 |
|
---|
503 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
504 | MSK_LISTBOX,
|
---|
505 | LM_QUERYSELECTION,
|
---|
506 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
507 | *tempmask = 0;
|
---|
508 | if (sSelect >= 0)
|
---|
509 | WinSendDlgItemMsg(hwnd,
|
---|
510 | MSK_LISTBOX,
|
---|
511 | LM_QUERYITEMTEXT,
|
---|
512 | MPFROM2SHORT(sSelect,
|
---|
513 | CCHMAXPATH), MPFROMP(tempmask));
|
---|
514 | WinSetDlgItemText(hwnd, MSK_MASK, tempmask);
|
---|
515 | }
|
---|
516 | break;
|
---|
517 |
|
---|
518 | case LN_ENTER:
|
---|
519 | WinSendDlgItemMsg(hwnd, DID_OK, BM_CLICK, MPFROMSHORT(TRUE), MPVOID);
|
---|
520 | break;
|
---|
521 | }
|
---|
522 | break;
|
---|
523 | }
|
---|
524 | return 0;
|
---|
525 |
|
---|
526 | case WM_COMMAND:
|
---|
527 | switch (SHORT1FROMMP(mp1)) {
|
---|
528 | case MSK_ALL:
|
---|
529 | {
|
---|
530 | MASK *mask = (MASK *) INSTDATA(hwnd);
|
---|
531 |
|
---|
532 | if (mask) {
|
---|
533 | if (!mask->fNoAttribs) {
|
---|
534 | WinCheckButton(hwnd, MSK_SYSTEM, TRUE);
|
---|
535 | WinCheckButton(hwnd, MSK_HIDDEN, TRUE);
|
---|
536 | WinCheckButton(hwnd, MSK_READONLY, TRUE);
|
---|
537 | WinCheckButton(hwnd, MSK_ARCHIVED, TRUE);
|
---|
538 | WinCheckButton(hwnd, MSK_DIRECTORY, TRUE);
|
---|
539 | WinCheckButton(hwnd, MSK_MUSTSYSTEM, FALSE);
|
---|
540 | WinCheckButton(hwnd, MSK_MUSTHIDDEN, FALSE);
|
---|
541 | WinCheckButton(hwnd, MSK_MUSTREADONLY, FALSE);
|
---|
542 | WinCheckButton(hwnd, MSK_MUSTARCHIVED, FALSE);
|
---|
543 | WinCheckButton(hwnd, MSK_MUSTDIRECTORY, FALSE);
|
---|
544 | if (!mask->fNoDirs)
|
---|
545 | WinCheckButton(hwnd, MSK_SHOWDIRS, TRUE);
|
---|
546 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTSYSTEM), TRUE);
|
---|
547 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTHIDDEN), TRUE);
|
---|
548 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTARCHIVED), TRUE);
|
---|
549 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTREADONLY), TRUE);
|
---|
550 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTDIRECTORY), TRUE);
|
---|
551 | }
|
---|
552 | if (mask->fIsTree) {
|
---|
553 | WinCheckButton(hwnd, MSK_DIRECTORY, TRUE);
|
---|
554 | WinCheckButton(hwnd, MSK_MUSTDIRECTORY, FALSE);
|
---|
555 | WinCheckButton(hwnd, MSK_SHOWDIRS, FALSE);
|
---|
556 | WinEnableWindow(WinWindowFromID(hwnd, MSK_DIRECTORY), FALSE);
|
---|
557 | WinEnableWindow(WinWindowFromID(hwnd, MSK_SHOWDIRS), FALSE);
|
---|
558 | }
|
---|
559 | if (mask->fIsSeeAll) {
|
---|
560 | WinCheckButton(hwnd, MSK_DIRECTORY, FALSE);
|
---|
561 | WinCheckButton(hwnd, MSK_MUSTDIRECTORY, FALSE);
|
---|
562 | WinCheckButton(hwnd, MSK_SHOWDIRS, FALSE);
|
---|
563 | WinEnableWindow(WinWindowFromID(hwnd, MSK_DIRECTORY), FALSE);
|
---|
564 | WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTDIRECTORY), FALSE);
|
---|
565 | WinEnableWindow(WinWindowFromID(hwnd, MSK_SHOWDIRS), FALSE);
|
---|
566 | }
|
---|
567 | }
|
---|
568 | }
|
---|
569 | /* intentional fallthru */
|
---|
570 | case MSK_CLEAR:
|
---|
571 | WinSetDlgItemText(hwnd, MSK_MASK, NullStr);
|
---|
572 | break;
|
---|
573 |
|
---|
574 | case MSK_DELETE:
|
---|
575 | case DID_OK:
|
---|
576 | {
|
---|
577 | CHAR test[CCHMAXPATH];
|
---|
578 | MASK *mask;
|
---|
579 | SHORT sSelect;
|
---|
580 |
|
---|
581 | mask = INSTDATA(hwnd);
|
---|
582 | *test = 0;
|
---|
583 | WinQueryDlgItemText(hwnd, MSK_MASK, CCHMAXPATH, test);
|
---|
584 | test[CCHMAXPATH - 1] = 0;
|
---|
585 | bstrip(test);
|
---|
586 | if (SHORT1FROMMP(mp1) == DID_OK) {
|
---|
587 | mask->attrFile =
|
---|
588 | (WinQueryButtonCheckstate(hwnd, MSK_SYSTEM) *
|
---|
589 | FILE_SYSTEM) | (WinQueryButtonCheckstate(hwnd,
|
---|
590 | MSK_HIDDEN) *
|
---|
591 | FILE_HIDDEN) | (WinQueryButtonCheckstate(hwnd,
|
---|
592 | MSK_READONLY)
|
---|
593 | *
|
---|
594 | FILE_READONLY) |
|
---|
595 | (WinQueryButtonCheckstate(hwnd, MSK_ARCHIVED) *
|
---|
596 | FILE_ARCHIVED) | (WinQueryButtonCheckstate(hwnd,
|
---|
597 | MSK_DIRECTORY) *
|
---|
598 | FILE_DIRECTORY);
|
---|
599 | mask->antiattr =
|
---|
600 | (WinQueryButtonCheckstate(hwnd, MSK_MUSTSYSTEM) *
|
---|
601 | FILE_SYSTEM) | (WinQueryButtonCheckstate(hwnd,
|
---|
602 | MSK_MUSTHIDDEN) *
|
---|
603 | FILE_HIDDEN) | (WinQueryButtonCheckstate(hwnd,
|
---|
604 | MSK_MUSTREADONLY)
|
---|
605 | *
|
---|
606 | FILE_READONLY) |
|
---|
607 | (WinQueryButtonCheckstate(hwnd, MSK_MUSTARCHIVED) *
|
---|
608 | FILE_ARCHIVED) | (WinQueryButtonCheckstate(hwnd,
|
---|
609 | MSK_MUSTDIRECTORY) *
|
---|
610 | FILE_DIRECTORY);
|
---|
611 | mask->fShowDirs =
|
---|
612 | (WinQueryButtonCheckstate(hwnd, MSK_SHOWDIRS) != FALSE);
|
---|
613 | if (mask->fText)
|
---|
614 | WinQueryDlgItemText(hwnd, MSK_TEXT, 256, mask->szText);
|
---|
615 | }
|
---|
616 | if (*test) {
|
---|
617 | if (SHORT1FROMMP(mp1) == DID_OK) {
|
---|
618 | strcpy(mask->szMask, test);
|
---|
619 | add_mask(test);
|
---|
620 | save_masks();
|
---|
621 | DosEnterCritSec();
|
---|
622 | SetMask(mask->szMask, mask);
|
---|
623 | DosExitCritSec();
|
---|
624 | WinDismissDlg(hwnd, 1);
|
---|
625 | }
|
---|
626 | else {
|
---|
627 | WinSetDlgItemText(hwnd, MSK_MASK, NullStr);
|
---|
628 | remove_mask(test);
|
---|
629 | save_masks();
|
---|
630 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
631 | MSK_LISTBOX,
|
---|
632 | LM_SEARCHSTRING,
|
---|
633 | MPFROM2SHORT(0, LIT_FIRST),
|
---|
634 | MPFROMP(test));
|
---|
635 | if (sSelect >= 0)
|
---|
636 | WinSendDlgItemMsg(hwnd,
|
---|
637 | MSK_LISTBOX,
|
---|
638 | LM_DELETEITEM,
|
---|
639 | MPFROM2SHORT(sSelect, 0), MPVOID);
|
---|
640 | }
|
---|
641 | }
|
---|
642 | else {
|
---|
643 | if (SHORT1FROMMP(mp1) == DID_OK) {
|
---|
644 | *mask->szMask = 0;
|
---|
645 | DosEnterCritSec();
|
---|
646 | SetMask(mask->szMask, mask);
|
---|
647 | DosExitCritSec();
|
---|
648 | WinDismissDlg(hwnd, 1);
|
---|
649 | }
|
---|
650 | else
|
---|
651 | DosBeep(50, 100); // MSK_DELETE
|
---|
652 | }
|
---|
653 | }
|
---|
654 | break;
|
---|
655 |
|
---|
656 | case IDM_HELP:
|
---|
657 | if (hwndHelp)
|
---|
658 | WinSendMsg(hwndHelp,
|
---|
659 | HM_DISPLAY_HELP,
|
---|
660 | MPFROM2SHORT(HELP_FILTER, 0), MPFROMSHORT(HM_RESOURCEID));
|
---|
661 | break;
|
---|
662 |
|
---|
663 | case DID_CANCEL:
|
---|
664 | WinDismissDlg(hwnd, 0);
|
---|
665 | break;
|
---|
666 | }
|
---|
667 | return 0;
|
---|
668 | }
|
---|
669 |
|
---|
670 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
---|
671 | }
|
---|
672 |
|
---|
673 | #pragma alloc_text(FILTER,Filter)
|
---|
674 | #pragma alloc_text(MASKS,load_masks,save_masks,add_mask,remove_mask,PickMaskDlgProc)
|
---|