diff --git a/OfficeUtils/src/ZipUtilsCP.cpp b/OfficeUtils/src/ZipUtilsCP.cpp index d57f692ad2..0b22243d27 100644 --- a/OfficeUtils/src/ZipUtilsCP.cpp +++ b/OfficeUtils/src/ZipUtilsCP.cpp @@ -634,6 +634,7 @@ int ZipDir( const WCHAR* dir, const WCHAR* outputFile, const OnProgressCallback* wstring szText; zipFile zf = zipOpenHelp(outputFile); + if (!zf) return -1; unsigned int filesCount = get_files_count( dir ); unsigned int currentFileIndex = 0; @@ -760,36 +761,38 @@ int ZipDir( const WCHAR* dir, const WCHAR* outputFile, const OnProgressCallback* if(oFile.ReadFile(pData, oFile.GetFileSize(), dwSizeRead)) { zipFile zf = zipOpenHelp(outputFile); + if (zf) + { + wstring inputFileName( inputFile ); - wstring inputFileName( inputFile ); + wstring::size_type pos = 0; + static const wstring::size_type npos = -1; - wstring::size_type pos = 0; - static const wstring::size_type npos = -1; + pos = inputFileName.find_last_of( L'\\' ); - pos = inputFileName.find_last_of( L'\\' ); + wstring zipFileName; - wstring zipFileName; + if ( pos != npos ) + { + zipFileName = wstring( ( inputFileName.begin() + pos + 1 ), inputFileName.end() ); + } + else + { + zipFileName = wstring( inputFileName.begin(), inputFileName.end() ); + } + std::string zipFileNameA = codepage_issue_fixToOEM(zipFileName); - if ( pos != npos ) - { - zipFileName = wstring( ( inputFileName.begin() + pos + 1 ), inputFileName.end() ); - } - else - { - zipFileName = wstring( inputFileName.begin(), inputFileName.end() ); - } - std::string zipFileNameA = codepage_issue_fixToOEM(zipFileName); - - err = zipOpenNewFileInZip( zf, zipFileNameA.c_str(), &zinfo, NULL, 0, NULL, 0, NULL, method, compressionLevel ); - err = zipWriteInFileInZip( zf, pData, dwSizeRead ); - err = zipCloseFileInZip( zf ); - err = zipClose( zf, NULL ); + err = zipOpenNewFileInZip( zf, zipFileNameA.c_str(), &zinfo, NULL, 0, NULL, 0, NULL, method, compressionLevel ); + err = zipWriteInFileInZip( zf, pData, dwSizeRead ); + err = zipCloseFileInZip( zf ); + err = zipClose( zf, NULL ); + } } RELEASEARRAYOBJECTS(pData); } } - return false; + return err; } /*========================================================================================================*/