source: trunk/dll/assoc.c@ 907

Last change on this file since 907 was 907, checked in by Steven Levine, 18 years ago

Avoid out of memory traps in Compare Directories
Rework Compare Directories progress display for 2 second update rate
Start refactoring to reduce dependence on fm3dll.h
Add timer services (IsITimerExpired etc.)

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