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