source: trunk/dll/assoc.c@ 1844

Last change on this file since 1844 was 1616, checked in by Gregg Young, 14 years ago

Updated a*.c files to Doxygen commenting style. (Ticket 55)

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