source: trunk/dll/assoc.c@ 927

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

Free pszWorkBuf memory for NormalizeCmdLine calls. Add comments for ticket 161 fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.9 KB
Line 
1
2/**************************************************************************************
3
4 $Id: assoc.c 927 2008-01-17 02:22:03Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2004, 2008 Steven H.Levine
8
9 01 Aug 04 SHL Rework lstrip/rstrip usage
10 14 Jul 06 SHL Use Runtime_Error
11 29 Jul 06 SHL Use xfgets, xfgets_bstripcr
12 10 Sep 06 GKY Add Move to last, Okay adds if new, Replace Current in Listbox Dialog
13 19 Oct 06 GKY Rework replace logic
14 18 Feb 07 GKY Move error messages etc to string file
15 19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
16 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
17 06 Jan 08 GKY Use NormalizeCmdLine to check program strings on entry
18
19**************************************************************************************/
20
21#include <stdlib.h>
22#include <string.h>
23#include <share.h>
24
25#define INCL_DOS
26#define INCL_WIN
27#define INCL_PM
28#define INCL_WINHOOKS
29#define INCL_LONGLONG // dircnrs.h
30
31#include "fm3dlg.h"
32#include "fm3str.h"
33#include "pathutil.h" // BldQuotedFileName
34#include "errutil.h" // Dos_Error...
35#include "strutil.h" // GetPString
36#include "fm3dll.h"
37
38#pragma data_seg(DATA1)
39
40typedef struct
41{
42 CHAR mask[CCHMAXPATH];
43 CHAR cl[MAXCOMLINESTRG];
44 CHAR sig[CCHMAXPATH];
45 LONG offset;
46 ULONG flags;
47}
48ASSOC;
49
50typedef struct LINKASSOC
51{
52 CHAR *mask;
53 CHAR *cl;
54 CHAR *sig;
55 LONG offset;
56 ULONG flags;
57 struct LINKASSOC *prev;
58 struct LINKASSOC *next;
59}
60LINKASSOC;
61
62static LINKASSOC *asshead = NULL, *asstail = NULL;
63static BOOL assloaded = FALSE, replace = FALSE;
64
65static PSZ pszSrcFile = __FILE__;
66
67MRESULT EXPENTRY AssocTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
68{
69 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
70 static BOOL emphasized = FALSE;
71
72 switch (msg) {
73 case DM_DRAGOVER:
74 if (!emphasized) {
75 emphasized = TRUE;
76 DrawTargetEmphasis(hwnd, emphasized);
77 }
78 if (AcceptOneDrop(hwnd, mp1, mp2))
79 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
80 return MRFROM2SHORT(DOR_NEVERDROP, 0);
81
82 case DM_DRAGLEAVE:
83 if (emphasized) {
84 emphasized = FALSE;
85 DrawTargetEmphasis(hwnd, emphasized);
86 }
87 break;
88
89 case DM_DROPHELP:
90 DropHelp(mp1, mp2, hwnd, GetPString(IDS_ASSOCDROPHELPTEXT));
91 return 0;
92
93 case DM_DROP:
94 {
95 char szFrom[CCHMAXPATH + 5];
96
97 if (emphasized) {
98 emphasized = FALSE;
99 DrawTargetEmphasis(hwnd, emphasized);
100 }
101 if (GetOneDrop(hwnd, mp1, mp2, szFrom, CCHMAXPATH)) {
102 strcat(szFrom, " %a");
103 WinSetWindowText(hwnd, szFrom);
104 }
105 }
106 return 0;
107 }
108 return (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
109 WinDefWindowProc(hwnd, msg, mp1, mp2);
110}
111
112VOID free_associations(VOID)
113{
114 LINKASSOC *info, *next;
115
116 info = asshead;
117 while (info) {
118 next = info->next;
119 free(info->mask);
120 free(info->cl);
121 if (info->sig)
122 free(info->sig);
123 free(info);
124 info = next;
125 }
126 asshead = asstail = NULL;
127}
128
129VOID load_associations(VOID)
130{
131 FILE *fp;
132 LINKASSOC *info;
133 CHAR cl[1024];
134 CHAR mask[CCHMAXPATH + 24];
135 CHAR sig[CCHMAXPATH + 24];
136 CHAR offset[72];
137 CHAR flags[72];
138
139 if (asshead)
140 free_associations();
141 assloaded = TRUE;
142 save_dir2(mask);
143 if (mask[strlen(mask) - 1] != '\\')
144 strcat(mask, "\\");
145 strcat(mask, "ASSOC.DAT");
146 fp = _fsopen(mask, "r", SH_DENYWR);
147 if (fp) {
148 while (!feof(fp)) {
149 if (!xfgets(mask, sizeof(mask), fp, pszSrcFile, __LINE__)) // fixme why +24?
150 break;
151 mask[CCHMAXPATH] = 0;
152 bstripcr(mask);
153 if (!*mask || *mask == ';')
154 continue;
155 if (!xfgets(cl, sizeof(cl), fp, pszSrcFile, __LINE__) ||
156 !xfgets(sig, CCHMAXPATH + 24, fp, pszSrcFile, __LINE__) ||
157 !xfgets(offset, sizeof(offset), fp, pszSrcFile, __LINE__) ||
158 !xfgets(flags, sizeof(flags), fp, pszSrcFile, __LINE__))
159 break; /* error! */
160 cl[1000] = 0;
161 bstripcr(cl);
162 sig[CCHMAXPATH] = 0;
163 bstripcr(sig);
164 offset[34] = 0;
165 bstripcr(offset);
166 flags[34] = 0;
167 bstripcr(flags);
168 if (!*cl)
169 continue;
170 info = xmallocz(sizeof(LINKASSOC), pszSrcFile, __LINE__);
171 if (info) {
172 info->cl = xstrdup(cl, pszSrcFile, __LINE__);
173 info->mask = xstrdup(mask, pszSrcFile, __LINE__);
174 if (*sig)
175 info->sig = xstrdup(sig, pszSrcFile, __LINE__);
176 info->offset = atol(offset);
177 info->flags = atol(flags);
178 if (!info->cl || !info->mask) {
179 if (info->cl)
180 free(info->cl);
181 if (info->mask)
182 free(info->mask);
183 free(info);
184 break;
185 }
186 if (!asshead)
187 asshead = info;
188 else {
189 asstail->next = info;
190 info->prev = asstail;
191 }
192 asstail = info;
193 }
194 }
195 fclose(fp);
196 }
197}
198
199VOID save_associations(VOID)
200{
201 LINKASSOC *info;
202 FILE *fp;
203 CHAR s[CCHMAXPATH + 14];
204
205 if (!assloaded || !asshead)
206 return;
207 info = asshead;
208#ifdef NEVER
209 while (info) {
210 next = info->next;
211 if (!strcmp("*", info->mask)) {
212 if (info != asshead) { /* already top record */
213 if (info->prev)
214 (info->prev)->next = info->next;
215 if (info->next)
216 (info->next)->prev = info->prev;
217 if (info == asstail)
218 asstail = info->prev;
219 info->next = asshead->next;
220 info->prev = NULL;
221 asshead = info;
222 }
223 }
224 info = next;
225 }
226#endif
227 save_dir2(s);
228 if (s[strlen(s) - 1] != '\\')
229 strcat(s, "\\");
230 strcat(s, "ASSOC.DAT");
231 fp = xfopen(s, "w", pszSrcFile, __LINE__);
232 if (fp) {
233 fputs(GetPString(IDS_ASSOCFILETEXT), fp);
234 info = asshead;
235 while (info) {
236 fprintf(fp,
237 ";\n%0.*s\n%0.1000s\n%0.*s\n%lu\n%lu\n",
238 CCHMAXPATH,
239 info->mask,
240 info->cl,
241 CCHMAXPATH,
242 (info->sig) ? info->sig : NullStr, info->offset, info->flags);
243 info = info->next;
244 }
245 fclose(fp);
246 }
247}
248
249LINKASSOC *add_association(ASSOC * addme)
250{
251 LINKASSOC *info;
252
253 if (addme && *addme->cl && *addme->mask) {
254 info = asshead;
255 while (info) {
256 if ((!replace) && (!stricmp(info->mask, addme->mask) &&
257 ((!info->sig && !*addme->sig) || (!replace) &&
258 (info->sig && !strcmp(addme->sig, info->sig)))))
259 return NULL;
260 info = info->next;
261 }
262 if (!info) {
263 info = xmallocz(sizeof(LINKASSOC), pszSrcFile, __LINE__);
264 if (info) {
265 info->cl = xstrdup(addme->cl, pszSrcFile, __LINE__);
266 info->mask = xstrdup(addme->mask, pszSrcFile, __LINE__);
267 if (*addme->sig)
268 info->sig = xstrdup(addme->sig, pszSrcFile, __LINE__);
269 if (addme->offset)
270 info->offset = addme->offset;
271 if (addme->flags)
272 info->flags = addme->flags;
273 if (!info->cl || !info->mask) {
274 if (info->cl)
275 free(info->cl);
276 if (info->mask)
277 free(info->mask);
278 free(info);
279 }
280 else {
281 if (!asshead) /* only item in list */
282 asshead = asstail = info;
283 else {
284 if (asstail) { /* place at tail */
285 asstail->next = info;
286 info->prev = asstail;
287 }
288 asstail = info;
289 }
290 return info;
291 }
292 }
293 }
294 }
295 return NULL;
296}
297
298BOOL kill_association(ASSOC * killme)
299{
300 LINKASSOC *info;
301
302 if (killme && *killme->mask) {
303 info = asshead;
304 while (info) {
305 if (!stricmp(info->mask, killme->mask) &&
306 info->offset == killme->offset &&
307 (((!info->sig || !*info->sig) && !*killme->sig) ||
308 (info->sig && !strcmp(killme->sig, info->sig)))) {
309 if (info == asshead) {
310 asshead = info->next;
311 if (info == asstail)
312 asstail = info->prev;
313 }
314 else {
315 if (info->next)
316 (info->next)->prev = info->prev;
317 if (info->prev)
318 (info->prev)->next = info->next;
319 if (info == asstail)
320 asstail = info->prev;
321 }
322 free(info->cl);
323 free(info->mask);
324 if (info->sig)
325 free(info->sig);
326 free(info);
327 return TRUE;
328 }
329 info = info->next;
330 }
331 }
332 return FALSE;
333}
334
335INT ExecAssociation(HWND hwnd, CHAR * datafile)
336{
337 CHAR *file, sig[CCHMAXPATH], sigl[CCHMAXPATH], mask[CCHMAXPATH], *p;
338 FILE *fp;
339 BOOL didmatch, exclude;
340 ULONG offset;
341 LINKASSOC *info;
342
343 if (!assloaded)
344 load_associations();
345 if (!asshead)
346 return -1;
347 if (!datafile || !*datafile)
348 return -1;
349 file = strrchr(datafile, '\\');
350 if (!file)
351 file = strrchr(datafile, ':');
352 if (file)
353 file++;
354 else
355 file = datafile;
356 info = asshead;
357 while (info) {
358 strcpy(mask, info->mask);
359 p = strtok(mask, ";");
360 while (p) {
361 if (*p == '/') {
362 p++;
363 exclude = TRUE;
364 }
365 else
366 exclude = FALSE;
367 didmatch = wildcard((strchr(p, '\\') ||
368 strchr(p, ':')) ? datafile : file, p, FALSE);
369 if (exclude && didmatch)
370 didmatch = FALSE;
371 if (didmatch) {
372 if (info->sig && *info->sig) {
373 strcpy(sigl, info->sig);
374 literal(sigl);
375 fp = _fsopen(datafile, "rb", SH_DENYNO);
376 if (fp) {
377 if (info->offset < 0L) {
378 fseek(fp, 0L, SEEK_END);
379 offset = ftell(fp) + info->offset;
380 }
381 else
382 offset = info->offset;
383 fseek(fp, offset, SEEK_SET);
384 if (fread(sig,
385 1,
386 strlen(sigl),
387 fp) != strlen(sigl) || strncmp(sigl, sig, strlen(sigl)))
388 didmatch = FALSE;
389 fclose(fp);
390 }
391 }
392 }
393 if (didmatch) { /* got a match; do it... */
394
395 CHAR *list[2];
396 INT flags, rc;
397 BOOL dieafter = FALSE;
398
399 if (fAmAV2) {
400 if (stristr(info->cl, "AV2.EXE") ||
401 stristr(info->cl, "AV2.CMD") || stristr(info->cl, "<>"))
402 return -1;
403 }
404 if (!strcmp(info->cl, "<>")) {
405 OpenObject(datafile, Default, hwnd);
406 return 0;
407 }
408 list[0] = datafile;
409 list[1] = NULL;
410 flags = info->flags;
411 if (!(flags & FULLSCREEN))
412 flags |= WINDOWED;
413 if (flags & KEEP)
414 flags |= SEPARATEKEEP;
415 else
416 flags |= SEPARATE;
417 flags &= (~KEEP);
418 if (flags & DIEAFTER)
419 dieafter = TRUE;
420 flags &= (~DIEAFTER);
421 rc = ExecOnList(hwnd,
422 info->cl,
423 flags,
424 NULL, list, GetPString(IDS_EXECASSOCTITLETEXT),
425 pszSrcFile, __LINE__);
426 if (rc != -1 && dieafter)
427 PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
428 return rc;
429 }
430 p = strtok(0, ";");
431 }
432 info = info->next;
433 }
434 return -1;
435}
436
437MRESULT EXPENTRY AssocDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
438{
439 LINKASSOC *info;
440 SHORT x, y;
441
442 switch (msg) {
443 case WM_INITDLG:
444 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
445 WinSendDlgItemMsg(hwnd, ASS_MASK, EM_SETTEXTLIMIT,
446 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
447 WinSendDlgItemMsg(hwnd, ASS_CL, EM_SETTEXTLIMIT,
448 MPFROM2SHORT(1000, 0), MPVOID);
449 WinSendDlgItemMsg(hwnd, ASS_SIG, EM_SETTEXTLIMIT,
450 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
451 WinSendDlgItemMsg(hwnd, ASS_OFFSET, EM_SETTEXTLIMIT,
452 MPFROM2SHORT(34, 0), MPVOID);
453 WinSetDlgItemText(hwnd, ASS_MASK, NullStr);
454 WinSetDlgItemText(hwnd, ASS_CL, NullStr);
455 WinSetDlgItemText(hwnd, ASS_SIG, NullStr);
456 WinSetDlgItemText(hwnd, ASS_OFFSET, "0");
457 WinCheckButton(hwnd, ASS_DEFAULT, TRUE);
458 WinCheckButton(hwnd, ASS_PROMPT, FALSE);
459 WinCheckButton(hwnd, ASS_KEEP, FALSE);
460 WinCheckButton(hwnd, ASS_DIEAFTER, FALSE);
461 PostMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
462 {
463 PFNWP oldproc;
464
465 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, ASS_CL),
466 (PFNWP) AssocTextProc);
467 if (oldproc)
468 WinSetWindowPtr(WinWindowFromID(hwnd, ASS_CL), QWL_USER,
469 (PVOID) oldproc);
470 }
471 break;
472
473 case UM_UNDO:
474 {
475 CHAR s[1002 + CCHMAXPATH + 6];
476
477 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
478 info = asshead;
479 while (info) {
480 sprintf(s,
481 "%-12s \x1a %-24s %s%s%s",
482 info->mask,
483 info->cl,
484 (info->sig && *info->sig) ?
485 "[" : NullStr,
486 (info->sig && *info->sig) ? info->sig : NullStr,
487 (info->sig && *info->sig) ? "]" : NullStr);
488 x = (SHORT) WinSendDlgItemMsg(hwnd,
489 ASS_LISTBOX,
490 LM_INSERTITEM,
491 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
492 if (x >= 0)
493 WinSendDlgItemMsg(hwnd,
494 ASS_LISTBOX,
495 LM_SETITEMHANDLE, MPFROMSHORT(x), MPFROMP(info));
496 info = info->next;
497 }
498 WinSendDlgItemMsg(hwnd,
499 ASS_LISTBOX,
500 LM_SELECTITEM, MPFROMSHORT(0), MPFROMSHORT(TRUE));
501 }
502 return 0;
503
504 case WM_CONTROL:
505 if (SHORT1FROMMP(mp1) == ASS_LISTBOX) {
506 switch (SHORT2FROMMP(mp1)) {
507 case LN_ENTER:
508 case LN_SELECT:
509 x = (SHORT) WinSendDlgItemMsg(hwnd,
510 ASS_LISTBOX,
511 LM_QUERYSELECTION,
512 MPFROMSHORT(LIT_FIRST), MPVOID);
513 if (x >= 0) {
514
515 CHAR s[36];
516
517 info = (LINKASSOC *) WinSendDlgItemMsg(hwnd,
518 ASS_LISTBOX,
519 LM_QUERYITEMHANDLE,
520 MPFROMSHORT(x), MPVOID);
521 if (!info) {
522 Runtime_Error(pszSrcFile, __LINE__, "Query item handle failed");
523 break;
524 }
525 WinSetDlgItemText(hwnd, ASS_MASK, info->mask);
526 WinSetDlgItemText(hwnd, ASS_CL, info->cl);
527 WinSetDlgItemText(hwnd, ASS_SIG,
528 (info->sig && *info->sig) ? info->sig : NullStr);
529 sprintf(s, "%ld", info->offset);
530 WinSetDlgItemText(hwnd, ASS_OFFSET, s);
531 if (!(info->flags & 1023))
532 WinCheckButton(hwnd, ASS_DEFAULT, TRUE);
533 else {
534 if (info->flags & FULLSCREEN)
535 WinCheckButton(hwnd, ASS_FULLSCREEN, TRUE);
536 else if (info->flags & MINIMIZED)
537 WinCheckButton(hwnd, ASS_MINIMIZED, TRUE);
538 else if (info->flags & MAXIMIZED)
539 WinCheckButton(hwnd, ASS_MAXIMIZED, TRUE);
540 else if (info->flags & INVISIBLE)
541 WinCheckButton(hwnd, ASS_INVISIBLE, TRUE);
542 }
543 WinCheckButton(hwnd, ASS_KEEP, ((info->flags & KEEP) != 0));
544 WinCheckButton(hwnd, ASS_DIEAFTER, ((info->flags & DIEAFTER) != 0));
545 WinCheckButton(hwnd, ASS_PROMPT, ((info->flags & PROMPT) != 0));
546 {
547 CHAR env[1002];
548 ULONG size;
549
550 *env = 0;
551 size = sizeof(env) - 1;
552 if (PrfQueryProfileData(fmprof,
553 FM3Str, info->cl, env, &size) && *env)
554 WinSetDlgItemText(hwnd, ASS_ENVIRON, env);
555 else
556 WinSetDlgItemText(hwnd, ASS_ENVIRON, NullStr);
557 }
558 }
559 break;
560 }
561 }
562 return 0;
563
564 case WM_COMMAND:
565 switch (SHORT1FROMMP(mp1)) {
566 case ASS_TOP:
567 x = (SHORT) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
568 LM_QUERYSELECTION,
569 MPFROMSHORT(LIT_FIRST), MPVOID);
570 if (x >= 0) {
571 info = (LINKASSOC *) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
572 LM_QUERYITEMHANDLE,
573 MPFROMSHORT(x), MPVOID);
574 if (info) {
575 if (info != asshead) {
576 if (info->prev)
577 info->prev->next = info->next;
578 if (info->next)
579 info->next->prev = info->prev;
580 if (info == asstail)
581 asstail = info->prev;
582 info->prev = NULL;
583 info->next = asshead;
584 asshead->prev = info;
585 asshead = info;
586 WinSendMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
587 }
588 }
589 }
590 break;
591
592 case ASS_BOTTOM:
593 x = (SHORT) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
594 LM_QUERYSELECTION,
595 MPFROMSHORT(LIT_FIRST), MPVOID);
596 if (x >= 0) {
597 info = (LINKASSOC *) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
598 LM_QUERYITEMHANDLE,
599 MPFROMSHORT(x), MPVOID);
600 if (info) {
601 if (info != asstail) {
602 if (info->next)
603 info->next->prev = info->prev;
604 if (info->prev)
605 info->prev->next = info->next;
606 if (info == asshead)
607 asshead = info->next;
608 info->next = NULL;
609 info->prev = asstail;
610 asstail->next = info;
611 asstail = info;
612 WinSendMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
613 }
614 }
615 }
616 break;
617 case ASS_FIND:
618 {
619 CHAR filename[CCHMAXPATH + 9], szfilename[CCHMAXPATH + 9];
620
621 *filename = 0;
622 if (insert_filename(hwnd, filename, 2, FALSE) && *filename) {
623 BldQuotedFileName(szfilename, filename);
624 strcat(szfilename, " %a");
625 WinSetDlgItemText(hwnd, ASS_CL, szfilename);
626 }
627 }
628 break;
629
630 case DID_OK:
631 {
632 ASSOC temp;
633 CHAR dummy[34];
634 PSZ pszWorkBuf;
635 replace = FALSE;
636
637 {
638 x = (SHORT) WinSendDlgItemMsg(hwnd,
639 ASS_LISTBOX,
640 LM_QUERYSELECTION, MPVOID, MPVOID);
641 if (x == LIT_NONE)
642 x = (SHORT) WinSendDlgItemMsg(hwnd,
643 ASS_LISTBOX,
644 LM_SELECTITEM,
645 MPFROMSHORT(0), MPFROMSHORT(TRUE));
646 }
647 pszWorkBuf = xmalloc(MAXCOMLINESTRG, pszSrcFile, __LINE__);
648 memset(&temp, 0, sizeof(ASSOC));
649 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
650 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl);
651 NormalizeCmdLine(pszWorkBuf, temp.cl);
652 memcpy(temp.cl, pszWorkBuf, strlen(pszWorkBuf) + 1);
653 xfree(pszWorkBuf);
654 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
655 rstrip(temp.sig);
656 if (*temp.sig) {
657 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
658 temp.offset = atol(dummy);
659 }
660 bstrip(temp.mask);
661 bstrip(temp.cl);
662 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT))
663 temp.flags = 0;
664 else if (WinQueryButtonCheckstate(hwnd, ASS_FULLSCREEN))
665 temp.flags = FULLSCREEN;
666 else if (WinQueryButtonCheckstate(hwnd, ASS_MINIMIZED))
667 temp.flags = MINIMIZED;
668 else if (WinQueryButtonCheckstate(hwnd, ASS_MAXIMIZED))
669 temp.flags = MAXIMIZED;
670 else if (WinQueryButtonCheckstate(hwnd, ASS_INVISIBLE))
671 temp.flags = INVISIBLE;
672 if (WinQueryButtonCheckstate(hwnd, ASS_KEEP))
673 temp.flags |= KEEP;
674 if (WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
675 temp.flags |= DIEAFTER;
676 if (WinQueryButtonCheckstate(hwnd, ASS_PROMPT))
677 temp.flags |= PROMPT;
678 if (fCancelAction){
679 fCancelAction = FALSE;
680 break;
681 }
682 else
683 info = add_association(&temp);
684 if (!info)
685 WinDismissDlg(hwnd, 1); /* Runtime_Error(pszSrcFile, __LINE__, "add_association"); */
686 else {
687
688 CHAR s[1002 + CCHMAXPATH + 6];
689
690 *s = 0;
691 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s);
692 bstripcr(s);
693 if (*s)
694 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s);
695 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask,
696 temp.cl, (*temp.sig) ?
697 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr,
698 (*temp.sig) ? "]" : NullStr);
699 x = (SHORT) WinSendDlgItemMsg(hwnd,
700 ASS_LISTBOX,
701 LM_INSERTITEM,
702 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
703 if (x >= 0) {
704 WinSendDlgItemMsg(hwnd,
705 ASS_LISTBOX,
706 LM_SETITEMHANDLE,
707 MPFROMSHORT(x), MPFROMP(info));
708 WinSendDlgItemMsg(hwnd,
709 ASS_LISTBOX,
710 LM_SELECTITEM,
711 MPFROMSHORT(x), MPFROMSHORT(TRUE));
712 }
713 save_associations();
714 }
715 }
716 WinDismissDlg(hwnd, 1);
717 break;
718
719 case DID_CANCEL:
720 WinDismissDlg(hwnd, 0);
721 break;
722
723 case IDM_HELP:
724 if (hwndHelp)
725 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
726 MPFROM2SHORT(HELP_ASSOC, 0), MPFROMSHORT(HM_RESOURCEID));
727 break;
728
729 case ASS_ADD:
730 {
731 ASSOC temp;
732 CHAR dummy[34];
733 PSZ pszWorkBuf;
734 replace = FALSE;
735
736 pszWorkBuf = xmalloc(MAXCOMLINESTRG, pszSrcFile, __LINE__);
737 memset(&temp, 0, sizeof(ASSOC));
738 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
739 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl);
740 NormalizeCmdLine(pszWorkBuf, temp.cl);
741 memcpy(temp.cl, pszWorkBuf, strlen(pszWorkBuf) + 1);
742 xfree(pszWorkBuf);
743 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
744 rstrip(temp.sig);
745 if (*temp.sig) {
746 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
747 temp.offset = atol(dummy);
748 }
749 bstrip(temp.mask);
750 bstrip(temp.cl);
751 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT))
752 temp.flags = 0;
753 else if (WinQueryButtonCheckstate(hwnd, ASS_FULLSCREEN))
754 temp.flags = FULLSCREEN;
755 else if (WinQueryButtonCheckstate(hwnd, ASS_MINIMIZED))
756 temp.flags = MINIMIZED;
757 else if (WinQueryButtonCheckstate(hwnd, ASS_MAXIMIZED))
758 temp.flags = MAXIMIZED;
759 else if (WinQueryButtonCheckstate(hwnd, ASS_INVISIBLE))
760 temp.flags = INVISIBLE;
761 if (WinQueryButtonCheckstate(hwnd, ASS_KEEP))
762 temp.flags |= KEEP;
763 if (WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
764 temp.flags |= DIEAFTER;
765 if (WinQueryButtonCheckstate(hwnd, ASS_PROMPT))
766 temp.flags |= PROMPT;
767 if (fCancelAction){
768 fCancelAction = FALSE;
769 break;
770 }
771 else
772 info = add_association(&temp);
773 //Add will fail if mask is not changed
774 if (info) {
775
776 CHAR s[1002 + CCHMAXPATH + 6];
777
778 *s = 0;
779 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s);
780 bstripcr(s);
781 if (*s)
782 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s);
783 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask,
784 temp.cl, (*temp.sig) ?
785 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr,
786 (*temp.sig) ? "]" : NullStr);
787 x = (SHORT) WinSendDlgItemMsg(hwnd,
788 ASS_LISTBOX,
789 LM_INSERTITEM,
790 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
791 if (x >= 0) {
792 WinSendDlgItemMsg(hwnd,
793 ASS_LISTBOX,
794 LM_SETITEMHANDLE,
795 MPFROMSHORT(x), MPFROMP(info));
796 WinSendDlgItemMsg(hwnd,
797 ASS_LISTBOX,
798 LM_SELECTITEM,
799 MPFROMSHORT(x), MPFROMSHORT(TRUE));
800 }
801 save_associations();
802 }
803 }
804 break;
805
806 case ASS_DELETE:
807 {
808 ASSOC temp;
809 CHAR dummy[34];
810
811 memset(&temp, 0, sizeof(ASSOC));
812 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
813 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
814 rstrip(temp.sig);
815 if (*temp.sig) {
816 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
817 temp.offset = atol(dummy);
818 }
819 bstrip(temp.mask);
820 PrfWriteProfileData(fmprof, FM3Str, temp.mask, NULL, 0L);
821 if (kill_association(&temp))
822 /* Runtime_Error(pszSrcFile, __LINE__, "kill_association");
823 else */{
824 x = (SHORT) WinSendDlgItemMsg(hwnd,
825 ASS_LISTBOX,
826 LM_QUERYSELECTION,
827 MPFROMSHORT(LIT_FIRST), MPVOID);
828 if (x >= 0) {
829 WinSendDlgItemMsg(hwnd,
830 ASS_LISTBOX,
831 LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
832 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_SELECTITEM,
833 MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE));
834 }
835 save_associations();
836 }
837 }
838 break;
839 case ASS_REPLACE:
840
841 {
842 ASSOC temp;
843 CHAR dummy[34];
844 PSZ pszWorkBuf;
845 replace = TRUE;
846
847 y = (SHORT) WinSendDlgItemMsg(hwnd,
848 ASS_LISTBOX,
849 LM_QUERYSELECTION,
850 MPFROMSHORT(LIT_CURSOR), MPVOID);
851 pszWorkBuf = xmalloc(MAXCOMLINESTRG, pszSrcFile, __LINE__);
852 memset(&temp, 0, sizeof(ASSOC));
853 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
854 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl);
855 NormalizeCmdLine(pszWorkBuf, temp.cl);
856 memcpy(temp.cl, pszWorkBuf, strlen(pszWorkBuf) + 1);
857 xfree(pszWorkBuf);
858 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
859 rstrip(temp.sig);
860 if (*temp.sig) {
861 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
862 temp.offset = atol(dummy);
863 }
864 bstrip(temp.mask);
865 bstrip(temp.cl);
866 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT))
867 temp.flags = 0;
868 else if (WinQueryButtonCheckstate(hwnd, ASS_FULLSCREEN))
869 temp.flags = FULLSCREEN;
870 else if (WinQueryButtonCheckstate(hwnd, ASS_MINIMIZED))
871 temp.flags = MINIMIZED;
872 else if (WinQueryButtonCheckstate(hwnd, ASS_MAXIMIZED))
873 temp.flags = MAXIMIZED;
874 else if (WinQueryButtonCheckstate(hwnd, ASS_INVISIBLE))
875 temp.flags = INVISIBLE;
876 if (WinQueryButtonCheckstate(hwnd, ASS_KEEP))
877 temp.flags |= KEEP;
878 if (WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
879 temp.flags |= DIEAFTER;
880 if (WinQueryButtonCheckstate(hwnd, ASS_PROMPT))
881 temp.flags |= PROMPT;
882 if (fCancelAction){
883 fCancelAction = FALSE;
884 break;
885 }
886 else
887 info = add_association(&temp);
888 //Add will fail if mask is not changed
889 if (info) {
890
891 CHAR s[1002 + CCHMAXPATH + 6];
892
893 *s = 0;
894 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s);
895 bstripcr(s);
896 if (*s)
897 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s);
898 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask,
899 temp.cl, (*temp.sig) ?
900 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr,
901 (*temp.sig) ? "]" : NullStr);
902 x = (SHORT) WinSendDlgItemMsg(hwnd,
903 ASS_LISTBOX,
904 LM_INSERTITEM,
905 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
906 if (x >= 0) {
907 WinSendDlgItemMsg(hwnd,
908 ASS_LISTBOX,
909 LM_SETITEMHANDLE,
910 MPFROMSHORT(x), MPFROMP(info));
911 WinSendDlgItemMsg(hwnd,
912 ASS_LISTBOX,
913 LM_SELECTITEM,
914 MPFROMSHORT(x), MPFROMSHORT(TRUE));
915 }
916 save_associations();
917 }
918 }
919 {
920 ASSOC temp;
921 CHAR dummy[34];
922
923 WinSendDlgItemMsg(hwnd,
924 ASS_LISTBOX,
925 LM_SELECTITEM, MPFROMSHORT(y), MPFROMSHORT(TRUE));
926 memset(&temp, 0, sizeof(ASSOC));
927 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
928 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
929 rstrip(temp.sig);
930 if (*temp.sig) {
931 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
932 temp.offset = atol(dummy);
933 }
934 bstrip(temp.mask);
935 PrfWriteProfileData(fmprof, FM3Str, temp.mask, NULL, 0L);
936 if (!kill_association(&temp))
937 Runtime_Error(pszSrcFile, __LINE__, "kill_association");
938 else {
939
940 if (y >= 0) {
941 WinSendDlgItemMsg(hwnd,
942 ASS_LISTBOX,
943 LM_DELETEITEM, MPFROMSHORT(y), MPVOID);
944 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_SELECTITEM,
945 MPFROMSHORT(x - 1), MPFROMSHORT(TRUE));
946 }
947 save_associations();
948 }
949 }
950 break;
951 }
952 return 0;
953 }
954 return WinDefDlgProc(hwnd, msg, mp1, mp2);
955}
956
957VOID EditAssociations(HWND hwnd)
958{
959 static CHAR stop = 0;
960
961 if (stop)
962 return;
963 stop++;
964 if (!assloaded)
965 load_associations();
966 WinDlgBox(HWND_DESKTOP, hwnd, AssocDlgProc, FM3ModHandle, ASS_FRAME, NULL);
967 stop = 0;
968}
969
970#pragma alloc_text(ASSOC2,free_commands,load_associations,save_associations)
971#pragma alloc_text(ASSOC2,ExecAssociation,AssocTextProc)
972#pragma alloc_text(ASSOC,add_association,kill_association,AssocDlgProc,EditAssociations)
Note: See TracBrowser for help on using the repository browser.