Changeset 153 for trunk/dll/dirsize.c


Ignore:
Timestamp:
May 26, 2005, 4:14:11 AM (20 years ago)
Author:
root
Message:

Rework for CNRITEM.szSubject
Use ULONGLONG and CommaFmtULL

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/dirsize.c

    r91 r153  
    77
    88  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
    1618
    1719***********************************************************************/
     
    2022#define INCL_WIN
    2123#define INCL_GPI
    22 
     24#define INCL_LONGLONG
    2325#include <os2.h>
     26
    2427#include <stdio.h>
    2528#include <stdlib.h>
    2629#include <string.h>
    2730#include <ctype.h>
     31
    2832#include "fm3dll.h"
    2933#include "fm3dlg.h"
     
    6064
    6165
    62 static ULONG ProcessDir (HWND hwndCnr,CHAR *pszFileName,PCNRITEM pciParent,
    63                          CHAR *pchStopFlag,BOOL top, BOOL *pfIsKB)
     66static BOOL ProcessDir(HWND hwndCnr,CHAR *pszFileName,
     67                       PCNRITEM pciParent,
     68                       CHAR *pchStopFlag,BOOL top,
     69                       PULONGLONG pullTotalBytes)
    6470{
    6571  CHAR           maskstr[CCHMAXPATH];
     
    6975  register char  *pp;
    7076  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;
    7680  HDIR           hdir;
    7781  FILEFINDBUF4   *pFFB;
     
    8084  PCNRITEM       pCI;
    8185
     86  // fixme to report errors
     87  *pullTotalBytes = 0;          // In case we fail
     88
    8289  pFFB = malloc(sizeof(FILEFINDBUF4) /* * FilesToGet */);
    8390  if(!pFFB)
    84     return -1L;
     91    return FALSE;
    8592  strcpy(maskstr,pszFileName);
    8693  if(maskstr[strlen(maskstr) - 1] != '\\')
     
    108115   * requesting EASIZE.  sheesh.
    109116   */
    110   if((!rc && (pFFB->attrFile & FILE_DIRECTORY)) || strlen(pszFileName) < 4)
     117  if ((!rc && (pFFB->attrFile & FILE_DIRECTORY)) ||
     118      strlen(pszFileName) < 4)
    111119  {
    112     if(*pchStopFlag) {
     120    if (*pchStopFlag) {
    113121      free(pFFB);
    114       return -1L;
     122      return FALSE;
    115123    }
    116     //printf("CM_ALLOCRECORD\n");
    117124    pCI = WinSendMsg(hwndCnr,CM_ALLOCRECORD,MPFROMLONG(EXTRA_RECORD_BYTES2),
    118                       MPFROMLONG(1L));
    119     if(!pCI) {
     125                     MPFROMLONG(1L));
     126    if (!pCI) {
    120127      free(pFFB);
    121       return -1L;
     128      return FALSE;
    122129    }
    123130    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);
    128133    }
    129134    else
     
    131136    pCI->pszLongname = pCI->szFileName;
    132137    pCI->rc.hptrIcon = hptrDir;
    133     *pCI->szDispAttr = *pCI->Longname = *pCI->subject = 0;
     138    *pCI->szDispAttr = *pCI->szLongname = *pCI->szSubject = 0;
    134139    pCI->attrFile = 0L;
    135140  }
     
    144149              GetPString(IDS_CANTFINDDIRTEXT),
    145150              pszFileName);
    146     return -1L;
     151    return FALSE;
    147152  }
    148153
     
    184189    //printf("Insert failed\n");
    185190    free(pFFB);
    186     return -1L;
     191    return FALSE;
    187192  }
    188193  hdir = HDIR_CREATE;
     
    216221           !(pffbFile->attrFile & FILE_DIRECTORY))
    217222        {
    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;
    222225
    223226          if(!(pffbFile->attrFile & FILE_DIRECTORY))
     
    230233            if(!*pchStopFlag)
    231234            {
    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;
    243237            }
    244238          }
     
    260254  free(pFFB);
    261255
    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
    275258  WinSendMsg(hwndCnr,CM_INVALIDATERECORD,MPFROMP(&pCI),
    276259             MPFROM2SHORT(1,CMA_ERASE | CMA_TEXTCHANGED));
    277260
    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;
    290263}
    291264
    292265
    293 static VOID FillInRecSizes (HWND hwndCnr,PCNRITEM pciParent,ULONG ulTotalKB,
     266static VOID FillInRecSizes (HWND hwndCnr,PCNRITEM pciParent,ULONGLONG ullTotalBytes,
    294267                     CHAR *pchStopFlag,BOOL isroot)
    295268{
     
    300273
    301274    float       fltPct = 0.0;
    302     CHAR        szCurDirKB[80];
    303     CHAR        szSubDirKB[80];
    304     CHAR        szAllDirKB[80];
     275    CHAR        szCurDir[80];
     276    CHAR        szSubDir[80];
     277    CHAR        szAllDir[80];
    305278    CHAR        szBar[80];
    306279
    307     // cbFile = currect directory usage in KB
    308     // easize = subdirectory usage in KB
    309     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');
    310283    *szBar = 0;
    311284
    312     if(ulTotalKB) {
    313 
     285    if (ullTotalBytes)
     286    {
    314287      register UINT  cBar;
    315288
    316       if(isroot) {
    317 
     289      if(isroot)
     290      {
    318291        FSALLOCATE fsa;
    319292        APIRET     rc;
     
    322295        rc = DosQueryFSInfo(toupper(*pCI->szFileName) - '@',FSIL_ALLOC,&fsa,
    323296                            sizeof(FSALLOCATE));
    324         if(!rc)
     297        if (!rc)
    325298        {
    326           fltPct = (ulTotalKB * 100.0) /
    327                     ((float)fsa.cUnit * (fsa.cSectorUnit * fsa.cbSector) / 1024);
     299          fltPct = (ullTotalBytes * 100.0) /
     300                    ((float)fsa.cUnit * (fsa.cSectorUnit * fsa.cbSector));
    328301        }
    329         pCI->Longname[1] = 1;   // Flag root
     302        pCI->szLongname[1] = 1; // Flag root - hack cough
    330303      }
    331304      else
    332         fltPct = (((float)pCI->cbFile + pCI->easize) * 100.0) / ulTotalKB;
     305        fltPct = (((float)pCI->cbFile + pCI->easize) * 100.0) / ullTotalBytes;
    333306
    334307      cBar = (UINT)fltPct / 2;
     
    345318
    346319    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');
    349322    sprintf(&pCI->szFileName[strlen(pCI->szFileName)],
    350             "  %sk + %sk = %sk (%.02lf%%%s)\r%s",
    351             szCurDirKB,
    352             szSubDirKB,
    353             szAllDirKB,
     323            "  %s + %s = %s (%.02lf%%%s)\r%s",
     324            szCurDir,
     325            szSubDir,
     326            szAllDir,
    354327            fltPct,
    355             (isroot) ? GetPString(IDS_OFDRIVETEXT) : NullStr,
     328            isroot ? GetPString(IDS_OFDRIVETEXT) : NullStr,
    356329            szBar);
    357330    WinSendMsg(hwndCnr,
     
    368341    if(*pchStopFlag)
    369342      break;
    370     FillInRecSizes(hwndCnr,pCI,ulTotalKB,pchStopFlag,isroot);
     343    FillInRecSizes(hwndCnr,pCI,ullTotalBytes,pchStopFlag,isroot);
    371344    isroot = FALSE;
    372345    pCI = (PCNRITEM)WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(pCI),
     
    419392  DIRSIZE       *dirsize = (DIRSIZE *)args;
    420393  HWND          hwndCnr;
    421   ULONG         ulTotal;
     394  ULONGLONG     ull;
     395  BOOL          ok;
    422396
    423397  if(!dirsize)
     
    429403  // priority_normal();
    430404  hab = WinInitialize(0);
    431   if(hab) {
     405  if(hab)
     406  {
    432407    hmq = WinCreateMsgQueue(hab,0);
    433     if(hmq) {
    434     BOOL fIsKB;
     408    if(hmq)
     409    {
    435410      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);
    438413      DosPostEventSem(CompactSem);
    439414      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);
    443416      WinEnableWindowUpdate(hwndCnr,TRUE);
    444417      WinSendMsg(hwndCnr,CM_INVALIDATERECORD,MPVOID,
     
    525498          rc = DosQueryFSInfo(toupper(*pTemp->dirname) - '@',FSIL_ALLOC,&fsa,
    526499                              sizeof(FSALLOCATE));
    527           if(!rc) {
     500          if (!rc)
     501          {
    528502
    529503            CHAR s[132],tf[80],tb[80],tu[80];
    530504
    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');
    540514            sprintf(s,
    541515                    GetPString(IDS_FREESPACETEXT),
     
    576550                                MPFROMLONG(CMA_FIRST),
    577551                                MPFROMSHORT(CRA_CURSORED));
    578         if(pci && (INT)pci != -1) {
     552        if (pci && (INT)pci != -1)
     553        {
    579554          commafmt(tb,sizeof(tb),pci->attrFile);
    580555          sprintf(s,
     
    633608              if(p) {
    634609                /* draw text */
    635                 if(!pci->cbFile)  /* no size */
     610                if (!pci->cbFile)  /* no size */
    636611                  GpiSetColor(oi->hps,CLR_DARKGRAY);
    637                 else if(!pci->easize) /* no size below */
     612                else if (!pci->easize) /* no size below */
    638613                  GpiSetColor(oi->hps,CLR_DARKBLUE);
    639614                else
     
    705680                /* fill box with graph bar, flags is integer % */
    706681                if(pci->flags) {
    707                   if(pci->Longname[1] == 1) /* is root record */
     682                  if(pci->szLongname[1] == 1) /* is root record */
    708683                    GpiSetColor(oi->hps,CLR_DARKGREEN);
    709684                  else
     
    717692
    718693                  /* draw highlights and shadows on graph */
    719                   if(pci->Longname[1] == 1)
     694                  if(pci->szLongname[1] == 1)
    720695                    GpiSetColor(oi->hps,CLR_GREEN);
    721696                  else
     
    734709                  ptl.x = oi->rclItem.xLeft + pci->flags;
    735710                  GpiLine(oi->hps,&ptl);
    736                   if(pci->Longname[1] != 1) {
     711                  if(pci->szLongname[1] != 1) {
    737712                    GpiSetColor(oi->hps,CLR_DARKRED);
    738713                    ptl.x = oi->rclItem.xLeft + 2;
Note: See TracChangeset for help on using the changeset viewer.