source: trunk/dll/dirsize.c@ 224

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

More 64-bit math fixes

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