Minor Zip fixes

This commit is contained in:
Alex Zolotarev 2013-06-18 10:36:57 +03:00 committed by Alex Zolotarev
parent 8dabfc9d1b
commit a16d85a35f
3 changed files with 15 additions and 10 deletions

View file

@ -14,18 +14,23 @@
namespace
{
struct ZipHandle
class ZipHandle
{
zipFile m_zipFile;
zipFile m_zipFileHandle;
public:
ZipHandle(string const & filePath)
{
m_zipFile = zipOpen(filePath.c_str(), 0);
m_zipFileHandle = zipOpen(filePath.c_str(), 0);
}
~ZipHandle()
{
if (m_zipFile)
zipClose(m_zipFile, NULL);
if (m_zipFileHandle)
zipClose(m_zipFileHandle, NULL);
}
zipFile Handle() const { return m_zipFileHandle; }
};
void CreateTMZip(tm_zip & res)
@ -47,7 +52,7 @@ void CreateTMZip(tm_zip & res)
bool CreateZipFromPathDeflatedAndDefaultCompression(string const & filePath, string const & zipFilePath)
{
ZipHandle zip(zipFilePath);
if (!zip.m_zipFile)
if (!zip.Handle())
return false;
// Special syntax to initialize struct with zeroes
@ -55,7 +60,7 @@ bool CreateZipFromPathDeflatedAndDefaultCompression(string const & filePath, str
CreateTMZip(zipInfo.tmz_date);
string fileName = filePath;
my::GetNameFromFullPath(fileName);
if (zipOpenNewFileInZip(zip.m_zipFile, fileName.c_str(), &zipInfo,
if (::zipOpenNewFileInZip(zip.Handle(), fileName.c_str(), &zipInfo,
NULL, 0, NULL, 0, "ZIP from MapsWithMe", Z_DEFLATED, Z_DEFAULT_COMPRESSION) < 0)
{
return false;
@ -73,7 +78,7 @@ bool CreateZipFromPathDeflatedAndDefaultCompression(string const & filePath, str
size_t const toRead = min(bufSize, fileSize - currSize);
f.Read(currSize, &buffer[0], toRead);
if (ZIP_OK != zipWriteInFileInZip(zip.m_zipFile, &buffer[0], toRead))
if (ZIP_OK != ::zipWriteInFileInZip(zip.Handle(), &buffer[0], toRead))
return false;
currSize += toRead;

View file

@ -98,7 +98,7 @@ void ZipFileReader::UnzipFile(string const & zipContainer, string const & fileIn
MY_SCOPE_GUARD(outFileGuard, bind(&FileWriter::DeleteFileX, cref(outFilePath)));
FileWriter outFile(outFilePath);
int pos = 0;
uint64_t pos = 0;
while (true)
{
int const readBytes = unzReadCurrentFile(zip, &buf[0], BUF_SIZE);

View file

@ -13,7 +13,7 @@ private:
uint64_t m_uncompressedFileSize;
public:
typedef function<void(int, int)> ProgressFn;
typedef function<void(uint64_t, uint64_t)> ProgressFn;
/// Contains file name inside zip and it's uncompressed size
typedef vector<pair<string, uint32_t> > FileListT;