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