source: trunk/dll/dirsize.c@ 176

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

More large file formatting updates

  • 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 176 2005-05-28 17:41:08Z 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
20***********************************************************************/
21
22#define INCL_DOS
23#define INCL_WIN
24#define INCL_GPI
25#define INCL_LONGLONG
26#include <os2.h>
27
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#include <ctype.h>
32
33#include "fm3dll.h"
34#include "fm3dlg.h"
35#include "fm3str.h"
36
37#pragma alloc_text(DIRSIZE,ProcessDir,FillCnrThread,DirSizeProc)
38#pragma alloc_text(DIRSIZE2,PrintToFile,FillInRecSizes,SortSizeCnr)
39
40typedef struct {
41 CHAR *pszFileName;
42 HWND hwndCnr;
43 CHAR *pchStopFlag;
44 DIRCNRDATA *pDCD;
45} DIRSIZE;
46
47typedef struct {
48 CHAR dirname[CCHMAXPATH];
49 CHAR pchStopFlag;
50 BOOL dying;
51 BOOL working;
52 HPOINTER hptr;
53} TEMP;
54
55
56static SHORT APIENTRY SortSizeCnr (PMINIRECORDCORE p1,PMINIRECORDCORE p2,
57 PVOID SortFlags)
58{
59 ULONG size1,size2;
60
61 size1 = ((PCNRITEM)p1)->cbFile + ((PCNRITEM)p1)->easize;
62 size2 = ((PCNRITEM)p2)->cbFile + ((PCNRITEM)p2)->easize;
63 return (size1 < size2) ? 1 : (size1 == size2) ? 0 : -1;
64}
65
66
67static BOOL ProcessDir(HWND hwndCnr,CHAR *pszFileName,
68 PCNRITEM pciParent,
69 CHAR *pchStopFlag,BOOL top,
70 PULONGLONG pullTotalBytes)
71{
72 CHAR maskstr[CCHMAXPATH];
73 CHAR *pEndMask;
74 register char *p;
75 register char *sp;
76 register char *pp;
77 ULONG nm;
78 ULONGLONG ullCurDirBytes = 0;
79 ULONGLONG ullSubDirBytes = 0;
80 ULONGLONG ull;
81 HDIR hdir;
82 FILEFINDBUF4 *pFFB;
83 APIRET rc;
84 RECORDINSERT ri;
85 PCNRITEM pCI;
86
87 // fixme to report errors
88 *pullTotalBytes = 0; // In case we fail
89
90 pFFB = malloc(sizeof(FILEFINDBUF4) /* * FilesToGet */);
91 if(!pFFB)
92 return FALSE;
93 strcpy(maskstr,pszFileName);
94 if(maskstr[strlen(maskstr) - 1] != '\\')
95 strcat(maskstr,"\\");
96 pEndMask = &maskstr[strlen(maskstr)]; // Point after last backslash
97 strcat(maskstr,"*");
98 //printf("%s\n",maskstr);
99
100 hdir = HDIR_CREATE;
101 nm = 1L;
102 memset(pFFB,0,sizeof(FILEFINDBUF4));
103 DosError(FERR_DISABLEHARDERR);
104 //printf("FIND1\n");
105 rc = DosFindFirst(pszFileName, &hdir,
106 FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
107 FILE_SYSTEM | FILE_HIDDEN | MUST_HAVE_DIRECTORY,
108 pFFB, sizeof(FILEFINDBUF4),&nm, FIL_QUERYEASIZE);
109
110 if(!rc)
111 DosFindClose(hdir);
112
113 /*
114 * the "|| strlen(pszFileName) < 4 below works around an OS/2 bug
115 * that prevents FAT root directories from being found when
116 * requesting EASIZE. sheesh.
117 */
118 if ((!rc && (pFFB->attrFile & FILE_DIRECTORY)) ||
119 strlen(pszFileName) < 4)
120 {
121 if (*pchStopFlag) {
122 free(pFFB);
123 return FALSE;
124 }
125 pCI = WinSendMsg(hwndCnr,CM_ALLOCRECORD,MPFROMLONG(EXTRA_RECORD_BYTES2),
126 MPFROMLONG(1L));
127 if (!pCI) {
128 free(pFFB);
129 return FALSE;
130 }
131 if(!rc) {
132 ullCurDirBytes = pFFB->cbFile;
133 ullCurDirBytes += CBLIST_TO_EASIZE(pFFB->cbList);
134 }
135 else
136 DosError(FERR_DISABLEHARDERR);
137 pCI->pszLongname = pCI->szFileName;
138 pCI->rc.hptrIcon = hptrDir;
139 *pCI->szDispAttr = *pCI->szLongname = *pCI->szSubject = 0;
140 pCI->attrFile = 0L;
141 }
142 else
143 {
144 free(pFFB);
145 Dos_Error(MB_ENTER,
146 rc,
147 HWND_DESKTOP,
148 __FILE__,
149 __LINE__,
150 GetPString(IDS_CANTFINDDIRTEXT),
151 pszFileName);
152 return FALSE;
153 }
154
155 if(strlen(pszFileName) < 4 || top)
156 strcpy(pCI->szFileName,pszFileName);
157 else {
158 p = strrchr(pszFileName,'\\');
159 if(!p)
160 p = pszFileName;
161 else
162 p++;
163 sp = (strchr(pszFileName,' ') != NULL) ? "\"" : NullStr;
164 pp = pCI->szFileName;
165 if(*sp) {
166 *pp = *sp;
167 pp++;
168 *pp = 0;
169 }
170 strcpy(pp,p);
171 if(*sp)
172 strcat(pp,sp);
173 }
174 pCI->pszFileName = pCI->szFileName + strlen(pCI->szFileName);
175 pCI->rc.pszIcon = pCI->pszLongname;
176 pCI->rc.flRecordAttr |= CRA_RECORDREADONLY;
177 if(fForceUpper)
178 strupr(pCI->szFileName);
179 else if(fForceLower)
180 strlwr(pCI->szFileName);
181 memset(&ri,0,sizeof(RECORDINSERT));
182 ri.cb = sizeof(RECORDINSERT);
183 ri.pRecordOrder = (PRECORDCORE)CMA_END;
184 ri.pRecordParent = (PRECORDCORE)pciParent;
185 ri.zOrder = (USHORT)CMA_TOP;
186 ri.cRecordsInsert = 1L;
187 ri.fInvalidateRecord = TRUE;
188 //printf("CM_INSERTRECORD\n");
189 if(!WinSendMsg(hwndCnr,CM_INSERTRECORD,MPFROMP(pCI),MPFROMP(&ri))) {
190 //printf("Insert failed\n");
191 free(pFFB);
192 return FALSE;
193 }
194 hdir = HDIR_CREATE;
195 nm = 1L;
196 //printf("FIND2\n");
197 rc = DosFindFirst(maskstr,&hdir,
198 FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
199 FILE_SYSTEM | FILE_HIDDEN | FILE_DIRECTORY,
200 pFFB,
201 sizeof(FILEFINDBUF4),
202 &nm,
203 FIL_QUERYEASIZE);
204 if(!rc)
205 {
206 register PBYTE fb = (PBYTE)pFFB;
207 FILEFINDBUF4 *pffbFile;
208 ULONG x;
209
210 while(!rc)
211 {
212 priority_normal();
213 //printf("Found %lu\n",nm);
214 for(x = 0L;x < nm;x++)
215 {
216 pffbFile = (FILEFINDBUF4 *)fb;
217 //printf("%s\n",pffbFile->achName);
218 //fflush(stdout);
219 // Total size skipping . and ..
220 if((*pffbFile->achName != '.' ||
221 (pffbFile->achName[1] && pffbFile->achName[1] != '.')) ||
222 !(pffbFile->attrFile & FILE_DIRECTORY))
223 {
224 ullCurDirBytes += pffbFile->cbFile;
225 ullCurDirBytes += CBLIST_TO_EASIZE(pffbFile->cbList) & 0x3ff;
226
227 if(!(pffbFile->attrFile & FILE_DIRECTORY))
228 pCI->attrFile++; // Bump file count
229 if(*pchStopFlag)
230 break;
231 if(pffbFile->attrFile & FILE_DIRECTORY) {
232 // Recurse into subdir
233 strcpy(pEndMask,pffbFile->achName); // Append dirname to base dirname
234 if(!*pchStopFlag)
235 {
236 ProcessDir(hwndCnr,maskstr,pCI,pchStopFlag,FALSE,&ull);
237 ullSubDirBytes += ull;
238 }
239 }
240 }
241 if(!pffbFile->oNextEntryOffset)
242 break;
243 fb += pffbFile->oNextEntryOffset;
244 } // for matches
245 if(*pchStopFlag)
246 break;
247 DosSleep(0L);
248 nm = 1L; /* FilesToGet */
249 rc = DosFindNext(hdir,pFFB,sizeof(FILEFINDBUF4) ,&nm);
250 } // while more found
251 DosFindClose(hdir);
252 priority_normal();
253 }
254
255 free(pFFB);
256
257 pCI->cbFile = ullCurDirBytes;
258 pCI->easize = ullSubDirBytes; // hack cough
259 WinSendMsg(hwndCnr,CM_INVALIDATERECORD,MPFROMP(&pCI),
260 MPFROM2SHORT(1,CMA_ERASE | CMA_TEXTCHANGED));
261
262 *pullTotalBytes = ullCurDirBytes + ullSubDirBytes;
263 return TRUE;
264}
265
266
267static VOID FillInRecSizes (HWND hwndCnr,PCNRITEM pciParent,ULONGLONG ullTotalBytes,
268 CHAR *pchStopFlag,BOOL isroot)
269{
270 PCNRITEM pCI = pciParent;
271 SHORT attrib = CMA_FIRSTCHILD;
272
273 if(pCI) {
274
275 float fltPct = 0.0;
276 CHAR szCurDir[80];
277 CHAR szSubDir[80];
278 CHAR szAllDir[80];
279 CHAR szBar[80];
280
281 // cbFile = currect directory usage in bytes
282 // easize = subdirectory usage in bytes
283 CommaFmtULL(szCurDir,sizeof(szCurDir),pCI->cbFile,'K');
284 *szBar = 0;
285
286 if (ullTotalBytes)
287 {
288 register UINT cBar;
289
290 if(isroot)
291 {
292 FSALLOCATE fsa;
293 APIRET rc;
294
295 memset(&fsa,0,sizeof(fsa));
296 rc = DosQueryFSInfo(toupper(*pCI->szFileName) - '@',FSIL_ALLOC,&fsa,
297 sizeof(FSALLOCATE));
298 if (!rc)
299 {
300 fltPct = (ullTotalBytes * 100.0) /
301 ((float)fsa.cUnit * (fsa.cSectorUnit * fsa.cbSector));
302 }
303 pCI->szLongname[1] = 1; // Flag root - hack cough
304 }
305 else
306 fltPct = (((float)pCI->cbFile + pCI->easize) * 100.0) / ullTotalBytes;
307
308 cBar = (UINT)fltPct / 2;
309 if (cBar)
310 memset(szBar, '#', cBar);
311 if(cBar * 2 != (UINT)fltPct) {
312 szBar[cBar] = '=';
313 cBar++;
314 }
315 if (cBar < 50)
316 memset(szBar + cBar, ' ', 50 - cBar);
317 szBar[50] = 0;
318 }
319
320 pCI->flags = (ULONG)fltPct;
321 CommaFmtULL(szSubDir,sizeof(szSubDir),pCI->easize,'K');
322 CommaFmtULL(szAllDir,sizeof(szAllDir),pCI->cbFile + pCI->easize,'K');
323 sprintf(&pCI->szFileName[strlen(pCI->szFileName)],
324 " %s + %s = %s (%.02lf%%%s)\r%s",
325 szCurDir,
326 szSubDir,
327 szAllDir,
328 fltPct,
329 isroot ? GetPString(IDS_OFDRIVETEXT) : NullStr,
330 szBar);
331 WinSendMsg(hwndCnr,
332 CM_INVALIDATERECORD,
333 MPFROMP(&pCI),
334 MPFROM2SHORT(1,0));
335 isroot = FALSE;
336 }
337 else
338 attrib = CMA_FIRST;
339 pCI = (PCNRITEM)WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(pCI),
340 MPFROM2SHORT(attrib,CMA_ITEMORDER));
341 while(pCI && (INT)pCI != -1) {
342 if(*pchStopFlag)
343 break;
344 FillInRecSizes(hwndCnr,pCI,ullTotalBytes,pchStopFlag,isroot);
345 isroot = FALSE;
346 pCI = (PCNRITEM)WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(pCI),
347 MPFROM2SHORT(CMA_NEXT,CMA_ITEMORDER));
348 }
349}
350
351
352static VOID PrintToFile (HWND hwndCnr,ULONG indent,PCNRITEM pciParent,
353 FILE *fp)
354{
355 PCNRITEM pci;
356 register CHAR *p;
357
358 if(!pciParent) {
359 pciParent = WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(NULL),
360 MPFROM2SHORT(CMA_FIRST,CMA_ITEMORDER));
361 indent = 0;
362 }
363 if(pciParent) {
364 p = strchr(pciParent->szFileName,'\r');
365 if(p)
366 *p = 0;
367 fprintf(fp,"%*.*s%s %lu %s%s\n",
368 indent * 2,indent * 2," ",
369 pciParent->szFileName,
370 pciParent->attrFile,
371 GetPString(IDS_FILETEXT),
372 &"s"[pciParent->attrFile == 1]);
373 if(p)
374 *p = '\r';
375 if(pciParent->rc.flRecordAttr & CRA_EXPANDED) {
376 pci = (PCNRITEM)WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(pciParent),
377 MPFROM2SHORT(CMA_FIRSTCHILD,CMA_ITEMORDER));
378 while(pci && (INT)pci != -1) {
379 DosSleep(0L);
380 PrintToFile(hwndCnr,indent + 1,pci,fp);
381 pci = (PCNRITEM)WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(pci),
382 MPFROM2SHORT(CMA_NEXT,CMA_ITEMORDER));
383 }
384 }
385 }
386}
387
388
389static VOID FillCnrThread (VOID *args)
390{
391 HAB hab;
392 HMQ hmq;
393 DIRSIZE *dirsize = (DIRSIZE *)args;
394 HWND hwndCnr;
395 ULONGLONG ull;
396 BOOL ok;
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.