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