source: trunk/dll/undel.c@ 1505

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

Improved drivebar changes; Added AddBackslashToPath() to remove repeatative code. replaced "
" with PCSZ variable; ANY_OBJ added the DosAlloc... (experimental)

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