source: trunk/dll/assoc.c@ 1505

Last change on this file since 1505 was 1498, checked in by Gregg Young, 16 years ago

Changes to get FM2 to compile with the latest watcom 1.9 beta (mostly type casts of CHAR CONSTANT * to CHAR *). Changes to get the environment settings working everywhere again (broken by the change that moved commands to the INI); Added an environment size variable (set to 2048 which was the largest I found hard coded). Still need to find everywhere the environment size is set and use this variable.

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