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