source: trunk/dll/assoc.c@ 909

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

Added quoting code to commands, associations and avv; Minor clean up and fixed one problem with quoting logic; Added warning re %a for commands to work on selected files.

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