Refactoring

This commit is contained in:
Alexey
2023-07-20 17:28:37 +03:00
parent 1e2964ccbe
commit 739a1d2a35
2 changed files with 14 additions and 40 deletions

View File

@ -723,44 +723,14 @@ namespace ZLibZipUtils
int UnzipToDir( const WCHAR* zipFile, const WCHAR* unzipDir, const OnProgressCallback* progress, const WCHAR* password, bool opt_extract_without_path, bool clearOutputDirectory )
{
unzFile uf = NULL;
int err = -1;
if(NSDirectory::Exists(unzipDir))
err = 0;
if ( ( zipFile != NULL ) && ( unzipDir != NULL ) )
if ( ( zipFile != NULL ) )
{
int old = zlip_get_addition_flag();
zlip_set_addition_flag(old | ZLIB_ADDON_FLAG_READ_ONLY);
uf = unzOpenHelp (zipFile);
zlip_set_addition_flag(old);
}
if ( uf != NULL )
{
if ( clearOutputDirectory )
{
ClearDirectory( unzipDir );
}
if ( err == 0 )
{
if(NULL != password)
{
std::string passwordA = codepage_issue_fixToOEM(password);
err = do_extract( uf, unzipDir, opt_extract_without_path, 1, passwordA.c_str(), progress );
}
else
err = do_extract( uf, unzipDir, opt_extract_without_path, 1, NULL, progress );
}
if ( err == UNZ_OK )
{
err = unzClose( uf );
}
}
int err = UnzipToDir(uf, unzipDir, progress, password, opt_extract_without_path, clearOutputDirectory);
return err;
}
@ -769,12 +739,6 @@ namespace ZLibZipUtils
int UnzipToDir(BYTE* data, size_t len, const WCHAR* unzipDir, const OnProgressCallback* progress, const WCHAR* password, bool opt_extract_without_path, bool clearOutputDirectory )
{
unzFile uf = NULL;
int err = -1;
if(NSDirectory::Exists(unzipDir))
err = 0;
BUFFER_IO* buf = new BUFFER_IO;
if ( ( data != NULL ) && ( len != 0 ) )
{
@ -790,8 +754,18 @@ namespace ZLibZipUtils
zlip_set_addition_flag(old);
}
int err = UnzipToDir(uf, unzipDir, progress, password, opt_extract_without_path, clearOutputDirectory);
RELEASEOBJECT(buf);
return err;
}
if ( uf != NULL )
int UnzipToDir(unzFile uf, const WCHAR* unzipDir, const OnProgressCallback* progress, const WCHAR* password, bool opt_extract_without_path, bool clearOutputDirectory )
{
int err = -1;
if(NSDirectory::Exists(unzipDir))
err = 0;
if ( uf != NULL && unzipDir != NULL )
{
if ( clearOutputDirectory )
{
@ -814,7 +788,6 @@ namespace ZLibZipUtils
err = unzClose( uf );
}
}
RELEASEOBJECT(buf);
return err;
}

View File

@ -63,6 +63,7 @@ namespace ZLibZipUtils
int ZipDir( const WCHAR* dir, const WCHAR* outputFile, const OnProgressCallback* progress, bool sorted = false, int method = Z_DEFLATED, int compressionLevel = -1, bool bDateTime = false);
int ZipFile( const WCHAR* inputFile, const WCHAR* outputFile, int method = Z_DEFLATED, int compressionLevel = -1, bool bDateTime = false );
bool ClearDirectory( const WCHAR* dir, bool delDir = false );
int UnzipToDir( unzFile uf, const WCHAR* unzipDir, const OnProgressCallback* progress, const WCHAR* password, bool opt_extract_without_path, bool clearOutputDirectory );
int UnzipToDir( const WCHAR* zipFile, const WCHAR* unzipDir, const OnProgressCallback* progress, const WCHAR* password = NULL, bool opt_extract_without_path = false, bool clearOutputDirectory = false );
int UnzipToDir( BYTE* data, size_t len, const WCHAR* unzipDir, const OnProgressCallback* progress, const WCHAR* password = NULL, bool opt_extract_without_path = false, bool clearOutputDirectory = false );
int UncompressBytes( BYTE* destBuf, ULONG* destSize, const BYTE* sourceBuf, ULONG sourceSize );