[123] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: remap.c 1544 2010-09-30 13:00:59Z 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;
|
---|
[1544] | 89 | CHAR *moder = "r";
|
---|
[2] | 90 |
|
---|
| 91 | loadedres = TRUE;
|
---|
[1398] | 92 | BldFullPathName(s, pFM2SaveDirectory, PCSZ_RESOURCEDAT);
|
---|
[1544] | 93 | fp = xfsopen(s, moder, SH_DENYWR, pszSrcFile, __LINE__, TRUE);
|
---|
[353] | 94 | if (fp) {
|
---|
[404] | 95 | while (x < MAXNUMRES && !feof(fp)) {
|
---|
[551] | 96 | if (!xfgets_bstripcr(s, sizeof(s), fp, pszSrcFile, __LINE__))
|
---|
| 97 | break;
|
---|
[404] | 98 | if (*s && *s != ';') {
|
---|
[551] | 99 | info = xmalloc(sizeof(LINKRES), pszSrcFile, __LINE__);
|
---|
| 100 | if (info) {
|
---|
| 101 | info->res = xstrdup(s, pszSrcFile, __LINE__);
|
---|
| 102 | if (!info->res)
|
---|
[1039] | 103 | free(info);
|
---|
[353] | 104 | else {
|
---|
[551] | 105 | x++;
|
---|
| 106 | info->next = NULL;
|
---|
| 107 | if (!reshead)
|
---|
| 108 | reshead = info;
|
---|
| 109 | else
|
---|
| 110 | last->next = info;
|
---|
| 111 | last = info;
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
[2] | 114 | }
|
---|
| 115 | }
|
---|
| 116 | fclose(fp);
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[551] | 120 | VOID save_resources(VOID)
|
---|
[353] | 121 | {
|
---|
[2] | 122 | /* save linked list of resources to RESOURCE.DAT file */
|
---|
| 123 |
|
---|
| 124 | LINKRES *info;
|
---|
[551] | 125 | FILE *fp;
|
---|
| 126 | CHAR s[CCHMAXPATH + 14];
|
---|
[1544] | 127 | CHAR *modew = "w";
|
---|
[2] | 128 |
|
---|
[551] | 129 | if (!loadedres)
|
---|
[2] | 130 | return;
|
---|
[1398] | 131 | BldFullPathName(s, pFM2SaveDirectory, PCSZ_RESOURCEDAT);
|
---|
[1118] | 132 | if (CheckDriveSpaceAvail(s, ullDATFileSpaceNeeded, 1) == 2)
|
---|
[1117] | 133 | return; //already gave error msg
|
---|
[551] | 134 | if (reshead) {
|
---|
[1544] | 135 | fp = xfopen(s, modew, pszSrcFile, __LINE__, FALSE);
|
---|
[353] | 136 | if (fp) {
|
---|
[551] | 137 | fputs(GetPString(IDS_REMOTEFILETEXT), fp);
|
---|
[2] | 138 | info = reshead;
|
---|
[353] | 139 | while (info) {
|
---|
[551] | 140 | fprintf(fp, "%0.*s\n", CCHMAXPATH, info->res);
|
---|
| 141 | info = info->next;
|
---|
[2] | 142 | }
|
---|
| 143 | fclose(fp);
|
---|
| 144 | }
|
---|
| 145 | }
|
---|
| 146 | else
|
---|
| 147 | unlink(s);
|
---|
| 148 | }
|
---|
| 149 |
|
---|
[551] | 150 | BOOL add_resource(CHAR * res)
|
---|
[353] | 151 | {
|
---|
[551] | 152 | LINKRES *info, *last = NULL;
|
---|
| 153 | INT x = 0;
|
---|
[2] | 154 |
|
---|
[551] | 155 | if (!res || !*res)
|
---|
[2] | 156 | return FALSE;
|
---|
[551] | 157 | if (!loadedres)
|
---|
[2] | 158 | load_resources();
|
---|
| 159 | info = reshead;
|
---|
[551] | 160 | while (info) {
|
---|
| 161 | if (!stricmp(info->res, res))
|
---|
[2] | 162 | return FALSE;
|
---|
| 163 | last = info;
|
---|
| 164 | info = info->next;
|
---|
| 165 | x++;
|
---|
| 166 | }
|
---|
[551] | 167 | info = xmalloc(sizeof(LINKRES), pszSrcFile, __LINE__);
|
---|
| 168 | if (info) {
|
---|
| 169 | info->res = xstrdup(res, pszSrcFile, __LINE__);
|
---|
[353] | 170 | if (!info->res)
|
---|
[1039] | 171 | free(info);
|
---|
[353] | 172 | else {
|
---|
[2] | 173 | info->next = NULL;
|
---|
[551] | 174 | if (!reshead)
|
---|
| 175 | reshead = info;
|
---|
[2] | 176 | else
|
---|
[551] | 177 | last->next = info;
|
---|
| 178 | if (x > MAXNUMRES) {
|
---|
| 179 | info = reshead;
|
---|
| 180 | reshead = reshead->next;
|
---|
[1039] | 181 | free(info);
|
---|
[2] | 182 | }
|
---|
| 183 | return TRUE;
|
---|
| 184 | }
|
---|
| 185 | }
|
---|
| 186 | return FALSE;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
[551] | 189 | BOOL remove_resource(CHAR * res)
|
---|
[353] | 190 | {
|
---|
[551] | 191 | LINKRES *info, *last = NULL;
|
---|
[2] | 192 |
|
---|
[551] | 193 | if (!res || !*res)
|
---|
[2] | 194 | return FALSE;
|
---|
[551] | 195 | if (!loadedres)
|
---|
[2] | 196 | load_resources();
|
---|
| 197 | info = reshead;
|
---|
[551] | 198 | while (info) {
|
---|
| 199 | if (!stricmp(info->res, res)) {
|
---|
| 200 | if (last)
|
---|
| 201 | last->next = info->next;
|
---|
[2] | 202 | else
|
---|
[551] | 203 | reshead = info->next;
|
---|
[1009] | 204 | xfree(info->res, pszSrcFile, __LINE__);
|
---|
[1039] | 205 | free(info);
|
---|
[2] | 206 | return TRUE;
|
---|
| 207 | }
|
---|
| 208 | last = info;
|
---|
| 209 | info = info->next;
|
---|
| 210 | }
|
---|
| 211 | return FALSE;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
[551] | 214 | VOID free_resources(VOID)
|
---|
[353] | 215 | {
|
---|
[551] | 216 | LINKRES *info, *next;
|
---|
[2] | 217 |
|
---|
| 218 | info = reshead;
|
---|
[551] | 219 | while (info) {
|
---|
[2] | 220 | next = info->next;
|
---|
[1009] | 221 | xfree(info->res, pszSrcFile, __LINE__);
|
---|
[1039] | 222 | free(info);
|
---|
[2] | 223 | info = next;
|
---|
| 224 | }
|
---|
| 225 | reshead = NULL;
|
---|
| 226 | DosPostEventSem(CompactSem);
|
---|
| 227 | }
|
---|
| 228 |
|
---|
[551] | 229 | MRESULT EXPENTRY RemapDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
[353] | 230 | {
|
---|
[2] | 231 | static BOOL fRemapped;
|
---|
[551] | 232 | static APPNOTIFY *apphead = NULL, *apptail = NULL;
|
---|
[2] | 233 |
|
---|
[551] | 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;
|
---|
[2] | 244 |
|
---|
[551] | 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;
|
---|
[2] | 252 | }
|
---|
[551] | 253 | }
|
---|
| 254 | {
|
---|
| 255 | ULONG ulDriveMap, ulDriveNum, x, ulType;
|
---|
| 256 | CHAR s[3] = " :";
|
---|
[2] | 257 |
|
---|
[551] | 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';
|
---|
[766] | 263 | if (!(ulDriveMap & (1 << x)))
|
---|
[551] | 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 | }
|
---|
[2] | 278 | }
|
---|
[551] | 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 | }
|
---|
[2] | 292 | break;
|
---|
[551] | 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];
|
---|
[2] | 302 |
|
---|
[551] | 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) {
|
---|
[2] | 315 |
|
---|
[551] | 316 | CHAR buf[2048];
|
---|
| 317 | ULONG len;
|
---|
| 318 | APIRET rc;
|
---|
| 319 | FSQBUFFER2 *p2;
|
---|
[2] | 320 |
|
---|
[551] | 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) {
|
---|
[2] | 327 |
|
---|
[551] | 328 | CHAR *p;
|
---|
[2] | 329 |
|
---|
[551] | 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,
|
---|
[1498] | 338 | (CHAR *) GetPString(IDS_UNKNOWNBRKTTEXT));
|
---|
[551] | 339 | }
|
---|
| 340 | else
|
---|
| 341 | WinSetDlgItemText(hwnd,
|
---|
| 342 | MAP_ATTACHTO,
|
---|
[1498] | 343 | (CHAR *) GetPString(IDS_UNKNOWNBRKTTEXT));
|
---|
[551] | 344 | }
|
---|
| 345 | }
|
---|
| 346 | }
|
---|
| 347 | break;
|
---|
[2] | 348 | }
|
---|
| 349 | break;
|
---|
[551] | 350 | }
|
---|
| 351 | break;
|
---|
[2] | 352 |
|
---|
[551] | 353 | case WM_APPTERMINATENOTIFY:
|
---|
| 354 | {
|
---|
| 355 | APPNOTIFY *info;
|
---|
| 356 | SHORT x, c;
|
---|
| 357 | CHAR d[3];
|
---|
| 358 | HWND hwndList;
|
---|
[2] | 359 |
|
---|
[551] | 360 | if (!mp2)
|
---|
| 361 | fRemapped = TRUE;
|
---|
| 362 | info = apphead;
|
---|
| 363 | GetRidOfIt:
|
---|
| 364 | while (info) {
|
---|
| 365 | if (info->happ == (HAPP) mp1) {
|
---|
[2] | 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 | */
|
---|
[551] | 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) {
|
---|
[2] | 419 |
|
---|
[551] | 420 | PROGDETAILS pgd;
|
---|
| 421 | CHAR params[368], *p;
|
---|
| 422 | HAPP happ;
|
---|
[2] | 423 |
|
---|
[551] | 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;
|
---|
[1394] | 432 | pgd.pszTitle = info->attach ? (PSZ)GetPString(IDS_ATTACHREQTEXT) :
|
---|
| 433 | (PSZ)GetPString(IDS_DETACHREQTEXT);
|
---|
[551] | 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),
|
---|
[1402] | 457 | GetPString(IDS_CANTSTARTNETUSETEXT));
|
---|
[551] | 458 | if (!mp2 || (ULONG) mp2 == 1041 || info->failedonce)
|
---|
[1039] | 459 | free(info);
|
---|
[551] | 460 | break;
|
---|
| 461 | }
|
---|
| 462 | info = info->next;
|
---|
[2] | 463 | }
|
---|
[551] | 464 | }
|
---|
| 465 | break;
|
---|
[2] | 466 |
|
---|
[551] | 467 | case WM_COMMAND:
|
---|
| 468 | switch (SHORT1FROMMP(mp1)) {
|
---|
| 469 | case MAP_DELETE:
|
---|
| 470 | {
|
---|
| 471 | SHORT x;
|
---|
| 472 | CHAR resource[CCHMAXPATH];
|
---|
[2] | 473 |
|
---|
[551] | 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;
|
---|
[2] | 508 |
|
---|
[551] | 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;
|
---|
[2] | 515 |
|
---|
[551] | 516 | case MAP_INFO:
|
---|
| 517 | case MAP_DETACH:
|
---|
| 518 | {
|
---|
| 519 | CHAR d[3], s[CCHMAXPATH];
|
---|
| 520 | SHORT x;
|
---|
[2] | 521 |
|
---|
[551] | 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;
|
---|
[2] | 542 |
|
---|
[551] | 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;
|
---|
[1394] | 548 | pgd.pszTitle = (PSZ)GetPString(IDS_DETACHREQTEXT);
|
---|
[551] | 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) {
|
---|
[2] | 562 |
|
---|
[551] | 563 | APPNOTIFY *info;
|
---|
[2] | 564 |
|
---|
[551] | 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 | }
|
---|
[353] | 588 | #ifdef NEVER // fixme to be gone?
|
---|
[551] | 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;
|
---|
[2] | 611 |
|
---|
[551] | 612 | case MAP_INFO:
|
---|
| 613 | runemf2(SEPARATEKEEP | WINDOWED | MAXIMIZED,
|
---|
[888] | 614 | hwnd, pszSrcFile, __LINE__,
|
---|
[551] | 615 | NULL, NULL, "%s /C NET USE %s", GetCmdSpec(FALSE), d);
|
---|
| 616 | break;
|
---|
| 617 | }
|
---|
| 618 | }
|
---|
| 619 | }
|
---|
| 620 | }
|
---|
| 621 | break;
|
---|
[2] | 622 |
|
---|
[551] | 623 | case MAP_ATTACH:
|
---|
| 624 | {
|
---|
| 625 | CHAR d[3], s[CCHMAXPATH];
|
---|
| 626 | SHORT x;
|
---|
[2] | 627 |
|
---|
[551] | 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) {
|
---|
[2] | 643 |
|
---|
[551] | 644 | PROGDETAILS pgd;
|
---|
| 645 | CHAR params[368], *p;
|
---|
| 646 | HAPP happ;
|
---|
[2] | 647 |
|
---|
[551] | 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;
|
---|
[1394] | 653 | pgd.pszTitle = (PSZ)GetPString(IDS_ATTACHREQTEXT);
|
---|
[551] | 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) {
|
---|
[2] | 667 |
|
---|
[551] | 668 | APPNOTIFY *info;
|
---|
[2] | 669 |
|
---|
[551] | 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);
|
---|
[353] | 691 | #ifdef NEVER // fixme to be gone?
|
---|
[551] | 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;
|
---|
[2] | 718 |
|
---|
[551] | 719 | case IDM_HELP:
|
---|
| 720 | if (hwndHelp)
|
---|
| 721 | WinSendMsg(hwndHelp,
|
---|
| 722 | HM_DISPLAY_HELP,
|
---|
| 723 | MPFROM2SHORT(HELP_REMAP, 0), MPFROMSHORT(HM_RESOURCEID));
|
---|
| 724 | break;
|
---|
[2] | 725 |
|
---|
[551] | 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);
|
---|
[2] | 734 | }
|
---|
[551] | 735 | WinDismissDlg(hwnd, 0);
|
---|
| 736 | break;
|
---|
| 737 | }
|
---|
| 738 | return 0;
|
---|
[2] | 739 |
|
---|
[551] | 740 | case WM_DESTROY:
|
---|
| 741 | if (apphead) {
|
---|
[2] | 742 |
|
---|
[551] | 743 | APPNOTIFY *info, *next;
|
---|
[2] | 744 |
|
---|
[551] | 745 | info = apphead;
|
---|
| 746 | while (info) {
|
---|
| 747 | next = info->next;
|
---|
[1039] | 748 | free(info);
|
---|
[551] | 749 | info = next;
|
---|
[2] | 750 | }
|
---|
[551] | 751 | apphead = apptail = NULL;
|
---|
| 752 | saymsg(MB_YESNOCANCEL,
|
---|
| 753 | HWND_DESKTOP,
|
---|
| 754 | GetPString(IDS_NOTICETITLETEXT),
|
---|
[1402] | 755 | GetPString(IDS_REMAPNOTICETEXT));
|
---|
[551] | 756 | }
|
---|
| 757 | free_resources();
|
---|
| 758 | loadedres = FALSE;
|
---|
| 759 | break;
|
---|
[2] | 760 | }
|
---|
[551] | 761 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
---|
[2] | 762 | }
|
---|
[793] | 763 |
|
---|
| 764 | #pragma alloc_text(FMREMAP,RemapDlgProc,load_resources,save_resources)
|
---|
| 765 | #pragma alloc_text(FMREMAP,add_resource,remove_resource,free_resources)
|
---|