Mercurial > code
changeset 285:9b6990fa8fd9
Zip:
* add unchange functions
* add password
* add numEntries
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 11 Nov 2014 14:52:25 +0100 |
parents | 9be2cd100167 |
children | 2ff6559c5f1d |
files | C++/ZipArchive.cpp C++/ZipArchive.h |
diffstat | 2 files changed, 98 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/C++/ZipArchive.cpp Tue Nov 11 14:04:36 2014 +0100 +++ b/C++/ZipArchive.cpp Tue Nov 11 14:52:25 2014 +0100 @@ -69,7 +69,7 @@ { auto src = zip_source_file(archive, m_path.c_str(), m_start, m_length); - if (!src) + if (src == nullptr) throw std::runtime_error(zip_strerror(archive)); return src; @@ -246,3 +246,50 @@ if (zip_delete(m_handle.get(), index) < 0) throw std::runtime_error(zip_strerror(m_handle.get())); } + +ZipInt64 ZipArchive::numEntries(ZipFlags flags) const +{ + return zip_get_num_entries(m_handle.get(), flags); +} + +void ZipArchive::unchange(ZipUint64 index) +{ + if (zip_unchange(m_handle.get(), index) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); +} + +void ZipArchive::unchangeAll() +{ + if (zip_unchange_all(m_handle.get()) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); +} + +void ZipArchive::unchangeArchive() +{ + if (zip_unchange_archive(m_handle.get()) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); +} + +void ZipArchive::setDefaultPassword(const std::string &password) +{ + auto cstr = (password.size() > 0) ? password.c_str() : nullptr; + + if (zip_set_default_password(m_handle.get(), cstr) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); +} + +void ZipArchive::setFlag(ZipFlags flags, int value) +{ + if (zip_set_archive_flag(m_handle.get(), flags, value) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); +} + +int ZipArchive::getFlag(ZipFlags which, ZipFlags flags) const +{ + auto ret = zip_get_archive_flag(m_handle.get(), which, flags); + + if (ret < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); + + return ret; +}
--- a/C++/ZipArchive.h Tue Nov 11 14:04:36 2014 +0100 +++ b/C++/ZipArchive.h Tue Nov 11 14:52:25 2014 +0100 @@ -369,6 +369,56 @@ * @param index the file index in the archive */ void remove(ZipUint64 index); + + /** + * Get the number of entries in the archive. + * + * @param flags the optional flags + * @return the number of entries + */ + ZipInt64 numEntries(ZipFlags flags = 0) const; + + /** + * Revert changes on the file. + * + * @param index the index + */ + void unchange(ZipUint64 index); + + /** + * Revert all changes. + */ + void unchangeAll(); + + /** + * Revert changes to archive. + */ + void unchangeArchive(); + + /** + * Set the defaut password. + * + * @param password the password or empty to unset it + */ + void setDefaultPassword(const std::string &password = ""); + + /** + * Set an archive flag. + * + * @param flag the flag to set + * @param value the value + */ + void setFlag(ZipFlags flag, int value); + + /** + * Get an archive flag. + * + * @param which which flag + * @param flags the optional flags + * @return the value + */ + int getFlag(ZipFlags which, ZipFlags flags) const; + }; #endif // !_ZIP_ARCHIVE_H_