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