source: trunk/dll/assoc.c@ 1039

Last change on this file since 1039 was 1039, checked in by Gregg Young, 17 years ago

Removed unnecessary xfrees and included fortify.h where needed; moved several misplaced (x)frees;

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