source: trunk/dll/assoc.c@ 1877

Last change on this file since 1877 was 1877, checked in by Gregg Young, 10 years ago

Remove debug code

  • 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 1877 2015-10-11 21:43:27Z 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 rc = ExecOnList(hwnd,
531 info->pszCmdLine,
532 flags, NULL,
533 info->env != NullStr ? info->env : NULL,
534 list,
535 GetPString(IDS_EXECASSOCTITLETEXT),
536 pszSrcFile, __LINE__);
537 if (rc != -1 && dieafter)
538 PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
539 return rc;
540 }
541 p = strtok(0, ";");
542 }
543 info = info->next;
544 }
545 return -1;
546}
547
548MRESULT EXPENTRY AssocDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
549{
550 LINKASSOC *info;
551 SHORT x, y;
552
553 switch (msg) {
554 case WM_INITDLG:
555 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
556 WinSendDlgItemMsg(hwnd, ASS_MASK, EM_SETTEXTLIMIT,
557 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
558 WinSendDlgItemMsg(hwnd, ASS_CL, EM_SETTEXTLIMIT,
559 MPFROM2SHORT(MaxComLineStrg - 1, 0), MPVOID);
560 WinSendDlgItemMsg(hwnd, ASS_ENVIRON, EM_SETTEXTLIMIT,
561 MPFROM2SHORT(ENVIRONMENT_SIZE - 1, 0), MPVOID);
562 WinSendDlgItemMsg(hwnd, ASS_SIG, EM_SETTEXTLIMIT,
563 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
564 WinSendDlgItemMsg(hwnd, ASS_OFFSET, EM_SETTEXTLIMIT,
565 MPFROM2SHORT(34, 0), MPVOID);
566 WinSetDlgItemText(hwnd, ASS_MASK, NullStr);
567 WinSetDlgItemText(hwnd, ASS_CL, NullStr);
568 WinSetDlgItemText(hwnd, ASS_SIG, NullStr);
569 WinSetDlgItemText(hwnd, ASS_OFFSET, "0");
570 WinCheckButton(hwnd, ASS_DEFAULT, TRUE);
571 WinCheckButton(hwnd, ASS_PROMPT, FALSE);
572 WinCheckButton(hwnd, ASS_KEEP, FALSE);
573 WinCheckButton(hwnd, ASS_DIEAFTER, FALSE);
574 PostMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
575 {
576 PFNWP oldproc;
577
578 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, ASS_CL),
579 (PFNWP) AssocTextProc);
580 if (oldproc)
581 WinSetWindowPtr(WinWindowFromID(hwnd, ASS_CL), QWL_USER,
582 (PVOID) oldproc);
583 }
584 break;
585
586 case UM_UNDO:
587 {
588 PSZ pszDisplayStr;
589
590 pszDisplayStr = xmallocz((CCHMAXPATH * 2) + MaxComLineStrg + 6,
591 pszSrcFile, __LINE__);
592 if (pszDisplayStr) {
593 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
594 info = asshead;
595 while (info) {
596 sprintf(pszDisplayStr,
597 "%-12s \x1a %-24s %s%s%s",
598 info->mask,
599 info->pszCmdLine,
600 (info->sig && *info->sig) ?
601 "[" : NullStr,
602 (info->sig && *info->sig) ? info->sig : NullStr,
603 (info->sig && *info->sig) ? "]" : NullStr);
604 x = (SHORT) WinSendDlgItemMsg(hwnd,
605 ASS_LISTBOX,
606 LM_INSERTITEM,
607 MPFROM2SHORT(LIT_END, 0), MPFROMP(pszDisplayStr));
608 if (x >= 0)
609 WinSendDlgItemMsg(hwnd,
610 ASS_LISTBOX,
611 LM_SETITEMHANDLE, MPFROMSHORT(x), MPFROMP(info));
612 info = info->next;
613 }
614 WinSendDlgItemMsg(hwnd,
615 ASS_LISTBOX,
616 LM_SELECTITEM, MPFROMSHORT(0), MPFROMSHORT(TRUE));
617 xfree(pszDisplayStr, pszSrcFile, __LINE__);
618 }
619 }
620 return 0;
621
622 case WM_CONTROL:
623 if (SHORT1FROMMP(mp1) == ASS_LISTBOX) {
624 switch (SHORT2FROMMP(mp1)) {
625 case LN_ENTER:
626 case LN_SELECT:
627 x = (SHORT) WinSendDlgItemMsg(hwnd,
628 ASS_LISTBOX,
629 LM_QUERYSELECTION,
630 MPFROMSHORT(LIT_FIRST), MPVOID);
631 if (x >= 0) {
632
633 CHAR s[36];
634
635 info = (LINKASSOC *) WinSendDlgItemMsg(hwnd,
636 ASS_LISTBOX,
637 LM_QUERYITEMHANDLE,
638 MPFROMSHORT(x), MPVOID);
639 if (!info) {
640 Runtime_Error(pszSrcFile, __LINE__, "Query item handle failed");
641 break;
642 }
643 WinSetDlgItemText(hwnd, ASS_MASK, info->mask);
644 WinSetDlgItemText(hwnd, ASS_CL, info->pszCmdLine);
645 WinSetDlgItemText(hwnd, ASS_SIG,
646 (info->sig && *info->sig) ? info->sig : NullStr);
647 sprintf(s, "%ld", info->offset);
648 WinSetDlgItemText(hwnd, ASS_OFFSET, s);
649 if (!(info->flags & 1023))
650 WinCheckButton(hwnd, ASS_DEFAULT, TRUE);
651 else {
652 if (info->flags & FULLSCREEN)
653 WinCheckButton(hwnd, ASS_FULLSCREEN, TRUE);
654 else if (info->flags & MINIMIZED)
655 WinCheckButton(hwnd, ASS_MINIMIZED, TRUE);
656 else if (info->flags & MAXIMIZED)
657 WinCheckButton(hwnd, ASS_MAXIMIZED, TRUE);
658 else if (info->flags & INVISIBLE)
659 WinCheckButton(hwnd, ASS_INVISIBLE, TRUE);
660 }
661 WinCheckButton(hwnd, ASS_KEEP, ((info->flags & KEEP) != 0));
662 WinCheckButton(hwnd, ASS_DIEAFTER, ((info->flags & DIEAFTER) != 0));
663 WinCheckButton(hwnd, ASS_PROMPT, ((info->flags & PROMPT) != 0));
664 {
665 CHAR env[ENVIRONMENT_SIZE];
666 //ULONG size;
667 CHAR key[CCHMAXPATH];
668
669 *env = 0;
670 //size = sizeof(env) - 1;
671 sprintf(key, "ASSOC.%senv", info->pszCmdLine);
672 if (PrfQueryProfileString(fmprof, FM3Str, key, NullStr, env, sizeof(env)) &&
673 env != NullStr)
674 WinSetDlgItemText(hwnd, ASS_ENVIRON, env);
675 else
676 WinSetDlgItemText(hwnd, ASS_ENVIRON, NullStr);
677 }
678 }
679 break;
680 }
681 }
682 return 0;
683
684 case WM_COMMAND:
685 switch (SHORT1FROMMP(mp1)) {
686 case ASS_TOP:
687 x = (SHORT) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
688 LM_QUERYSELECTION,
689 MPFROMSHORT(LIT_FIRST), MPVOID);
690 if (x >= 0) {
691 info = (LINKASSOC *) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
692 LM_QUERYITEMHANDLE,
693 MPFROMSHORT(x), MPVOID);
694 if (info) {
695 if (info != asshead) {
696 if (info->prev)
697 info->prev->next = info->next;
698 if (info->next)
699 info->next->prev = info->prev;
700 if (info == asstail)
701 asstail = info->prev;
702 info->prev = NULL;
703 info->next = asshead;
704 asshead->prev = info;
705 asshead = info;
706 WinSendMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
707 save_associations();
708 }
709 }
710 }
711 break;
712
713 case ASS_BOTTOM:
714 x = (SHORT) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
715 LM_QUERYSELECTION,
716 MPFROMSHORT(LIT_FIRST), MPVOID);
717 if (x >= 0) {
718 info = (LINKASSOC *) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
719 LM_QUERYITEMHANDLE,
720 MPFROMSHORT(x), MPVOID);
721 if (info) {
722 if (info != asstail) {
723 if (info->next)
724 info->next->prev = info->prev;
725 if (info->prev)
726 info->prev->next = info->next;
727 if (info == asshead)
728 asshead = info->next;
729 info->next = NULL;
730 info->prev = asstail;
731 asstail->next = info;
732 asstail = info;
733 WinSendMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
734 save_associations();
735 }
736 }
737 }
738 break;
739 case ASS_FIND:
740 {
741 CHAR filename[CCHMAXPATH + 9], szfilename[CCHMAXPATH + 9];
742
743 *filename = 0;
744 if (insert_filename(hwnd, filename, 2, FALSE) && *filename) {
745 BldQuotedFileName(szfilename, filename);
746 strcat(szfilename, " %a");
747 WinSetDlgItemText(hwnd, ASS_CL, szfilename);
748 }
749 }
750 break;
751
752 case DID_OK:
753 {
754 ASSOC temp;
755 CHAR dummy[34];
756 PSZ pszWorkBuf;
757 replace = FALSE;
758
759 memset(&temp, 0, sizeof(ASSOC));
760 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
761 if (!temp.pszCmdLine)
762 break; //already complained
763
764 {
765 x = (SHORT) WinSendDlgItemMsg(hwnd,
766 ASS_LISTBOX,
767 LM_QUERYSELECTION, MPVOID, MPVOID);
768 if (x == LIT_NONE)
769 x = (SHORT) WinSendDlgItemMsg(hwnd,
770 ASS_LISTBOX,
771 LM_SELECTITEM,
772 MPFROMSHORT(0), MPFROMSHORT(TRUE));
773 }
774 pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
775 if (!pszWorkBuf) {
776 free(temp.pszCmdLine);
777 break; //already complained
778 }
779 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
780 WinQueryDlgItemText(hwnd, ASS_CL, MaxComLineStrg, temp.pszCmdLine);
781 if (strcmp(temp.pszCmdLine, "<>")) {
782 NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
783 memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
784 }
785 free(pszWorkBuf);
786 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
787 rstrip(temp.sig);
788 if (*temp.sig) {
789 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
790 temp.offset = atol(dummy);
791 }
792 bstrip(temp.mask);
793 bstrip(temp.pszCmdLine);
794 temp.flags = CheckExecutibleFlags(hwnd, 1);
795 if (fCancelAction){
796 fCancelAction = FALSE;
797 free(temp.pszCmdLine);
798 break;
799 }
800 else
801 info = add_association(&temp);
802 if (!info)
803 WinDismissDlg(hwnd, 1);
804 else {
805 display_associations(hwnd, &temp, info);
806 save_associations();
807 }
808 free(temp.pszCmdLine);
809 }
810 WinDismissDlg(hwnd, 1);
811 break;
812
813 case DID_CANCEL:
814 WinDismissDlg(hwnd, 0);
815 break;
816
817 case IDM_HELP:
818 if (hwndHelp)
819 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
820 MPFROM2SHORT(HELP_ASSOC, 0), MPFROMSHORT(HM_RESOURCEID));
821 break;
822
823 case ASS_ADD:
824 {
825 ASSOC temp;
826 CHAR dummy[34];
827 PSZ pszWorkBuf;
828 replace = FALSE;
829
830 memset(&temp, 0, sizeof(ASSOC));
831 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
832 if (!temp.pszCmdLine)
833 break; //already complained
834 pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
835 if (!pszWorkBuf) {
836 free(temp.pszCmdLine);
837 break; //already complained
838 }
839 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
840 WinQueryDlgItemText(hwnd, ASS_CL, MaxComLineStrg, temp.pszCmdLine);
841 if (strcmp(temp.pszCmdLine, "<>")) {
842 NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
843 memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
844 }
845 free(pszWorkBuf);
846 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
847 rstrip(temp.sig);
848 if (*temp.sig) {
849 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
850 temp.offset = atol(dummy);
851 }
852 bstrip(temp.mask);
853 bstrip(temp.pszCmdLine);
854 temp.flags = CheckExecutibleFlags(hwnd, 1);
855 if (fCancelAction){
856 fCancelAction = FALSE;
857 free(temp.pszCmdLine);
858 break;
859 }
860 else
861 info = add_association(&temp);
862 //Add will fail if mask is not changed
863 if (info) {
864 display_associations(hwnd, &temp, info);
865 save_associations();
866 }
867 free(temp.pszCmdLine);
868 }
869 break;
870
871 case ASS_DELETE:
872 {
873 ASSOC temp;
874 CHAR dummy[34];
875 CHAR key[CCHMAXPATH];
876
877 memset(&temp, 0, sizeof(ASSOC));
878 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
879 if (!temp.pszCmdLine)
880 break; //already complained
881 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
882 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
883 rstrip(temp.sig);
884 if (*temp.sig) {
885 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
886 temp.offset = atol(dummy);
887 }
888 //bstrip(temp.mask);
889 sprintf(key, "ASSOC.%senv", temp.pszCmdLine);
890 PrfWriteProfileString(fmprof, FM3Str, key, NULL);
891 if (kill_association(&temp)) {
892 x = (SHORT) WinSendDlgItemMsg(hwnd,
893 ASS_LISTBOX,
894 LM_QUERYSELECTION,
895 MPFROMSHORT(LIT_FIRST), MPVOID);
896 if (x >= 0) {
897 WinSendDlgItemMsg(hwnd,
898 ASS_LISTBOX,
899 LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
900 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_SELECTITEM,
901 MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE));
902 }
903 save_associations();
904 }
905 free(temp.pszCmdLine);
906 }
907
908 break;
909 case ASS_REPLACE:
910
911 {
912 ASSOC temp;
913 CHAR dummy[34];
914 PSZ pszWorkBuf;
915 replace = TRUE;
916
917 memset(&temp, 0, sizeof(ASSOC));
918 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
919 if (!temp.pszCmdLine)
920 break; //already complained
921 y = (SHORT) WinSendDlgItemMsg(hwnd,
922 ASS_LISTBOX,
923 LM_QUERYSELECTION,
924 MPFROMSHORT(LIT_CURSOR), MPVOID);
925 pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
926 if (!pszWorkBuf) {
927 free(temp.pszCmdLine);
928 break; //already complained
929 }
930 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
931 WinQueryDlgItemText(hwnd, ASS_CL, MaxComLineStrg, temp.pszCmdLine);
932 if (strcmp(temp.pszCmdLine, "<>")) {
933 NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
934 memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
935 }
936 free(pszWorkBuf);
937 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
938 rstrip(temp.sig);
939 if (*temp.sig) {
940 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
941 temp.offset = atol(dummy);
942 }
943 bstrip(temp.mask);
944 bstrip(temp.pszCmdLine);
945 WinQueryDlgItemText(hwnd, ASS_ENVIRON, sizeof(temp.env), temp.env);
946 bstrip(temp.env);
947 temp.flags = CheckExecutibleFlags(hwnd, 1);
948 if (fCancelAction){
949 fCancelAction = FALSE;
950 free(temp.pszCmdLine);
951 break;
952 }
953 else
954 info = add_association(&temp);
955 if (info) {
956 display_associations(hwnd, &temp, info);
957 save_associations();
958 }
959 free(temp.pszCmdLine);
960 }
961 {
962 ASSOC temp;
963 CHAR dummy[34];
964 CHAR key[CCHMAXPATH];
965
966 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
967 if (!temp.pszCmdLine)
968 break; //already complained
969 WinSendDlgItemMsg(hwnd,
970 ASS_LISTBOX,
971 LM_SELECTITEM, MPFROMSHORT(y), MPFROMSHORT(TRUE));
972 memset(temp.sig, 0, sizeof(temp.sig));
973 memset(temp.mask, 0, sizeof(temp.mask));
974 temp.offset = 0;
975 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
976 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
977 rstrip(temp.sig);
978 if (*temp.sig) {
979 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
980 temp.offset = atol(dummy);
981 }
982 //bstrip(temp.mask);
983 sprintf(key, "ASSOC.%senv", temp.pszCmdLine);
984 PrfWriteProfileString(fmprof, FM3Str, key, NULL);
985 if (!kill_association(&temp))
986 Runtime_Error(pszSrcFile, __LINE__, "kill_association");
987 else {
988
989 if (y >= 0) {
990 WinSendDlgItemMsg(hwnd,
991 ASS_LISTBOX,
992 LM_DELETEITEM, MPFROMSHORT(y), MPVOID);
993 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_SELECTITEM,
994 MPFROMSHORT(x - 1), MPFROMSHORT(TRUE));
995 }
996 save_associations();
997 }
998 free(temp.pszCmdLine);
999 }
1000 break;
1001 }
1002 return 0;
1003 }
1004 return WinDefDlgProc(hwnd, msg, mp1, mp2);
1005}
1006
1007VOID EditAssociations(HWND hwnd)
1008{
1009 static CHAR stop = 0;
1010
1011 if (stop)
1012 return;
1013 stop++;
1014 if (!assloaded)
1015 load_associations();
1016 WinDlgBox(HWND_DESKTOP, hwnd, AssocDlgProc, FM3ModHandle, ASS_FRAME, NULL);
1017 stop = 0;
1018}
1019
1020#pragma alloc_text(ASSOC2,free_associations,load_associations,save_associations,display_associations)
1021#pragma alloc_text(ASSOC2,ExecAssociation,AssocTextProc)
1022#pragma alloc_text(ASSOC,add_association,kill_association,AssocDlgProc,EditAssociations)
Note: See TracBrowser for help on using the repository browser.