From 739a1d2a3517d991a3e91fc46fd32e627b0f9839 Mon Sep 17 00:00:00 2001 From: Alexey Date: Thu, 20 Jul 2023 17:28:37 +0300 Subject: [PATCH] Refactoring --- OfficeUtils/src/ZipUtilsCP.cpp | 53 +++++++++------------------------- OfficeUtils/src/ZipUtilsCP.h | 1 + 2 files changed, 14 insertions(+), 40 deletions(-) diff --git a/OfficeUtils/src/ZipUtilsCP.cpp b/OfficeUtils/src/ZipUtilsCP.cpp index 02442e720b..198954d011 100644 --- a/OfficeUtils/src/ZipUtilsCP.cpp +++ b/OfficeUtils/src/ZipUtilsCP.cpp @@ -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; } diff --git a/OfficeUtils/src/ZipUtilsCP.h b/OfficeUtils/src/ZipUtilsCP.h index 69d03699e9..d0c530fb6a 100644 --- a/OfficeUtils/src/ZipUtilsCP.h +++ b/OfficeUtils/src/ZipUtilsCP.h @@ -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 );