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