From abd074d0b781fa907d7c65ae47b33523932de81e Mon Sep 17 00:00:00 2001 From: Luiz Rafael Culik Date: Sat, 19 May 2001 21:59:37 +0000 Subject: [PATCH] See changelog 2001-05-19 19:00 GMT -3 --- harbour/ChangeLog | 17 + harbour/contrib/hbzlib/doc/zipnew.txt | 639 ++++++++++++++++++ harbour/contrib/hbzlib/hbzip2.h | 115 ++++ harbour/contrib/hbzlib/makefile2.bc | 126 ++++ harbour/contrib/hbzlib/zip.c | 192 ++++++ harbour/contrib/hbzlib/zipcomp.cpp | 376 +++++++++++ harbour/contrib/hbzlib/zipnew.cpp | 889 ++++++++++++++++++++++++++ harbour/utils/hbmake/hbmake.prg | 41 +- 8 files changed, 2384 insertions(+), 11 deletions(-) create mode 100644 harbour/contrib/hbzlib/doc/zipnew.txt create mode 100644 harbour/contrib/hbzlib/hbzip2.h create mode 100644 harbour/contrib/hbzlib/makefile2.bc create mode 100644 harbour/contrib/hbzlib/zip.c create mode 100644 harbour/contrib/hbzlib/zipcomp.cpp create mode 100644 harbour/contrib/hbzlib/zipnew.cpp diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 2d012e6633..f42594a824 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,20 @@ +2001-05-19 19:00 GMT -3 Luiz Rafael Culik ++contrib/hbzlib/hbzip2.h + *include files need by the library ++contrib/hbzlib/zip.c + *Harbour Level functions for hbzlib ++contrib/hbzlib/zipcomp.cpp + *Low level api's for hbzlib compression ++contrib/hbzlib/zipnew.cpp + *Low level api's for hbzlib Extraction ++contrib/hbzlib/makefile2.bc + *makefile to make the new hbzlib ++contrib/hbzlib/doc/zipnew.txt + *Docs for the new hbzlib function interface +*utils/hbmake/hbmake.prg + *Fixed an small bug when generating the script(possibitity fo not find the file under linux) + *updated to the new license + 2001-05-18 13:20 UTC-0400 David G. Holm * source/rtl/dbdelim.prg diff --git a/harbour/contrib/hbzlib/doc/zipnew.txt b/harbour/contrib/hbzlib/doc/zipnew.txt new file mode 100644 index 0000000000..451408e281 --- /dev/null +++ b/harbour/contrib/hbzlib/doc/zipnew.txt @@ -0,0 +1,639 @@ +/* + * $DOC$ + * $FUNCNAME$ + * HB_ZIPFILE() + * $CATEGORY$ + * ZIP FUNCTION + * $ONELINER$ + * Create a zip file + * $SYNTAX$ + * HB_ZIPFILE( , | , , + * , ,,,) ---> lCompress + * $ARGUMENTS$ + * Name of the zip file + * + * Name of a file to Compress, Drive and/or path + * can be used + * + * An array containing files to compress, Drive and/or path + * can be used + * + * Compression level ranging from 0 to 9 + * + * Code block to execute while compressing + * + * Toggle to overwite the file if exists + * + * Password to encrypt the files + * + * Toggle to store the path or not + * + * Toggle to store the Drive letter and path or not + * $RETURNS$ + * .t. if file was create, otherwise .f. + * $DESCRIPTION$ + * This function creates a zip file named . If the extension + * is ommited, .ZIP will be assumed. If the second parameter is a + * character string, this file will be added to the zip file. If the + * second parameter is an array, all file names contained in + * will be compressed. + * + * If is used, it detemines the compression type where 0 means + * no compression and 9 means best compression. + * + * If is used, every time the file is opened to compress it + * will evaluate bBlock. Parameters of bBlock are cFile and nPos. + * + * If is used , it toggles to overwrite or not the existing + * file. Default is to overwrite the file,otherwise if is false + * the new files are added to the . + * + * If is used, all files that are added to the archive are encrypted + * with the password. + * + * If is used, it tells thats the path should also be stored with + * the file name. Default is false. + * + * If is used, it tells thats the Drive and path should also be stored + * with the file name. Default is false. + * + * $EXAMPLES$ + * FUNCTION MAIN() + * + * IF HB_ZIPFILE( "TEST.ZIP","TEST.PRG") + * qout("File was successly create") + * ENDIF + * + * IF HB_ZIPFILE( "TEST1.ZIP",{"TEST.PRG","c:\windows\win.ini"}) + * qout("File was successly create") + * ENDIF + * + * IF HB_ZIPFILE( "TEST2.ZIP",{"TEST.PRG","c:\windows\win.ini"},8,{|nPos,cFile|,qout(cFile)}) + * qout("File was successly create") + * ENDIF + * + * aFiles := {"TEST.PRG","c:\windows\win.ini"} + * nLen := Len(afiles) + * aGauge := GaugeNew( 5, 5, 7,40 , "W/B", "W+/B" ,'²') + * GaugeDisplay( aGauge ) + * Hb_ZIPFILE('test33.zip',aFiles,8,{|cFile,nPos| GaugeUpdate(aGauge,nPos/nLen)},,'hello') + * 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 + * $END$ + */ + +/* + * $DOC$ + * $FUNCNAME$ + * HB_UNZIPFILE() + * $CATEGORY$ + * ZIP FUNCTION + * $ONELINER$ + * Unzip a compressed file + * $SYNTAX$ + * HB_UNZIPFILE( , , ) ,,, + * [|] <---> lCompress + * $ARGUMENTS$ + * Name of the zip file + * + * Code block to execute while compressing + * + * Toggle to create directory if needed + * + * Password to use to extract files + * + * Path to extract the files. + * + * | An file or an Array of files to extract + * $RETURNS$ + * .t. if all file was successfuly restored, otherwise .f. + * $DESCRIPTION$ + * This function restores all files contained inside the . + * If the extension is ommited, .ZIP will be assumed. If a file already + * exists, it wlll be overwriten. + * + * If is used, every time the file is opened to compress it + * will evaluate bBlock. Parameters of bBlock are cFile and nPos. + * + * The is an obrogatory parameter. Set to ".\" to extract to the + * current dir + * $EXAMPLES$ + * FUNCTION MAIN() + * + * IF HB_UNZIPFILE( "TEST.ZIP") + * qout("File was successly create") + * ENDIF + * + * IF HB_ZIPFILE( "TEST2.ZIP",{|cFile|,qout(cFile)}) + * qout("File was successly create") + * ENDIF + * + * 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 + * $END$ + */ + +/* + * $DOC$ + * $FUNCNAME$ + * HB_GETUNZIPFILE() + * $CATEGORY$ + * ZIP FUNCTION + * $ONELINER$ + * Gets the number of files that are in the zipfile + * $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 purpose 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 + * $END$ + */ + +/* + * $DOC$ + * $FUNCNAME$ + * HB_ZIPFILEBYTDSPAN() + * $CATEGORY$ + * ZIP FUNCTION + * $ONELINER$ + * Create a zip file + * $SYNTAX$ + * HB_ZIPFILEBYTDSPAN()( , | , , + * , ,,,) ---> lCompress + * $ARGUMENTS$ + * Name of the zip file + * + * Name of a file to Compress, Drive and/or path + * can be used + * + * An array containing files to compress, Drive and/or path + * can be used + * + * Compression level ranging from 0 to 9 + * + * Code block to execute while compressing + * + * Toggle to overwite the file if exists + * + * Password to encrypt the files + * + * Size of the archive + * + * Toggle to store the path or not + * + * Toggle to store the Drive letter and path or not + * $RETURNS$ + * .t. if file was create, otherwise .f. + * $DESCRIPTION$ + * This function creates a zip file named . If the extension + * is ommited, .ZIP will be assumed. If the second parameter is a + * character string, this file will be added to the zip file. If the + * second parameter is an array, all file names contained in + * will be compressed. + * + * If is used, it detemines the compression type where 0 means + * no compression and 9 means best compression. + * + * If is used, every time the file is opened to compress it + * will evaluate bBlock. Parameters of bBlock are cFile and nPos. + * + * If is used , it toggles to overwrite or not the existing + * file. Default is to overwrite the file,otherwise if is false + * the new files are added to the . + * + * If is used, it tells thats the path should also be stored with + * the file name. Default is false. + * + * If is used, it tells thats the Drive and path should also be stored + * with the file name. Default is false. + * + * $EXAMPLES$ + * FUNCTION MAIN() + * + * IF HB_ZIPFILEBYTDSPAN( "TEST.ZIP","TEST.PRG") + * qout("File was successly create") + * ENDIF + * + * IF ZIPFILEBYTDSPAN( "TEST1.ZIP",{"TEST.PRG","c:\windows\win.ini"}) + * qout("File was successly create") + * ENDIF + * + * IF HB_ZIPFILEBYTDSPAN( "TEST2.ZIP",{"TEST.PRG","c:\windows\win.ini"},8,{|nPos,cFile|,qout(cFile)},'hello',,521421) + * qout("File was successly create") + * ENDIF + * + * aFiles := {"TEST.PRG","c:\windows\win.ini"} + * nLen := Len(afiles) + * aGauge := GaugeNew( 5, 5, 7,40 , "W/B", "W+/B" ,'²') + * GaugeDisplay( aGauge ) + * HB_ZIPFILEBYTDSPAN('test33.zip',aFiles,8,{|cFile,nPos| GaugeUpdate(aGauge,nPos/nLen)},,'hello',,6585452) + * 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 + * $END$ + */ + + +/* + * $DOC$ + * $FUNCNAME$ + * HB_ZIPFILEBYPKSPAN() + * $CATEGORY$ + * ZIP FUNCTION + * $ONELINER$ + * Create a zip file on removable media + * $SYNTAX$ + * HB_ZIPFILEBYPKSPAN( , | , , + * , ,,) ---> lCompress + * $ARGUMENTS$ + * Name of the zip file + * + * Name of a file to Compress, Drive and/or path + * can be used + * + * An array containing files to compress, Drive and/or path + * can be used + * + * Compression level ranging from 0 to 9 + * + * Code block to execute while compressing + * + * Toggle to overwite the file if exists + * + * Password to encrypt the files + * + * Toggle to store the path or not + * + * Toggle to store the Drive letter and path or not + * $RETURNS$ + * .t. if file was create, otherwise .f. + * $DESCRIPTION$ + * This function creates a zip file named . If the extension + * is ommited, .ZIP will be assumed. If the second parameter is a + * character string, this file will be added to the zip file. If the + * second parameter is an array, all file names contained in + * will be compressed.Also , the use of this function is for creating + * backup in removable media like an floppy drive/zip drive. + * + * If is used, it detemines the compression type where 0 means + * no compression and 9 means best compression. + * + * If is used, every time the file is opened to compress it + * will evaluate bBlock. Parameters of bBlock are cFile and nPos. + * + * If is used , it toggles to overwrite or not the existing + * file. Default is to overwrite the file,otherwise if is false + * the new files are added to the . + * + * If is used, all files that are added to the archive are encrypted + * with the password. + * + * If is used, it tells thats the path should also be stored with + * the file name. Default is false. + * + * If is used, it tells thats the Drive and path should also be stored + * with the file name. Default is false. + * + * Before calling this function, Set an Changedisk codeblock by calling + * the HB_SETDISKZIP(). + * $EXAMPLES$ + * FUNCTION MAIN() + * + * IF HB_ZIPFILE( "a:\TEST.ZIP","TEST.PRG") + * qout("File was successly create") + * ENDIF + * + * IF HB_ZIPFILEBYPKSPAN( "a:\TEST1.ZIP",{"TEST.PRG","c:\windows\win.ini"}) + * qout("File was successly create") + * ENDIF + * + * IF HB_ZIPFILEBYPKSPAN( "TEST2.ZIP",{"TEST.PRG","c:\windows\win.ini"},8,{|nPos,cFile|,qout(cFile)}) + * qout("File was successly create") + * ENDIF + * + * aFiles := {"TEST.PRG","c:\windows\win.ini"} + * nLen := Len(afiles) + * aGauge := GaugeNew( 5, 5, 7,40 , "W/B", "W+/B" ,'²') + * GaugeDisplay( aGauge ) + * Hb_ZIPFILEBYPKSPAN('f:\test33.zip',aFiles,8,{|cFile,nPos| GaugeUpdate(aGauge,nPos/nLen)},,'hello') + * // assuming f:\ as an Zip Drive + * 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 + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * HB_SETDISKZIP() + * $CATEGORY$ + * Zip Function + * $ONELINER$ + * Set an codeblock for disk changes + * $SYNTAX$ + * HB_SETDISKZIP() + * $ARGUMENTS$ + * an Code block that contains an function that will be performed + * when the need of changing disk are need. + * $RETURNS$ + * It returns allways True + * $DESCRIPTION$ + * This function will set an codeblock that will be evaluated every time + * that an changedisk event is neccessary. + * + * Set this function before opening archives that are in removable media. + * This block will be released, when the caller finish it job. + * $EXAMPLES$ + * HB_SETDISKZIP({|x| alert('Please insert disk no "+str(x,3))}) + * $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 + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * HB_ZIPDELETEFILES() + * $CATEGORY$ + * Zip Functions + * $ONELINER$ + * Delete files from an zip archive + * $SYNTAX$ + * HB_ZIPDELETEFILES(,|) --> + * $ARGUMENTS$ + * The name of the zip files from where the files will be deleted + * + * An File to be removed + * + * An Array of Files to Be Removed + * $RETURNS$ + * If the files are deleted , it will return .T., otherwise + * it will return .f. for the Follow cases: Spanned Archives, the file + * could not be found in the zip file. + * $DESCRIPTION$ + * This function removes files from an Zip archive. + * $EXAMPLES$ + * ? "has the file zipnew.i been deleted ",if(HB_ZIPDELETEFILES('\test23.zip','zipnew.i'),"Yes","No") + * $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 + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * HB_ZIPTESTPK() + * $CATEGORY$ + * Zip Functions + * $ONELINER$ + * Test pkSpaned zip files + * $SYNTAX$ + * HB_ZIPTESTPK() --> + * $ARGUMENTS$ + * File to be tested. + * $RETURNS$ + * An code that tell if the current disk is the Last of an pkspanded + * disk set. + * $DESCRIPTION$ + * This function tests if the disk inserted is the last disk of an backup + * set or not. + * It will return the follow return code when an error is found + * + * + * Error code Meaning + * 114 Incorrect Disk + * 103 No Call back was set with HB_SETDISKZIP() + *
+ * + * Call this function to determine if the disk inserted is the correct + * one before any other function. + * $EXAMPLES$ + * if (HB_ZIPTESTPK('a:\test22.zip')==114) + * ? "invalid Disk" + * endif + * $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 + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * HB_GETZIPCOMMENT() + * $CATEGORY$ + * Zip Functions + * $ONELINER$ + * Return the comment of an zip file + * $SYNTAX$ + * HB_GETZIPCOMMENT() --> + * $ARGUMENTS$ + * File to get the comment from + * $RETURNS$ + * The comment that was stored in + * $DESCRIPTION$ + * This function recieve an valid zip file name as parameter, + * and return the global comment stored within. + * $EXAMPLES$ + * ? "The comment of tes.zip",HB_GETZIPCOMMENT('tes.zip') + * $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 + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * HB_SETZIPCOMMENT() + * $CATEGORY$ + * Zip Functions + * $ONELINER$ + * Set an Zip archive Comment + * $SYNTAX$ + * HB_SETZIPCOMMENT() -->Nil + * $ARGUMENTS$ + * Comment to add to the zip archive + * $RETURNS$ + * this function always return NIL + * $DESCRIPTION$ + * This function stored an global comment to an zip archive. + * It should be called before any of the Compression Function. + * $EXAMPLES$ + * HB_SETZIPCOMMENT("This is an Test") + * hb_zipfile('test.zip',{"\windows\ios.ini","\windows\win.ini"}) + * $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 + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * HB_SETBUFFER() + * $CATEGORY$ + * + * $ONELINER$ + * + * $SYNTAX$ + * HB_SETBUFFER([],[],[]) -->Nil + * $ARGUMENTS$ + * The size of the write buffer. + * + * The size of the extract buffer. + * + * The size of the read buffer. + * $RETURNS$ + * This function always return NIL. + * $DESCRIPTION$ + * This function set the size of the internal buffers for read/write/extract + * operation + * + * If the size of the buffer is smaller then the default , the function + * will automaticaly use the default values,which is 65535/16384/32768. + * + * This function be called before any of the Compression/decompression + * Function. + * $EXAMPLES$ + * HB_SETBUFFER(100000,115214,65242) + * $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 + * $END$ + */ + +/* + * $DOC$ + * $FUNCNAME$ + * HB_GETUNRARFILE() + * $CATEGORY$ + * RAR FUNCTION + * $ONELINER$ + * Gets the number of files that are in the rar file + * $SYNTAX$ + * HB_GETUNRARFILE( ) ---> nNumber + * $ARGUMENTS$ + * Name of the rar file + * $RETURNS$ + * The number of files contained inside the rarfile + * $DESCRIPTION$ + * This function returns the number of files that is stored in the rar file. + * $EXAMPLES$ + * FUNCTION MAIN() + * Local nFiles :=HB_GETUNZIPFILE('test.zip') + * + * if nFiles >0 + * ? "This files Contains ",nfiles + * endif + * + * 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 + * $END$ + */ diff --git a/harbour/contrib/hbzlib/hbzip2.h b/harbour/contrib/hbzlib/hbzip2.h new file mode 100644 index 0000000000..acc88cdfe1 --- /dev/null +++ b/harbour/contrib/hbzlib/hbzip2.h @@ -0,0 +1,115 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Header file for the Zlib API, + * + * Copyright 2000-2001 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, or (at your option) + * any later version. + * + * 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 software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries 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 Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + + +#ifndef HB_APIZLIB_H_ +#define HB_APIZLIB_H_ +#include +#include +#include +#include +#include +#include +#include + +#include + +#ifdef __cplusplus +#include +extern "C" { +#endif + +#define filePos 1 +#define Lenght 2 +#define Method 3 +#define Size 4 +#define Ratio 5 +#define Date 6 +#define Time 7 +#define Crc32 8 +#define Attr 9 +#define WRITEBUFFERSIZE (16384) +#define MAXFILENAME (256) +typedef struct _HB_ZIP_INTERNAL{ +int iWrite; +int iExtract; +int iRead; +char * szComment; +PHB_ITEM pItem; +} HB_ZIP_INTERNAL,* PHB_ZIP_INTERNAL,* HB_ZIP_INTERNAL_PTR; +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 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_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_DeleteOne(char *szFile,char *szFiletoDelete); +extern int hb_DeleteSel(char *szFile,PHB_ITEM pArray,BOOL bCase); +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); +#ifdef __cplusplus +} +#endif +#endif /* HB_APIEXT_H_ */ diff --git a/harbour/contrib/hbzlib/makefile2.bc b/harbour/contrib/hbzlib/makefile2.bc new file mode 100644 index 0000000000..9af9cc13d3 --- /dev/null +++ b/harbour/contrib/hbzlib/makefile2.bc @@ -0,0 +1,126 @@ +# +# $Id$ +# + +# +# Makefile for Zlib library for Borland C/C++ 3.x, 4.x, 5.x compilers +# +.autodepend + +CC = bcc32 +IL = implib +ID = impdef +# NOTE: Using TASM for some reason, this should be normally TASM32. +# I'll leave it to TASM until a better solution is found +AS = tasm + +BIN_DIR = ..\..\..\bin +OBJ_DIR = ..\..\..\obj\b32 +LIB_DIR = ..\..\..\lib\b32 + +COMMON_LIB = $(LIB_DIR)\common.lib +DBFCDX_LIB = $(LIB_DIR)\dbfcdx.lib +DBFNTX_LIB = $(LIB_DIR)\dbfntx.lib +DEBUG_LIB = $(LIB_DIR)\debug.lib +LANG_LIB = $(LIB_DIR)\lang.lib +MACRO_LIB = $(LIB_DIR)\macro.lib +NULSYS_LIB = $(LIB_DIR)\nulsys.lib +PP_LIB = $(LIB_DIR)\pp.lib +RDD_LIB = $(LIB_DIR)\rdd.lib +RTL_LIB = $(LIB_DIR)\rtl.lib +VM_LIB = $(LIB_DIR)\vm.lib +GTWIN_LIB = $(LIB_DIR)\gtwin.lib +SAMPLES_LIB = $(LIB_DIR)\samples.lib +HB_GT_LIB = $(GTWIN_LIB) +# This is needed, otherwise the libs may overflow when +# debug info is requested with -v -y +ARFLAGS = /P32 + + +#!if !$d(BCC_NOOPTIM) +#CFLAGS = -O2- $(CFLAGS) +#!endif + +# +# Directory macros. These should never have to change. +# + +INCLUDE_DIR = ..\..\..\include;.;\temp\ziparchive +ZLIB_DIR = . +WINSYS_DIR = \WINDOWS\SYSTEM +CFLAGS = -I$(INCLUDE_DIR) -d $(C_USR) $(CFLAGS) -DWIN32 +CLIBFLAGS = $(CFLAGS) +HARBOUR_EXE = $(BIN_DIR)\harbour.exe +HARBOURFLAGS = -i$(INCLUDE_DIR) -n -q0 -w -es2 -gc0 $(PRG_USR) $(HARBOURFLAGS) +LDFLAGS = $(LDFLAGS) + +# +# Macros to access our library names +# + +ZLIB_LIB = $(LIB_DIR)\zlib1.lib +ZLIB_EXE = $(ZLIB_DIR)\x\test.exe + + +ZLIB_BOR_LIB = $(LIB_DIR)\ziparchive.lib +ZLIB_LIB_OBJS = \ + $(OBJ_DIR)\zipnew.obj \ + $(OBJ_DIR)\zipcomp.obj \ + $(OBJ_DIR)\zipfile.obj + +ZLIB_EXE_OBJS = \ + $(OBJ_DIR)\test.obj + +all: \ + $(ZLIB_LIB) \ + $(ZLIB_EXE_OBJS) \ + $(ZLIB_EXE) + + +$(ZLIB_LIB) = $(ZLIB_LIB_OBJS) + +$(ZLIB_EXE) = $(ZLIB_EXE_OBJS) + +$(ZLIB_LIB) : $(ZLIB_LIB_OBJS) + + +$(OBJ_DIR)\zipnew.obj : $(ZLIB_DIR)\zipnew.cpp + $(CC) -u -c $(CLIBFLAGS) -P -o$@ $** + tlib $(ZLIB_LIB) $(ARFLAGS) -+$@,, + +$(OBJ_DIR)\zipfile.obj : $(ZLIB_DIR)\zipfile.c + $(CC) -c $(CLIBFLAGS) -o$@ $** + tlib $(ZLIB_LIB) $(ARFLAGS) -+$@,, + +$(OBJ_DIR)\zipcomp.obj : $(ZLIB_DIR)\zipcomp.cpp + $(CC) -P -u -c $(CLIBFLAGS) -o$@ $** + tlib $(ZLIB_LIB) $(ARFLAGS) -+$@,, + + +$(ZLIB_EXE) : $(ZLIB_EXE_OBJS) + + echo. $(CFLAGS) > make.tmp + echo. -M -e$(ZLIB_EXE) >> make.tmp + echo. -I$(INCLUDE_DIR) >> make.tmp + echo. $(OBJ_DIR)\test.obj >> make.tmp + echo. $(ZLIB_LIB) >> make.tmp + echo. $(ZLIB_BOR_LIB) >> make.tmp + echo. $(PP_LIB) >> make.tmp + echo. $(COMMON_LIB) >> make.tmp + echo. $(VM_LIB) >> make.tmp + echo. $(RTL_LIB) >> make.tmp + echo. $(HB_GT_LIB) >> make.tmp + echo. $(LANG_LIB) >> make.tmp + echo. $(RDD_LIB) >> make.tmp + echo. $(MACRO_LIB) >> make.tmp + echo. $(DBFNTX_LIB) >> make.tmp + echo. $(DBFCDX_LIB) >> make.tmp + echo. $(SAMPLES_LIB) >> make.tmp + $(CC) @make.tmp + del make.tmp + +$(OBJ_DIR)\test.c : $(ZLIB_DIR)\test.prg + $(HARBOUR_EXE) $(HARBOURFLAGS) $** -o$@ + +$(OBJ_DIR)\test.obj : $(OBJ_DIR)\test.c + $(CC) -u -c $(CLIBFLAGS) -o$@ $** diff --git a/harbour/contrib/hbzlib/zip.c b/harbour/contrib/hbzlib/zip.c new file mode 100644 index 0000000000..3265c269f3 --- /dev/null +++ b/harbour/contrib/hbzlib/zip.c @@ -0,0 +1,192 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Harbour zip file compress function, + * + * Copyright 2000-2001 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, or (at your option) + * any later version. + * + * 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 software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries 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 Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include + +extern PHB_ITEM pArray; + +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)); + } + + + + 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_FUNC(HB_GETFILESINZIP) +{ + if( ISCHAR(1) ){ + char szFile[_POSIX_PATH_MAX]; + strcpy(szFile,hb_parc(1)); + hb___GetFilesNamesFromZip(hb___CheckFile(szFile),ISLOG(2) ? hb_parl(2) : 0); + hb_itemReturn(pArray); + hb_itemRelease(pArray); +} +} +/* +HB_FUNC(HB_ZIPGETPASSWORD) +{ +char *szName=hb_parc(1); +char *szPassWord; + szPassWord=hb_getPassWord(szName); +hb_retc(szPassWord); +} +*/ +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_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)); + } + + 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_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)); + } + + 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_FUNC(HB_UNZIPFILE) + +{ + if( ISCHAR(1) && ISCHAR(6) ){ + 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))); + } + 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))); + } + + else{ + 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_FUNC(HB_SETDISKZIP) +{ +hb_retl(hb___SetCallbackFunc(hb_itemParam(1))); +} +HB_FUNC(HB_ZIPDELETEFILES) +{ + if (ISCHAR(1)&& ISCHAR(2)){ + char szFile[_POSIX_PATH_MAX]; + strcpy(szFile,hb_parc(1)); + hb_retl(hb_DeleteOne(hb___CheckFile(szFile),hb_parc(2))); + } + if (ISCHAR(1)&&ISARRAY(2)) { + char szFile[_POSIX_PATH_MAX]; + strcpy(szFile,hb_parc(1)); + hb_retl(hb_DeleteSel(hb___CheckFile(szFile),hb_param(2,HB_IT_ARRAY),ISLOG(3) ? hb_parl(3) : 0)); +} +} +HB_FUNC(HB_ZIPTESTPK) +{ + char szFile[_POSIX_PATH_MAX]; + strcpy(szFile,hb_parc(1)); + hb_retni(hb_TestForPKS(hb___CheckFile(szFile))); + +} +HB_FUNC(HB_SETBUFFER) + { + hb_SetZipBuff(ISNUM(1) ? hb_parni(1) : 65535,ISNUM(2) ? hb_parni(2) : 16384,ISNUM(3) ? hb_parni(3) : 32768); +} +HB_FUNC(HB_SETZIPCOMMENT) + { + hb_SetZipComment(hb_parc(1)); +} +HB_FUNC(HB_GETZIPCOMMENT) + { + hb_retc(hb_GetZipComment(hb_parc(1))); +} diff --git a/harbour/contrib/hbzlib/zipcomp.cpp b/harbour/contrib/hbzlib/zipcomp.cpp new file mode 100644 index 0000000000..923f0371d8 --- /dev/null +++ b/harbour/contrib/hbzlib/zipcomp.cpp @@ -0,0 +1,376 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Zlib low level interface for Harbour + * + * Copyright 2000-2001 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, or (at your option) + * any later version. + * + * 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 software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries 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 Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbzip2.h" + +extern PHB_ITEM pArray; +PHB_ITEM pDiskStatus=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) +{ + uLong uiCount; + char szNewFile[MAXFILENAME]; + int iCause=0; + BOOL bFileExist=hb_fsFile(szFile); + CZipArchive szZip; + if (szPassWord != NULL){ + szZip.SetPassword(szPassWord); + } + if (pZipI.szComment != NULL) + szZip.SetGlobalComment(pZipI.szComment); + try { + if (bFileExist && bOverWrite){ + szZip.Open(szFile,CZipArchive::zipCreate,0); + } + else{ + if (!bFileExist) { + szZip.Open(szFile,CZipArchive::zipCreate,0); + } + else { + szZip.Open(szFile,CZipArchive::zipOpen,0); + } + } + + } + catch (CZipException* e) + { + iCause=e->m_iCause ; + + } + catch(...){} + for (uiCount=1;(uiCount<= hb_arrayLen(pArray)) ;uiCount++) + { + const char *szDummy = (char *)hb_arrayGetCPtr(pArray,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); + } + catch(...){} + 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); + } + + } + try { + szZip.Close(); + } + catch (CZipException* e) + { + iCause=e->m_iCause ; + + } + catch(...){} + + return iCause; /* 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) +{ + uLong uiCount; + char szNewFile[MAXFILENAME]; + CZipArchive szZip; + int iCause=0; + + BOOL bFileExist=hb_fsFile(szFile); + if (pDiskBlock !=NULL){ + pDiskStatus=pDiskBlock; + } + if (szPassWord != NULL){ + szZip.SetPassword(szPassWord); + } + if (pZipI.szComment != NULL) + szZip.SetGlobalComment(pZipI.szComment); + + if (iSpanSize ==NULL) { + iSpanSize=1457664; + } + /* + try { + szZip.Open(szFile,CZipArchive::zipCreateSpan,iSpanSize); + } + */ + try { + if (bFileExist && bOverWrite){ + szZip.Open(szFile,CZipArchive::zipCreateSpan,iSpanSize); + } + else{ + if (!bFileExist) { + szZip.Open(szFile,CZipArchive::zipCreateSpan,iSpanSize); + } + else { + iCause=0; + return iCause; + } + } +} + catch (CZipException* e) + { + iCause=e->m_iCause ; + + } + catch(...){} + + for (uiCount=1;(uiCount<= hb_arrayLen(pArray)) ;uiCount++) + { + const char *szDummy = (char *)hb_arrayGetCPtr(pArray,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); + + } + catch(...){} + 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); + } + + } + try { + szZip.Close(); + } + catch (CZipException* e) + { + iCause=e->m_iCause ; + + } + catch(...){} + pDiskStatus=NULL ; + return iCause; /* to avoid warning */ +} +/* +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); + hb_itemRelease(pDisk); + hb_itemRelease(pVolume); + return iReturn; + +} +*/ +int hb_CompressFileStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive) +{ + uLong uiCount; + char szNewFile[MAXFILENAME]; + int iCause=0; + BOOL bFileExist=hb_fsFile(szFile); + CZipArchive szZip; + if (szPassWord != NULL){ + szZip.SetPassword(szPassWord); + } + if (pZipI.szComment != NULL) + szZip.SetGlobalComment(pZipI.szComment); + + try { + if (bFileExist && bOverWrite){ + szZip.Open(szFile,CZipArchive::zipCreate,0); + } + else{ + if (!bFileExist) { + szZip.Open(szFile,CZipArchive::zipCreate,0); + } + else { + szZip.Open(szFile,CZipArchive::zipOpen,0); + } + } + + } + catch (CZipException* e) + { + iCause=e->m_iCause ; + + } + try { + if (szPassWord != NULL){ + szZip.SetPassword(szPassWord); + } + if (bDrive) + szZip.AddNewFileDrv((const char*)szFiletoCompress, iCompLevel, true,NULL,NULL,65536); + 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); + + } + catch(...){} + if(pBlock !=NULL){ + PHB_ITEM pFileName=hb_itemPutC(NULL,szFiletoCompress ); + hb_vmEvalBlockV( pBlock, 1, pFileName ); + hb_itemRelease(pFileName); + + } + + + try { + szZip.Close(); + } + catch (CZipException* e) + { + iCause=e->m_iCause ; + + } + catch(...){} + + return iCause; /* 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) +{ + uLong uiCount; + char szNewFile[MAXFILENAME]; + CZipArchive szZip; + int iCause=0; + BOOL bTdSpan=FALSE; + BOOL bFileExist=hb_fsFile(szFile); + if (pDiskBlock !=NULL){ + pDiskStatus=pDiskBlock; + } + if (szPassWord != NULL){ + szZip.SetPassword(szPassWord); + } + if (pZipI.szComment != NULL) + szZip.SetGlobalComment(pZipI.szComment); + + if (iSpanSize ==NULL) { + iSpanSize=1457664; + } + try { + if (bFileExist && bOverWrite){ + szZip.Open(szFile,CZipArchive::zipCreateSpan,iSpanSize); + } + else{ + if (!bFileExist) { + szZip.Open(szFile,CZipArchive::zipCreateSpan,iSpanSize); + } + else { + iCause=0; + return iCause; + } + } + } + catch (CZipException& e) + { + iCause=e.m_iCause ; + } + catch(...){} + try { + if (szPassWord != NULL){ + szZip.SetPassword(szPassWord); + } + if (bDrive) + szZip.AddNewFileDrv((const char*) szFiletoCompress, iCompLevel, true,NULL,NULL,65536); + 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); + + } + catch(...){} + if(pBlock !=NULL){ + PHB_ITEM pFileName=hb_itemPutC(NULL,szFiletoCompress ); + hb_vmEvalBlockV( pBlock, 1, pFileName ); + hb_itemRelease(pFileName); + } + try { + szZip.Close(); + } + catch (CZipException& e) + { + iCause=e.m_iCause ; + } + catch(...){} + pDiskStatus=NULL ; + return iCause; /* to avoid warning */ +} + +#ifdef __cplusplus +} +#endif + diff --git a/harbour/contrib/hbzlib/zipnew.cpp b/harbour/contrib/hbzlib/zipnew.cpp new file mode 100644 index 0000000000..59deacac1a --- /dev/null +++ b/harbour/contrib/hbzlib/zipnew.cpp @@ -0,0 +1,889 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Zlib low level interface for Harbour + * + * Copyright 2000-2001 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, or (at your option) + * any later version. + * + * 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 software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries 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 Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbzip2.h" +char szTempTime[80]; +PHB_ITEM pArray=NULL; +static PHB_ITEM pChangeDiskBlock; +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); +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) +{ + uLong uiCount; + char szNewFile[MAXFILENAME]; + CZipArchive szZip; + int iCause=0; + BOOL bFileExist=hb_fsFile(szFile); + szZip.SetSpanCallback(hb_SetCallBack,(void*) &pChangeDiskBlock); + if (szPassWord != NULL){ + szZip.SetPassword(szPassWord); + } + try { + if (bFileExist && bOverWrite){ + szZip.Open(szFile,CZipArchive::zipCreateSpan,0); + } + else{ + if (!bFileExist) { + szZip.Open(szFile,CZipArchive::zipCreateSpan,0); + } + else { + iCause=0; + return iCause; + } + } + + } + + catch (CZipException* e) + { + iCause=e->m_iCause ; + + } + catch(...){} + for (uiCount=1;(uiCount<= hb_arrayLen(pArray)) ;uiCount++) + { + const char *szDummy = (char *)hb_arrayGetCPtr(pArray,uiCount) ; + try { + if (szPassWord != NULL){ + szZip.SetPassword(szPassWord); + } + if (bDrive) + szZip.AddNewFileDrv(szDummy, iCompLevel, true,hb_SetProgress,NULL,65536); + if (bPath) + szZip.AddNewFile(szDummy, iCompLevel, true,hb_SetProgress,NULL,65536); + if (!bDrive && !bPath) + szZip.AddNewFile(szDummy, iCompLevel, false,hb_SetProgress,NULL,65536); + + } + + catch(...){} + 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); + } + + } + try { + szZip.Close(); + } + catch (CZipException* e) + { + iCause=e->m_iCause ; + + } + catch(...){} + if (pChangeDiskBlock){ + hb_itemRelease(pChangeDiskBlock); + } + + return iCause; /* to avoid warning */ +} + + +PHB_ITEM hb___GetFilesNamesFromZip(char *szFile,BOOL iMode) +{ + char szFileNameinZip[_POSIX_PATH_MAX]; + int iNumbersOfFiles; + int iReturn=true; + CZipArchive szZip; + int uiCount; + + PHB_ITEM pItem=NULL; + +int iOMode=0; +iOMode=hb_CheckSpamMode(szFile); +if (pZipI.iWrite>0) { + szZip.SetAdvanced(pZipI.iWrite,pZipI.iExtract,pZipI.iRead); + +} + + try { + if(iOMode==0) { + szZip.Open(szFile,CZipArchive::zipOpen,0); + } + else { + if (iOMode ==-1) { + szZip.SetSpanCallback(hb_SetCallBack,(void*) &pChangeDiskBlock); + szZip.Open(szFile,CZipArchive::zipOpen,0); + } + else { + if (iOMode==-2) { + szZip.Open(szFile,CZipArchive::zipOpen,1); + } + else { + iReturn =false; + } + } + } + } + catch (...) { } + +if (iReturn) { + iNumbersOfFiles=szZip.GetNoEntries(); + pArray=hb_itemArrayNew( iNumbersOfFiles ); + time_t theTime; + tm *SzTime; + + for(uiCount=0;uiCount0) { + + pItem=hb_itemPutNL(NULL,fh.m_uUncomprSize); + hb_itemArrayPut(pTempArray,Lenght,pItem); + hb_itemRelease(pItem); + pItem=hb_itemPutNL(NULL,fh.m_uComprSize); + hb_itemArrayPut(pTempArray,Size,pItem); + hb_itemRelease(pItem); + iRatio=100-((fh.m_uComprSize*100)/fh.m_uUncomprSize); + if (iRatio <0){ + iRatio=0; + } + pItem=hb_itemPutNL(NULL,iRatio); + hb_itemArrayPut(pTempArray,Ratio,pItem); + hb_itemRelease(pItem); + } + else { + pItem=hb_itemPutNL(NULL,fh.m_uUncomprSize); + hb_itemArrayPut(pTempArray,Lenght,pItem); + hb_itemRelease(pItem); + pItem=hb_itemPutNL(NULL,fh.m_uComprSize); + hb_itemArrayPut(pTempArray,Size,pItem); + hb_itemRelease(pItem); + iRatio=0; + pItem=hb_itemPutNL(NULL,iRatio); + hb_itemArrayPut(pTempArray,Ratio,pItem); + hb_itemRelease(pItem); + } + + if (iMeth==0 || uAttr & FILE_ATTRIBUTE_DIRECTORY) { + szMethod="Stored"; + } + if (iMeth==Z_DEFLATED) { + uInt iLevel=(uInt)((fh.m_uFlag & 0x6)/2); + if (iLevel==0) { + szMethod="DeflatN"; + } + else if (iLevel==1) { + szMethod="DeflatX"; + } + else if ((iLevel==2) || (iLevel==3)) { + szMethod="DeflatF"; + } + else { + szMethod="Unknow"; + } + } + pItem=hb_itemPutC(NULL,szMethod); + hb_itemArrayPut(pTempArray,Method,pItem); + hb_itemRelease(pItem); + + sprintf(szCRC,"%8.8lx\n",(uLong)fh.m_uCrc32); + + pItem=hb_itemPutCL(NULL,szCRC,8); + hb_itemArrayPut(pTempArray,Crc32,pItem); + hb_itemRelease(pItem); + + pItem=hb_itemPutD(NULL,(long) (fh.m_uModDate >> 9) +1980 , (long) ((fh.m_uModDate & ~0xFE00) >> 5) ,(long)fh.m_uModDate & ~0xFFE0); + /* (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); + theTime=fh.GetTime(); + SzTime= localtime(&theTime); + hb_____GetTime(SzTime); + iLen=strlen(szTempTime); + + for(iCount=10;iCount<16;iCount++) { + if( (iCount>10) && (iCount<16)) { + szTime[iiCount]=szTempTime[iCount]; + iiCount++; + } + } + pItem=hb_itemPutCL(NULL,szTime,5); + hb_itemArrayPut(pTempArray,Time,pItem); + hb_itemRelease(pItem); + pItem=hb_itemPutCL(NULL,szAttr,5); + hb_itemArrayPut(pTempArray,Attr,pItem); + hb_itemRelease(pItem); + hb_itemArrayPut(pArray,uiCount+1,pTempArray); + hb_itemRelease(pTempArray); + + } + else { + const char * szFileNameInZip; + CZipString szTempString=(LPCTSTR)fh.GetFileName(); + szFileNameInZip=(const char *)szTempString; + pItem=hb_itemPutC(NULL,(char *) szFileNameInZip); + hb_itemArrayPut(pArray,uiCount+1,pItem); + hb_itemRelease(pItem); + } +} +} + szZip.Close(); + if (pChangeDiskBlock){ + hb_itemRelease(pChangeDiskBlock); + } + + hb_itemReturn( pArray); +} + + char *hb___CheckFile( char * szFile) + { + int uiCount,uiLen; + int uiDot_Found=0; + uiLen=strlen(szFile); + + for (uiCount=0;uiCounttm_sec; + t.tm_min = tz->tm_min; + t.tm_hour = tz->tm_hour; + t.tm_mday = tz->tm_mday; + t.tm_mon = tz->tm_mon; + t.tm_year = tz->tm_year; + t.tm_wday = 4; + t.tm_yday = 0; + t.tm_isdst = 0; + strcpy(szTempTime, asctime(&t)); + +} +char *hb_getPassWord(char *szName) +{ +const char * szTempPass; +CZipArchive szZip; +CZipString szPassWord; +int iNumbersOfFiles; + CZipFileHeader fh; + szZip.SetSpanCallback(hb_SetCallBack,NULL); +szZip.Open(szName,CZipArchive::zipOpen,0); +iNumbersOfFiles=szZip.GetNoEntries(); +szZip.GetFileInfo(fh, (WORD)1); +if (fh.IsEncrypted()){ + szPassWord= szZip.GetPassword(); + szTempPass=(const char *) szPassWord; + } +szZip.Close(); +return (char*)szTempPass; +} + + +int hb___GetNumbersofFilestoUnzip(char *szFile) +{ + int iNumbersOfFiles=0; + CZipArchive szZip; + + szZip.SetSpanCallback(hb_SetCallBack,NULL); + szZip.Open(szFile,CZipArchive::zipOpen,0); + iNumbersOfFiles=szZip.GetNoEntries(); + szZip.Close(); + if (pChangeDiskBlock){ + hb_itemRelease(pChangeDiskBlock); + } + + return iNumbersOfFiles; +} + +int hb_CmpPkSpanStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive) +{ + uLong uiCount; + char szNewFile[MAXFILENAME]; + CZipArchive szZip; + int iCause=0; + BOOL bFileExist=hb_fsFile(szFile); + szZip.SetSpanCallback(hb_SetCallBack,(void*) &pChangeDiskBlock); + if (szPassWord != NULL){ + szZip.SetPassword(szPassWord); + } + try { + if (bFileExist && bOverWrite){ + szZip.Open(szFile,CZipArchive::zipCreateSpan,0); + } + else{ + if (!bFileExist) { + szZip.Open(szFile,CZipArchive::zipCreateSpan,0); + } + else { + iCause=0; + return iCause; + } + } + + } + + catch (CZipException* e) + { + iCause=e->m_iCause ; + + } + catch(...){} + try { + if (szPassWord != NULL){ + szZip.SetPassword(szPassWord); + } + if (bDrive) + szZip.AddNewFileDrv(szFiletoCompress, iCompLevel, true,hb_SetProgress,NULL,65536); + if (bPath) + szZip.AddNewFile(szFiletoCompress, iCompLevel, true,hb_SetProgress,NULL,65536); + if (!bDrive && !bPath) + szZip.AddNewFile(szFiletoCompress, iCompLevel, false,hb_SetProgress,NULL,65536); + } + + catch(...){} + if(pBlock !=NULL){ + PHB_ITEM pFileName=hb_itemPutC(NULL,szFiletoCompress ); + hb_vmEvalBlockV( pBlock, 1, pFileName ); + hb_itemRelease(pFileName); + + } + + + try { + szZip.Close(); + } + catch (CZipException* e) + { + iCause=e->m_iCause ; + + } + catch(...){} + if (pChangeDiskBlock){ + hb_itemRelease(pChangeDiskBlock); + } + + return iCause; /* to avoid warning */ +} + + +int hb___SetCallbackFunc(PHB_ITEM pFunc) +{ +pChangeDiskBlock=pFunc; +pZipI.pItem=pFunc; + +return true; +} +bool hb_SetCallBack(DWORD iNumber, int , void* pData) +{ +/* PHB_ITEM p=(PHB_ITEM)*pData;*/ + PHB_ITEM pDisk=hb_itemPutNL(NULL,iNumber); + int iReturn=1; + hb_vmEvalBlockV( pChangeDiskBlock, 1,pDisk ); + hb_itemRelease(pDisk); +/* hb_itemRelease(p);*/ + return iReturn; + +} +bool hb_SetProgress(DWORD , int iSoFar, void* pData){ +/* CProgressInfo* p = static_cast(pData); + iSoFar += p->m_iTotalSoFar; + //iTotal = p->m_iTotal; + + p->m_pProgress->SetPos(iSoFar); + p->m_pProgress->RedrawWindow(); + return true; +*/ +return TRUE; +} +int hb_UnzipAll(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pDiskBlock){ +bool iReturn=true; +uLong uiCount=0; +int iCause=0; +int iMode=true; +CZipArchive szZip; +if (pDiskBlock){ + pChangeDiskBlock=pDiskBlock; +} + if (szPassWord != NULL){ + szZip.SetPassword(szPassWord); + } +iMode=hb_CheckSpamMode(szFile); + try { + if(iMode==0) { + szZip.Open(szFile,CZipArchive::zipOpen,0); + } + else { + if (iMode ==-1) { + szZip.SetSpanCallback(hb_SetCallBack,(void*) &pChangeDiskBlock); + szZip.Open(szFile,CZipArchive::zipOpen,0); + } + else { + if (iMode==-2) { + szZip.Open(szFile,CZipArchive::zipOpen,1); + } + else { + iReturn =false; + } + } + } + } + catch (CZipException& e) { + iCause=e.m_iCause ; + } + + if (iReturn) { + + for (uiCount=0;uiCount<=szZip.GetNoEntries();uiCount++){ + CZipFileHeader fh; + const char * szFileNameInZip; + CZipString szTempString; + + szZip.GetFileInfo(fh, (WORD)uiCount); + szTempString =(LPCTSTR)fh.GetFileName(); + szFileNameInZip=(const char *)szTempString; + + try { + szZip.SetPassword(szPassWord); + szZip.ExtractFile((WORD)uiCount,(LPCTSTR)szPath,bWithPath,NULL,NULL,NULL); + } + catch (CZipException& e) + { + iCause=e.m_iCause ; + } + if(pBlock !=NULL){ + + PHB_ITEM pFileName=hb_itemPutC(NULL,(char *)szFileNameInZip); + PHB_ITEM pFilePos=hb_itemPutNI(NULL,uiCount); + hb_vmEvalBlockV( pBlock, 2, pFileName, pFilePos ); + hb_itemRelease(pFileName); + hb_itemRelease(pFilePos); + } + + } + + } + if (pChangeDiskBlock){ + hb_itemRelease(pChangeDiskBlock); + } + +return iReturn; +} +int hb_UnzipOne(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,char *szFiletoExtract) +{ +bool iReturn=true; +int uiCount=0; +int iCause=0; +int iMode=0; + CZipArchive szZip; + szZip.SetSpanCallback(hb_SetCallBack,(void*) &pChangeDiskBlock); +iMode=hb_CheckSpamMode(szFile) ; + if (szPassWord != NULL){ + szZip.SetPassword(szPassWord); + } + /* + try { + if (hb_CheckSpamMode(szFile) !=-2) { + szZip.Open(szFile,CZipArchive::zipOpen,0); + } + else{ + szZip.Open(szFile,CZipArchive::zipOpen,1); + } + } +*/ + try { + if(iMode==0) { + szZip.Open(szFile,CZipArchive::zipOpen,0); + } + else { + if (iMode ==-1) { + szZip.SetSpanCallback(hb_SetCallBack,(void*) &pChangeDiskBlock); + szZip.Open(szFile,CZipArchive::zipOpen,0); + } + else { + if (iMode==-2) { + szZip.Open(szFile,CZipArchive::zipOpen,1); + } + else { + iReturn =false; + } + } + } + } + + catch (CZipException& e) { + iCause=e.m_iCause ; + } +/* if (iCause != 0){ + szZip.Close(); + }*/ + uiCount = szZip.FindFile((LPCTSTR)szFiletoExtract,false); + if (uiCount ==-1){ + uiCount = szZip.FindFile((LPCTSTR)szFiletoExtract,true); + } + if (uiCount >0){ + CZipFileHeader fh; + const char * szFileNameInZip; + CZipString szTempString; + szZip.GetFileInfo(fh, (WORD)uiCount); + szTempString =(LPCTSTR)fh.GetFileName(); + szFileNameInZip=(const char *)szTempString; + + try { + szZip.SetPassword(szPassWord); + szZip.ExtractFile((WORD)uiCount,(LPCTSTR)szPath,bWithPath,NULL,NULL,NULL); + } + catch (CZipException* e) + { + iCause=e->m_iCause ; + } + if(pBlock !=NULL){ + + PHB_ITEM pFileName=hb_itemPutC(NULL,(char *)szFileNameInZip); + hb_vmEvalBlockV( pBlock, 1, pFileName ); + hb_itemRelease(pFileName); + } + + + } + szZip.Close(); + if (pChangeDiskBlock){ + hb_itemRelease(pChangeDiskBlock); + } + +return iReturn; +} + +int hb_DeleteOne(char *szFile,char *szFiletoDelete) +{ +bool iReturn; +int uiCount=0; +int iCause=0; + CZipArchive szZip; +int iMode=0; +iMode=hb_CheckSpamMode(szFile); + try { + if(iMode==0) { + szZip.Open(szFile,CZipArchive::zipOpen,0); + } + else { + if (iMode ==-1 ||iMode == -2) { + iReturn =false; + } + } + } + + catch (CZipException e) { + iCause=e.m_iCause ; + } + uiCount = szZip.FindFile((LPCTSTR)szFiletoDelete,false); + if (uiCount ==-1){ + uiCount = szZip.FindFile((LPCTSTR)szFiletoDelete,true); + } + if (uiCount >0){ + CZipFileHeader fh; + szZip.GetFileInfo(fh, (WORD)uiCount); + if (szZip.DeleteFile((WORD)uiCount)) + iReturn = true; + else + iReturn = false; + } + szZip.Close(); + if (pChangeDiskBlock){ + hb_itemRelease(pChangeDiskBlock); + } + +return iReturn; +} + +int hb_DeleteSel(char *szFile,PHB_ITEM pArray,BOOL bCase) +{ + bool iReturn=true; + int uiCount=0; + int iCause=0; + CZipArchive szZip; + CZipStringArray aFiles; +int iMode=0; +iMode=hb_CheckSpamMode(szFile); + try { + if(iMode==0) { + szZip.Open(szFile,CZipArchive::zipOpen,0); + } + else { + if (iMode ==-1 ||iMode == -2) { + iReturn =false; + } + } + } + + catch (CZipException e) { + iCause=e.m_iCause ; + } + if (iReturn){ + for (uiCount=1;(uiCount<= hb_arrayLen(pArray)) ;uiCount++) { + const char *szDummy = (char *)hb_arrayGetCPtr(pArray,uiCount) ; + aFiles.Add(szDummy); + } + if (bCase) + szZip.DeleteFiles(aFiles,true); + else + szZip.DeleteFiles(aFiles,false); +} + szZip.Close(); + if (pChangeDiskBlock){ + hb_itemRelease(pChangeDiskBlock); + } + + return iReturn; +} + + +hb_UnzipSel(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pSelArray) +{ +bool iReturn=true; +int uiCount=0; +int iCause=0; +CZipArchive szZip; +int iMode=0; +iMode=hb_CheckSpamMode(szFile); + if (szPassWord != NULL){ + szZip.SetPassword(szPassWord); + } + try { + if(iMode==0) { + szZip.Open(szFile,CZipArchive::zipOpen,0); + } + else { + if (iMode ==-1) { + szZip.SetSpanCallback(hb_SetCallBack,(void*) &pChangeDiskBlock); + szZip.Open(szFile,CZipArchive::zipOpen,0); + } + else { + if (iMode==-2) { + szZip.Open(szFile,CZipArchive::zipOpen,1); + } + else { + iReturn =false; + } + } + } + } + catch (CZipException* e) { + iCause=e->m_iCause ; + } + if (iReturn) { + for (iCause=0;(iCause<= hb_arrayLen(pSelArray)) ;iCause++){ + uiCount = szZip.FindFile((LPCTSTR)hb_arrayGetCPtr(pSelArray,iCause),false); + if (uiCount ==-1){ + uiCount = szZip.FindFile((LPCTSTR)hb_arrayGetCPtr(pSelArray,iCause),true); + } + if (uiCount >0){ + CZipFileHeader fh; + const char * szFileNameInZip; + CZipString szTempString; + szZip.GetFileInfo(fh, (WORD)uiCount); + szTempString =(LPCTSTR)fh.GetFileName(); + szFileNameInZip=(const char *)szTempString; + + try { + szZip.SetPassword(szPassWord); + szZip.ExtractFile((WORD)uiCount,(LPCTSTR)szPath,bWithPath,NULL,NULL,NULL); + } + catch (CZipException* e) + { + iCause=e->m_iCause ; + } + if(pBlock !=NULL){ + + PHB_ITEM pFileName=hb_itemPutC(NULL,(char *)szFileNameInZip); + hb_vmEvalBlockV( pBlock, 1, pFileName ); + hb_itemRelease(pFileName); + } + + } +} + } + if (pChangeDiskBlock){ + hb_itemRelease(pChangeDiskBlock); + } + szZip.Close(); +return iReturn; +} + +int hb_TestForPKS(char *szFile) +{ + return hb_CheckSpamMode(szFile); +} +void hb_SetZipBuff(int a,int b,int c) +{ +if (a && b && c){ + pZipI.iWrite = a>= 65535 ? a : 65535; + pZipI.iExtract = b>=16384 ? b : 16384; + pZipI.iRead= c >=32768 ? c : 32768; +} +} +void hb_SetZipComment(char *szComment) +{ +pZipI.szComment=szComment; +} +char * hb_GetZipComment(char *szFile) +{ +const char *szReturn; +bool iReturn=true; +CZipString szTemp; +int iCause=0; +CZipArchive szZip; +int iMode=0; +iMode=hb_CheckSpamMode(szFile); + try { + if(iMode==0) { + szZip.Open(szFile,CZipArchive::zipOpen,0); + } + else { + if (iMode ==-1) { + szZip.SetSpanCallback(hb_SetCallBack,(void*) &pChangeDiskBlock); + szZip.Open(szFile,CZipArchive::zipOpen,0); + } + else { + if (iMode==-2) { + szZip.Open(szFile,CZipArchive::zipOpen,1); + } + else { + iReturn =false; + } + } + } + } + catch (CZipException* e) { + iCause=e->m_iCause ; + } +if (iReturn) { + szTemp=szZip.GetGlobalComment(); + szReturn=(const char *) szTemp; +} + if (pChangeDiskBlock){ + hb_itemRelease(pChangeDiskBlock); + } + +szZip.Close(); +return (char*)szReturn; + +} + +#ifdef __cplusplus +} +#endif +int hb_CheckSpamMode(char * szFile) +{ +CZipArchive szZip; + +int iReturn = 0; +int iCause=0; +szZip.SetSpanCallback(hb_SetCallBack,(void*) &pChangeDiskBlock); +try{ iCause=0; szZip.Open(szFile,CZipArchive::zipOpen,0);} +catch(CZipException &e) { + if (e.m_iCause == CZipException::cdirNotFound) { + szZip.Close(true); + iReturn=114; + return iReturn; + } + if (e.m_iCause == CZipException::noCallback) { + szZip.Close(true); + iReturn=103; + return iReturn; + +} +} + iReturn =szZip.GetSpanMode(); + szZip.Close(); + + return iReturn; +} diff --git a/harbour/utils/hbmake/hbmake.prg b/harbour/utils/hbmake/hbmake.prg index 2410b81d8d..e19dc7f327 100644 --- a/harbour/utils/hbmake/hbmake.prg +++ b/harbour/utils/hbmake/hbmake.prg @@ -1005,6 +1005,10 @@ Local cDefBccLibs := "lang.lib vm.lib rtl.lib rdd.lib macro.lib pp.lib dbfntx.l Local cDefGccLibs := "-lvm -lrtl -lgtdos -llang -lrdd -lrtl -lvm -lmacro -lpp -ldbfntx -ldbfcdx -lcommon" Local cscreen := Savescreen( 0, 0, Maxrow(), Maxcol() ) local citem:="" +Local cExt:="" +Local cDrive:="" +local cPath:="" +Local cTest:="" nLinkHandle := Fcreate( cFile ) Fwrite( nLinkHandle, "#BCC" + CRLF ) Fwrite( nLinkHandle, "VERSION=BCB.01" + CRLF ) @@ -1119,7 +1123,7 @@ pickarry( 10, 15, 19, 64, aIn, aOut ) nLenaOut := Len( aOut ) For x := 1 To nLenaOut - aOut[ x ] := lower(Trim( Left( aOut[ x ], 12 ) )) + aOut[ x ] := Trim( Left( aOut[ x ], 12 ) ) Next aOut := Asort( aOut ) @@ -1145,10 +1149,12 @@ Next aObjs := aClone(aout) For x := 1 To Len( aObjs ) cItem:=aObjs[ x ] + hb_FNAMESPLIT(ciTem,@cPath ,@cTest, @cExt , @cDrive) + cExt:=substr(cExt,2) If !lGcc - aObjs[ x ]:=strtran( cItem, ".prg", ".obj" ) + aObjs[ x ]:=cTest+"."+strtran( cExt, "prg", "obj" ) Else - aObjs[ x ]:=strtran( cItem, ".prg", ".o" ) + aObjs[ x ]:=cTest+"."+strtran( cExt, "prg", "o" ) Endif Next @@ -1163,23 +1169,33 @@ Elseif lCw Endif if lGcc if at("linux",Getenv("HB_ARCHITECTURE"))>0 .or. cOs=="Linux" - Fwrite( nLinkHandle, "PROJECT = " + if(isupper(cTopfile),Strtran( cTopfile, ".PRG", "" ),Strtran( cTopfile, ".prg", "" )) + " $(PR) "+CRLF ) + + hb_FNAMESPLIT(cTopfile,@cPath ,@cTest, @cExt , @cDrive) + cExt:=substr(cExt,2) +/* Fwrite( nLinkHandle, "PROJECT = " + if(isupper(cTopfile),Strtran( cTopfile, ".PRG", "" ),Strtran( cTopfile, ".prg", "" )) + " $(PR) "+CRLF )*/ + Fwrite( nLinkHandle, "PROJECT = " + if(isupper(cExt),Strtran( cTopfile, "PRG", "" ),Strtran( cTopfile, "prg", "" )) + " $(PR) "+CRLF ) else - Fwrite( nLinkHandle, "PROJECT = " + if(isupper(cTopfile),Strtran( cTopfile, ".PRG", ".EXE" ),Strtran( cTopfile, ".prg", ".exe" )) +" $(PR) "+ CRLF ) + hb_FNAMESPLIT(cTopfile,@cPath ,@cTest, @cExt , @cDrive) + cExt:=substr(cExt,2) + Fwrite( nLinkHandle, "PROJECT = " + if(isupper(cExt),cTest+"."+Strtran( cExt, "PRG", "EXE" ),cTest+"."+Strtran( cExt, "prg", "exe" )) +" $(PR) "+ CRLF ) endif else - -Fwrite( nLinkHandle, "PROJECT = " + if(isupper(cTopfile),Strtran( cTopfile, ".PRG", ".EXE" ),Strtran( cTopfile, ".prg", ".exe" )) + " $(PR) "+CRLF ) + hb_FNAMESPLIT(cTopfile,@cPath ,@cTest, @cExt , @cDrive) + cExt:=substr(cExt,2) +Fwrite( nLinkHandle, "PROJECT = " + if(isupper(cExt),cTest+"."+Strtran( cExt, "PRG", "exe" ),cTest+"."+Strtran( cExt, "prg", "exe" )) +" $(PR) "+ CRLF ) +//Fwrite( nLinkHandle, "PROJECT = " + if(isupper(cTopfile),Strtran( cTopfile, ".PRG", ".EXE" ),Strtran( cTopfile, ".prg", ".exe" )) + " $(PR) "+CRLF ) endif - -Fwrite( nLinkHandle, "OBJFILES = " + if(isupper(cTopfile),Strtran( cTopfile, ".PRG", ".OBJ" ),Strtran( cTopfile, ".prg", ".obj" )) ) + hb_FNAMESPLIT(cTopfile,@cPath ,@cTest, @cExt , @cDrive) + cExt:=substr(cExt,2) +//Fwrite( nLinkHandle, "OBJFILES = " + if(isupper(cTopfile),Strtran( cTopfile, ".PRG", ".OBJ" ),Strtran( cTopfile, ".prg", ".obj" )) ) + Fwrite( nLinkHandle, "OBJFILES = " + if(isupper(cExt),cTest+"."+Strtran( cExt, "PRG", "OBJ" ),cTest+"."+Strtran( cExt, "prg", "obj" )) ) if len(aObjs)<1 Fwrite( nLinkHandle, +" $(OB) "+ CRLF ) else //Fwrite( nLinkHandle, "OBJFILES = " + if(isupper(cTopfile),Strtran( cTopfile, ".PRG", ".OBJ" ),Strtran( cTopfile, ".prg", ".obj" ))) - +//Fwrite( nLinkHandle, "OBJFILES = " + if(isupper(cExt),cTest+"."+Strtran( cExt, "PRG", "OBJ" ),cTest+"."+Strtran( cExt, "prg", "obj" )) ) For x := 1 To Len( aobjs ) If x <> Len( aobjs ) .and. aObjs[x]<>cTopfile Fwrite( nLinkHandle, " " + aobjs[ x ] ) @@ -1188,7 +1204,10 @@ For x := 1 To Len( aobjs ) Endif Next endif -Fwrite( nLinkHandle, "CFILES = " + if(isupper(cTopfile),Strtran( cTopfile, ".PRG", ".C" ),Strtran( cTopfile, ".prg", ".c" ))) + hb_FNAMESPLIT(cTopfile,@cPath ,@cTest, @cExt , @cDrive) + cExt:=substr(cExt,2) + Fwrite( nLinkHandle, "CFILES = " + if(isupper(cExt),cTest+"."+Strtran( cExt, "PRG", "c" ),cTest+"."+Strtran( cExt, "prg", "c" )) ) +//Fwrite( nLinkHandle, "CFILES = " + if(isupper(cTopfile),Strtran( cTopfile, ".PRG", "C" ),Strtran( cTopfile, ".prg", "c" ))) if len(aCs)<1 Fwrite( nLinkHandle, +" $(CF)"+ CRLF ) //