From b61a07ef28c2a8bc6cb8d02f5fa672441f7b582b Mon Sep 17 00:00:00 2001 From: Luiz Rafael Culik Date: Sun, 30 Sep 2001 11:14:21 +0000 Subject: [PATCH] p See changelog 2001-09-30 08:20 GMT -3 --- harbour/contrib/hbzlib/doc/zipnew.txt | 31 +++- harbour/contrib/hbzlib/hbzip2.h | 25 ++-- harbour/contrib/hbzlib/zip.c | 18 +-- harbour/contrib/hbzlib/zipcomp.cpp | 207 +++++++++++++++++++++----- harbour/contrib/hbzlib/zipnew.cpp | 153 ++++++++++++++++--- 5 files changed, 359 insertions(+), 75 deletions(-) diff --git a/harbour/contrib/hbzlib/doc/zipnew.txt b/harbour/contrib/hbzlib/doc/zipnew.txt index ab6a8fc400..e33faec491 100644 --- a/harbour/contrib/hbzlib/doc/zipnew.txt +++ b/harbour/contrib/hbzlib/doc/zipnew.txt @@ -8,7 +8,7 @@ * Create a zip file * $SYNTAX$ * HB_ZIPFILE( , | , , - * , ,,,) ---> lCompress + * , ,,,,) ---> lCompress * $ARGUMENTS$ * Name of the zip file * @@ -29,6 +29,8 @@ * Toggle to store the path or not * * Toggle to store the Drive letter and path or not + * + * Code block for File Progress * $RETURNS$ * .t. if file was create, otherwise .f. * $DESCRIPTION$ @@ -57,6 +59,10 @@ * If is used, it tells thats the Drive and path should also be stored * with the file name. Default is false. * + * If is used, an Code block is evaluated, showing the total + * of that file has beeing processed. + * The codeblock must be defined as follow {|nPos,nTotal| GaugeUpdate(aGauge1,(nPos/nTotal))} + * * $EXAMPLES$ * FUNCTION MAIN() * @@ -100,7 +106,7 @@ * Unzip a compressed file * $SYNTAX$ * HB_UNZIPFILE( , , ) ,,, - * [|] <---> lCompress + * [|] ,) <---> lCompress * $ARGUMENTS$ * Name of the zip file * @@ -113,6 +119,8 @@ * Path to extract the files. * * | An file or an Array of files to extract + * + * Code block for File Progress * $RETURNS$ * .t. if all file was successfuly restored, otherwise .f. * $DESCRIPTION$ @@ -125,6 +133,10 @@ * * The is an obrogatory parameter. Set to ".\" to extract to the * current dir + * + * If is used, an Code block is evaluated, showing the total + * of that file has beeing processed. + * The codeblock must be defined as follow {|nPos,nTotal| GaugeUpdate(aGauge1,(nPos/nTotal))} * $EXAMPLES$ * FUNCTION MAIN() * @@ -212,7 +224,7 @@ * Create a zip file * $SYNTAX$ * HB_ZIPFILEBYTDSPAN()( , | , , - * , ,,,,) ---> lCompress + * , ,,,,,) ---> lCompress * $ARGUMENTS$ * Name of the zip file * @@ -235,6 +247,8 @@ * Toggle to store the path or not * * Toggle to store the Drive letter and path or not + * + * Code block for File Progress * $RETURNS$ * .t. if file was create, otherwise .f. * $DESCRIPTION$ @@ -260,6 +274,9 @@ * If is used, it tells thats the Drive and path should also be stored * with the file name. Default is false. * + * If is used, an Code block is evaluated, showing the total + * of that file has beeing processed. + * The codeblock must be defined as follow {|nPos,nTotal| GaugeUpdate(aGauge1,(nPos/nTotal))} * $EXAMPLES$ * FUNCTION MAIN() * @@ -304,7 +321,7 @@ * Create a zip file on removable media * $SYNTAX$ * HB_ZIPFILEBYPKSPAN( , | , , - * , ,,,) ---> lCompress + * , ,,,,) ---> lCompress * $ARGUMENTS$ * Name of the zip file * @@ -325,6 +342,8 @@ * Toggle to store the path or not * * Toggle to store the Drive letter and path or not + * + * Code block for File Progress * $RETURNS$ * .t. if file was create, otherwise .f. * $DESCRIPTION$ @@ -354,6 +373,10 @@ * If is used, it tells thats the Drive and path should also be stored * with the file name. Default is false. * + * If is used, an Code block is evaluated, showing the total + * of that file has beeing processed. + * The codeblock must be defined as follow {|nPos,nTotal| GaugeUpdate(aGauge1,(nPos/nTotal))} + * * Before calling this function, Set an Changedisk codeblock by calling * the HB_SETDISKZIP(). * $EXAMPLES$ diff --git a/harbour/contrib/hbzlib/hbzip2.h b/harbour/contrib/hbzlib/hbzip2.h index acc88cdfe1..9db1a2b3dc 100644 --- a/harbour/contrib/hbzlib/hbzip2.h +++ b/harbour/contrib/hbzlib/hbzip2.h @@ -53,6 +53,7 @@ #ifndef HB_APIZLIB_H_ #define HB_APIZLIB_H_ +#define HB_OS_WIN_32_USED #include #include #include @@ -68,6 +69,7 @@ extern "C" { #endif + #define filePos 1 #define Lenght 2 #define Method 3 @@ -86,22 +88,26 @@ int iRead; char * szComment; PHB_ITEM pItem; } HB_ZIP_INTERNAL,* PHB_ZIP_INTERNAL,* HB_ZIP_INTERNAL_PTR; +#ifndef LPCTSTR +typedef const char *LPCSTR; +typedef LPCSTR LPCTSTR; +#endif extern char *hb___CheckFile( char * szFile); extern PHB_ITEM hb___GetFilesNamesFromZip(char *szFile,BOOL iMode); extern void hb_____GetTime(struct tm *tz); -extern int hb_CmpPkSpan(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive); -extern int hb_CmpPkSpanStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive); +extern int hb_CmpPkSpan(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress); +extern int hb_CmpPkSpanStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress); extern char *hb_getPassWord(char *szName); extern int hb___GetNumbersofFilestoUnzip(char *szFile); extern int hb___SetCallbackFunc(PHB_ITEM pFunc); -extern int hb_CmpTdSpan(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,PHB_ITEM pDiskBlock,int iSpanSize ,BOOL bPath ,BOOL bDrive); +extern int hb_CmpTdSpan(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,PHB_ITEM pDiskBlock,int iSpanSize ,BOOL bPath ,BOOL bDrive,PHB_ITEM pProgress); -extern int hb_CompressFile(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive); -extern int hb_CompressFileStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive); -extern int hb_CmpTdSpanStd(char *szFile,char * szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,PHB_ITEM pDiskBlock,int iSpanSize,BOOL bPath,BOOL bDrive); -extern int hb_UnzipAll(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pDiskBlock); -extern int hb_UnzipOne(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,char *szFiletoExtract); -extern int hb_UnzipSel(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pArray); +extern int hb_CompressFile(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress); +extern int hb_CompressFileStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress); +extern int hb_CmpTdSpanStd(char *szFile,char * szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,PHB_ITEM pDiskBlock,int iSpanSize,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress); +extern int hb_UnzipAll(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pDiskBlock,PHB_ITEM pProgress); +extern int hb_UnzipOne(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,char *szFiletoExtract,PHB_ITEM pProgress); +extern int hb_UnzipSel(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pArray,PHB_ITEM pProgress); extern int hb_DeleteOne(char *szFile,char *szFiletoDelete); extern int hb_DeleteSel(char *szFile,PHB_ITEM pArray,BOOL bCase); @@ -109,6 +115,7 @@ extern int hb_TestForPKS(char *szFile); extern void hb_SetZipBuff(int a,int b,int c); extern void hb_SetZipComment(char *szComment); extern char *hb_GetZipComment(char *szFile); +extern unsigned long GetCurrentFileSize( LPCTSTR szFile); #ifdef __cplusplus } #endif diff --git a/harbour/contrib/hbzlib/zip.c b/harbour/contrib/hbzlib/zip.c index 6a881aea29..d09aabfe4d 100644 --- a/harbour/contrib/hbzlib/zip.c +++ b/harbour/contrib/hbzlib/zip.c @@ -59,13 +59,13 @@ HB_FUNC(HB_ZIPFILE) if( ISCHAR(1) && ISCHAR(2)) { char szFile[_POSIX_PATH_MAX]; strcpy(szFile,hb_parc(1)); - hb_retl(hb_CompressFileStd(hb___CheckFile(szFile),hb_parc(2),ISNUM(3) ? hb_parni(3) : (-1) ,hb_param( 4, HB_IT_BLOCK) ,ISLOG(5) ? hb_parl(5) : 0,hb_parc(6),ISLOG(7) ? hb_parl(7) : 0 ,ISLOG(8) ? hb_parl(8) : 0)); + hb_retl(hb_CompressFileStd(hb___CheckFile(szFile),hb_parc(2),ISNUM(3) ? hb_parni(3) : (-1) ,hb_param( 4, HB_IT_BLOCK) ,ISLOG(5) ? hb_parl(5) : 0,hb_parc(6),ISLOG(7) ? hb_parl(7) : 0 ,ISLOG(8) ? hb_parl(8) : 0,hb_itemParam(9))); } if(ISCHAR(1) && ISARRAY(2)) { char szFile[_POSIX_PATH_MAX]; strcpy(szFile,hb_parc(1)); - hb_retl(hb_CompressFile(hb___CheckFile(szFile),hb_param( 2, HB_IT_ARRAY ),ISNUM(3) ? hb_parni(3) : (-1) ,hb_param( 4,HB_IT_BLOCK),ISLOG(5) ? hb_parl(5) : 0,hb_parc(6),ISLOG(7) ? hb_parl(7) : 0,ISLOG(8) ? hb_parl(8) : 0)); + hb_retl(hb_CompressFile(hb___CheckFile(szFile),hb_param( 2, HB_IT_ARRAY ),ISNUM(3) ? hb_parni(3) : (-1) ,hb_param( 4,HB_IT_BLOCK),ISLOG(5) ? hb_parl(5) : 0,hb_parc(6),ISLOG(7) ? hb_parl(7) : 0,ISLOG(8) ? hb_parl(8) : 0,hb_itemParam(9))); } @@ -103,13 +103,13 @@ HB_FUNC(HB_ZIPFILEBYTDSPAN) if( ISCHAR(1) && ISCHAR(2)) { char szFile[_POSIX_PATH_MAX]; strcpy(szFile,hb_parc(1)); - hb_retl(hb_CmpTdSpanStd(hb___CheckFile(szFile),hb_parc(2),ISNUM(3) ? hb_parni(3) : (-1),hb_param( 4, HB_IT_BLOCK) ,ISLOG(5) ? hb_parl(5) : 0, hb_parc(6),hb_param( 7,HB_IT_BLOCK),ISNUM(8) ? hb_parni(8) : NULL,ISLOG(9) ? hb_parl(9) : 0,ISLOG(10) ? hb_parl(10) : 0)); + hb_retl(hb_CmpTdSpanStd(hb___CheckFile(szFile),hb_parc(2),ISNUM(3) ? hb_parni(3) : (-1),hb_param( 4, HB_IT_BLOCK) ,ISLOG(5) ? hb_parl(5) : 0, hb_parc(6) ,hb_param( 7,HB_IT_BLOCK),ISNUM(8) ? hb_parni(8) : 0,ISLOG(9) ? hb_parl(9) : 0,ISLOG(10) ? hb_parl(10) : 0,hb_itemParam(11))); } if(ISCHAR(1) && ISARRAY(2)) { char szFile[_POSIX_PATH_MAX]; strcpy(szFile,hb_parc(1)); - hb_retl(hb_CmpTdSpan(hb___CheckFile(szFile),hb_param( 2, HB_IT_ARRAY ),ISNUM(3) ? hb_parni(3) : (-1) ,hb_param( 4,HB_IT_BLOCK),ISLOG(5) ? hb_parl(5) : 0 ,hb_parc(6) ,hb_param( 7,HB_IT_BLOCK),ISNUM(8) ? hb_parni(8) : NULL,ISLOG(9) ? hb_parl(9) : 0,ISLOG(10) ? hb_parl(10) : 0)); + hb_retl(hb_CmpTdSpan(hb___CheckFile(szFile),hb_param( 2, HB_IT_ARRAY ),ISNUM(3) ? hb_parni(3) : (-1) ,hb_param( 4,HB_IT_BLOCK),ISLOG(5) ? hb_parl(5) : 0 ,hb_parc(6) ,hb_param( 7,HB_IT_BLOCK),ISNUM(8) ? hb_parni(8) :0,ISLOG(9) ? hb_parl(9) : 0,ISLOG(10) ? hb_parl(10) : 0,hb_itemParam(11))); } } @@ -118,14 +118,14 @@ HB_FUNC(HB_ZIPFILEBYPKSPAN) if( ISCHAR(1) && ISCHAR(2)) { char szFile[_POSIX_PATH_MAX]; strcpy(szFile,hb_parc(1)); - hb_retl(hb_CmpPkSpanStd(hb___CheckFile(szFile),hb_parc(2),ISNUM(3) ? hb_parni(3) : (-1),hb_param( 4, HB_IT_BLOCK) ,ISLOG(5) ? hb_parl(5) : 0, hb_parc(6),ISLOG(7) ? hb_parl(7) : 0,ISLOG(8) ? hb_parl(8) : 0)); + hb_retl(hb_CmpPkSpanStd(hb___CheckFile(szFile),hb_parc(2),ISNUM(3) ? hb_parni(3) : (-1),hb_param( 4, HB_IT_BLOCK) ,ISLOG(5) ? hb_parl(5) : 0, hb_parc(6),ISLOG(7) ? hb_parl(7) : 0,ISLOG(8) ? hb_parl(8) : 0,hb_itemParam(9))); } if(ISCHAR(1) && ISARRAY(2)) { char szFile[_POSIX_PATH_MAX]; strcpy(szFile,hb_parc(1)); - hb_retl(hb_CmpPkSpan(hb___CheckFile(szFile),hb_param( 2, HB_IT_ARRAY ),ISNUM(3) ? hb_parni(3) : (-1),hb_param( 4,HB_IT_BLOCK),ISLOG(5) ? hb_parl(5) : 0,hb_parc(6),ISLOG(7) ? hb_parl(7) : 0,ISLOG(8) ? hb_parl(8) : 0)); + hb_retl(hb_CmpPkSpan(hb___CheckFile(szFile),hb_param( 2, HB_IT_ARRAY ),ISNUM(3) ? hb_parni(3) : (-1),hb_param( 4,HB_IT_BLOCK),ISLOG(5) ? hb_parl(5) : 0,hb_parc(6),ISLOG(7) ? hb_parl(7) : 0,ISLOG(8) ? hb_parl(8) : 0,hb_itemParam(9))); } } @@ -136,19 +136,19 @@ HB_FUNC(HB_UNZIPFILE) char szFile[_POSIX_PATH_MAX]; strcpy(szFile,hb_parc(1)); - hb_retl(hb_UnzipOne(hb___CheckFile(szFile),hb_param( 2, HB_IT_BLOCK),ISLOG(3) ? hb_parl(3) : 0 ,hb_parc(4),hb_parc(5),hb_parc(6))); + hb_retl(hb_UnzipOne(hb___CheckFile(szFile),hb_param( 2, HB_IT_BLOCK),ISLOG(3) ? hb_parl(3) : 0 ,hb_parc(4),hb_parc(5),hb_parc(6),hb_itemParam(7))); } if( ISCHAR(1) && ISARRAY(6) ){ char szFile[_POSIX_PATH_MAX]; strcpy(szFile,hb_parc(1)); - hb_retl(hb_UnzipSel(hb___CheckFile(szFile),hb_param( 2, HB_IT_BLOCK),ISLOG(3) ? hb_parl(3) : 0 ,hb_parc(4),hb_parc(5),hb_param(6,HB_IT_ARRAY))); + hb_retl(hb_UnzipSel(hb___CheckFile(szFile),hb_param( 2, HB_IT_BLOCK),ISLOG(3) ? hb_parl(3) : 0 ,hb_parc(4),hb_parc(5),hb_param(6,HB_IT_ARRAY),hb_itemParam(7))); } if ( ! ISCHAR(6) && ! ISARRAY(6) ) { char szFile[_POSIX_PATH_MAX]; strcpy(szFile,hb_parc(1)); - hb_retl(hb_UnzipAll(hb___CheckFile(szFile),hb_param( 2, HB_IT_BLOCK),ISLOG(3) ? hb_parl(3) : 0 ,hb_parc(4),hb_parc(5),hb_param( 6, HB_IT_BLOCK))); + hb_retl(hb_UnzipAll(hb___CheckFile(szFile),hb_param( 2, HB_IT_BLOCK),ISLOG(3) ? hb_parl(3) : 0 ,hb_parc(4),hb_parc(5),hb_param( 6, HB_IT_BLOCK),hb_itemParam(7))); } } HB_FUNC(HB_SETDISKZIP) diff --git a/harbour/contrib/hbzlib/zipcomp.cpp b/harbour/contrib/hbzlib/zipcomp.cpp index 73cd77da23..6cc92f889c 100644 --- a/harbour/contrib/hbzlib/zipcomp.cpp +++ b/harbour/contrib/hbzlib/zipcomp.cpp @@ -49,25 +49,30 @@ * If you do not wish that, delete this exception notice. * */ - +#define HB_OS_WIN_32_USED #include "hbzip2.h" extern PHB_ITEM pArray; PHB_ITEM pDiskStatus=NULL; +PHB_ITEM pProgressInfo=NULL; int iTotal=0; + #ifdef __cplusplus extern "C" { #endif extern HB_ZIP_INTERNAL pZipI; -/*bool hb_SetProgressofTdSpan(DWORD , int iSoFar, void* pData);*/ -int hb_CompressFile(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive) +bool hb_SetProgressofTdSpan(DWORD , int iSoFar, void* pData); + +int hb_CompressFile(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress) { uLong uiCount; + uLong uiPos; char szNewFile[MAXFILENAME]; int iCause=0; - BOOL bFileExist=hb_fsFile(szFile); + BOOL bFileExist=hb_fsFile((BYTE*)szFile); CZipArchive szZip; BOOL bReturn = true; + DWORD dwSize=0; if (szPassWord != NULL){ szZip.SetPassword(szPassWord); } @@ -93,19 +98,47 @@ int hb_CompressFile(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBloc bReturn=false; } catch(...){} + if (pProgress != NULL) + pProgressInfo=pProgress; for (uiCount=1;(uiCount<= hb_arrayLen(pArray)) ;uiCount++) { const char *szDummy = (char *)hb_arrayGetCPtr(pArray,uiCount) ; + dwSize=GetCurrentFileSize(szDummy); + uiPos=uiCount; try { if (szPassWord != NULL){ szZip.SetPassword(szPassWord); + } - if (bDrive) - szZip.AddNewFileDrv(szDummy, iCompLevel, true,NULL,NULL,65536); - if (bPath) - szZip.AddNewFile(szDummy, iCompLevel, true,NULL,NULL,65536); - if (!bDrive && !bPath) - szZip.AddNewFile(szDummy, iCompLevel, false,NULL,NULL,65536); + if (uiPos== hb_arrayLen(pArray)) + iTotal+=dwSize; + if (pProgress == NULL) + { + #if defined(HB_OS_WIN_32) || defined(__MINGW32__) + if (bDrive) + szZip.AddNewFileDrv(szDummy, iCompLevel, true,NULL,NULL,65536); + #endif + if (bPath) + szZip.AddNewFile(szDummy, iCompLevel, true,NULL,NULL,65536); + if (!bDrive && !bPath) + szZip.AddNewFile(szDummy, iCompLevel, false,NULL,NULL,65536); + } + else + { +#if defined(HB_OS_WIN_32) || defined(__MINGW32__) + if (bDrive) + szZip.AddNewFileDrv(szDummy, iCompLevel, true,hb_SetProgressofTdSpan,&(PHB_ITEM)pProgress,65536); +#endif + if (bPath) + szZip.AddNewFile(szDummy, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536); + if (!bDrive && !bPath) + szZip.AddNewFile(szDummy, iCompLevel, false,hb_SetProgressofTdSpan,&pProgress,65536); + } +/* iTotal+=dwSize;*/ + if (uiPos== hb_arrayLen(pArray)) + iTotal-=dwSize; + else + iTotal+=dwSize; } catch(...){} if(pBlock !=NULL){ @@ -127,18 +160,20 @@ int hb_CompressFile(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBloc bReturn=false; } catch(...){} - + hb_itemRelease(pProgressInfo ); return bReturn; /* to avoid warning */ } - int hb_CmpTdSpan(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,PHB_ITEM pDiskBlock,int iSpanSize,BOOL bPath,BOOL bDrive) + int hb_CmpTdSpan(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,PHB_ITEM pDiskBlock,int iSpanSize,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress) { uLong uiCount; char szNewFile[MAXFILENAME]; CZipArchive szZip; int iCause=0; BOOL bReturn=true; - BOOL bFileExist=hb_fsFile(szFile); + uLong uiPos; + BOOL bFileExist=hb_fsFile((BYTE*)szFile); + DWORD dwSize=0; if (pDiskBlock !=NULL){ pDiskStatus=pDiskBlock; } @@ -148,7 +183,7 @@ int hb_CompressFile(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBloc if (pZipI.szComment != NULL) szZip.SetGlobalComment(pZipI.szComment); - if (iSpanSize ==NULL) { + if (iSpanSize ==0) { iSpanSize=1457664; } /* @@ -177,20 +212,49 @@ int hb_CompressFile(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBloc bReturn=false; } catch(...){} + if (pProgress != NULL) + pProgressInfo=pProgress; for (uiCount=1;(uiCount<= hb_arrayLen(pArray)) ;uiCount++) { const char *szDummy = (char *)hb_arrayGetCPtr(pArray,uiCount) ; + dwSize=GetCurrentFileSize(szDummy); + uiPos=uiCount; try { if (szPassWord != NULL){ szZip.SetPassword(szPassWord); } + if (uiPos== hb_arrayLen(pArray)) + iTotal+=dwSize; + + if (pProgress == NULL) + { + + #if defined(HB_OS_WIN_32) || defined(__MINGW32__) if (bDrive) szZip.AddNewFileDrv(szDummy, iCompLevel, true,NULL,NULL,65536); + #endif if (bPath) szZip.AddNewFile(szDummy, iCompLevel, true,NULL,NULL,65536); if (!bDrive && !bPath) szZip.AddNewFile(szDummy, iCompLevel, false,NULL,NULL,65536); + } + else + { +#if defined(HB_OS_WIN_32) || defined(__MINGW32__) + if (bDrive) + szZip.AddNewFileDrv(szDummy, iCompLevel, true,hb_SetProgressofTdSpan,&(PHB_ITEM)pProgress,65536); +#endif + if (bPath) + szZip.AddNewFile(szDummy, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536); + if (!bDrive && !bPath) + szZip.AddNewFile(szDummy, iCompLevel, false,hb_SetProgressofTdSpan,&pProgress,65536); + } + if (uiPos== hb_arrayLen(pArray)) + iTotal-=dwSize; + else + iTotal+=dwSize; + } catch(...){} @@ -218,33 +282,41 @@ int hb_CompressFile(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBloc } /* bool hb_SetProgressofTdSpan(DWORD , int iSoFar, void* pData){ - CZipStorage * pStorage=(CZipStorage*)pData; + int iReturn=1; - DWORD iVolumeLeft=pStorage->m_uCurrentVolSize; - PHB_ITEM pDisk=NULL; - PHB_ITEM pVolume=hb_itemPutNL(NULL,iVolumeLeft); - int iPorcent=0; - int iWrite=(pStorage->m_iBytesWritten*100); - iTotal+=iSoFar; - iPorcent=iWrite/iVolumeLeft; - if (iPorcent==0 || pStorage->m_iBytesWritten==0 ){ - iWrite= (iVolumeLeft*100); - } - pDisk= hb_itemPutNL(NULL,iWrite); - hb_vmEvalBlockV( pDiskStatus, 2,pDisk ,pVolume); + iSoFar+=iTotal; + PHB_ITEM pDisk; + pDisk= hb_itemPutNL(NULL,iTotal); + hb_vmEvalBlockV( pProgressInfo, 1,pDisk ); hb_itemRelease(pDisk); - hb_itemRelease(pVolume); - return iReturn; + return iReturn; } */ -int hb_CompressFileStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive) +bool hb_SetProgressofTdSpan(DWORD a, int iSoFar, void* pData){ + + int iReturn=1; +/* iSoFar+=iTotal;*/ + + PHB_ITEM pDisk; + PHB_ITEM pTotal =hb_itemPutNL(NULL,a); + pDisk= hb_itemPutNL(NULL,iSoFar); + hb_vmEvalBlockV( pProgressInfo, 2,pDisk,pTotal); + hb_itemRelease(pDisk); + hb_itemRelease(pTotal); + + return iReturn; + +} + +int hb_CompressFileStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress) { uLong uiCount; char szNewFile[MAXFILENAME]; int iCause=0; - BOOL bFileExist=hb_fsFile(szFile); + BOOL bFileExist=hb_fsFile((BYTE*)szFile); BOOL bReturn=true; + DWORD dwSize=0; CZipArchive szZip; if (szPassWord != NULL){ szZip.SetPassword(szPassWord); @@ -271,17 +343,38 @@ int hb_CompressFileStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ iCause=e->m_iCause ; bReturn=false; } + if (pProgress != NULL) + pProgressInfo=pProgress; + try { + dwSize=GetCurrentFileSize(szFiletoCompress); if (szPassWord != NULL){ szZip.SetPassword(szPassWord); } + if (pProgress == NULL) + { + + #if defined(HB_OS_WIN_32) || defined(__MINGW32__) if (bDrive) szZip.AddNewFileDrv((const char*)szFiletoCompress, iCompLevel, true,NULL,NULL,65536); + #endif if (bPath) szZip.AddNewFile((const char*)szFiletoCompress, iCompLevel, true,NULL,NULL,65536); if (!bDrive && !bPath) szZip.AddNewFile((const char*)szFiletoCompress, iCompLevel, false,NULL,NULL,65536); + } + else { + #if defined(HB_OS_WIN_32) || defined(__MINGW32__) + if (bDrive) + szZip.AddNewFileDrv((const char*)szFiletoCompress, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536); + #endif + if (bPath) + szZip.AddNewFile((const char*)szFiletoCompress, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536); + if (!bDrive && !bPath) + szZip.AddNewFile((const char*)szFiletoCompress, iCompLevel, false,hb_SetProgressofTdSpan,&pProgress,65536); + } + iTotal+=dwSize; } catch(...){} if(pBlock !=NULL){ @@ -304,7 +397,7 @@ int hb_CompressFileStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ return bReturn; /* to avoid warning */ } - int hb_CmpTdSpanStd(char *szFile,char * szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,PHB_ITEM pDiskBlock,int iSpanSize,BOOL bPath,BOOL bDrive) + int hb_CmpTdSpanStd(char *szFile,char * szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,PHB_ITEM pDiskBlock,int iSpanSize,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress) { uLong uiCount; char szNewFile[MAXFILENAME]; @@ -312,17 +405,19 @@ int hb_CompressFileStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ int iCause=0; BOOL bTdSpan=FALSE; BOOL bReturn=true; - BOOL bFileExist=hb_fsFile(szFile); + DWORD dwSize=0; + BOOL bFileExist=hb_fsFile((BYTE*)szFile); if (pDiskBlock !=NULL){ pDiskStatus=pDiskBlock; } + if (szPassWord != NULL){ szZip.SetPassword(szPassWord); } if (pZipI.szComment != NULL) szZip.SetGlobalComment(pZipI.szComment); - if (iSpanSize ==NULL) { + if (iSpanSize ==0) { iSpanSize=1457664; } try { @@ -344,16 +439,38 @@ int hb_CompressFileStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ iCause=e.m_iCause ; } catch(...){} + if (pProgress != NULL) + pProgressInfo=pProgress; + try { if (szPassWord != NULL){ szZip.SetPassword(szPassWord); } + dwSize=GetCurrentFileSize(szFiletoCompress); + if (pProgress == NULL) + { + + #if defined(HB_OS_WIN_32) || defined(__MINGW32__) if (bDrive) szZip.AddNewFileDrv((const char*) szFiletoCompress, iCompLevel, true,NULL,NULL,65536); + #endif if (bPath) szZip.AddNewFile((const char*) szFiletoCompress, iCompLevel, true,NULL,NULL,65536); if (!bDrive && !bPath) szZip.AddNewFile((const char*) szFiletoCompress, iCompLevel, false,NULL,NULL,65536); + } + else { + #if defined(HB_OS_WIN_32) || defined(__MINGW32__) + if (bDrive) + szZip.AddNewFileDrv((const char*) szFiletoCompress, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536); + #endif + if (bPath) + szZip.AddNewFile((const char*) szFiletoCompress, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536); + if (!bDrive && !bPath) + szZip.AddNewFile((const char*) szFiletoCompress, iCompLevel, false,hb_SetProgressofTdSpan,&pProgress,65536); + } + iTotal+=dwSize; + } catch(...){} @@ -374,7 +491,29 @@ int hb_CompressFileStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ pDiskStatus=NULL ; return true; /* to avoid warning */ } +#if defined(HB_OS_WIN_32) || defined(__MINGW32__) +DWORD GetCurrentFileSize( LPCTSTR szFile) +{ + DWORD dwFileSize=0; + DWORD dwFlags=FILE_ATTRIBUTE_ARCHIVE; + HANDLE hFind; + WIN32_FIND_DATA hFilesFind; + hFind = FindFirstFile(szFile,&hFilesFind); + if (hFind != INVALID_HANDLE_VALUE){ + if (dwFlags & hFilesFind.dwFileAttributes) { + if(hFilesFind.nFileSizeHigh>0) + return ((hFilesFind.nFileSizeHigh*MAXDWORD)+hFilesFind.nFileSizeLow); + else + return (hFilesFind.nFileSizeLow); + } + + } + + FindClose(hFind); + return -1; + } +#endif #ifdef __cplusplus } #endif diff --git a/harbour/contrib/hbzlib/zipnew.cpp b/harbour/contrib/hbzlib/zipnew.cpp index 17800c721e..8456117bc3 100644 --- a/harbour/contrib/hbzlib/zipnew.cpp +++ b/harbour/contrib/hbzlib/zipnew.cpp @@ -54,22 +54,28 @@ char szTempTime[80]; PHB_ITEM pArray=NULL; static PHB_ITEM pChangeDiskBlock; +extern PHB_ITEM pProgressInfo; +extern int iTotal; int hb_CheckSpamMode(char * szFile); /* hb_itemRelease(pChangeDiskBlock); */ #ifdef __cplusplus extern "C" { bool hb_SetCallBack(DWORD iNumber, int , void* pData); bool hb_SetProgress(DWORD , int iSoFar, void* pData); +extern bool hb_SetProgressofTdSpan(DWORD , int iSoFar, void* pData); +bool hb_SetProgressofUnc(DWORD , int iSoFar, void* pData); HB_ZIP_INTERNAL pZipI; #endif -int hb_CmpPkSpan(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive) +int hb_CmpPkSpan(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress) { uLong uiCount; char szNewFile[MAXFILENAME]; CZipArchive szZip; int iCause=0; + uLong uiPos; + DWORD dwSize=0; BOOL bReturn=true; - BOOL bFileExist=hb_fsFile(szFile); + BOOL bFileExist=hb_fsFile((BYTE*)szFile); szZip.SetSpanCallback(hb_SetCallBack,(void*) &pChangeDiskBlock); if (szPassWord != NULL){ szZip.SetPassword(szPassWord); @@ -96,19 +102,50 @@ int hb_CmpPkSpan(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BO bReturn=false; } catch(...){} + if (pProgress != NULL) + pProgressInfo=pProgress; + for (uiCount=1;(uiCount<= hb_arrayLen(pArray)) ;uiCount++) { const char *szDummy = (char *)hb_arrayGetCPtr(pArray,uiCount) ; + dwSize=GetCurrentFileSize(szDummy); + uiPos=uiCount; + try { if (szPassWord != NULL){ szZip.SetPassword(szPassWord); } + if (uiPos== hb_arrayLen(pArray)) + iTotal+=dwSize; + if (pProgress == NULL) + { + + #if defined(__WIN32__) || defined(__MINGW32__) if (bDrive) - szZip.AddNewFileDrv(szDummy, iCompLevel, true,hb_SetProgress,NULL,65536); + szZip.AddNewFileDrv(szDummy, iCompLevel, true,NULL,NULL,65536); + #endif if (bPath) - szZip.AddNewFile(szDummy, iCompLevel, true,hb_SetProgress,NULL,65536); + szZip.AddNewFile(szDummy, iCompLevel, true,NULL,NULL,65536); if (!bDrive && !bPath) - szZip.AddNewFile(szDummy, iCompLevel, false,hb_SetProgress,NULL,65536); + szZip.AddNewFile(szDummy, iCompLevel, false,NULL,NULL,65536); + } + else + { + #if defined(__WIN32__) || defined(__MINGW32__) + if (bDrive) + szZip.AddNewFileDrv(szDummy, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536); + #endif + if (bPath) + szZip.AddNewFile(szDummy, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536); + if (!bDrive && !bPath) + szZip.AddNewFile(szDummy, iCompLevel, false,hb_SetProgressofTdSpan,&pProgress,65536); + + } + if (uiPos== hb_arrayLen(pArray)) + iTotal-=dwSize; + else + iTotal+=dwSize; + } @@ -210,10 +247,12 @@ if (iReturn) { pItem=hb_itemPutC(NULL,(char *)szFileNameInZip); hb_itemArrayPut(pTempArray,filePos,pItem); hb_itemRelease(pItem); + /* szAttr[0] = uAttr & FILE_ATTRIBUTE_READONLY ? _T('r') : _T('-'); szAttr[1] = uAttr & FILE_ATTRIBUTE_HIDDEN ? _T('h') : _T('-'); szAttr[2] = uAttr & FILE_ATTRIBUTE_SYSTEM ? _T('s') : _T('w'); szAttr[3] = (uAttr & FILE_ATTRIBUTE_DIRECTORY) ? _T('D') : uAttr & FILE_ATTRIBUTE_ARCHIVE ? _T('a'): _T('-'); + */ szAttr[4] = fh.IsEncrypted() ? _T('*') : _T(' '); if (fh.m_uUncomprSize>0) { @@ -244,10 +283,11 @@ if (iReturn) { hb_itemArrayPut(pTempArray,Ratio,pItem); hb_itemRelease(pItem); } - +#if defined(__WIN32__) if (iMeth==0 || uAttr & FILE_ATTRIBUTE_DIRECTORY) { szMethod="Stored"; - } + } +#endif if (iMeth==Z_DEFLATED) { uInt iLevel=(uInt)((fh.m_uFlag & 0x6)/2); if (iLevel==0) { @@ -385,14 +425,15 @@ int hb___GetNumbersofFilestoUnzip(char *szFile) return iNumbersOfFiles; } -int hb_CmpPkSpanStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive) +int hb_CmpPkSpanStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress) { uLong uiCount; char szNewFile[MAXFILENAME]; CZipArchive szZip; int iCause=0; + DWORD dwSize=0; BOOL bReturn=true; - BOOL bFileExist=hb_fsFile(szFile); + BOOL bFileExist=hb_fsFile((BYTE*)szFile); szZip.SetSpanCallback(hb_SetCallBack,(void*) &pChangeDiskBlock); if (szPassWord != NULL){ szZip.SetPassword(szPassWord); @@ -419,16 +460,39 @@ int hb_CmpPkSpanStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM bReturn=false; } catch(...){} + if (pProgress != NULL) + pProgressInfo=pProgress; + try { + dwSize=GetCurrentFileSize(szFiletoCompress); if (szPassWord != NULL){ szZip.SetPassword(szPassWord); } + if (pProgress == NULL) + { + + #if defined(__WIN32__) || defined(__MINGW32__) if (bDrive) - szZip.AddNewFileDrv(szFiletoCompress, iCompLevel, true,hb_SetProgress,NULL,65536); + szZip.AddNewFileDrv(szFiletoCompress, iCompLevel, true,NULL,NULL,65536); + #endif if (bPath) - szZip.AddNewFile(szFiletoCompress, iCompLevel, true,hb_SetProgress,NULL,65536); + szZip.AddNewFile(szFiletoCompress, iCompLevel, true,NULL,NULL,65536); if (!bDrive && !bPath) - szZip.AddNewFile(szFiletoCompress, iCompLevel, false,hb_SetProgress,NULL,65536); + szZip.AddNewFile(szFiletoCompress, iCompLevel, false,NULL,NULL,65536); + } + else + { + #if defined(__WIN32__) || defined(__MINGW32__) + if (bDrive) + szZip.AddNewFileDrv(szFiletoCompress, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536); + #endif + if (bPath) + szZip.AddNewFile(szFiletoCompress, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536); + if (!bDrive && !bPath) + szZip.AddNewFile(szFiletoCompress, iCompLevel, false,hb_SetProgressofTdSpan,&pProgress,65536); + + } + iTotal+=dwSize; } catch(...){} @@ -461,7 +525,6 @@ int hb___SetCallbackFunc(PHB_ITEM pFunc) { pChangeDiskBlock=pFunc; pZipI.pItem=pFunc; - return true; } bool hb_SetCallBack(DWORD iNumber, int , void* pData) @@ -486,7 +549,7 @@ bool hb_SetProgress(DWORD , int iSoFar, void* pData){ */ return TRUE; } -int hb_UnzipAll(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pDiskBlock){ +int hb_UnzipAll(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pDiskBlock,PHB_ITEM pProgress){ bool iReturn=true; uLong uiCount=0; int iCause=0; @@ -499,6 +562,9 @@ if (pDiskBlock){ szZip.SetPassword(szPassWord); } iMode=hb_CheckSpamMode(szFile); + if (pProgress != NULL) + pProgressInfo=pProgress; + try { if(iMode==0) { szZip.Open(szFile,CZipArchive::zipOpen,0); @@ -534,8 +600,18 @@ iMode=hb_CheckSpamMode(szFile); szFileNameInZip=(const char *)szTempString; try { + if (pProgress == NULL) + { + szZip.SetPassword(szPassWord); szZip.ExtractFile((WORD)uiCount,(LPCTSTR)szPath,bWithPath,NULL,NULL,NULL); + } + else + { + szZip.SetPassword(szPassWord); + szZip.ExtractFile((WORD)uiCount,(LPCTSTR)szPath,bWithPath,NULL,hb_SetProgressofUnc,(void*)&pProgress); + } + } catch (CZipException& e) { @@ -559,7 +635,7 @@ iMode=hb_CheckSpamMode(szFile); return iReturn; } -int hb_UnzipOne(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,char *szFiletoExtract) +int hb_UnzipOne(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,char *szFiletoExtract,PHB_ITEM pProgress) { bool iReturn=true; int uiCount=0; @@ -607,21 +683,34 @@ iMode=hb_CheckSpamMode(szFile) ; /* if (iCause != 0){ szZip.Close(); }*/ + if (pProgress != NULL) + pProgressInfo=pProgress; + uiCount = szZip.FindFile((LPCTSTR)szFiletoExtract,false); if (uiCount ==-1){ uiCount = szZip.FindFile((LPCTSTR)szFiletoExtract,true); } - if (uiCount >0){ + if (uiCount >=0){ CZipFileHeader fh; const char * szFileNameInZip; CZipString szTempString; szZip.GetFileInfo(fh, (WORD)uiCount); - szTempString =(LPCTSTR)fh.GetFileName(); + szTempString =(LPCTSTR)fh.GetFileName(); + iTotal=fh.m_uUncomprSize; szFileNameInZip=(const char *)szTempString; try { + if (pProgress == NULL) + { + szZip.SetPassword(szPassWord); szZip.ExtractFile((WORD)uiCount,(LPCTSTR)szPath,bWithPath,NULL,NULL,NULL); + } + else { + szZip.SetPassword(szPassWord); + szZip.ExtractFile((WORD)uiCount,(LPCTSTR)szPath,bWithPath,NULL, hb_SetProgressofUnc,(void*)&pProgress); + + } } catch (CZipException& e) { @@ -727,7 +816,7 @@ iMode=hb_CheckSpamMode(szFile); } -hb_UnzipSel(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pSelArray) +int hb_UnzipSel(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pSelArray,PHB_ITEM pProgress) { bool iReturn=true; int uiCount=0; @@ -738,6 +827,9 @@ iMode=hb_CheckSpamMode(szFile); if (szPassWord != NULL){ szZip.SetPassword(szPassWord); } + if (pProgress != NULL) + pProgressInfo=pProgress; + try { if(iMode==0) { szZip.Open(szFile,CZipArchive::zipOpen,0); @@ -766,7 +858,7 @@ iMode=hb_CheckSpamMode(szFile); if (uiCount ==-1){ uiCount = szZip.FindFile((LPCTSTR)hb_arrayGetCPtr(pSelArray,iCause),true); } - if (uiCount >0){ + if (uiCount >=0){ CZipFileHeader fh; const char * szFileNameInZip; CZipString szTempString; @@ -775,8 +867,16 @@ iMode=hb_CheckSpamMode(szFile); szFileNameInZip=(const char *)szTempString; try { + if (pProgress == NULL) + { + szZip.SetPassword(szPassWord); szZip.ExtractFile((WORD)uiCount,(LPCTSTR)szPath,bWithPath,NULL,NULL,NULL); + } + else { + szZip.SetPassword(szPassWord); + szZip.ExtractFile((WORD)uiCount,(LPCTSTR)szPath,bWithPath,NULL,hb_SetProgressofUnc,(void*)&pProgress); + } } catch (CZipException* e) { @@ -888,3 +988,18 @@ catch(CZipException &e) { return iReturn; } +bool hb_SetProgressofUnc(DWORD a, int iSoFar, void* pData){ + + int iReturn=1; +/* iSoFar+=iTotal;*/ + + PHB_ITEM pDisk; + PHB_ITEM pTotal =hb_itemPutNL(NULL,iTotal); + pDisk= hb_itemPutNL(NULL,iSoFar); + hb_vmEvalBlockV( pProgressInfo, 2,pDisk,pTotal); + hb_itemRelease(pDisk); + hb_itemRelease(pTotal); + + return iReturn; + +}