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