source: trunk/dll/assoc.c@ 888

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

runemf2 now quotes executable strings if needed (Ticket 180); it also reports where it was called from on errors

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