HB_BOOL hb_fileRename( const char * pszFileName, const char * pszNewName ) { int i = s_fileFindDrv( pszFileName ); if( i >= 0 ) return s_pFileTypes[ i ]->Rename( s_pFileTypes[ i ], pszFileName, pszNewName ); return hb_fsRename( pszFileName, pszNewName ); }
HB_BOOL hb_fileRename( const char * pFilename, const char * pszNewName ) { int i = s_iFileTypes; while( --i >= 0 ) { if( s_pFileTypes[ i ]->Accept( pFilename ) ) return s_pFileTypes[ i ]->Rename( pFilename, pszNewName ); } return hb_fsRename( pFilename, pszNewName ); }
static HB_BOOL s_fileRename( PHB_FILE_FUNCS pFuncs, const char * pszName, const char * pszNewName ) { HB_SYMBOL_UNUSED( pFuncs ); return hb_fsRename( pszName, pszNewName ); }
static int hb_zipDeleteFile( const char * szZipFile, const char * szFileMask ) { char szTempFile[ HB_PATH_MAX ]; char szCurrFile[ HB_PATH_MAX ]; PHB_FNAME pFileName; HB_FHANDLE hFile; unzFile hUnzip; zipFile hZip; unz_global_info ugi; unz_file_info ufi; zip_fileinfo zfi; char * pszGlobalComment = NULL; char * pszFileComment = NULL; void * pExtraField = NULL; void * pLocalExtraField = NULL; int iFilesLeft = 0; int iFilesDel = 0; int iExtraFieldLen; int method; int level; int iResult; char * pszFree; /* open source file */ hUnzip = unzOpen( hb_fsNameConv( szZipFile, &pszFree ) ); if( pszFree ) hb_xfree( pszFree ); if( hUnzip == NULL ) return UNZ_ERRNO; pFileName = hb_fsFNameSplit( szZipFile ); hFile = hb_fsCreateTemp( pFileName->szPath, NULL, FC_NORMAL, szTempFile ); hZip = NULL; if( hFile != FS_ERROR ) { hb_fsClose( hFile ); hZip = zipOpen( szTempFile, APPEND_STATUS_CREATE ); } hb_xfree( pFileName ); if( hZip == NULL ) { unzClose( hUnzip ); return UNZ_ERRNO; } iResult = unzGetGlobalInfo( hUnzip, &ugi ); if( iResult == UNZ_OK ) { if( ugi.size_comment > 0 ) { pszGlobalComment = ( char * ) hb_xgrab( ugi.size_comment + 1 ); if( ( uLong ) unzGetGlobalComment( hUnzip, pszGlobalComment, ugi.size_comment ) != ugi.size_comment ) iResult = UNZ_ERRNO; pszGlobalComment[ ugi.size_comment ] = '\0'; } if( iResult == UNZ_OK ) iResult = unzGoToFirstFile( hUnzip ); } while( iResult == UNZ_OK ) { iResult = unzGetCurrentFileInfo( hUnzip, &ufi, szCurrFile, HB_PATH_MAX - 1, NULL, 0, NULL, 0 ); if( iResult != UNZ_OK ) break; if( hb_strMatchFile( szCurrFile, szFileMask ) ) iFilesDel++; else { if( ufi.size_file_extra ) pExtraField = ( char * ) hb_xgrab( ufi.size_file_extra ); if( ufi.size_file_comment ) pszFileComment = ( char * ) hb_xgrab( ufi.size_file_comment + 1 ); iResult = unzGetCurrentFileInfo( hUnzip, &ufi, NULL, 0, pExtraField, ufi.size_file_extra, pszFileComment, ufi.size_file_comment ); if( pszFileComment ) pszFileComment[ ufi.size_file_comment ] = '\0'; if( iResult != UNZ_OK ) break; iResult = unzOpenCurrentFile2( hUnzip, &method, &level, 1 ); if( iResult != UNZ_OK ) break; iExtraFieldLen = unzGetLocalExtrafield( hUnzip, NULL, 0 ); if( iExtraFieldLen < 0 ) { iResult = UNZ_ERRNO; break; } else if( iExtraFieldLen > 0 ) { pLocalExtraField = hb_xgrab( iExtraFieldLen ); if( unzGetLocalExtrafield( hUnzip, pLocalExtraField, iExtraFieldLen ) != iExtraFieldLen ) { iResult = UNZ_ERRNO; break; } } memset( &zfi, 0, sizeof( zfi ) ); memcpy( &zfi.tmz_date, &ufi.tmu_date, sizeof( tm_unz ) ); zfi.dosDate = ufi.dosDate; zfi.internal_fa = ufi.internal_fa; zfi.external_fa = ufi.external_fa; iResult = zipOpenNewFileInZip2( hZip, szCurrFile, &zfi, pLocalExtraField, iExtraFieldLen, pExtraField, ufi.size_file_extra, pszFileComment, method, level, 1 ); if( iResult != UNZ_OK ) break; if( ufi.compressed_size ) { void * buffer = hb_xgrab( HB_Z_IOBUF_SIZE ); uLong ulLeft = ufi.compressed_size; while( ulLeft > 0 ) { int iRead = HB_MIN( ulLeft, HB_Z_IOBUF_SIZE ); iResult = unzReadCurrentFile( hUnzip, ( voidp ) buffer, iRead ); if( iResult < 0 ) break; if( iResult != iRead ) { iResult = UNZ_ERRNO; break; } iResult = zipWriteInFileInZip( hZip, ( voidp ) buffer, iRead ); if( iResult != UNZ_OK ) break; ulLeft -= iRead; } hb_xfree( buffer ); if( iResult != UNZ_OK ) break; } iResult = zipCloseFileInZipRaw( hZip, ufi.uncompressed_size, ufi.crc ); if( iResult != UNZ_OK ) break; iResult = unzCloseCurrentFile( hUnzip ); if( iResult != UNZ_OK ) break; if( pExtraField ) { hb_xfree( pExtraField ); pExtraField = NULL; } if( pszFileComment ) { hb_xfree( pszFileComment ); pszFileComment = NULL; } if( pLocalExtraField ) { hb_xfree( pLocalExtraField ); pLocalExtraField = NULL; } iFilesLeft++; } iResult = unzGoToNextFile( hUnzip ); } if( pExtraField ) hb_xfree( pExtraField ); if( pszFileComment ) hb_xfree( pszFileComment ); if( pLocalExtraField ) hb_xfree( pLocalExtraField ); if( iFilesDel == 0 ) iResult = UNZ_ERRNO; else if( iResult == UNZ_END_OF_LIST_OF_FILE ) iResult = UNZ_OK; if( iResult != UNZ_OK ) zipClose( hZip, NULL ); else iResult = zipClose( hZip, pszGlobalComment ); unzClose( hUnzip ); if( pszGlobalComment ) hb_xfree( pszGlobalComment ); if( iResult != UNZ_OK ) hb_fsDelete( szTempFile ); else { hb_fsDelete( szZipFile ); if( iFilesLeft == 0 ) hb_fsDelete( szTempFile ); else if( ! hb_fsRename( szTempFile, szZipFile ) ) iResult = UNZ_ERRNO; } return iResult; }