source: trunk/dll/assoc.c@ 1082

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

Changes so FM2 will use TMP/TEMP directory for all temp files; Replaced save_dir2 with global variable so BldFullPathName could easily replace code that performed the same function; Added #ifdef FORTIFY to free_ function that are only used when fortified.

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