[DEV] correct the interface of acess of android zip file interface

This commit is contained in:
Edouard DUPIN 2015-04-21 22:58:06 +02:00
parent e9583aa311
commit d98a438428
7 changed files with 56 additions and 51 deletions

View File

@ -11,7 +11,7 @@
#include <etk/archive/Zip.h> #include <etk/archive/Zip.h>
#include <etk/debug.h> #include <etk/debug.h>
static const etk::Archive::Content g_error; static const etk::ArchiveContent g_error;
const std::string& etk::Archive::getName(size_t _id) const { const std::string& etk::Archive::getName(size_t _id) const {
@ -26,7 +26,7 @@ const std::string& etk::Archive::getName(size_t _id) const {
return error; return error;
} }
const etk::Archive::Content& etk::Archive::getContent(size_t _id) const { const etk::ArchiveContent& etk::Archive::getContent(size_t _id) const {
size_t id = 0; size_t id = 0;
for (auto &it : m_content) { for (auto &it : m_content) {
if (id == _id) { if (id == _id) {
@ -37,7 +37,7 @@ const etk::Archive::Content& etk::Archive::getContent(size_t _id) const {
return g_error; return g_error;
} }
const etk::Archive::Content& etk::Archive::getContent(const std::string& _key) const { const etk::ArchiveContent& etk::Archive::getContent(const std::string& _key) const {
auto it = m_content.find(_key); auto it = m_content.find(_key);
if (it == m_content.end()) { if (it == m_content.end()) {
return g_error; return g_error;

View File

@ -15,43 +15,42 @@
#include <map> #include <map>
namespace etk { namespace etk {
class Archive { class ArchiveContent {
private:
int32_t m_link; //!< number of element open on this file
public: public:
class Content { void increaseRef() {
private: m_link++;
int32_t m_link; //!< number of element open on this file
public:
void increaseRef() {
m_link++;
};
void decreaseRef() {
m_link--;
};
int32_t getNumberOfRef() const {
return m_link;
};
private:
int32_t m_theoricSize; //!< number of element open on this file
public:
int32_t getTheoricSize() const {
return m_theoricSize;
};
private:
std::vector<char> m_data;
public:
Content(int32_t _basicSize=0) :
m_link(-1),
m_theoricSize(_basicSize) { };
int32_t size() const {
return m_data.size();
};
void* data() const {
return (void*)&m_data[0];
};
std::vector<char>& getDataVector() {
return m_data;
};
}; };
void decreaseRef() {
m_link--;
};
int32_t getNumberOfRef() const {
return m_link;
};
private:
int32_t m_theoricSize; //!< number of element open on this file
public:
int32_t getTheoricSize() const {
return m_theoricSize;
};
private:
std::vector<char> m_data;
public:
ArchiveContent(int32_t _basicSize=0) :
m_link(-1),
m_theoricSize(_basicSize) { };
int32_t size() const {
return m_data.size();
};
void* data() const {
return (void*)&m_data[0];
};
std::vector<char>& getDataVector() {
return m_data;
};
};
class Archive {
public: public:
Archive(const std::string& _fileName) : Archive(const std::string& _fileName) :
m_fileName(_fileName) { m_fileName(_fileName) {
@ -69,7 +68,7 @@ namespace etk {
return m_fileName; return m_fileName;
}; };
protected: protected:
std::map<std::string, Content> m_content; std::map<std::string, ArchiveContent> m_content;
public: public:
/** /**
* @brief Get the number of elements * @brief Get the number of elements
@ -89,13 +88,13 @@ namespace etk {
* @param[in] _id id of the element (must be < Size()) * @param[in] _id id of the element (must be < Size())
* @return the archive content * @return the archive content
*/ */
const Content& getContent(size_t _id) const; const ArchiveContent& getContent(size_t _id) const;
/** /**
* @brief Get the File name of the ID * @brief Get the File name of the ID
* @param[in] _key name of the file * @param[in] _key name of the file
* @return FileName of the requested id * @return FileName of the requested id
*/ */
const Content& getContent(const std::string& _key) const; const ArchiveContent& getContent(const std::string& _key) const;
/** /**
* @brief Check if a file exist * @brief Check if a file exist
* @param[in] _key Name of the file * @param[in] _key Name of the file
@ -121,7 +120,7 @@ namespace etk {
* @brief Request the load in memory of the concerned file. * @brief Request the load in memory of the concerned file.
* @param[in] _id Id of the file to load. * @param[in] _id Id of the file to load.
*/ */
virtual void loadFile(const std::map<std::string, Content>::iterator& it) { }; virtual void loadFile(const std::map<std::string, ArchiveContent>::iterator& it) { };
public: public:
/** /**
* @brief Load an Achive with a specific name. * @brief Load an Achive with a specific name.

View File

@ -38,7 +38,7 @@ etk::archive::Zip::Zip(const std::string& _fileName) :
if(tmpFileName[strlen(tmpFileName) - 1] == '/' ) { if(tmpFileName[strlen(tmpFileName) - 1] == '/' ) {
// find directory ... // find directory ...
} else { } else {
m_content.insert(std::pair<std::string, etk::Archive::Content>(tmpFileName, etk::Archive::Content(tmpFileInfo.uncompressed_size))); m_content.insert(std::pair<std::string, etk::ArchiveContent>(tmpFileName, etk::ArchiveContent(tmpFileInfo.uncompressed_size)));
} }
/* Go the the next entry listed in the zip file. */ /* Go the the next entry listed in the zip file. */
if((iii+1) < m_info.number_entry) { if((iii+1) < m_info.number_entry) {
@ -57,7 +57,7 @@ etk::archive::Zip::~Zip() {
}; };
} }
void etk::archive::Zip::loadFile(const std::map<std::string, Content>::iterator& it) { void etk::archive::Zip::loadFile(const std::map<std::string, ArchiveContent>::iterator& it) {
TK_VERBOSE("Real load file : '" << it->first << "'"); TK_VERBOSE("Real load file : '" << it->first << "'");
unzGoToFirstFile(m_ctx); unzGoToFirstFile(m_ctx);

View File

@ -24,7 +24,7 @@
Zip(const std::string& _fileName); Zip(const std::string& _fileName);
virtual ~Zip(); virtual ~Zip();
protected: // herited functions : protected: // herited functions :
virtual void loadFile(const std::map<std::string, Content>::iterator& it); virtual void loadFile(const std::map<std::string, ArchiveContent>::iterator& it);
}; };
}; };
}; };

View File

@ -25,6 +25,10 @@ extern "C" {
#include <errno.h> #include <errno.h>
} }
#ifdef __TARGET_OS__Android
# include <etk/archive/Archive.h>
#endif
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
// For ctime // For ctime

View File

@ -13,14 +13,15 @@
#include <etk/os/FSNodeRight.h> #include <etk/os/FSNodeRight.h>
#ifdef __TARGET_OS__Android
# include <etk/archive/Archive.h>
#endif
#define MAX_FILE_NAME (10240) #define MAX_FILE_NAME (10240)
//http://developer.android.com/guide/topics/data/data-storage.html //http://developer.android.com/guide/topics/data/data-storage.html
#ifdef __TARGET_OS__Android
namespace etk {
class ArchiveContent;
}
#endif
namespace etk { namespace etk {
void setArgZero(const std::string& _val); void setArgZero(const std::string& _val);
std::string simplifyPath(std::string _input); std::string simplifyPath(std::string _input);
@ -174,7 +175,7 @@ namespace etk {
* @return false : An error Occured * @return false : An error Occured
*/ */
bool loadDataZip(); bool loadDataZip();
const etk::Archive::Content* m_zipContent; const etk::ArchiveContent* m_zipContent;
int32_t m_zipReadingOffset; int32_t m_zipReadingOffset;
#endif #endif
public: public:

View File

@ -45,6 +45,7 @@ def create(target):
if target.name != "Windows": if target.name != "Windows":
myModule.add_export_flag_LD("-ldl -rdynamic") myModule.add_export_flag_LD("-ldl -rdynamic")
# for ald C++ compatibility (old GCC) just link with boost ...
if target.config["compilator"] == "gcc" \ if target.config["compilator"] == "gcc" \
and target.xx_version < 4007000: and target.xx_version < 4007000:
# note : this framework depend on C++ 11, but a simple port of Boost for old compatibility has been done ... # note : this framework depend on C++ 11, but a simple port of Boost for old compatibility has been done ...
@ -54,8 +55,8 @@ def create(target):
else: else:
myModule.compile_version_XX(2011) myModule.compile_version_XX(2011)
# name of the dependency # name of the dependency
myModule.add_optionnal_module_depend('linearmath', "ETK_BUILD_LINEARMATH", export=True)
myModule.add_optionnal_module_depend('minizip', "ETK_BUILD_MINIZIP") myModule.add_optionnal_module_depend('minizip', "ETK_BUILD_MINIZIP")
myModule.add_optionnal_module_depend('linearmath', "ETK_BUILD_LINEARMATH", export=True)
myModule.add_export_path(tools.get_current_path(__file__) + "/binding_X11") myModule.add_export_path(tools.get_current_path(__file__) + "/binding_X11")
if target.name=="Windows": if target.name=="Windows":