Code: Select all
/*
* $DOC$
* $FUNCNAME$
* HB_ZIPFILE()
* $CATEGORY$
* ZIP FUNCTION
* $ONELINER$
* Create a zip file
* $SYNTAX$
* HB_ZIPFILE( <cFile> , <cFileToCompress> | <aFiles>, <nLevel> ,
* <bBlock>,<lOverWrite> ,<cPassword>,<lWithPath>,<lWithDrive>) ---> lCompress
* $ARGUMENTS$
* <cFile> Name of the zip file
*
* <cFileToCompress> Name of a file to Compress, Drive and/or path
* can be used
*
* <aFiles> An array containing files to compress, Drive and/or path
* can be used
*
* <nLevel> Compression level ranging from 0 to 9
*
* <bBlock> Code block to execute while compressing
*
* <lOverWrite> Toggle to overwite the file if exists
*
* <cPassword> Password to encrypt the files
*
* <lWithPath> Toggle to store the path or not
*
* <lWithDrive> Toggle to store the Drive letter and path or not
* $RETURNS$
* <lCompress> .t. if file was create, otherwise .f.
* $DESCRIPTION$
* This function creates a zip file named <cFile>. 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 <aFiles>
* will be compressed.
*
* If <nLevel> is used, it detemines the compression type where 0 means
* no compression and 9 means best compression.
*
* If <bBlock> is used, every time the file is opened to compress it
* will evaluate bBlock. Parameters of bBlock are cFile and nPos.
*
* If <lOverWrite> is used , it toggles to overwrite or not the existing
* file. Default is to overwrite the file,otherwise if <lOverWrite> is false
* the new files are added to the <cFile>.
*
* If <cPassword> is used, all files that are added to the archive are encrypted
* with the password.
*
* If <lWithPath> is used, it tells thats the path should also be stored with
* the file name. Default is false.
*
* If <lWithDrive> 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( <cFile> , <bBlock> , <lWithPath>) ,<cPassWord>,<cPath>,
* [<cFile>|<aFile>] <---> lCompress
* $ARGUMENTS$
* <cFile> Name of the zip file
*
* <bBlock> Code block to execute while compressing
*
* <lWithPath> Toggle to create directory if needed
*
* <cPassWord> Password to use to extract files
*
* <cPath> Path to extract the files.
*
* <cFile>|<aFiles> An file or an Array of files to extract
* $RETURNS$
* <lCompress> .t. if all file was successfuly restored, otherwise .f.
* $DESCRIPTION$
* This function restores all files contained inside the <cFile>.
* If the extension is ommited, .ZIP will be assumed. If a file already
* exists, it wlll be overwriten.
*
* If <bBlock> is used, every time the file is opened to compress it
* will evaluate bBlock. Parameters of bBlock are cFile and nPos.
*
* The <cPath> 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( <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 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()( <cFile> , <cFileToCompress> | <aFiles>, <nLevel> ,
* <bBlock>,<lOverWrite> ,<cPassword>,<iSize>,<lWithPath>,<lWithDrive>) ---> lCompress
* $ARGUMENTS$
* <cFile> Name of the zip file
*
* <cFileToCompress> Name of a file to Compress, Drive and/or path
* can be used
*
* <aFiles> An array containing files to compress, Drive and/or path
* can be used
*
* <nLevel> Compression level ranging from 0 to 9
*
* <bBlock> Code block to execute while compressing
*
* <lOverWrite> Toggle to overwite the file if exists
*
* <cPassword> Password to encrypt the files
*
* <iSize> Size of the archive, in bytes,default is 1457664 bytes
*
* <lWithPath> Toggle to store the path or not
*
* <lWithDrive> Toggle to store the Drive letter and path or not
* $RETURNS$
* <lCompress> .t. if file was create, otherwise .f.
* $DESCRIPTION$
* This function creates a zip file named <cFile>. 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 <aFiles>
* will be compressed.
*
* If <nLevel> is used, it detemines the compression type where 0 means
* no compression and 9 means best compression.
*
* If <bBlock> is used, every time the file is opened to compress it
* will evaluate bBlock. Parameters of bBlock are cFile and nPos.
*
* If <lOverWrite> is used , it toggles to overwrite or not the existing
* file. Default is to overwrite the file,otherwise if <lOverWrite> is false
* the new files are added to the <cFile>.
*
* If <lWithPath> is used, it tells thats the path should also be stored with
* the file name. Default is false.
*
* If <lWithDrive> 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( <cFile> , <cFileToCompress> | <aFiles>, <nLevel> ,
* <bBlock>,<lOverWrite> ,<cPassword>,<lWithPath>,<lWithDrive>) ---> lCompress
* $ARGUMENTS$
* <cFile> Name of the zip file
*
* <cFileToCompress> Name of a file to Compress, Drive and/or path
* can be used
*
* <aFiles> An array containing files to compress, Drive and/or path
* can be used
*
* <nLevel> Compression level ranging from 0 to 9
*
* <bBlock> Code block to execute while compressing
*
* <lOverWrite> Toggle to overwite the file if exists
*
* <cPassword> Password to encrypt the files
*
* <lWithPath> Toggle to store the path or not
*
* <lWithDrive> Toggle to store the Drive letter and path or not
* $RETURNS$
* <lCompress> .t. if file was create, otherwise .f.
* $DESCRIPTION$
* This function creates a zip file named <cFile>. 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 <aFiles>
* will be compressed.Also , the use of this function is for creating
* backup in removable media like an floppy drive/zip drive.
*
* If <nLevel> is used, it detemines the compression type where 0 means
* no compression and 9 means best compression.
*
* If <bBlock> is used, every time the file is opened to compress it
* will evaluate bBlock. Parameters of bBlock are cFile and nPos.
*
* If <lOverWrite> is used , it toggles to overwrite or not the existing
* file. Default is to overwrite the file,otherwise if <lOverWrite> is false
* the new files are added to the <cFile>.
*
* If <cPassword> is used, all files that are added to the archive are encrypted
* with the password.
*
* If <lWithPath> is used, it tells thats the path should also be stored with
* the file name. Default is false.
*
* If <lWithDrive> 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(<bBlock>)
* $ARGUMENTS$
* <bBlock> 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(<cFile>,<cFiletoDelete>|<aFiles>) --> <lDeleted>
* $ARGUMENTS$
* <cFile> The name of the zip files from where the files will be deleted
*
* <cFiletoDelete> An File to be removed
*
* <aFiles> An Array of Files to Be Removed
* $RETURNS$
* <lDeleted> 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(<cFile>) --> <nReturnCode>
* $ARGUMENTS$
* <cFile> File to be tested.
* $RETURNS$
* <nReturn> 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
*
* <table>
* Error code Meaning
* 114 Incorrect Disk
* 103 No Call back was set with HB_SETDISKZIP()
* </table>
*
* 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(<szFile>) --> <szComment>
* $ARGUMENTS$
* <szFile> File to get the comment from
* $RETURNS$
* <szComment> The comment that was stored in <szFile>
* $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(<cComment>) -->Nil
* $ARGUMENTS$
* <cComment> Comment to add to the zip archive
* $RETURNS$
* <NIL> 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([<nWriteBuffer>],[<nExtractBuffer>],[<nReadBuffer>]) -->Nil
* $ARGUMENTS$
* <nWriteBuffer> The size of the write buffer.
*
* <nExtractBuffer> The size of the extract buffer.
*
* <nReadBuffer> The size of the read buffer.
* $RETURNS$
* <NIL> 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( <cFile>) ---> nNumber
* $ARGUMENTS$
* <cFile> Name of the rar file
* $RETURNS$
* <nNumber> 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$
*/
/* $DOC$
* $FUNCNAME$
* COMPRESSSTRING()
* $CATEGORY$
* Compression()
* $ONELINER$
* Compress an string
* $SYNTAX$
* CompressString(@<cString>,@<nSize>)
* $ARGUMENTS$
* <cString> Buffer to compress, must be passed by reference.
*
* <nSize> The Lenght of the compression String
* $RETURNS$
* NIL
* $DESCRIPTION$
* This function compress an string buffer and return the compression function
* and the size of this compression function.
* This size is required for uncompression the string
* $EXAMPLES$
* Local cTest:= memoread('tzipfile.prg')
* ? 'String before compressing',cTest
*
* COMPRESSSTRING(@cTest,@nSize)
* ? "Size",nSize
* ? " "
* ? " "
* ? 'String after compressing',cTest
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $SEEALSO$
* UNCOMPRESSSTRING()
* $END$
*/
/* $DOC$
* $FUNCNAME$
* UNCOMPRESSSTRING()
* $CATEGORY$
* Compression
* $ONELINER$
* Uncompress an String
* $SYNTAX$
* UNCOMPRESSSTRING(<cBuffer>,<nSize>) ---> <cUncompressBuffer>
* $ARGUMENTS$
* <cBuffer> The compressing string to uncompress
*
* <nSize> The saved size returned by compressionstring
* $RETURNS$
* <cUncompressBuffer> The String uncompressed
* $DESCRIPTION$
*
* $EXAMPLES$
* cOrig:=UNCOMPRESSSTRING(cTest,nSize)
* ?'uncompressed String',cOrig
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $SEEALSO$
* COMPRESSSTRING()
* $END$
*/