source: trunk/dll/dirsize.c@ 206

Last change on this file since 206 was 206, checked in by root, 20 years ago

Drop obsoletes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.1 KB
Line 
1
2/***********************************************************************
3
4 $Id: dirsize.c 206 2005-06-08 05:59:59Z root $
5
6 Directory sizes
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2001, 2005 Steven H. Levine
10
11 16 Oct 02 SHL Handle large partitions
12 12 Feb 03 SHL Use CBLIST_TO_EASIZE
13 21 Nov 03 SHL Avoid VAC \ after // bug (wierd)
14 21 Nov 03 SHL Correct minor typos
15 21 Nov 03 SHL Total drives >4GB better
16 24 May 05 SHL Rework for CNRITEM.szSubject
17 25 May 05 SHL Use ULONGLONG and CommaFmtULL
18 26 May 05 SHL More large file formatting updates
19 06 Jun 05 SHL Drop obsoletes
20
21***********************************************************************/
22
23#define INCL_DOS
24#define INCL_WIN
25#define INCL_GPI
26#define INCL_LONGLONG
27#include <os2.h>
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <ctype.h>
33
34#include "fm3dll.h"
35#include "fm3dlg.h"
36#include "fm3str.h"
37
38#pragma alloc_text(DIRSIZE,ProcessDir,FillCnrThread,DirSizeProc)
39#pragma alloc_text(DIRSIZE2,PrintToFile,FillInRecSizes,SortSizeCnr)
40
41typedef struct {
42 CHAR *pszFileName;
43 HWND hwndCnr;
44 CHAR *pchStopFlag;
45 DIRCNRDATA *pDCD;
46} DIRSIZE;
47
48typedef struct {
49 CHAR dirname[CCHMAXPATH];
50 CHAR pchStopFlag;
51 BOOL dying;
52 BOOL working;
53 HPOINTER hptr;
54} TEMP;
55
56
57static SHORT APIENTRY SortSizeCnr (PMINIRECORDCORE p1,PMINIRECORDCORE p2,
58 PVOID SortFlags)
59{
60 ULONG size1,size2;
61
62 size1 = ((PCNRITEM)p1)->cbFile + ((PCNRITEM)p1)->easize;
63 size2 = ((PCNRITEM)p2)->cbFile + ((PCNRITEM)p2)->easize;
64 return (size1 < size2) ? 1 : (size1 == size2) ? 0 : -1;
65}
66
67
68static BOOL ProcessDir(HWND hwndCnr,CHAR *pszFileName,
69 PCNRITEM pciParent,
70 CHAR *pchStopFlag,BOOL top,
71 PULONGLONG pullTotalBytes)
72{
73 CHAR maskstr[CCHMAXPATH];
74 CHAR *pEndMask;
75 register char *p;
76 register char *sp;
77 register char *pp;
78 ULONG nm;
79 ULONGLONG ullCurDirBytes = 0;
80 ULONGLONG ullSubDirBytes = 0;
81 ULONGLONG ull;
82 HDIR hdir;
83 FILEFINDBUF4 *pFFB;
84 APIRET rc;
85 RECORDINSERT ri;
86 PCNRITEM pCI;
87
88 // fixme to report errors
89 *pullTotalBytes = 0; // In case we fail
90
91 pFFB = malloc(sizeof(FILEFINDBUF4) /* * FilesToGet */);
92 if(!pFFB)
93 return FALSE;
94 strcpy(maskstr,pszFileName);
95 if(maskstr[strlen(maskstr) - 1] != '\\')
96 strcat(maskstr,"\\");
97 pEndMask = &maskstr[strlen(maskstr)]; // Point after last backslash
98 strcat(maskstr,"*");
99 //printf("%s\n",maskstr);
100
101 hdir = HDIR_CREATE;
102 nm = 1L;
103 memset(pFFB,0,sizeof(FILEFINDBUF4));
104 DosError(FERR_DISABLEHARDERR);
105 //printf("FIND1\n");
106 rc = DosFindFirst(pszFileName, &hdir,
107 FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
108 FILE_SYSTEM | FILE_HIDDEN | MUST_HAVE_DIRECTORY,
109 pFFB, sizeof(FILEFINDBUF4),&nm, FIL_QUERYEASIZE);
110
111 if(!rc)
112 DosFindClose(hdir);
113
114 /*
115 * the "|| strlen(pszFileName) < 4 below works around an OS/2 bug
116 * that prevents FAT root directories from being found when
117 * requesting EASIZE. sheesh.
118 */
119 if ((!rc && (pFFB->attrFile & FILE_DIRECTORY)) ||
120 strlen(pszFileName) < 4)
121 {
122 if (*pchStopFlag) {
123 free(pFFB);
124 return FALSE;
125 }
126 pCI = WinSendMsg(hwndCnr,CM_ALLOCRECORD,MPFROMLONG(EXTRA_RECORD_BYTES2),
127 MPFROMLONG(1L));
128 if (!pCI) {
129 free(pFFB);
130 return FALSE;
131 }
132 if(!rc) {
133 ullCurDirBytes = pFFB->cbFile;
134 ullCurDirBytes += CBLIST_TO_EASIZE(pFFB->cbList);
135 }
136 else
137 DosError(FERR_DISABLEHARDERR);
138 pCI->pszLongname = pCI->szFileName;
139 pCI->rc.hptrIcon = hptrDir;
140 *pCI->szDispAttr = *pCI->szLongname = *pCI->szSubject = 0;
141 pCI->attrFile = 0L;
142 }
143 else
144 {
145 free(pFFB);
146 Dos_Error(MB_ENTER,
147 rc,
148 HWND_DESKTOP,
149 __FILE__,
150 __LINE__,
151 GetPString(IDS_CANTFINDDIRTEXT),
152 pszFileName);
153 return FALSE;
154 }
155
156 if(strlen(pszFileName) < 4 || top)
157 strcpy(pCI->szFileName,pszFileName);
158 else {
159 p = strrchr(pszFileName,'\\');
160 if(!p)
161 p = pszFileName;
162 else
163 p++;
164 sp = (strchr(pszFileName,' ') != NULL) ? "\"" : NullStr;
165 pp = pCI->szFileName;
166 if(*sp) {
167 *pp = *sp;
168 pp++;
169 *pp = 0;
170 }
171 strcpy(pp,p);
172 if(*sp)
173 strcat(pp,sp);
174 }
175 pCI->pszFileName = pCI->szFileName + strlen(pCI->szFileName);
176 pCI->rc.pszIcon = pCI->pszLongname;
177 pCI->rc.flRecordAttr |= CRA_RECORDREADONLY;
178 if(fForceUpper)
179 strupr(pCI->szFileName);
180 else if(fForceLower)
181 strlwr(pCI->szFileName);
182 memset(&ri,0,sizeof(RECORDINSERT));
183 ri.cb = sizeof(RECORDINSERT);
184 ri.pRecordOrder = (PRECORDCORE)CMA_END;
185 ri.pRecordParent = (PRECORDCORE)pciParent;
186 ri.zOrder = (USHORT)CMA_TOP;
187 ri.cRecordsInsert = 1L;
188 ri.fInvalidateRecord = TRUE;
189 //printf("CM_INSERTRECORD\n");
190 if(!WinSendMsg(hwndCnr,CM_INSERTRECORD,MPFROMP(pCI),MPFROMP(&ri))) {
191 //printf("Insert failed\n");
192 free(pFFB);
193 return FALSE;
194 }
195 hdir = HDIR_CREATE;
196 nm = 1L;
197 //printf("FIND2\n");
198 rc = DosFindFirst(maskstr,&hdir,
199 FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
200 FILE_SYSTEM | FILE_HIDDEN | FILE_DIRECTORY,
201 pFFB,
202 sizeof(FILEFINDBUF4),
203 &nm,
204 FIL_QUERYEASIZE);
205 if(!rc)
206 {
207 register PBYTE fb = (PBYTE)pFFB;
208 FILEFINDBUF4 *pffbFile;
209 ULONG x;
210
211 while(!rc)
212 {
213 priority_normal();
214 //printf("Found %lu\n",nm);
215 for(x = 0L;x < nm;x++)
216 {
217 pffbFile = (FILEFINDBUF4 *)fb;
218 //printf("%s\n",pffbFile->achName);
219 //fflush(stdout);
220 // Total size skipping . and ..
221 if((*pffbFile->achName != '.' ||
222 (pffbFile->achName[1] && pffbFile->achName[1] != '.')) ||
223 !(pffbFile->attrFile & FILE_DIRECTORY))
224 {
225 ullCurDirBytes += pffbFile->cbFile;
226 ullCurDirBytes += CBLIST_TO_EASIZE(pffbFile->cbList) & 0x3ff;
227
228 if(!(pffbFile->attrFile & FILE_DIRECTORY))
229 pCI->attrFile++; // Bump file count
230 if(*pchStopFlag)
231 break;
232 if(pffbFile->attrFile & FILE_DIRECTORY) {
233 // Recurse into subdir
234 strcpy(pEndMask,pffbFile->achName); // Append dirname to base dirname
235 if(!*pchStopFlag)
236 {
237 ProcessDir(hwndCnr,maskstr,pCI,pchStopFlag,FALSE,&ull);
238 ullSubDirBytes += ull;
239 }
240 }
241 }
242 if(!pffbFile->oNextEntryOffset)
243 break;
244 fb += pffbFile->oNextEntryOffset;
245 } // for matches
246 if(*pchStopFlag)
247 break;
248 DosSleep(0L);
249 nm = 1L; /* FilesToGet */
250 rc = DosFindNext(hdir,pFFB,sizeof(FILEFINDBUF4) ,&nm);
251 } // while more found
252 DosFindClose(hdir);
253 priority_normal();
254 }
255
256 free(pFFB);
257
258 pCI->cbFile = ullCurDirBytes;
259 pCI->easize = ullSubDirBytes; // hack cough
260 WinSendMsg(hwndCnr,CM_INVALIDATERECORD,MPFROMP(&pCI),
261 MPFROM2SHORT(1,CMA_ERASE | CMA_TEXTCHANGED));
262
263 *pullTotalBytes = ullCurDirBytes + ullSubDirBytes;
264 return TRUE;
265}
266
267
268static VOID FillInRecSizes (HWND hwndCnr,PCNRITEM pciParent,ULONGLONG ullTotalBytes,
269 CHAR *pchStopFlag,BOOL isroot)
270{
271 PCNRITEM pCI = pciParent;
272 SHORT attrib = CMA_FIRSTCHILD;
273
274 if(pCI) {
275
276 float fltPct = 0.0;
277 CHAR szCurDir[80];
278 CHAR szSubDir[80];
279 CHAR szAllDir[80];
280 CHAR szBar[80];
281
282 // cbFile = currect directory usage in bytes
283 // easize = subdirectory usage in bytes
284 CommaFmtULL(szCurDir,sizeof(szCurDir),pCI->cbFile,'K');
285 *szBar = 0;
286
287 if (ullTotalBytes)
288 {
289 register UINT cBar;
290
291 if(isroot)
292 {
293 FSALLOCATE fsa;
294 APIRET rc;
295
296 memset(&fsa,0,sizeof(fsa));
297 rc = DosQueryFSInfo(toupper(*pCI->szFileName) - '@',FSIL_ALLOC,&fsa,
298 sizeof(FSALLOCATE));
299 if (!rc)
300 {
301 fltPct = (ullTotalBytes * 100.0) /
302 ((float)fsa.cUnit * (fsa.cSectorUnit * fsa.cbSector));
303 }
304 pCI->szLongname[1] = 1; // Flag root - hack cough
305 }
306 else
307 fltPct = (((float)pCI->cbFile + pCI->easize) * 100.0) / ullTotalBytes;
308
309 cBar = (UINT)fltPct / 2;
310 if (cBar)
311 memset(szBar, '#', cBar);
312 if(cBar * 2 != (UINT)fltPct) {
313 szBar[cBar] = '=';
314 cBar++;
315 }
316 if (cBar < 50)
317 memset(szBar + cBar, ' ', 50 - cBar);
318 szBar[50] = 0;
319 }
320
321 pCI->flags = (ULONG)fltPct;
322 CommaFmtULL(szSubDir,sizeof(szSubDir),pCI->easize,'K');
323 CommaFmtULL(szAllDir,sizeof(szAllDir),pCI->cbFile + pCI->easize,'K');
324 sprintf(&pCI->szFileName[strlen(pCI->szFileName)],
325 " %s + %s = %s (%.02lf%%%s)\r%s",
326 szCurDir,
327 szSubDir,
328 szAllDir,
329 fltPct,
330 isroot ? GetPString(IDS_OFDRIVETEXT) : NullStr,
331 szBar);
332 WinSendMsg(hwndCnr,
333 CM_INVALIDATERECORD,
334 MPFROMP(&pCI),
335 MPFROM2SHORT(1,0));
336 isroot = FALSE;
337 }
338 else
339 attrib = CMA_FIRST;
340 pCI = (PCNRITEM)WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(pCI),
341 MPFROM2SHORT(attrib,CMA_ITEMORDER));
342 while(pCI && (INT)pCI != -1) {
343 if(*pchStopFlag)
344 break;
345 FillInRecSizes(hwndCnr,pCI,ullTotalBytes,pchStopFlag,isroot);
346 isroot = FALSE;
347 pCI = (PCNRITEM)WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(pCI),
348 MPFROM2SHORT(CMA_NEXT,CMA_ITEMORDER));
349 }
350}
351
352
353static VOID PrintToFile (HWND hwndCnr,ULONG indent,PCNRITEM pciParent,
354 FILE *fp)
355{
356 PCNRITEM pci;
357 register CHAR *p;
358
359 if(!pciParent) {
360 pciParent = WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(NULL),
361 MPFROM2SHORT(CMA_FIRST,CMA_ITEMORDER));
362 indent = 0;
363 }
364 if(pciParent) {
365 p = strchr(pciParent->szFileName,'\r');
366 if(p)
367 *p = 0;
368 fprintf(fp,"%*.*s%s %lu %s%s\n",
369 indent * 2,indent * 2," ",
370 pciParent->szFileName,
371 pciParent->attrFile,
372 GetPString(IDS_FILETEXT),
373 &"s"[pciParent->attrFile == 1]);
374 if(p)
375 *p = '\r';
376 if(pciParent->rc.flRecordAttr & CRA_EXPANDED) {
377 pci = (PCNRITEM)WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(pciParent),
378 MPFROM2SHORT(CMA_FIRSTCHILD,CMA_ITEMORDER));
379 while(pci && (INT)pci != -1) {
380 DosSleep(0L);
381 PrintToFile(hwndCnr,indent + 1,pci,fp);
382 pci = (PCNRITEM)WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(pci),
383 MPFROM2SHORT(CMA_NEXT,CMA_ITEMORDER));
384 }
385 }
386 }
387}
388
389
390static VOID FillCnrThread (VOID *args)
391{
392 HAB hab;
393 HMQ hmq;
394 DIRSIZE *dirsize = (DIRSIZE *)args;
395 HWND hwndCnr;
396 ULONGLONG ull;
397
398 if(!dirsize)
399 return;
400 hwndCnr = dirsize->hwndCnr;
401
402 DosError(FERR_DISABLEHARDERR);
403
404 // priority_normal();
405 hab = WinInitialize(0);
406 if(hab)
407 {
408 hmq = WinCreateMsgQueue(hab,0);
409 if(hmq)
410 {
411 WinCancelShutdown(hmq,TRUE);
412 ProcessDir(hwndCnr,dirsize->pszFileName,
413 (PCNRITEM)NULL,dirsize->pchStopFlag,TRUE,&ull);
414 DosPostEventSem(CompactSem);
415 WinEnableWindowUpdate(hwndCnr,FALSE);
416 FillInRecSizes(hwndCnr,NULL,ull,dirsize->pchStopFlag,TRUE);
417 WinEnableWindowUpdate(hwndCnr,TRUE);
418 WinSendMsg(hwndCnr,CM_INVALIDATERECORD,MPVOID,
419 MPFROM2SHORT(0,CMA_ERASE | CMA_TEXTCHANGED));
420 WinDestroyMsgQueue(hmq);
421 }
422 WinTerminate(hab);
423 }
424 PostMsg(WinQueryWindow(hwndCnr,QW_PARENT),
425 UM_CONTAINER_FILLED,
426 MPVOID,MPVOID);
427 free(dirsize);
428}
429
430
431MRESULT EXPENTRY DirSizeProc (HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
432{
433 TEMP *pTemp;
434
435 switch(msg) {
436 case WM_INITDLG:
437 if(!mp2) {
438 WinDismissDlg(hwnd,0);
439 break;
440 }
441 pTemp = malloc(sizeof(TEMP));
442 if(!pTemp) {
443 WinDismissDlg(hwnd,0);
444 break;
445 }
446 memset(pTemp,0,sizeof(TEMP));
447 strcpy(pTemp->dirname,(CHAR *)mp2);
448 WinSetWindowPtr(hwnd,0,(PVOID)pTemp);
449 pTemp->hptr = WinLoadPointer(HWND_DESKTOP,FM3ModHandle,DIRSIZE_ICON);
450 WinDefDlgProc(hwnd,WM_SETICON,MPFROMLONG(pTemp->hptr),MPVOID);
451 {
452 CHAR s[CCHMAXPATH + 81];
453
454 sprintf(s,
455 GetPString(IDS_DIRSIZETITLETEXT),
456 pTemp->dirname);
457 WinSetWindowText(hwnd,s);
458 }
459 {
460 DIRSIZE *dirsize;
461
462 dirsize = malloc(sizeof(DIRSIZE));
463 if(!dirsize) {
464 WinDismissDlg(hwnd,0);
465 break;
466 }
467 dirsize->pchStopFlag = (CHAR *)&pTemp->pchStopFlag;
468 dirsize->pszFileName = pTemp->dirname;
469 dirsize->hwndCnr = WinWindowFromID(hwnd,DSZ_CNR);
470 if(_beginthread(FillCnrThread,NULL,122880L * 5L,(PVOID)dirsize) == -1) {
471 free(dirsize);
472 WinDismissDlg(hwnd,0);
473 break;
474 }
475 pTemp->working = TRUE;
476 }
477 PostMsg(hwnd,UM_SETUP,MPVOID,MPVOID);
478 break;
479
480 case UM_SETUP:
481 {
482 CNRINFO cnri;
483 FSALLOCATE fsa;
484 APIRET rc;
485
486 memset(&cnri,0,sizeof(CNRINFO));
487 cnri.cb = sizeof(CNRINFO);
488 WinSendDlgItemMsg(hwnd,DSZ_CNR,CM_QUERYCNRINFO,
489 MPFROMP(&cnri),MPFROMLONG(sizeof(CNRINFO)));
490 cnri.cyLineSpacing = 0;
491 cnri.cxTreeIndent = 12L;
492 cnri.flWindowAttr = CV_TREE | CV_FLOW | CA_TREELINE | CA_OWNERDRAW;
493 WinSendDlgItemMsg(hwnd,DSZ_CNR,CM_SETCNRINFO,MPFROMP(&cnri),
494 MPFROMLONG(CMA_FLWINDOWATTR | CMA_TREEICON |
495 CMA_LINESPACING | CMA_CXTREEINDENT));
496 pTemp = INSTDATA(hwnd);
497 if(pTemp && isalpha(*pTemp->dirname)) {
498 memset(&fsa,0,sizeof(fsa));
499 rc = DosQueryFSInfo(toupper(*pTemp->dirname) - '@',FSIL_ALLOC,&fsa,
500 sizeof(FSALLOCATE));
501 if (!rc)
502 {
503
504 CHAR s[132],tf[80],tb[80],tu[80];
505
506 CommaFmtULL(tf,sizeof(tf),
507 (ULONGLONG)fsa.cUnitAvail *
508 (fsa.cSectorUnit * fsa.cbSector),'M');
509 CommaFmtULL(tb,sizeof(tb),
510 (ULONGLONG)fsa.cUnit *
511 (fsa.cSectorUnit * fsa.cbSector),'M');
512 CommaFmtULL(tu,sizeof(tu),
513 (ULONGLONG)(fsa.cUnit - fsa.cUnitAvail) *
514 (fsa.cSectorUnit * fsa.cbSector),'M');
515 sprintf(s,
516 GetPString(IDS_FREESPACETEXT),
517 tf,
518 tb,
519 tu);
520 WinSetDlgItemText(hwnd,
521 DSZ_FREESPACE,
522 s);
523 }
524 else
525 WinSetDlgItemText(hwnd,
526 DSZ_FREESPACE,
527 GetPString(IDS_FREESPACEUTEXT));
528 }
529 }
530 return 0;
531
532 case UM_CONTAINER_FILLED:
533 pTemp = INSTDATA(hwnd);
534 if(!pTemp || pTemp->dying) {
535 if (pTemp)
536 pTemp->working = FALSE;
537 WinDismissDlg(hwnd,0);
538 return 0;
539 }
540 pTemp->working = FALSE;
541 {
542 CHAR tb[44],s[66];
543 PCNRITEM pci;
544
545 pci = WinSendDlgItemMsg(hwnd,DSZ_CNR,CM_QUERYRECORD,MPVOID,
546 MPFROM2SHORT(CMA_FIRST,CMA_ITEMORDER));
547 if(pci && (INT)pci != -1)
548 WinSendDlgItemMsg(hwnd,DSZ_CNR,CM_EXPANDTREE,MPFROMP(pci),MPVOID);
549 *s = 0;
550 pci = WinSendDlgItemMsg(hwnd,DSZ_CNR,CM_QUERYRECORDEMPHASIS,
551 MPFROMLONG(CMA_FIRST),
552 MPFROMSHORT(CRA_CURSORED));
553 if (pci && (INT)pci != -1)
554 {
555 commafmt(tb,sizeof(tb),pci->attrFile);
556 sprintf(s,
557 "%s %s%s",
558 tb,
559 GetPString(IDS_FILETEXT),
560 &"s"[pci->attrFile == 1]);
561 }
562 WinSetDlgItemText(hwnd,DSZ_NUMFILES,s);
563 }
564 WinSendDlgItemMsg(hwnd,DSZ_CNR,CM_SORTRECORD,MPFROMP(SortSizeCnr),
565 MPVOID);
566 DosBeep(500,25);
567 return 0;
568
569 case WM_ADJUSTWINDOWPOS:
570 PostMsg(hwnd,UM_STRETCH,MPVOID,MPVOID);
571 break;
572
573 case UM_STRETCH:
574 {
575 SWP swpC,swp;
576
577 WinQueryWindowPos(hwnd,&swp);
578 if(!(swp.fl & (SWP_HIDE | SWP_MINIMIZE))) {
579 WinQueryWindowPos(WinWindowFromID(hwnd,DSZ_CNR),&swpC);
580 WinSetWindowPos(WinWindowFromID(hwnd,DSZ_CNR),HWND_TOP,
581 SysVal(SV_CXSIZEBORDER),
582 swpC.y,
583 swp.cx - (SysVal(SV_CXSIZEBORDER) * 2),
584 (swp.cy - swpC.y) - (SysVal(SV_CYTITLEBAR) +
585 SysVal(SV_CYSIZEBORDER)),
586 SWP_MOVE | SWP_SIZE);
587 }
588 }
589 return 0;
590
591 case WM_DRAWITEM:
592 if(mp2) {
593
594 OWNERITEM *oi = mp2;
595 CNRDRAWITEMINFO *cnd;
596 PCNRITEM pci;
597
598 if(oi->idItem == CMA_TEXT) {
599 cnd = (CNRDRAWITEMINFO *)oi->hItem;
600 if(cnd) {
601 pci = (PCNRITEM)cnd->pRecord;
602 if(pci) {
603
604 POINTL aptl[TXTBOX_COUNT],ptl;
605 CHAR *p;
606 LONG clr,x;
607
608 p = strchr(pci->szFileName,'\r');
609 if(p) {
610 /* draw text */
611 if (!pci->cbFile) /* no size */
612 GpiSetColor(oi->hps,CLR_DARKGRAY);
613 else if (!pci->easize) /* no size below */
614 GpiSetColor(oi->hps,CLR_DARKBLUE);
615 else
616 GpiSetColor(oi->hps,CLR_BLACK);
617 GpiSetBackMix(oi->hps,BM_LEAVEALONE);
618 GpiSetMix(oi->hps,FM_OVERPAINT);
619 *p = 0;
620 GpiQueryTextBox(oi->hps,strlen(pci->szFileName),
621 pci->szFileName,TXTBOX_COUNT,aptl);
622 ptl.x = oi->rclItem.xLeft;
623 ptl.y = (oi->rclItem.yTop - aptl[TXTBOX_TOPRIGHT].y);
624 GpiMove(oi->hps,&ptl);
625 GpiCharString(oi->hps,strlen(pci->szFileName),
626 pci->szFileName);
627 *p = '\r';
628
629 /* draw the graph box */
630 GpiQueryTextBox(oi->hps,1,"#",TXTBOX_COUNT,aptl);
631 /* draw black outline */
632 GpiSetColor(oi->hps,CLR_BLACK);
633 ptl.x = oi->rclItem.xLeft;
634 ptl.y = oi->rclItem.yBottom + 2;
635 GpiMove(oi->hps,&ptl);
636 ptl.x = oi->rclItem.xLeft + 101;
637 ptl.y = (oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y);
638 GpiBox(oi->hps,DRO_OUTLINE,&ptl,0,0);
639 /* fill with gray */
640 GpiSetColor(oi->hps,CLR_PALEGRAY);
641 ptl.x = oi->rclItem.xLeft + 1;
642 ptl.y = oi->rclItem.yBottom + 3;
643 GpiMove(oi->hps,&ptl);
644 ptl.x = oi->rclItem.xLeft + 100;
645 ptl.y = (oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y) - 1;
646 GpiBox(oi->hps,DRO_OUTLINEFILL,&ptl,0,0);
647
648 /* draw shadow at bottom & right sides */
649 GpiSetColor(oi->hps,CLR_DARKGRAY);
650 ptl.x = oi->rclItem.xLeft + 1;
651 ptl.y = oi->rclItem.yBottom + 3;
652 GpiMove(oi->hps,&ptl);
653 ptl.x = oi->rclItem.xLeft + 100;
654 GpiLine(oi->hps,&ptl);
655 ptl.y = (oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y) - 1;
656 GpiLine(oi->hps,&ptl);
657
658 /* draw highlight at top and left sides */
659 GpiSetColor(oi->hps,CLR_WHITE);
660 ptl.x = oi->rclItem.xLeft + 1;
661 GpiLine(oi->hps,&ptl);
662 ptl.y = oi->rclItem.yBottom + 3;
663 GpiLine(oi->hps,&ptl);
664
665 /* draw shadow of box */
666 GpiSetColor(oi->hps,CLR_DARKGRAY);
667 ptl.x = oi->rclItem.xLeft + 2;
668 ptl.y = oi->rclItem.yBottom;
669 GpiMove(oi->hps,&ptl);
670 ptl.x = oi->rclItem.xLeft + 103;
671 GpiLine(oi->hps,&ptl);
672 ptl.y = (oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y) - 2;
673 GpiLine(oi->hps,&ptl);
674 ptl.x--;
675 GpiMove(oi->hps,&ptl);
676 ptl.y = oi->rclItem.yBottom + 1;
677 GpiLine(oi->hps,&ptl);
678 ptl.x = oi->rclItem.xLeft + 2;
679 GpiLine(oi->hps,&ptl);
680
681 /* fill box with graph bar, flags is integer % */
682 if(pci->flags) {
683 if(pci->szLongname[1] == 1) /* is root record */
684 GpiSetColor(oi->hps,CLR_DARKGREEN);
685 else
686 GpiSetColor(oi->hps,CLR_RED);
687 ptl.x = oi->rclItem.xLeft + 1;
688 ptl.y = oi->rclItem.yBottom + 3;
689 GpiMove(oi->hps,&ptl);
690 ptl.x = oi->rclItem.xLeft + pci->flags;
691 ptl.y = (oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y) - 1;
692 GpiBox(oi->hps,DRO_OUTLINEFILL,&ptl,0,0);
693
694 /* draw highlights and shadows on graph */
695 if(pci->szLongname[1] == 1)
696 GpiSetColor(oi->hps,CLR_GREEN);
697 else
698 GpiSetColor(oi->hps,CLR_PALEGRAY);
699 if(pci->flags > 5) {
700 ptl.x = oi->rclItem.xLeft + 1;
701 ptl.y = oi->rclItem.yBottom + 3;
702 GpiMove(oi->hps,&ptl);
703 ptl.y = (oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y) - 1;
704 GpiLine(oi->hps,&ptl);
705 }
706 else {
707 ptl.y = (oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y) - 1;
708 GpiMove(oi->hps,&ptl);
709 }
710 ptl.x = oi->rclItem.xLeft + pci->flags;
711 GpiLine(oi->hps,&ptl);
712 if(pci->szLongname[1] != 1) {
713 GpiSetColor(oi->hps,CLR_DARKRED);
714 ptl.x = oi->rclItem.xLeft + 2;
715 ptl.y = oi->rclItem.yBottom + 3;
716 GpiMove(oi->hps,&ptl);
717 ptl.x = oi->rclItem.xLeft + pci->flags;
718 GpiLine(oi->hps,&ptl);
719 }
720 }
721
722 /* draw hash marks in box */
723 GpiSetColor(oi->hps,CLR_WHITE);
724 clr = CLR_WHITE;
725 for(x = 1;x < 10;x++) {
726 if(clr == CLR_WHITE && x * 10 > pci->flags) {
727 clr = CLR_BLACK;
728 GpiSetColor(oi->hps,CLR_BLACK);
729 }
730 ptl.x = (oi->rclItem.xLeft + 1) + (x * 10);
731 ptl.y = oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y - 1;
732 GpiMove(oi->hps,&ptl);
733 switch(x) {
734 case 1:
735 case 3:
736 case 7:
737 case 9:
738 ptl.y -= 1;
739 break;
740 case 5:
741 ptl.y -= 4;
742 break;
743 case 2:
744 case 4:
745 case 6:
746 case 8:
747 ptl.y -= 2;
748 break;
749 }
750 GpiLine(oi->hps,&ptl);
751 }
752 return MRFROMLONG(TRUE);
753 }
754 }
755 }
756 }
757 }
758 return FALSE;
759
760 case WM_CONTROL:
761 switch(SHORT2FROMMP(mp1)) {
762 case CN_ENTER:
763 if(mp2) {
764
765 PCNRITEM pci = (PCNRITEM)((PNOTIFYRECORDENTER)mp2)->pRecord;
766 CHAR pszFileName[CCHMAXPATH],szTemp[CCHMAXPATH];
767
768 if(pci) {
769 *pszFileName = 0;
770 while(pci && (INT)pci != -1) {
771 memset(szTemp,0,sizeof(szTemp));
772 strncpy(szTemp,pci->szFileName,
773 pci->pszFileName - pci->szFileName);
774 strrev(szTemp);
775 if(*pszFileName && *szTemp != '\\')
776 strcat(pszFileName,"\\");
777 strcat(pszFileName,szTemp);
778 pci = WinSendDlgItemMsg(hwnd,DSZ_CNR,CM_QUERYRECORD,
779 MPFROMP(pci),
780 MPFROM2SHORT(CMA_PARENT,
781 CMA_ITEMORDER));
782 }
783 strrev(pszFileName);
784 if(!fVTreeOpensWPS)
785 OpenDirCnr((HWND)0,
786 (hwndMain) ? hwndMain : HWND_DESKTOP,
787 hwnd,
788 FALSE,
789 pszFileName);
790 else {
791
792 ULONG size = sizeof(ULONG),flWindowAttr = CV_ICON;
793 CHAR s[33];
794
795 strcpy(s,"ICON");
796 PrfQueryProfileData(fmprof,appname,"DirflWindowAttr",
797 (PVOID)&flWindowAttr,&size);
798 if(flWindowAttr & CV_DETAIL) {
799 if(IsRoot(pszFileName))
800 strcpy(s,"TREE");
801 else
802 strcpy(s,"DETAILS");
803 }
804 OpenObject(pszFileName,s,hwnd);
805 }
806 }
807 }
808 break;
809 case CN_EMPHASIS:
810 pTemp = INSTDATA(hwnd);
811 if(pTemp && !pTemp->working && mp2) {
812
813 PNOTIFYRECORDEMPHASIS pre = mp2;
814 PCNRITEM pci;
815 CHAR tb[44],s[66];
816
817 pci = (PCNRITEM)((pre) ? pre->pRecord : NULL);
818 if(pci && (pre->fEmphasisMask & CRA_SELECTED) &&
819 (pci->rc.flRecordAttr & CRA_SELECTED)) {
820 commafmt(tb,sizeof(tb),pci->attrFile);
821 sprintf(s,
822 "%s %s%s",
823 tb,
824 GetPString(IDS_FILETEXT),
825 &"s"[pci->attrFile == 1]);
826 WinSetDlgItemText(hwnd,
827 DSZ_NUMFILES,
828 s);
829 }
830 }
831 break;
832 }
833 return 0;
834
835 case WM_COMMAND:
836 switch(SHORT1FROMMP(mp1)) {
837 case IDM_HELP:
838 if(hwndHelp)
839 WinSendMsg(hwndHelp,HM_DISPLAY_HELP,
840 MPFROM2SHORT(HELP_DIRSIZE,0),
841 MPFROMSHORT(HM_RESOURCEID));
842 break;
843
844 case DSZ_PRINT:
845 pTemp = INSTDATA(hwnd);
846 if(pTemp && !pTemp->working) {
847
848 CHAR pszFileName[CCHMAXPATH];
849 FILE *fp;
850
851 save_dir2(pszFileName);
852 sprintf(&pszFileName[strlen(pszFileName)],"\\%csizes.Rpt",
853 (pTemp) ? toupper(*pTemp->dirname) : '+');
854 if(export_filename(hwnd,pszFileName,FALSE) && *pszFileName) {
855 if(stricmp(pszFileName,"PRN") &&
856 strnicmp(pszFileName,"\\DEV\\LPT",8) &&
857 !strchr(pszFileName,'.'))
858 strcat(pszFileName,".RPT");
859 fp = fopen(pszFileName,"a+");
860 if(fp) {
861 WinSetPointer(HWND_DESKTOP,hptrBusy);
862 PrintToFile(WinWindowFromID(hwnd,DSZ_CNR),0,NULL,fp);
863 fclose(fp);
864 WinSetPointer(HWND_DESKTOP,hptrArrow);
865 }
866 else
867 saymsg(MB_CANCEL,
868 hwnd,
869 GetPString(IDS_ERRORTEXT),
870 GetPString(IDS_COMPCANTOPENTEXT),
871 pszFileName);
872 }
873 }
874 else
875 DosBeep(50,100);
876 break;
877
878 case DSZ_EXPAND:
879 case DSZ_COLLAPSE:
880 {
881 PCNRITEM pci;
882
883 pci = (PCNRITEM)WinSendDlgItemMsg(hwnd,DSZ_CNR,
884 CM_QUERYRECORDEMPHASIS,
885 MPFROMLONG(CMA_FIRST),
886 MPFROMSHORT(CRA_CURSORED));
887 if(pci)
888 ExpandAll(WinWindowFromID(hwnd,DSZ_CNR),
889 (SHORT1FROMMP(mp1) == DSZ_EXPAND),pci);
890 }
891 break;
892
893 case DID_OK:
894 case DID_CANCEL:
895 pTemp = INSTDATA(hwnd);
896 if(pTemp) {
897 if(pTemp->working) {
898 pTemp->dying = TRUE;
899 pTemp->pchStopFlag = 0xff;
900 DosBeep(1000,100);
901 }
902 else
903 WinDismissDlg(hwnd,0);
904 }
905 break;
906 }
907 return 0;
908
909 case WM_CLOSE:
910 pTemp = INSTDATA(hwnd);
911 if(pTemp)
912 pTemp->pchStopFlag = 0xff;
913 DosSleep(1L);
914 break;
915
916 case WM_DESTROY:
917 pTemp = INSTDATA(hwnd);
918 if(pTemp) {
919 pTemp->pchStopFlag = 0xff;
920 if(pTemp->hptr)
921 WinDestroyPointer(pTemp->hptr);
922 DosSleep(33L);
923 free(pTemp);
924 }
925 DosPostEventSem(CompactSem);
926 break;
927 }
928 return WinDefDlgProc(hwnd,msg,mp1,mp2);
929}
Note: See TracBrowser for help on using the repository browser.