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