diff --git a/harbour/contrib/hbzlib/hbzip.h b/harbour/contrib/hbzlib/hbzip.h index 21a303a176..496a6a3b77 100644 --- a/harbour/contrib/hbzlib/hbzip.h +++ b/harbour/contrib/hbzlib/hbzip.h @@ -43,15 +43,20 @@ #include "hbvmpub.h" #define WIN32 #include "zip.h" +#include "unzip.h" #if defined(HB_EXTERN_C) extern "C" { #endif extern uLong hb___filetime(char *f, tm_zip *tmzip, uLong *dt); extern char *hb___CheckFile( char * szFile); -extern int hb___CompressOneFile(char *szFile,char *szFiletoCompress); -extern int hb___CompressMultipleFile(char *szFile,PHB_ITEM pArray); - +extern int hb___CompressOneFile(char *szFile,char *szFiletoCompress,int iCompLevel); +extern int hb___CompressMultipleFile(char *szFile,PHB_ITEM pArray,int iCompLevel); +extern int hb___unZipFiles(char *szFile); +extern int hb___ExtractCurrentFile(unzFile uf,const int* popt_extract_without_path,int* popt_overwrite); +extern void hb____ChangeFileDate(const char *filename,uLong dosdate,tm_unz tmu_date); +extern int hb___MyMkdir(const char *DirectoryName); +extern int hb___MakeDir(char *NewDirectory); #if defined(HB_EXTERN_C) } #endif diff --git a/harbour/contrib/hbzlib/makefile.bc b/harbour/contrib/hbzlib/makefile.bc index d1f8936148..fb3ea06ffd 100644 --- a/harbour/contrib/hbzlib/makefile.bc +++ b/harbour/contrib/hbzlib/makefile.bc @@ -64,6 +64,7 @@ ZLIB_BOR_DEF = $(LIB_DIR)\zlib.def ZLIB_BOR_LIB = $(LIB_DIR)\zlib_bor.lib ZLIB_LIB_OBJS = \ $(OBJ_DIR)\zipfile1.obj \ + $(OBJ_DIR)\zipfile2.obj \ $(OBJ_DIR)\zlibapi.obj ZLIB_EXE_OBJS = \ $(OBJ_DIR)\test.obj @@ -91,6 +92,10 @@ $(OBJ_DIR)\zipfile1.obj : $(ZLIB_DIR)\zipfile1.c $(CC) -v -c $(CLIBFLAGS) -o$@ $** tlib $(ZLIB_LIB) $(ARFLAGS) -+$@,, +$(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$@ $** tlib $(ZLIB_LIB) $(ARFLAGS) -+$@,, diff --git a/harbour/contrib/hbzlib/test.prg b/harbour/contrib/hbzlib/test.prg index aa28338724..e69de29bb2 100644 --- a/harbour/contrib/hbzlib/test.prg +++ b/harbour/contrib/hbzlib/test.prg @@ -1,4 +0,0 @@ -Function Main() -HB_ZIPFILE('test.zip','zip.h') -Hb_ZIPFILE('test1.zip',{'.\test.prg','.\zlib.h','.\zip.h','..\..\obj\b32\test.obj'}) -return nil diff --git a/harbour/contrib/hbzlib/zipfile2.c b/harbour/contrib/hbzlib/zipfile2.c new file mode 100644 index 0000000000..6813c400e8 --- /dev/null +++ b/harbour/contrib/hbzlib/zipfile2.c @@ -0,0 +1,301 @@ +#include "hbzip.h" +#include +#include +#include +#include +#include +#include + +# include +# include + +#define CASESENSITIVITY (0) +#define WRITEBUFFERSIZE (8192) +extern int err; + +void hb____ChangeFileDate(const char *filename,uLong dosdate,tm_unz tmu_date) +{ +#ifdef WIN32 + HANDLE hFile; + FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; + HB_SYMBOL_UNUSED(tmu_date); + hFile = CreateFile(filename,GENERIC_READ | GENERIC_WRITE, + 0,NULL,OPEN_EXISTING,0,NULL); + GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); + DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); + LocalFileTimeToFileTime(&ftLocal,&ftm); + SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); + CloseHandle(hFile); +#endif +} + + +/* mymkdir and change_file_date are not 100 % portable + As I don't know well Unix, I wait feedback for the unix portion */ + +int hb___MyMkdir(const char *DirectoryName) +{ + int uiReturn; + uiReturn = mkdir(DirectoryName); + return uiReturn; +} + +int hb___MakeDir(char *NewDirectory) +{ + char *szBuffer ; + char *p; + int uiLen = strlen(NewDirectory); + + if (uiLen <= 0) + return 0; + + szBuffer = (void*)hb_xalloc(uiLen+1); + strcpy(szBuffer,NewDirectory); + + if (szBuffer[uiLen-1] == '/') { + szBuffer[uiLen-1] = '\0'; + } + if (hb___MyMkdir(szBuffer) == 0) + { + hb_xfree((void*) szBuffer); + return 1; + } + + p = szBuffer+1; + while (1) + { + char hold; + + while(*p && *p != '\\' && *p != '/') + p++; + hold = *p; + *p = 0; + if ((hb___MyMkdir(szBuffer) == -1) && (errno == ENOENT)) + { + hb_xfree((void*) szBuffer); + return 0; + } + if (hold == 0) + break; + *p++ = hold; + } + hb_xfree((void*) szBuffer); + return 1; +} + +int hb___ExtractOneFile(unzFile uf,const char* filename,int opt_extract_without_path,int opt_overwrite) +{ + err = UNZ_OK; + if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK) + { + return 2; + } + + if (hb___ExtractCurrentFile(uf,&opt_extract_without_path, + &opt_overwrite) == UNZ_OK) + return 0; + else + return 1; +} + +int hb___Extract(unzFile uf,int opt_extract_without_path,int opt_overwrite) +{ + uLong uiCount; + unz_global_info szGlobalUnzipInfo; + + + err = unzGetGlobalInfo (uf,&szGlobalUnzipInfo); + if (err!=UNZ_OK) { +/* printf("error %d with zipfile in unzGetGlobalInfo \n",err);*/ +} + for (uiCount=1;uiCount<=szGlobalUnzipInfo.number_entry;uiCount++) + { + if (hb___ExtractCurrentFile(uf,&opt_extract_without_path, + &opt_overwrite) != UNZ_OK) + break; + + if ((uiCount+1)0) + if (hb_fsWrite(fout,buf,err)==0) + { + + err=UNZ_ERRNO; + break; + } + } + while (err>0); + hb_fsClose(fout); + if (err==0) + hb____ChangeFileDate(write_filename,file_info.dosDate, + file_info.tmu_date); + } + + if (err==UNZ_OK) + { + err = unzCloseCurrentFile (uf); + if (err!=UNZ_OK) + { + + } + } + else + unzCloseCurrentFile(uf); /* don't lose the error */ + } + + hb_xfree((void*)buf); + return err; +} + +