source: trunk/dll/assoc.c@ 1479

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

Work around MMIO's failure to recognize MPG files as media. Reorder file type checks to eliminate problem with MMIO identifying exes etc as media. Check for zero byte file and let user decide to open in an editor or abort (also prevents MMIO misidentification). Tickets 70, 405, 409, 410

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