1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: remap.c 1039 2008-07-05 22:16:21Z gyoung $
|
---|
5 |
|
---|
6 | Copyright (c) 1993, 1998 M. Kimes
|
---|
7 | Copyright (c) 2004, 2006 Steven H.Levine
|
---|
8 |
|
---|
9 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
---|
10 | 06 Aug 05 SHL Renames
|
---|
11 | 22 Jul 06 SHL Check more run time errors
|
---|
12 | 29 Jul 06 SHL Use xfgets
|
---|
13 | 31 Aug 06 SHL Use _fsopen to avoid noise complaints
|
---|
14 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
15 | 29 Feb 08 GKY Use xfree where appropriate
|
---|
16 |
|
---|
17 | ***********************************************************************/
|
---|
18 |
|
---|
19 | #include <stdlib.h>
|
---|
20 | #include <string.h>
|
---|
21 | #include <share.h>
|
---|
22 | #include <io.h> // unlink
|
---|
23 |
|
---|
24 | #define INCL_DOS
|
---|
25 | #define INCL_WIN
|
---|
26 | #define INCL_LONGLONG // dircnrs.h
|
---|
27 |
|
---|
28 | #include "fm3dlg.h"
|
---|
29 | #include "fm3str.h"
|
---|
30 | #include "errutil.h" // Dos_Error...
|
---|
31 | #include "strutil.h" // GetPString
|
---|
32 | #include "fm3dll.h"
|
---|
33 | #include "fortify.h"
|
---|
34 |
|
---|
35 | #pragma data_seg(DATA1)
|
---|
36 |
|
---|
37 | static PSZ pszSrcFile = __FILE__;
|
---|
38 |
|
---|
39 | typedef struct APPNOTIFY
|
---|
40 | {
|
---|
41 | HAPP happ;
|
---|
42 | BOOL attach;
|
---|
43 | BOOL failedonce;
|
---|
44 | CHAR uncname[CCHMAXPATH];
|
---|
45 | CHAR device;
|
---|
46 | struct APPNOTIFY *next;
|
---|
47 | struct APPNOTIFY *prev;
|
---|
48 | }
|
---|
49 | APPNOTIFY;
|
---|
50 |
|
---|
51 | typedef struct LINKRES
|
---|
52 | {
|
---|
53 | CHAR *res;
|
---|
54 | struct LINKRES *next;
|
---|
55 | }
|
---|
56 | LINKRES;
|
---|
57 |
|
---|
58 | static LINKRES *reshead = NULL;
|
---|
59 | static BOOL loadedres = FALSE;
|
---|
60 |
|
---|
61 | #define MAXNUMRES 200
|
---|
62 |
|
---|
63 | VOID load_resources(VOID)
|
---|
64 | {
|
---|
65 | /* load linked list of resources from RESOURCE.DAT file */
|
---|
66 |
|
---|
67 | FILE *fp;
|
---|
68 | LINKRES *info, *last = NULL;
|
---|
69 | CHAR s[CCHMAXPATH + 14];
|
---|
70 | INT x = 0;
|
---|
71 |
|
---|
72 | loadedres = TRUE;
|
---|
73 | save_dir2(s);
|
---|
74 | if (s[strlen(s) - 1] != '\\')
|
---|
75 | strcat(s, "\\");
|
---|
76 | strcat(s, "RESOURCE.DAT");
|
---|
77 | fp = _fsopen(s, "r", SH_DENYWR);
|
---|
78 | if (fp) {
|
---|
79 | while (x < MAXNUMRES && !feof(fp)) {
|
---|
80 | if (!xfgets_bstripcr(s, sizeof(s), fp, pszSrcFile, __LINE__))
|
---|
81 | break;
|
---|
82 | if (*s && *s != ';') {
|
---|
83 | info = xmalloc(sizeof(LINKRES), pszSrcFile, __LINE__);
|
---|
84 | if (info) {
|
---|
85 | info->res = xstrdup(s, pszSrcFile, __LINE__);
|
---|
86 | if (!info->res)
|
---|
87 | free(info);
|
---|
88 | else {
|
---|
89 | x++;
|
---|
90 | info->next = NULL;
|
---|
91 | if (!reshead)
|
---|
92 | reshead = info;
|
---|
93 | else
|
---|
94 | last->next = info;
|
---|
95 | last = info;
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|
99 | }
|
---|
100 | fclose(fp);
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | VOID save_resources(VOID)
|
---|
105 | {
|
---|
106 | /* save linked list of resources to RESOURCE.DAT file */
|
---|
107 |
|
---|
108 | LINKRES *info;
|
---|
109 | FILE *fp;
|
---|
110 | CHAR s[CCHMAXPATH + 14];
|
---|
111 |
|
---|
112 | if (!loadedres)
|
---|
113 | return;
|
---|
114 | save_dir2(s);
|
---|
115 | if (s[strlen(s) - 1] != '\\')
|
---|
116 | strcat(s, "\\");
|
---|
117 | strcat(s, "RESOURCE.DAT");
|
---|
118 | if (reshead) {
|
---|
119 | fp = xfopen(s, "w", pszSrcFile, __LINE__);
|
---|
120 | if (fp) {
|
---|
121 | fputs(GetPString(IDS_REMOTEFILETEXT), fp);
|
---|
122 | info = reshead;
|
---|
123 | while (info) {
|
---|
124 | fprintf(fp, "%0.*s\n", CCHMAXPATH, info->res);
|
---|
125 | info = info->next;
|
---|
126 | }
|
---|
127 | fclose(fp);
|
---|
128 | }
|
---|
129 | }
|
---|
130 | else
|
---|
131 | unlink(s);
|
---|
132 | }
|
---|
133 |
|
---|
134 | BOOL add_resource(CHAR * res)
|
---|
135 | {
|
---|
136 | LINKRES *info, *last = NULL;
|
---|
137 | INT x = 0;
|
---|
138 |
|
---|
139 | if (!res || !*res)
|
---|
140 | return FALSE;
|
---|
141 | if (!loadedres)
|
---|
142 | load_resources();
|
---|
143 | info = reshead;
|
---|
144 | while (info) {
|
---|
145 | if (!stricmp(info->res, res))
|
---|
146 | return FALSE;
|
---|
147 | last = info;
|
---|
148 | info = info->next;
|
---|
149 | x++;
|
---|
150 | }
|
---|
151 | info = xmalloc(sizeof(LINKRES), pszSrcFile, __LINE__);
|
---|
152 | if (info) {
|
---|
153 | info->res = xstrdup(res, pszSrcFile, __LINE__);
|
---|
154 | if (!info->res)
|
---|
155 | free(info);
|
---|
156 | else {
|
---|
157 | info->next = NULL;
|
---|
158 | if (!reshead)
|
---|
159 | reshead = info;
|
---|
160 | else
|
---|
161 | last->next = info;
|
---|
162 | if (x > MAXNUMRES) {
|
---|
163 | info = reshead;
|
---|
164 | reshead = reshead->next;
|
---|
165 | free(info);
|
---|
166 | }
|
---|
167 | return TRUE;
|
---|
168 | }
|
---|
169 | }
|
---|
170 | return FALSE;
|
---|
171 | }
|
---|
172 |
|
---|
173 | BOOL remove_resource(CHAR * res)
|
---|
174 | {
|
---|
175 | LINKRES *info, *last = NULL;
|
---|
176 |
|
---|
177 | if (!res || !*res)
|
---|
178 | return FALSE;
|
---|
179 | if (!loadedres)
|
---|
180 | load_resources();
|
---|
181 | info = reshead;
|
---|
182 | while (info) {
|
---|
183 | if (!stricmp(info->res, res)) {
|
---|
184 | if (last)
|
---|
185 | last->next = info->next;
|
---|
186 | else
|
---|
187 | reshead = info->next;
|
---|
188 | xfree(info->res, pszSrcFile, __LINE__);
|
---|
189 | free(info);
|
---|
190 | return TRUE;
|
---|
191 | }
|
---|
192 | last = info;
|
---|
193 | info = info->next;
|
---|
194 | }
|
---|
195 | return FALSE;
|
---|
196 | }
|
---|
197 |
|
---|
198 | VOID free_resources(VOID)
|
---|
199 | {
|
---|
200 | LINKRES *info, *next;
|
---|
201 |
|
---|
202 | info = reshead;
|
---|
203 | while (info) {
|
---|
204 | next = info->next;
|
---|
205 | xfree(info->res, pszSrcFile, __LINE__);
|
---|
206 | free(info);
|
---|
207 | info = next;
|
---|
208 | }
|
---|
209 | reshead = NULL;
|
---|
210 | DosPostEventSem(CompactSem);
|
---|
211 | }
|
---|
212 |
|
---|
213 | MRESULT EXPENTRY RemapDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
214 | {
|
---|
215 | static BOOL fRemapped;
|
---|
216 | static APPNOTIFY *apphead = NULL, *apptail = NULL;
|
---|
217 |
|
---|
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;
|
---|
228 |
|
---|
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;
|
---|
236 | }
|
---|
237 | }
|
---|
238 | {
|
---|
239 | ULONG ulDriveMap, ulDriveNum, x, ulType;
|
---|
240 | CHAR s[3] = " :";
|
---|
241 |
|
---|
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 & (1 << 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 | }
|
---|
262 | }
|
---|
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 | }
|
---|
276 | break;
|
---|
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];
|
---|
286 |
|
---|
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) {
|
---|
299 |
|
---|
300 | CHAR buf[2048];
|
---|
301 | ULONG len;
|
---|
302 | APIRET rc;
|
---|
303 | FSQBUFFER2 *p2;
|
---|
304 |
|
---|
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) {
|
---|
311 |
|
---|
312 | CHAR *p;
|
---|
313 |
|
---|
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;
|
---|
332 | }
|
---|
333 | break;
|
---|
334 | }
|
---|
335 | break;
|
---|
336 |
|
---|
337 | case WM_APPTERMINATENOTIFY:
|
---|
338 | {
|
---|
339 | APPNOTIFY *info;
|
---|
340 | SHORT x, c;
|
---|
341 | CHAR d[3];
|
---|
342 | HWND hwndList;
|
---|
343 |
|
---|
344 | if (!mp2)
|
---|
345 | fRemapped = TRUE;
|
---|
346 | info = apphead;
|
---|
347 | GetRidOfIt:
|
---|
348 | while (info) {
|
---|
349 | if (info->happ == (HAPP) mp1) {
|
---|
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 | */
|
---|
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) {
|
---|
403 |
|
---|
404 | PROGDETAILS pgd;
|
---|
405 | CHAR params[368], *p;
|
---|
406 | HAPP happ;
|
---|
407 |
|
---|
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;
|
---|
447 | }
|
---|
448 | }
|
---|
449 | break;
|
---|
450 |
|
---|
451 | case WM_COMMAND:
|
---|
452 | switch (SHORT1FROMMP(mp1)) {
|
---|
453 | case MAP_DELETE:
|
---|
454 | {
|
---|
455 | SHORT x;
|
---|
456 | CHAR resource[CCHMAXPATH];
|
---|
457 |
|
---|
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;
|
---|
492 |
|
---|
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;
|
---|
499 |
|
---|
500 | case MAP_INFO:
|
---|
501 | case MAP_DETACH:
|
---|
502 | {
|
---|
503 | CHAR d[3], s[CCHMAXPATH];
|
---|
504 | SHORT x;
|
---|
505 |
|
---|
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;
|
---|
526 |
|
---|
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) {
|
---|
546 |
|
---|
547 | APPNOTIFY *info;
|
---|
548 |
|
---|
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 | }
|
---|
572 | #ifdef NEVER // fixme to be gone?
|
---|
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;
|
---|
595 |
|
---|
596 | case MAP_INFO:
|
---|
597 | runemf2(SEPARATEKEEP | WINDOWED | MAXIMIZED,
|
---|
598 | hwnd, pszSrcFile, __LINE__,
|
---|
599 | NULL, NULL, "%s /C NET USE %s", GetCmdSpec(FALSE), d);
|
---|
600 | break;
|
---|
601 | }
|
---|
602 | }
|
---|
603 | }
|
---|
604 | }
|
---|
605 | break;
|
---|
606 |
|
---|
607 | case MAP_ATTACH:
|
---|
608 | {
|
---|
609 | CHAR d[3], s[CCHMAXPATH];
|
---|
610 | SHORT x;
|
---|
611 |
|
---|
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) {
|
---|
627 |
|
---|
628 | PROGDETAILS pgd;
|
---|
629 | CHAR params[368], *p;
|
---|
630 | HAPP happ;
|
---|
631 |
|
---|
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) {
|
---|
651 |
|
---|
652 | APPNOTIFY *info;
|
---|
653 |
|
---|
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);
|
---|
675 | #ifdef NEVER // fixme to be gone?
|
---|
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;
|
---|
702 |
|
---|
703 | case IDM_HELP:
|
---|
704 | if (hwndHelp)
|
---|
705 | WinSendMsg(hwndHelp,
|
---|
706 | HM_DISPLAY_HELP,
|
---|
707 | MPFROM2SHORT(HELP_REMAP, 0), MPFROMSHORT(HM_RESOURCEID));
|
---|
708 | break;
|
---|
709 |
|
---|
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);
|
---|
718 | }
|
---|
719 | WinDismissDlg(hwnd, 0);
|
---|
720 | break;
|
---|
721 | }
|
---|
722 | return 0;
|
---|
723 |
|
---|
724 | case WM_DESTROY:
|
---|
725 | if (apphead) {
|
---|
726 |
|
---|
727 | APPNOTIFY *info, *next;
|
---|
728 |
|
---|
729 | info = apphead;
|
---|
730 | while (info) {
|
---|
731 | next = info->next;
|
---|
732 | free(info);
|
---|
733 | info = next;
|
---|
734 | }
|
---|
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;
|
---|
744 | }
|
---|
745 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
---|
746 | }
|
---|
747 |
|
---|
748 | #pragma alloc_text(FMREMAP,RemapDlgProc,load_resources,save_resources)
|
---|
749 | #pragma alloc_text(FMREMAP,add_resource,remove_resource,free_resources)
|
---|