From 2212c3b26fd9e93f1e829346f0a03a5fb28d2f3b Mon Sep 17 00:00:00 2001 From: Alexey Date: Mon, 5 Dec 2022 03:28:21 +0300 Subject: [PATCH] Fix chdir --- OfficeUtils/src/ZipUtilsCP.cpp | 58 +++++++++++----------------------- 1 file changed, 19 insertions(+), 39 deletions(-) diff --git a/OfficeUtils/src/ZipUtilsCP.cpp b/OfficeUtils/src/ZipUtilsCP.cpp index 5200ff8ee5..b6ef621246 100644 --- a/OfficeUtils/src/ZipUtilsCP.cpp +++ b/OfficeUtils/src/ZipUtilsCP.cpp @@ -120,8 +120,8 @@ namespace ZLibZipUtils static void change_file_date( const wchar_t *filename, uLong dosdate, tm_unz tmu_date ); static int mymkdir( const wchar_t* dirname ); static int makedir( const wchar_t *newdir ); - static int do_extract_currentfile( unzFile uf, const int* popt_extract_without_path, int* popt_overwrite, const char* password ); - static int do_extract( unzFile uf, int opt_extract_without_path, int opt_overwrite, const char* password, const OnProgressCallback* progress ); + static int do_extract_currentfile( unzFile uf, const WCHAR* unzip_dir, const int* popt_extract_without_path, int* popt_overwrite, const char* password ); + static int do_extract( unzFile uf, const WCHAR* unzip_dir, int opt_extract_without_path, int opt_overwrite, const char* password, const OnProgressCallback* progress ); static bool is_file_in_archive(unzFile uf, const wchar_t *filename); static bool current_file_is_find(unzFile uf, const wchar_t *filename); @@ -217,7 +217,7 @@ namespace ZLibZipUtils pos += replace.length(); } } - static int do_extract_currentfile( unzFile uf, const int* popt_extract_without_path, int* popt_overwrite, const char* password ) + static int do_extract_currentfile( unzFile uf, const WCHAR* unzip_dir, const int* popt_extract_without_path, int* popt_overwrite, const char* password ) { char filename_inzipA[256]; wchar_t filename_inzip[256]; @@ -233,6 +233,11 @@ namespace ZLibZipUtils std::wstring filenameW = codepage_issue_fixFromOEM(filename_inzipA); wcscpy(filename_inzip , filenameW.c_str()); + std::wstring output = std::wstring(unzip_dir) + L"/" + std::wstring(filename_inzip); + for(int i = 0; i < output.size(); i++) + if(output[i] == L'\\') + output[i] = L'/';; + if (err!=UNZ_OK) { return err; @@ -250,7 +255,7 @@ namespace ZLibZipUtils { if ((*popt_extract_without_path)==0) { - mymkdir(filename_inzip); + mymkdir(output.c_str()); } } else @@ -258,8 +263,8 @@ namespace ZLibZipUtils const wchar_t* write_filename; int skip=0; - if ((*popt_extract_without_path)==0) - write_filename = filename_inzip; + if ((*popt_extract_without_path)==0) + write_filename = output.c_str(); else write_filename = filename_withoutpath; @@ -381,7 +386,7 @@ namespace ZLibZipUtils /*========================================================================================================*/ - static int do_extract( unzFile uf, int opt_extract_without_path, int opt_overwrite, const char* password, const OnProgressCallback* progress ) + static int do_extract( unzFile uf, const WCHAR* unzip_dir, int opt_extract_without_path, int opt_overwrite, const char* password, const OnProgressCallback* progress ) { uLong i; unz_global_info gi; @@ -392,7 +397,7 @@ namespace ZLibZipUtils for (i=0;i