source: trunk/dll/assoc.c@ 1118

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

Clean up of fix for trap caused by FM/2 being on a full disk. It now preserves the data files. (Ticket 152, 271)

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