Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use case sensitive file compare and c++11 formating #175

Merged
merged 1 commit into from
Jan 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions src/util/ZipSerialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class ZipSerializePrivate
public:
zlib_filefunc_def pzlib_filefunc;
string path;
zipFile create;
unzFile open;
zipFile create = nullptr;
unzFile open = nullptr;
};
}

Expand All @@ -61,19 +61,17 @@ ZipSerialize::ZipSerialize(const string& path, bool create)
fill_fopen_filefunc(&d->pzlib_filefunc);
#endif
d->path = path;
d->create = 0;
d->open = 0;
if(create)
{
DEBUG("ZipSerialize::create(%s)", path.c_str());
d->create = zipOpen2((char*)util::File::encodeName(d->path).c_str(), APPEND_STATUS_CREATE, 0, &d->pzlib_filefunc);
d->create = zipOpen2(util::File::encodeName(d->path).c_str(), APPEND_STATUS_CREATE, nullptr, &d->pzlib_filefunc);
if(!d->create)
THROW("Failed to create ZIP file '%s'.", d->path.c_str());
}
else
{
DEBUG("ZipSerialize::open(%s)", path.c_str());
d->open = unzOpen2((char*)util::File::encodeName(d->path).c_str(), &d->pzlib_filefunc);
d->open = unzOpen2(util::File::encodeName(d->path).c_str(), &d->pzlib_filefunc);
if(!d->open)
THROW("Failed to open ZIP file '%s'.", d->path.c_str());
}
Expand All @@ -86,7 +84,7 @@ ZipSerialize::ZipSerialize(const string& path, bool create)
*/
ZipSerialize::~ZipSerialize()
{
if(d->create) zipClose(d->create, 0);
if(d->create) zipClose(d->create, nullptr);
if(d->open) unzClose(d->open);
delete d;
}
Expand All @@ -111,12 +109,12 @@ vector<string> ZipSerialize::list() const
THROW("Failed to go to the next file inside ZIP container. ZLib error: %d", unzResult);

unz_file_info fileInfo;
unzResult = unzGetCurrentFileInfo(d->open, &fileInfo, 0, 0, 0, 0, 0, 0);
unzResult = unzGetCurrentFileInfo(d->open, &fileInfo, nullptr, 0, nullptr, 0, nullptr, 0);
if(unzResult != UNZ_OK)
THROW("Failed to get filename of the current file inside ZIP container. ZLib error: %d", unzResult);

string fileName(fileInfo.size_filename, 0);
unzResult = unzGetCurrentFileInfo(d->open, &fileInfo, &fileName[0], uLong(fileName.size()), 0, 0, 0, 0);
unzResult = unzGetCurrentFileInfo(d->open, &fileInfo, &fileName[0], uLong(fileName.size()), nullptr, 0, nullptr, 0);
if(unzResult != UNZ_OK)
THROW("Failed to get filename of the current file inside ZIP container. ZLib error: %d", unzResult);

Expand All @@ -140,7 +138,7 @@ void ZipSerialize::extract(const string &file, ostream &os) const
if(file[file.size()-1] == '/')
return;

int unzResult = unzLocateFile(d->open, file.c_str(), 0);
int unzResult = unzLocateFile(d->open, file.c_str(), 1);
if(unzResult != UNZ_OK)
THROW("Failed to open file inside ZIP container. ZLib error: %d", unzResult);

Expand Down Expand Up @@ -200,8 +198,8 @@ void ZipSerialize::addFile(const string& containerPath, istream &is, const Prope
int compression = flags & DontCompress ? Z_NULL : Z_DEFLATED;
int level = flags & DontCompress ? Z_NO_COMPRESSION : Z_DEFAULT_COMPRESSION;
int zipResult = zipOpenNewFileInZip4(d->create, containerPath.c_str(),
&info, 0, 0, 0, 0, prop.comment.c_str(), compression, level, 0,
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, 0, 0, 0, 2048);
&info, nullptr, 0, nullptr, 0, prop.comment.c_str(), compression, level, 0,
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, nullptr, 0, 0, 2048);
if(zipResult != ZIP_OK)
THROW("Failed to create new file inside ZIP container. ZLib error: %d", zipResult);

Expand All @@ -214,7 +212,7 @@ void ZipSerialize::addFile(const string& containerPath, istream &is, const Prope
if(is.gcount() <= 0)
break;

zipResult = zipWriteInFileInZip(d->create, buf, (unsigned int)is.gcount());
zipResult = zipWriteInFileInZip(d->create, buf, unsigned(is.gcount()));
if(zipResult != ZIP_OK)
{
zipCloseFileInZip(d->create);
Expand All @@ -234,7 +232,7 @@ ZipSerialize::Properties ZipSerialize::properties(const string &file) const
THROW("Failed to open file inside ZIP container. ZLib error: %d", unzResult);

unz_file_info info;
unzResult = unzGetCurrentFileInfo(d->open, &info, 0, 0, 0, 0, 0, 0);
unzResult = unzGetCurrentFileInfo(d->open, &info, nullptr, 0, nullptr, 0, nullptr, 0);
if(unzResult != UNZ_OK)
THROW("Failed to get filename of the current file inside ZIP container. ZLib error: %d", unzResult);

Expand All @@ -252,7 +250,7 @@ ZipSerialize::Properties ZipSerialize::properties(const string &file) const
return prop;

prop.comment.resize(info.size_file_comment);
unzResult = unzGetCurrentFileInfo(d->open, &info, 0, 0, 0, 0, &prop.comment[0], uLong(prop.comment.size()));
unzResult = unzGetCurrentFileInfo(d->open, &info, nullptr, 0, nullptr, 0, &prop.comment[0], uLong(prop.comment.size()));
if(unzResult != UNZ_OK)
THROW("Failed to get filename of the current file inside ZIP container. ZLib error: %d", unzResult);

Expand Down