bool Callback( int iProgress ) { PHB_ITEM Disk = hb_itemPutNL( NULL, m_uDiskNeeded ); ( void ) iProgress; hb_vmEvalBlockV( ChangeDiskBlock, 1, Disk ); hb_itemRelease( Disk ); return TRUE; }
bool Callback( int iProgress ) { PHB_ITEM Disk = hb_itemPutNL( NULL, m_uTotalSoFar ), Total = hb_itemPutNL( NULL, m_uTotalToDo ); ( void ) iProgress; hb_vmEvalBlockV( pProgressInfo, 2, Disk, Total ); hb_itemRelease( Disk ); hb_itemRelease( Total ); return TRUE; }
bool hb_SetProgressofTdSpan( DWORD a, int iSoFar, void * pData ) { PHB_ITEM Disk = hb_itemPutNL( NULL, iSoFar ), Total = hb_itemPutNL( NULL, a ); HB_SYMBOL_UNUSED( pData ); hb_vmEvalBlockV( pProgressInfo, 2, Disk, Total ); hb_itemRelease( Disk ); hb_itemRelease( Total ); return TRUE; }
static HB_BOOL hb_copyfile( const char * szSource, const char * szDest, PHB_ITEM pBlock ) { HB_BOOL bRetVal = HB_FALSE; HB_FHANDLE fhndSource; HB_TRACE( HB_TR_DEBUG, ( "hb_copyfile(%s, %s)", szSource, szDest ) ); while( ( fhndSource = hb_spOpen( szSource, FO_READ | FO_SHARED | FO_PRIVATE ) ) == FS_ERROR ) { HB_USHORT uiAction = hb_errRT_BASE_Ext1( EG_OPEN, 2012, NULL, szSource, hb_fsError(), EF_CANDEFAULT | EF_CANRETRY, 0 ); if( uiAction != E_RETRY ) break; } if( fhndSource != FS_ERROR ) { HB_FHANDLE fhndDest; while( ( fhndDest = hb_spCreate( szDest, FC_NORMAL ) ) == FS_ERROR ) { HB_USHORT uiAction = hb_errRT_BASE_Ext1( EG_CREATE, 2012, NULL, szDest, hb_fsError(), EF_CANDEFAULT | EF_CANRETRY, 0 ); if( uiAction != E_RETRY ) break; } if( fhndDest != FS_ERROR ) { #if defined( HB_OS_UNIX ) struct stat struFileInfo; int iSuccess = fstat( fhndSource, &struFileInfo ); #endif HB_BYTE * buffer = ( HB_BYTE * ) hb_xgrab( BUFFER_SIZE ); HB_SIZE nRead; bRetVal = HB_TRUE; if( hb_itemType( pBlock ) != HB_IT_BLOCK ) pBlock = NULL; while( ( nRead = hb_fsReadLarge( fhndSource, buffer, BUFFER_SIZE ) ) != 0 ) { while( hb_fsWriteLarge( fhndDest, buffer, nRead ) != nRead ) { HB_USHORT uiAction = hb_errRT_BASE_Ext1( EG_WRITE, 2016, NULL, szDest, hb_fsError(), EF_CANDEFAULT | EF_CANRETRY, 0 ); if( uiAction != E_RETRY ) { bRetVal = HB_FALSE; break; } } if( pBlock ) { PHB_ITEM pCnt = hb_itemPutNS( NULL, nRead ); hb_vmEvalBlockV( pBlock, 1, pCnt ); hb_itemRelease( pCnt ); } } hb_xfree( buffer ); #if defined( HB_OS_UNIX ) if( iSuccess == 0 ) fchmod( fhndDest, struFileInfo.st_mode ); #endif hb_fsClose( fhndDest ); } hb_fsClose( fhndSource ); } return bRetVal; }
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 ) { DWORD dwSize; BOOL bAdded = FALSE; BOOL bReturn = TRUE; BOOL bFileExist = hb_fsFile( szFile ); CZipArchive szZip; SpanCallbackc span; SpanActionCallbackc spanac; szZip.SetSpanCallback( &span ); if( iSpanSize == 0 ) { iSpanSize = 1457664; } try { if( ( bFileExist && bOverWrite ) || ! bFileExist ) { szZip.Open( szFile, CZipArchive::zipCreateSpan, iSpanSize ); } else { return ( int ) false; } } catch( CZipException ) { bReturn = FALSE; } catch( ... ) { } if( szPassWord != NULL ) { szZip.SetPassword( szPassWord ); } if( pZipI.szComment != NULL ) { szZip.SetGlobalComment( pZipI.szComment ); hb_xfree( pZipI.szComment ); } if( HB_IS_BLOCK( pProgress ) ) { pProgressInfo = pProgress; szZip.SetCallback( &spanac ); } if( bReturn ) { try { if( szPassWord != NULL ) { szZip.SetPassword( szPassWord ); } dwSize = GetCurrentFileSize( szFiletoCompress ); if( pBlock != NULL ) { 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; } } } catch( ... ) { } } try { szZip.Close(); } catch( CZipException ) { bReturn = FALSE; } catch( ... ) { } if( pProgressInfo ) { hb_itemRelease( pProgressInfo ); } return ( int ) bReturn; }
int hb_CmpTdSpan( const char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, const char * szPassWord, int iSpanSize, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ) { ULONG ulCount = 0; const char * szDummy; DWORD dwSize; BOOL bAdded = FALSE; BOOL bReturn = TRUE; BOOL bFileExist = hb_fsFile( szFile ); CZipArchive szZip; SpanCallbackc span; SpanActionCallbackc spanac; szZip.SetSpanCallback( &span ); if( iSpanSize == 0 ) { iSpanSize = 1457664; } try { if( ( bFileExist && bOverWrite ) || ! bFileExist ) { szZip.Open( szFile, CZipArchive::zipCreateSpan, iSpanSize ); } else { bReturn = FALSE; return ( int ) bReturn; } } catch( CZipException ) { bReturn = FALSE; } catch( ... ) { } //if (! bReturn ) //{ if( szPassWord != NULL ) { szZip.SetPassword( szPassWord ); } if( pZipI.szComment != NULL ) { szZip.SetGlobalComment( pZipI.szComment ); hb_xfree( pZipI.szComment ); } if( HB_IS_BLOCK( pProgress ) ) { pProgressInfo = pProgress; szZip.SetCallback( &spanac ); } for( ulCount = 1; ( ulCount <= hb_arrayLen( pArray ) ); ulCount++ ) { szDummy = ( char * ) hb_arrayGetCPtr( pArray, ulCount ); dwSize = GetCurrentFileSize( szDummy ); bAdded = FALSE; if( dwSize != ( DWORD ) -1 ) { if( pBlock != NULL ) { PHB_ITEM FileName = hb_itemPutC( NULL, hb_arrayGetCPtr( pArray, ulCount ) ), FilePos = hb_itemPutNI( NULL, ulCount ); hb_vmEvalBlockV( pBlock, 2, FileName, FilePos ); hb_itemRelease( FileName ); hb_itemRelease( FilePos ); } 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( ... ) { } } } //} try { szZip.Close(); } catch( CZipException ) { bReturn = FALSE; } catch( ... ) { } return ( int ) bReturn; }
int hb_CompressFile( const char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, const char * szPassWord, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ) { ULONG ulCount = 0; const char * szDummy; char * szDummyLower = NULL; char * szFileLower = hb_strdup( ( char * ) szFile ); BOOL bFileExist = hb_fsFile( szFile ); BOOL bAdded = FALSE; BOOL bReturn = TRUE; DWORD dwSize; CZipArchive szZip; SpanCallbackc span; SpanActionCallbackc spanac; szZip.SetSpanCallback( &span ); #ifdef HB_OS_WIN_32 hb_strLower( szFileLower, strlen( szFileLower ) ); #endif try { if( ( bFileExist && bOverWrite ) || ! bFileExist ) { szZip.Open( szFile, CZipArchive::zipCreate, 0 ); } else { szZip.Open( szFile, CZipArchive::zipOpen, 0 ); } } catch( CZipException ) { bReturn = FALSE; } catch( ... ) { } if( bReturn ) { if( szPassWord != NULL ) { szZip.SetPassword( szPassWord ); } if( pZipI.szComment != NULL ) { szZip.SetGlobalComment( pZipI.szComment ); hb_xfree( pZipI.szComment ); } if( HB_IS_BLOCK( pProgress ) ) { pProgressInfo = pProgress; szZip.SetCallback( &spanac ); } for( ulCount = 1; ( ulCount <= hb_arrayLen( pArray ) ); ulCount++ ) { szDummy = ( char * ) hb_arrayGetCPtr( pArray, ulCount ); dwSize = GetCurrentFileSize( szDummy ); bAdded = FALSE; szDummyLower = hb_strdup( ( char * ) szDummy ); #ifdef HB_OS_WIN_32 hb_strLower( szDummyLower, strlen( szDummyLower ) ); #endif // Prevent adding current archive file ! if( strstr( szFileLower, szDummyLower ) == NULL && strstr( szDummyLower, szFileLower ) == NULL ) { if( dwSize != ( DWORD ) -1 ) { if( pBlock != NULL ) { PHB_ITEM FileName = hb_itemPutC( NULL, hb_arrayGetCPtr( pArray, ulCount ) ), FilePos = hb_itemPutNI( NULL, ulCount ); hb_vmEvalBlockV( pBlock, 2, FileName, FilePos ); hb_itemRelease( FileName ); hb_itemRelease( FilePos ); } 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( ... ) { } } } hb_xfree( szDummyLower ); } } hb_xfree( szFileLower ); try { szZip.Close(); } catch( CZipException ) { bReturn = FALSE; } catch( ... ) { } return ( int ) bReturn; }