source: trunk/dll/assoc.c@ 1570

Last change on this file since 1570 was 1544, checked in by Gregg Young, 15 years ago

Changes to fopen and _fsopen to allow FM2 to be loaded in high memory

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