From b4d9c85b4cc8e20a04f5e26a29a7170a9f2086ca Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 23 Jun 2008 22:22:29 +0000 Subject: [PATCH] 2008-06-24 00:21 UTC+0200 Viktor Szakats (harbour.01 syenar hu) + contrib/hbziparch/tests + contrib/hbziparch/tests/bld_b32.bat + contrib/hbziparch/tests/bld_vc.bat + contrib/hbziparch/tests/zipa.prg + contrib/hbziparch/tests/unzipa.prg * contrib/hbziparch/hbziparc.c * contrib/hbziparch/hbzipcom.cpp * contrib/hbziparch/hbcomprs.c * contrib/hbziparch/hbzipnew.cpp * Further cleanup. ! Several potential buffer overruns fixed. (there are still quite some left) + Added simple tests. --- harbour/ChangeLog | 15 +++ harbour/contrib/hbziparch/hbcomprs.c | 20 ++-- harbour/contrib/hbziparch/hbziparc.c | 67 ++++++------ harbour/contrib/hbziparch/hbzipcom.cpp | 110 +++----------------- harbour/contrib/hbziparch/hbzipnew.cpp | 36 +------ harbour/contrib/hbziparch/tests/bld_b32.bat | 14 +++ harbour/contrib/hbziparch/tests/bld_vc.bat | 14 +++ harbour/contrib/hbziparch/tests/unzipa.prg | 9 ++ harbour/contrib/hbziparch/tests/zipa.prg | 9 ++ 9 files changed, 115 insertions(+), 179 deletions(-) create mode 100644 harbour/contrib/hbziparch/tests/bld_b32.bat create mode 100644 harbour/contrib/hbziparch/tests/bld_vc.bat create mode 100644 harbour/contrib/hbziparch/tests/unzipa.prg create mode 100644 harbour/contrib/hbziparch/tests/zipa.prg diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 895620fc9a..9131d1c44c 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,21 @@ 2008-12-31 13:59 UTC+0100 Foo Bar */ +2008-06-24 00:21 UTC+0200 Viktor Szakats (harbour.01 syenar hu) + + contrib/hbziparch/tests + + contrib/hbziparch/tests/bld_b32.bat + + contrib/hbziparch/tests/bld_vc.bat + + contrib/hbziparch/tests/zipa.prg + + contrib/hbziparch/tests/unzipa.prg + * contrib/hbziparch/hbziparc.c + * contrib/hbziparch/hbzipcom.cpp + * contrib/hbziparch/hbcomprs.c + * contrib/hbziparch/hbzipnew.cpp + * Further cleanup. + ! Several potential buffer overruns fixed. + (there are still quite some left) + + Added simple tests. + 2008-06-23 20:06 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * include/hbextern.ch * HB_GETREADVAR() added. diff --git a/harbour/contrib/hbziparch/hbcomprs.c b/harbour/contrib/hbziparch/hbcomprs.c index f98444f6d1..3a22f9d93f 100644 --- a/harbour/contrib/hbziparch/hbcomprs.c +++ b/harbour/contrib/hbziparch/hbcomprs.c @@ -99,30 +99,28 @@ static void hb_fsGrabDirectory( PHB_ITEM pDir, const char * szDirSpec, USHORT ui } while( hb_fsFindNext( ffind ) ); - hb_fsFindClose( ffind ); hb_itemRelease( pSubarray ); + hb_fsFindClose( ffind ); } } void HB_EXPORT hb_fsDirectory( PHB_ITEM pDir, char* szSkleton, char* szAttributes, BOOL bDirOnly, BOOL bFullPath ) { - USHORT uiMask, uiMaskNoLabel; + USHORT uiMask; + USHORT uiMaskNoLabel; BYTE *szDirSpec; /* #if defined(__MINGW32__) || ( defined(_MSC_VER) && _MSC_VER >= 910 ) PHB_ITEM pEightDotThree = hb_param( 3, HB_IT_LOGICAL ); - BOOL bEightDotThree; - - // Do we want 8.3 support? - bEightDotThree = ( pEightDotThree ? hb_itemGetL( pEightDotThree ) : FALSE ); + BOOL bEightDotThree = pEightDotThree ? hb_itemGetL( pEightDotThree ) : FALSE; // Do we want 8.3 support? #endif */ PHB_FNAME pDirSpec = NULL; BOOL bAlloc = FALSE; - /* Get the passed attributes and convert them to Harbour Flags */ + /* Get the passed attributes and convert them to Harbour Flags */ uiMask = HB_FA_ARCHIVE | HB_FA_READONLY | HB_FA_NORMAL @@ -141,9 +139,7 @@ void HB_EXPORT hb_fsDirectory( PHB_ITEM pDir, char* szSkleton, char* szAttribute hb_arrayNew( pDir, 0 ); if ( bDirOnly ) - { szAttributes = "D"; - } if( szAttributes && strlen( szAttributes ) > 0 ) { @@ -155,13 +151,9 @@ void HB_EXPORT hb_fsDirectory( PHB_ITEM pDir, char* szSkleton, char* szAttribute } if ( szSkleton && strlen( szSkleton ) > 0 ) - { szDirSpec = hb_fsNameConv( ( BYTE * ) szSkleton, &bAlloc ); - } else - { szDirSpec = (BYTE *) OS_FILE_MASK; - } if( bDirOnly || bFullPath ) { @@ -185,7 +177,7 @@ void HB_EXPORT hb_fsDirectory( PHB_ITEM pDir, char* szSkleton, char* szAttribute hb_fsGrabDirectory( pDir, (const char*) szDirSpec, uiMaskNoLabel, pDirSpec, bFullPath, bDirOnly ); } - if ( pDirSpec != NULL ) + if( pDirSpec ) hb_xfree( pDirSpec ); if( bAlloc ) diff --git a/harbour/contrib/hbziparch/hbziparc.c b/harbour/contrib/hbziparch/hbziparc.c index 22f15cbb5a..7bc06f35fe 100644 --- a/harbour/contrib/hbziparch/hbziparc.c +++ b/harbour/contrib/hbziparch/hbziparc.c @@ -205,16 +205,12 @@ static void ZipCreateExclude( PHB_ITEM pExclude ) s_ExcludeFile = hb_itemArrayNew(0); if( pExclude == NULL ) - { return; - } if ( HB_IS_STRING( pExclude ) ) { if ( hb_itemGetCLen( pExclude ) == 0 ) - { return; - } if ( strchr( hb_itemGetCPtr( pExclude ) , '*') != NULL || strchr( hb_itemGetCPtr( pExclude ), '?' ) != NULL ) { @@ -263,9 +259,7 @@ static void ZipCreateExclude( PHB_ITEM pExclude ) WildFile= hb_itemNew( NULL ); if ( ufx == 0 ) - { return; - } for ( ux = 0 ; ux < ufx ; ux ++ ) { @@ -578,9 +572,7 @@ HB_FUNC( HB_ZIPFILE ) strcat( szFile, hb_parc( 1 ) ) ; } else - { - strcpy( szFile, hb_parc( 1 ) ); - } + hb_strncpy( szFile, hb_parc( 1 ), sizeof( szFile ) - 1 ); hb_xfree( pCurDir) ; szZipFileName = hb___CheckFile( szFile ); @@ -592,10 +584,10 @@ HB_FUNC( HB_ZIPFILE ) s_FileToZip, ISNUM( 3 ) ? hb_parni( 3 ) : ( -1 ), hb_param( 4, HB_IT_BLOCK ), - ISLOG( 5 ) ? hb_parl( 5 ) : 0, + ISLOG( 5 ) ? hb_parl( 5 ) : FALSE, ISCHAR( 6 ) ? hb_parc( 6 ) : NULL, - ISLOG( 7 ) ? hb_parl( 7 ) : 0, - ISLOG( 8 ) ? hb_parl( 8 ) : 0, + ISLOG( 7 ) ? hb_parl( 7 ) : FALSE, + ISLOG( 8 ) ? hb_parl( 8 ) : FALSE, pProgress ); ResetAttribs(); hb_itemRelease( pProgress ); @@ -616,12 +608,13 @@ HB_FUNC( HB_GETFILESINZIP ) char szFile[ _POSIX_PATH_MAX ]; char *szZipFileName; PHB_ITEM pArray; - strcpy( szFile, hb_parc( 1 ) ); + + hb_strncpy( szFile, hb_parc( 1 ), sizeof( szFile ) - 1 ); szZipFileName = hb___CheckFile( szFile ); pArray = hb___GetFileNamesFromZip( szZipFileName, - ISLOG( 2 ) ? hb_parl( 2 ) : 0 ); + ISLOG( 2 ) ? hb_parl( 2 ) : FALSE ); hb_itemReturn( pArray ); hb_itemRelease( pArray ) ; @@ -642,7 +635,8 @@ HB_FUNC( HB_GETFILECOUNT ) { char szFile[ _POSIX_PATH_MAX ]; char *szZipFileName; - strcpy( szFile, hb_parc( 1 ) ); + + hb_strncpy( szFile, hb_parc( 1 ), sizeof( szFile ) - 1 ); szZipFileName = hb___CheckFile( szFile ); @@ -792,9 +786,8 @@ HB_FUNC( HB_ZIPFILEBYTDSPAN ) strcat( szFile, hb_parc( 1 ) ) ; } else - { - strcpy( szFile, hb_parc( 1 ) ); - } + hb_strncpy( szFile, hb_parc( 1 ), sizeof( szFile ) - 1 ); + hb_xfree( pCurDir ) ; /* by JGS */ szZipFileName = hb___CheckFile( szFile ); @@ -805,11 +798,11 @@ HB_FUNC( HB_ZIPFILEBYTDSPAN ) s_FileToZip, ISNUM( 3 ) ? hb_parni( 3 ) : ( -1 ), hb_param( 4, HB_IT_BLOCK ), - ISLOG( 5 ) ? hb_parl( 5 ) : 0, + ISLOG( 5 ) ? hb_parl( 5 ) : FALSE, ISCHAR( 6 ) ? hb_parc( 6 ) : NULL, ISNUM( 7 ) ? hb_parni( 7 ) : 0, - ISLOG( 8 ) ? hb_parl( 8 ) : 0, - ISLOG( 9 ) ? hb_parl( 9 ) : 0, + ISLOG( 8 ) ? hb_parl( 8 ) : FALSE, + ISLOG( 9 ) ? hb_parl( 9 ) : FALSE, pProgress ); ResetAttribs(); hb_itemRelease( pProgress ); @@ -970,9 +963,8 @@ HB_FUNC( HB_ZIPFILEBYPKSPAN ) strcat( szFile, hb_parc( 1 ) ) ; } else - { - strcpy( szFile, hb_parc( 1 ) ); - } + hb_strncpy( szFile, hb_parc( 1 ), sizeof( szFile ) - 1 ); + hb_xfree( pCurDir ); /* by JGS */ szZipFileName = hb___CheckFile( szFile ); @@ -984,10 +976,10 @@ HB_FUNC( HB_ZIPFILEBYPKSPAN ) s_FileToZip, ISNUM( 3 ) ? hb_parni( 3 ) : ( -1 ), hb_param( 4, HB_IT_BLOCK ), - ISLOG( 5 ) ? hb_parl( 5 ) : 0, + ISLOG( 5 ) ? hb_parl( 5 ) : FALSE, ISCHAR( 6 ) ? hb_parc( 6 ) : NULL, - ISLOG( 7 ) ? hb_parl( 7 ) : 0, - ISLOG( 8 ) ? hb_parl( 8 ) : 0, + ISLOG( 7 ) ? hb_parl( 7 ) : FALSE, + ISLOG( 8 ) ? hb_parl( 8 ) : FALSE, pProgress ); ResetAttribs(); hb_itemRelease( pProgress ); @@ -1082,7 +1074,8 @@ HB_FUNC( HB_UNZIPFILE ) pCurDir = ( BYTE * )hb_xstrcpy( NULL, OS_PATH_DELIMITER_STRING, ( const char * )hb_fsCurDir( 0 ) , NULL ); - strcpy( szFile, hb_parc( 1 ) ); + hb_strncpy( szFile, hb_parc( 1 ), sizeof( szFile ) - 1 ); + szZipFileName = hb___CheckFile( szFile ); s_UnzipFiles = hb_itemArrayNew(0); @@ -1125,7 +1118,7 @@ HB_FUNC( HB_UNZIPFILE ) PHB_ITEM pProgress = ISBLOCK( 7 ) ? hb_itemNew( hb_param( 7 , HB_IT_BLOCK ) ) : hb_itemNew( NULL ); bRet = hb_UnzipSel( szZipFileName, hb_param( 2, HB_IT_BLOCK ), - ISLOG( 3 ) ? hb_parl( 3 ) : 0, + ISLOG( 3 ) ? hb_parl( 3 ) : FALSE, ISCHAR( 4 ) ? hb_parc( 4 ) : NULL, ISCHAR( 5 ) ? hb_parc( 5 ) : ".\\", s_UnzipFiles, @@ -1234,7 +1227,7 @@ HB_FUNC( HB_ZIPDELETEFILES ) char *szZipFileName; int ulLen; - strcpy( szFile, hb_parc( 1 ) ); + hb_strncpy( szFile, hb_parc( 1 ), sizeof( szFile ) - 1 ); szZipFileName = hb___CheckFile( szFile ); hb___GetFileNamesFromZip( szZipFileName, TRUE ); @@ -1299,7 +1292,7 @@ HB_FUNC( HB_ZIPDELETEFILES ) { bRet = hb_DeleteSel( szZipFileName, s_DelZip, - ISLOG( 3 ) ? hb_parl( 3 ) : 0 ); + ISLOG( 3 ) ? hb_parl( 3 ) : FALSE ); } hb_xfree(szZipFileName); @@ -1360,7 +1353,7 @@ HB_FUNC( HB_ZIPTESTPK ) char szFile[ _POSIX_PATH_MAX ]; char *szZipFileName; - strcpy( szFile, hb_parc( 1 ) ); + hb_strncpy( szFile, hb_parc( 1 ), sizeof( szFile ) - 1 ); szZipFileName = hb___CheckFile( szFile ); hb_retni( hb_TestForPKS( szZipFileName ) ); @@ -1492,7 +1485,7 @@ HB_FUNC( HB_GETZIPCOMMENT ) * $ONELINER$ * Unzip a compressed file referenced by it number in the zipfile * $SYNTAX$ - * HB_UNZIPFILE( , , , , , + * HB_UNZIPFILEINDEX( , , , , , * | , ) ---> lCompress * $ARGUMENTS$ * Name of the zip file @@ -1567,7 +1560,7 @@ HB_FUNC( HB_UNZIPFILEINDEX ) DelZip = hb_itemArrayNew(0); - strcpy( szFile, hb_parc( 1 ) ); + hb_strncpy( szFile, hb_parc( 1 ), sizeof( szFile ) - 1 ); szZipFileName = hb___CheckFile( szFile ); hb___GetFileNamesFromZip( szZipFileName, TRUE ); @@ -1606,7 +1599,7 @@ HB_FUNC( HB_UNZIPFILEINDEX ) PHB_ITEM pProgress = ISBLOCK( 7 ) ? hb_itemNew( hb_param( 7 , HB_IT_BLOCK ) ) : hb_itemNew( NULL ); bRet = hb_UnzipSelIndex( szZipFileName, hb_param( 2, HB_IT_BLOCK ), - ISLOG( 3 ) ? hb_parl( 3 ) : 0, + ISLOG( 3 ) ? hb_parl( 3 ) : FALSE, ISCHAR( 4 ) ? hb_parc( 4 ) : NULL, hb_parc( 5 ), DelZip, @@ -1656,11 +1649,11 @@ HB_FUNC(HB_UNZIPALLFILE) char szFile[_POSIX_PATH_MAX]; char *szZipFile; PHB_ITEM pProgress = ISBLOCK( 7 ) ? hb_itemNew( hb_param( 7, HB_IT_BLOCK ) ) : hb_itemNew( NULL ); - strcpy(szFile, hb_parc(1)); + hb_strncpy( szFile, hb_parc( 1 ), sizeof( szFile ) - 1 ); szZipFile = hb___CheckFile(szFile); hb_retl( hb_UnzipAll( szZipFile, hb_param( 2, HB_IT_BLOCK), - ISLOG(3) ? hb_parl(3) : 0, + ISLOG(3) ? hb_parl(3) : FALSE, hb_parc(4), ISCHAR(5) ? hb_parc(5) : NULL, hb_param( 6, HB_IT_BLOCK ), diff --git a/harbour/contrib/hbziparch/hbzipcom.cpp b/harbour/contrib/hbziparch/hbzipcom.cpp index 3a39e1562b..7b456b5a47 100644 --- a/harbour/contrib/hbziparch/hbzipcom.cpp +++ b/harbour/contrib/hbziparch/hbzipcom.cpp @@ -75,7 +75,8 @@ class SpanActionCallbackc : public CZipActionCallback { bool Callback( int iProgress ) { - PHB_ITEM Disk = hb_itemPutNL(NULL, m_uTotalSoFar ), Total=hb_itemPutNL( NULL, m_uTotalToDo ); + PHB_ITEM Disk = hb_itemPutNL( NULL, m_uTotalSoFar ); + PHB_ITEM Total = hb_itemPutNL( NULL, m_uTotalToDo ); hb_vmEvalBlockV( hbza_pProgressInfo, 2, Disk,Total); @@ -91,7 +92,7 @@ static DWORD hb_GetCurrentFileSize( LPCTSTR szFile ) { DWORD dwFlags = FILE_ATTRIBUTE_ARCHIVE; HANDLE hFind; - WIN32_FIND_DATA hFilesFind; + WIN32_FIND_DATA hFilesFind; hFind = FindFirstFile( szFile, &hFilesFind ); @@ -100,36 +101,22 @@ static DWORD hb_GetCurrentFileSize( LPCTSTR szFile ) if ( dwFlags & hFilesFind.dwFileAttributes ) { if( hFilesFind.nFileSizeHigh>0 ) - { return ( ( hFilesFind.nFileSizeHigh*MAXDWORD )+hFilesFind.nFileSizeLow ); - } else - { return ( hFilesFind.nFileSizeLow ); - } - } } FindClose( hFind ); return ( DWORD ) -1; - } #elif defined( __GNUC__ ) { - USHORT ushbMask = 63; - USHORT usFileAttr = HB_FA_ARCHIVE; struct stat sStat; - if ( stat( szFile, &sStat ) != -1 ) - { - return sStat.st_size; - } - - return -1; + return stat( szFile, &sStat ) == -1 ? -1 : sStat.st_size; } - #endif int hb_CompressFile( char *szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char *szPassWord, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ) @@ -156,15 +143,10 @@ int hb_CompressFile( char *szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBl try { if( ( bFileExist && bOverWrite ) || !bFileExist ) - { szZip.Open( szFile, CZipArchive::zipCreate, 0 ); - } else - { szZip.Open( szFile, CZipArchive::zipOpen, 0 ); - } } - catch ( CZipException ) { bReturn = FALSE; @@ -175,10 +157,8 @@ int hb_CompressFile( char *szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBl if ( bReturn ) { - if ( szPassWord != NULL ) - { + if( szPassWord ) szZip.SetPassword( szPassWord ); - } if ( hbza_pZipI.szComment != NULL ) { @@ -223,14 +203,9 @@ int hb_CompressFile( char *szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBl try { if ( bPath && !bAdded ) - { szZip.AddNewFile( szDummy, iCompLevel, true, CZipArchive::zipsmSafeSmart, 65536 ); - // bAdded = TRUE; - } else if ( !bDrive && !bPath && !bAdded ) - { szZip.AddNewFile( szDummy, iCompLevel, false, CZipArchive::zipsmSafeSmart, 65536 ); - } } catch( ... ){} @@ -240,11 +215,11 @@ int hb_CompressFile( char *szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBl } } hb_xfree( szFileLower ) ; + try { szZip.Close( ); } - catch ( CZipException ) { bReturn = FALSE; @@ -270,11 +245,8 @@ int hb_CmpTdSpan( char *szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock szZip.SetSpanCallback( &span ); - - if ( iSpanSize == 0 ) - { + if( iSpanSize == 0 ) iSpanSize = 1457664; - } try { @@ -299,10 +271,8 @@ int hb_CmpTdSpan( char *szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock //if (! bReturn ) //{ - if ( szPassWord != NULL ) - { + if( szPassWord ) szZip.SetPassword( szPassWord ); - } if ( hbza_pZipI.szComment != NULL ) { @@ -337,17 +307,10 @@ int hb_CmpTdSpan( char *szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock try { - if ( bPath && !bAdded ) - { szZip.AddNewFile( szDummy, iCompLevel, true, CZipArchive::zipsmSafeSmart, 65536 ); - // bAdded = TRUE; - } else if ( !bDrive && !bPath && !bAdded ) - { szZip.AddNewFile( szDummy, iCompLevel, false, CZipArchive::zipsmSafeSmart, 65536 ); - } - } catch( ... ){} } @@ -358,7 +321,6 @@ int hb_CmpTdSpan( char *szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock { szZip.Close(); } - catch ( CZipException ) { bReturn = FALSE; @@ -386,15 +348,10 @@ int hb_CompressFileStd( char *szFile, char *szFiletoCompress, int iCompLevel, PH try { if( ( bFileExist && bOverWrite ) || !bFileExist ) - { szZip.Open( szFile, CZipArchive::zipCreate, 0 ); - } else - { szZip.Open( szFile, CZipArchive::zipOpen, 0 ); - } } - catch ( CZipException ) { bReturn = FALSE; @@ -402,10 +359,8 @@ int hb_CompressFileStd( char *szFile, char *szFiletoCompress, int iCompLevel, PH if ( bReturn ) { - if ( szPassWord != NULL ) - { + if( szPassWord ) szZip.SetPassword( szPassWord ); - } if ( hbza_pZipI.szComment != NULL ) { @@ -433,7 +388,6 @@ int hb_CompressFileStd( char *szFile, char *szFiletoCompress, int iCompLevel, PH hb_vmEvalBlockV( pBlock, 1, FileName); hb_itemRelease( FileName ); - } #if ( defined( __WIN32__ ) || defined( __MINGW32__ ) ) && defined( HB_USE_DRIVE_ADD ) @@ -453,32 +407,22 @@ int hb_CompressFileStd( char *szFile, char *szFiletoCompress, int iCompLevel, PH if ( bPath && !bAdded ) { if( ! szZip.AddNewFile( szFiletoCompress, iCompLevel, true, CZipArchive::zipsmSafeSmart, 65536 )) - { bReturn = FALSE; - } - else - { - // bAdded = TRUE; - } } else if ( !bDrive && !bPath && !bAdded ) { if (! szZip.AddNewFile( szFiletoCompress, iCompLevel, false, CZipArchive::zipsmSafeSmart, 65536 )) - { bReturn = FALSE; - } } - - } } catch( ... ){} } + try { szZip.Close( ); } - catch ( CZipException ) { bReturn = FALSE; @@ -501,24 +445,16 @@ int hb_CmpTdSpanStd( char *szFile, char * szFiletoCompress, int iCompLevel, PHB_ szZip.SetSpanCallback( &span ); - - if ( iSpanSize == 0 ) - { + if( iSpanSize == 0 ) iSpanSize = 1457664; - } try { if( ( bFileExist && bOverWrite ) || !bFileExist ) - { szZip.Open( szFile, CZipArchive::zipCreateSpan, iSpanSize ); - } else - { return ( int ) false; - } } - catch ( CZipException ) { bReturn = FALSE; @@ -526,10 +462,8 @@ int hb_CmpTdSpanStd( char *szFile, char * szFiletoCompress, int iCompLevel, PHB_ catch( ... ){} - if ( szPassWord != NULL ) - { + if( szPassWord ) szZip.SetPassword( szPassWord ); - } if ( hbza_pZipI.szComment != NULL ) { @@ -542,56 +476,42 @@ int hb_CmpTdSpanStd( char *szFile, char * szFiletoCompress, int iCompLevel, PHB_ hbza_pProgressInfo = pProgress; szZip.SetCallback( &spanac ); } + if ( bReturn ) { try { - if ( szPassWord != NULL ) - { + if( szPassWord ) szZip.SetPassword( szPassWord ); - } - if( pBlock != NULL ) + if( pBlock ) { PHB_ITEM FileName=hb_itemPutC( NULL, szFiletoCompress ) ; hb_vmEvalBlockV( pBlock, 1, FileName); hb_itemRelease( FileName ); - } #if defined( __WIN32__ ) || defined( __MINGW32__ ) if ( bDrive && !bAdded ) { if (! szZip.AddNewFileDrv( szFiletoCompress, iCompLevel, true, CZipArchive::zipsmSafeSmart, 65536 ) ) - { bReturn = FALSE; - } else - { bAdded = TRUE; - } } #endif if ( bPath && !bAdded ) { if (! szZip.AddNewFile( szFiletoCompress, iCompLevel, true, CZipArchive::zipsmSafeSmart, 65536 ) ) - { bReturn = FALSE; - } - else - { - // bAdded = TRUE; - } } else if ( !bDrive && !bPath && !bAdded ) { if (! szZip.AddNewFile( szFiletoCompress, iCompLevel, false, CZipArchive::zipsmSafeSmart, 65536 ) ) - { bReturn = FALSE; - } } } diff --git a/harbour/contrib/hbziparch/hbzipnew.cpp b/harbour/contrib/hbziparch/hbzipnew.cpp index 88fe496a53..f4196a3a2d 100644 --- a/harbour/contrib/hbziparch/hbzipnew.cpp +++ b/harbour/contrib/hbziparch/hbzipnew.cpp @@ -109,12 +109,12 @@ static int hb_CheckSpanMode( char * szFile ) { szZip.Close( true ); iReturn = 114; - } else if ( e.m_iCause == CZipException::noCallback ) + } + else if ( e.m_iCause == CZipException::noCallback ) { szZip.Close( true ); iReturn = 103; } - else if ( e.m_iCause == CZipException::generic ) { szZip.Close( true ); @@ -125,103 +125,73 @@ static int hb_CheckSpanMode( char * szFile ) 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::tooLongFileName ) { 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::internal ) { 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; } - - - - } + if ( ! iReturn ) { iReturn = szZip.GetSpanMode( ); diff --git a/harbour/contrib/hbziparch/tests/bld_b32.bat b/harbour/contrib/hbziparch/tests/bld_b32.bat new file mode 100644 index 0000000000..0f151f5711 --- /dev/null +++ b/harbour/contrib/hbziparch/tests/bld_b32.bat @@ -0,0 +1,14 @@ +@echo off +rem +rem $Id$ +rem + +if "%HB_BIN_INSTALL%" == "" set HB_BIN_INSTALL=..\..\..\bin +if "%HB_LIB_INSTALL%" == "" set HB_LIB_INSTALL=..\..\..\lib +if "%HB_INC_INSTALL%" == "" set HB_INC_INSTALL=..\..\..\include + +set HB_ARCHITECTURE=w32 +set HB_COMPILER=bcc32 +set HB_USER_LIBS=hbziparch.lib + +call %HB_BIN_INSTALL%\bld.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 diff --git a/harbour/contrib/hbziparch/tests/bld_vc.bat b/harbour/contrib/hbziparch/tests/bld_vc.bat new file mode 100644 index 0000000000..a1e2e51e11 --- /dev/null +++ b/harbour/contrib/hbziparch/tests/bld_vc.bat @@ -0,0 +1,14 @@ +@echo off +rem +rem $Id$ +rem + +if "%HB_BIN_INSTALL%" == "" set HB_BIN_INSTALL=..\..\..\bin +if "%HB_LIB_INSTALL%" == "" set HB_LIB_INSTALL=..\..\..\lib +if "%HB_INC_INSTALL%" == "" set HB_INC_INSTALL=..\..\..\include + +set HB_ARCHITECTURE=w32 +set HB_COMPILER=msvc +set HB_USER_LIBS=hbziparch.lib + +call %HB_BIN_INSTALL%\bld.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 diff --git a/harbour/contrib/hbziparch/tests/unzipa.prg b/harbour/contrib/hbziparch/tests/unzipa.prg new file mode 100644 index 0000000000..d5cb51a299 --- /dev/null +++ b/harbour/contrib/hbziparch/tests/unzipa.prg @@ -0,0 +1,9 @@ +/* + * $Id$ + */ + +PROCEDURE Main( cZip, ... ) + + ? hb_UnzipFile( cZip, NIL, .F., NIL, NIL, hb_AParams() ) + + RETURN diff --git a/harbour/contrib/hbziparch/tests/zipa.prg b/harbour/contrib/hbziparch/tests/zipa.prg new file mode 100644 index 0000000000..de9722a43c --- /dev/null +++ b/harbour/contrib/hbziparch/tests/zipa.prg @@ -0,0 +1,9 @@ +/* + * $Id$ + */ + +PROCEDURE Main( cZip, ... ) + + ? hb_ZipFile( cZip, hb_AParams() ) + + RETURN