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
RevLine 
[123]1
2/***********************************************************************
3
4 $Id: undel.c 1402 2009-03-14 17:17:59Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
[1335]7 Copyright (c) 2004, 2008 Steven H. Levine
[123]8
[145]9 01 Aug 04 SHL Rework lstrip/rstrip usage
10 24 May 05 SHL Rework Win_Error usage
[328]11 17 Jul 06 SHL Use Runtime_Error
[406]12 29 Jul 06 SHL Use xfgets_bstripcr
[528]13 03 Nov 06 SHL Count thread usage
[775]14 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
[793]15 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
[985]16 29 Feb 08 GKY Use xfree where appropriate
[1075]17 16 JUL 08 GKY Use TMP directory for temp files
[1335]18 10 Dec 08 SHL Integrate exception handler support
[1402]19 08 Mar 09 GKY Removed variable aurguments from docopyf and unlinkf (not used)
20 08 Mar 09 GKY Additional strings move to PCSZs
[123]21
22***********************************************************************/
23
[2]24#include <stdlib.h>
25#include <string.h>
26#include <ctype.h>
[1335]27// #include <process.h> // _beginthread
[328]28
[907]29#define INCL_DOS
30#define INCL_WIN
31#define INCL_LONGLONG
32
[1185]33#include "fm3dll.h"
[1227]34#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
35#include "undel.h"
[1214]36#include "init.h" // Data declaration(s)
37#include "mainwnd.h" // Data declaration(s)
[2]38#include "fm3dlg.h"
39#include "fm3str.h"
[907]40#include "errutil.h" // Dos_Error...
41#include "strutil.h" // GetPString
[1335]42#include "pathutil.h" // BldFullPathName
[1161]43#include "walkem.h" // FillPathListBox
[1185]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
[1038]51#include "fortify.h"
[1335]52#include "excputil.h" // xbeginthread
[2]53
54#pragma data_seg(DATA2)
[328]55
56static PSZ pszSrcFile = __FILE__;
57
[551]58struct tempstruct
59{
[2]60 HWND hwnd;
61 CHAR path[CCHMAXPATH];
62 BOOL inclsubdirs;
63};
64
[551]65static VOID FillUndelListThread(VOID * arg)
[328]66{
[551]67 HWND hwnd;
[1073]68 CHAR s[CCHMAXPATH * 2], szTempFile[CCHMAXPATH];
[551]69 CHAR *path;
70 HAB thab;
71 HMQ thmq;
[2]72 FILE *fp;
[551]73 HFILE oldstdout, newstdout;
[2]74 struct tempstruct *undelinfo;
[551]75 BOOL killme = FALSE;
[847]76 FILESTATUS3 fsa;
[2]77
78 undelinfo = (struct tempstruct *)arg;
79 hwnd = undelinfo->hwnd;
80 path = undelinfo->path;
81 DosError(FERR_DISABLEHARDERR);
82
[1038]83# ifdef FORTIFY
84 Fortify_EnterScope();
[1063]85# endif
[2]86 thab = WinInitialize(0);
[551]87 thmq = WinCreateMsgQueue(thab, 0);
[528]88 if (thab && thmq) {
[551]89 WinCancelShutdown(thmq, TRUE);
[528]90 IncrThreadUsage();
[551]91 WinSendDlgItemMsg(hwnd, UNDEL_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
[1075]92 BldFullPathName(szTempFile, pTmpDir, "$UDELETE.#$#");
[1402]93 unlinkf(szTempFile);
[1073]94 fp = xfopen(szTempFile, "w", pszSrcFile, __LINE__);
[328]95 if (!fp) {
[551]96 Win_Error(NULLHANDLE, hwnd, pszSrcFile, __LINE__,
97 GetPString(IDS_REDIRECTERRORTEXT));
[328]98 killme = TRUE;
99 goto Abort;
100 }
101 else {
[2]102 newstdout = -1;
[551]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;
[2]110 }
111 oldstdout = fileno(stdout);
[551]112 DosDupHandle(fileno(fp), &oldstdout);
[2]113 runemf2(SEPARATE | INVISIBLE | WINDOWED | BACKGROUND | WAIT,
[888]114 hwnd, pszSrcFile, __LINE__,
[551]115 NULL,
116 NULL,
117 "UNDELETE.COM %s /L%s",
118 path, (undelinfo->inclsubdirs) ? " /S" : NullStr);
[2]119 oldstdout = fileno(stdout);
[551]120 DosDupHandle(newstdout, &oldstdout);
[2]121 DosClose(newstdout);
122 fclose(fp);
123 }
[1073]124 fp = xfopen(szTempFile, "r", pszSrcFile, __LINE__);
[328]125 if (fp) {
[551]126 xfgets(s, sizeof(s), fp, pszSrcFile, __LINE__); // Skip 1st line
[406]127 while (!feof(fp)) {
[551]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)) {
[2]133
[551]134 APIRET temp;
[2]135
[551]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,
[1402]145 hwnd, GetPString(IDS_ERRORTEXT), s);
[551]146 if (temp == MBID_YES)
147 runemf2(BACKGROUND | INVISIBLE | SEPARATE | WINDOWED,
[888]148 hwnd, pszSrcFile, __LINE__,
[551]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
[847]160 && DosQueryPathInfo(s, FIL_STANDARD, &fsa,
[551]161 (ULONG) sizeof(fsa)))
162 WinSendDlgItemMsg(hwnd, UNDEL_LISTBOX, LM_INSERTITEM,
163 MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
164 }
[2]165 }
166 fclose(fp);
167 }
[551]168 Abort:
[528]169 ;
170 }
[1073]171 DosForceDelete(szTempFile);
[1009]172 xfree(undelinfo, pszSrcFile, __LINE__);
[528]173 if (thmq) {
[551]174 PostMsg(hwnd, UM_CONTAINER_FILLED, MPVOID, MPVOID);
[528]175 if (killme)
[551]176 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
[2]177 WinDestroyMsgQueue(thmq);
[528]178 }
179 if (thab) {
180 DecrThreadUsage();
[2]181 WinTerminate(thab);
182 }
[1038]183# ifdef FORTIFY
[1063]184 Fortify_LeaveScope();
185# endif
[2]186}
187
[551]188MRESULT EXPENTRY UndeleteDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[328]189{
[551]190 SHORT sSelect;
191 static BOOL listdone, changed = FALSE, refresh = FALSE;
192 static HPOINTER hptrIcon = (HPOINTER) 0;
[2]193
[551]194 switch (msg) {
195 case WM_INITDLG:
196 listdone = TRUE;
[1009]197 if (!mp2 || !*(CHAR *)mp2) {
[1398]198 Runtime_Error(pszSrcFile, __LINE__, NULL);
[551]199 WinDismissDlg(hwnd, 0);
[2]200 break;
[551]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];
[2]208
[1009]209 strcpy(s, (CHAR *)mp2);
[551]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;
[2]220
[551]221 case UM_SETUP:
222 if (listdone) {
[2]223
[551]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);
[1335]245 if (xbeginthread(FillUndelListThread,
246 65536,
247 undelinfo,
248 pszSrcFile,
249 __LINE__) == -1)
250 {
[1039]251 free(undelinfo);
[551]252 listdone = TRUE;
253 WinDismissDlg(hwnd, 0);
[328]254 }
[551]255 else
[771]256 DosSleep(100);//05 Aug 07 GKY 500
[2]257 }
[551]258 refresh = FALSE;
259 }
260 else
261 refresh = TRUE;
262 changed = FALSE;
263 return 0;
[2]264
[551]265 case UM_CONTAINER_FILLED:
266 listdone = TRUE;
267 {
268 CHAR s[33];
[2]269
[551]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;
[2]280
[551]281 case WM_CONTROL:
282 switch (SHORT1FROMMP(mp1)) {
283 case UNDEL_SUBDIRS:
284 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
285 break;
[2]286
[551]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;
[2]296 }
297 break;
298
[551]299 case UNDEL_DRIVELIST:
300 if (!listdone) {
301 Runtime_Error(pszSrcFile, __LINE__, "not listdone");
302 break;
[2]303 }
[551]304 switch (SHORT2FROMMP(mp1)) {
305 case CBN_ENTER:
306 {
307 CHAR s[CCHMAXPATH], drive, *p;
[2]308
[551]309 strset(s, 0);
310 WinQueryDlgItemText(hwnd, UNDEL_DRIVELIST, 3, s);
311 if (!isalpha(*s)) {
[1398]312 Runtime_Error(pszSrcFile, __LINE__, NULL);
[328]313 }
314 else {
[551]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;
[2]342
[551]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;
[2]350
[551]351 default:
352 break;
353 }
354 return 0;
[2]355
[551]356 case WM_ADJUSTWINDOWPOS:
357 PostMsg(hwnd, UM_STRETCH, MPVOID, MPVOID);
358 break;
[2]359
[551]360 case UM_STRETCH:
361 {
362 SWP swpC, swp, swpM, swpD, swpL, swpE;
[2]363
[551]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);
[2]404 }
[551]405 }
406 return 0;
[2]407
[551]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");
[328]414 }
[551]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,
[888]455 hwnd, pszSrcFile, __LINE__,
[551]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 }
[328]472 break;
[2]473
[551]474 case DID_CANCEL:
475 if (!listdone)
476 Runtime_Error(pszSrcFile, __LINE__, "is busy");
477 else
478 WinDismissDlg(hwnd, 0);
[2]479 break;
[551]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;
[2]502 }
[551]503 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]504}
[793]505
506#pragma alloc_text(UNDELETE,FillUndelListThread,UndeleteDlgProc)
Note: See TracBrowser for help on using the repository browser.