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