Changeset 153 for trunk/dll/dirsize.c
- Timestamp:
- May 26, 2005, 4:14:11 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/dirsize.c
r91 r153 7 7 8 8 Copyright (c) 1993-98 M. Kimes 9 Copyright (c) 2001, 2002 Steven H.Levine 10 11 Revisions 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 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 16 18 17 19 ***********************************************************************/ … … 20 22 #define INCL_WIN 21 23 #define INCL_GPI 22 24 #define INCL_LONGLONG 23 25 #include <os2.h> 26 24 27 #include <stdio.h> 25 28 #include <stdlib.h> 26 29 #include <string.h> 27 30 #include <ctype.h> 31 28 32 #include "fm3dll.h" 29 33 #include "fm3dlg.h" … … 60 64 61 65 62 static ULONG ProcessDir (HWND hwndCnr,CHAR *pszFileName,PCNRITEM pciParent, 63 CHAR *pchStopFlag,BOOL top, BOOL *pfIsKB) 66 static BOOL ProcessDir(HWND hwndCnr,CHAR *pszFileName, 67 PCNRITEM pciParent, 68 CHAR *pchStopFlag,BOOL top, 69 PULONGLONG pullTotalBytes) 64 70 { 65 71 CHAR maskstr[CCHMAXPATH]; … … 69 75 register char *pp; 70 76 ULONG nm; 71 ULONG ulCurDirKB = 0L; 72 ULONG ulCurDirBytes = 0L; 73 ULONG ulSubDirKB = 0L; 74 ULONG ulSubDirBytes = 0L; 75 ULONG ulTotal; 77 ULONGLONG ullCurDirBytes = 0; 78 ULONGLONG ullSubDirBytes = 0; 79 ULONGLONG ull; 76 80 HDIR hdir; 77 81 FILEFINDBUF4 *pFFB; … … 80 84 PCNRITEM pCI; 81 85 86 // fixme to report errors 87 *pullTotalBytes = 0; // In case we fail 88 82 89 pFFB = malloc(sizeof(FILEFINDBUF4) /* * FilesToGet */); 83 90 if(!pFFB) 84 return -1L;91 return FALSE; 85 92 strcpy(maskstr,pszFileName); 86 93 if(maskstr[strlen(maskstr) - 1] != '\\') … … 108 115 * requesting EASIZE. sheesh. 109 116 */ 110 if((!rc && (pFFB->attrFile & FILE_DIRECTORY)) || strlen(pszFileName) < 4) 117 if ((!rc && (pFFB->attrFile & FILE_DIRECTORY)) || 118 strlen(pszFileName) < 4) 111 119 { 112 if (*pchStopFlag) {120 if (*pchStopFlag) { 113 121 free(pFFB); 114 return -1L;122 return FALSE; 115 123 } 116 //printf("CM_ALLOCRECORD\n");117 124 pCI = WinSendMsg(hwndCnr,CM_ALLOCRECORD,MPFROMLONG(EXTRA_RECORD_BYTES2), 118 119 if (!pCI) {125 MPFROMLONG(1L)); 126 if (!pCI) { 120 127 free(pFFB); 121 return -1L;128 return FALSE; 122 129 } 123 130 if(!rc) { 124 ulCurDirKB = pFFB->cbFile >> 10; 125 ulCurDirBytes = pFFB->cbFile & 0x3ff; 126 ulCurDirKB += CBLIST_TO_EASIZE(pFFB->cbList) >> 10; 127 ulCurDirBytes += CBLIST_TO_EASIZE(pFFB->cbList) & 0x3ff; 131 ullCurDirBytes = pFFB->cbFile; 132 ullCurDirBytes += CBLIST_TO_EASIZE(pFFB->cbList); 128 133 } 129 134 else … … 131 136 pCI->pszLongname = pCI->szFileName; 132 137 pCI->rc.hptrIcon = hptrDir; 133 *pCI->szDispAttr = *pCI-> Longname = *pCI->subject = 0;138 *pCI->szDispAttr = *pCI->szLongname = *pCI->szSubject = 0; 134 139 pCI->attrFile = 0L; 135 140 } … … 144 149 GetPString(IDS_CANTFINDDIRTEXT), 145 150 pszFileName); 146 return -1L;151 return FALSE; 147 152 } 148 153 … … 184 189 //printf("Insert failed\n"); 185 190 free(pFFB); 186 return -1L;191 return FALSE; 187 192 } 188 193 hdir = HDIR_CREATE; … … 216 221 !(pffbFile->attrFile & FILE_DIRECTORY)) 217 222 { 218 ulCurDirKB += pffbFile->cbFile >> 10; 219 ulCurDirBytes += pffbFile->cbFile & 0x3ff; 220 ulCurDirKB += CBLIST_TO_EASIZE(pffbFile->cbList) >> 10; 221 ulCurDirBytes += CBLIST_TO_EASIZE(pffbFile->cbList) & 0x3ff; 223 ullCurDirBytes += pffbFile->cbFile; 224 ullCurDirBytes += CBLIST_TO_EASIZE(pffbFile->cbList) & 0x3ff; 222 225 223 226 if(!(pffbFile->attrFile & FILE_DIRECTORY)) … … 230 233 if(!*pchStopFlag) 231 234 { 232 BOOL fIsKB; 233 ulTotal = ProcessDir(hwndCnr,maskstr,pCI,pchStopFlag,FALSE, &fIsKB); 234 if(ulTotal != (ULONG)-1L) { 235 if (fIsKB) 236 ulSubDirKB += ulTotal; 237 else { 238 ulSubDirKB += (ulTotal >> 10); 239 // Assume we can delay propagating to KB 240 ulSubDirBytes += (ulTotal & 0x3ff); 241 } 242 } 235 ProcessDir(hwndCnr,maskstr,pCI,pchStopFlag,FALSE,&ull); 236 ullSubDirBytes += ull; 243 237 } 244 238 } … … 260 254 free(pFFB); 261 255 262 // Propage carry 263 ulCurDirKB += ulCurDirBytes >> 10; 264 ulCurDirBytes &= 0x3ff; 265 if (ulCurDirBytes) 266 ulCurDirKB++; 267 268 ulSubDirKB += ulSubDirBytes >> 10; 269 ulSubDirBytes &= 0x3ff; 270 if (ulSubDirBytes) 271 ulSubDirKB++; 272 273 pCI->cbFile = ulCurDirKB; 274 pCI->easize = ulSubDirKB; 256 pCI->cbFile = ullCurDirBytes; 257 pCI->easize = ullSubDirBytes; // hack fixme 275 258 WinSendMsg(hwndCnr,CM_INVALIDATERECORD,MPFROMP(&pCI), 276 259 MPFROM2SHORT(1,CMA_ERASE | CMA_TEXTCHANGED)); 277 260 278 ulTotal = ulCurDirKB + ulSubDirKB 279 + (ulCurDirBytes >> 10) + (ulSubDirBytes >> 10); 280 if (ulTotal >= 1L << 21) { 281 *pfIsKB = TRUE; 282 } 283 else { 284 *pfIsKB = FALSE; 285 ulTotal = (ulCurDirKB << 10) + (ulSubDirKB << 10) 286 + ulCurDirBytes + ulSubDirBytes; 287 } 288 289 return ulTotal; 261 *pullTotalBytes = ullCurDirBytes + ullSubDirBytes; 262 return TRUE; 290 263 } 291 264 292 265 293 static VOID FillInRecSizes (HWND hwndCnr,PCNRITEM pciParent,ULONG ulTotalKB,266 static VOID FillInRecSizes (HWND hwndCnr,PCNRITEM pciParent,ULONGLONG ullTotalBytes, 294 267 CHAR *pchStopFlag,BOOL isroot) 295 268 { … … 300 273 301 274 float fltPct = 0.0; 302 CHAR szCurDir KB[80];303 CHAR szSubDir KB[80];304 CHAR szAllDir KB[80];275 CHAR szCurDir[80]; 276 CHAR szSubDir[80]; 277 CHAR szAllDir[80]; 305 278 CHAR szBar[80]; 306 279 307 // cbFile = currect directory usage in KB308 // easize = subdirectory usage in KB309 commafmt(szCurDirKB,sizeof(szCurDirKB),pCI->cbFile);280 // cbFile = currect directory usage in bytes 281 // easize = subdirectory usage in bytes 282 CommaFmtULL(szCurDir,sizeof(szCurDir),pCI->cbFile,'K'); 310 283 *szBar = 0; 311 284 312 if (ulTotalKB) {313 285 if (ullTotalBytes) 286 { 314 287 register UINT cBar; 315 288 316 if(isroot) {317 289 if(isroot) 290 { 318 291 FSALLOCATE fsa; 319 292 APIRET rc; … … 322 295 rc = DosQueryFSInfo(toupper(*pCI->szFileName) - '@',FSIL_ALLOC,&fsa, 323 296 sizeof(FSALLOCATE)); 324 if (!rc)297 if (!rc) 325 298 { 326 fltPct = (ul TotalKB* 100.0) /327 ((float)fsa.cUnit * (fsa.cSectorUnit * fsa.cbSector) / 1024);299 fltPct = (ullTotalBytes * 100.0) / 300 ((float)fsa.cUnit * (fsa.cSectorUnit * fsa.cbSector)); 328 301 } 329 pCI-> Longname[1] = 1; // Flag root302 pCI->szLongname[1] = 1; // Flag root - hack cough 330 303 } 331 304 else 332 fltPct = (((float)pCI->cbFile + pCI->easize) * 100.0) / ul TotalKB;305 fltPct = (((float)pCI->cbFile + pCI->easize) * 100.0) / ullTotalBytes; 333 306 334 307 cBar = (UINT)fltPct / 2; … … 345 318 346 319 pCI->flags = (ULONG)fltPct; 347 commafmt(szSubDirKB,sizeof(szSubDirKB),pCI->easize);348 commafmt(szAllDirKB,sizeof(szAllDirKB),pCI->cbFile + pCI->easize);320 CommaFmtULL(szSubDir,sizeof(szSubDir),pCI->easize,'M'); 321 CommaFmtULL(szAllDir,sizeof(szAllDir),pCI->cbFile + pCI->easize,'M'); 349 322 sprintf(&pCI->szFileName[strlen(pCI->szFileName)], 350 " %s k + %sk = %sk(%.02lf%%%s)\r%s",351 szCurDir KB,352 szSubDir KB,353 szAllDir KB,323 " %s + %s = %s (%.02lf%%%s)\r%s", 324 szCurDir, 325 szSubDir, 326 szAllDir, 354 327 fltPct, 355 (isroot)? GetPString(IDS_OFDRIVETEXT) : NullStr,328 isroot ? GetPString(IDS_OFDRIVETEXT) : NullStr, 356 329 szBar); 357 330 WinSendMsg(hwndCnr, … … 368 341 if(*pchStopFlag) 369 342 break; 370 FillInRecSizes(hwndCnr,pCI,ul TotalKB,pchStopFlag,isroot);343 FillInRecSizes(hwndCnr,pCI,ullTotalBytes,pchStopFlag,isroot); 371 344 isroot = FALSE; 372 345 pCI = (PCNRITEM)WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(pCI), … … 419 392 DIRSIZE *dirsize = (DIRSIZE *)args; 420 393 HWND hwndCnr; 421 ULONG ulTotal; 394 ULONGLONG ull; 395 BOOL ok; 422 396 423 397 if(!dirsize) … … 429 403 // priority_normal(); 430 404 hab = WinInitialize(0); 431 if(hab) { 405 if(hab) 406 { 432 407 hmq = WinCreateMsgQueue(hab,0); 433 if(hmq) {434 BOOL fIsKB;408 if(hmq) 409 { 435 410 WinCancelShutdown(hmq,TRUE); 436 ulTotal =ProcessDir(hwndCnr,dirsize->pszFileName,437 (PCNRITEM)NULL,dirsize->pchStopFlag,TRUE, &fIsKB);411 ProcessDir(hwndCnr,dirsize->pszFileName, 412 (PCNRITEM)NULL,dirsize->pchStopFlag,TRUE,&ull); 438 413 DosPostEventSem(CompactSem); 439 414 WinEnableWindowUpdate(hwndCnr,FALSE); 440 if (!fIsKB) 441 ulTotal = (ulTotal >> 10) + (ulTotal & 0x3ff ? 1 : 0); 442 FillInRecSizes(hwndCnr,NULL,ulTotal,dirsize->pchStopFlag,TRUE); 415 FillInRecSizes(hwndCnr,NULL,ull,dirsize->pchStopFlag,TRUE); 443 416 WinEnableWindowUpdate(hwndCnr,TRUE); 444 417 WinSendMsg(hwndCnr,CM_INVALIDATERECORD,MPVOID, … … 525 498 rc = DosQueryFSInfo(toupper(*pTemp->dirname) - '@',FSIL_ALLOC,&fsa, 526 499 sizeof(FSALLOCATE)); 527 if(!rc) { 500 if (!rc) 501 { 528 502 529 503 CHAR s[132],tf[80],tb[80],tu[80]; 530 504 531 commafmt(tf,sizeof(tf),532 (ULONG)(((float)fsa.cUnitAvail *533 (fsa.cSectorUnit * fsa.cbSector)) / 1024L));534 commafmt(tb,sizeof(tb),535 (ULONG)(((float)fsa.cUnit *536 (fsa.cSectorUnit * fsa.cbSector)) / 1024L));537 commafmt(tu,sizeof(tu),538 (ULONG)(((float)(fsa.cUnit - fsa.cUnitAvail) *539 (fsa.cSectorUnit * fsa.cbSector)) / 1024L));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'); 540 514 sprintf(s, 541 515 GetPString(IDS_FREESPACETEXT), … … 576 550 MPFROMLONG(CMA_FIRST), 577 551 MPFROMSHORT(CRA_CURSORED)); 578 if(pci && (INT)pci != -1) { 552 if (pci && (INT)pci != -1) 553 { 579 554 commafmt(tb,sizeof(tb),pci->attrFile); 580 555 sprintf(s, … … 633 608 if(p) { 634 609 /* draw text */ 635 if (!pci->cbFile) /* no size */610 if (!pci->cbFile) /* no size */ 636 611 GpiSetColor(oi->hps,CLR_DARKGRAY); 637 else if (!pci->easize) /* no size below */612 else if (!pci->easize) /* no size below */ 638 613 GpiSetColor(oi->hps,CLR_DARKBLUE); 639 614 else … … 705 680 /* fill box with graph bar, flags is integer % */ 706 681 if(pci->flags) { 707 if(pci-> Longname[1] == 1) /* is root record */682 if(pci->szLongname[1] == 1) /* is root record */ 708 683 GpiSetColor(oi->hps,CLR_DARKGREEN); 709 684 else … … 717 692 718 693 /* draw highlights and shadows on graph */ 719 if(pci-> Longname[1] == 1)694 if(pci->szLongname[1] == 1) 720 695 GpiSetColor(oi->hps,CLR_GREEN); 721 696 else … … 734 709 ptl.x = oi->rclItem.xLeft + pci->flags; 735 710 GpiLine(oi->hps,&ptl); 736 if(pci-> Longname[1] != 1) {711 if(pci->szLongname[1] != 1) { 737 712 GpiSetColor(oi->hps,CLR_DARKRED); 738 713 ptl.x = oi->rclItem.xLeft + 2;
Note:
See TracChangeset
for help on using the changeset viewer.