See changelog 2000-07-31 00:10 GMT -3

This commit is contained in:
Luiz Rafael Culik
2000-07-31 03:02:01 +00:00
parent 3d37397709
commit 31da53b1cc
5 changed files with 687 additions and 22 deletions

View File

@@ -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( <cFile>) ---> nNumber
* $ARGUMENTS$
* <cFile> Name of the zip file
* $RETURNS$
* <nNumber> 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

View File

@@ -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

View File

@@ -0,0 +1,136 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* HB_ZIPFILE() FUNCTION Harbour zip file compress function
*
* Copyright 2000 Luiz Rafael Culik <culik@sl.conex.net>
* 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);
}
}

View File

@@ -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)<iNumbersOfFiles)
{
err = unzGoToNextFile(szUnzipFile);
@@ -461,7 +558,23 @@ PHB_ITEM hb___GetFilesNamesFromZip(char *szFile)
}
unzCloseCurrentFile(szUnzipFile);
hb_itemReturn(pArray);
}
void hb_____GetTime(unz_file_info file_info)
{
struct tm t;
t.tm_sec = file_info.tmu_date.tm_sec;
t.tm_min = file_info.tmu_date.tm_min;
t.tm_hour = file_info.tmu_date.tm_hour;
t.tm_mday = file_info.tmu_date.tm_mday;
t.tm_mon = file_info.tmu_date.tm_mon;
t.tm_year = file_info.tmu_date.tm_year;
t.tm_wday = 4;
t.tm_yday = 0;
t.tm_isdst = 0;
strcpy(szTempTime, asctime(&t));
}

View File

@@ -0,0 +1,365 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* Low level zip functions for Zlib dll Call
*
* Copyright 2000 Luiz Rafael Culik <culik@sl.conex.net>
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#ifdef HB_OS_UNIX
# include <unistd.h>
# include <utime.h>
# include <sys/types.h>
# include <sys/stat.h>
#else
# include <direct.h>
# include <io.h>
#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;uiCount<uiLen;uiCount++)
if (szFile[uiCount]=='.')
uiDot_Found=1;
if (uiDot_Found==0)
strcat(szFile,".zip");
return szFile;
}
int hb___CompressOneFile(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite)
{
int 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)
{
szZipFile = zipOpen(szNewFile,0);
if (szZipFile == NULL) {
err= ZIP_ERRNO;
}
else {
FHANDLE nFileHandle;
int size_read;
char *filenameinzip = szFiletoCompress;
zip_fileinfo szZipFileInfo;
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_mon = szZipFileInfo.tmz_date.tm_year = 0;
szZipFileInfo.dosDate = 0;
szZipFileInfo.internal_fa = 0;
szZipFileInfo.external_fa = 0;
hb___filetime(filenameinzip,&szZipFileInfo.tmz_date,&szZipFileInfo.dosDate);
if(pBlock !=NULL){
PHB_ITEM pFileName=hb_itemPutC(NULL,szFiletoCompress );
hb_vmEvalBlockV( pBlock, 1, pFileName );
hb_itemRelease(pFileName);
}
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(filenameinzip,FO_READ+FO_COMPAT);
if (nFileHandle==NULL)
{
err=ZIP_ERRNO;
}
}
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)
{
/* 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 */
}