source: trunk/dll/assoc.c@ 911

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

Commenting, help file, history update for recent changes; Minor clean up.

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