Commit 114050c2 authored by ElenaSubbotina's avatar ElenaSubbotina

fix bug #33849

parent 7eee0755
......@@ -477,11 +477,30 @@ namespace ZLibZipUtils
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;
NSFile::CFileBinary oFile;
if(oFile.OpenFile(file_name))
{
DWORD dwSizeRead;
BYTE* pData = new BYTE[oFile.GetFileSize()];
if(oFile.ReadFile(pData, oFile.GetFileSize(), dwSizeRead))
{
std::string zipFileNameA = codepage_issue_fixToOEM(zip_file_name);
err = zipOpenNewFileInZip( zf, zipFileNameA.c_str(), &zi, NULL, 0, NULL, 0, NULL, method, compressionLevel );
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;
......@@ -531,6 +550,7 @@ namespace ZLibZipUtils
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];
......@@ -539,47 +559,49 @@ namespace ZLibZipUtils
zipDeque.push_back( zipDir + sDirName );
}
for(int i = 0; i < aCurFiles.GetCount(); ++i)
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];
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 );
oneZipFile(zf, zi, file, zipFileName, 0, compressionLevel);
aCurFiles.RemoveAt(i);
break;
}
RELEASEARRAYOBJECTS(pData);
}
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;
oneZipFile(zf, zi, file, zipFileName, Z_DEFLATED, compressionLevel);
if ( progress != NULL )
{
short cancel = 0;
long progressValue = ( 1000000 / filesCount * currentFileIndex );
if(NULL != progress)
(*progress)( UTILS_ONPROGRESSEVENT_ID, progressValue, &cancel );
if ( cancel != 0 )
{
err = zipClose( zf, NULL );
return err;
zipClose( zf, NULL );
}
}
currentFileIndex++;
}
}
err = zipClose( zf, NULL );
zipClose( zf, NULL );
if ( progress != NULL )
{
......@@ -587,12 +609,10 @@ namespace ZLibZipUtils
long progressValue = 1000000;
if(NULL != progress)
(*progress)( UTILS_ONPROGRESSEVENT_ID, progressValue, &cancel );
}
}
return err;
}
return 0;
}
/*========================================================================================================*/
......
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