source: trunk/dll/assoc.c@ 689

Last change on this file since 689 was 618, checked in by Steven Levine, 18 years ago

Add more drag/drop error checking
Use FreeDragInfoData
Sync with NumItemsToUnhilite AcceptOneDrop GetOneDrop mods

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.3 KB
Line 
1
2/**************************************************************************************
3
4 $Id: assoc.c 618 2007-04-20 19:19:03Z stevenhl $
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
17**************************************************************************************/
18
19#define INCL_DOS
20#define INCL_WIN
21#define INCL_PM
22#define INCL_WINHOOKS
23
24#include <os2.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <ctype.h>
29#include <share.h>
30#include "fm3dll.h"
31#include "fm3dlg.h"
32#include "fm3str.h"
33
34#pragma data_seg(DATA1)
35
36typedef struct
37{
38 CHAR mask[CCHMAXPATH];
39 CHAR cl[1001];
40 CHAR sig[CCHMAXPATH];
41 LONG offset;
42 ULONG flags;
43}
44ASSOC;
45
46typedef struct LINKASSOC
47{
48 CHAR *mask;
49 CHAR *cl;
50 CHAR *sig;
51 LONG offset;
52 ULONG flags;
53 struct LINKASSOC *prev;
54 struct LINKASSOC *next;
55}
56LINKASSOC;
57
58static LINKASSOC *asshead = NULL, *asstail = NULL;
59static BOOL assloaded = FALSE, replace = FALSE;
60
61static PSZ pszSrcFile = __FILE__;
62
63#pragma alloc_text(ASSOC2,free_commands,load_associations,save_associations)
64#pragma alloc_text(ASSOC2,ExecAssociation,AssocTextProc)
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
248#pragma alloc_text(ASSOC,add_association,kill_association,AssocDlgProc,EditAssociations)
249
250LINKASSOC *add_association(ASSOC * addme)
251{
252 LINKASSOC *info;
253
254 if (addme && *addme->cl && *addme->mask) {
255 info = asshead;
256 while (info) {
257 if ((!replace) && (!stricmp(info->mask, addme->mask) &&
258 ((!info->sig && !*addme->sig) || (!replace) &&
259 (info->sig && !strcmp(addme->sig, info->sig)))))
260 return NULL;
261 info = info->next;
262 }
263 if (!info) {
264 info = xmallocz(sizeof(LINKASSOC), pszSrcFile, __LINE__);
265 if (info) {
266 info->cl = xstrdup(addme->cl, pszSrcFile, __LINE__);
267 info->mask = xstrdup(addme->mask, pszSrcFile, __LINE__);
268 if (*addme->sig)
269 info->sig = xstrdup(addme->sig, pszSrcFile, __LINE__);
270 if (addme->offset)
271 info->offset = addme->offset;
272 if (addme->flags)
273 info->flags = addme->flags;
274 if (!info->cl || !info->mask) {
275 if (info->cl)
276 free(info->cl);
277 if (info->mask)
278 free(info->mask);
279 free(info);
280 }
281 else {
282 if (!asshead) /* only item in list */
283 asshead = asstail = info;
284 else {
285 if (asstail) { /* place at tail */
286 asstail->next = info;
287 info->prev = asstail;
288 }
289 asstail = info;
290 }
291 return info;
292 }
293 }
294 }
295 }
296 return NULL;
297}
298
299BOOL kill_association(ASSOC * killme)
300{
301 LINKASSOC *info;
302
303 if (killme && *killme->mask) {
304 info = asshead;
305 while (info) {
306 if (!stricmp(info->mask, killme->mask) &&
307 info->offset == killme->offset &&
308 (((!info->sig || !*info->sig) && !*killme->sig) ||
309 (info->sig && !strcmp(killme->sig, info->sig)))) {
310 if (info == asshead) {
311 asshead = info->next;
312 if (info == asstail)
313 asstail = info->prev;
314 }
315 else {
316 if (info->next)
317 (info->next)->prev = info->prev;
318 if (info->prev)
319 (info->prev)->next = info->next;
320 if (info == asstail)
321 asstail = info->prev;
322 }
323 free(info->cl);
324 free(info->mask);
325 if (info->sig)
326 free(info->sig);
327 free(info);
328 return TRUE;
329 }
330 info = info->next;
331 }
332 }
333 return FALSE;
334}
335
336INT ExecAssociation(HWND hwnd, CHAR * datafile)
337{
338 CHAR *file, sig[CCHMAXPATH], sigl[CCHMAXPATH], mask[CCHMAXPATH], *p;
339 FILE *fp;
340 BOOL didmatch, exclude;
341 ULONG offset;
342 LINKASSOC *info;
343
344 if (!assloaded)
345 load_associations();
346 if (!asshead)
347 return -1;
348 if (!datafile || !*datafile)
349 return -1;
350 file = strrchr(datafile, '\\');
351 if (!file)
352 file = strrchr(datafile, ':');
353 if (file)
354 file++;
355 else
356 file = datafile;
357 info = asshead;
358 while (info) {
359 strcpy(mask, info->mask);
360 p = strtok(mask, ";");
361 while (p) {
362 if (*p == '/') {
363 p++;
364 exclude = TRUE;
365 }
366 else
367 exclude = FALSE;
368 didmatch = wildcard((strchr(p, '\\') ||
369 strchr(p, ':')) ? datafile : file, p, FALSE);
370 if (exclude && didmatch)
371 didmatch = FALSE;
372 if (didmatch) {
373 if (info->sig && *info->sig) {
374 strcpy(sigl, info->sig);
375 literal(sigl);
376 fp = _fsopen(datafile, "rb", SH_DENYNO);
377 if (fp) {
378 if (info->offset < 0L) {
379 fseek(fp, 0L, SEEK_END);
380 offset = ftell(fp) + info->offset;
381 }
382 else
383 offset = info->offset;
384 fseek(fp, offset, SEEK_SET);
385 if (fread(sig,
386 1,
387 strlen(sigl),
388 fp) != strlen(sigl) || strncmp(sigl, sig, strlen(sigl)))
389 didmatch = FALSE;
390 fclose(fp);
391 }
392 }
393 }
394 if (didmatch) { /* got a match; do it... */
395
396 CHAR *list[2];
397 INT flags, rc;
398 BOOL dieafter = FALSE;
399
400 if (fAmAV2) {
401 if (stristr(info->cl, "AV2.EXE") ||
402 stristr(info->cl, "AV2.CMD") || stristr(info->cl, "<>"))
403 return -1;
404 }
405 if (!strcmp(info->cl, "<>")) {
406 OpenObject(datafile, Default, hwnd);
407 return 0;
408 }
409 list[0] = datafile;
410 list[1] = NULL;
411 flags = info->flags;
412 if (!(flags & FULLSCREEN))
413 flags |= WINDOWED;
414 if (flags & KEEP)
415 flags |= SEPARATEKEEP;
416 else
417 flags |= SEPARATE;
418 flags &= (~KEEP);
419 if (flags & DIEAFTER)
420 dieafter = TRUE;
421 flags &= (~DIEAFTER);
422 rc = ExecOnList(hwnd,
423 info->cl,
424 flags,
425 NULL, list, GetPString(IDS_EXECASSOCTITLETEXT));
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];
620
621 *filename = 0;
622 if (insert_filename(hwnd, filename, 2, FALSE) && *filename) {
623 strcat(filename, " %a");
624 WinSetDlgItemText(hwnd, ASS_CL, filename);
625 }
626 }
627 break;
628
629 case DID_OK:
630 {
631 ASSOC temp;
632 CHAR dummy[34];
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 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
649 rstrip(temp.sig);
650 if (*temp.sig) {
651 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
652 temp.offset = atol(dummy);
653 }
654 bstrip(temp.mask);
655 bstrip(temp.cl);
656 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT))
657 temp.flags = 0;
658 else if (WinQueryButtonCheckstate(hwnd, ASS_FULLSCREEN))
659 temp.flags = FULLSCREEN;
660 else if (WinQueryButtonCheckstate(hwnd, ASS_MINIMIZED))
661 temp.flags = MINIMIZED;
662 else if (WinQueryButtonCheckstate(hwnd, ASS_MAXIMIZED))
663 temp.flags = MAXIMIZED;
664 else if (WinQueryButtonCheckstate(hwnd, ASS_INVISIBLE))
665 temp.flags = INVISIBLE;
666 if (WinQueryButtonCheckstate(hwnd, ASS_KEEP))
667 temp.flags |= KEEP;
668 if (WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
669 temp.flags |= DIEAFTER;
670 if (WinQueryButtonCheckstate(hwnd, ASS_PROMPT))
671 temp.flags |= PROMPT;
672 info = add_association(&temp);
673 if (!info)
674 WinDismissDlg(hwnd, 1); /* Runtime_Error(pszSrcFile, __LINE__, "add_association"); */
675 else {
676
677 CHAR s[1002 + CCHMAXPATH + 6];
678
679 *s = 0;
680 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s);
681 bstripcr(s);
682 if (*s)
683 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s);
684 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask,
685 temp.cl, (*temp.sig) ?
686 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr,
687 (*temp.sig) ? "]" : NullStr);
688 x = (SHORT) WinSendDlgItemMsg(hwnd,
689 ASS_LISTBOX,
690 LM_INSERTITEM,
691 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
692 if (x >= 0) {
693 WinSendDlgItemMsg(hwnd,
694 ASS_LISTBOX,
695 LM_SETITEMHANDLE,
696 MPFROMSHORT(x), MPFROMP(info));
697 WinSendDlgItemMsg(hwnd,
698 ASS_LISTBOX,
699 LM_SELECTITEM,
700 MPFROMSHORT(x), MPFROMSHORT(TRUE));
701 }
702 save_associations();
703 }
704 }
705 WinDismissDlg(hwnd, 1);
706 break;
707
708 case DID_CANCEL:
709 WinDismissDlg(hwnd, 0);
710 break;
711
712 case IDM_HELP:
713 if (hwndHelp)
714 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
715 MPFROM2SHORT(HELP_ASSOC, 0), MPFROMSHORT(HM_RESOURCEID));
716 break;
717
718 case ASS_ADD:
719 {
720 ASSOC temp;
721 CHAR dummy[34];
722
723 replace = FALSE;
724
725 memset(&temp, 0, sizeof(ASSOC));
726 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
727 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl);
728 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
729 rstrip(temp.sig);
730 if (*temp.sig) {
731 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
732 temp.offset = atol(dummy);
733 }
734 bstrip(temp.mask);
735 bstrip(temp.cl);
736 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT))
737 temp.flags = 0;
738 else if (WinQueryButtonCheckstate(hwnd, ASS_FULLSCREEN))
739 temp.flags = FULLSCREEN;
740 else if (WinQueryButtonCheckstate(hwnd, ASS_MINIMIZED))
741 temp.flags = MINIMIZED;
742 else if (WinQueryButtonCheckstate(hwnd, ASS_MAXIMIZED))
743 temp.flags = MAXIMIZED;
744 else if (WinQueryButtonCheckstate(hwnd, ASS_INVISIBLE))
745 temp.flags = INVISIBLE;
746 if (WinQueryButtonCheckstate(hwnd, ASS_KEEP))
747 temp.flags |= KEEP;
748 if (WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
749 temp.flags |= DIEAFTER;
750 if (WinQueryButtonCheckstate(hwnd, ASS_PROMPT))
751 temp.flags |= PROMPT;
752 info = add_association(&temp);
753 //Add will fail if mask is not changed
754 if (info) {
755
756 CHAR s[1002 + CCHMAXPATH + 6];
757
758 *s = 0;
759 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s);
760 bstripcr(s);
761 if (*s)
762 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s);
763 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask,
764 temp.cl, (*temp.sig) ?
765 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr,
766 (*temp.sig) ? "]" : NullStr);
767 x = (SHORT) WinSendDlgItemMsg(hwnd,
768 ASS_LISTBOX,
769 LM_INSERTITEM,
770 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
771 if (x >= 0) {
772 WinSendDlgItemMsg(hwnd,
773 ASS_LISTBOX,
774 LM_SETITEMHANDLE,
775 MPFROMSHORT(x), MPFROMP(info));
776 WinSendDlgItemMsg(hwnd,
777 ASS_LISTBOX,
778 LM_SELECTITEM,
779 MPFROMSHORT(x), MPFROMSHORT(TRUE));
780 }
781 save_associations();
782 }
783 }
784 break;
785
786 case ASS_DELETE:
787 {
788 ASSOC temp;
789 CHAR dummy[34];
790
791 memset(&temp, 0, sizeof(ASSOC));
792 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
793 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
794 rstrip(temp.sig);
795 if (*temp.sig) {
796 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
797 temp.offset = atol(dummy);
798 }
799 bstrip(temp.mask);
800 PrfWriteProfileData(fmprof, FM3Str, temp.mask, NULL, 0L);
801 if (kill_association(&temp))
802 /* Runtime_Error(pszSrcFile, __LINE__, "kill_association");
803 else */{
804 x = (SHORT) WinSendDlgItemMsg(hwnd,
805 ASS_LISTBOX,
806 LM_QUERYSELECTION,
807 MPFROMSHORT(LIT_FIRST), MPVOID);
808 if (x >= 0) {
809 WinSendDlgItemMsg(hwnd,
810 ASS_LISTBOX,
811 LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
812 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_SELECTITEM,
813 MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE));
814 }
815 save_associations();
816 }
817 }
818 break;
819 case ASS_REPLACE:
820
821 {
822 ASSOC temp;
823 CHAR dummy[34];
824
825 replace = TRUE;
826
827 y = (SHORT) WinSendDlgItemMsg(hwnd,
828 ASS_LISTBOX,
829 LM_QUERYSELECTION,
830 MPFROMSHORT(LIT_CURSOR), MPVOID);
831 memset(&temp, 0, sizeof(ASSOC));
832 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
833 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl);
834 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
835 rstrip(temp.sig);
836 if (*temp.sig) {
837 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
838 temp.offset = atol(dummy);
839 }
840 bstrip(temp.mask);
841 bstrip(temp.cl);
842 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT))
843 temp.flags = 0;
844 else if (WinQueryButtonCheckstate(hwnd, ASS_FULLSCREEN))
845 temp.flags = FULLSCREEN;
846 else if (WinQueryButtonCheckstate(hwnd, ASS_MINIMIZED))
847 temp.flags = MINIMIZED;
848 else if (WinQueryButtonCheckstate(hwnd, ASS_MAXIMIZED))
849 temp.flags = MAXIMIZED;
850 else if (WinQueryButtonCheckstate(hwnd, ASS_INVISIBLE))
851 temp.flags = INVISIBLE;
852 if (WinQueryButtonCheckstate(hwnd, ASS_KEEP))
853 temp.flags |= KEEP;
854 if (WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
855 temp.flags |= DIEAFTER;
856 if (WinQueryButtonCheckstate(hwnd, ASS_PROMPT))
857 temp.flags |= PROMPT;
858 info = add_association(&temp);
859 //Add will fail if mask is not changed
860 if (info) {
861
862 CHAR s[1002 + CCHMAXPATH + 6];
863
864 *s = 0;
865 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s);
866 bstripcr(s);
867 if (*s)
868 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s);
869 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask,
870 temp.cl, (*temp.sig) ?
871 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr,
872 (*temp.sig) ? "]" : NullStr);
873 x = (SHORT) WinSendDlgItemMsg(hwnd,
874 ASS_LISTBOX,
875 LM_INSERTITEM,
876 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
877 if (x >= 0) {
878 WinSendDlgItemMsg(hwnd,
879 ASS_LISTBOX,
880 LM_SETITEMHANDLE,
881 MPFROMSHORT(x), MPFROMP(info));
882 WinSendDlgItemMsg(hwnd,
883 ASS_LISTBOX,
884 LM_SELECTITEM,
885 MPFROMSHORT(x), MPFROMSHORT(TRUE));
886 }
887 save_associations();
888 }
889 }
890 {
891 ASSOC temp;
892 CHAR dummy[34];
893
894 WinSendDlgItemMsg(hwnd,
895 ASS_LISTBOX,
896 LM_SELECTITEM, MPFROMSHORT(y), MPFROMSHORT(TRUE));
897 memset(&temp, 0, sizeof(ASSOC));
898 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
899 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
900 rstrip(temp.sig);
901 if (*temp.sig) {
902 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
903 temp.offset = atol(dummy);
904 }
905 bstrip(temp.mask);
906 PrfWriteProfileData(fmprof, FM3Str, temp.mask, NULL, 0L);
907 if (!kill_association(&temp))
908 Runtime_Error(pszSrcFile, __LINE__, "kill_association");
909 else {
910
911 if (y >= 0) {
912 WinSendDlgItemMsg(hwnd,
913 ASS_LISTBOX,
914 LM_DELETEITEM, MPFROMSHORT(y), MPVOID);
915 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_SELECTITEM,
916 MPFROMSHORT(x - 1), MPFROMSHORT(TRUE));
917 }
918 save_associations();
919 }
920 }
921 break;
922 }
923 return 0;
924 }
925 return WinDefDlgProc(hwnd, msg, mp1, mp2);
926}
927
928VOID EditAssociations(HWND hwnd)
929{
930 static CHAR stop = 0;
931
932 if (stop)
933 return;
934 stop++;
935 if (!assloaded)
936 load_associations();
937 WinDlgBox(HWND_DESKTOP, hwnd, AssocDlgProc, FM3ModHandle, ASS_FRAME, NULL);
938 stop = 0;
939}
Note: See TracBrowser for help on using the repository browser.