source: trunk/dll/assoc.c@ 1194

Last change on this file since 1194 was 1188, checked in by John Small, 17 years ago

Ticket 187: Draft 2: Move remaining function declarations

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