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