| [123] | 1 |  | 
|---|
|  | 2 | /*********************************************************************** | 
|---|
|  | 3 |  | 
|---|
|  | 4 | $Id: remap.c 1402 2009-03-14 17:17:59Z gyoung $ | 
|---|
|  | 5 |  | 
|---|
| [246] | 6 | Copyright (c) 1993, 1998 M. Kimes | 
|---|
| [1394] | 7 | Copyright (c) 2004, 2009 Steven H.Levine | 
|---|
| [123] | 8 |  | 
|---|
| [246] | 9 | 01 Aug 04 SHL Rework lstrip/rstrip usage | 
|---|
|  | 10 | 06 Aug 05 SHL Renames | 
|---|
| [353] | 11 | 22 Jul 06 SHL Check more run time errors | 
|---|
| [404] | 12 | 29 Jul 06 SHL Use xfgets | 
|---|
| [469] | 13 | 31 Aug 06 SHL Use _fsopen to avoid noise complaints | 
|---|
| [793] | 14 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat | 
|---|
| [985] | 15 | 29 Feb 08 GKY Use xfree where appropriate | 
|---|
| [1082] | 16 | 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory and use BldFullPathName | 
|---|
| [1119] | 17 | 24 Aug 08 GKY Warn full drive on save of .DAT file; prevent loss of existing file | 
|---|
| [123] | 18 |  | 
|---|
|  | 19 | ***********************************************************************/ | 
|---|
|  | 20 |  | 
|---|
| [2] | 21 | #include <stdlib.h> | 
|---|
|  | 22 | #include <string.h> | 
|---|
|  | 23 | #include <share.h> | 
|---|
| [689] | 24 | #include <io.h>                         // unlink | 
|---|
| [404] | 25 |  | 
|---|
| [907] | 26 | #define INCL_DOS | 
|---|
|  | 27 | #define INCL_WIN | 
|---|
|  | 28 | #define INCL_LONGLONG                   // dircnrs.h | 
|---|
|  | 29 |  | 
|---|
| [1187] | 30 | #include "fm3dll.h" | 
|---|
| [1226] | 31 | #include "fm3dll2.h"                    // #define's for UM_*, control id's, etc. | 
|---|
|  | 32 | #include "remap.h" | 
|---|
| [1212] | 33 | #include "arccnrs.h"                    // Data declaration(s) | 
|---|
|  | 34 | #include "mainwnd.h"                    // Data declaration(s) | 
|---|
|  | 35 | #include "notebook.h"                   // Data declaration(s) | 
|---|
|  | 36 | #include "info.h"                       // Data declaration(s) | 
|---|
|  | 37 | #include "init.h"                       // Data declaration(s) | 
|---|
|  | 38 | #include "newview.h"                    // Data declarations | 
|---|
| [2] | 39 | #include "fm3dlg.h" | 
|---|
|  | 40 | #include "fm3str.h" | 
|---|
| [907] | 41 | #include "errutil.h"                    // Dos_Error... | 
|---|
|  | 42 | #include "strutil.h"                    // GetPString | 
|---|
| [1082] | 43 | #include "pathutil.h"                   // BldFullPathName | 
|---|
| [1187] | 44 | #include "valid.h"                      // CheckDrive, FillInDriveFlags | 
|---|
|  | 45 | #include "wrappers.h"                   // xfgets | 
|---|
|  | 46 | #include "strips.h"                     // bstrip | 
|---|
|  | 47 | #include "misc.h"                       // CheckDriveSpaceAvail | 
|---|
|  | 48 | #include "systemf.h"                    // runemf2 | 
|---|
|  | 49 | #include "dirs.h"                       // save_dir2 | 
|---|
| [1039] | 50 | #include "fortify.h" | 
|---|
| [2] | 51 |  | 
|---|
|  | 52 | #pragma data_seg(DATA1) | 
|---|
| [353] | 53 |  | 
|---|
|  | 54 | static PSZ pszSrcFile = __FILE__; | 
|---|
|  | 55 |  | 
|---|
| [551] | 56 | typedef struct APPNOTIFY | 
|---|
|  | 57 | { | 
|---|
|  | 58 | HAPP happ; | 
|---|
|  | 59 | BOOL attach; | 
|---|
|  | 60 | BOOL failedonce; | 
|---|
|  | 61 | CHAR uncname[CCHMAXPATH]; | 
|---|
|  | 62 | CHAR device; | 
|---|
| [2] | 63 | struct APPNOTIFY *next; | 
|---|
|  | 64 | struct APPNOTIFY *prev; | 
|---|
| [551] | 65 | } | 
|---|
|  | 66 | APPNOTIFY; | 
|---|
| [2] | 67 |  | 
|---|
| [551] | 68 | typedef struct LINKRES | 
|---|
|  | 69 | { | 
|---|
|  | 70 | CHAR *res; | 
|---|
| [2] | 71 | struct LINKRES *next; | 
|---|
| [551] | 72 | } | 
|---|
|  | 73 | LINKRES; | 
|---|
| [2] | 74 |  | 
|---|
| [551] | 75 | static LINKRES *reshead = NULL; | 
|---|
|  | 76 | static BOOL loadedres = FALSE; | 
|---|
| [2] | 77 |  | 
|---|
|  | 78 | #define MAXNUMRES 200 | 
|---|
|  | 79 |  | 
|---|
| [551] | 80 | VOID load_resources(VOID) | 
|---|
| [353] | 81 | { | 
|---|
| [2] | 82 | /* load linked list of resources from RESOURCE.DAT file */ | 
|---|
|  | 83 |  | 
|---|
| [551] | 84 | FILE *fp; | 
|---|
|  | 85 | LINKRES *info, *last = NULL; | 
|---|
|  | 86 | CHAR s[CCHMAXPATH + 14]; | 
|---|
|  | 87 | INT x = 0; | 
|---|
| [2] | 88 |  | 
|---|
|  | 89 | loadedres = TRUE; | 
|---|
| [1398] | 90 | BldFullPathName(s, pFM2SaveDirectory, PCSZ_RESOURCEDAT); | 
|---|
| [551] | 91 | fp = _fsopen(s, "r", SH_DENYWR); | 
|---|
| [353] | 92 | if (fp) { | 
|---|
| [404] | 93 | while (x < MAXNUMRES && !feof(fp)) { | 
|---|
| [551] | 94 | if (!xfgets_bstripcr(s, sizeof(s), fp, pszSrcFile, __LINE__)) | 
|---|
|  | 95 | break; | 
|---|
| [404] | 96 | if (*s && *s != ';') { | 
|---|
| [551] | 97 | info = xmalloc(sizeof(LINKRES), pszSrcFile, __LINE__); | 
|---|
|  | 98 | if (info) { | 
|---|
|  | 99 | info->res = xstrdup(s, pszSrcFile, __LINE__); | 
|---|
|  | 100 | if (!info->res) | 
|---|
| [1039] | 101 | free(info); | 
|---|
| [353] | 102 | else { | 
|---|
| [551] | 103 | x++; | 
|---|
|  | 104 | info->next = NULL; | 
|---|
|  | 105 | if (!reshead) | 
|---|
|  | 106 | reshead = info; | 
|---|
|  | 107 | else | 
|---|
|  | 108 | last->next = info; | 
|---|
|  | 109 | last = info; | 
|---|
|  | 110 | } | 
|---|
|  | 111 | } | 
|---|
| [2] | 112 | } | 
|---|
|  | 113 | } | 
|---|
|  | 114 | fclose(fp); | 
|---|
|  | 115 | } | 
|---|
|  | 116 | } | 
|---|
|  | 117 |  | 
|---|
| [551] | 118 | VOID save_resources(VOID) | 
|---|
| [353] | 119 | { | 
|---|
| [2] | 120 | /* save linked list of resources to RESOURCE.DAT file */ | 
|---|
|  | 121 |  | 
|---|
|  | 122 | LINKRES *info; | 
|---|
| [551] | 123 | FILE *fp; | 
|---|
|  | 124 | CHAR s[CCHMAXPATH + 14]; | 
|---|
| [2] | 125 |  | 
|---|
| [551] | 126 | if (!loadedres) | 
|---|
| [2] | 127 | return; | 
|---|
| [1398] | 128 | BldFullPathName(s, pFM2SaveDirectory, PCSZ_RESOURCEDAT); | 
|---|
| [1118] | 129 | if (CheckDriveSpaceAvail(s, ullDATFileSpaceNeeded, 1) == 2) | 
|---|
| [1117] | 130 | return; //already gave error msg | 
|---|
| [551] | 131 | if (reshead) { | 
|---|
|  | 132 | fp = xfopen(s, "w", pszSrcFile, __LINE__); | 
|---|
| [353] | 133 | if (fp) { | 
|---|
| [551] | 134 | fputs(GetPString(IDS_REMOTEFILETEXT), fp); | 
|---|
| [2] | 135 | info = reshead; | 
|---|
| [353] | 136 | while (info) { | 
|---|
| [551] | 137 | fprintf(fp, "%0.*s\n", CCHMAXPATH, info->res); | 
|---|
|  | 138 | info = info->next; | 
|---|
| [2] | 139 | } | 
|---|
|  | 140 | fclose(fp); | 
|---|
|  | 141 | } | 
|---|
|  | 142 | } | 
|---|
|  | 143 | else | 
|---|
|  | 144 | unlink(s); | 
|---|
|  | 145 | } | 
|---|
|  | 146 |  | 
|---|
| [551] | 147 | BOOL add_resource(CHAR * res) | 
|---|
| [353] | 148 | { | 
|---|
| [551] | 149 | LINKRES *info, *last = NULL; | 
|---|
|  | 150 | INT x = 0; | 
|---|
| [2] | 151 |  | 
|---|
| [551] | 152 | if (!res || !*res) | 
|---|
| [2] | 153 | return FALSE; | 
|---|
| [551] | 154 | if (!loadedres) | 
|---|
| [2] | 155 | load_resources(); | 
|---|
|  | 156 | info = reshead; | 
|---|
| [551] | 157 | while (info) { | 
|---|
|  | 158 | if (!stricmp(info->res, res)) | 
|---|
| [2] | 159 | return FALSE; | 
|---|
|  | 160 | last = info; | 
|---|
|  | 161 | info = info->next; | 
|---|
|  | 162 | x++; | 
|---|
|  | 163 | } | 
|---|
| [551] | 164 | info = xmalloc(sizeof(LINKRES), pszSrcFile, __LINE__); | 
|---|
|  | 165 | if (info) { | 
|---|
|  | 166 | info->res = xstrdup(res, pszSrcFile, __LINE__); | 
|---|
| [353] | 167 | if (!info->res) | 
|---|
| [1039] | 168 | free(info); | 
|---|
| [353] | 169 | else { | 
|---|
| [2] | 170 | info->next = NULL; | 
|---|
| [551] | 171 | if (!reshead) | 
|---|
|  | 172 | reshead = info; | 
|---|
| [2] | 173 | else | 
|---|
| [551] | 174 | last->next = info; | 
|---|
|  | 175 | if (x > MAXNUMRES) { | 
|---|
|  | 176 | info = reshead; | 
|---|
|  | 177 | reshead = reshead->next; | 
|---|
| [1039] | 178 | free(info); | 
|---|
| [2] | 179 | } | 
|---|
|  | 180 | return TRUE; | 
|---|
|  | 181 | } | 
|---|
|  | 182 | } | 
|---|
|  | 183 | return FALSE; | 
|---|
|  | 184 | } | 
|---|
|  | 185 |  | 
|---|
| [551] | 186 | BOOL remove_resource(CHAR * res) | 
|---|
| [353] | 187 | { | 
|---|
| [551] | 188 | LINKRES *info, *last = NULL; | 
|---|
| [2] | 189 |  | 
|---|
| [551] | 190 | if (!res || !*res) | 
|---|
| [2] | 191 | return FALSE; | 
|---|
| [551] | 192 | if (!loadedres) | 
|---|
| [2] | 193 | load_resources(); | 
|---|
|  | 194 | info = reshead; | 
|---|
| [551] | 195 | while (info) { | 
|---|
|  | 196 | if (!stricmp(info->res, res)) { | 
|---|
|  | 197 | if (last) | 
|---|
|  | 198 | last->next = info->next; | 
|---|
| [2] | 199 | else | 
|---|
| [551] | 200 | reshead = info->next; | 
|---|
| [1009] | 201 | xfree(info->res, pszSrcFile, __LINE__); | 
|---|
| [1039] | 202 | free(info); | 
|---|
| [2] | 203 | return TRUE; | 
|---|
|  | 204 | } | 
|---|
|  | 205 | last = info; | 
|---|
|  | 206 | info = info->next; | 
|---|
|  | 207 | } | 
|---|
|  | 208 | return FALSE; | 
|---|
|  | 209 | } | 
|---|
|  | 210 |  | 
|---|
| [551] | 211 | VOID free_resources(VOID) | 
|---|
| [353] | 212 | { | 
|---|
| [551] | 213 | LINKRES *info, *next; | 
|---|
| [2] | 214 |  | 
|---|
|  | 215 | info = reshead; | 
|---|
| [551] | 216 | while (info) { | 
|---|
| [2] | 217 | next = info->next; | 
|---|
| [1009] | 218 | xfree(info->res, pszSrcFile, __LINE__); | 
|---|
| [1039] | 219 | free(info); | 
|---|
| [2] | 220 | info = next; | 
|---|
|  | 221 | } | 
|---|
|  | 222 | reshead = NULL; | 
|---|
|  | 223 | DosPostEventSem(CompactSem); | 
|---|
|  | 224 | } | 
|---|
|  | 225 |  | 
|---|
| [551] | 226 | MRESULT EXPENTRY RemapDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| [353] | 227 | { | 
|---|
| [2] | 228 | static BOOL fRemapped; | 
|---|
| [551] | 229 | static APPNOTIFY *apphead = NULL, *apptail = NULL; | 
|---|
| [2] | 230 |  | 
|---|
| [551] | 231 | switch (msg) { | 
|---|
|  | 232 | case WM_INITDLG: | 
|---|
|  | 233 | WinSendDlgItemMsg(hwnd, | 
|---|
|  | 234 | MAP_ATTACHTO, | 
|---|
|  | 235 | EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID); | 
|---|
|  | 236 | fRemapped = FALSE; | 
|---|
|  | 237 | if (!loadedres) | 
|---|
|  | 238 | load_resources(); | 
|---|
|  | 239 | { | 
|---|
|  | 240 | LINKRES *info; | 
|---|
| [2] | 241 |  | 
|---|
| [551] | 242 | info = reshead; | 
|---|
|  | 243 | while (info) { | 
|---|
|  | 244 | WinSendDlgItemMsg(hwnd, | 
|---|
|  | 245 | MAP_ATTACHTO, | 
|---|
|  | 246 | LM_INSERTITEM, | 
|---|
|  | 247 | MPFROM2SHORT(LIT_END, 0), MPFROMP(info->res)); | 
|---|
|  | 248 | info = info->next; | 
|---|
| [2] | 249 | } | 
|---|
| [551] | 250 | } | 
|---|
|  | 251 | { | 
|---|
|  | 252 | ULONG ulDriveMap, ulDriveNum, x, ulType; | 
|---|
|  | 253 | CHAR s[3] = " :"; | 
|---|
| [2] | 254 |  | 
|---|
| [551] | 255 | DosError(FERR_DISABLEHARDERR); | 
|---|
|  | 256 | if (!DosQCurDisk(&ulDriveNum, &ulDriveMap)) { | 
|---|
|  | 257 | for (x = 0; x < 26; x++) { | 
|---|
|  | 258 | if (!(driveflags[x] & DRIVE_IGNORE)) { | 
|---|
|  | 259 | *s = (CHAR) x + 'A'; | 
|---|
| [766] | 260 | if (!(ulDriveMap & (1 << x))) | 
|---|
| [551] | 261 | WinSendDlgItemMsg(hwnd, | 
|---|
|  | 262 | MAP_ATTACHLIST, | 
|---|
|  | 263 | LM_INSERTITEM, | 
|---|
|  | 264 | MPFROM2SHORT(LIT_END, 0), MPFROMP(s)); | 
|---|
|  | 265 | else { | 
|---|
|  | 266 | CheckDrive((CHAR) x + 'A', NULL, &ulType); | 
|---|
|  | 267 | if (ulType & DRIVE_REMOTE) | 
|---|
|  | 268 | WinSendDlgItemMsg(hwnd, | 
|---|
|  | 269 | MAP_DETACHLIST, | 
|---|
|  | 270 | LM_INSERTITEM, | 
|---|
|  | 271 | MPFROM2SHORT(LIT_END, 0), MPFROMP(s)); | 
|---|
|  | 272 | } | 
|---|
|  | 273 | } | 
|---|
|  | 274 | } | 
|---|
| [2] | 275 | } | 
|---|
| [551] | 276 | else | 
|---|
|  | 277 | WinDismissDlg(hwnd, 0); | 
|---|
|  | 278 | } | 
|---|
|  | 279 | break; | 
|---|
|  | 280 |  | 
|---|
|  | 281 | case WM_CONTROL: | 
|---|
|  | 282 | switch (SHORT1FROMMP(mp1)) { | 
|---|
|  | 283 | case MAP_ATTACHLIST: | 
|---|
|  | 284 | switch (SHORT2FROMMP(mp1)) { | 
|---|
|  | 285 | case LN_ENTER: | 
|---|
|  | 286 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(MAP_ATTACH, 0), MPVOID); | 
|---|
|  | 287 | break; | 
|---|
|  | 288 | } | 
|---|
| [2] | 289 | break; | 
|---|
| [551] | 290 | case MAP_DETACHLIST: | 
|---|
|  | 291 | switch (SHORT2FROMMP(mp1)) { | 
|---|
|  | 292 | case LN_ENTER: | 
|---|
|  | 293 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(MAP_DETACH, 0), MPVOID); | 
|---|
|  | 294 | break; | 
|---|
|  | 295 | case LN_SELECT: | 
|---|
|  | 296 | { | 
|---|
|  | 297 | SHORT x; | 
|---|
|  | 298 | CHAR d[3]; | 
|---|
| [2] | 299 |  | 
|---|
| [551] | 300 | WinSetDlgItemText(hwnd, MAP_ATTACHTO, NullStr); | 
|---|
|  | 301 | x = (SHORT) WinSendDlgItemMsg(hwnd, | 
|---|
|  | 302 | MAP_DETACHLIST, | 
|---|
|  | 303 | LM_QUERYSELECTION, | 
|---|
|  | 304 | MPFROMSHORT(LIT_FIRST), MPVOID); | 
|---|
|  | 305 | if (x >= 0) { | 
|---|
|  | 306 | *d = 0; | 
|---|
|  | 307 | WinSendDlgItemMsg(hwnd, | 
|---|
|  | 308 | MAP_DETACHLIST, | 
|---|
|  | 309 | LM_QUERYITEMTEXT, | 
|---|
|  | 310 | MPFROM2SHORT(x, sizeof(d)), MPFROMP(d)); | 
|---|
|  | 311 | if (*d) { | 
|---|
| [2] | 312 |  | 
|---|
| [551] | 313 | CHAR buf[2048]; | 
|---|
|  | 314 | ULONG len; | 
|---|
|  | 315 | APIRET rc; | 
|---|
|  | 316 | FSQBUFFER2 *p2; | 
|---|
| [2] | 317 |  | 
|---|
| [551] | 318 | memset(buf, 0, sizeof(buf)); | 
|---|
|  | 319 | len = sizeof(buf); | 
|---|
|  | 320 | p2 = (FSQBUFFER2 *) buf; | 
|---|
|  | 321 | DosError(FERR_DISABLEHARDERR); | 
|---|
|  | 322 | rc = DosQueryFSAttach(d, 0, FSAIL_QUERYNAME, p2, &len); | 
|---|
|  | 323 | if (!rc) { | 
|---|
| [2] | 324 |  | 
|---|
| [551] | 325 | CHAR *p; | 
|---|
| [2] | 326 |  | 
|---|
| [551] | 327 | p = (char *)p2->szName; | 
|---|
|  | 328 | p += p2->cbName + 1; | 
|---|
|  | 329 | p += p2->cbFSDName + 1; | 
|---|
|  | 330 | if (p2->cbFSAData) | 
|---|
|  | 331 | WinSetDlgItemText(hwnd, MAP_ATTACHTO, p); | 
|---|
|  | 332 | else | 
|---|
|  | 333 | WinSetDlgItemText(hwnd, | 
|---|
|  | 334 | MAP_ATTACHTO, | 
|---|
|  | 335 | GetPString(IDS_UNKNOWNBRKTTEXT)); | 
|---|
|  | 336 | } | 
|---|
|  | 337 | else | 
|---|
|  | 338 | WinSetDlgItemText(hwnd, | 
|---|
|  | 339 | MAP_ATTACHTO, | 
|---|
|  | 340 | GetPString(IDS_UNKNOWNBRKTTEXT)); | 
|---|
|  | 341 | } | 
|---|
|  | 342 | } | 
|---|
|  | 343 | } | 
|---|
|  | 344 | break; | 
|---|
| [2] | 345 | } | 
|---|
|  | 346 | break; | 
|---|
| [551] | 347 | } | 
|---|
|  | 348 | break; | 
|---|
| [2] | 349 |  | 
|---|
| [551] | 350 | case WM_APPTERMINATENOTIFY: | 
|---|
|  | 351 | { | 
|---|
|  | 352 | APPNOTIFY *info; | 
|---|
|  | 353 | SHORT x, c; | 
|---|
|  | 354 | CHAR d[3]; | 
|---|
|  | 355 | HWND hwndList; | 
|---|
| [2] | 356 |  | 
|---|
| [551] | 357 | if (!mp2) | 
|---|
|  | 358 | fRemapped = TRUE; | 
|---|
|  | 359 | info = apphead; | 
|---|
|  | 360 | GetRidOfIt: | 
|---|
|  | 361 | while (info) { | 
|---|
|  | 362 | if (info->happ == (HAPP) mp1) { | 
|---|
| [2] | 363 | /* Note:  if this next line is removed, FM/2 will start the attach/detach | 
|---|
|  | 364 | * request again, once for each request, to see if it might succeed and to | 
|---|
|  | 365 | * ensure the request is seen by the user in case interaction is required. | 
|---|
|  | 366 | */ | 
|---|
| [551] | 367 | info->failedonce = TRUE; | 
|---|
|  | 368 | hwndList = WinWindowFromID(hwnd, | 
|---|
|  | 369 | (info->attach) ? | 
|---|
|  | 370 | MAP_ATTACHLIST : MAP_DETACHLIST); | 
|---|
|  | 371 | if (!mp2 || (ULONG) mp2 == 1041 || info->failedonce) { | 
|---|
|  | 372 | if (info->prev) | 
|---|
|  | 373 | info->prev->next = info->next; | 
|---|
|  | 374 | if (info->next) | 
|---|
|  | 375 | info->next->prev = info->prev; | 
|---|
|  | 376 | if (apphead == info) | 
|---|
|  | 377 | apphead = info->next; | 
|---|
|  | 378 | if (apptail == info) | 
|---|
|  | 379 | apptail = info->prev; | 
|---|
|  | 380 | } | 
|---|
|  | 381 | if (!mp2) { | 
|---|
|  | 382 | if (*info->uncname && | 
|---|
|  | 383 | stricmp(info->uncname, GetPString(IDS_UNKNOWNBRKTTEXT)) && | 
|---|
|  | 384 | add_resource(info->uncname)) { | 
|---|
|  | 385 | save_resources(); | 
|---|
|  | 386 | WinSendDlgItemMsg(hwnd, | 
|---|
|  | 387 | MAP_ATTACHTO, | 
|---|
|  | 388 | LM_INSERTITEM, | 
|---|
|  | 389 | MPFROM2SHORT(LIT_END, 0), | 
|---|
|  | 390 | MPFROMP(info->uncname)); | 
|---|
|  | 391 | } | 
|---|
|  | 392 | c = (SHORT) WinSendMsg(hwndList, | 
|---|
|  | 393 | LM_QUERYITEMCOUNT, MPVOID, MPVOID); | 
|---|
|  | 394 | if (c > 0) { | 
|---|
|  | 395 | for (x = 0; x < c; x++) { | 
|---|
|  | 396 | *d = 0; | 
|---|
|  | 397 | WinSendMsg(hwndList, | 
|---|
|  | 398 | LM_QUERYITEMTEXT, | 
|---|
|  | 399 | MPFROM2SHORT(x, sizeof(d)), MPFROMP(d)); | 
|---|
|  | 400 | if (*d == info->device) { | 
|---|
|  | 401 | WinSendMsg(hwndList, LM_DELETEITEM, MPFROMSHORT(x), MPVOID); | 
|---|
|  | 402 | hwndList = WinWindowFromID(hwnd, | 
|---|
|  | 403 | (info->attach) ? | 
|---|
|  | 404 | MAP_DETACHLIST : MAP_ATTACHLIST); | 
|---|
|  | 405 | d[1] = ':'; | 
|---|
|  | 406 | d[2] = 0; | 
|---|
|  | 407 | WinSendMsg(hwndList, | 
|---|
|  | 408 | LM_INSERTITEM, | 
|---|
|  | 409 | MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(d)); | 
|---|
|  | 410 | break; | 
|---|
|  | 411 | } | 
|---|
|  | 412 | } | 
|---|
|  | 413 | } | 
|---|
|  | 414 | } | 
|---|
|  | 415 | else if ((ULONG) mp2 != 1041 && !info->failedonce) { | 
|---|
| [2] | 416 |  | 
|---|
| [551] | 417 | PROGDETAILS pgd; | 
|---|
|  | 418 | CHAR params[368], *p; | 
|---|
|  | 419 | HAPP happ; | 
|---|
| [2] | 420 |  | 
|---|
| [551] | 421 | *d = info->device; | 
|---|
|  | 422 | d[1] = ':'; | 
|---|
|  | 423 | d[2] = 0; | 
|---|
|  | 424 | p = GetCmdSpec(FALSE); | 
|---|
|  | 425 | memset(&pgd, 0, sizeof(pgd)); | 
|---|
|  | 426 | pgd.Length = sizeof(pgd); | 
|---|
|  | 427 | pgd.progt.progc = PROG_WINDOWABLEVIO; | 
|---|
|  | 428 | pgd.progt.fbVisible = SHE_VISIBLE; | 
|---|
| [1394] | 429 | pgd.pszTitle = info->attach ? (PSZ)GetPString(IDS_ATTACHREQTEXT) : | 
|---|
|  | 430 | (PSZ)GetPString(IDS_DETACHREQTEXT); | 
|---|
| [551] | 431 | pgd.pszExecutable = p; | 
|---|
|  | 432 | pgd.pszParameters = params; | 
|---|
|  | 433 | pgd.pszStartupDir = NULL; | 
|---|
|  | 434 | pgd.pszIcon = NULL; | 
|---|
|  | 435 | pgd.pszEnvironment = NULL; | 
|---|
|  | 436 | pgd.swpInitial.hwndInsertBehind = HWND_TOP; | 
|---|
|  | 437 | pgd.swpInitial.hwnd = hwnd; | 
|---|
|  | 438 | pgd.swpInitial.fl = SWP_SHOW | SWP_ACTIVATE; | 
|---|
|  | 439 | if (info->attach) | 
|---|
|  | 440 | sprintf(params, "/C NET USE %s \"%s\"", d, info->uncname); | 
|---|
|  | 441 | else | 
|---|
|  | 442 | sprintf(params, "/C NET USE %s /D", d); | 
|---|
|  | 443 | info->failedonce = TRUE; | 
|---|
|  | 444 | happ = WinStartApp(hwnd, &pgd, pgd.pszParameters, | 
|---|
|  | 445 | NULL, SAF_MAXIMIZED); | 
|---|
|  | 446 | if (!happ) | 
|---|
|  | 447 | goto GetRidOfIt; | 
|---|
|  | 448 | info->happ = happ; | 
|---|
|  | 449 | break; | 
|---|
|  | 450 | } | 
|---|
|  | 451 | else if ((ULONG) mp2 == 1041) | 
|---|
|  | 452 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION, hwnd, | 
|---|
|  | 453 | GetPString(IDS_ERRORTEXT), | 
|---|
| [1402] | 454 | GetPString(IDS_CANTSTARTNETUSETEXT)); | 
|---|
| [551] | 455 | if (!mp2 || (ULONG) mp2 == 1041 || info->failedonce) | 
|---|
| [1039] | 456 | free(info); | 
|---|
| [551] | 457 | break; | 
|---|
|  | 458 | } | 
|---|
|  | 459 | info = info->next; | 
|---|
| [2] | 460 | } | 
|---|
| [551] | 461 | } | 
|---|
|  | 462 | break; | 
|---|
| [2] | 463 |  | 
|---|
| [551] | 464 | case WM_COMMAND: | 
|---|
|  | 465 | switch (SHORT1FROMMP(mp1)) { | 
|---|
|  | 466 | case MAP_DELETE: | 
|---|
|  | 467 | { | 
|---|
|  | 468 | SHORT x; | 
|---|
|  | 469 | CHAR resource[CCHMAXPATH]; | 
|---|
| [2] | 470 |  | 
|---|
| [551] | 471 | x = (SHORT) WinSendDlgItemMsg(hwnd, | 
|---|
|  | 472 | MAP_ATTACHTO, | 
|---|
|  | 473 | LM_QUERYSELECTION, | 
|---|
|  | 474 | MPFROMSHORT(LIT_FIRST), MPVOID); | 
|---|
|  | 475 | if (x >= 0) { | 
|---|
|  | 476 | *resource = 0; | 
|---|
|  | 477 | WinSendDlgItemMsg(hwnd, | 
|---|
|  | 478 | MAP_ATTACHTO, | 
|---|
|  | 479 | LM_QUERYITEMTEXT, | 
|---|
|  | 480 | MPFROM2SHORT(x, sizeof(resource)), | 
|---|
|  | 481 | MPFROMP(resource)); | 
|---|
|  | 482 | bstrip(resource); | 
|---|
|  | 483 | if (*resource) { | 
|---|
|  | 484 | if (remove_resource(resource)) { | 
|---|
|  | 485 | save_resources(); | 
|---|
|  | 486 | WinSendDlgItemMsg(hwnd, | 
|---|
|  | 487 | MAP_ATTACHTO, | 
|---|
|  | 488 | LM_DELETEITEM, MPFROMSHORT(x), MPVOID); | 
|---|
|  | 489 | if (x) | 
|---|
|  | 490 | x--; | 
|---|
|  | 491 | WinSendDlgItemMsg(hwnd, | 
|---|
|  | 492 | MAP_ATTACHTO, | 
|---|
|  | 493 | LM_SELECTITEM, | 
|---|
|  | 494 | MPFROMSHORT(x), MPFROMSHORT(TRUE)); | 
|---|
|  | 495 | if (!(SHORT) WinSendDlgItemMsg(hwnd, | 
|---|
|  | 496 | MAP_ATTACHTO, | 
|---|
|  | 497 | LM_QUERYITEMCOUNT, | 
|---|
|  | 498 | MPVOID, MPVOID)) | 
|---|
|  | 499 | WinSetDlgItemText(hwnd, MAP_ATTACHTO, NullStr); | 
|---|
|  | 500 | } | 
|---|
|  | 501 | } | 
|---|
|  | 502 | } | 
|---|
|  | 503 | } | 
|---|
|  | 504 | break; | 
|---|
| [2] | 505 |  | 
|---|
| [551] | 506 | case MAP_CLEAR: | 
|---|
|  | 507 | free_resources(); | 
|---|
|  | 508 | save_resources(); | 
|---|
|  | 509 | WinSendDlgItemMsg(hwnd, MAP_ATTACHTO, LM_DELETEALL, MPVOID, MPVOID); | 
|---|
|  | 510 | WinSetDlgItemText(hwnd, MAP_ATTACHTO, NullStr); | 
|---|
|  | 511 | break; | 
|---|
| [2] | 512 |  | 
|---|
| [551] | 513 | case MAP_INFO: | 
|---|
|  | 514 | case MAP_DETACH: | 
|---|
|  | 515 | { | 
|---|
|  | 516 | CHAR d[3], s[CCHMAXPATH]; | 
|---|
|  | 517 | SHORT x; | 
|---|
| [2] | 518 |  | 
|---|
| [551] | 519 | *s = 0; | 
|---|
|  | 520 | WinQueryDlgItemText(hwnd, MAP_ATTACHTO, sizeof(s), s); | 
|---|
|  | 521 | bstrip(s); | 
|---|
|  | 522 | x = (SHORT) WinSendDlgItemMsg(hwnd, | 
|---|
|  | 523 | MAP_DETACHLIST, | 
|---|
|  | 524 | LM_QUERYSELECTION, | 
|---|
|  | 525 | MPFROMSHORT(LIT_FIRST), MPVOID); | 
|---|
|  | 526 | if (x >= 0) { | 
|---|
|  | 527 | *d = 0; | 
|---|
|  | 528 | WinSendDlgItemMsg(hwnd, | 
|---|
|  | 529 | MAP_DETACHLIST, | 
|---|
|  | 530 | LM_QUERYITEMTEXT, | 
|---|
|  | 531 | MPFROM2SHORT(x, sizeof(d)), MPFROMP(d)); | 
|---|
|  | 532 | if (*d) { | 
|---|
|  | 533 | switch (SHORT1FROMMP(mp1)) { | 
|---|
|  | 534 | case MAP_DETACH: | 
|---|
|  | 535 | { | 
|---|
|  | 536 | PROGDETAILS pgd; | 
|---|
|  | 537 | CHAR params[368], *p; | 
|---|
|  | 538 | HAPP happ; | 
|---|
| [2] | 539 |  | 
|---|
| [551] | 540 | p = GetCmdSpec(FALSE); | 
|---|
|  | 541 | memset(&pgd, 0, sizeof(pgd)); | 
|---|
|  | 542 | pgd.Length = sizeof(pgd); | 
|---|
|  | 543 | pgd.progt.progc = PROG_WINDOWABLEVIO; | 
|---|
|  | 544 | pgd.progt.fbVisible = SHE_VISIBLE; | 
|---|
| [1394] | 545 | pgd.pszTitle = (PSZ)GetPString(IDS_DETACHREQTEXT); | 
|---|
| [551] | 546 | pgd.pszExecutable = p; | 
|---|
|  | 547 | pgd.pszParameters = params; | 
|---|
|  | 548 | pgd.pszStartupDir = NULL; | 
|---|
|  | 549 | pgd.pszIcon = NULL; | 
|---|
|  | 550 | pgd.pszEnvironment = NULL; | 
|---|
|  | 551 | pgd.swpInitial.hwndInsertBehind = HWND_TOP; | 
|---|
|  | 552 | pgd.swpInitial.hwnd = hwnd; | 
|---|
|  | 553 | pgd.swpInitial.fl = SWP_SHOW | SWP_ACTIVATE; | 
|---|
|  | 554 | sprintf(params, "/C NET USE %s /D", d); | 
|---|
|  | 555 | happ = WinStartApp(hwnd, | 
|---|
|  | 556 | &pgd, | 
|---|
|  | 557 | pgd.pszParameters, NULL, SAF_MAXIMIZED); | 
|---|
|  | 558 | if (happ) { | 
|---|
| [2] | 559 |  | 
|---|
| [551] | 560 | APPNOTIFY *info; | 
|---|
| [2] | 561 |  | 
|---|
| [551] | 562 | WinSetDlgItemText(hwnd, MAP_ATTACHTO, NullStr); | 
|---|
|  | 563 | info = xmallocz(sizeof(APPNOTIFY), pszSrcFile, __LINE__); | 
|---|
|  | 564 | if (info) { | 
|---|
|  | 565 | info->happ = happ; | 
|---|
|  | 566 | info->attach = FALSE; | 
|---|
|  | 567 | info->failedonce = FALSE; | 
|---|
|  | 568 | strcpy(info->uncname, s); | 
|---|
|  | 569 | info->device = *d; | 
|---|
|  | 570 | if (!apphead) | 
|---|
|  | 571 | apphead = info; | 
|---|
|  | 572 | else { | 
|---|
|  | 573 | apptail->next = info; | 
|---|
|  | 574 | info->prev = apptail; | 
|---|
|  | 575 | } | 
|---|
|  | 576 | apptail = info; | 
|---|
|  | 577 | } | 
|---|
|  | 578 | } | 
|---|
|  | 579 | else | 
|---|
|  | 580 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION, | 
|---|
|  | 581 | hwnd, | 
|---|
|  | 582 | GetPString(IDS_ERRORTEXT), | 
|---|
|  | 583 | GetPString(IDS_CANTSTARTTEXT), p, params); | 
|---|
|  | 584 | } | 
|---|
| [353] | 585 | #ifdef NEVER                            // fixme to be gone? | 
|---|
| [551] | 586 | DosError(FERR_DISABLEHARDERR); | 
|---|
|  | 587 | rc = DosFSAttach(d, s, d, strlen(d) + 1, FS_DETACH); | 
|---|
|  | 588 | if (rc) { | 
|---|
|  | 589 | Dos_Error(MB_CANCEL, | 
|---|
|  | 590 | rc, | 
|---|
|  | 591 | hwnd, | 
|---|
|  | 592 | pszSrcFile, | 
|---|
|  | 593 | __LINE__, GetPString(IDS_DETACHFAILEDTEXT), d, s); | 
|---|
|  | 594 | } | 
|---|
|  | 595 | else { | 
|---|
|  | 596 | fRemapped = TRUE; | 
|---|
|  | 597 | WinSendDlgItemMsg(hwnd, | 
|---|
|  | 598 | MAP_DETACHLIST, | 
|---|
|  | 599 | LM_DELETEITEM, MPFROMSHORT(x), MPVOID); | 
|---|
|  | 600 | WinSendDlgItemMsg(hwnd, | 
|---|
|  | 601 | MAP_ATTACHLIST, | 
|---|
|  | 602 | LM_INSERTITEM, | 
|---|
|  | 603 | MPFROM2SHORT(LIT_SORTASCENDING, 0), | 
|---|
|  | 604 | MPFROMP(d)); | 
|---|
|  | 605 | } | 
|---|
|  | 606 | #endif // fixme to be gone? | 
|---|
|  | 607 | break; | 
|---|
| [2] | 608 |  | 
|---|
| [551] | 609 | case MAP_INFO: | 
|---|
|  | 610 | runemf2(SEPARATEKEEP | WINDOWED | MAXIMIZED, | 
|---|
| [888] | 611 | hwnd, pszSrcFile, __LINE__, | 
|---|
| [551] | 612 | NULL, NULL, "%s /C NET USE %s", GetCmdSpec(FALSE), d); | 
|---|
|  | 613 | break; | 
|---|
|  | 614 | } | 
|---|
|  | 615 | } | 
|---|
|  | 616 | } | 
|---|
|  | 617 | } | 
|---|
|  | 618 | break; | 
|---|
| [2] | 619 |  | 
|---|
| [551] | 620 | case MAP_ATTACH: | 
|---|
|  | 621 | { | 
|---|
|  | 622 | CHAR d[3], s[CCHMAXPATH]; | 
|---|
|  | 623 | SHORT x; | 
|---|
| [2] | 624 |  | 
|---|
| [551] | 625 | *s = 0; | 
|---|
|  | 626 | WinQueryDlgItemText(hwnd, MAP_ATTACHTO, sizeof(s), s); | 
|---|
|  | 627 | bstrip(s); | 
|---|
|  | 628 | if (*s) { | 
|---|
|  | 629 | x = (SHORT) WinSendDlgItemMsg(hwnd, | 
|---|
|  | 630 | MAP_ATTACHLIST, | 
|---|
|  | 631 | LM_QUERYSELECTION, | 
|---|
|  | 632 | MPFROMSHORT(LIT_FIRST), MPVOID); | 
|---|
|  | 633 | if (x >= 0) { | 
|---|
|  | 634 | *d = 0; | 
|---|
|  | 635 | WinSendDlgItemMsg(hwnd, | 
|---|
|  | 636 | MAP_ATTACHLIST, | 
|---|
|  | 637 | LM_QUERYITEMTEXT, | 
|---|
|  | 638 | MPFROM2SHORT(x, sizeof(d)), MPFROMP(d)); | 
|---|
|  | 639 | if (*d) { | 
|---|
| [2] | 640 |  | 
|---|
| [551] | 641 | PROGDETAILS pgd; | 
|---|
|  | 642 | CHAR params[368], *p; | 
|---|
|  | 643 | HAPP happ; | 
|---|
| [2] | 644 |  | 
|---|
| [551] | 645 | p = GetCmdSpec(FALSE); | 
|---|
|  | 646 | memset(&pgd, 0, sizeof(pgd)); | 
|---|
|  | 647 | pgd.Length = sizeof(pgd); | 
|---|
|  | 648 | pgd.progt.progc = PROG_WINDOWABLEVIO; | 
|---|
|  | 649 | pgd.progt.fbVisible = SHE_VISIBLE; | 
|---|
| [1394] | 650 | pgd.pszTitle = (PSZ)GetPString(IDS_ATTACHREQTEXT); | 
|---|
| [551] | 651 | pgd.pszExecutable = p; | 
|---|
|  | 652 | pgd.pszParameters = params; | 
|---|
|  | 653 | pgd.pszStartupDir = NULL; | 
|---|
|  | 654 | pgd.pszIcon = NULL; | 
|---|
|  | 655 | pgd.pszEnvironment = NULL; | 
|---|
|  | 656 | pgd.swpInitial.hwndInsertBehind = HWND_TOP; | 
|---|
|  | 657 | pgd.swpInitial.hwnd = hwnd; | 
|---|
|  | 658 | pgd.swpInitial.fl = SWP_SHOW | SWP_ACTIVATE; | 
|---|
|  | 659 | sprintf(params, "/C NET USE %s \"%s\"", d, s); | 
|---|
|  | 660 | happ = WinStartApp(hwnd, | 
|---|
|  | 661 | &pgd, | 
|---|
|  | 662 | pgd.pszParameters, NULL, SAF_MAXIMIZED); | 
|---|
|  | 663 | if (happ) { | 
|---|
| [2] | 664 |  | 
|---|
| [551] | 665 | APPNOTIFY *info; | 
|---|
| [2] | 666 |  | 
|---|
| [551] | 667 | info = xmallocz(sizeof(APPNOTIFY), pszSrcFile, __LINE__); | 
|---|
|  | 668 | if (info) { | 
|---|
|  | 669 | info->happ = happ; | 
|---|
|  | 670 | info->attach = TRUE; | 
|---|
|  | 671 | info->failedonce = FALSE; | 
|---|
|  | 672 | strcpy(info->uncname, s); | 
|---|
|  | 673 | info->device = *d; | 
|---|
|  | 674 | if (!apphead) | 
|---|
|  | 675 | apphead = info; | 
|---|
|  | 676 | else { | 
|---|
|  | 677 | apptail->next = info; | 
|---|
|  | 678 | info->prev = apptail; | 
|---|
|  | 679 | } | 
|---|
|  | 680 | apptail = info; | 
|---|
|  | 681 | } | 
|---|
|  | 682 | } | 
|---|
|  | 683 | else | 
|---|
|  | 684 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION, | 
|---|
|  | 685 | hwnd, | 
|---|
|  | 686 | GetPString(IDS_ERRORTEXT), | 
|---|
|  | 687 | GetPString(IDS_CANTSTARTTEXT), p, params); | 
|---|
| [353] | 688 | #ifdef NEVER                            // fixme to be gone? | 
|---|
| [551] | 689 | DosError(FERR_DISABLEHARDERR); | 
|---|
|  | 690 | rc = DosFSAttach(d, s, s, strlen(s) + 1, FS_ATTACH); | 
|---|
|  | 691 | if (rc) { | 
|---|
|  | 692 | Dos_Error(MB_CANCEL, | 
|---|
|  | 693 | rc, | 
|---|
|  | 694 | hwnd, | 
|---|
|  | 695 | pszSrcFile, | 
|---|
|  | 696 | __LINE__, GetPString(IDS_ATTACHFAILEDTEXT), s, d); | 
|---|
|  | 697 | } | 
|---|
|  | 698 | else { | 
|---|
|  | 699 | fRemapped = TRUE; | 
|---|
|  | 700 | WinSendDlgItemMsg(hwnd, | 
|---|
|  | 701 | MAP_ATTACHLIST, | 
|---|
|  | 702 | LM_DELETEITEM, MPFROMSHORT(x), MPVOID); | 
|---|
|  | 703 | WinSendDlgItemMsg(hwnd, | 
|---|
|  | 704 | MAP_DETACHLIST, | 
|---|
|  | 705 | LM_INSERTITEM, | 
|---|
|  | 706 | MPFROM2SHORT(LIT_SORTASCENDING, 0), | 
|---|
|  | 707 | MPFROMP(d)); | 
|---|
|  | 708 | } | 
|---|
|  | 709 | #endif // fixme to be gone? | 
|---|
|  | 710 | } | 
|---|
|  | 711 | } | 
|---|
|  | 712 | } | 
|---|
|  | 713 | } | 
|---|
|  | 714 | break; | 
|---|
| [2] | 715 |  | 
|---|
| [551] | 716 | case IDM_HELP: | 
|---|
|  | 717 | if (hwndHelp) | 
|---|
|  | 718 | WinSendMsg(hwndHelp, | 
|---|
|  | 719 | HM_DISPLAY_HELP, | 
|---|
|  | 720 | MPFROM2SHORT(HELP_REMAP, 0), MPFROMSHORT(HM_RESOURCEID)); | 
|---|
|  | 721 | break; | 
|---|
| [2] | 722 |  | 
|---|
| [551] | 723 | case DID_CANCEL: | 
|---|
|  | 724 | if (fRemapped) { | 
|---|
|  | 725 | if (hwndTree) | 
|---|
|  | 726 | PostMsg(hwndTree, WM_COMMAND, MPFROM2SHORT(IDM_RESCAN, 0), MPVOID); | 
|---|
|  | 727 | else | 
|---|
|  | 728 | FillInDriveFlags(NULL); | 
|---|
|  | 729 | if (hwndMain) | 
|---|
|  | 730 | PostMsg(hwndMain, UM_BUILDDRIVEBAR, MPVOID, MPVOID); | 
|---|
| [2] | 731 | } | 
|---|
| [551] | 732 | WinDismissDlg(hwnd, 0); | 
|---|
|  | 733 | break; | 
|---|
|  | 734 | } | 
|---|
|  | 735 | return 0; | 
|---|
| [2] | 736 |  | 
|---|
| [551] | 737 | case WM_DESTROY: | 
|---|
|  | 738 | if (apphead) { | 
|---|
| [2] | 739 |  | 
|---|
| [551] | 740 | APPNOTIFY *info, *next; | 
|---|
| [2] | 741 |  | 
|---|
| [551] | 742 | info = apphead; | 
|---|
|  | 743 | while (info) { | 
|---|
|  | 744 | next = info->next; | 
|---|
| [1039] | 745 | free(info); | 
|---|
| [551] | 746 | info = next; | 
|---|
| [2] | 747 | } | 
|---|
| [551] | 748 | apphead = apptail = NULL; | 
|---|
|  | 749 | saymsg(MB_YESNOCANCEL, | 
|---|
|  | 750 | HWND_DESKTOP, | 
|---|
|  | 751 | GetPString(IDS_NOTICETITLETEXT), | 
|---|
| [1402] | 752 | GetPString(IDS_REMAPNOTICETEXT)); | 
|---|
| [551] | 753 | } | 
|---|
|  | 754 | free_resources(); | 
|---|
|  | 755 | loadedres = FALSE; | 
|---|
|  | 756 | break; | 
|---|
| [2] | 757 | } | 
|---|
| [551] | 758 | return WinDefDlgProc(hwnd, msg, mp1, mp2); | 
|---|
| [2] | 759 | } | 
|---|
| [793] | 760 |  | 
|---|
|  | 761 | #pragma alloc_text(FMREMAP,RemapDlgProc,load_resources,save_resources) | 
|---|
|  | 762 | #pragma alloc_text(FMREMAP,add_resource,remove_resource,free_resources) | 
|---|