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