source: trunk/dll/assoc.c@ 1844

Last change on this file since 1844 was 1616, checked in by Gregg Young, 14 years ago

Updated a*.c files to Doxygen commenting style. (Ticket 55)

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