diff options
Diffstat (limited to 'src/lib/util')
-rw-r--r-- | src/lib/util/un7z.cpp | 56 | ||||
-rw-r--r-- | src/lib/util/unzip.cpp | 40 | ||||
-rw-r--r-- | src/lib/util/unzip.h | 4 |
3 files changed, 74 insertions, 26 deletions
diff --git a/src/lib/util/un7z.cpp b/src/lib/util/un7z.cpp index bca825c1f71..d4761c5347d 100644 --- a/src/lib/util/un7z.cpp +++ b/src/lib/util/un7z.cpp @@ -124,12 +124,21 @@ public: archive_file::error initialize(); - int first_file() { return search(0, 0, std::string(), false, false); } - int next_file() { return (m_curr_file_idx < 0) ? -1 : search(m_curr_file_idx + 1, 0, std::string(), false, false); } + int first_file() { return search(0, 0, std::string(), false, false, false); } + int next_file() { return (m_curr_file_idx < 0) ? -1 : search(m_curr_file_idx + 1, 0, std::string(), false, false, false); } - int search(std::uint32_t crc) { return search(0, crc, std::string(), true, false); } - int search(const std::string &filename) { return search(0, 0, filename, false, true); } - int search(std::uint32_t crc, const std::string &filename) { return search(0, crc, filename, true, true); } + int search(std::uint32_t crc) + { + return search(0, crc, std::string(), true, false, false); + } + int search(const std::string &filename, bool partialpath) + { + return search(0, 0, filename, false, true, partialpath); + } + int search(std::uint32_t crc, const std::string &filename, bool partialpath) + { + return search(0, crc, filename, true, true, partialpath); + } bool current_is_directory() const { return m_curr_is_dir; } const std::string ¤t_name() const { return m_curr_name; } @@ -144,7 +153,13 @@ private: m7z_file_impl &operator=(const m7z_file_impl &) = delete; m7z_file_impl &operator=(m7z_file_impl &&) = delete; - int search(int i, std::uint32_t search_crc, const std::string &search_filename, bool matchcrc, bool matchname); + int search( + int i, + std::uint32_t search_crc, + const std::string &search_filename, + bool matchcrc, + bool matchname, + bool partialpath); void make_utf8_name(int index); static constexpr std::size_t CACHE_SIZE = 8; @@ -187,9 +202,18 @@ public: virtual int first_file() override { return m_impl->first_file(); } virtual int next_file() override { return m_impl->next_file(); } - virtual int search(std::uint32_t crc) override { return m_impl->search(crc); } - virtual int search(const std::string &filename) override { return m_impl->search(filename); } - virtual int search(std::uint32_t crc, const std::string &filename) override { return m_impl->search(crc, filename); } + virtual int search(std::uint32_t crc) override + { + return m_impl->search(crc); + } + virtual int search(const std::string &filename, bool partialpath) override + { + return m_impl->search(filename, partialpath); + } + virtual int search(std::uint32_t crc, const std::string &filename, bool partialpath) override + { + return m_impl->search(crc, filename, partialpath); + } virtual bool current_is_directory() const override { return m_impl->current_is_directory(); } virtual const std::string ¤t_name() const override { return m_impl->current_name(); } @@ -373,7 +397,13 @@ archive_file::error m7z_file_impl::decompress(void *buffer, std::uint32_t length } -int m7z_file_impl::search(int i, std::uint32_t search_crc, const std::string &search_filename, bool matchcrc, bool matchname) +int m7z_file_impl::search( + int i, + std::uint32_t search_crc, + const std::string &search_filename, + bool matchcrc, + bool matchname, + bool partialpath) { for ( ; i < m_db.db.NumFiles; i++) { @@ -383,7 +413,11 @@ int m7z_file_impl::search(int i, std::uint32_t search_crc, const std::string &se const std::uint64_t size(f.Size); const std::uint32_t crc(f.Crc); const bool crcmatch(crc == search_crc); - const bool namematch(!core_stricmp(search_filename.c_str(), &m_utf8_buf[0])); + auto const partialoffset(m_utf8_buf.size() - 1 - search_filename.length()); + bool const partialpossible((m_utf8_buf.size() > (search_filename.length() + 1)) && (m_utf8_buf[partialoffset - 1] == '/')); + const bool namematch( + !core_stricmp(search_filename.c_str(), &m_utf8_buf[0]) || + (partialpath && partialpossible && !core_stricmp(search_filename.c_str(), &m_utf8_buf[partialoffset]))); const bool found = ((!matchcrc && !matchname) || !f.IsDir) && (!matchcrc || crcmatch) && (!matchname || namematch); if (found) diff --git a/src/lib/util/unzip.cpp b/src/lib/util/unzip.cpp index 2751f83ffb6..6a9e407252d 100644 --- a/src/lib/util/unzip.cpp +++ b/src/lib/util/unzip.cpp @@ -156,26 +156,27 @@ public: int first_file() { m_cd_pos = 0; - return search(0, std::string(), false, false); + return search(0, std::string(), false, false, false); } int next_file() { - return search(0, std::string(), false, false); + return search(0, std::string(), false, false, false); } + int search(std::uint32_t crc) { m_cd_pos = 0; - return search(crc, std::string(), true, false); + return search(crc, std::string(), true, false, false); } - int search(const std::string &filename) + int search(const std::string &filename, bool partialpath) { m_cd_pos = 0; - return search(0, filename, false, true); + return search(0, filename, false, true, partialpath); } - int search(std::uint32_t crc, const std::string &filename) + int search(std::uint32_t crc, const std::string &filename, bool partialpath) { m_cd_pos = 0; - return search(crc, filename, true, true); + return search(crc, filename, true, true, partialpath); } bool current_is_directory() const { return m_curr_is_dir; } @@ -191,7 +192,7 @@ private: zip_file_impl &operator=(const zip_file_impl &) = delete; zip_file_impl &operator=(zip_file_impl &&) = delete; - int search(std::uint32_t search_crc, const std::string &search_filename, bool matchcrc, bool matchname); + int search(std::uint32_t search_crc, const std::string &search_filename, bool matchcrc, bool matchname, bool partialpath); archive_file::error reopen() { @@ -281,9 +282,18 @@ public: virtual int first_file() override { return m_impl->first_file(); } virtual int next_file() override { return m_impl->next_file(); } - virtual int search(std::uint32_t crc) override { return m_impl->search(crc); } - virtual int search(const std::string &filename) override { return m_impl->search(filename); } - virtual int search(std::uint32_t crc, const std::string &filename) override { return m_impl->search(crc, filename); } + virtual int search(std::uint32_t crc) override + { + return m_impl->search(crc); + } + virtual int search(const std::string &filename, bool partialpath) override + { + return m_impl->search(filename, partialpath); + } + virtual int search(std::uint32_t crc, const std::string &filename, bool partialpath) override + { + return m_impl->search(crc, filename, partialpath); + } virtual bool current_is_directory() const override { return m_impl->current_is_directory(); } virtual const std::string ¤t_name() const override { return m_impl->current_name(); } @@ -396,7 +406,7 @@ void zip_file_impl::close(ptr &&zip) in the ZIP -------------------------------------------------*/ -int zip_file_impl::search(std::uint32_t search_crc, const std::string &search_filename, bool matchcrc, bool matchname) +int zip_file_impl::search(std::uint32_t search_crc, const std::string &search_filename, bool matchcrc, bool matchname, bool partialpath) { // if we're at or past the end, we're done std::string filename; @@ -437,7 +447,11 @@ int zip_file_impl::search(std::uint32_t search_crc, const std::string &search_fi // check to see if it matches query bool const crcmatch(search_crc == m_header.crc); - const bool namematch(!core_stricmp(search_filename.c_str(), filename.c_str())); + auto const partialoffset(filename.length() - search_filename.length()); + bool const partialpossible((filename.length() > search_filename.length()) && (filename[partialoffset - 1] == '/')); + const bool namematch( + !core_stricmp(search_filename.c_str(), filename.c_str()) || + (partialpath && partialpossible && !core_stricmp(search_filename.c_str(), filename.c_str() + partialoffset))); bool const found = ((!matchcrc && !matchname) || !is_dir) && (!matchcrc || crcmatch) && (!matchname || namematch); if (found) diff --git a/src/lib/util/unzip.h b/src/lib/util/unzip.h index 5fafaec57a4..928e6ef56d5 100644 --- a/src/lib/util/unzip.h +++ b/src/lib/util/unzip.h @@ -71,8 +71,8 @@ public: // find a file index by crc, filename or both - returns non-negative on match virtual int search(std::uint32_t crc) = 0; - virtual int search(const std::string &filename) = 0; - virtual int search(std::uint32_t crc, const std::string &filename) = 0; + virtual int search(const std::string &filename, bool partialpath) = 0; + virtual int search(std::uint32_t crc, const std::string &filename, bool partialpath) = 0; // information on most recently found file virtual bool current_is_directory() const = 0; |