diff --git a/harbour/ChangeLog b/harbour/ChangeLog index af08865c98..8649f423ed 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,26 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-09-02 23:37 UTC+0200 Viktor Szakats (harbour.01 syenar hu) + * contrib/hbziparch/hbziparc.c + * contrib/hbziparch/hbzipnew.cpp + * Complete cleanup/refactor/fixes. + (original functions and internal logic was kept, + except some shady path/curdir manipulations, which + were removed, along with any directory changes) + The code got significantly easier to oversee, so if + someone wants to find out how this interface works, + now the code is much easier to read. If we want to + keep this in Harbour, maybe we could just swap the + low-level interface to utilize hbmzip calls instead + of ZipArchive ones. We would lose the segmented + archive feature though, but I'm not sure how + important this is these days, when there is no + floppy disk anymore. + Code size is now 40% smaller than in 1.0.0. + It's still far from being perfect, but now it's at + least possible to fix. + 2008-09-02 10:23 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * utils/hbmake/hbmake.prg ; Applied patch by Bill Robertson: diff --git a/harbour/contrib/hbziparch/hbziparc.c b/harbour/contrib/hbziparch/hbziparc.c index bfa84499b7..d306e531a3 100644 --- a/harbour/contrib/hbziparch/hbziparc.c +++ b/harbour/contrib/hbziparch/hbziparc.c @@ -4,7 +4,7 @@ /* * Harbour Project source code: - * Harbour zip file compress function, + * ZipArchive high level interface for Harbour * * Copyright 2000-2001 Luiz Rafael Culik * www - http://www.harbour-project.org @@ -50,8 +50,6 @@ * */ -#define HB_OS_WIN_32_USED - #include "hbapi.h" #include "hbapiitm.h" #include "hbapifs.h" @@ -62,17 +60,17 @@ HB_EXTERN_BEGIN extern void hb_fsDirectory( PHB_ITEM pDir, char * szSkleton, char * szAttributes, BOOL bDirOnly, BOOL bFullPath ); +extern PHB_ITEM hb_GetFileNamesFromZip( char * szFile, BOOL bVerbose ); +extern ULONG hb_GetNumberofFilestoUnzip( char * szFile ); extern BOOL hb_TransferFilesFromzip( char * szSource, char * szDest, PHB_ITEM pArray ); -extern PHB_ITEM hb_GetFileNamesFromZip( char * szFile, BOOL iMode ); -extern int hb_GetNumberofFilestoUnzip( char * szFile ); -extern int hb_SetCallbackFunc( PHB_ITEM pFunc ); -extern int hb_CmpPkSpan( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassWord, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ); -extern int hb_CmpTdSpan( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassWord, int iSpanSize, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ); -extern int hb_CompressFile( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassWord, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ); -extern int hb_UnzipAll( char * szFile, PHB_ITEM pBlock, BOOL bWithPath, char * szPassWord, char * pbyBuffer, PHB_ITEM pDiskBlock, PHB_ITEM pProgress ); -extern int hb_UnzipSel( char * szFile, PHB_ITEM pBlock, BOOL bWithPath, char * szPassWord, const char * szPath, PHB_ITEM pArray, PHB_ITEM pProgress ); -extern int hb_UnzipSelIndex( char * szFile, PHB_ITEM pBlock, BOOL bWithPath, char * szPassWord, char * szPath, PHB_ITEM pSelArray, PHB_ITEM pProgress ); -extern int hb_DeleteSel( char * szFile, PHB_ITEM pArray, BOOL bCase ); +extern BOOL hb_SetCallbackFunc( PHB_ITEM pFunc ); +extern BOOL hb_CmpPkSpan( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassWord, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ); +extern BOOL hb_CmpTdSpan( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassWord, long iSpanSize, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ); +extern BOOL hb_CompressFile( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassWord, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ); +extern BOOL hb_UnzipAll( char * szFile, PHB_ITEM pBlock, BOOL bWithPath, char * szPassWord, char * pbyBuffer, PHB_ITEM pDiskBlock, PHB_ITEM pProgress ); +extern BOOL hb_UnzipSel( char * szFile, PHB_ITEM pBlock, BOOL bWithPath, char * szPassWord, const char * szPath, PHB_ITEM pArray, PHB_ITEM pProgress ); +extern BOOL hb_UnzipSelIndex( char * szFile, PHB_ITEM pBlock, BOOL bWithPath, char * szPassWord, char * szPath, PHB_ITEM pSelArray, PHB_ITEM pProgress ); +extern BOOL hb_DeleteSel( char * szFile, PHB_ITEM pArray ); extern int hb_CheckSpanMode( char * szFile ); extern void hb_SetZipBuff( int a, int b, int c ); extern void hb_SetZipComment( char * szComment ); @@ -82,66 +80,48 @@ extern void hb_SetZipReadOnly( BOOL bRead ); HB_EXTERN_END -#if defined( HB_OS_LINUX ) - #include - #include -#endif - -#if defined( HB_OS_LINUX ) - -static int GetFileAttributes( char * szEntry ) +static void hb_ClearArchiveFlag( PHB_ITEM pProcFiles ) { - struct stat sStat; - stat( szEntry, &sStat ); - return ( int ) sStat.st_mode; -} + ULONG nPos, nLen = hb_arrayLen( pProcFiles ); -static void SetFileAttributes( char * szEntry, ULONG ulAttr) -{ - chmod( szEntry, ulAttr ); -} - -#endif - -static void ResetAttribs( PHB_ITEM pFileToZip, PHB_ITEM pFileAttribs ) -{ - ULONG ulAtt; - ULONG ulZipLen = hb_arrayLen( pFileToZip ); - - for( ulAtt = 0; ulAtt < ulZipLen; ulAtt++ ) + for( nPos = 0; nPos < nLen; nPos++ ) { - SetFileAttributes( hb_arrayGetCPtr( pFileToZip, ulAtt + 1 ), - hb_arrayGetNI( pFileAttribs, ulAtt + 1 ) ); + ULONG nAttr; + + hb_fsGetAttr( ( BYTE * ) hb_arrayGetCPtr( pProcFiles, nPos + 1 ), &nAttr ); + /* TOFIX: Doesn't work for some reason. + May be a problem or property of hb_fsSetAttr(). */ + nAttr &= ~HB_FA_ARCHIVE; + hb_fsSetAttr( ( BYTE * ) hb_arrayGetCPtr( pProcFiles, nPos + 1 ), nAttr ); } } -static void UnzipCreateArray( const char * szSkleton, PHB_ITEM pList, PHB_ITEM pZipArray ) +static void UnzipCreateArray( const char * szSkleton, PHB_ITEM pProcFiles, PHB_ITEM pZipFiles ) { - int ul, ulLen = hb_arrayLen( pZipArray ); + ULONG nPos, nLen = hb_arrayLen( pZipFiles ); - for( ul = 0; ul < ulLen; ul++ ) + for( nPos = 0; nPos < nLen; nPos++ ) { - PHB_ITEM pZipEntry = hb_arrayGetItemPtr( pZipArray, ul + 1 ); - const char * szEntry = hb_arrayGetCPtr( pZipEntry, 1 ); + const char * szEntry = hb_arrayGetCPtr( pZipFiles, nPos + 1 ); BOOL bOkAdd = TRUE; if( szSkleton ) bOkAdd = hb_strMatchFile( szEntry, ( const char * ) szSkleton ); - if( !bOkAdd ) + if( ! bOkAdd ) { PHB_FNAME pFileName = hb_fsFNameSplit( szEntry ); if( pFileName->szName ) { - char * szFile = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 1 ); + char * pszFile = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 1 ); pFileName->szPath = ( char * ) ""; - hb_fsFNameMerge( szFile, pFileName ); - bOkAdd = ( hb_stricmp( szSkleton, szFile ) == 0 ); - hb_xfree( szFile ); + hb_fsFNameMerge( pszFile, pFileName ); + bOkAdd = hb_strMatchFile( szSkleton, pszFile ); + hb_xfree( pszFile ); if( ! bOkAdd ) - bOkAdd = ( hb_stricmp( szSkleton, szEntry ) == 0 ); + bOkAdd = hb_strMatchFile( szSkleton, szEntry ); } hb_xfree( pFileName ); @@ -149,355 +129,297 @@ static void UnzipCreateArray( const char * szSkleton, PHB_ITEM pList, PHB_ITEM p if( bOkAdd ) { - PHB_ITEM Temp = hb_itemNew( NULL ); - hb_arrayAddForward( pList, hb_itemPutC( Temp, szEntry ) ); - hb_itemRelease( Temp ); + PHB_ITEM pTemp = hb_itemPutC( NULL, szEntry ); + hb_arrayAddForward( pProcFiles, pTemp ); + hb_itemRelease( pTemp ); } } } -static BOOL ZipTestExclude( char * szEntry, PHB_ITEM pExcludeFile ) +static BOOL ZipTestExclude( char * szEntry, PHB_ITEM pExcludeFiles ) { - int uiEx, uiExLen = hb_arrayLen( pExcludeFile ); + ULONG nPos, nLen = hb_arrayLen( pExcludeFiles ); - for( uiEx = 0; uiEx < uiExLen; uiEx++ ) + for( nPos = 0; nPos < nLen; nPos++ ) { - if( strcmp( hb_arrayGetCPtr( pExcludeFile, uiEx + 1 ), hb_strupr( szEntry ) ) == 0 ) + if( hb_strMatchFile( hb_arrayGetCPtr( pExcludeFiles, nPos + 1 ), szEntry ) ) return FALSE; } return TRUE; } -static PHB_ITEM ZipCreateExclude( PHB_ITEM pExclude ) +static PHB_ITEM ZipCreateExclude( PHB_ITEM pExcludeParam ) { - PHB_ITEM pExcludeFile = hb_itemArrayNew( 0 ); + PHB_ITEM pExcludeFiles = hb_itemArrayNew( 0 ); - if( pExclude ) + if( pExcludeParam ) { - if( HB_IS_STRING( pExclude ) ) + if( HB_IS_STRING( pExcludeParam ) ) { - if( strchr( hb_itemGetCPtr( pExclude ), '*' ) || - strchr( hb_itemGetCPtr( pExclude ), '?' ) ) + if( strchr( hb_itemGetCPtr( pExcludeParam ), '*' ) || + strchr( hb_itemGetCPtr( pExcludeParam ), '?' ) ) { - PHB_ITEM WildFile; - int ui, uiLen; + PHB_ITEM pDirFiles; + ULONG nPos, nLen; - WildFile = hb_itemNew( NULL ); + pDirFiles = hb_itemNew( NULL ); - hb_fsDirectory( WildFile, hb_itemGetCPtr( pExclude ), NULL, 0, TRUE ); - uiLen = hb_arrayLen( WildFile ); + hb_fsDirectory( pDirFiles, hb_itemGetCPtr( pExcludeParam ), NULL, 0, TRUE ); + nLen = hb_arrayLen( pDirFiles ); - for( ui = 0; ui < uiLen; ui++ ) + for( nPos = 0; nPos < nLen; nPos++ ) { - PHB_ITEM ExTmp = hb_itemPutC( NULL, hb_arrayGetCPtr( hb_arrayGetItemPtr( WildFile, ui + 1 ), F_NAME ) ); - hb_arrayAddForward( pExcludeFile, ExTmp ); - hb_itemRelease( ExTmp ); + PHB_ITEM pTemp = hb_itemPutC( NULL, hb_arrayGetCPtr( hb_arrayGetItemPtr( pDirFiles, nPos + 1 ), F_NAME ) ); + hb_arrayAddForward( pExcludeFiles, pTemp ); + hb_itemRelease( pTemp ); } - hb_itemRelease( WildFile ); + hb_itemRelease( pDirFiles ); } - else if( hb_itemGetCLen( pExclude ) > 0 ) + else if( hb_itemGetCLen( pExcludeParam ) ) { - PHB_ITEM ExTmp = hb_itemPutC( NULL, hb_itemGetCPtr( pExclude ) ); - hb_arrayAddForward( pExcludeFile, ExTmp ); - hb_itemRelease( ExTmp ); + PHB_ITEM pTemp = hb_itemPutC( NULL, hb_itemGetCPtr( pExcludeParam ) ); + hb_arrayAddForward( pExcludeFiles, pTemp ); + hb_itemRelease( pTemp ); } } - else if( HB_IS_ARRAY( pExclude ) ) + else if( HB_IS_ARRAY( pExcludeParam ) ) { - int ux, ufx = hb_arrayLen( pExclude ); + ULONG nPos, nLen = hb_arrayLen( pExcludeParam ); - for( ux = 0; ux < ufx; ux++ ) + for( nPos = 0; nPos < nLen; nPos++ ) { - char * szExclude = hb_arrayGetCPtr( pExclude, ux + 1 ); + char * szExclude = hb_arrayGetCPtr( pExcludeParam, nPos + 1 ); if( strchr( szExclude, '*' ) || strchr( szExclude, '?' ) ) { - PHB_ITEM WildFile = hb_itemNew( NULL ); - int uiW, uiWLen; + PHB_ITEM pDirFiles = hb_itemNew( NULL ); + ULONG nDirPos, nDirLen; - hb_fsDirectory( WildFile, szExclude, NULL, 0, TRUE ); - uiWLen = hb_arrayLen( WildFile ); + hb_fsDirectory( pDirFiles, szExclude, NULL, 0, TRUE ); + nDirLen = hb_arrayLen( pDirFiles ); - for( uiW = 0; uiW < uiWLen; uiW++ ) + for( nDirPos = 0; nDirPos < nDirLen; nDirPos++ ) { - PHB_ITEM ExTmp = hb_itemNew( NULL ); - hb_arrayAddForward( pExcludeFile, hb_itemPutC( ExTmp, hb_arrayGetCPtr( hb_arrayGetItemPtr( WildFile, uiW + 1 ), F_NAME ) ) ); - hb_itemRelease( ExTmp ); + PHB_ITEM pTemp = hb_itemPutC( NULL, hb_arrayGetCPtr( hb_arrayGetItemPtr( pDirFiles, nDirPos + 1 ), F_NAME ) ); + hb_arrayAddForward( pExcludeFiles, pTemp ); + hb_itemRelease( pTemp ); } - hb_itemRelease( WildFile ); + hb_itemRelease( pDirFiles ); } else { - PHB_ITEM ExTmp = hb_itemNew( NULL ); - hb_arrayAddForward( pExcludeFile, hb_itemPutC( ExTmp, szExclude ) ); - hb_itemRelease( ExTmp ); + PHB_ITEM pTemp = hb_itemPutC( NULL, szExclude ); + hb_arrayAddForward( pExcludeFiles, pTemp ); + hb_itemRelease( pTemp ); } } } } - return pExcludeFile; + return pExcludeFiles; } -static void ZipCreateArray( PHB_ITEM pParam, BOOL bFullPath, PHB_ITEM pFileToZip, PHB_ITEM pFileAttribs, PHB_ITEM pExclude ) +static PHB_ITEM ZipCreateArray( PHB_ITEM pParam, BOOL bFullPath, PHB_ITEM pExcludeParam ) { - BYTE * pCurDir = ( BYTE * ) hb_xstrcpy( NULL, HB_OS_PATH_DELIM_CHR_STRING, ( const char * ) hb_fsCurDir( 0 ), NULL ); + PHB_ITEM pProcFiles = hb_itemArrayNew( 0 ); - PHB_ITEM pExcludeFile = ZipCreateExclude( pExclude ); - PHB_ITEM Temp, TempArray; - PHB_ITEM WildFile = hb_itemNew( NULL ); - int ulArr, ulLenArr; - - if( HB_IS_STRING( pParam ) ) + if( pParam ) { - TempArray = hb_itemArrayNew( 0 ); - Temp = hb_itemPutC( NULL, hb_itemGetCPtr( pParam ) ); - hb_arrayAddForward( TempArray, Temp ); - hb_itemRelease( Temp ); - } - else - TempArray = hb_arrayClone( pParam ); + PHB_ITEM pExcludeFiles = ZipCreateExclude( pExcludeParam ); + PHB_ITEM pParamArray; + PHB_ITEM pDirFiles = hb_itemNew( NULL ); + + ULONG nArrayPos, nArrayLen; - ulLenArr = hb_arrayLen( TempArray ); - - for( ulArr = 0; ulArr < ulLenArr; ulArr++ ) - { - char * szArrEntry = hb_arrayGetC( TempArray, ulArr + 1 ); - - if( szArrEntry ) + if( HB_IS_STRING( pParam ) ) { + PHB_ITEM pTemp; + + pParamArray = hb_itemArrayNew( 0 ); + + pTemp = hb_itemPutC( NULL, hb_itemGetCPtr( pParam ) ); + hb_arrayAddForward( pParamArray, pTemp ); + hb_itemRelease( pTemp ); + } + else + pParamArray = hb_arrayClone( pParam ); + + nArrayLen = hb_arrayLen( pParamArray ); + + for( nArrayPos = 0; nArrayPos < nArrayLen; nArrayPos++ ) + { + char * szArrEntry = hb_arrayGetCPtr( pParamArray, nArrayPos + 1 ); + if( strchr( szArrEntry, '*' ) || strchr( szArrEntry, '?' ) ) { - int ul, ulLen; - - #if !defined( HB_OS_UNIX_COMPATIBLE ) - /* by JGS if don't gave path or there is a relative path add current dir ! */ - PHB_FNAME fDirSpec = hb_fsFNameSplit( ( char * ) szArrEntry ); - - if( ! fDirSpec->szDrive && - fDirSpec->szPath && - fDirSpec->szPath[ 0 ] != HB_OS_PATH_DELIM_CHR ) - #else - /* if don't gave path add current dir ! */ - if( ! strchr( szArrEntry, HB_OS_PATH_DELIM_CHR ) ) - #endif + ULONG nPos, nLen; + + hb_fsDirectory( pDirFiles, szArrEntry, NULL, 0, bFullPath ); + nLen = hb_arrayLen( pDirFiles ); + + for( nPos = 0; nPos < nLen; nPos++ ) { - char * szTemp = szArrEntry; - szArrEntry = hb_xstrcpy( NULL, ( char * ) pCurDir, HB_OS_PATH_DELIM_CHR_STRING, szTemp, NULL ); - hb_xfree( szTemp ); - } - - hb_fsDirectory( WildFile, szArrEntry, NULL, 0, bFullPath ); /* bFullPath by JGS */ - ulLen = hb_arrayLen( WildFile ); - - for( ul = 0; ul < ulLen; ul++ ) - { - char * szEntry = hb_arrayGetC( hb_arrayGetItemPtr( WildFile, ul + 1 ), F_NAME ); - - #if !defined( HB_OS_UNIX_COMPATIBLE ) /* by JGS */ - if( ! bFullPath && fDirSpec->szPath ) - { - char * szFile = szEntry; - szEntry = hb_xstrcpy( NULL, fDirSpec->szPath, szFile, NULL ); - hb_xfree( szFile ); - } - #endif - - if( ZipTestExclude( szEntry, pExcludeFile ) ) + char * pszEntry = hb_arrayGetCPtr( hb_arrayGetItemPtr( pDirFiles, nPos + 1 ), F_NAME ); + + if( ZipTestExclude( pszEntry, pExcludeFiles ) ) { - Temp = hb_itemNew( NULL ); - hb_arrayAddForward( pFileToZip, hb_itemPutC( Temp, szEntry ) ); - hb_itemRelease( Temp ); - Temp = hb_itemNew( NULL ); - hb_arrayAddForward( pFileAttribs, hb_itemPutNI( Temp, GetFileAttributes( szEntry ) ) ); - hb_itemRelease( Temp ); - - #if defined(HB_OS_LINUX) - SetFileAttributes( szEntry, 0777 ); - #else - SetFileAttributes( szEntry, HB_FA_ARCHIVE ); - #endif + PHB_ITEM pTemp = hb_itemPutC( NULL, pszEntry ); + hb_arrayAddForward( pProcFiles, pTemp ); + hb_itemRelease( pTemp ); } - - if( szEntry ) - hb_xfree( szEntry ); } - - #if !defined( HB_OS_UNIX_COMPATIBLE ) /* by JGS */ - hb_xfree( fDirSpec ); - #endif - - hb_itemClear( WildFile ); + + hb_itemClear( pDirFiles ); } else { - Temp = hb_itemPutC( NULL, szArrEntry ); - hb_arrayAddForward( pFileToZip, Temp ); - hb_itemRelease( Temp ); - Temp = hb_itemPutNI( NULL, GetFileAttributes( szArrEntry ) ); - hb_arrayAddForward( pFileAttribs, Temp ); - hb_itemRelease( Temp ); - - #if defined(HB_OS_LINUX) - SetFileAttributes( szArrEntry, 0777 ); - #else - SetFileAttributes( szArrEntry, HB_FA_ARCHIVE ); - #endif + PHB_ITEM pTemp = hb_itemPutC( NULL, szArrEntry ); + hb_arrayAddForward( pProcFiles, pTemp ); + hb_itemRelease( pTemp ); } - - hb_xfree( szArrEntry ); } + + hb_itemRelease( pParamArray ); + hb_itemRelease( pDirFiles ); + hb_itemRelease( pExcludeFiles ); } - hb_itemRelease( WildFile ); - hb_itemRelease( TempArray ); - - hb_itemRelease( pExcludeFile ); - - hb_xfree( pCurDir ); + return pProcFiles; } -static char * hb_CheckFile( const char * szFile ) +static char * hb_FNAddZipExt( const char * szFile ) { - PHB_FNAME pFileName = hb_fsFNameSplit( szFile ); - char * szZipName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 1 ); + PHB_FNAME pZipFileName = hb_fsFNameSplit( szFile ); + char * pszZipFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 1 ); - if( ! pFileName->szExtension ) - pFileName->szExtension = ".zip"; + if( ! pZipFileName->szExtension ) + pZipFileName->szExtension = ".zip"; - hb_fsFNameMerge( szZipName, pFileName ); - hb_xfree( pFileName ); + hb_fsFNameMerge( pszZipFileName, pZipFileName ); + hb_xfree( pZipFileName ); - return szZipName; + return pszZipFileName; } /* * $DOC$ * $FUNCNAME$ - * HB_ZIPFILE() + * HB_ZIPFILE() * $CATEGORY$ - * Zip Functions + * Zip Functions * $ONELINER$ - * Create a zip file + * Create a zip file * $SYNTAX$ - * HB_ZIPFILE( , | , , - * , , , , , - * ) ---> lCompress + * HB_ZIPFILE( , | , , + * , , , , , + * ) ---> lCompress * $ARGUMENTS$ - * Name of the zip file to create + * Name of the zip file to create * - * Name of a file to Compress, Drive and/or path - * can be used - * _or_ - * An array containing files to compress, Drive and/or path - * can be used + * Name of a file to Compress, Drive and/or path + * can be used + * _or_ + * An array containing files to compress, Drive and/or path + * can be used * - * Compression level ranging from 0 to 9 + * Compression level ranging from 0 to 9 * - * Code block to execute while compressing + * Code block to execute while compressing * - * Toggle to overwrite the file if exists + * Toggle to overwrite the file if exists * - * Password to encrypt the files + * Password to encrypt the files * - * Toggle to store the path or not + * Toggle to store the path or not * - * Toggle to store the Drive letter and path or not + * Toggle to store the Drive letter and path or not * - * Code block for File Progress + * Code block for File Progress * $RETURNS$ - * .T. if file was create, otherwise .F. + * .T. if file was create, otherwise .F. * $DESCRIPTION$ - * This function creates a zip file named . If the extension - * is omitted, .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. + * This function creates a zip file named . If the extension + * is omitted, .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 determines the compression type where 0 means - * no compression and 9 means best compression. + * If is used, it determines 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, 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 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, all files that are added to the archive are encrypted + * with the password. * - * If is used, it tells the path should also be stored with - * the file name. Default is false. + * If is used, it tells 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. + * If is used, it tells thats the Drive and path should also be stored + * with the file name. Default is false. * - * If is used, an Code block is evaluated, showing the total - * of that file has being processed. - * The codeblock must be defined as follow {|nPos,nTotal| GaugeUpdate(aGauge1,(nPos/nTotal))} + * If is used, an Code block is evaluated, showing the total + * of that file has being processed. + * The codeblock must be defined as follow {|nPos,nTotal| GaugeUpdate(aGauge1,(nPos/nTotal))} * * $EXAMPLES$ - * FUNCTION MAIN() + * FUNCTION MAIN() * - * IF HB_ZIPFILE( "test.zip", "test.prg" ) - * qout( "File was successfully created" ) - * ENDIF + * IF HB_ZIPFILE( "test.zip", "test.prg" ) + * qout( "File was successfully created" ) + * ENDIF * - * IF HB_ZIPFILE( "test1.zip", { "test.prg", "C:\windows\win.ini" } ) - * qout( "File was successfully created" ) - * ENDIF + * IF HB_ZIPFILE( "test1.zip", { "test.prg", "C:\windows\win.ini" } ) + * qout( "File was successfully created" ) + * ENDIF * - * IF HB_ZIPFILE( "test2.zip", { "test.prg", "C:\windows\win.ini" }, 9, {|cFile,nPos,| qout(cFile) } ) - * qout( "File was successfully created" ) - * ENDIF + * IF HB_ZIPFILE( "test2.zip", { "test.prg", "C:\windows\win.ini" }, 9, {|cFile,nPos,| qout(cFile) } ) + * qout( "File was successfully created" ) + * 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, 9, {|cFile,nPos| GaugeUpdate( aGauge, nPos/nLen ) },, "hello" ) - * Return NIL + * 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, 9, {|cFile,nPos| GaugeUpdate( aGauge, nPos/nLen ) },, "hello" ) + * Return NIL * $STATUS$ - * R + * R * $COMPLIANCE$ - * This function is a Harbour extension + * This function is a Harbour extension * $PLATFORMS$ - * All + * All * $FILES$ - * Library is hbziparch.lib + * Library is hbziparch.lib * $END$ */ HB_FUNC( HB_ZIPFILE ) { - BOOL bRet = FALSE; + BOOL bReturn = FALSE; if( ISCHAR( 1 ) ) { - PHB_ITEM pParam = hb_param( 2, HB_IT_STRING | HB_IT_ARRAY ); + PHB_ITEM pProcFiles = ZipCreateArray( hb_param( 2, HB_IT_STRING | HB_IT_ARRAY ), + ISLOG( 11 ) ? hb_parl( 11 ) : TRUE, + hb_param( 10, HB_IT_STRING | HB_IT_ARRAY ) ); - if( pParam ) + if( hb_arrayLen( pProcFiles ) ) { - char * szZipFileName = hb_CheckFile( hb_parc( 1 ) ); - PHB_ITEM pFileToZip = hb_itemArrayNew( 0 ); - PHB_ITEM pFileAttribs = hb_itemArrayNew( 0 ); + char * pszZipFileName = hb_FNAddZipExt( hb_parc( 1 ) ); - ZipCreateArray( pParam, - ISLOG( 11 ) ? hb_parl( 11 ) : TRUE, - pFileToZip, - pFileAttribs, - hb_param( 10, HB_IT_STRING | HB_IT_ARRAY ) ); - - if( hb_arrayLen( pFileToZip ) > 0 ) - { - bRet = hb_CompressFile( szZipFileName, - pFileToZip, + bReturn = hb_CompressFile( pszZipFileName, + pProcFiles, ISNUM( 3 ) ? hb_parni( 3 ) : -1, hb_param( 4, HB_IT_BLOCK ), hb_parl( 5 ), @@ -506,324 +428,271 @@ HB_FUNC( HB_ZIPFILE ) hb_parl( 8 ), hb_param( 9, HB_IT_BLOCK ) ); - if( bRet ) - ResetAttribs( pFileToZip, pFileAttribs ); - } + if( bReturn ) + hb_ClearArchiveFlag( pProcFiles ); - hb_itemRelease( pFileAttribs ); - hb_itemRelease( pFileToZip ); - hb_xfree( szZipFileName ); + hb_xfree( pszZipFileName ); } + + hb_itemRelease( pProcFiles ); } - hb_retl( bRet ); -} - -HB_FUNC( HB_GETFILESINZIP ) -{ - if( ISCHAR( 1 ) ) - { - char * szZipFileName = hb_CheckFile( hb_parc( 1 ) ); - - hb_itemReturnRelease( hb_GetFileNamesFromZip( szZipFileName, hb_parl( 2 ) ) ); - - hb_xfree( szZipFileName ); - } - else - hb_reta( 0 ); -} - -HB_FUNC( HB_ZIPWITHPASSWORD ) -{ - hb_retl( hb_IsPassWord( hb_parc( 1 ) ) ); -} - -HB_FUNC( HB_GETFILECOUNT ) -{ - int iRet = 0; - - if( ISCHAR( 1 ) ) - { - char * szZipFileName = hb_CheckFile( hb_parc( 1 ) ); - - iRet = hb_GetNumberofFilestoUnzip( szZipFileName ); - - hb_xfree( szZipFileName ); - } - - hb_retni( iRet ); + hb_retl( bReturn ); } /* * $DOC$ * $FUNCNAME$ - * HB_ZIPFILEBYTDSPAN() + * HB_ZIPFILEBYTDSPAN() * $CATEGORY$ - * Zip Functions + * Zip Functions * $ONELINER$ - * Create a zip file + * Create a zip file * $SYNTAX$ - * HB_ZIPFILEBYTDSPAN( , | , , - * , , , , , , - * ) ---> lCompress + * HB_ZIPFILEBYTDSPAN( , | , , + * , , , , , , + * ) ---> lCompress * $ARGUMENTS$ - * Name of the zip file + * Name of the zip file * - * Name of a file to Compress, Drive and/or path - * can be used - * _or_ - * An array containing files to compress, Drive and/or path - * can be used + * Name of a file to Compress, Drive and/or path + * can be used + * _or_ + * An array containing files to compress, Drive and/or path + * can be used * - * Compression level ranging from 0 to 9 + * Compression level ranging from 0 to 9 * - * Code block to execute while compressing + * Code block to execute while compressing * - * Toggle to overwrite the file if exists + * Toggle to overwrite the file if exists * - * Password to encrypt the files + * Password to encrypt the files * - * Size of the archive, in bytes. Default is 1457664 bytes + * Size of the archive, in bytes. Default is 1457664 bytes * - * Toggle to store the path or not + * Toggle to store the path or not * - * Toggle to store the Drive letter and path or not + * Toggle to store the Drive letter and path or not * - * Code block for File Progress + * Code block for File Progress * $RETURNS$ - * .T. if file was create, otherwise .F. + * .T. if file was create, otherwise .F. * $DESCRIPTION$ - * This function creates a zip file named . If the extension - * is omitted, .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. + * This function creates a zip file named . If the extension + * is omitted, .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 determines the compression type where 0 means - * no compression and 9 means best compression. + * If is used, it determines 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, 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 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 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. + * If is used, it tells thats the Drive and path should also + * be stored with the file name. Default is false. * - * If is used, an Code block is evaluated, showing the total - * of that file has being processed. - * The codeblock must be defined as follow {|nPos,nTotal| GaugeUpdate(aGauge1,(nPos/nTotal))} + * If is used, an Code block is evaluated, showing the total + * of that file has being processed. + * The codeblock must be defined as follow {|nPos,nTotal| GaugeUpdate(aGauge1,(nPos/nTotal))} * $EXAMPLES$ - * FUNCTION MAIN() + * FUNCTION MAIN() * - * IF HB_ZIPFILEBYTDSPAN( "test.zip", "test.prg" ) - * qout( "File was successfully created" ) - * ENDIF + * IF HB_ZIPFILEBYTDSPAN( "test.zip", "test.prg" ) + * qout( "File was successfully created" ) + * ENDIF * - * IF HB_ZIPFILEBYTDSPAN( "test1.zip", { "test.prg", "C:\windows\win.ini" } ) - * qout( "File was successfully created" ) - * ENDIF + * IF HB_ZIPFILEBYTDSPAN( "test1.zip", { "test.prg", "C:\windows\win.ini" } ) + * qout( "File was successfully created" ) + * ENDIF * - * IF HB_ZIPFILEBYTDSPAN( "test2.zip", { "test.prg", "C:\windows\win.ini" }, 9, {|nPos,cFile| qout(cFile) }, "hello",, 521421 ) - * qout("File was successfully created" ) - * ENDIF + * IF HB_ZIPFILEBYTDSPAN( "test2.zip", { "test.prg", "C:\windows\win.ini" }, 9, {|nPos,cFile| qout(cFile) }, "hello",, 521421 ) + * qout("File was successfully created" ) + * 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, 9, {|cFile,nPos| GaugeUpdate( aGauge, nPos/nLen) },, "hello",, 6585452 ) - * Return NIL + * 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, 9, {|cFile,nPos| GaugeUpdate( aGauge, nPos/nLen) },, "hello",, 6585452 ) + * Return NIL * $STATUS$ - * R + * R * $COMPLIANCE$ - * This function is a Harbour extension + * This function is a Harbour extension * $PLATFORMS$ - * All + * All * $FILES$ - * Library is hbziparch.lib + * Library is hbziparch.lib * $END$ */ HB_FUNC( HB_ZIPFILEBYTDSPAN ) { - BOOL bRet = FALSE; + BOOL bReturn = FALSE; if( ISCHAR( 1 ) ) { - PHB_ITEM pParam = hb_param( 2, HB_IT_STRING | HB_IT_ARRAY ); + PHB_ITEM pProcFiles = ZipCreateArray( hb_param( 2, HB_IT_STRING | HB_IT_ARRAY ), + ISLOG( 12 ) ? hb_parl( 12 ) : TRUE, + hb_param( 11, HB_IT_STRING | HB_IT_ARRAY ) ); - if( pParam ) + if( hb_arrayLen( pProcFiles ) ) { - char * szZipFileName = hb_CheckFile( hb_parc( 1 ) ); - PHB_ITEM pFileToZip = hb_itemArrayNew( 0 ); - PHB_ITEM pFileAttribs = hb_itemArrayNew( 0 ); + char * pszZipFileName = hb_FNAddZipExt( hb_parc( 1 ) ); - ZipCreateArray( pParam, - ISLOG( 12 ) ? hb_parl( 12 ) : TRUE, - pFileToZip, - pFileAttribs, - hb_param( 11, HB_IT_STRING | HB_IT_ARRAY ) ); - - if( hb_arrayLen( pFileToZip ) > 0 ) - { - bRet = hb_CmpTdSpan( szZipFileName, - pFileToZip, + bReturn = hb_CmpTdSpan( pszZipFileName, + pProcFiles, ISNUM( 3 ) ? hb_parni( 3 ) : -1, hb_param( 4, HB_IT_BLOCK ), hb_parl( 5 ), hb_parc( 6 ), - hb_parni( 7 ), + hb_parnl( 7 ), hb_parl( 8 ), hb_parl( 9 ), hb_param( 10, HB_IT_BLOCK ) ); - if( bRet ) - ResetAttribs( pFileToZip, pFileAttribs ); - } + if( bReturn ) + hb_ClearArchiveFlag( pProcFiles ); - hb_itemRelease( pFileAttribs ); - hb_itemRelease( pFileToZip ); - hb_xfree( szZipFileName ); + hb_xfree( pszZipFileName ); } + + hb_itemRelease( pProcFiles ); } - hb_retl( bRet ); + hb_retl( bReturn ); } /* * $DOC$ * $FUNCNAME$ - * HB_ZIPFILEBYPKSPAN() + * HB_ZIPFILEBYPKSPAN() * $CATEGORY$ - * Zip Functions + * Zip Functions * $ONELINER$ - * Create a zip file on removable media + * Create a zip file on removable media * $SYNTAX$ - * HB_ZIPFILEBYPKSPAN( , | , , - * , , , , , - * ) ---> lCompress + * HB_ZIPFILEBYPKSPAN( , | , , + * , , , , , + * ) ---> lCompress * $ARGUMENTS$ - * Name of the zip file + * Name of the zip file * - * Name of a file to Compress, Drive and/or path - * can be used - * _or_ - * An array containing files to compress, Drive and/or path - * can be used + * Name of a file to Compress, Drive and/or path + * can be used + * _or_ + * An array containing files to compress, Drive and/or path + * can be used * - * Compression level ranging from 0 to 9 + * Compression level ranging from 0 to 9 * - * Code block to execute while compressing + * Code block to execute while compressing * - * Toggle to overwrite the file if exists + * Toggle to overwrite the file if exists * - * Password to encrypt the files + * Password to encrypt the files * - * Toggle to store the path or not + * Toggle to store the path or not * - * Toggle to store the Drive letter and path or not + * Toggle to store the Drive letter and path or not * - * Code block for File Progress + * Code block for File Progress * $RETURNS$ - * .T. if file was create, otherwise .F. + * .T. if file was create, otherwise .F. * $DESCRIPTION$ - * This function creates a zip file named . If the extension - * is omitted, .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. + * This function creates a zip file named . If the extension + * is omitted, .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 determines the compression type where 0 means - * no compression and 9 means best compression. + * If is used, it determines 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, 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 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, 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 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. + * If is used, it tells thats the Drive and path should also be stored + * with the file name. Default is false. * - * If is used, an Code block is evaluated, showing the total - * of that file has being processed. - * The codeblock must be defined as follow {|nPos,nTotal| GaugeUpdate(aGauge1,(nPos/nTotal))} + * If is used, an Code block is evaluated, showing the total + * of that file has being processed. + * The codeblock must be defined as follow {|nPos,nTotal| GaugeUpdate(aGauge1,(nPos/nTotal))} * - * Before calling this function, Set an Changedisk codeblock by calling - * the HB_SETDISKZIP(). + * Before calling this function, Set an Changedisk codeblock by calling + * the HB_SETDISKZIP(). * $EXAMPLES$ - * FUNCTION MAIN() + * FUNCTION MAIN() * - * hb_setdiskzip( {|nDisk| Alert( "Please insert disk no " + Str( nDisk, 3 ) ) } ) + * hb_setdiskzip( {|nDisk| Alert( "Please insert disk no " + Str( nDisk, 3 ) ) } ) * - * IF HB_ZIPFILEBYPKSPAN( "A:\test.zip", "test.prg" ) - * qout( "File was successfully created" ) - * ENDIF + * IF HB_ZIPFILEBYPKSPAN( "A:\test.zip", "test.prg" ) + * qout( "File was successfully created" ) + * ENDIF * - * IF HB_ZIPFILEBYPKSPAN( "A:\test1.zip", { "test.prg", "C:\windows\win.ini" } ) - * qout( "File was successfully created" ) - * ENDIF + * IF HB_ZIPFILEBYPKSPAN( "A:\test1.zip", { "test.prg", "C:\windows\win.ini" } ) + * qout( "File was successfully created" ) + * ENDIF * - * IF HB_ZIPFILEBYPKSPAN( "test2.zip", { "test.prg", "C:\windows\win.ini"}, 9, {|nPos,cFile| qout(cFile) } ) - * qout( "File was successfully created" ) - * ENDIF + * IF HB_ZIPFILEBYPKSPAN( "test2.zip", { "test.prg", "C:\windows\win.ini"}, 9, {|nPos,cFile| qout(cFile) } ) + * qout( "File was successfully created" ) + * 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, 9, {|cFile,nPos| GaugeUpdate( aGauge, nPos/nLen ) },, "hello" ) - * // assuming F:\ is a Zip Drive - * Return NIL + * 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, 9, {|cFile,nPos| GaugeUpdate( aGauge, nPos/nLen ) },, "hello" ) + * // assuming F:\ is a Zip Drive + * Return NIL * $STATUS$ - * R + * R * $COMPLIANCE$ - * This function is a Harbour extension + * This function is a Harbour extension * $PLATFORMS$ - * All + * All * $FILES$ - * Library is hbziparch.lib + * Library is hbziparch.lib * $END$ */ HB_FUNC( HB_ZIPFILEBYPKSPAN ) { - BOOL bRet = FALSE; + BOOL bReturn = FALSE; if( ISCHAR( 1 ) ) { - PHB_ITEM pParam = hb_param( 2, HB_IT_STRING | HB_IT_ARRAY ); + PHB_ITEM pProcFiles = ZipCreateArray( hb_param( 2, HB_IT_STRING | HB_IT_ARRAY ), + ISLOG( 11 ) ? hb_parl( 11 ) : TRUE, + hb_param( 10, HB_IT_STRING | HB_IT_ARRAY ) ); - if( pParam ) + if( hb_arrayLen( pProcFiles ) ) { - char * szZipFileName = hb_CheckFile( hb_parc( 1 ) ); - PHB_ITEM pFileToZip = hb_itemArrayNew( 0 ); - PHB_ITEM pFileAttribs = hb_itemArrayNew( 0 ); + char * pszZipFileName = hb_FNAddZipExt( hb_parc( 1 ) ); - ZipCreateArray( pParam, - ISLOG( 11 ) ? hb_parl( 11 ) : TRUE, - pFileToZip, - pFileAttribs, - hb_param( 10, HB_IT_STRING | HB_IT_ARRAY ) ); - - if( hb_arrayLen( pFileToZip ) > 0 ) - { - bRet = hb_CmpPkSpan( szZipFileName, - pFileToZip, + bReturn = hb_CmpPkSpan( pszZipFileName, + pProcFiles, ISNUM( 3 ) ? hb_parni( 3 ) : -1, hb_param( 4, HB_IT_BLOCK ), hb_parl( 5 ), @@ -832,177 +701,281 @@ HB_FUNC( HB_ZIPFILEBYPKSPAN ) hb_parl( 8 ), hb_param( 9, HB_IT_BLOCK ) ); - if( bRet ) - ResetAttribs( pFileToZip, pFileAttribs ); - } + if( bReturn ) + hb_ClearArchiveFlag( pProcFiles ); - hb_itemRelease( pFileAttribs ); - hb_itemRelease( pFileToZip ); - hb_xfree( szZipFileName ); + hb_xfree( pszZipFileName ); } + + hb_itemRelease( pProcFiles ); } - hb_retl( bRet ); + hb_retl( bReturn ); } /* * $DOC$ * $FUNCNAME$ - * HB_UNZIPFILE() + * HB_UNZIPFILE() * $CATEGORY$ - * Zip Functions + * Zip Functions * $ONELINER$ - * Unzip a compressed file + * Unzip a compressed file * $SYNTAX$ - * HB_UNZIPFILE( , , , , , - * | , ) ---> lCompress + * HB_UNZIPFILE( , , , , , + * | , ) ---> lCompress * $ARGUMENTS$ - * Name of the zip file to extract + * Name of the zip file to extract * - * Code block to execute while extracting + * Code block to execute while extracting * - * Toggle to create directory if needed + * Toggle to create directory if needed * - * Password to use to extract files + * Password to use to extract files * - * Path to extract the files to - mandatory + * Path to extract the files to - mandatory * - * | A File or Array of files to extract - mandatory + * | A File or Array of files to extract - mandatory * - * Code block for File Progress + * Code block for File Progress * $RETURNS$ - * .T. if all file was successfully restored, otherwise .F. + * .T. if all file was successfully restored, otherwise .F. * $DESCRIPTION$ - * This function restores all files contained inside the . - * If the extension is omitted, .zip will be assumed. If a file already - * exists, it will be overwritten. + * This function restores all files contained inside the . + * If the extension is omitted, .zip will be assumed. If a file already + * exists, it will be overwritten. * - * 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, every time the file is opened to compress it + * will evaluate bBlock. Parameters of bBlock are cFile and nPos. * - * The is a mandatory parameter. Set to ".\" to extract to the - * current directory + * The is a mandatory parameter. Set to ".\" to extract to the + * current directory * - * If or are not provided, no files will be extracted! - * Make sure you provide the file or files you want extracted + * If or are not provided, no files will be extracted! + * Make sure you provide the file or files you want extracted * - * If is used, an Code block is evaluated, showing the total - * of that file has being processed. - * The codeblock must be defined as follow {|nPos,nTotal| GaugeUpdate(aGauge1,(nPos/nTotal))} + * If is used, an Code block is evaluated, showing the total + * of that file has being processed. + * The codeblock must be defined as follow {|nPos,nTotal| GaugeUpdate(aGauge1,(nPos/nTotal))} * $EXAMPLES$ - * FUNCTION MAIN() + * FUNCTION MAIN() * - * aExtract := hb_GetFilesInZip( "test.zip" ) // extract all files in zip - * IF HB_UNZIPFILE( "test.zip",,,, ".\", aExtract ) - * qout("File was successfully extracted") - * ENDIF + * aExtract := hb_GetFilesInZip( "test.zip" ) // extract all files in zip + * IF HB_UNZIPFILE( "test.zip",,,, ".\", aExtract ) + * qout("File was successfully extracted") + * ENDIF * - * aExtract := hb_GetFilesInZip( "test2.zip" ) // extract all files in zip - * IF HB_UNZIPFILE( "test2.zip", {|cFile| qout( cFile ) },,, ".\", aExtract ) - * qout("File was successfully extracted") - * ENDIF - * Return NIL + * aExtract := hb_GetFilesInZip( "test2.zip" ) // extract all files in zip + * IF HB_UNZIPFILE( "test2.zip", {|cFile| qout( cFile ) },,, ".\", aExtract ) + * qout("File was successfully extracted") + * ENDIF + * Return NIL * $STATUS$ - * R + * R * $COMPLIANCE$ - * This function is a Harbour extension + * This function is a Harbour extension * $PLATFORMS$ - * All + * All * $FILES$ - * Library is hbziparch.lib + * Library is hbziparch.lib * $END$ */ HB_FUNC( HB_UNZIPFILE ) { - BOOL bRet = FALSE; + BOOL bReturn = FALSE; - if( ISCHAR( 1 ) && ( ISARRAY( 6 ) || ISCHAR( 6 ) ) ) + if( ISCHAR( 1 ) ) { - char * szZipFileName = hb_CheckFile( hb_parc( 1 ) ); - PHB_ITEM pUnzip = hb_param( 6, HB_IT_ANY ); - BYTE * pCurDir = ( BYTE * ) hb_xstrcpy( NULL, HB_OS_PATH_DELIM_CHR_STRING, ( const char * ) hb_fsCurDir( 0 ), NULL ); - PHB_ITEM pUnzipFiles = hb_itemArrayNew( 0 ); + char * pszZipFileName = hb_FNAddZipExt( hb_parc( 1 ) ); - if( hb_CheckSpanMode( szZipFileName ) <= 0 ) + if( hb_CheckSpanMode( pszZipFileName ) <= 0 ) { - PHB_ITEM pZipArray = hb_GetFileNamesFromZip( szZipFileName, TRUE ); + PHB_ITEM pUnzip = hb_param( 6, HB_IT_STRING | HB_IT_ARRAY ); + PHB_ITEM pProcFiles = hb_itemArrayNew( 0 ); + PHB_ITEM pZipFiles = hb_GetFileNamesFromZip( pszZipFileName, FALSE ); - if( pUnzip ) + if( ! pUnzip ) + UnzipCreateArray( "*", pProcFiles, pZipFiles ); + else if( HB_IS_ARRAY( pUnzip ) ) { - if( HB_IS_STRING( pUnzip ) ) - { - UnzipCreateArray( hb_itemGetCPtr( pUnzip ), pUnzipFiles, pZipArray ); - } - else if( HB_IS_ARRAY( pUnzip ) ) - { - int uiZ, uiZLen = hb_arrayLen( pUnzip ); + ULONG nPos, nLen = hb_arrayLen( pUnzip ); - for( uiZ = 0; uiZ < uiZLen; uiZ++ ) - UnzipCreateArray( hb_arrayGetCPtr( pUnzip, uiZ + 1 ), pUnzipFiles, pZipArray ); - } + for( nPos = 0; nPos < nLen; nPos++ ) + UnzipCreateArray( hb_arrayGetCPtr( pUnzip, nPos + 1 ), pProcFiles, pZipFiles ); } else - UnzipCreateArray( "*", pUnzipFiles, pZipArray ); + UnzipCreateArray( hb_itemGetCPtr( pUnzip ), pProcFiles, pZipFiles ); - if( hb_arrayLen( pUnzipFiles ) > 0 ) + if( hb_arrayLen( pProcFiles ) ) { - bRet = hb_UnzipSel( szZipFileName, - hb_param( 2, HB_IT_BLOCK ), - hb_parl( 3 ), - hb_parc( 4 ), - hb_parc( 5 ), - pUnzipFiles, - hb_param( 7 , HB_IT_BLOCK ) ); + bReturn = hb_UnzipSel( pszZipFileName, + hb_param( 2, HB_IT_BLOCK ), + hb_parl( 3 ), + hb_parc( 4 ), + hb_parc( 5 ), + pProcFiles, + hb_param( 7, HB_IT_BLOCK ) ); } - - hb_itemRelease( pZipArray ); + + hb_itemRelease( pZipFiles ); + hb_itemRelease( pProcFiles ); } - hb_itemRelease( pUnzipFiles ); - hb_fsChDir( pCurDir ); - hb_xfree( pCurDir ); - hb_xfree( szZipFileName ); + hb_xfree( pszZipFileName ); } - hb_retl( bRet ); + hb_retl( bReturn ); } -/* $DOC$ +/* + * $DOC$ * $FUNCNAME$ - * HB_SETDISKZIP() + * HB_UNZIPFILEINDEX() * $CATEGORY$ * Zip Functions * $ONELINER$ - * Set an codeblock for disk changes + * Unzip a compressed file referenced by it number in the zipfile * $SYNTAX$ - * HB_SETDISKZIP( ) ---> TRUE + * HB_UNZIPFILEINDEX( , , , , , + * | , ) ---> lCompress * $ARGUMENTS$ - * an Code block that contains an function that will be performed - * when the need of changing disk are need. - * $RETURNS$ - * It always returns True - * $DESCRIPTION$ - * This function will set an codeblock that will be evaluated every time - * that an changedisk event is necessary. receives nDisk as a - * code block param that corresponds to the diskette number to be processed. + * Name of the zip file * - * Set this function before opening archives that are in removable media. - * This block will be released, when the caller finish it job. + * Code block to execute while compressing + * + * Toggle to create directory if needed + * + * Password to use to extract files + * + * Path to extract the files to - mandatory. + * + * | A File or Array of files position to extract - mandatory + * + * Code block for File Progress + * $RETURNS$ + * .T. if all file was successfully restored, otherwise .F. + * $DESCRIPTION$ + * This function restores all files contained inside the . + * If the extension is omitted, .zip will be assumed. If a file already + * exists, it will be overwritten. + * + * If is used, every time the file is opened to compress it + * will evaluate bBlock. Parameters of bBlock are cFile and nPos. + * + * The is a mandatory parameter. Set to ".\" to extract to the + * current dir + * + * If or are not provided, no files will be extracted! + * Make sure you provide the file or files you want extracted + * + * If is used, an Code block is evaluated, showing the total + * of that file has being processed. + * The codeblock must be defined as follow {|nPos,nTotal| GaugeUpdate(aGauge1,(nPos/nTotal))} * $EXAMPLES$ - * HB_SETDISKZIP( {|nDisk| Alert( "Please insert disk no " + Str( nDisk, 3 ) ) } ) + * FUNCTION MAIN() + * + * IF HB_UNZIPFILEINDEX( "test.zip",,,, ".\", 1 ) + * qout( "File was successfully created" ) + * ENDIF + * + * IF HB_UNZIPFILEINDEX( "test2.zip", {|cFile| qout(cFile) },,, ".\", { 1, 2 } ) + * qout( "File was successfully created" ) + * ENDIF + * + * Return NIL + * $STATUS$ + * R * $COMPLIANCE$ - * This function is a Harbour extension + * This function is a Harbour extension * $PLATFORMS$ - * All + * All * $FILES$ - * Library is hbziparch.lib + * Library is hbziparch.lib * $END$ */ -HB_FUNC( HB_SETDISKZIP ) +HB_FUNC( HB_UNZIPFILEINDEX ) { - hb_retl( hb_SetCallbackFunc( hb_param( 1, HB_IT_BLOCK ) ) ); + BOOL bReturn = FALSE; + + if( ISCHAR( 1 ) ) + { + PHB_ITEM pDelZip = hb_param( 6, HB_IT_NUMERIC | HB_IT_ARRAY ); + + if( pDelZip ) + { + char * pszZipFileName = hb_FNAddZipExt( hb_parc( 1 ) ); + PHB_ITEM pZipFiles = hb_GetFileNamesFromZip( pszZipFileName, FALSE ); + ULONG nZipLen = hb_arrayLen( pZipFiles ); + PHB_ITEM pProcFiles = hb_itemArrayNew( 0 ); + + if( HB_IS_NUMERIC( pDelZip ) ) + { + ULONG nZipPos = hb_itemGetNL( pDelZip ); + + if( nZipPos > 0 && nZipPos <= nZipLen ) + { + PHB_ITEM pTemp = hb_itemPutNL( NULL, nZipPos ); + hb_arrayAddForward( pProcFiles, pTemp ); + hb_itemRelease( pTemp ); + } + } + else + { + ULONG nPos, nLen = hb_arrayLen( pDelZip ); + + for( nPos = 0; nPos < nLen; nPos++ ) + { + ULONG nZipPos = hb_arrayGetNL( pDelZip, nPos + 1 ); + + if( nZipPos > 0 && nZipPos <= nZipLen ) + { + PHB_ITEM pTemp = hb_itemPutNL( NULL, nZipPos ); + hb_arrayAddForward( pProcFiles, pTemp ); + hb_itemRelease( pTemp ); + } + } + } + + if( hb_arrayLen( pProcFiles ) ) + { + bReturn = hb_UnzipSelIndex( pszZipFileName, + hb_param( 2, HB_IT_BLOCK ), + hb_parl( 3 ), + hb_parc( 4 ), + hb_parc( 5 ), + pProcFiles, + hb_param( 7, HB_IT_BLOCK ) ); + } + + hb_itemRelease( pProcFiles ); + hb_itemRelease( pZipFiles ); + hb_xfree( pszZipFileName ); + } + } + + hb_retl( bReturn ); +} + +HB_FUNC( HB_UNZIPALLFILE ) +{ + if( ISCHAR( 1 ) ) + { + char * szZipFile = hb_FNAddZipExt( hb_parc( 1 ) ); + + hb_retl( hb_UnzipAll( szZipFile, + hb_param( 2, HB_IT_BLOCK ), + hb_parl( 3 ), + hb_parc( 4 ), + hb_parc( 5 ), + hb_param( 6, HB_IT_BLOCK ), + hb_param( 7, HB_IT_BLOCK ) ) ); + + hb_xfree( szZipFile ); + } + else + hb_retl( FALSE ); } /* $DOC$ @@ -1029,76 +1002,109 @@ HB_FUNC( HB_SETDISKZIP ) * $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" ) + * ? "has the file zipnew.i been deleted ", iif( HB_ZIPDELETEFILES( "\test23.zip", "zipnew.i" ), "Yes", "No" ) * $STATUS$ * R * $COMPLIANCE$ - * This function is a Harbour extension + * This function is a Harbour extension * $PLATFORMS$ - * All + * All * $FILES$ - * Library is hbziparch.lib + * Library is hbziparch.lib * $END$ */ HB_FUNC( HB_ZIPDELETEFILES ) { - BOOL bRet = FALSE; + BOOL bReturn = FALSE; if( ISCHAR( 1 ) ) { PHB_ITEM pDelZip = hb_param( 2, HB_IT_STRING | HB_IT_ARRAY | HB_IT_NUMERIC ); - PHB_ITEM pDelZipFiles = hb_itemArrayNew( 0 ); if( pDelZip ) { - char * szZipFileName = hb_CheckFile( hb_parc( 1 ) ); - PHB_ITEM pZipArray = hb_GetFileNamesFromZip( szZipFileName, TRUE ); - int ulLen = hb_arrayLen( pZipArray ); + char * pszZipFileName = hb_FNAddZipExt( hb_parc( 1 ) ); + PHB_ITEM pZipFiles = hb_GetFileNamesFromZip( pszZipFileName, FALSE ); + ULONG nZipLen = hb_arrayLen( pZipFiles ); - if( ulLen ) + if( nZipLen ) { + PHB_ITEM pProcFiles = hb_itemArrayNew( 0 ); + if( HB_IS_STRING( pDelZip ) ) { - if( hb_itemGetCLen( pDelZip ) > 0 ) - UnzipCreateArray( hb_itemGetCPtr( pDelZip ), pDelZipFiles, pZipArray ); + if( hb_itemGetCLen( pDelZip ) ) + UnzipCreateArray( hb_itemGetCPtr( pDelZip ), pProcFiles, pZipFiles ); } else if( HB_IS_ARRAY( pDelZip ) ) { - int uiIn, uiInLen = hb_arrayLen( pDelZip ); + ULONG nPos, nLen = hb_arrayLen( pDelZip ); - for( uiIn = 0; uiIn < uiInLen; uiIn++ ) - UnzipCreateArray( hb_arrayGetCPtr( pDelZip, uiIn + 1 ), pDelZipFiles, pZipArray ); + for( nPos = 0; nPos < nLen; nPos++ ) + UnzipCreateArray( hb_arrayGetCPtr( pDelZip, nPos + 1 ), pProcFiles, pZipFiles ); } else if( HB_IS_NUMERIC( pDelZip ) ) { - int iIndex = hb_itemGetNI( pDelZip ); + ULONG nZipPos = hb_itemGetNL( pDelZip ); - if( iIndex > 0 && iIndex <= ulLen ) + if( nZipPos > 0 && nZipPos <= nZipLen ) { - PHB_ITEM pZipEntry = hb_arrayGetItemPtr( pZipArray, iIndex ); - PHB_ITEM Temp = hb_itemNew( NULL ); - hb_arrayAddForward( pDelZipFiles, hb_itemPutC( Temp, hb_arrayGetCPtr( pZipEntry, 1 ) ) ); - hb_itemRelease( Temp ); + PHB_ITEM pTemp = hb_itemPutC( NULL, hb_arrayGetCPtr( pZipFiles, nZipPos ) ); + hb_arrayAddForward( pProcFiles, pTemp ); + hb_itemRelease( pTemp ); } } - if( hb_arrayLen( pDelZipFiles ) > 0 ) - { - bRet = hb_DeleteSel( szZipFileName, - pDelZipFiles, - hb_parl( 3 ) ); - } + if( hb_arrayLen( pProcFiles ) ) + bReturn = hb_DeleteSel( pszZipFileName, pProcFiles ); + + hb_itemRelease( pProcFiles ); } - hb_itemRelease( pZipArray ); - hb_xfree( szZipFileName ); + hb_itemRelease( pZipFiles ); + hb_xfree( pszZipFileName ); } - - hb_itemRelease( pDelZipFiles ); } - hb_retl( bRet ); + hb_retl( bReturn ); +} + +/* $DOC$ + * $FUNCNAME$ + * HB_SETDISKZIP() + * $CATEGORY$ + * Zip Functions + * $ONELINER$ + * Set an codeblock for disk changes + * $SYNTAX$ + * HB_SETDISKZIP( ) ---> TRUE + * $ARGUMENTS$ + * an Code block that contains an function that will be performed + * when the need of changing disk are need. + * $RETURNS$ + * It always returns True + * $DESCRIPTION$ + * This function will set an codeblock that will be evaluated every time + * that an changedisk event is necessary. receives nDisk as a + * code block param that corresponds to the diskette number to be processed. + * + * 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( {|nDisk| Alert( "Please insert disk no " + Str( nDisk, 3 ) ) } ) + * $COMPLIANCE$ + * This function is a Harbour extension + * $PLATFORMS$ + * All + * $FILES$ + * Library is hbziparch.lib + * $END$ + */ + +HB_FUNC( HB_SETDISKZIP ) +{ + hb_retl( hb_SetCallbackFunc( hb_param( 1, HB_IT_BLOCK ) ) ); } /* $DOC$ @@ -1129,27 +1135,27 @@ HB_FUNC( HB_ZIPDELETEFILES ) * 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 Diskette" - * endif + * if HB_ZIPTESTPK( "A:\test22.zip" ) == 114 + * ? "Invalid Diskette" + * endif * $STATUS$ * R * $COMPLIANCE$ - * This function is a Harbour extension + * This function is a Harbour extension * $PLATFORMS$ - * All + * All * $FILES$ - * Library is hbziparch.lib + * Library is hbziparch.lib * $END$ */ HB_FUNC( HB_ZIPTESTPK ) { - char * szZipFileName = hb_CheckFile( hb_parc( 1 ) ); + char * pszZipFileName = hb_FNAddZipExt( hb_parc( 1 ) ); - hb_retni( hb_CheckSpanMode( szZipFileName ) ); + hb_retni( hb_CheckSpanMode( pszZipFileName ) ); - hb_xfree( szZipFileName ); + hb_xfree( pszZipFileName ); } /* $DOC$ @@ -1186,9 +1192,9 @@ HB_FUNC( HB_ZIPTESTPK ) * $COMPLIANCE$ * This function is a Harbour extension * $PLATFORMS$ - * All + * All * $FILES$ - * Library is hbziparch.lib + * Library is hbziparch.lib * $END$ */ @@ -1255,9 +1261,9 @@ HB_FUNC( HB_SETZIPCOMMENT ) * $COMPLIANCE$ * This function is a Harbour extension * $PLATFORMS$ - * All + * All * $FILES$ - * Library is hbziparch.lib + * Library is hbziparch.lib * $END$ */ @@ -1266,136 +1272,6 @@ HB_FUNC( HB_GETZIPCOMMENT ) hb_retc_buffer( hb_GetZipComment( hb_parc( 1 ) ) ); } -/* - * $DOC$ - * $FUNCNAME$ - * HB_UNZIPFILEINDEX() - * $CATEGORY$ - * Zip Functions - * $ONELINER$ - * Unzip a compressed file referenced by it number in the zipfile - * $SYNTAX$ - * HB_UNZIPFILEINDEX( , , , , , - * | , ) ---> 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 to - mandatory. - * - * | A File or Array of files position to extract - mandatory - * - * Code block for File Progress - * $RETURNS$ - * .T. if all file was successfully restored, otherwise .F. - * $DESCRIPTION$ - * This function restores all files contained inside the . - * If the extension is omitted, .zip will be assumed. If a file already - * exists, it will be overwritten. - * - * If is used, every time the file is opened to compress it - * will evaluate bBlock. Parameters of bBlock are cFile and nPos. - * - * The is a mandatory parameter. Set to ".\" to extract to the - * current dir - * - * If or are not provided, no files will be extracted! - * Make sure you provide the file or files you want extracted - * - * If is used, an Code block is evaluated, showing the total - * of that file has being processed. - * The codeblock must be defined as follow {|nPos,nTotal| GaugeUpdate(aGauge1,(nPos/nTotal))} - * $EXAMPLES$ - * FUNCTION MAIN() - * - * IF HB_UNZIPFILEINDEX( "test.zip",,,, ".\", 1 ) - * qout( "File was successfully created" ) - * ENDIF - * - * IF HB_UNZIPFILEINDEX( "test2.zip", {|cFile| qout(cFile) },,, ".\", { 1, 2 } ) - * qout( "File was successfully created" ) - * ENDIF - * - * Return NIL - * $STATUS$ - * R - * $COMPLIANCE$ - * This function is a Harbour extension - * $PLATFORMS$ - * All - * $FILES$ - * Library is hbziparch.lib - * $END$ - */ - -HB_FUNC( HB_UNZIPFILEINDEX ) -{ - BOOL bRet = FALSE; - - if( ISCHAR( 1 ) ) - { - PHB_ITEM pDelZip = hb_param( 6, HB_IT_NUMERIC | HB_IT_ARRAY ); - - if( pDelZip ) - { - char * szZipFileName = hb_CheckFile( hb_parc( 1 ) ); - PHB_ITEM pZipArray = hb_GetFileNamesFromZip( szZipFileName, TRUE ); - int ulLen = hb_arrayLen( pZipArray ); - PHB_ITEM DelZip = hb_itemArrayNew( 0 ); - - if( HB_IS_NUMERIC( pDelZip ) ) - { - int iIndex = hb_itemGetNI( pDelZip ); - - if( iIndex > 0 && iIndex <= ulLen ) - { - PHB_ITEM Temp = hb_itemNew( NULL ); - hb_arrayAddForward( DelZip, hb_itemPutNI( Temp, iIndex ) ); - hb_itemRelease( Temp ); - } - } - else - { - int ui; - - for( ui = 0; ui < ulLen; ui++ ) - { - int iIndex = hb_arrayGetNI( pDelZip, ui + 1 ); - - if( iIndex && iIndex > 0 && iIndex <= ulLen ) - { - PHB_ITEM Temp = hb_itemNew( NULL ); - hb_arrayAddForward( DelZip, hb_itemPutNI( Temp, iIndex ) ); - hb_itemRelease( Temp ); - } - } - } - - if( hb_arrayLen( DelZip ) > 0 ) - { - bRet = hb_UnzipSelIndex( szZipFileName, - hb_param( 2, HB_IT_BLOCK ), - hb_parl( 3 ), - hb_parc( 4 ), - hb_parc( 5 ), - DelZip, - hb_param( 7, HB_IT_BLOCK ) ); - } - - hb_itemRelease( DelZip ); - hb_itemRelease( pZipArray ); - hb_xfree( szZipFileName ); - } - } - - hb_retl( bRet ); -} - HB_FUNC( TRANSFERFROMZIP ) { hb_retl( hb_TransferFilesFromzip( hb_parc( 1 ), @@ -1408,21 +1284,37 @@ HB_FUNC( SETZIPREADONLY ) hb_SetZipReadOnly( hb_parl( 1 ) ); } -HB_FUNC( HB_UNZIPALLFILE ) +HB_FUNC( HB_ZIPWITHPASSWORD ) { - if( ISCHAR( 1 ) && ! ISCHAR( 6 ) && ! ISARRAY( 6 ) ) - { - char * szZipFile = hb_CheckFile( hb_parc( 1 ) ); + hb_retl( hb_IsPassWord( hb_parc( 1 ) ) ); +} - hb_retl( hb_UnzipAll( szZipFile, - hb_param( 2, HB_IT_BLOCK ), - hb_parl( 3 ), - hb_parc( 4 ), - hb_parc( 5 ), - hb_param( 6, HB_IT_BLOCK ), - hb_param( 7, HB_IT_BLOCK ) ) ); - hb_xfree( szZipFile ); +HB_FUNC( HB_GETFILECOUNT ) +{ + ULONG nCount = 0; + + if( ISCHAR( 1 ) ) + { + char * pszZipFileName = hb_FNAddZipExt( hb_parc( 1 ) ); + + nCount = hb_GetNumberofFilestoUnzip( pszZipFileName ); + + hb_xfree( pszZipFileName ); + } + + hb_retnl( ( long ) nCount ); +} + +HB_FUNC( HB_GETFILESINZIP ) +{ + if( ISCHAR( 1 ) ) + { + char * pszZipFileName = hb_FNAddZipExt( hb_parc( 1 ) ); + + hb_itemReturnRelease( hb_GetFileNamesFromZip( pszZipFileName, hb_parl( 2 ) ) ); + + hb_xfree( pszZipFileName ); } else - hb_retl( FALSE ); + hb_reta( 0 ); } diff --git a/harbour/contrib/hbziparch/hbzipnew.cpp b/harbour/contrib/hbziparch/hbzipnew.cpp index 2e2242fe0c..bca9f3126c 100644 --- a/harbour/contrib/hbziparch/hbzipnew.cpp +++ b/harbour/contrib/hbziparch/hbzipnew.cpp @@ -4,7 +4,7 @@ /* * Harbour Project source code: - * Zlib low level interface for Harbour + * ZipArchive low level interface for Harbour * * Copyright 2000-2003 Luiz Rafael Culik * www - http://www.harbour-project.org @@ -65,7 +65,7 @@ #include "ZipArchive.h" #endif -#define HBZA_FI_FILEPOS 1 +#define HBZA_FI_FILENAME 1 #define HBZA_FI_LENGTH 2 #define HBZA_FI_METHOD 3 #define HBZA_FI_SIZE 4 @@ -92,316 +92,222 @@ static HB_ZA_SETTINGS s_hbzaSettings = { 0 }; extern "C" { #endif -class SegmCallback : public CZipSegmCallback +class CHBZipSegmCallback : public CZipSegmCallback { bool Callback( ZIP_SIZE_TYPE iProgress ) { - PHB_ITEM Disk = hb_itemPutNL( NULL, m_uVolumeNeeded ); + PHB_ITEM pDisk = hb_itemPutNL( NULL, m_uVolumeNeeded ); HB_SYMBOL_UNUSED( iProgress ); - hb_vmEvalBlockV( s_hbzaSettings.pChangeDiskBlock, 1, Disk); - hb_itemRelease( Disk ); + hb_vmEvalBlockV( s_hbzaSettings.pChangeDiskBlock, 1, pDisk ); + hb_itemRelease( pDisk ); return true; } }; -class SegmActionCallback : public CZipActionCallback +class CHBZipActionCallback : public CZipActionCallback { bool Callback( ZIP_SIZE_TYPE iProgress ) { - PHB_ITEM Disk = hb_itemPutNL( NULL, m_uProcessed ); - PHB_ITEM Total = hb_itemPutNL( NULL, m_uTotalToProcess ); + PHB_ITEM pDisk = hb_itemPutNL( NULL, m_uProcessed ); + PHB_ITEM pTotal = hb_itemPutNL( NULL, m_uTotalToProcess ); HB_SYMBOL_UNUSED( iProgress ); - hb_vmEvalBlockV( s_hbzaSettings.pProgressBlock, 2, Disk, Total ); - hb_itemRelease( Disk ); - hb_itemRelease( Total ); + hb_vmEvalBlockV( s_hbzaSettings.pProgressBlock, 2, pDisk, pTotal ); + hb_itemRelease( pDisk ); + hb_itemRelease( pTotal ); return true; } }; -class SegmCallbackc : public CZipSegmCallback -{ - bool Callback( ZIP_SIZE_TYPE iProgress ) - { - PHB_ITEM Disk = hb_itemPutNL( NULL, m_uVolumeNeeded ); - HB_SYMBOL_UNUSED( iProgress ); - hb_vmEvalBlockV( s_hbzaSettings.pChangeDiskBlock, 1, Disk ); - hb_itemRelease( Disk ); - - return true; - } -}; - -class SegmActionCallbackc : public CZipActionCallback -{ - bool Callback( ZIP_SIZE_TYPE iProgress ) - { - PHB_ITEM Disk = hb_itemPutNL( NULL, m_uProcessed ); - PHB_ITEM Total = hb_itemPutNL( NULL, m_uTotalToProcess ); - HB_SYMBOL_UNUSED( iProgress ); - hb_vmEvalBlockV( s_hbzaSettings.pProgressBlock, 2, Disk, Total ); - hb_itemRelease( Disk ); - hb_itemRelease( Total ); - - return true; - } -}; - -static HB_FOFFSET hb_GetCurrentFileSize( const char * szFile ) -{ - return hb_fsFSize( ( BYTE * ) szFile, TRUE ); -} - int hb_CheckSpanMode( char * szFile ) { + CZipArchive myzip; int iReturn = 0; - CZipArchive szZip; - SegmCallback span; - - szZip.SetSegmCallback( &span ); + CHBZipSegmCallback cb_Segm; + myzip.SetSegmCallback( &cb_Segm ); try { - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); /* s.r. to avoid GPF when ZIP file is read only ! */ + myzip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); /* s.r. to avoid GPF when ZIP file is read only ! */ } catch( CZipException &e ) { - if( e.m_iCause == CZipException::cdirNotFound ) + switch( e.m_iCause ) { - szZip.Close( true ); - iReturn = 114; - } - else if( e.m_iCause == CZipException::noCallback ) - { - szZip.Close( true ); - iReturn = 103; - } - else if( e.m_iCause == CZipException::genericError ) - { - szZip.Close( true ); - iReturn = 100; - } - else if( e.m_iCause == CZipException::badZipFile ) - { - szZip.Close( true ); - iReturn = 101; - } - else if( e.m_iCause == CZipException::badCrc ) - { - szZip.Close( true ); - iReturn = 102; - } - else if( e.m_iCause == CZipException::aborted ) - { - szZip.Close( true ); - iReturn = 104; - } - else if( e.m_iCause == CZipException::abortedAction ) - { - szZip.Close( true ); - iReturn = 105; - } - else if( e.m_iCause == CZipException::abortedSafely ) - { - szZip.Close( true ); - iReturn = 106; - } - else if( e.m_iCause == CZipException::nonRemovable ) - { - szZip.Close( true ); - iReturn = 107; - } - else if( e.m_iCause == CZipException::tooManyVolumes ) - { - szZip.Close( true ); - iReturn = 108; - } - else if( e.m_iCause == CZipException::tooLongData ) - { - szZip.Close( true ); - iReturn = 109; - } - else if( e.m_iCause == CZipException::badPassword ) - { - szZip.Close( true ); - iReturn = 110; - } - else if( e.m_iCause == CZipException::dirWithSize ) - { - szZip.Close( true ); - iReturn = 111; - } - else if( e.m_iCause == CZipException::internalError ) - { - szZip.Close( true ); - iReturn = 112; - } - else if( e.m_iCause == CZipException::notRemoved ) - { - szZip.Close( true ); - iReturn = 113; - } - else if( e.m_iCause == CZipException::notRenamed ) - { - szZip.Close( true ); - iReturn = 114; - } - else if( e.m_iCause == CZipException::platfNotSupp ) - { - szZip.Close( true ); - iReturn = 115; + case CZipException::genericError : iReturn = 100; break; + case CZipException::badZipFile : iReturn = 101; break; + case CZipException::badCrc : iReturn = 102; break; + case CZipException::noCallback : iReturn = 103; break; + case CZipException::aborted : iReturn = 104; break; + case CZipException::abortedAction : iReturn = 105; break; + case CZipException::abortedSafely : iReturn = 106; break; + case CZipException::nonRemovable : iReturn = 107; break; + case CZipException::tooManyVolumes: iReturn = 108; break; + case CZipException::tooLongData : iReturn = 109; break; + case CZipException::badPassword : iReturn = 110; break; + case CZipException::dirWithSize : iReturn = 111; break; + case CZipException::internalError : iReturn = 112; break; + case CZipException::notRemoved : iReturn = 113; break; + case CZipException::notRenamed : iReturn = 114; break; + case CZipException::platfNotSupp : iReturn = 115; break; + case CZipException::cdirNotFound : iReturn = 116; break; } } - if( ! iReturn ) + if( iReturn == 0 ) { - iReturn = szZip.GetSegmMode(); - szZip.Close(); + iReturn = myzip.GetSegmMode(); + myzip.Close(); } + else + myzip.Close( true ); return iReturn; } -int hb_CmpPkSpan( char *szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char *szPassWord, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ) +static BOOL hb_zipopenread( CZipArchive * myzip, CHBZipSegmCallback * cb_Segm, char * szFile ) { - ULONG ulCount; - - BOOL bReturn = TRUE; - BOOL bFileExist = hb_fsFile( ( BYTE * ) szFile ); - CZipString szArchive = szFile; - - CZipArchive szZip; - SegmCallback span; - SegmActionCallback spanac; - - szZip.SetSegmCallback( &span ); - bDrive = false; - - try - { - if( ( bFileExist && bOverWrite ) || !bFileExist ) - szZip.Open( szArchive, CZipArchive::zipCreateSegm, 0 ); - else - bReturn = FALSE; - } - catch( CZipException ) - { - bReturn = FALSE; - } - catch( ... ) - {} - - if( ! bReturn ) - return ( int ) bReturn; - - if( szPassWord ) - szZip.SetPassword( szPassWord ); - - if( s_hbzaSettings.pszComment ) - { - szZip.SetGlobalComment( s_hbzaSettings.pszComment ); - hb_xfree( s_hbzaSettings.pszComment ); - } - - if( pProgress && HB_IS_BLOCK( pProgress ) ) - { - s_hbzaSettings.pProgressBlock = pProgress; - szZip.SetCallback( &spanac ); - } - - for( ulCount = 1; ulCount <= hb_arrayLen( pArray ); ulCount++ ) - { - if( pBlock && HB_IS_BLOCK( pBlock ) ) - { - PHB_ITEM FileName = hb_itemPutC( NULL, hb_arrayGetCPtr( pArray, ulCount ) ); - PHB_ITEM FilePos = hb_itemPutNI( NULL, ulCount ); - hb_vmEvalBlockV( pBlock, 2, FileName, FilePos ); - hb_itemRelease( FileName ); - hb_itemRelease( FilePos ); - } - - try - { - szZip.AddNewFile( hb_arrayGetCPtr( pArray, ulCount ), iCompLevel, ( bDrive || bPath ) ? true : false, CZipArchive::zipsmSafeSmart, 65536 ); - } - catch( ... ) - {} - } - - try - { - szZip.Close(); - } - catch( CZipException ) - { - bReturn = FALSE; - } - catch( ... ) - {} - - return ( int ) bReturn; -} - -PHB_ITEM hb_GetFileNamesFromZip( char * szFile, BOOL iMode ) -{ - PHB_ITEM pZipArray; - bool iReturn = true; - - CZipArchive szZip; - SegmCallback span; - - if( s_hbzaSettings.iWrite > 0 ) - szZip.SetAdvanced( s_hbzaSettings.iWrite, s_hbzaSettings.iExtract, s_hbzaSettings.iRead ); - try { switch( hb_CheckSpanMode( szFile ) ) { case 0: - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); + myzip->Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); break; case -1: - szZip.SetSegmCallback( &span ); - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); + { + myzip->SetSegmCallback( cb_Segm ); + myzip->Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); break; - + } case -2: - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 1 ); + myzip->Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 1 ); break; default: - iReturn = false; + return FALSE; } } catch( ... ) {} - if( iReturn ) + return TRUE; +} + +BOOL hb_IsPassWord( char * szFile ) +{ + CZipArchive myzip; + CHBZipSegmCallback cb_Segm; + BOOL bReturn = hb_zipopenread( &myzip, &cb_Segm, szFile ); + + if( bReturn ) { - int iNumberOfFiles = szZip.GetCount(); - ULONG ulCount; + CZipFileHeader fh; - pZipArray = hb_itemArrayNew( iNumberOfFiles ); + myzip.GetFileInfo( fh, 0 ); - for( ulCount = 0; ulCount < ( ULONG ) iNumberOfFiles; ulCount++ ) + bReturn = fh.IsEncrypted(); + + myzip.Close(); + } + + return bReturn; +} + +static void hb_CallbackFuncFree( void * cargo ) +{ + HB_SYMBOL_UNUSED( cargo ); + + if( s_hbzaSettings.pChangeDiskBlock ) + { + hb_itemRelease( s_hbzaSettings.pChangeDiskBlock ); + s_hbzaSettings.pChangeDiskBlock = NULL; + } +} + +BOOL hb_SetCallbackFunc( PHB_ITEM pChangeDiskBlock ) +{ + if( s_hbzaSettings.pChangeDiskBlock ) + hb_itemClear( s_hbzaSettings.pChangeDiskBlock ); + else + { + /* register cleanup function, it's executed only once */ + hb_vmAtExit( hb_CallbackFuncFree, NULL ); + s_hbzaSettings.pChangeDiskBlock = hb_itemNew( NULL ); + } + + if( pChangeDiskBlock ) + hb_itemCopy( s_hbzaSettings.pChangeDiskBlock, pChangeDiskBlock ); + + return TRUE; +} + +void hb_SetZipBuff( int a, int b, int c ) +{ + s_hbzaSettings.iWrite = HB_MIN( a, 65535 ); + s_hbzaSettings.iExtract = HB_MIN( b, 16384 ); + s_hbzaSettings.iRead = HB_MIN( c, 32768 ); +} + +void hb_SetZipReadOnly( int iRead ) +{ + s_hbzaSettings.iReadOnly = iRead; +} + +void hb_SetZipComment( char * szComment ) +{ + s_hbzaSettings.pszComment = hb_strdup( szComment ); +} + +char * hb_GetZipComment( char * szFile ) +{ + CZipArchive myzip; + CHBZipSegmCallback cb_Segm; + char * szTemp; + + szTemp = hb_strdup( hb_zipopenread( &myzip, &cb_Segm, szFile ) ? ( const char * ) myzip.GetGlobalComment() : "" ); + + myzip.Close(); + + return szTemp; +} + +PHB_ITEM hb_GetFileNamesFromZip( char * szFile, BOOL bVerbose ) +{ + CZipArchive myzip; + CHBZipSegmCallback cb_Segm; + BOOL bReturn = hb_zipopenread( &myzip, &cb_Segm, szFile ); + PHB_ITEM pZipArray; + + if( bReturn ) + { + ZIP_INDEX_TYPE nZipFCount = myzip.GetCount(); + ZIP_INDEX_TYPE nZipFPos; + + if( s_hbzaSettings.iWrite > 0 ) + myzip.SetAdvanced( s_hbzaSettings.iWrite, s_hbzaSettings.iExtract, s_hbzaSettings.iRead ); + + pZipArray = hb_itemArrayNew( nZipFCount ); + + for( nZipFPos = 0; nZipFPos < nZipFCount; nZipFPos++ ) { CZipFileHeader fh; - szZip.GetFileInfo( fh, ( WORD ) ulCount ); + myzip.GetFileInfo( fh, nZipFPos ); - if( iMode ) + if( bVerbose ) { - PHB_ITEM TempArray = hb_itemArrayNew( 9 ); + PHB_ITEM pTempArray = hb_itemArrayNew( 9 ); char szAttr[ 5 ]; char szTime[ 9 ]; - char * szMethod = NULL; + char * szMethod = "Unknown"; char szCRC[ 9 ]; int iRatio; - hb_arraySetC( TempArray, HBZA_FI_FILEPOS, ( char * ) ( LPCTSTR ) fh.GetFileName() ); + hb_arraySetC( pTempArray, HBZA_FI_FILENAME, ( char * ) ( LPCTSTR ) fh.GetFileName() ); if( fh.m_uUncomprSize > 0 ) { @@ -410,25 +316,25 @@ PHB_ITEM hb_GetFileNamesFromZip( char * szFile, BOOL iMode ) if( iRatio < 0 ) iRatio = 0; - hb_arraySetNL( TempArray, HBZA_FI_LENGTH, fh.m_uUncomprSize ); - hb_arraySetNL( TempArray, HBZA_FI_SIZE, fh.m_uComprSize ); - hb_arraySetNL( TempArray, HBZA_FI_RATIO, iRatio ); + hb_arraySetNL( pTempArray, HBZA_FI_LENGTH , fh.m_uUncomprSize ); + hb_arraySetNL( pTempArray, HBZA_FI_SIZE , fh.m_uComprSize ); + hb_arraySetNL( pTempArray, HBZA_FI_RATIO , iRatio ); } else { iRatio = 0; - hb_arraySetNL( TempArray, HBZA_FI_LENGTH, fh.m_uUncomprSize ); - hb_arraySetNL( TempArray, HBZA_FI_SIZE, fh.m_uComprSize ); - hb_arraySetNL( TempArray, HBZA_FI_RATIO, iRatio ); + hb_arraySetNL( pTempArray, HBZA_FI_LENGTH , fh.m_uUncomprSize ); + hb_arraySetNL( pTempArray, HBZA_FI_SIZE , fh.m_uComprSize ); + hb_arraySetNL( pTempArray, HBZA_FI_RATIO , iRatio ); } #if defined( HB_OS_WIN_32 ) { DWORD uAttr = fh.GetSystemAttr(); - szAttr[ 0 ] = uAttr & FILE_ATTRIBUTE_READONLY ? ( char ) _T( 'r' ) : ( char ) _T( '-' ); - szAttr[ 1 ] = uAttr & FILE_ATTRIBUTE_HIDDEN ? ( char ) _T( 'h' ) : ( char ) _T( '-' ); - szAttr[ 2 ] = uAttr & FILE_ATTRIBUTE_SYSTEM ? ( char ) _T( 's' ) : ( char ) _T( 'w' ); - szAttr[ 3 ] = uAttr & FILE_ATTRIBUTE_DIRECTORY ? ( char ) _T( 'D' ) : uAttr & FILE_ATTRIBUTE_ARCHIVE ? ( char ) _T( 'a' ): ( char ) _T( '-' ); + szAttr[ 0 ] = uAttr & FILE_ATTRIBUTE_READONLY ? 'r' : '-'; + szAttr[ 1 ] = uAttr & FILE_ATTRIBUTE_HIDDEN ? 'h' : '-'; + szAttr[ 2 ] = uAttr & FILE_ATTRIBUTE_SYSTEM ? 's' : 'w'; + szAttr[ 3 ] = uAttr & FILE_ATTRIBUTE_DIRECTORY ? 'D' : uAttr & FILE_ATTRIBUTE_ARCHIVE ? 'a' : '-'; if( fh.m_uMethod == 0 || uAttr & FILE_ATTRIBUTE_DIRECTORY ) szMethod = "Stored"; @@ -440,11 +346,11 @@ PHB_ITEM hb_GetFileNamesFromZip( char * szFile, BOOL iMode ) szAttr[ 3 ] = ' '; #endif - szAttr[ 4 ] = fh.IsEncrypted() ? ( char ) _T( '*' ) : ( char ) _T( ' ' ); + szAttr[ 4 ] = fh.IsEncrypted() ? '*' : ' '; if( fh.m_uMethod == Z_DEFLATED ) { - UINT iLevel = ( UINT )( ( fh.m_uFlag & 0x6 ) / 2 ); + UINT iLevel = ( UINT ) ( ( fh.m_uFlag & 0x6 ) / 2 ); switch( iLevel ) { @@ -460,18 +366,15 @@ PHB_ITEM hb_GetFileNamesFromZip( char * szFile, BOOL iMode ) case 3: szMethod = "DeflatF"; break; - - default: - szMethod = "Unknown"; } } - hb_arraySetC( TempArray, HBZA_FI_METHOD, szMethod ); + hb_arraySetC( pTempArray, HBZA_FI_METHOD, szMethod ); snprintf( szCRC, sizeof( szCRC ), "%8.8lx", ( ULONG ) fh.m_uCrc32 ); - hb_arraySetCL( TempArray, HBZA_FI_CRC32, szCRC, 8 ); - hb_arraySetDL( TempArray, HBZA_FI_DATE, hb_dateEncode( ( LONG ) ( fh.m_uModDate >> 9 ) + 1980, ( LONG ) ( ( fh.m_uModDate & ~0xFE00 ) >> 5 ), ( LONG ) fh.m_uModDate & ~0xFFE0 ) ); + hb_arraySetCL( pTempArray, HBZA_FI_CRC32, szCRC, 8 ); + hb_arraySetDL( pTempArray, HBZA_FI_DATE, hb_dateEncode( ( LONG ) ( fh.m_uModDate >> 9 ) + 1980, ( LONG ) ( ( fh.m_uModDate & ~0xFE00 ) >> 5 ), ( LONG ) fh.m_uModDate & ~0xFFE0 ) ); { time_t theTime = fh.GetTime(); @@ -480,49 +383,62 @@ PHB_ITEM hb_GetFileNamesFromZip( char * szFile, BOOL iMode ) snprintf( szTime, sizeof( szTime ), "%02d:%02d:%02d", SzTime->tm_hour, SzTime->tm_min, SzTime->tm_sec ); } - hb_arraySetCL( TempArray, HBZA_FI_TIME, szTime, 8 ); - hb_arraySetCL( TempArray, HBZA_FI_ATTR, szAttr, 5 ); - hb_arraySetForward( pZipArray, ulCount+1, TempArray ); - hb_itemRelease( TempArray ); + hb_arraySetCL( pTempArray, HBZA_FI_TIME, szTime, 8 ); + hb_arraySetCL( pTempArray, HBZA_FI_ATTR, szAttr, 5 ); + hb_arraySetForward( pZipArray, ( ULONG ) nZipFPos + 1, pTempArray ); + hb_itemRelease( pTempArray ); } else - hb_arraySetC( pZipArray, ulCount + 1, ( char * ) ( LPCTSTR ) fh.GetFileName() ); + hb_arraySetC( pZipArray, ( ULONG ) nZipFPos + 1, ( char * ) ( LPCTSTR ) fh.GetFileName() ); } + + myzip.Close(); } else pZipArray = hb_itemArrayNew( 0 ); - szZip.Close(); - return pZipArray; } -BOOL hb_IsPassWord( char *szFile ) +ULONG hb_GetNumberofFilestoUnzip( char * szFile ) { - BOOL bReturn = TRUE; - CZipFileHeader fh; + CZipArchive myzip; + ZIP_INDEX_TYPE nZipFCount = 0; - CZipArchive szZip; - SegmCallback span; + CHBZipSegmCallback cb_Segm; + myzip.SetSegmCallback( &cb_Segm ); + + try + { + myzip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); + nZipFCount = myzip.GetCount(); + myzip.Close(); + } + catch( CZipException &e ) + { + if( e.m_iCause == CZipException::badZipFile || e.m_iCause == CZipException::cdirNotFound ) + nZipFCount = ( ZIP_INDEX_TYPE ) -1; + } + + return ( ULONG ) nZipFCount; +} + +BOOL hb_DeleteSel( char * szFile, PHB_ITEM pArray ) +{ + CZipArchive myzip; + BOOL bReturn = TRUE; try { switch( hb_CheckSpanMode( szFile ) ) { case 0: - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); + myzip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); break; case -1: - szZip.SetSegmCallback( &span ); - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); - break; - case -2: - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 1 ); - break; - - default: +/* default: */ bReturn = FALSE; } } @@ -531,464 +447,212 @@ BOOL hb_IsPassWord( char *szFile ) if( bReturn ) { - szZip.GetFileInfo( fh, ( WORD )0 ); + CZipStringArray aFiles; + ULONG nPos; - bReturn = fh.IsEncrypted(); + for( nPos = 1; nPos <= hb_arrayLen( pArray ); nPos ++ ) + aFiles.Add( hb_arrayGetCPtr( pArray, nPos ) ); - szZip.Close(); + myzip.RemoveFiles( aFiles ); + + myzip.Close(); } return bReturn; } -int hb_GetNumberofFilestoUnzip( char * szFile ) +BOOL hb_UnzipAll( char * szFile, PHB_ITEM pBlock, BOOL bWithPath, char * szPassword, char * pbyBuffer, PHB_ITEM pDiskBlock, PHB_ITEM pProgress ) { - int iNumberOfFiles = 0; - - CZipArchive szZip; - SegmCallback span; - - szZip.SetSegmCallback( &span ); - - try - { - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); - iNumberOfFiles = szZip.GetCount(); - szZip.Close(); - } - catch( CZipException &e ) - { - if( e.m_iCause == CZipException::badZipFile || e.m_iCause == CZipException::cdirNotFound ) - iNumberOfFiles = -1; - } - - return iNumberOfFiles; -} - -static void hb_CallbackFuncFree( void * cargo ) -{ - HB_SYMBOL_UNUSED( cargo ); - - if( s_hbzaSettings.pChangeDiskBlock ) - { - hb_itemRelease( s_hbzaSettings.pChangeDiskBlock ); - s_hbzaSettings.pChangeDiskBlock = NULL; - } -} - -int hb_SetCallbackFunc( PHB_ITEM pFunc ) -{ - if( s_hbzaSettings.pChangeDiskBlock ) - hb_itemClear( s_hbzaSettings.pChangeDiskBlock ); - else - { - /* register cleanup function, it's executed only once */ - hb_vmAtExit( hb_CallbackFuncFree, NULL ); - s_hbzaSettings.pChangeDiskBlock = hb_itemNew( NULL ); - } - - if( pFunc ) - hb_itemCopy( s_hbzaSettings.pChangeDiskBlock, pFunc ); - - return ( int ) true; -} - -int hb_DeleteSel( char * szFile, PHB_ITEM pArray, BOOL bCase ) -{ - bool iReturn = true; - CZipArchive szZip; - CZipStringArray aFiles; - - HB_SYMBOL_UNUSED( bCase ); - - try - { - switch( hb_CheckSpanMode( szFile ) ) - { - case 0: - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); - break; - - case -1: - case -2: -/* default: */ - iReturn = false; - } - } - catch( CZipException ) - {} - - if( iReturn ) - { - ULONG ulCount; - - for( ulCount = 1; ulCount <= ( ULONG ) hb_arrayLen( pArray ); ulCount ++ ) - aFiles.Add( ( char * ) hb_arrayGetCPtr( pArray, ulCount ) ); - - szZip.RemoveFiles( aFiles ); - } - - szZip.Close(); - - return ( int ) iReturn; -} - -int hb_UnzipAll( char * szFile, PHB_ITEM pBlock, BOOL bWithPath, char * szPassWord, char * pbyBuffer, PHB_ITEM pDiskBlock, PHB_ITEM pProgress ) -{ - bool iReturn = true; - int iMode; - CZipArchive szZip; - SegmCallback span; - SegmActionCallback spanac; - - char * szPath = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 1 ); + CZipArchive myzip; + CHBZipSegmCallback cb_Segm; + BOOL bReturn = hb_zipopenread( &myzip, &cb_Segm, szFile ); HB_SYMBOL_UNUSED( pDiskBlock ); - if( pProgress && HB_IS_BLOCK( pProgress ) ) + if( bReturn ) { - s_hbzaSettings.pProgressBlock = pProgress; - szZip.SetCallback( &spanac ); - } + CHBZipActionCallback cb_Action; + char * pszPath = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 1 ); + ZIP_INDEX_TYPE uiCount; - if( szPassWord ) - szZip.SetPassword( szPassWord ); + if( szPassword ) + myzip.SetPassword( szPassword ); - iMode = hb_CheckSpanMode( szFile ); - - try - { - if( iMode == 0 ) - szZip.Open( szFile, CZipArchive::zipOpen, 0 ); - else + if( pProgress && HB_IS_BLOCK( pProgress ) ) { - if( iMode == -1 ) - { - szZip.SetSegmCallback( &span ); - szZip.Open( szFile, CZipArchive::zipOpen, 0 ); - } - else - { - if( iMode == -2 ) - szZip.Open( szFile, CZipArchive::zipOpen, 1 ); - else - iReturn = false; - } - } - } - catch( ... ) - {} - - if( iReturn ) - { - uLong uiCount; - - if( pbyBuffer ) - { - if( hb_stricmp( pbyBuffer, ".\\" ) == 0 ) - hb_fsCurDirBuff( 0, ( BYTE * ) szPath, _POSIX_PATH_MAX + 1 ); - else - hb_strncpy( szPath, pbyBuffer, _POSIX_PATH_MAX ); - - szZip.SetRootPath( szPath ); + s_hbzaSettings.pProgressBlock = pProgress; + myzip.SetCallback( &cb_Action ); } - for( uiCount = 0; uiCount < ( uLong ) szZip.GetCount(); uiCount++ ) + hb_strncpy( pszPath, pbyBuffer && strcmp( pbyBuffer, ".\\" ) ? pbyBuffer : "", _POSIX_PATH_MAX ); + + myzip.SetRootPath( pszPath ); + + for( uiCount = 0; uiCount < myzip.GetCount(); uiCount++ ) { CZipFileHeader fh; - szZip.GetFileInfo( fh, ( WORD ) uiCount ); + myzip.GetFileInfo( fh, uiCount ); if( pBlock && HB_IS_BLOCK( pBlock ) ) { - PHB_ITEM FileName = hb_itemPutC( NULL, ( char * ) ( LPCTSTR ) fh.GetFileName() ); - PHB_ITEM FilePos = hb_itemPutNI( NULL, uiCount ); - hb_vmEvalBlockV( pBlock, 2, FileName, FilePos ); - hb_itemRelease( FileName ); - hb_itemRelease( FilePos ); + PHB_ITEM pFileName = hb_itemPutC( NULL, ( char * ) ( LPCTSTR ) fh.GetFileName() ); + PHB_ITEM pFilePos = hb_itemPutNL( NULL, ( LONG ) uiCount ); + hb_vmEvalBlockV( pBlock, 2, pFileName, pFilePos ); + hb_itemRelease( pFileName ); + hb_itemRelease( pFilePos ); } try { - szZip.SetPassword( szPassWord ); - szZip.ExtractFile( ( WORD ) uiCount, ( LPCTSTR ) szPath, bWithPath ? true : false, NULL, 65536 ); + myzip.SetPassword( szPassword ); + myzip.ExtractFile( uiCount, ( LPCTSTR ) pszPath, bWithPath ? true : false, NULL, 65536 ); } catch( ... ) { - szZip.CloseFile( NULL, true ); + myzip.CloseFile( NULL, true ); } } + + hb_xfree( pszPath ); + + myzip.Close(); } - hb_xfree( szPath ); - - return iReturn; + return bReturn; } -int hb_UnzipSel( char * szFile, PHB_ITEM pBlock, BOOL lWithPath, char * szPassWord, const char * pbyBuffer, PHB_ITEM pSelArray, PHB_ITEM pProgress ) +BOOL hb_UnzipSel( char * szFile, PHB_ITEM pBlock, BOOL lWithPath, char * szPassword, const char * pbyBuffer, PHB_ITEM pSelArray, PHB_ITEM pProgress ) { - bool iReturn = true; - char * szPath = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 1 ); + CZipArchive myzip; + CHBZipSegmCallback cb_Segm; + BOOL bReturn = hb_zipopenread( &myzip, &cb_Segm, szFile ); - CZipArchive szZip; - SegmCallback span; - SegmActionCallback spanac; - - if( pProgress && HB_IS_BLOCK( pProgress ) ) + if( bReturn ) { - s_hbzaSettings.pProgressBlock = pProgress; - szZip.SetCallback( &spanac ); - } + CHBZipActionCallback cb_Action; + char * pszPath = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 1 ); + ULONG nPos; - try - { - switch( hb_CheckSpanMode( szFile ) ) + if( szPassword ) + myzip.SetPassword( szPassword ); + + if( pProgress && HB_IS_BLOCK( pProgress ) ) { - case 0: - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); - break; - - case -1: - szZip.SetSegmCallback( &span ); - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); - break; - - case -2: - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 1 ); - break; - - default: - iReturn = false; - } - } - catch( CZipException ) - {} - - if( iReturn ) - { - int iCause; - - if( szPassWord != NULL ) - szZip.SetPassword( szPassWord ); - - if( pbyBuffer ) - { - if( hb_stricmp( pbyBuffer, ".\\" ) == 0 ) - hb_fsCurDirBuff( 0, ( BYTE * ) szPath, _POSIX_PATH_MAX + 1 ); - else - hb_strncpy( szPath, pbyBuffer, _POSIX_PATH_MAX ); - - szZip.SetRootPath( szPath ); + s_hbzaSettings.pProgressBlock = pProgress; + myzip.SetCallback( &cb_Action ); } - for( iCause = 1; iCause <= ( int ) hb_arrayLen( pSelArray ); iCause++ ) + hb_strncpy( pszPath, pbyBuffer && strcmp( pbyBuffer, ".\\" ) ? pbyBuffer : "", _POSIX_PATH_MAX ); + + myzip.SetRootPath( pszPath ); + + for( nPos = 1; nPos <= hb_arrayLen( pSelArray ); nPos++ ) { - LPCTSTR lpFiletoExtract = hb_arrayGetC( pSelArray, iCause ); - ULONG ulCount = szZip.FindFile( lpFiletoExtract, false ); + ZIP_INDEX_TYPE nZipFPos = myzip.FindFile( ( LPCTSTR ) hb_arrayGetCPtr( pSelArray, nPos ), false ); - if( ulCount == ( ULONG ) -1 ) - ulCount = szZip.FindFile( lpFiletoExtract, true ); + if( nZipFPos == ( ZIP_INDEX_TYPE ) -1 ) + nZipFPos = myzip.FindFile( ( LPCTSTR ) hb_arrayGetCPtr( pSelArray, nPos ), true ); + if( nZipFPos != ( ZIP_INDEX_TYPE ) -1 ) { CZipFileHeader fh; - szZip.GetFileInfo( fh, ( WORD ) ulCount ); + myzip.GetFileInfo( fh, nZipFPos ); if( pBlock && HB_IS_BLOCK( pBlock ) ) { - PHB_ITEM FileName = hb_itemPutC( NULL, ( char * ) ( LPCTSTR ) fh.GetFileName() ); - PHB_ITEM FilePos = hb_itemPutNI( NULL, iCause ); - hb_vmEvalBlockV( pBlock, 2, FileName, FilePos ); - hb_itemRelease( FileName ); - hb_itemRelease( FilePos ); + PHB_ITEM pFileName = hb_itemPutC( NULL, ( char * ) ( LPCTSTR ) fh.GetFileName() ); + PHB_ITEM pFilePos = hb_itemPutNI( NULL, nPos ); + hb_vmEvalBlockV( pBlock, 2, pFileName, pFilePos ); + hb_itemRelease( pFileName ); + hb_itemRelease( pFilePos ); } try { - szZip.ExtractFile( ( WORD ) ulCount, ( LPCTSTR ) szPath, lWithPath ? true : false, NULL, 65536 ); + myzip.ExtractFile( nZipFPos, ( LPCTSTR ) pszPath, lWithPath ? true : false, NULL, 65536 ); } catch( ... ) { - iReturn = false; - szZip.CloseFile( NULL, true ); + bReturn = FALSE; + myzip.CloseFile( NULL, true ); } } - - if( lpFiletoExtract ) - hb_xfree( ( void * ) lpFiletoExtract ); } + + hb_xfree( pszPath ); + + myzip.Close(); } - szZip.Close(); - - hb_xfree( szPath ); - - return ( int ) iReturn; + return bReturn; } - -int hb_UnzipSelIndex( char * szFile, PHB_ITEM pBlock, BOOL lWithPath, char * szPassWord, char * szPath, PHB_ITEM pSelArray, PHB_ITEM pProgress ) +BOOL hb_UnzipSelIndex( char * szFile, PHB_ITEM pBlock, BOOL lWithPath, char * szPassword, char * pszPath, PHB_ITEM pSelArray, PHB_ITEM pProgress ) { - bool iReturn = true; + CZipArchive myzip; + CHBZipSegmCallback cb_Segm; + BOOL bReturn = hb_zipopenread( &myzip, &cb_Segm, szFile ); - CZipArchive szZip; - SegmCallback span; - SegmActionCallback spanac; - - if( pProgress && HB_IS_BLOCK( pProgress ) ) + if( bReturn ) { - s_hbzaSettings.pProgressBlock = pProgress; - szZip.SetCallback( &spanac ); - } + CHBZipActionCallback cb_Action; + ULONG nPos; - try - { - switch( hb_CheckSpanMode( szFile ) ) + if( szPassword ) + myzip.SetPassword( szPassword ); + + if( pProgress && HB_IS_BLOCK( pProgress ) ) { - case 0: - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); - break; - - case -1: - szZip.SetSegmCallback( &span ); - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); - break; - - case -2: - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 1 ); - break; - - default: - iReturn = false; + s_hbzaSettings.pProgressBlock = pProgress; + myzip.SetCallback( &cb_Action ); } - } - catch( CZipException ) - {} - if( iReturn ) - { - int iCause; - - if( szPassWord ) - szZip.SetPassword( szPassWord ); - - for( iCause = 0; iCause <= ( int ) hb_arrayLen( pSelArray ); iCause++ ) + for( nPos = 0; nPos <= hb_arrayLen( pSelArray ); nPos++ ) { - ULONG ulCount = hb_arrayGetNI( pSelArray, iCause ) - 1; + ZIP_INDEX_TYPE nZipFPos = ( ZIP_INDEX_TYPE ) hb_arrayGetNL( pSelArray, nPos ) - 1; CZipFileHeader fh; - szZip.GetFileInfo( fh, ( WORD ) ulCount ); + myzip.GetFileInfo( fh, nZipFPos ); if( pBlock && HB_IS_BLOCK( pBlock ) ) { - PHB_ITEM FileName = hb_itemPutC( NULL, ( char * ) ( LPCTSTR ) fh.GetFileName() ); - hb_vmEvalBlockV( pBlock, 1, FileName ); - hb_itemRelease( FileName ); + PHB_ITEM pFileName = hb_itemPutC( NULL, ( char * ) ( LPCTSTR ) fh.GetFileName() ); + hb_vmEvalBlockV( pBlock, 1, pFileName ); + hb_itemRelease( pFileName ); } try { - szZip.ExtractFile( ( WORD ) ulCount, ( LPCTSTR ) szPath, lWithPath ? true : false, NULL, 65536 ); + myzip.ExtractFile( nZipFPos, ( LPCTSTR ) pszPath, lWithPath ? true : false, NULL, 65536 ); } catch( ... ) { - iReturn = false; - szZip.CloseFile( NULL, true ); + bReturn = FALSE; + myzip.CloseFile( NULL, true ); } } + + myzip.Close(); } - szZip.Close(); - - return ( int ) iReturn; -} - -void hb_SetZipBuff( int a, int b, int c ) -{ - s_hbzaSettings.iWrite = HB_MIN( a, 65535 ); - s_hbzaSettings.iExtract = HB_MIN( b, 16384 ); - s_hbzaSettings.iRead = HB_MIN( c, 32768 ); -} - -void hb_SetZipComment( char * szComment ) -{ - s_hbzaSettings.pszComment = hb_strdup( szComment ); -} - -void hb_SetZipReadOnly( int iRead ) -{ - s_hbzaSettings.iReadOnly = iRead; -} - -char * hb_GetZipComment( char * szFile ) -{ - char * szTemp; - bool iReturn = true; - - CZipArchive szZip; - SegmCallback span; - - try - { - switch( hb_CheckSpanMode( szFile ) ) - { - case 0: - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); - break; - - case -1: - szZip.SetSegmCallback( &span ); - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); - break; - - case -2: - szZip.Open( szFile, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 1 ); - break; - - default: - iReturn = false; - } - } - catch( CZipException ) - {} - - szTemp = hb_strdup( iReturn ? ( const char * ) szZip.GetGlobalComment() : "" ); - - szZip.Close(); - - return szTemp; + return bReturn; } BOOL hb_TransferFilesFromzip( char * szSource, char * szDest, PHB_ITEM pArray ) { - CZipArchive szZSource; - CZipArchive szZDest; + CZipArchive myzipSource; + CZipArchive myzipDest; CZipStringArray aFiles; - BOOL bReturn = TRUE; BOOL bReturn1 = TRUE; + BOOL bReturn2 = TRUE; try { switch( hb_CheckSpanMode( szSource ) ) { case 0: - szZSource.Open( szSource, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); - break; - - case -1: - case -2: -/* default: */ - bReturn = FALSE; - } - } - catch( CZipException ) - {} - - try - { - switch( hb_CheckSpanMode( szDest ) ) - { - case 0: - szZDest.Open( szDest, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); + myzipSource.Open( szSource, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); break; case -1: @@ -1000,17 +664,34 @@ BOOL hb_TransferFilesFromzip( char * szSource, char * szDest, PHB_ITEM pArray ) catch( CZipException ) {} - if( bReturn && bReturn1 ) + try { - ULONG ulCount; + switch( hb_CheckSpanMode( szDest ) ) + { + case 0: + myzipDest.Open( szDest, s_hbzaSettings.iReadOnly ? CZipArchive::zipOpenReadOnly : CZipArchive::zipOpen, 0 ); + break; - for( ulCount = 1; ulCount <= ( ULONG ) hb_arrayLen( pArray ); ulCount++ ) - aFiles.Add( ( char * ) hb_arrayGetCPtr( pArray, ulCount ) ); + case -1: + case -2: +/* default: */ + bReturn2 = FALSE; + } + } + catch( CZipException ) + {} - szZDest.GetFromArchive( szZSource, aFiles, false ); + if( bReturn1 && bReturn2 ) + { + ULONG nPos; - szZDest.Close(); - szZSource.Close(); + for( nPos = 1; nPos <= hb_arrayLen( pArray ); nPos++ ) + aFiles.Add( hb_arrayGetCPtr( pArray, nPos ) ); + + myzipDest.GetFromArchive( myzipSource, aFiles, false ); + + myzipDest.Close(); + myzipSource.Close(); return TRUE; } @@ -1018,17 +699,15 @@ BOOL hb_TransferFilesFromzip( char * szSource, char * szDest, PHB_ITEM pArray ) return FALSE; } -int hb_CompressFile( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassWord, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ) +BOOL hb_CompressFile( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassword, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ) { - char * szFileLower = hb_strdup( ( char * ) szFile ); - BOOL bFileExist = hb_fsFile( ( BYTE * ) szFile ); + CZipArchive myzip; BOOL bReturn = TRUE; + BOOL bFileExist = hb_fsFileExists( szFile ); + char * szFileLower = hb_strdup( ( char * ) szFile ); - CZipArchive szZip; - SegmCallbackc span; - SegmActionCallbackc spanac; - - szZip.SetSegmCallback( &span ); + CHBZipSegmCallback cb_Segm; + myzip.SetSegmCallback( &cb_Segm ); #ifdef HB_OS_WIN_32 hb_strLower( szFileLower, strlen( szFileLower ) ); @@ -1037,9 +716,9 @@ int hb_CompressFile( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pB try { if( ( bFileExist && bOverWrite ) || !bFileExist ) - szZip.Open( szFile, CZipArchive::zipCreate, 0 ); + myzip.Open( szFile, CZipArchive::zipCreate, 0 ); else - szZip.Open( szFile, CZipArchive::zipOpen, 0 ); + myzip.Open( szFile, CZipArchive::zipOpen, 0 ); } catch( CZipException ) { @@ -1050,50 +729,52 @@ int hb_CompressFile( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pB if( bReturn ) { - ULONG ulCount; + CHBZipActionCallback cb_Action; + ULONG nPos; - if( szPassWord ) - szZip.SetPassword( szPassWord ); + if( szPassword ) + myzip.SetPassword( szPassword ); if( s_hbzaSettings.pszComment ) { - szZip.SetGlobalComment( s_hbzaSettings.pszComment ); + myzip.SetGlobalComment( s_hbzaSettings.pszComment ); hb_xfree( s_hbzaSettings.pszComment ); } if( pProgress && HB_IS_BLOCK( pProgress ) ) { s_hbzaSettings.pProgressBlock = pProgress; - szZip.SetCallback( &spanac ); + myzip.SetCallback( &cb_Action ); } - for( ulCount = 1; ulCount <= hb_arrayLen( pArray ); ulCount++ ) + for( nPos = 1; nPos <= hb_arrayLen( pArray ); nPos++ ) { - const char * szDummy = ( char * ) hb_arrayGetCPtr( pArray, ulCount ); - char * szDummyLower = hb_strdup( ( char * ) szDummy ); + const char * szDummy = hb_arrayGetCPtr( pArray, nPos ); + char * szDummyLower = hb_strdup( szDummy ); #ifdef HB_OS_WIN_32 hb_strLower( szDummyLower, strlen( szDummyLower ) ); #endif /* Prevent adding current archive file. */ + /* TOFIX: strstr() is not suitable for portable filename comparison. */ if( ! strstr( szFileLower, szDummyLower ) && ! strstr( szDummyLower, szFileLower ) ) { - if( hb_GetCurrentFileSize( szDummy ) != F_ERROR ) + if( hb_fsFileExists( szDummy ) ) { if( pBlock && HB_IS_BLOCK( pBlock ) ) { - PHB_ITEM FileName = hb_itemPutC( NULL, szDummy ); - PHB_ITEM FilePos = hb_itemPutNI( NULL, ulCount ); - hb_vmEvalBlockV( pBlock, 2, FileName, FilePos ); - hb_itemRelease( FileName ); - hb_itemRelease( FilePos ); + PHB_ITEM pFileName = hb_itemPutC( NULL, szDummy ); + PHB_ITEM pFilePos = hb_itemPutNI( NULL, nPos ); + hb_vmEvalBlockV( pBlock, 2, pFileName, pFilePos ); + hb_itemRelease( pFileName ); + hb_itemRelease( pFilePos ); } try { - szZip.AddNewFile( szDummy, iCompLevel, ( bDrive || bPath ) ? true : false, CZipArchive::zipsmSafeSmart, 65536 ); + myzip.AddNewFile( szDummy, iCompLevel, ( bDrive || bPath ) ? true : false, CZipArchive::zipsmSafeSmart, 65536 ); } catch( ... ) {} @@ -1108,7 +789,7 @@ int hb_CompressFile( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pB try { - szZip.Close(); + myzip.Close(); } catch( CZipException ) { @@ -1117,26 +798,24 @@ int hb_CompressFile( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pB catch( ... ) {} - return ( int ) bReturn; + return bReturn; } -int hb_CompressFileStd( char * szFile, char * szFiletoCompress, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassWord, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ) +BOOL hb_CompressFileStd( char * szFile, char * szFiletoCompress, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassword, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ) { + CZipArchive myzip; BOOL bReturn = TRUE; - BOOL bFileExist = hb_fsFile( ( BYTE * ) szFile ); + BOOL bFileExist = hb_fsFileExists( szFile ); - CZipArchive szZip; - SegmCallbackc span; - SegmActionCallbackc spanac; - - szZip.SetSegmCallback( &span ); + CHBZipSegmCallback cb_Segm; + myzip.SetSegmCallback( &cb_Segm ); try { if( ( bFileExist && bOverWrite ) || !bFileExist ) - szZip.Open( szFile, CZipArchive::zipCreate, 0 ); + myzip.Open( szFile, CZipArchive::zipCreate, 0 ); else - szZip.Open( szFile, CZipArchive::zipOpen, 0 ); + myzip.Open( szFile, CZipArchive::zipOpen, 0 ); } catch( CZipException ) { @@ -1145,33 +824,35 @@ int hb_CompressFileStd( char * szFile, char * szFiletoCompress, int iCompLevel, if( bReturn ) { - if( szPassWord ) - szZip.SetPassword( szPassWord ); + CHBZipActionCallback cb_Action; + + if( szPassword ) + myzip.SetPassword( szPassword ); if( s_hbzaSettings.pszComment ) { - szZip.SetGlobalComment( s_hbzaSettings.pszComment ); + myzip.SetGlobalComment( s_hbzaSettings.pszComment ); hb_xfree( s_hbzaSettings.pszComment ); } if( pProgress && HB_IS_BLOCK( pProgress ) ) { s_hbzaSettings.pProgressBlock = pProgress; - szZip.SetCallback( &spanac ); + myzip.SetCallback( &cb_Action ); } try { - if( hb_GetCurrentFileSize( szFiletoCompress ) != F_ERROR ) + if( hb_fsFileExists( szFiletoCompress ) ) { if( pBlock && HB_IS_BLOCK( pBlock ) ) { - PHB_ITEM FileName = hb_itemPutC( NULL, szFiletoCompress ); - hb_vmEvalBlockV( pBlock, 1, FileName ); - hb_itemRelease( FileName ); + PHB_ITEM pFileName = hb_itemPutC( NULL, szFiletoCompress ); + hb_vmEvalBlockV( pBlock, 1, pFileName ); + hb_itemRelease( pFileName ); } - if( ! szZip.AddNewFile( szFiletoCompress, iCompLevel, ( bDrive || bPath ) ? true : false, CZipArchive::zipsmSafeSmart, 65536 ) ) + if( ! myzip.AddNewFile( szFiletoCompress, iCompLevel, ( bDrive || bPath ) ? true : false, CZipArchive::zipsmSafeSmart, 65536 ) ) bReturn = FALSE; } } @@ -1181,7 +862,7 @@ int hb_CompressFileStd( char * szFile, char * szFiletoCompress, int iCompLevel, try { - szZip.Close(); + myzip.Close(); } catch( CZipException ) { @@ -1190,29 +871,26 @@ int hb_CompressFileStd( char * szFile, char * szFiletoCompress, int iCompLevel, catch( ... ) {} - return ( int ) bReturn; + return bReturn; } -int hb_CmpTdSpanStd( char * szFile, char * szFiletoCompress, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassWord, int iSpanSize, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ) +BOOL hb_CmpPkSpan( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassword, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ) { + CZipArchive myzip; BOOL bReturn = TRUE; - BOOL bFileExist = hb_fsFile( ( BYTE * ) szFile ); + BOOL bFileExist = hb_fsFileExists( szFile ); - CZipArchive szZip; - SegmCallbackc span; - SegmActionCallbackc spanac; + CHBZipSegmCallback cb_Segm; + myzip.SetSegmCallback( &cb_Segm ); - szZip.SetSegmCallback( &span ); - - if( iSpanSize == 0 ) - iSpanSize = 1457664; + bDrive = FALSE; try { if( ( bFileExist && bOverWrite ) || !bFileExist ) - szZip.Open( szFile, CZipArchive::zipCreateSegm, iSpanSize ); + myzip.Open( szFile, CZipArchive::zipCreateSegm, 0 ); else - return ( int ) false; + bReturn = FALSE; } catch( CZipException ) { @@ -1221,45 +899,49 @@ int hb_CmpTdSpanStd( char * szFile, char * szFiletoCompress, int iCompLevel, PHB catch( ... ) {} - if( szPassWord ) - szZip.SetPassword( szPassWord ); - - if( s_hbzaSettings.pszComment ) - { - szZip.SetGlobalComment( s_hbzaSettings.pszComment ); - hb_xfree( s_hbzaSettings.pszComment ); - } - - if( pProgress && HB_IS_BLOCK( pProgress ) ) - { - s_hbzaSettings.pProgressBlock = pProgress; - szZip.SetCallback( &spanac ); - } - if( bReturn ) { - try - { - if( szPassWord ) - szZip.SetPassword( szPassWord ); + CHBZipActionCallback cb_Action; + ULONG nPos; + if( szPassword ) + myzip.SetPassword( szPassword ); + + if( s_hbzaSettings.pszComment ) + { + myzip.SetGlobalComment( s_hbzaSettings.pszComment ); + hb_xfree( s_hbzaSettings.pszComment ); + } + + if( pProgress && HB_IS_BLOCK( pProgress ) ) + { + s_hbzaSettings.pProgressBlock = pProgress; + myzip.SetCallback( &cb_Action ); + } + + for( nPos = 1; nPos <= hb_arrayLen( pArray ); nPos++ ) + { if( pBlock && HB_IS_BLOCK( pBlock ) ) { - PHB_ITEM FileName = hb_itemPutC( NULL, szFiletoCompress ); - hb_vmEvalBlockV( pBlock, 1, FileName ); - hb_itemRelease( FileName ); + PHB_ITEM pFileName = hb_itemPutC( NULL, hb_arrayGetCPtr( pArray, nPos ) ); + PHB_ITEM pFilePos = hb_itemPutNI( NULL, nPos ); + hb_vmEvalBlockV( pBlock, 2, pFileName, pFilePos ); + hb_itemRelease( pFileName ); + hb_itemRelease( pFilePos ); } - - if( ! szZip.AddNewFile( szFiletoCompress, iCompLevel, ( bDrive || bPath ) ? true : false, CZipArchive::zipsmSafeSmart, 65536 ) ) - bReturn = FALSE; + + try + { + myzip.AddNewFile( hb_arrayGetCPtr( pArray, nPos ), iCompLevel, ( bDrive || bPath ) ? true : false, CZipArchive::zipsmSafeSmart, 65536 ); + } + catch( ... ) + {} } - catch( ... ) - {} } try { - szZip.Close(); + myzip.Close(); } catch( CZipException ) { @@ -1268,19 +950,17 @@ int hb_CmpTdSpanStd( char * szFile, char * szFiletoCompress, int iCompLevel, PHB catch( ... ) {} - return ( int ) bReturn; + return bReturn; } -int hb_CmpTdSpan( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassWord, int iSpanSize, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ) +BOOL hb_CmpTdSpan( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassword, long iSpanSize, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ) { + CZipArchive myzip; BOOL bReturn = TRUE; - BOOL bFileExist = hb_fsFile( ( BYTE * ) szFile ); + BOOL bFileExist = hb_fsFileExists( szFile ); - CZipArchive szZip; - SegmCallbackc span; - SegmActionCallbackc spanac; - - szZip.SetSegmCallback( &span ); + CHBZipSegmCallback cb_Segm; + myzip.SetSegmCallback( &cb_Segm ); if( iSpanSize == 0 ) iSpanSize = 1457664; @@ -1288,12 +968,9 @@ int hb_CmpTdSpan( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBloc try { if( ( bFileExist && bOverWrite ) || !bFileExist ) - szZip.Open( szFile, CZipArchive::zipCreateSegm, iSpanSize ); + myzip.Open( szFile, CZipArchive::zipCreateSegm, iSpanSize ); else - { bReturn = FALSE; - return ( int ) bReturn; - } } catch( CZipException ) { @@ -1302,43 +979,44 @@ int hb_CmpTdSpan( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBloc catch( ... ) {} - /*if( ! bReturn )*/ + if( bReturn ) { - ULONG ulCount; + CHBZipActionCallback cb_Action; + ULONG nPos; - if( szPassWord ) - szZip.SetPassword( szPassWord ); + if( szPassword ) + myzip.SetPassword( szPassword ); if( s_hbzaSettings.pszComment ) { - szZip.SetGlobalComment( s_hbzaSettings.pszComment ); + myzip.SetGlobalComment( s_hbzaSettings.pszComment ); hb_xfree( s_hbzaSettings.pszComment ); } if( pProgress && HB_IS_BLOCK( pProgress ) ) { s_hbzaSettings.pProgressBlock = pProgress; - szZip.SetCallback( &spanac ); + myzip.SetCallback( &cb_Action ); } - for( ulCount = 1; ulCount <= hb_arrayLen( pArray ); ulCount++ ) + for( nPos = 1; nPos <= hb_arrayLen( pArray ); nPos++ ) { - const char * szDummy = ( char * ) hb_arrayGetCPtr( pArray, ulCount ); + const char * szDummy = hb_arrayGetCPtr( pArray, nPos ); - if( hb_GetCurrentFileSize( szDummy ) != F_ERROR ) + if( hb_fsFileExists( szDummy ) ) { if( pBlock && HB_IS_BLOCK( pBlock ) ) { - PHB_ITEM FileName = hb_itemPutC( NULL, szDummy ); - PHB_ITEM FilePos = hb_itemPutNI( NULL, ulCount ); - hb_vmEvalBlockV( pBlock, 2, FileName, FilePos ); - hb_itemRelease( FileName ); - hb_itemRelease( FilePos ); + PHB_ITEM pFileName = hb_itemPutC( NULL, szDummy ); + PHB_ITEM pFilePos = hb_itemPutNI( NULL, nPos ); + hb_vmEvalBlockV( pBlock, 2, pFileName, pFilePos ); + hb_itemRelease( pFileName ); + hb_itemRelease( pFilePos ); } try { - szZip.AddNewFile( szDummy, iCompLevel, ( bDrive || bPath ) ? true : false, CZipArchive::zipsmSafeSmart, 65536 ); + myzip.AddNewFile( szDummy, iCompLevel, ( bDrive || bPath ) ? true : false, CZipArchive::zipsmSafeSmart, 65536 ); } catch( ... ) {} @@ -1348,7 +1026,7 @@ int hb_CmpTdSpan( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBloc try { - szZip.Close(); + myzip.Close(); } catch( CZipException ) { @@ -1357,7 +1035,7 @@ int hb_CmpTdSpan( char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBloc catch( ... ) {} - return ( int ) bReturn; + return bReturn; } #ifdef __cplusplus