source: trunk/dll/assoc.c@ 1877

Last change on this file since 1877 was 1877, checked in by Gregg Young, 10 years ago

Remove debug code

  • 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 1877 2015-10-11 21:43:27Z 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);
[551]530 rc = ExecOnList(hwnd,
[985]531 info->pszCmdLine,
[1497]532 flags, NULL,
[1519]533 info->env != NullStr ? info->env : NULL,
534 list,
535 GetPString(IDS_EXECASSOCTITLETEXT),
[1321]536 pszSrcFile, __LINE__);
[551]537 if (rc != -1 && dieafter)
538 PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
539 return rc;
[2]540 }
[551]541 p = strtok(0, ";");
[2]542 }
543 info = info->next;
544 }
545 return -1;
546}
547
[551]548MRESULT EXPENTRY AssocDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[342]549{
[2]550 LINKASSOC *info;
[551]551 SHORT x, y;
[2]552
[551]553 switch (msg) {
554 case WM_INITDLG:
555 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
556 WinSendDlgItemMsg(hwnd, ASS_MASK, EM_SETTEXTLIMIT,
557 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
558 WinSendDlgItemMsg(hwnd, ASS_CL, EM_SETTEXTLIMIT,
[1519]559 MPFROM2SHORT(MaxComLineStrg - 1, 0), MPVOID);
560 WinSendDlgItemMsg(hwnd, ASS_ENVIRON, EM_SETTEXTLIMIT,
561 MPFROM2SHORT(ENVIRONMENT_SIZE - 1, 0), MPVOID);
[551]562 WinSendDlgItemMsg(hwnd, ASS_SIG, EM_SETTEXTLIMIT,
563 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
564 WinSendDlgItemMsg(hwnd, ASS_OFFSET, EM_SETTEXTLIMIT,
565 MPFROM2SHORT(34, 0), MPVOID);
566 WinSetDlgItemText(hwnd, ASS_MASK, NullStr);
567 WinSetDlgItemText(hwnd, ASS_CL, NullStr);
568 WinSetDlgItemText(hwnd, ASS_SIG, NullStr);
569 WinSetDlgItemText(hwnd, ASS_OFFSET, "0");
570 WinCheckButton(hwnd, ASS_DEFAULT, TRUE);
571 WinCheckButton(hwnd, ASS_PROMPT, FALSE);
572 WinCheckButton(hwnd, ASS_KEEP, FALSE);
573 WinCheckButton(hwnd, ASS_DIEAFTER, FALSE);
574 PostMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
575 {
576 PFNWP oldproc;
[2]577
[551]578 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, ASS_CL),
579 (PFNWP) AssocTextProc);
580 if (oldproc)
581 WinSetWindowPtr(WinWindowFromID(hwnd, ASS_CL), QWL_USER,
582 (PVOID) oldproc);
583 }
584 break;
[2]585
[551]586 case UM_UNDO:
587 {
[989]588 PSZ pszDisplayStr;
[2]589
[989]590 pszDisplayStr = xmallocz((CCHMAXPATH * 2) + MaxComLineStrg + 6,
[1321]591 pszSrcFile, __LINE__);
[989]592 if (pszDisplayStr) {
[1321]593 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
594 info = asshead;
595 while (info) {
596 sprintf(pszDisplayStr,
597 "%-12s \x1a %-24s %s%s%s",
598 info->mask,
599 info->pszCmdLine,
600 (info->sig && *info->sig) ?
601 "[" : NullStr,
602 (info->sig && *info->sig) ? info->sig : NullStr,
603 (info->sig && *info->sig) ? "]" : NullStr);
604 x = (SHORT) WinSendDlgItemMsg(hwnd,
605 ASS_LISTBOX,
606 LM_INSERTITEM,
607 MPFROM2SHORT(LIT_END, 0), MPFROMP(pszDisplayStr));
608 if (x >= 0)
609 WinSendDlgItemMsg(hwnd,
610 ASS_LISTBOX,
611 LM_SETITEMHANDLE, MPFROMSHORT(x), MPFROMP(info));
612 info = info->next;
613 }
614 WinSendDlgItemMsg(hwnd,
615 ASS_LISTBOX,
616 LM_SELECTITEM, MPFROMSHORT(0), MPFROMSHORT(TRUE));
617 xfree(pszDisplayStr, pszSrcFile, __LINE__);
[2]618 }
[551]619 }
620 return 0;
[2]621
[551]622 case WM_CONTROL:
623 if (SHORT1FROMMP(mp1) == ASS_LISTBOX) {
624 switch (SHORT2FROMMP(mp1)) {
625 case LN_ENTER:
626 case LN_SELECT:
627 x = (SHORT) WinSendDlgItemMsg(hwnd,
628 ASS_LISTBOX,
629 LM_QUERYSELECTION,
630 MPFROMSHORT(LIT_FIRST), MPVOID);
631 if (x >= 0) {
[2]632
[551]633 CHAR s[36];
[2]634
[551]635 info = (LINKASSOC *) WinSendDlgItemMsg(hwnd,
636 ASS_LISTBOX,
637 LM_QUERYITEMHANDLE,
638 MPFROMSHORT(x), MPVOID);
639 if (!info) {
640 Runtime_Error(pszSrcFile, __LINE__, "Query item handle failed");
641 break;
642 }
643 WinSetDlgItemText(hwnd, ASS_MASK, info->mask);
[985]644 WinSetDlgItemText(hwnd, ASS_CL, info->pszCmdLine);
[551]645 WinSetDlgItemText(hwnd, ASS_SIG,
646 (info->sig && *info->sig) ? info->sig : NullStr);
647 sprintf(s, "%ld", info->offset);
648 WinSetDlgItemText(hwnd, ASS_OFFSET, s);
649 if (!(info->flags & 1023))
650 WinCheckButton(hwnd, ASS_DEFAULT, TRUE);
651 else {
652 if (info->flags & FULLSCREEN)
653 WinCheckButton(hwnd, ASS_FULLSCREEN, TRUE);
654 else if (info->flags & MINIMIZED)
655 WinCheckButton(hwnd, ASS_MINIMIZED, TRUE);
656 else if (info->flags & MAXIMIZED)
657 WinCheckButton(hwnd, ASS_MAXIMIZED, TRUE);
658 else if (info->flags & INVISIBLE)
659 WinCheckButton(hwnd, ASS_INVISIBLE, TRUE);
660 }
661 WinCheckButton(hwnd, ASS_KEEP, ((info->flags & KEEP) != 0));
662 WinCheckButton(hwnd, ASS_DIEAFTER, ((info->flags & DIEAFTER) != 0));
663 WinCheckButton(hwnd, ASS_PROMPT, ((info->flags & PROMPT) != 0));
664 {
[1519]665 CHAR env[ENVIRONMENT_SIZE];
666 //ULONG size;
667 CHAR key[CCHMAXPATH];
[2]668
[551]669 *env = 0;
[1519]670 //size = sizeof(env) - 1;
671 sprintf(key, "ASSOC.%senv", info->pszCmdLine);
672 if (PrfQueryProfileString(fmprof, FM3Str, key, NullStr, env, sizeof(env)) &&
673 env != NullStr)
[551]674 WinSetDlgItemText(hwnd, ASS_ENVIRON, env);
675 else
676 WinSetDlgItemText(hwnd, ASS_ENVIRON, NullStr);
677 }
678 }
679 break;
[2]680 }
[551]681 }
682 return 0;
[2]683
[551]684 case WM_COMMAND:
685 switch (SHORT1FROMMP(mp1)) {
686 case ASS_TOP:
687 x = (SHORT) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
688 LM_QUERYSELECTION,
689 MPFROMSHORT(LIT_FIRST), MPVOID);
690 if (x >= 0) {
691 info = (LINKASSOC *) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
692 LM_QUERYITEMHANDLE,
693 MPFROMSHORT(x), MPVOID);
694 if (info) {
695 if (info != asshead) {
696 if (info->prev)
697 info->prev->next = info->next;
698 if (info->next)
699 info->next->prev = info->prev;
700 if (info == asstail)
701 asstail = info->prev;
702 info->prev = NULL;
703 info->next = asshead;
704 asshead->prev = info;
705 asshead = info;
[1594]706 WinSendMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
707 save_associations();
[551]708 }
709 }
710 }
711 break;
[2]712
[551]713 case ASS_BOTTOM:
714 x = (SHORT) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
715 LM_QUERYSELECTION,
716 MPFROMSHORT(LIT_FIRST), MPVOID);
717 if (x >= 0) {
718 info = (LINKASSOC *) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
719 LM_QUERYITEMHANDLE,
720 MPFROMSHORT(x), MPVOID);
721 if (info) {
722 if (info != asstail) {
723 if (info->next)
724 info->next->prev = info->prev;
725 if (info->prev)
726 info->prev->next = info->next;
727 if (info == asshead)
728 asshead = info->next;
729 info->next = NULL;
730 info->prev = asstail;
731 asstail->next = info;
732 asstail = info;
[1594]733 WinSendMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
734 save_associations();
[551]735 }
736 }
737 }
738 break;
739 case ASS_FIND:
740 {
[888]741 CHAR filename[CCHMAXPATH + 9], szfilename[CCHMAXPATH + 9];
[2]742
[551]743 *filename = 0;
[1321]744 if (insert_filename(hwnd, filename, 2, FALSE) && *filename) {
745 BldQuotedFileName(szfilename, filename);
[888]746 strcat(szfilename, " %a");
747 WinSetDlgItemText(hwnd, ASS_CL, szfilename);
[551]748 }
749 }
750 break;
[2]751
[551]752 case DID_OK:
753 {
754 ASSOC temp;
[1321]755 CHAR dummy[34];
756 PSZ pszWorkBuf;
757 replace = FALSE;
[506]758
[1321]759 memset(&temp, 0, sizeof(ASSOC));
760 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
761 if (!temp.pszCmdLine)
762 break; //already complained
[985]763
[551]764 {
765 x = (SHORT) WinSendDlgItemMsg(hwnd,
766 ASS_LISTBOX,
767 LM_QUERYSELECTION, MPVOID, MPVOID);
768 if (x == LIT_NONE)
769 x = (SHORT) WinSendDlgItemMsg(hwnd,
770 ASS_LISTBOX,
771 LM_SELECTITEM,
772 MPFROMSHORT(0), MPFROMSHORT(TRUE));
[1321]773 }
774 pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
775 if (!pszWorkBuf) {
776 free(temp.pszCmdLine);
777 break; //already complained
778 }
[551]779 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
[1321]780 WinQueryDlgItemText(hwnd, ASS_CL, MaxComLineStrg, temp.pszCmdLine);
781 if (strcmp(temp.pszCmdLine, "<>")) {
782 NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
783 memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
784 }
785 free(pszWorkBuf);
[551]786 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
787 rstrip(temp.sig);
788 if (*temp.sig) {
789 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
790 temp.offset = atol(dummy);
791 }
792 bstrip(temp.mask);
[1488]793 bstrip(temp.pszCmdLine);
794 temp.flags = CheckExecutibleFlags(hwnd, 1);
[1321]795 if (fCancelAction){
796 fCancelAction = FALSE;
797 free(temp.pszCmdLine);
798 break;
799 }
800 else
[551]801 info = add_association(&temp);
802 if (!info)
[1616]803 WinDismissDlg(hwnd, 1);
[1321]804 else {
805 display_associations(hwnd, &temp, info);
[551]806 save_associations();
[1321]807 }
808 free(temp.pszCmdLine);
[551]809 }
810 WinDismissDlg(hwnd, 1);
811 break;
[2]812
[551]813 case DID_CANCEL:
814 WinDismissDlg(hwnd, 0);
815 break;
[2]816
[551]817 case IDM_HELP:
818 if (hwndHelp)
819 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
820 MPFROM2SHORT(HELP_ASSOC, 0), MPFROMSHORT(HM_RESOURCEID));
821 break;
[2]822
[551]823 case ASS_ADD:
824 {
825 ASSOC temp;
[1321]826 CHAR dummy[34];
827 PSZ pszWorkBuf;
828 replace = FALSE;
[2]829
[1321]830 memset(&temp, 0, sizeof(ASSOC));
831 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
832 if (!temp.pszCmdLine)
833 break; //already complained
834 pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
835 if (!pszWorkBuf) {
836 free(temp.pszCmdLine);
837 break; //already complained
838 }
839 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
840 WinQueryDlgItemText(hwnd, ASS_CL, MaxComLineStrg, temp.pszCmdLine);
841 if (strcmp(temp.pszCmdLine, "<>")) {
842 NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
843 memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
844 }
845 free(pszWorkBuf);
[551]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);
[1488]853 bstrip(temp.pszCmdLine);
854 temp.flags = CheckExecutibleFlags(hwnd, 1);
[1321]855 if (fCancelAction){
856 fCancelAction = FALSE;
857 free(temp.pszCmdLine);
858 break;
859 }
860 else
861 info = add_association(&temp);
[551]862 //Add will fail if mask is not changed
863 if (info) {
[1321]864 display_associations(hwnd, &temp, info);
[551]865 save_associations();
866 }
[1321]867 free(temp.pszCmdLine);
[551]868 }
869 break;
[506]870
[551]871 case ASS_DELETE:
872 {
873 ASSOC temp;
[1519]874 CHAR dummy[34];
875 CHAR key[CCHMAXPATH];
[506]876
[1321]877 memset(&temp, 0, sizeof(ASSOC));
878 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
879 if (!temp.pszCmdLine)
880 break; //already complained
[551]881 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
882 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
883 rstrip(temp.sig);
884 if (*temp.sig) {
885 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
886 temp.offset = atol(dummy);
887 }
[1519]888 //bstrip(temp.mask);
889 sprintf(key, "ASSOC.%senv", temp.pszCmdLine);
890 PrfWriteProfileString(fmprof, FM3Str, key, NULL);
[985]891 if (kill_association(&temp)) {
[551]892 x = (SHORT) WinSendDlgItemMsg(hwnd,
893 ASS_LISTBOX,
894 LM_QUERYSELECTION,
895 MPFROMSHORT(LIT_FIRST), MPVOID);
896 if (x >= 0) {
897 WinSendDlgItemMsg(hwnd,
898 ASS_LISTBOX,
899 LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
900 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_SELECTITEM,
901 MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE));
902 }
903 save_associations();
[1321]904 }
905 free(temp.pszCmdLine);
[551]906 }
[985]907
[551]908 break;
909 case ASS_REPLACE:
[506]910
[551]911 {
912 ASSOC temp;
[1519]913 CHAR dummy[34];
[1321]914 PSZ pszWorkBuf;
915 replace = TRUE;
[506]916
[1321]917 memset(&temp, 0, sizeof(ASSOC));
918 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
919 if (!temp.pszCmdLine)
920 break; //already complained
[551]921 y = (SHORT) WinSendDlgItemMsg(hwnd,
922 ASS_LISTBOX,
923 LM_QUERYSELECTION,
[1321]924 MPFROMSHORT(LIT_CURSOR), MPVOID);
925 pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
926 if (!pszWorkBuf) {
927 free(temp.pszCmdLine);
928 break; //already complained
929 }
[551]930 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
[1321]931 WinQueryDlgItemText(hwnd, ASS_CL, MaxComLineStrg, temp.pszCmdLine);
932 if (strcmp(temp.pszCmdLine, "<>")) {
933 NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
934 memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
935 }
936 free(pszWorkBuf);
[551]937 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
938 rstrip(temp.sig);
939 if (*temp.sig) {
940 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
941 temp.offset = atol(dummy);
942 }
943 bstrip(temp.mask);
[1488]944 bstrip(temp.pszCmdLine);
[1519]945 WinQueryDlgItemText(hwnd, ASS_ENVIRON, sizeof(temp.env), temp.env);
946 bstrip(temp.env);
[1488]947 temp.flags = CheckExecutibleFlags(hwnd, 1);
[1321]948 if (fCancelAction){
949 fCancelAction = FALSE;
950 free(temp.pszCmdLine);
951 break;
952 }
953 else
[909]954 info = add_association(&temp);
[551]955 if (info) {
[1321]956 display_associations(hwnd, &temp, info);
[551]957 save_associations();
[1321]958 }
959 free(temp.pszCmdLine);
[2]960 }
[551]961 {
962 ASSOC temp;
[1519]963 CHAR dummy[34];
964 CHAR key[CCHMAXPATH];
[551]965
[1321]966 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
967 if (!temp.pszCmdLine)
968 break; //already complained
[551]969 WinSendDlgItemMsg(hwnd,
970 ASS_LISTBOX,
971 LM_SELECTITEM, MPFROMSHORT(y), MPFROMSHORT(TRUE));
[1321]972 memset(temp.sig, 0, sizeof(temp.sig));
973 memset(temp.mask, 0, sizeof(temp.mask));
974 temp.offset = 0;
[551]975 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
976 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
977 rstrip(temp.sig);
978 if (*temp.sig) {
979 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
980 temp.offset = atol(dummy);
981 }
[1519]982 //bstrip(temp.mask);
983 sprintf(key, "ASSOC.%senv", temp.pszCmdLine);
984 PrfWriteProfileString(fmprof, FM3Str, key, NULL);
[551]985 if (!kill_association(&temp))
986 Runtime_Error(pszSrcFile, __LINE__, "kill_association");
987 else {
988
989 if (y >= 0) {
990 WinSendDlgItemMsg(hwnd,
991 ASS_LISTBOX,
992 LM_DELETEITEM, MPFROMSHORT(y), MPVOID);
993 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_SELECTITEM,
994 MPFROMSHORT(x - 1), MPFROMSHORT(TRUE));
995 }
996 save_associations();
[1321]997 }
998 free(temp.pszCmdLine);
[551]999 }
1000 break;
1001 }
1002 return 0;
1003 }
1004 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]1005}
1006
[551]1007VOID EditAssociations(HWND hwnd)
[342]1008{
[2]1009 static CHAR stop = 0;
1010
[551]1011 if (stop)
[2]1012 return;
1013 stop++;
[551]1014 if (!assloaded)
[2]1015 load_associations();
[551]1016 WinDlgBox(HWND_DESKTOP, hwnd, AssocDlgProc, FM3ModHandle, ASS_FRAME, NULL);
[2]1017 stop = 0;
1018}
[793]1019
[1029]1020#pragma alloc_text(ASSOC2,free_associations,load_associations,save_associations,display_associations)
[793]1021#pragma alloc_text(ASSOC2,ExecAssociation,AssocTextProc)
1022#pragma alloc_text(ASSOC,add_association,kill_association,AssocDlgProc,EditAssociations)
Note: See TracBrowser for help on using the repository browser.