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