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