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