source: trunk/dll/dirsize.c@ 153

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

Rework for CNRITEM.szSubject
Use ULONGLONG and CommaFmtULL

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