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