source: trunk/dll/assoc.c@ 985

Last change on this file since 985 was 985, checked in by Gregg Young, 18 years ago

Update sizes dialog (ticket 44); Make max command line length user settable (ticket 199); use xfree for free in most cases (ticket 212); initial code to check for valid ini file (ticket 102); Some additional refactoring and structure rework; Some documentation updates;

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