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