home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / filestat.zip / filestat.c next >
Text File  |  1993-09-20  |  9KB  |  232 lines

  1.  
  2. /*
  3.  * This file was generated by the SOM Compiler.
  4.  * FileName: filestat.c.
  5.  * Generated using:
  6.  *     SOM Precompiler spc: 1.22
  7.  *     SOM Emitter emitc: 1.26
  8.  */
  9.  
  10. /*
  11.  * 
  12.  *      File Statistics: Displays statistics about files dropped on it
  13.  *      Written by : Ghassan Salem
  14.  *      Inspired by : Gregory Czaja (black Hole's originator)
  15.  */
  16.  
  17.  
  18. #define FileState_Class_Source
  19. #include "FileStat.ih"
  20. #include <wpshadow.h>
  21. #include <wpFolder.h>
  22. #include <wpDataf.h>
  23.  
  24. #include <limits.h>
  25. #include <locale.h>
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <malloc.h>
  30. void GoThrough(WPObject * pWPObject,PSZ,PSZ,ULONG *,ULONG *,ULONG *,ULONG *, ULONG *);
  31. PSZ pszFormatV(PSZ ,ULONG);
  32.  
  33. SOM_Scope MRESULT   SOMLINK FileStatX_wpDragOver(FileState *somSelf,
  34.         HWND hwndCnr,
  35.         PDRAGINFO pdrgInfo)
  36. {
  37.     ULONG ulItemCnt=0;
  38.     ULONG ulItem=0;
  39.     USHORT usDropIndic=DOR_DROP;
  40.     FileStateData *somThis = FileStateGetData(somSelf);
  41.     FileStateMethodDebug("FileState","FileStatX_wpDragOver");
  42.       ulItemCnt=DrgQueryDragitemCount(pdrgInfo);
  43.       for(ulItem=0;ulItem<ulItemCnt;ulItem++) {
  44.        DRAGITEM DItem;
  45.  
  46.         DrgQueryDragitem(pdrgInfo,sizeof(DItem),&DItem,ulItem);
  47.  
  48.                       /* check that it is a WPS object RMF */
  49.         if(!DrgVerifyRMF(&DItem,"DRM_OBJECT","DRF_OBJECT")) {
  50.                       /* if it's not - don't accept !      */
  51.           usDropIndic=DOR_NEVERDROP;
  52.         }/* end if */
  53.       }/* end for */
  54.  
  55.       return (MRFROM2SHORT(usDropIndic,DO_UNKNOWN));
  56. }
  57.  
  58. SOM_Scope MRESULT   SOMLINK FileStatX_wpDrop(FileState *somSelf,
  59.         HWND hwndCnr,
  60.         PDRAGINFO pdrgInfo,
  61.         PDRAGITEM pdrgItem)
  62. {
  63.     WPObject *pWPObjDropped;
  64.     PSZ   object;
  65.     PSZ   pszClass,pszBuffer[15],pszBuffer1[15],pszBuffer2[15],pszBuffer3[15],pszBuffer4[15];
  66.     static PSZ   pszSmallest=NULL;
  67.     static PSZ   pszBiggest=NULL;
  68.     static ULONG ulSmallest=99999999;
  69.     static ULONG ulBiggest=0;
  70.     static ULONG ulTotals=0;
  71.     static ULONG ulItemCnt;
  72.     static ULONG ulNfiles=0;
  73.     static ulSizeAll=0;
  74.     FileStateData *somThis = FileStateGetData(somSelf);
  75.     FileStateMethodDebug("FileState","FileStatX_wpDrop");
  76.     if (pszSmallest==NULL) {
  77.            pszSmallest=(char *)malloc(200);
  78.            pszBiggest=(char *)malloc(200);
  79.     } /* endif */
  80.     if(ulNfiles==0){
  81.        ulNfiles=DrgQueryDragitemCount(pdrgInfo);
  82.        ulItemCnt=0;
  83.     }
  84.     ulNfiles--;
  85.     pWPObjDropped=OBJECT_FROM_PREC(pdrgItem->ulItemID);
  86.     object       =_wpQueryTitle(pWPObjDropped);
  87.     pszClass     =(PSZ)_somGetClassName(pWPObjDropped);
  88.  
  89.     GoThrough(pWPObjDropped,pszSmallest,pszBiggest,&ulSmallest,
  90.     &ulBiggest,&ulTotals,&ulItemCnt,&ulSizeAll);
  91.     if(ulNfiles==0){
  92.        PSZ   message =malloc(600);
  93.        sprintf(message,"Smallest File: %s  %s Bytes\nBiggest File: %s %s Bytes\nTotal space (True/Alloc.): %s / %s Bytes\nNumber of Files:%s\n",
  94.             pszSmallest,pszFormatV(pszBuffer,ulSmallest),pszBiggest,pszFormatV(pszBuffer1,ulBiggest),pszFormatV(pszBuffer2,ulTotals),pszFormatV(pszBuffer4,ulSizeAll),pszFormatV(pszBuffer3,ulItemCnt));
  95.        WinMessageBox(HWND_DESKTOP,
  96.                                   HWND_DESKTOP,
  97.                                   message,
  98.                                  "Thanks for using File Statistics. Results are:",
  99.                                   0,
  100.                                   MB_OK | MB_DEFBUTTON2 | MB_INFORMATION | MB_SYSTEMMODAL|MB_MOVEABLE );
  101.        free(message);
  102.        *pszSmallest='\0';
  103.        ulSmallest=99999999;
  104.        *pszBiggest='\0';
  105.        ulTotals=ulBiggest=ulSizeAll=0;
  106.     }
  107.  
  108.     return (parent_wpDrop(somSelf,hwndCnr,pdrgInfo,pdrgItem));
  109. }
  110.  
  111. #undef SOM_CurrentClass
  112. #define SOM_CurrentClass SOMMeta
  113. SOM_Scope void   SOMLINK FileStatC_wpclsInitData(M_FileState *somSelf)
  114. {
  115.     /* M_FileStateData *somThis = M_FileStateGetData(somSelf); */
  116.     M_FileStateMethodDebug("M_FileState","FileStatC_wpclsInitData");
  117.  
  118.     parent_wpclsInitData(somSelf);
  119. }
  120.  
  121. SOM_Scope void   SOMLINK FileStatC_wpclsUnInitData(M_FileState *somSelf)
  122. {
  123.     /* M_FileStateData *somThis = M_FileStateGetData(somSelf); */
  124.     M_FileStateMethodDebug("M_FileState","FileStatC_wpclsUnInitData");
  125.  
  126.     parent_wpclsUnInitData(somSelf);
  127. }
  128. #undef SOM_CurrentClass
  129.  
  130. /*──────────────────────────────────────────────────────────────────────────┐
  131. │ GoThrough                                                          │
  132. │ Purpose: Scans all objects to get relevant data
  133. └──────────────────────────────────────────────────────────────────────────*/
  134. VOID GoThrough(WPObject * pWPObject,PSZ pszSmallest,PSZ pszBiggest,
  135. ULONG *ulSmallest,ULONG *ulBiggest,ULONG *ulSize,ULONG *ulCount,ULONG *ulSizeAll)
  136. {
  137.    ULONG ulFlags,ulFsize;
  138.  ULONG        PathInfoLevel;   /* Data required */
  139.  FILESTATUS3  PathInfoBuf;     /* File info buffer */
  140.  ULONG        PathInfoBufSize; /* Data buffer size */
  141.  
  142.    PSZ       pszObject =_wpQueryTitle(pWPObject);
  143.    PSZ       pszClass  =(PSZ)_somGetClassName(pWPObject);
  144.  APIRET       rc;              /* Return code */
  145.  
  146.        PSZ pszFilename=NULL;
  147.        ULONG  pcb;
  148.  
  149.    SOMClass *Class;
  150.    SOMClass *FolderClass=_somClassFromId(SOMClassMgrObject,
  151.                                          SOM_IdFromString("WPFolder"));
  152.    if (strcmp(pszClass,"WPShadow")==0) {
  153.        pWPObject=_wpQueryShadowedObject(pWPObject,FALSE);
  154.        pszClass  =(PSZ)_somGetClassName(pWPObject);
  155.    } /* endif */
  156.  
  157.    Class=_somClassFromId(SOMClassMgrObject,
  158.                                    SOM_IdFromString(pszClass));
  159.                                     /* those are represented by real files... */
  160.                                     /* resolve composite objects if necessary */
  161.    if (_somDescendedFrom(Class, FolderClass)){
  162.                                      /* get the real name for populate */
  163.        if _wpQueryRealName(pWPObject,NULL,&pcb,TRUE){
  164.           pszFilename=malloc(pcb+2);            /* get the buffer */
  165.           memset(pszFilename,'\0',pcb+1);
  166.           _wpQueryRealName(pWPObject,pszFilename,&pcb,TRUE);
  167.        } /* endif */
  168.        if (_wpPopulate(pWPObject, 0L, pszFilename, FALSE)) {
  169.           WPObject * pWPObjectTemp;
  170.                       /* go through folder's content   */
  171.           for(pWPObjectTemp=_wpQueryContent(pWPObject,pWPObjectTemp,QC_First);
  172.               pWPObjectTemp != NULL;
  173.               pWPObjectTemp=_wpQueryContent(pWPObject,pWPObjectTemp,QC_Next)) {
  174.  
  175.               GoThrough(pWPObjectTemp,pszSmallest,pszBiggest,ulSmallest,
  176.               ulBiggest,ulSize,ulCount,ulSizeAll);
  177.           }/* end for */
  178.        } /* endif */
  179.        if (pszFilename != NULL)
  180.           free(pszFilename);
  181.    } else {
  182.       if _wpQueryRealName(pWPObject,NULL,&pcb,TRUE){
  183.           pszFilename=malloc(pcb+2);            /* get the buffer */
  184.           memset(pszFilename,'\0',pcb+1);
  185.           _wpQueryRealName(pWPObject,pszFilename,&pcb,TRUE);
  186.           PathInfoLevel = 1;    /* Indicate that Level 1 information */
  187.           PathInfoBufSize = sizeof(FILESTATUS3);
  188.           rc = DosQueryPathInfo(pszFilename, PathInfoLevel, &PathInfoBuf,
  189.                                    PathInfoBufSize);
  190.           if(rc==0) {
  191.                (*ulCount)++;
  192.                ulFsize=PathInfoBuf.cbFile;
  193.                (*ulSize)+=ulFsize;
  194.                (*ulSizeAll)+=PathInfoBuf.cbFileAlloc;
  195.                if(*ulSmallest>ulFsize){
  196.                   *ulSmallest=ulFsize;
  197.                   strcpy(pszSmallest,pszFilename);
  198.                }
  199.                if(*ulBiggest<ulFsize){
  200.                   *ulBiggest=ulFsize;
  201.                   strcpy(pszBiggest,pszFilename);
  202.                }
  203.            } /* endif rc */
  204.      } /* endif _wpQuery*/
  205.   } /* endif */
  206.   return;
  207. }
  208. PSZ pszFormatV( PSZ pszBuf, ULONG ulNumber)
  209. {
  210.    char cGrp_sep;
  211.    PSZ pszTmp;
  212.    INT iI,iNs,iNth;
  213.    COUNTRYCODE  ctrycStructure;
  214.    COUNTRYINFO  ctryiMemBuff;
  215.    ULONG        ulDataLength;
  216.    APIRET        rc;        /* Return code */
  217.    ctrycStructure.country=0;
  218.    ctrycStructure.codepage=0;
  219.    rc = DosQueryCtryInfo(sizeof(ctryiMemBuff),
  220.               &ctrycStructure, &ctryiMemBuff,
  221.               &ulDataLength);
  222.     cGrp_sep=ctryiMemBuff.szThousandsSeparator[0];
  223.     sprintf(pszBuf,"%ld",ulNumber);
  224.     pszTmp=pszBuf+strlen(pszBuf);
  225.     while(pszTmp>pszBuf+3){
  226.        memmove(pszTmp-2,pszTmp-3,strlen(pszTmp)+4);
  227.        pszTmp-=3;
  228.        *pszTmp=cGrp_sep;
  229.     } /* endfor */
  230.     return pszBuf;
  231. }
  232.