Commit 114050c2 authored by ElenaSubbotina's avatar ElenaSubbotina

fix bug #33849

parent 7eee0755
...@@ -41,14 +41,14 @@ COfficeUtils::COfficeUtils(OnProgressCallback* fCallback) ...@@ -41,14 +41,14 @@ COfficeUtils::COfficeUtils(OnProgressCallback* fCallback)
HRESULT COfficeUtils::ExtractToDirectory(const std::wstring& zipFile, const std::wstring& unzipDir, wchar_t* password, SHORT extract_without_path) HRESULT COfficeUtils::ExtractToDirectory(const std::wstring& zipFile, const std::wstring& unzipDir, wchar_t* password, SHORT extract_without_path)
{ {
if( ZLibZipUtils::UnzipToDir( zipFile.c_str(), unzipDir.c_str(), m_fCallback, password, ( extract_without_path > 0 ) ? (true) : (false) ) == 0 ) if( ZLibZipUtils::UnzipToDir( zipFile.c_str(), unzipDir.c_str(), m_fCallback, password, ( extract_without_path > 0 ) ? (true) : (false) ) == 0 )
{ {
return S_OK; return S_OK;
} }
else else
{ {
return S_FALSE; return S_FALSE;
} }
} }
......
...@@ -477,122 +477,142 @@ namespace ZLibZipUtils ...@@ -477,122 +477,142 @@ namespace ZLibZipUtils
return false; return false;
} }
/*========================================================================================================*/ /*========================================================================================================*/
int ZipDir( const WCHAR* dir, const WCHAR* outputFile, const OnProgressCallback* progress, int compressionLevel )
{ int oneZipFile(zipFile & zf, zip_fileinfo & zi, std::wstring & file_name, std::wstring & zip_file_name, int method, int compressionLevel)
{
int err = -1; int err = -1;
if ( ( dir != NULL ) && ( outputFile != NULL ) ) NSFile::CFileBinary oFile;
{ if(oFile.OpenFile(file_name))
deque<wstring> StringDeque; {
deque<wstring> zipDeque; DWORD dwSizeRead;
StringDeque.push_back( wstring( dir ) ); BYTE* pData = new BYTE[oFile.GetFileSize()];
if(oFile.ReadFile(pData, oFile.GetFileSize(), dwSizeRead))
wstring zipDir; {
wstring file; std::string zipFileNameA = codepage_issue_fixToOEM(zip_file_name);
wstring zipFileName; err = zipOpenNewFileInZip( zf, zipFileNameA.c_str(), &zi, NULL, 0, NULL, 0, NULL, method, compressionLevel );
wstring szText; err = zipWriteInFileInZip( zf, pData, dwSizeRead );
err = zipCloseFileInZip( zf );
}
RELEASEARRAYOBJECTS(pData);
}
return 0;
}
int ZipDir( const WCHAR* dir, const WCHAR* outputFile, const OnProgressCallback* progress, int compressionLevel )
{
if ( ( dir != NULL ) && ( outputFile != NULL ) )
{
deque<wstring> StringDeque;
deque<wstring> zipDeque;
StringDeque.push_back( wstring( dir ) );
wstring zipDir;
wstring file;
wstring zipFileName;
wstring szText;
zipFile zf = zipOpenHelp(outputFile); zipFile zf = zipOpenHelp(outputFile);
zip_fileinfo zi; zip_fileinfo zi;
zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
zi.dosDate = 0; zi.dosDate = 0;
zi.internal_fa = 0; zi.internal_fa = 0;
zi.external_fa = 0; zi.external_fa = 0;
#if defined(_WIN32) || defined (_WIN64) #if defined(_WIN32) || defined (_WIN64)
SYSTEMTIME currTime; SYSTEMTIME currTime;
GetLocalTime( &currTime ); GetLocalTime( &currTime );
zi.tmz_date.tm_sec = currTime.wSecond; zi.tmz_date.tm_sec = currTime.wSecond;
zi.tmz_date.tm_min = currTime.wMinute; zi.tmz_date.tm_min = currTime.wMinute;
zi.tmz_date.tm_hour = currTime.wHour; zi.tmz_date.tm_hour = currTime.wHour;
zi.tmz_date.tm_mday = currTime.wDay; zi.tmz_date.tm_mday = currTime.wDay;
zi.tmz_date.tm_mon = currTime.wMonth; zi.tmz_date.tm_mon = currTime.wMonth;
zi.tmz_date.tm_year = currTime.wYear; zi.tmz_date.tm_year = currTime.wYear;
#endif #endif
unsigned int filesCount = get_files_count( dir ); unsigned int filesCount = get_files_count( dir );
unsigned int currentFileIndex = 0; unsigned int currentFileIndex = 0;
while ( !StringDeque.empty() ) while ( !StringDeque.empty() )
{ {
szText = StringDeque.front(); szText = StringDeque.front();
StringDeque.pop_front(); StringDeque.pop_front();
if(zipDeque.size() > 0) if(zipDeque.size() > 0)
{ {
zipDir = zipDeque.front() + wstring( L"/" ); zipDir = zipDeque.front() + wstring( L"/" );
zipDeque.pop_front(); zipDeque.pop_front();
} }
CArray<std::wstring> aCurFiles = NSDirectory::GetFiles(szText);
CArray<std::wstring> aCurDirectories = NSDirectory::GetDirectories(szText);
for(int i = 0; i < aCurDirectories.GetCount(); ++i)
{
std::wstring sCurDirectory = aCurDirectories[i];
std::wstring sDirName = NSSystemPath::GetFileName(sCurDirectory);
StringDeque.push_back( sCurDirectory );
zipDeque.push_back( zipDir + sDirName );
}
for(int i = 0; i < aCurFiles.GetCount(); ++i)
{
std::wstring cFilePath = aCurFiles[i];
std::wstring cFileName = NSSystemPath::GetFileName(cFilePath);
file = NSSystemPath::Combine(szText, cFileName);
zipFileName = zipDir + cFileName;
NSFile::CFileBinary oFile;
if(oFile.OpenFile(file))
{
DWORD dwSizeRead;
BYTE* pData = new BYTE[oFile.GetFileSize()];
if(oFile.ReadFile(pData, oFile.GetFileSize(), dwSizeRead))
{
std::string zipFileNameA = codepage_issue_fixToOEM(zipFileName);
err = zipOpenNewFileInZip( zf, zipFileNameA.c_str(), &zi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, compressionLevel );
err = zipWriteInFileInZip( zf, pData, dwSizeRead );
err = zipCloseFileInZip( zf );
}
RELEASEARRAYOBJECTS(pData);
}
if ( progress != NULL ) CArray<std::wstring> aCurFiles = NSDirectory::GetFiles(szText);
{ CArray<std::wstring> aCurDirectories = NSDirectory::GetDirectories(szText);
short cancel = 0;
long progressValue = ( 1000000 / filesCount * currentFileIndex ); for(int i = 0; i < aCurDirectories.GetCount(); ++i)
if(NULL != progress) {
(*progress)( UTILS_ONPROGRESSEVENT_ID, progressValue, &cancel ); std::wstring sCurDirectory = aCurDirectories[i];
std::wstring sDirName = NSSystemPath::GetFileName(sCurDirectory);
StringDeque.push_back( sCurDirectory );
zipDeque.push_back( zipDir + sDirName );
}
for (int i = 0; i < aCurFiles.GetCount(); ++i)
{
std::wstring cFileName = NSSystemPath::GetFileName(aCurFiles[i]);
if (std::wstring::npos != cFileName.find(L"mimetype")) // возможно и полное соответствие
{
std::wstring cFilePath = aCurFiles[i];
file = NSSystemPath::Combine(szText, cFileName);
zipFileName = zipDir + cFileName;
oneZipFile(zf, zi, file, zipFileName, 0, compressionLevel);
if ( cancel != 0 ) aCurFiles.RemoveAt(i);
{ break;
err = zipClose( zf, NULL ); }
}
return err; for (int i = 0; i < aCurFiles.GetCount(); ++i)
} {
} std::wstring cFilePath = aCurFiles[i];
std::wstring cFileName = NSSystemPath::GetFileName(cFilePath);
file = NSSystemPath::Combine(szText, cFileName);
zipFileName = zipDir + cFileName;
currentFileIndex++; oneZipFile(zf, zi, file, zipFileName, Z_DEFLATED, compressionLevel);
}
}
err = zipClose( zf, NULL ); if ( progress != NULL )
{
short cancel = 0;
long progressValue = ( 1000000 / filesCount * currentFileIndex );
if(NULL != progress)
(*progress)( UTILS_ONPROGRESSEVENT_ID, progressValue, &cancel );
if ( progress != NULL ) if ( cancel != 0 )
{ {
short cancel = 0; zipClose( zf, NULL );
long progressValue = 1000000; }
if(NULL != progress) }
(*progress)( UTILS_ONPROGRESSEVENT_ID, progressValue, &cancel ); currentFileIndex++;
}
}
zipClose( zf, NULL );
} if ( progress != NULL )
{
short cancel = 0;
long progressValue = 1000000;
if(NULL != progress)
(*progress)( UTILS_ONPROGRESSEVENT_ID, progressValue, &cancel );
}
} }
return 0;
return err; }
}
/*========================================================================================================*/ /*========================================================================================================*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment