Skip to content

Commit

Permalink
Merge pull request #3644 from DavidBauer1984/fix/zip-file-reader
Browse files Browse the repository at this point in the history
Improve ZipFileReader
  • Loading branch information
lpugin authored Apr 9, 2024
2 parents fa32d17 + ff4649d commit 23b4e2d
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/filereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool ZipFileReader::Load(const std::string &filename)
#else
std::ifstream fin(filename.c_str(), std::ios::in | std::ios::binary);
if (!fin.is_open()) {
LogError("File archive '%s' could not be open.", filename.c_str());
LogError("File archive '%s' could not be opened.", filename.c_str());
return false;
}

Expand Down Expand Up @@ -92,7 +92,7 @@ std::list<std::string> ZipFileReader::GetFileList() const
assert(m_file);

std::list<std::string> list;
for (miniz_cpp::zip_info &member : m_file->infolist()) {
for (const miniz_cpp::zip_info &member : m_file->infolist()) {
list.push_back(member.filename);
}
return list;
Expand All @@ -103,21 +103,17 @@ bool ZipFileReader::HasFile(const std::string &filename)
assert(m_file);

// Look for the file in the zip
for (miniz_cpp::zip_info &member : m_file->infolist()) {
if (member.filename == filename) {
return true;
}
}

return true;
const std::vector<miniz_cpp::zip_info> &fileInfoList = m_file->infolist();
return std::any_of(fileInfoList.cbegin(), fileInfoList.cend(),
[&filename](const auto &info) { return info.filename == filename; });
}

std::string ZipFileReader::ReadTextFile(const std::string &filename)
{
assert(m_file);

// Look for the meta file in the zip
for (miniz_cpp::zip_info &member : m_file->infolist()) {
for (const miniz_cpp::zip_info &member : m_file->infolist()) {
if (member.filename == filename) {
return m_file->read(member.filename);
}
Expand Down

0 comments on commit 23b4e2d

Please sign in to comment.