source: trunk/dll/assoc.c@ 1106

Last change on this file since 1106 was 1104, checked in by Gregg Young, 17 years ago

Replace save_dir2(dir) with strcpy(dir, pFM2SaveDirectory)

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