source: trunk/dll/assoc.c@ 920

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

Cleanup of NormalizeCmdLine moved to pathutil.c

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.8 KB
Line 
1
2/**************************************************************************************
3
4 $Id: assoc.c 920 2008-01-13 01:18:17Z 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 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
654 rstrip(temp.sig);
655 if (*temp.sig) {
656 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
657 temp.offset = atol(dummy);
658 }
659 bstrip(temp.mask);
660 bstrip(temp.cl);
661 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT))
662 temp.flags = 0;
663 else if (WinQueryButtonCheckstate(hwnd, ASS_FULLSCREEN))
664 temp.flags = FULLSCREEN;
665 else if (WinQueryButtonCheckstate(hwnd, ASS_MINIMIZED))
666 temp.flags = MINIMIZED;
667 else if (WinQueryButtonCheckstate(hwnd, ASS_MAXIMIZED))
668 temp.flags = MAXIMIZED;
669 else if (WinQueryButtonCheckstate(hwnd, ASS_INVISIBLE))
670 temp.flags = INVISIBLE;
671 if (WinQueryButtonCheckstate(hwnd, ASS_KEEP))
672 temp.flags |= KEEP;
673 if (WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
674 temp.flags |= DIEAFTER;
675 if (WinQueryButtonCheckstate(hwnd, ASS_PROMPT))
676 temp.flags |= PROMPT;
677 if (fCancelAction){
678 fCancelAction = FALSE;
679 break;
680 }
681 else
682 info = add_association(&temp);
683 if (!info)
684 WinDismissDlg(hwnd, 1); /* Runtime_Error(pszSrcFile, __LINE__, "add_association"); */
685 else {
686
687 CHAR s[1002 + CCHMAXPATH + 6];
688
689 *s = 0;
690 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s);
691 bstripcr(s);
692 if (*s)
693 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s);
694 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask,
695 temp.cl, (*temp.sig) ?
696 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr,
697 (*temp.sig) ? "]" : NullStr);
698 x = (SHORT) WinSendDlgItemMsg(hwnd,
699 ASS_LISTBOX,
700 LM_INSERTITEM,
701 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
702 if (x >= 0) {
703 WinSendDlgItemMsg(hwnd,
704 ASS_LISTBOX,
705 LM_SETITEMHANDLE,
706 MPFROMSHORT(x), MPFROMP(info));
707 WinSendDlgItemMsg(hwnd,
708 ASS_LISTBOX,
709 LM_SELECTITEM,
710 MPFROMSHORT(x), MPFROMSHORT(TRUE));
711 }
712 save_associations();
713 }
714 }
715 WinDismissDlg(hwnd, 1);
716 break;
717
718 case DID_CANCEL:
719 WinDismissDlg(hwnd, 0);
720 break;
721
722 case IDM_HELP:
723 if (hwndHelp)
724 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
725 MPFROM2SHORT(HELP_ASSOC, 0), MPFROMSHORT(HM_RESOURCEID));
726 break;
727
728 case ASS_ADD:
729 {
730 ASSOC temp;
731 CHAR dummy[34];
732 PSZ pszWorkBuf;
733 replace = FALSE;
734
735 pszWorkBuf = xmalloc(MAXCOMLINESTRG, pszSrcFile, __LINE__);
736 memset(&temp, 0, sizeof(ASSOC));
737 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
738 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl);
739 NormalizeCmdLine(pszWorkBuf, temp.cl);
740 memcpy(temp.cl, pszWorkBuf, strlen(pszWorkBuf) + 1);
741 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
742 rstrip(temp.sig);
743 if (*temp.sig) {
744 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
745 temp.offset = atol(dummy);
746 }
747 bstrip(temp.mask);
748 bstrip(temp.cl);
749 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT))
750 temp.flags = 0;
751 else if (WinQueryButtonCheckstate(hwnd, ASS_FULLSCREEN))
752 temp.flags = FULLSCREEN;
753 else if (WinQueryButtonCheckstate(hwnd, ASS_MINIMIZED))
754 temp.flags = MINIMIZED;
755 else if (WinQueryButtonCheckstate(hwnd, ASS_MAXIMIZED))
756 temp.flags = MAXIMIZED;
757 else if (WinQueryButtonCheckstate(hwnd, ASS_INVISIBLE))
758 temp.flags = INVISIBLE;
759 if (WinQueryButtonCheckstate(hwnd, ASS_KEEP))
760 temp.flags |= KEEP;
761 if (WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
762 temp.flags |= DIEAFTER;
763 if (WinQueryButtonCheckstate(hwnd, ASS_PROMPT))
764 temp.flags |= PROMPT;
765 if (fCancelAction){
766 fCancelAction = FALSE;
767 break;
768 }
769 else
770 info = add_association(&temp);
771 //Add will fail if mask is not changed
772 if (info) {
773
774 CHAR s[1002 + CCHMAXPATH + 6];
775
776 *s = 0;
777 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s);
778 bstripcr(s);
779 if (*s)
780 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s);
781 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask,
782 temp.cl, (*temp.sig) ?
783 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr,
784 (*temp.sig) ? "]" : NullStr);
785 x = (SHORT) WinSendDlgItemMsg(hwnd,
786 ASS_LISTBOX,
787 LM_INSERTITEM,
788 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
789 if (x >= 0) {
790 WinSendDlgItemMsg(hwnd,
791 ASS_LISTBOX,
792 LM_SETITEMHANDLE,
793 MPFROMSHORT(x), MPFROMP(info));
794 WinSendDlgItemMsg(hwnd,
795 ASS_LISTBOX,
796 LM_SELECTITEM,
797 MPFROMSHORT(x), MPFROMSHORT(TRUE));
798 }
799 save_associations();
800 }
801 }
802 break;
803
804 case ASS_DELETE:
805 {
806 ASSOC temp;
807 CHAR dummy[34];
808
809 memset(&temp, 0, sizeof(ASSOC));
810 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
811 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
812 rstrip(temp.sig);
813 if (*temp.sig) {
814 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
815 temp.offset = atol(dummy);
816 }
817 bstrip(temp.mask);
818 PrfWriteProfileData(fmprof, FM3Str, temp.mask, NULL, 0L);
819 if (kill_association(&temp))
820 /* Runtime_Error(pszSrcFile, __LINE__, "kill_association");
821 else */{
822 x = (SHORT) WinSendDlgItemMsg(hwnd,
823 ASS_LISTBOX,
824 LM_QUERYSELECTION,
825 MPFROMSHORT(LIT_FIRST), MPVOID);
826 if (x >= 0) {
827 WinSendDlgItemMsg(hwnd,
828 ASS_LISTBOX,
829 LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
830 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_SELECTITEM,
831 MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE));
832 }
833 save_associations();
834 }
835 }
836 break;
837 case ASS_REPLACE:
838
839 {
840 ASSOC temp;
841 CHAR dummy[34];
842 PSZ pszWorkBuf;
843 replace = TRUE;
844
845 y = (SHORT) WinSendDlgItemMsg(hwnd,
846 ASS_LISTBOX,
847 LM_QUERYSELECTION,
848 MPFROMSHORT(LIT_CURSOR), MPVOID);
849 pszWorkBuf = xmalloc(MAXCOMLINESTRG, pszSrcFile, __LINE__);
850 memset(&temp, 0, sizeof(ASSOC));
851 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
852 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl);
853 NormalizeCmdLine(pszWorkBuf, temp.cl);
854 memcpy(temp.cl, pszWorkBuf, strlen(pszWorkBuf) + 1);
855 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
856 rstrip(temp.sig);
857 if (*temp.sig) {
858 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
859 temp.offset = atol(dummy);
860 }
861 bstrip(temp.mask);
862 bstrip(temp.cl);
863 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT))
864 temp.flags = 0;
865 else if (WinQueryButtonCheckstate(hwnd, ASS_FULLSCREEN))
866 temp.flags = FULLSCREEN;
867 else if (WinQueryButtonCheckstate(hwnd, ASS_MINIMIZED))
868 temp.flags = MINIMIZED;
869 else if (WinQueryButtonCheckstate(hwnd, ASS_MAXIMIZED))
870 temp.flags = MAXIMIZED;
871 else if (WinQueryButtonCheckstate(hwnd, ASS_INVISIBLE))
872 temp.flags = INVISIBLE;
873 if (WinQueryButtonCheckstate(hwnd, ASS_KEEP))
874 temp.flags |= KEEP;
875 if (WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
876 temp.flags |= DIEAFTER;
877 if (WinQueryButtonCheckstate(hwnd, ASS_PROMPT))
878 temp.flags |= PROMPT;
879 if (fCancelAction){
880 fCancelAction = FALSE;
881 break;
882 }
883 else
884 info = add_association(&temp);
885 //Add will fail if mask is not changed
886 if (info) {
887
888 CHAR s[1002 + CCHMAXPATH + 6];
889
890 *s = 0;
891 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s);
892 bstripcr(s);
893 if (*s)
894 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s);
895 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask,
896 temp.cl, (*temp.sig) ?
897 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr,
898 (*temp.sig) ? "]" : NullStr);
899 x = (SHORT) WinSendDlgItemMsg(hwnd,
900 ASS_LISTBOX,
901 LM_INSERTITEM,
902 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
903 if (x >= 0) {
904 WinSendDlgItemMsg(hwnd,
905 ASS_LISTBOX,
906 LM_SETITEMHANDLE,
907 MPFROMSHORT(x), MPFROMP(info));
908 WinSendDlgItemMsg(hwnd,
909 ASS_LISTBOX,
910 LM_SELECTITEM,
911 MPFROMSHORT(x), MPFROMSHORT(TRUE));
912 }
913 save_associations();
914 }
915 }
916 {
917 ASSOC temp;
918 CHAR dummy[34];
919
920 WinSendDlgItemMsg(hwnd,
921 ASS_LISTBOX,
922 LM_SELECTITEM, MPFROMSHORT(y), MPFROMSHORT(TRUE));
923 memset(&temp, 0, sizeof(ASSOC));
924 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
925 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
926 rstrip(temp.sig);
927 if (*temp.sig) {
928 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
929 temp.offset = atol(dummy);
930 }
931 bstrip(temp.mask);
932 PrfWriteProfileData(fmprof, FM3Str, temp.mask, NULL, 0L);
933 if (!kill_association(&temp))
934 Runtime_Error(pszSrcFile, __LINE__, "kill_association");
935 else {
936
937 if (y >= 0) {
938 WinSendDlgItemMsg(hwnd,
939 ASS_LISTBOX,
940 LM_DELETEITEM, MPFROMSHORT(y), MPVOID);
941 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_SELECTITEM,
942 MPFROMSHORT(x - 1), MPFROMSHORT(TRUE));
943 }
944 save_associations();
945 }
946 }
947 break;
948 }
949 return 0;
950 }
951 return WinDefDlgProc(hwnd, msg, mp1, mp2);
952}
953
954VOID EditAssociations(HWND hwnd)
955{
956 static CHAR stop = 0;
957
958 if (stop)
959 return;
960 stop++;
961 if (!assloaded)
962 load_associations();
963 WinDlgBox(HWND_DESKTOP, hwnd, AssocDlgProc, FM3ModHandle, ASS_FRAME, NULL);
964 stop = 0;
965}
966
967#pragma alloc_text(ASSOC2,free_commands,load_associations,save_associations)
968#pragma alloc_text(ASSOC2,ExecAssociation,AssocTextProc)
969#pragma alloc_text(ASSOC,add_association,kill_association,AssocDlgProc,EditAssociations)
Note: See TracBrowser for help on using the repository browser.