source: trunk/dll/assoc.c@ 1104

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

Replace save_dir2(dir) with strcpy(dir, pFM2SaveDirectory)

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