source: trunk/dll/assoc.c@ 1082

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

Changes so FM2 will use TMP/TEMP directory for all temp files; Replaced save_dir2 with global variable so BldFullPathName could easily replace code that performed the same function; Added #ifdef FORTIFY to free_ function that are only used when fortified.

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