source: trunk/dll/undel.c@ 1402

Last change on this file since 1402 was 1402, checked in by Gregg Young, 16 years ago

Remove variable aurgs from docopy & unlinkf (not used); Move more strings to PCSZs and string table; Move PCSZs to compile time initialization; Fix hang on startup caused by a drive scan and a dircnr scan trying to update a drive in the tree at the same time (related to the "treeswitch options); Code cleanup mainly removal of old printfs, SayMsgs, DbgMsg and unneeded %s.

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