source: trunk/dll/assoc.c@ 1117

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

Check disk free space before writing data files to prevent traps from being on a full disk (ticket 154)

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