source: trunk/dll/undel.c@ 1398

Last change on this file since 1398 was 1398, checked in by Gregg Young, 17 years ago

Move embeded strings to PCSZ variables or string table; Eliminate Error2 functions Runtime_Error with NULL format string returns "No data" error. Change declares from PSZ to PCSZ in functions where the variable isn't changed. Added btm as an executable file type in several additional places. Use fProtectOnly to prevent attempt to execute Dos and Win programs on "Protect only" installs in several additional places.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.9 KB
Line 
1
2/***********************************************************************
3
4 $Id: undel.c 1398 2009-02-21 17:43:00Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2004, 2008 Steven H. Levine
8
9 01 Aug 04 SHL Rework lstrip/rstrip usage
10 24 May 05 SHL Rework Win_Error usage
11 17 Jul 06 SHL Use Runtime_Error
12 29 Jul 06 SHL Use xfgets_bstripcr
13 03 Nov 06 SHL Count thread usage
14 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
15 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
16 29 Feb 08 GKY Use xfree where appropriate
17 16 JUL 08 GKY Use TMP directory for temp files
18 10 Dec 08 SHL Integrate exception handler support
19
20***********************************************************************/
21
22#include <stdlib.h>
23#include <string.h>
24#include <ctype.h>
25// #include <process.h> // _beginthread
26
27#define INCL_DOS
28#define INCL_WIN
29#define INCL_LONGLONG
30
31#include "fm3dll.h"
32#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
33#include "undel.h"
34#include "init.h" // Data declaration(s)
35#include "mainwnd.h" // Data declaration(s)
36#include "fm3dlg.h"
37#include "fm3str.h"
38#include "errutil.h" // Dos_Error...
39#include "strutil.h" // GetPString
40#include "pathutil.h" // BldFullPathName
41#include "walkem.h" // FillPathListBox
42#include "common.h" // DecrThreadUsage, IncrThreadUsage
43#include "valid.h" // MakeFullName
44#include "copyf.h" // unlinkf
45#include "wrappers.h" // xfgets
46#include "strips.h" // bstrip
47#include "misc.h" // GetCmdSpec
48#include "systemf.h" // runemf2
49#include "fortify.h"
50#include "excputil.h" // xbeginthread
51
52#pragma data_seg(DATA2)
53
54static PSZ pszSrcFile = __FILE__;
55
56struct tempstruct
57{
58 HWND hwnd;
59 CHAR path[CCHMAXPATH];
60 BOOL inclsubdirs;
61};
62
63static VOID FillUndelListThread(VOID * arg)
64{
65 HWND hwnd;
66 CHAR s[CCHMAXPATH * 2], szTempFile[CCHMAXPATH];
67 CHAR *path;
68 HAB thab;
69 HMQ thmq;
70 FILE *fp;
71 HFILE oldstdout, newstdout;
72 struct tempstruct *undelinfo;
73 BOOL killme = FALSE;
74 FILESTATUS3 fsa;
75
76 undelinfo = (struct tempstruct *)arg;
77 hwnd = undelinfo->hwnd;
78 path = undelinfo->path;
79 DosError(FERR_DISABLEHARDERR);
80
81# ifdef FORTIFY
82 Fortify_EnterScope();
83# endif
84 thab = WinInitialize(0);
85 thmq = WinCreateMsgQueue(thab, 0);
86 if (thab && thmq) {
87 WinCancelShutdown(thmq, TRUE);
88 IncrThreadUsage();
89 WinSendDlgItemMsg(hwnd, UNDEL_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
90 BldFullPathName(szTempFile, pTmpDir, "$UDELETE.#$#");
91 unlinkf("%s", szTempFile);
92 fp = xfopen(szTempFile, "w", pszSrcFile, __LINE__);
93 if (!fp) {
94 Win_Error(NULLHANDLE, hwnd, pszSrcFile, __LINE__,
95 GetPString(IDS_REDIRECTERRORTEXT));
96 killme = TRUE;
97 goto Abort;
98 }
99 else {
100 newstdout = -1;
101 if (DosDupHandle(fileno(stdout), &newstdout)) {
102 saymsg(MB_CANCEL,
103 hwnd,
104 GetPString(IDS_MAYDAYTEXT), GetPString(IDS_REDIRECTERRORTEXT));
105 fclose(fp);
106 killme = TRUE;
107 goto Abort;
108 }
109 oldstdout = fileno(stdout);
110 DosDupHandle(fileno(fp), &oldstdout);
111 runemf2(SEPARATE | INVISIBLE | WINDOWED | BACKGROUND | WAIT,
112 hwnd, pszSrcFile, __LINE__,
113 NULL,
114 NULL,
115 "UNDELETE.COM %s /L%s",
116 path, (undelinfo->inclsubdirs) ? " /S" : NullStr);
117 oldstdout = fileno(stdout);
118 DosDupHandle(newstdout, &oldstdout);
119 DosClose(newstdout);
120 fclose(fp);
121 }
122 fp = xfopen(szTempFile, "r", pszSrcFile, __LINE__);
123 if (fp) {
124 xfgets(s, sizeof(s), fp, pszSrcFile, __LINE__); // Skip 1st line
125 while (!feof(fp)) {
126 strset(s, 0);
127 if (!xfgets_bstripcr(s, CCHMAXPATH + 2, fp, pszSrcFile, __LINE__))
128 break;
129 if (*s) {
130 if (!strnicmp(s, "SYS3194: ", 9)) {
131
132 APIRET temp;
133
134 strcat(s, " ");
135 xfgets(&s[strlen(s)], CCHMAXPATH + 128 - strlen(s), fp,
136 pszSrcFile, __LINE__);
137 fclose(fp);
138 s[CCHMAXPATH + 128] = 0;
139 stripcr(s);
140 rstrip(s);
141 strcat(s, GetPString(IDS_ASKABOUTUNDELETEHELPTEXT));
142 temp = saymsg(MB_YESNOCANCEL | MB_ICONEXCLAMATION,
143 hwnd, GetPString(IDS_ERRORTEXT), "%s", s);
144 if (temp == MBID_YES)
145 runemf2(BACKGROUND | INVISIBLE | SEPARATE | WINDOWED,
146 hwnd, pszSrcFile, __LINE__,
147 NULL, NULL, "%s /C HELP UNDELETE", GetCmdSpec(FALSE));
148 if (temp == MBID_CANCEL)
149 killme = TRUE;
150 goto Abort;
151 }
152 else if (s[1] != ':')
153 continue;
154 else if ((SHORT)
155 WinSendDlgItemMsg(hwnd, UNDEL_LISTBOX, LM_SEARCHSTRING,
156 MPFROM2SHORT(0, LIT_FIRST),
157 MPFROMP(s)) < 0
158 && DosQueryPathInfo(s, FIL_STANDARD, &fsa,
159 (ULONG) sizeof(fsa)))
160 WinSendDlgItemMsg(hwnd, UNDEL_LISTBOX, LM_INSERTITEM,
161 MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
162 }
163 }
164 fclose(fp);
165 }
166 Abort:
167 ;
168 }
169 DosForceDelete(szTempFile);
170 xfree(undelinfo, pszSrcFile, __LINE__);
171 if (thmq) {
172 PostMsg(hwnd, UM_CONTAINER_FILLED, MPVOID, MPVOID);
173 if (killme)
174 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
175 WinDestroyMsgQueue(thmq);
176 }
177 if (thab) {
178 DecrThreadUsage();
179 WinTerminate(thab);
180 }
181# ifdef FORTIFY
182 Fortify_LeaveScope();
183# endif
184}
185
186MRESULT EXPENTRY UndeleteDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
187{
188 SHORT sSelect;
189 static BOOL listdone, changed = FALSE, refresh = FALSE;
190 static HPOINTER hptrIcon = (HPOINTER) 0;
191
192 switch (msg) {
193 case WM_INITDLG:
194 listdone = TRUE;
195 if (!mp2 || !*(CHAR *)mp2) {
196 Runtime_Error(pszSrcFile, __LINE__, NULL);
197 WinDismissDlg(hwnd, 0);
198 break;
199 }
200 hptrIcon = WinLoadPointer(HWND_DESKTOP, FM3ModHandle, UNDEL_FRAME);
201 WinDefDlgProc(hwnd, WM_SETICON, MPFROMLONG(hptrIcon), MPVOID);
202 WinSendDlgItemMsg(hwnd, UNDEL_ENTRY, EM_SETTEXTLIMIT,
203 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
204 {
205 CHAR s[CCHMAXPATH];
206
207 strcpy(s, (CHAR *)mp2);
208 if (s[strlen(s) - 1] != '\\')
209 strcat(s, "\\");
210 strcat(s, "*");
211 WinSetDlgItemText(hwnd, UNDEL_ENTRY, s);
212 WinCheckButton(hwnd, UNDEL_SUBDIRS, TRUE);
213 FillPathListBox(hwnd, WinWindowFromID(hwnd, UNDEL_DRIVELIST), (HWND) 0,
214 s, TRUE);
215 }
216 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
217 break;
218
219 case UM_SETUP:
220 if (listdone) {
221
222 struct tempstruct *undelinfo;
223 CHAR s[CCHMAXPATH];
224
225 listdone = FALSE;
226 undelinfo = xmallocz(sizeof(struct tempstruct), pszSrcFile, __LINE__);
227 if (!undelinfo) {
228 listdone = TRUE;
229 WinDismissDlg(hwnd, 0);
230 }
231 else {
232 undelinfo->hwnd = hwnd;
233 WinQueryDlgItemText(hwnd,
234 UNDEL_ENTRY,
235 sizeof(undelinfo->path), undelinfo->path);
236 bstrip(undelinfo->path);
237 MakeFullName(undelinfo->path);
238 undelinfo->inclsubdirs = WinQueryButtonCheckstate(hwnd,
239 UNDEL_SUBDIRS);
240 sprintf(s,
241 GetPString(IDS_UNDELETETITLETEXT), toupper(*undelinfo->path));
242 WinSetWindowText(hwnd, s);
243 if (xbeginthread(FillUndelListThread,
244 65536,
245 undelinfo,
246 pszSrcFile,
247 __LINE__) == -1)
248 {
249 free(undelinfo);
250 listdone = TRUE;
251 WinDismissDlg(hwnd, 0);
252 }
253 else
254 DosSleep(100);//05 Aug 07 GKY 500
255 }
256 refresh = FALSE;
257 }
258 else
259 refresh = TRUE;
260 changed = FALSE;
261 return 0;
262
263 case UM_CONTAINER_FILLED:
264 listdone = TRUE;
265 {
266 CHAR s[33];
267
268 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
269 UNDEL_LISTBOX,
270 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
271 sprintf(s, "%d", sSelect);
272 WinSetDlgItemText(hwnd, UNDEL_COUNT, s);
273 if (refresh)
274 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
275 refresh = FALSE;
276 }
277 return 0;
278
279 case WM_CONTROL:
280 switch (SHORT1FROMMP(mp1)) {
281 case UNDEL_SUBDIRS:
282 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
283 break;
284
285 case UNDEL_ENTRY:
286 switch (SHORT2FROMMP(mp1)) {
287 case EN_CHANGE:
288 changed = TRUE;
289 break;
290 case EN_KILLFOCUS:
291 if (changed)
292 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
293 break;
294 }
295 break;
296
297 case UNDEL_DRIVELIST:
298 if (!listdone) {
299 Runtime_Error(pszSrcFile, __LINE__, "not listdone");
300 break;
301 }
302 switch (SHORT2FROMMP(mp1)) {
303 case CBN_ENTER:
304 {
305 CHAR s[CCHMAXPATH], drive, *p;
306
307 strset(s, 0);
308 WinQueryDlgItemText(hwnd, UNDEL_DRIVELIST, 3, s);
309 if (!isalpha(*s)) {
310 Runtime_Error(pszSrcFile, __LINE__, NULL);
311 }
312 else {
313 drive = toupper(*s);
314 WinQueryDlgItemText(hwnd, UNDEL_ENTRY, sizeof(s), s);
315 *s = drive;
316 s[1] = ':';
317 s[2] = '\\';
318 p = strrchr(s + 2, '\\');
319 if (p) {
320 p++;
321 if (*p)
322 memmove(s + 3, p, strlen(p) + 1);
323 else {
324 s[3] = '*';
325 s[4] = 0;
326 }
327 }
328 else {
329 s[3] = '*';
330 s[4] = 0;
331 }
332 s[CCHMAXPATH - 1] = 0;
333 WinSetDlgItemText(hwnd, UNDEL_ENTRY, s);
334 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
335 }
336 }
337 break;
338 }
339 break;
340
341 case UNDEL_LISTBOX:
342 switch (SHORT2FROMMP(mp2)) {
343 case LN_ENTER:
344 WinSendDlgItemMsg(hwnd, DID_OK, BM_CLICK, MPFROMSHORT(TRUE), MPVOID);
345 break;
346 }
347 break;
348
349 default:
350 break;
351 }
352 return 0;
353
354 case WM_ADJUSTWINDOWPOS:
355 PostMsg(hwnd, UM_STRETCH, MPVOID, MPVOID);
356 break;
357
358 case UM_STRETCH:
359 {
360 SWP swpC, swp, swpM, swpD, swpL, swpE;
361
362 WinQueryWindowPos(hwnd, &swp);
363 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE))) {
364 WinQueryWindowPos(WinWindowFromID(hwnd, UNDEL_LISTBOX), &swpC);
365 WinQueryWindowPos(WinWindowFromID(hwnd, UNDEL_MASKHDR), &swpM);
366 WinQueryWindowPos(WinWindowFromID(hwnd, UNDEL_DRVHDR), &swpD);
367 WinQueryWindowPos(WinWindowFromID(hwnd, UNDEL_DRIVELIST), &swpL);
368 WinQueryWindowPos(WinWindowFromID(hwnd, UNDEL_ENTRY), &swpE);
369 WinSetWindowPos(WinWindowFromID(hwnd, UNDEL_LISTBOX), HWND_TOP,
370 SysVal(SV_CXSIZEBORDER),
371 swpC.y,
372 swp.cx - (SysVal(SV_CXSIZEBORDER) * 2),
373 (swp.cy - swpC.y) - (SysVal(SV_CYTITLEBAR) +
374 SysVal(SV_CYSIZEBORDER) +
375 swpM.cy + 16),
376 SWP_MOVE | SWP_SIZE);
377 WinSetWindowPos(WinWindowFromID(hwnd, UNDEL_MASKHDR), HWND_TOP,
378 swpM.x,
379 (swp.cy - swpM.cy) - (SysVal(SV_CYTITLEBAR) +
380 SysVal(SV_CYSIZEBORDER) + 8),
381 swpM.cx, swpM.cy, SWP_MOVE | SWP_SIZE);
382 WinSetWindowPos(WinWindowFromID(hwnd, UNDEL_DRVHDR), HWND_TOP,
383 swpD.x,
384 (swp.cy - swpM.cy) - (SysVal(SV_CYTITLEBAR) +
385 SysVal(SV_CYSIZEBORDER) + 8),
386 swpD.cx, swpM.cy, SWP_MOVE | SWP_SIZE);
387 WinSetWindowPos(WinWindowFromID(hwnd, UNDEL_DRIVELIST), HWND_TOP,
388 swpL.x,
389 SysVal(SV_CYSIZEBORDER),
390 swpL.cx,
391 swp.cy - (SysVal(SV_CYTITLEBAR) +
392 (SysVal(SV_CYSIZEBORDER) * 2) + 6),
393 SWP_MOVE | SWP_SIZE);
394 WinSetWindowPos(WinWindowFromID(hwnd, UNDEL_ENTRY), HWND_TOP,
395 swpM.x + swpM.cx + 4,
396 (swp.cy - swpM.cy) - (SysVal(SV_CYTITLEBAR) +
397 SysVal(SV_CYSIZEBORDER) + 8),
398 swp.cx - ((swpM.x + swpM.cx + 4) +
399 (SysVal(SV_CXSIZEBORDER) + 8)),
400 swpM.cy + 2, SWP_MOVE | SWP_SIZE);
401 WinInvalidateRect(WinWindowFromID(hwnd, UNDEL_ENTRY), NULL, FALSE);
402 }
403 }
404 return 0;
405
406 case WM_COMMAND:
407 switch (SHORT1FROMMP(mp1)) {
408 case UNDEL_DEL:
409 case DID_OK:
410 if (changed || !listdone) {
411 Runtime_Error(pszSrcFile, __LINE__, "not done");
412 }
413 else {
414 sSelect = (USHORT) WinSendDlgItemMsg(hwnd, UNDEL_LISTBOX,
415 LM_QUERYSELECTION,
416 MPFROMSHORT(LIT_FIRST), MPVOID);
417 if (sSelect >= 0) {
418
419 FILE *fp;
420 CHAR s[CCHMAXPATH + 1];
421
422 DosForceDelete("\\FMUNDEL.CMD");
423 fp = xfopen("\\FMUNDEL.CMD", "w", pszSrcFile, __LINE__);
424 if (fp) {
425 while (sSelect >= 0) {
426 *s = 0;
427 WinSendDlgItemMsg(hwnd, UNDEL_LISTBOX, LM_QUERYITEMTEXT,
428 MPFROM2SHORT(sSelect, CCHMAXPATH),
429 MPFROMP(s));
430 if (SHORT1FROMMP(mp1) == UNDEL_DEL)
431 WinSendDlgItemMsg(hwnd, UNDEL_LISTBOX, LM_DELETEITEM,
432 MPFROM2SHORT(sSelect, 0), MPVOID);
433 if (*s) {
434 if (SHORT1FROMMP(mp1) == DID_OK)
435 fprintf(fp,
436 "IF NOT EXIST \"%s\" UNDELETE.COM \"%s\" /A\n",
437 s, s);
438 else
439 fprintf(fp, "UNDELETE.COM \"%s\" /F /A\n", s);
440 }
441 sSelect = (USHORT) WinSendDlgItemMsg(hwnd,
442 UNDEL_LISTBOX,
443 LM_QUERYSELECTION,
444 (SHORT1FROMMP(mp1) ==
445 DID_OK) ?
446 MPFROMSHORT(sSelect) :
447 MPFROMSHORT(LIT_FIRST),
448 MPVOID);
449 }
450 fprintf(fp, "DEL \\FMUNDEL.CMD /F\n");
451 fclose(fp);
452 runemf2(WINDOWED | BACKGROUND | SEPARATE | INVISIBLE,
453 hwnd, pszSrcFile, __LINE__,
454 NULL, NULL, "%s /C \\FMUNDEL.CMD", GetCmdSpec(FALSE));
455 }
456 }
457 if (SHORT1FROMMP(mp1) == DID_OK)
458 WinDismissDlg(hwnd, 0);
459 {
460 CHAR s[33];
461
462 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
463 UNDEL_LISTBOX,
464 LM_QUERYITEMCOUNT,
465 MPVOID, MPVOID);
466 sprintf(s, "%d", sSelect);
467 WinSetDlgItemText(hwnd, UNDEL_COUNT, s);
468 }
469 }
470 break;
471
472 case DID_CANCEL:
473 if (!listdone)
474 Runtime_Error(pszSrcFile, __LINE__, "is busy");
475 else
476 WinDismissDlg(hwnd, 0);
477 break;
478
479 case IDM_HELP:
480 saymsg(MB_ENTER | MB_ICONASTERISK,
481 hwnd,
482 GetPString(IDS_UNDELETEHELPTITLETEXT),
483 GetPString(IDS_UNDELETEHELPTEXT));
484 break;
485 }
486 return 0;
487
488 case WM_CLOSE:
489 if (!listdone) {
490 Runtime_Error(pszSrcFile, __LINE__, "not listdone");
491 return 0;
492 }
493 break;
494
495 case WM_DESTROY:
496 if (hptrIcon)
497 WinDestroyPointer(hptrIcon);
498 hptrIcon = (HPOINTER) 0;
499 break;
500 }
501 return WinDefDlgProc(hwnd, msg, mp1, mp2);
502}
503
504#pragma alloc_text(UNDELETE,FillUndelListThread,UndeleteDlgProc)
Note: See TracBrowser for help on using the repository browser.