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