source: trunk/dll/assoc.c@ 1203

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

Ticket 187: Move datadevlarations/definitions out of fm3dll.h

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