From 31da53b1cc5f1c0414fa6ed8f1c7e8550e7b9980 Mon Sep 17 00:00:00 2001 From: Luiz Rafael Culik Date: Mon, 31 Jul 2000 03:02:01 +0000 Subject: [PATCH] See changelog 2000-07-31 00:10 GMT -3 --- harbour/contrib/hbzlib/doc/zip.txt | 54 ++++- harbour/contrib/hbzlib/makefile.bc | 25 +- harbour/contrib/hbzlib/zipfile.c | 136 +++++++++++ harbour/contrib/hbzlib/zipfile2.c | 129 +++++++++- harbour/contrib/hbzlib/zlibapi1.c | 365 +++++++++++++++++++++++++++++ 5 files changed, 687 insertions(+), 22 deletions(-) create mode 100644 harbour/contrib/hbzlib/zipfile.c create mode 100644 harbour/contrib/hbzlib/zlibapi1.c diff --git a/harbour/contrib/hbzlib/doc/zip.txt b/harbour/contrib/hbzlib/doc/zip.txt index 5a2a1c474c..ce75949ff5 100644 --- a/harbour/contrib/hbzlib/doc/zip.txt +++ b/harbour/contrib/hbzlib/doc/zip.txt @@ -62,7 +62,7 @@ * $COMPLIANCE$ * This function is a Harbour extension * $PLATFORMS$ - * Win32 + * All * $FILES$ * Library is zlib.lib and zlib_bor.lib For Borland Compilers * Library is zlib.lib zlib_ms.lib for MSVC compilers @@ -106,11 +106,59 @@ * * Return Nil * $STATUS$ - * S + * R * $COMPLIANCE$ * This function is a Harbour extension * $PLATFORMS$ - * Win32 + * All + * $FILES$ + * Library is zlib.lib and zlib_bor.lib For Borland Compilers + * Library is zlib.lib zlib_ms.lib for MSVC compilers + * $END$ + */ + +/* + * $DOC$ + * $FUNCNAME$ + * HB_GETUNZIPFILE() + * $CATEGORY$ + * ZIP FUNCTION + * $ONELINER$ + * Gets the number of files + * $SYNTAX$ + * HB_GETUNZIPFILE( ) ---> nNumber + * $ARGUMENTS$ + * Name of the zip file + * $RETURNS$ + * The number of files contained inside the zipfile + * $DESCRIPTION$ + * This function returns the number of files that is stored in the zipfile. + * The propurse for this function is to use in conjuntion with the + * HB_UNZIPFILE() function, so you can use returned result in the code + * block. See example below. + * $EXAMPLES$ + * FUNCTION MAIN() + * Local nFiles :=HB_GETUNZIPFILE('test.zip') + * if nFiles >0 + * ? "This files Contains ",nfiles + * endif + * Return Nil + * + * Here is an example of How to use HB_GETUNZIPFILE() in conjunction + * with HB_UNZIPFILE() + * Function Main() + * Local aGauge,nLen + * aGauge := GaugeNew( 5, 5, 7,40 , "W/B", "W+/B" ,'²') + * GaugeDisplay( aGauge ) + * nlen:=HB_GETUNZIPFILE('test22') + * hb_UNZIPFILE('test22',{|cFile,nPos| GaugeUpdate(aGauge,nPos/nLen),qout(cFile)},.T.) + * return Nil + * $STATUS$ + * R + * $COMPLIANCE$ + * This function is a Harbour extension + * $PLATFORMS$ + * All * $FILES$ * Library is zlib.lib and zlib_bor.lib For Borland Compilers * Library is zlib.lib zlib_ms.lib for MSVC compilers diff --git a/harbour/contrib/hbzlib/makefile.bc b/harbour/contrib/hbzlib/makefile.bc index a0bc51601d..680eb4b764 100644 --- a/harbour/contrib/hbzlib/makefile.bc +++ b/harbour/contrib/hbzlib/makefile.bc @@ -48,8 +48,8 @@ ARFLAGS = /P32 INCLUDE_DIR = ..\..\include ZLIB_DIR = . WINSYS_DIR = \WINDOWS\SYSTEM -CFLAGS = -I$(INCLUDE_DIR) -d $(C_USR) $(CFLAGS) -y -CLIBFLAGS =$(CFLAGS) +CFLAGS = -I$(INCLUDE_DIR) -d $(C_USR) $(CFLAGS) +CLIBFLAGS =$(CFLAGS) -v -y HARBOUR_EXE = $(BIN_DIR)\harbour.exe HARBOURFLAGS = -i$(INCLUDE_DIR) -n -q0 -w -es2 -gc0 $(PRG_USR) $(HARBOURFLAGS) LDFLAGS = $(LDFLAGS) @@ -65,12 +65,13 @@ ZLIB_BOR_DLL = $(ZLIB_DIR)\hbzlib.dll ZLIB_BOR_DEF = $(LIB_DIR)\zlib.def ZLIB_BOR_LIB = $(LIB_DIR)\zlib_bor.lib ZLIB_LIB_OBJS = \ - $(OBJ_DIR)\zipfile1.obj \ + $(OBJ_DIR)\zipfile.obj \ $(OBJ_DIR)\zipfile2.obj \ - $(OBJ_DIR)\zlibapi.obj \ + $(OBJ_DIR)\zlibapi1.obj \ $(OBJ_DIR)\tzipfile.obj ZLIB_EXE_OBJS = \ $(OBJ_DIR)\test.obj + ZLIB_EXE2_OBJS = \ $(OBJ_DIR)\test2.obj @@ -84,7 +85,9 @@ all: \ $(ZLIB_EXE_OBJS) \ $(ZLIB_EXE2_OBJS) \ $(ZLIB_EXE) \ - $(ZLIB_EXE2) + $(ZLIB_EXE2) + + $(ZLIB_LIB) = $(ZLIB_LIB_OBJS) $(ZLIB_EXE) = $(ZLIB_EXE_OBJS) @@ -95,7 +98,7 @@ $(ZLIB_BOR_LIB) = $(ZLIB_BOR_LIB_OBJ) $(ZLIB_LIB) : $(ZLIB_LIB_OBJS) -$(OBJ_DIR)\zipfile1.obj : $(ZLIB_DIR)\zipfile1.c +$(OBJ_DIR)\zipfile.obj : $(ZLIB_DIR)\zipfile.c $(CC) -v -c $(CLIBFLAGS) -o$@ $** tlib $(ZLIB_LIB) $(ARFLAGS) -+$@,, @@ -103,8 +106,8 @@ $(OBJ_DIR)\zipfile2.obj : $(ZLIB_DIR)\zipfile2.c $(CC) -v -c $(CLIBFLAGS) -o$@ $** tlib $(ZLIB_LIB) $(ARFLAGS) -+$@,, -$(OBJ_DIR)\zlibapi.obj : $(ZLIB_DIR)\zlibapi.c - $(CC) -c -v $(CLIBFLAGS) -o$@ $** +$(OBJ_DIR)\zlibapi1.obj : $(ZLIB_DIR)\zlibapi1.c + $(CC) -c -v $(CLIBFLAGS) -o$@ $** tlib $(ZLIB_LIB) $(ARFLAGS) -+$@,, $(OBJ_DIR)\tzipfile.c : $(ZLIB_DIR)\tzipfile.prg @@ -121,7 +124,7 @@ $(ZLIB_BOR_LIB) : $(ZLIB_BOR_LIB_OBJ) $(ZLIB_EXE) : $(ZLIB_EXE_OBJS) - echo. $(CFLAGS) > make.tmp + echo. $(CFLAGS) -v -y > make.tmp echo. -M -e$(ZLIB_EXE) >> make.tmp echo. -I$(INCLUDE_DIR) >> make.tmp echo. $(OBJ_DIR)\test.obj >> make.tmp @@ -150,8 +153,8 @@ $(OBJ_DIR)\test.obj : $(OBJ_DIR)\test.c $(ZLIB_EXE2) : $(ZLIB_EXE2_OBJS) - echo. $(CFLAGS) > make.tmp - echo. -M -e$(ZLIB_EXE) >> make.tmp + echo. $(CFLAGS) -y -v> make.tmp + echo. -M -e$(ZLIB_EXE2) >> make.tmp echo. -I$(INCLUDE_DIR) >> make.tmp echo. $(OBJ_DIR)\test2.obj >> make.tmp echo. $(SAMPLES_LIB) >> make.tmp diff --git a/harbour/contrib/hbzlib/zipfile.c b/harbour/contrib/hbzlib/zipfile.c new file mode 100644 index 0000000000..36e11c3faf --- /dev/null +++ b/harbour/contrib/hbzlib/zipfile.c @@ -0,0 +1,136 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * HB_ZIPFILE() FUNCTION Harbour zip file compress function + * + * Copyright 2000 Luiz Rafael Culik + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version, with one exception: + * + * The exception is that if you link the Harbour Runtime Library (HRL) + * and/or the Harbour Virtual Machine (HVM) with other files to produce + * an executable, this does not by itself cause the resulting executable + * to be covered by the GNU General Public License. Your use of that + * executable is in no way restricted on account of linking the HRL + * and/or HVM code into it. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit + * their web site at http://www.gnu.org/). + * + */ + +#include "hbzip.h" +HB_FUNC(HB_ZIPFILE) +{ + if( ISCHAR(1) && ISCHAR(2)) { + int iCompLevel; + BOOL iOverWrite; + char szFile[_POSIX_PATH_MAX]; + strcpy(szFile,hb_parc(1)); + if( ISNUM(3)) { + iCompLevel=hb_parni(3); + + } + else { + iCompLevel= (-1); + } + if( ISLOG(5)) { + iOverWrite=hb_parl(5); + + } + else { + iOverWrite= 1; + } + hb_retl(hb___CompressOneFile(hb___CheckFile(szFile),hb_parc(2),iCompLevel,hb_param( 4, HB_IT_BLOCK) ,iOverWrite)); + +} + + if(ISCHAR(1) && ISARRAY(2)) { + int iCompLevel; + BOOL iOverWrite; + char szFile[_POSIX_PATH_MAX]; + strcpy(szFile,hb_parc(1)); + + if( ISNUM(3)) { + iCompLevel=hb_parni(3); + + } + else { + iCompLevel= (-1); + } + if( ISLOG(5)) { + iOverWrite=hb_parl(5); + + } + else { + iOverWrite= 1; + } + hb_retl(hb___CompressMultipleFile(hb___CheckFile(szFile),hb_param( 2, HB_IT_ARRAY ),iCompLevel,hb_param( 4,HB_IT_BLOCK),iOverWrite)); + + } + +} +HB_FUNC(HB_UNZIPFILE) + +{ + if( ISCHAR(1) ){ + BOOL iExtractPath; + char szFile[_POSIX_PATH_MAX]; + strcpy(szFile,hb_parc(1)); + + if( ISLOG(3)) { + iExtractPath=hb_parl(3); + } + else { + iExtractPath= 0; + } + hb_retl(hb___unZipFiles(hb___CheckFile(szFile),hb_param( 2, HB_IT_BLOCK),iExtractPath)); + + } +} + +HB_FUNC(HB_GETUNZIPFILE) +{ + if( ISCHAR(1) ){ + char szFile[_POSIX_PATH_MAX]; + strcpy(szFile,hb_parc(1)); + + hb_retni(hb___GetNumbersofFilestoUnzip(hb___CheckFile(szFile))); +} +} + +HB_FUNC(HB_GETFILESINZIP) +{ + if( ISCHAR(1) ){ + PHB_ITEM pArray=NULL; + BOOL bExtended; + char szFile[_POSIX_PATH_MAX]; + strcpy(szFile,hb_parc(1)); + + if( ISLOG(2)) { + bExtended=hb_parl(2); + } + else { + bExtended= 0; + } + pArray=hb___GetFilesNamesFromZip(hb___CheckFile(szFile),bExtended); + hb_itemReturn(pArray); + hb_itemRelease(pArray); + +} +} + diff --git a/harbour/contrib/hbzlib/zipfile2.c b/harbour/contrib/hbzlib/zipfile2.c index b6897a999e..3eded4f15b 100644 --- a/harbour/contrib/hbzlib/zipfile2.c +++ b/harbour/contrib/hbzlib/zipfile2.c @@ -55,8 +55,9 @@ extern int err; extern int Size_Buf; uLong uiCounter; +char szTempTime[80]; unzFile szUnzipFile=NULL; - +void hb_____GetTime(unz_file_info file_info) ; void hb____ChangeFileDate(char *filename,uLong dosdate,tm_unz tmu_date) { #if defined(HB_OS_WIN_32) @@ -108,9 +109,12 @@ int hb___MakeDir(char *szNewDirectory) if (szBuffer[uiLen-1] == '/') { szBuffer[uiLen-1] = '\0'; } + if (hb_fsMkDir(szBuffer)) { - hb_xfree((void*) szBuffer); + + hb_xfree((void*) szBuffer); + return 1; } @@ -123,17 +127,23 @@ int hb___MakeDir(char *szNewDirectory) szTemp++; szHold = *szTemp; *szTemp = 0; + iResult=hb_fsMkDir(szBuffer); if (( iResult== -1) && (errno == ENOENT)) { - hb_xfree((void*) szBuffer); + + hb_xfree((void*) szBuffer); + + return 0; } if (szHold == 0) break; *szTemp++ = szHold; } + hb_xfree((void*) szBuffer); + return 1; } @@ -189,7 +199,7 @@ BOOL hb___unZipFiles(char *szFile,PHB_ITEM pBlock,BOOL bExtractPath) { const char *szZipFileName=NULL; const char *szFilename_to_Extract=NULL; - int i; + BOOL opt_do_extract=1; int opt_overwrite=0; @@ -252,6 +262,7 @@ int hb___ExtractCurrentFile(unzFile szUnzipFile,BOOL popt_extract_without_path,B } Size_Buf = WRITEBUFFERSIZE; + szBuffer = (void*) hb_xalloc(Size_Buf); if (szBuffer==NULL) { @@ -269,7 +280,8 @@ int hb___ExtractCurrentFile(unzFile szUnzipFile,BOOL popt_extract_without_path,B if ((*filename_withoutpath)=='\0') { if (popt_extract_without_path) - { + { + hb_fsMkDir(filename_inzip); } } @@ -290,6 +302,7 @@ int hb___ExtractCurrentFile(unzFile szUnzipFile,BOOL popt_extract_without_path,B } if(pBlock !=NULL){ + PHB_ITEM pFileName=hb_itemPutC(NULL, (char *)write_filename); PHB_ITEM pFilePos=hb_itemPutNI(NULL,uiCounter); hb_vmEvalBlockV( pBlock, 2, pFileName, pFilePos ); @@ -306,6 +319,7 @@ int hb___ExtractCurrentFile(unzFile szUnzipFile,BOOL popt_extract_without_path,B if ((skip==0) && (err==UNZ_OK)) { + nFileHandle=hb_fsCreate((char *) write_filename,FC_NORMAL); @@ -335,6 +349,7 @@ int hb___ExtractCurrentFile(unzFile szUnzipFile,BOOL popt_extract_without_path,B break; } if (err>0) + if (hb_fsWrite(nFileHandle,szBuffer,err)==0) { @@ -343,6 +358,7 @@ int hb___ExtractCurrentFile(unzFile szUnzipFile,BOOL popt_extract_without_path,B } } while (err>0); + hb_fsClose(nFileHandle); if (err==0) hb____ChangeFileDate(write_filename,file_info.dosDate, @@ -361,7 +377,7 @@ int hb___ExtractCurrentFile(unzFile szUnzipFile,BOOL popt_extract_without_path,B unzCloseCurrentFile(szUnzipFile); /* don't lose the error */ } - hb_xfree((void*)szBuffer); + hb_xfree((void*)szBuffer); return err; } @@ -404,14 +420,18 @@ int hb___GetNumbersofFilestoUnzip(char *szFile) /* return iNumbersOfFiles; to avoid warning */ return szGlobalUnzipInfo.number_entry; } -PHB_ITEM hb___GetFilesNamesFromZip(char *szFile) + + +PHB_ITEM hb___GetFilesNamesFromZip(char *szFile,BOOL iMode) { const char *szZipFileName=NULL; char szFilename_Try[512]; char szFileNameinZip[256]; int iNumbersOfFiles; + PHB_ITEM pItem=NULL; PHB_ITEM pArray=NULL; + uLong uiCount; unz_global_info szGlobalUnzipInfo; if (szZipFileName == NULL) @@ -429,7 +449,7 @@ PHB_ITEM hb___GetFilesNamesFromZip(char *szFile) szUnzipFile = unzOpen(szFilename_Try); } } - + if (szUnzipFile==NULL) { exit(1); @@ -446,9 +466,86 @@ PHB_ITEM hb___GetFilesNamesFromZip(char *szFile) { break; } + if (iMode) + { + + PHB_ITEM pTempArray=hb_itemArrayNew(8); + char szTime[8]; + char *szMethod; + char szCRC[8]; + int iLen; + int iCount=0; + int iiCount=0; + + pItem=hb_itemPutC(NULL,szFileNameinZip); + hb_itemArrayPut(pTempArray,filePos,pItem); + hb_itemRelease(pItem); + if (file_info.uncompressed_size>0) { + + pItem=hb_itemPutNL(NULL,file_info.uncompressed_size); + hb_itemArrayPut(pTempArray,Lenght,pItem); + hb_itemRelease(pItem); + pItem=hb_itemPutNL(NULL,file_info.compressed_size); + hb_itemArrayPut(pTempArray,Size,pItem); + hb_itemRelease(pItem); + + pItem=hb_itemPutNL(NULL,100-((file_info.compressed_size*100)/file_info.uncompressed_size)); + hb_itemArrayPut(pTempArray,Ratio,pItem); + hb_itemRelease(pItem); + } + if (file_info.compression_method==0) { + szMethod="Stored"; + } + + if (file_info.compression_method==Z_DEFLATED) { + uInt iLevel=(uInt)((file_info.flag & 0x6)/2); + if (iLevel==0) { + szMethod="Defl:N"; + } + else if (iLevel==1) { + szMethod="Defl:X"; + } + else if ((iLevel==2) || (iLevel==3)) { + szMethod="Defl:F"; + } + else { + szMethod="Unknow"; + } + + pItem=hb_itemPutC(NULL,szMethod); + hb_itemArrayPut(pTempArray,Method,pItem); + hb_itemRelease(pItem); + } + sprintf(szCRC,"%8.8lx\n",(uLong)file_info.crc); + + pItem=hb_itemPutCL(NULL,szCRC,8); + hb_itemArrayPut(pTempArray,Crc32,pItem); + hb_itemRelease(pItem); + pItem=hb_itemPutD(NULL, (long)file_info.tmu_date.tm_year ,(long)file_info.tmu_date.tm_mon + 1,(long)file_info.tmu_date.tm_mday); + hb_itemArrayPut(pTempArray,Date,pItem); + hb_itemRelease(pItem); + hb_____GetTime(file_info); + iLen=strlen(szTempTime); + + for(iCount=10;iCount<19;iCount++) { + if( (iCount>10) && (iCount<19)) { + szTime[iiCount]=szTempTime[iCount]; + iiCount++; + } + } + pItem=hb_itemPutCL(NULL,szTime,8); + hb_itemArrayPut(pTempArray,Time,pItem); + hb_itemRelease(pItem); + hb_itemArrayPut(pArray,uiCount+1,pTempArray); + hb_itemRelease(pTempArray); + } + else { + pItem=hb_itemPutC(NULL,szFileNameinZip); hb_itemArrayPut(pArray,uiCount+1,pItem); hb_itemRelease(pItem); + + } if ((uiCount+1) + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version, with one exception: + * + * The exception is that if you link the Harbour Runtime Library (HRL) + * and/or the Harbour Virtual Machine (HVM) with other files to produce + * an executable, this does not by itself cause the resulting executable + * to be covered by the GNU General Public License. Your use of that + * executable is in no way restricted on account of linking the HRL + * and/or HVM code into it. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit + * their web site at http://www.gnu.org/). + * + */ + + + +#include +#include +#include +#include +#include +#include + +#ifdef HB_OS_UNIX +# include +# include +# include +# include +#else +# include +# include +#endif +#include "hbzip.h" +#include "zip.h" +#define WRITEBUFFERSIZE (16384) +#define MAXFILENAME (256) +int iZipOk; +int Opt_OverWrite=1; +int opt_compress_level=Z_DEFAULT_COMPRESSION; +int err=0; +int Size_Buf=0; +int errclose; +void *cBuffer=NULL; +zipFile szZipFile; +#if defined(HB_OS_WIN_32) +uLong hb___filetime(char *f, tm_zip *tmzip, uLong *dt) +{ + int iRet = 0; + HB_SYMBOL_UNUSED(tmzip); + { + FILETIME ftLocal; + HANDLE hFind; + WIN32_FIND_DATA ff32; + + hFind = FindFirstFile(f,&ff32); + if (hFind != INVALID_HANDLE_VALUE) + { + FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); + FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); + FindClose(hFind); + iRet = 1; + } + } + return iRet; +} +#elif defined(HB_OS_UNIX) +uLong hb___filetime(char *f, tm_zip *tmzip, uLong *dt) +{ + int ret=0; + struct stat s; /* results of stat() */ + struct tm* filedate; + time_t tm_t=0; + + if (strcmp(f,"-")!=0) + { + char name[MAXFILENAME]; + int len = strlen(f); + strcpy(name, f); + if (name[len - 1] == '/') + name[len - 1] = '\0'; + /* not all systems allow stat'ing a file with / appended */ + if (stat(name,&s)==0) + { + tm_t = s.st_mtime; + ret = 1; + } + } + filedate = localtime(&tm_t); + + tmzip->tm_sec = filedate->tm_sec; + tmzip->tm_min = filedate->tm_min; + tmzip->tm_hour = filedate->tm_hour; + tmzip->tm_mday = filedate->tm_mday; + tmzip->tm_mon = filedate->tm_mon ; + tmzip->tm_year = filedate->tm_year; + + return ret; +} +#else +uLong hb___filetime(char *f, tm_zip *tmzip, uLong *dt) +{ + return 0; +} +#endif + +char *hb___CheckFile( char * szFile) + { + int uiCount,uiLen; + int uiDot_Found=0; + iZipOk=1; + uiLen=strlen(szFile); + + for (uiCount=0;uiCount0) + { + err = zipWriteInFileInZip (szZipFile,cBuffer,size_read); + if (err<0) + { +/* printf("error in writing %s in the zipfile\n", + filenameinzip);*/ + } + + } + } while ((err == ZIP_OK) && (size_read>0)); + + hb_fsClose(nFileHandle); + if (err<0) + err=ZIP_ERRNO; + else + { + err = zipCloseFileInZip(szZipFile); + if (err!=ZIP_OK) + return err; + } + + errclose = zipClose(szZipFile,NULL); + if (errclose != ZIP_OK) + return errclose; + + } +} + + hb_xfree( (void *) cBuffer ) ; + return 1; /* to avoid warning */ +} + +int hb___CompressMultipleFile(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite) +{ + uLong uiCount; + char szNewFile[MAXFILENAME]; + strcpy(szNewFile,szFile); + + Size_Buf = WRITEBUFFERSIZE; + if(iCompLevel != NULL){ + opt_compress_level=iCompLevel; + } + + cBuffer = (void*) hb_xalloc(Size_Buf); + if (cBuffer==NULL) + { + return ZIP_INTERNALERROR; + } + if (iZipOk==1) + { +/* zipFile szZipFile;*/ + err=0; +/* ULONG nSize=hb_arrayLen(pArray) ;*/ + szZipFile = zipOpen(szNewFile,0); + if (szZipFile == NULL) + { + err= ZIP_ERRNO; + } + + for (uiCount=1;(uiCount<= hb_arrayLen(pArray)) && (err==ZIP_OK);uiCount++) + { + + FHANDLE nFileHandle; + int size_read; + zip_fileinfo szZipFileInfo; + + char *szDummy = hb_arrayGetCPtr(pArray,uiCount) ; + const char *filenameinzip =szDummy; +/* hb_itemFreeC(szDummy);*/ + szZipFileInfo.tmz_date.tm_sec = szZipFileInfo.tmz_date.tm_min = szZipFileInfo.tmz_date.tm_hour = 0; + szZipFileInfo.tmz_date.tm_mday = szZipFileInfo.tmz_date.tm_min = szZipFileInfo.tmz_date.tm_year = 0; + szZipFileInfo.dosDate = 0; + szZipFileInfo.internal_fa = 0; + szZipFileInfo.external_fa = 0; + hb___filetime((char *)filenameinzip,&szZipFileInfo.tmz_date,&szZipFileInfo.dosDate); + if(pBlock !=NULL){ + + PHB_ITEM pFileName=hb_itemPutC(NULL,hb_arrayGetCPtr(pArray,uiCount)); + PHB_ITEM pFilePos=hb_itemPutNI(NULL,uiCount); + hb_vmEvalBlockV( pBlock, 2, pFileName, pFilePos ); + hb_itemRelease(pFileName); + hb_itemRelease(pFilePos); + } + err = zipOpenNewFileInZip(szZipFile,filenameinzip,&szZipFileInfo, + NULL,0,NULL,0,NULL /* comment*/, + (opt_compress_level != 0) ? Z_DEFLATED : 0, + opt_compress_level); + + if (err == ZIP_OK) { + + nFileHandle = hb_fsOpen((char*) filenameinzip,FO_READ+FO_COMPAT); + + if (nFileHandle==NULL) + { + err=ZIP_ERRNO; + } + + hb_fsSetDevRaw(nFileHandle); + + } + + if (err == ZIP_OK) + do + { + err = ZIP_OK; + + size_read = hb_fsRead(nFileHandle,cBuffer,Size_Buf); + if (size_read < Size_Buf) + if (hb_fsEof(nFileHandle)==0) + { + + err = ZIP_ERRNO; + } + + if (size_read>0) + { + err = zipWriteInFileInZip (szZipFile,cBuffer,size_read); + if (err<0) + { + } + + } + } while ((err == ZIP_OK) && (size_read>0)); + + hb_fsClose(nFileHandle); + if (err<0) + { + err=ZIP_ERRNO; + } + else { + err = zipCloseFileInZip(szZipFile); + if (err!=ZIP_OK){ +/* printf("error in closing %s in the zipfile\n", + filenameinzip);*/ + return -1; + + + } + } + + } + errclose = zipClose(szZipFile,NULL); + } + + hb_xfree( (void *) cBuffer ) ; + + return 1; /* to avoid warning */ + +}