source: trunk/dll/assoc.c@ 1203

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

Ticket 187: Move datadevlarations/definitions out of fm3dll.h

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