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