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