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