source: trunk/dll/assoc.c@ 1194

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

Ticket 187: Draft 2: Move remaining function declarations

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