[DEV] start searching file property for Auto package in one file

This commit is contained in:
Edouard DUPIN 2015-04-22 23:59:53 +02:00
parent d98a438428
commit 742a070307
7 changed files with 85 additions and 35 deletions

View File

@ -60,13 +60,13 @@ void etk::Archive::display()
}
etk::Archive* etk::Archive::load(const std::string& _fileName) {
etk::Archive* output=NULL;
etk::Archive* output=nullptr;
std::string tmpName = etk::tolower(_fileName);
// select the corect Loader :
if( true == end_with(tmpName, ".zip")
|| true == end_with(tmpName, ".apk") ) {
output = new etk::archive::Zip(_fileName);
if (NULL==output) {
if (nullptr==output) {
TK_ERROR("An error occured when load archive : " << _fileName);
}
} else {
@ -75,6 +75,39 @@ etk::Archive* etk::Archive::load(const std::string& _fileName) {
return output;
}
etk::Archive* etk::Archive::loadPackage(const std::string& _fileName) {
etk::Archive* output=nullptr;
FILE* file = fopen(_fileName.c_str(), "rb");
if (file == nullptr) {
TK_ERROR("Can not open file : '" << _fileName);
return nullptr;
}
// move to end - 16 bytes:
fseek(file, -8, SEEK_END);
// get the basic binary size
uint64_t position = 0;
fread(&position, 1, sizeof(uint64_t), file);
TK_ERROR("position = " << position);
// move to the position
fseek(file, position, SEEK_SET);
char plop[1024];
fread(plop, 1, 16, file);
plop[16] = '\0';
// check if we have the mark: "***START DATA***" ==> if not ==> error
if (std::string(plop) != "***START DATA***") {
TK_ERROR("Error in the tag file : '" << plop << "'");
fclose(file);
return nullptr;
}
fclose(file);
file = nullptr;
output = new etk::archive::Zip(_fileName, position);
if (nullptr==output) {
TK_ERROR("An error occured when load archive : " << _fileName);
}
return output;
}
void etk::Archive::open(const std::string& _key) {
auto it = m_content.find(_key);

View File

@ -128,6 +128,12 @@ namespace etk {
* @return A pointer an the specified archive, the user might delete it.
*/
static Archive* load(const std::string& _fileName);
/**
* @brief Load an Achive with a specific name in package mode ==> this mean the data is associated with the basic binary.
* @param[in] _fileName File name of the specific archive.
* @return A pointer an the specified archive, the user might delete it.
*/
static Archive* loadPackage(const std::string& _fileName);
/**
* @brief Create an Achive with a specific name.

View File

@ -11,11 +11,11 @@
#include <etk/archive/Zip.h>
#include <etk/types.h>
etk::archive::Zip::Zip(const std::string& _fileName) :
etk::archive::Zip::Zip(const std::string& _fileName, uint64_t _offset) :
etk::Archive(_fileName),
m_ctx(nullptr) {
/* Open the zip file */
m_ctx = unzOpen(m_fileName.c_str());
m_ctx = unzOpenOffset(m_fileName.c_str(), _offset);
if(!m_ctx) {
TK_ERROR("Unable to open the zip file '" << m_fileName << "'");
return;

View File

@ -21,7 +21,7 @@
unzFile m_ctx; //!< mini zip context
unz_global_info m_info; //!< global information of the Zip
public:
Zip(const std::string& _fileName);
Zip(const std::string& _fileName, uint64_t _offset = 0LL);
virtual ~Zip();
protected: // herited functions :
virtual void loadFile(const std::map<std::string, ArchiveContent>::iterator& it);

View File

@ -25,7 +25,7 @@ extern "C" {
#include <errno.h>
}
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
# include <etk/archive/Archive.h>
#endif
@ -152,12 +152,22 @@ static std::string baseRunPathInHome = "/";
#ifdef __TARGET_OS__Android
static etk::Archive* s_APKArchive = NULL;
static etk::Archive* s_APKArchive = nullptr;
static void loadAPK(std::string& _apkPath)
{
TK_DEBUG("Loading APK \"" << _apkPath << "\"");
s_APKArchive = etk::Archive::load(_apkPath);
TK_ASSERT(s_APKArchive != NULL, "Error loading APK ... \"" << _apkPath << "\"");
TK_ASSERT(s_APKArchive != nullptr, "Error loading APK ... \"" << _apkPath << "\"");
//Just for debug, print APK contents
s_APKArchive->display();
}
#elif defined(__TARGET_OS__Windows)
static etk::Archive* s_APKArchive = nullptr;
static void loadAPK(std::string& _apkPath)
{
TK_DEBUG("Loading APK \"" << _apkPath << "\"");
s_APKArchive = etk::Archive::loadPackage(_apkPath);
TK_ASSERT(s_APKArchive != nullptr, "Error loading APK ... \"" << _apkPath << "\"");
//Just for debug, print APK contents
s_APKArchive->display();
}
@ -221,6 +231,7 @@ std::string getApplicationPath() {
TK_CRITICAL("Can not get the binary position in the tree ==> this is really bad ...");
} else {
binaryName = binaryCompleatePath;
loadAPK(binaryName);
}
#else
// check it to prevent test mode in local folder ...
@ -423,7 +434,7 @@ std::string etk::getUserRunFolder() {
#endif
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
bool etk::FSNode::loadDataZip() {
if (s_APKArchive == nullptr) {
return false;
@ -499,7 +510,7 @@ etk::FSNode::FSNode(const std::string& _nodeName) :
m_timeCreate(0),
m_timeModify(0),
m_timeAccess(0)
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
, m_zipContent(NULL),
m_zipReadingOffset(-1)
#endif
@ -515,7 +526,7 @@ etk::FSNode::FSNode(const std::string& _nodeName) :
m_timeCreate(0),
m_timeModify(0),
m_timeAccess(0)
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
, m_zipContent(NULL),
m_zipReadingOffset(-1)
#endif
@ -527,7 +538,7 @@ etk::FSNode::FSNode(const std::string& _nodeName) :
etk::FSNode::~FSNode() {
if( NULL != m_PointerFile
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
|| NULL != m_zipContent
#endif
) {
@ -560,7 +571,7 @@ void etk::FSNode::sortElementList(std::vector<etk::FSNode *>& _list) {
void etk::FSNode::privateSetName(const std::string& _newName) {
if( NULL != m_PointerFile
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
|| NULL != m_zipContent
#endif
) {
@ -570,7 +581,7 @@ void etk::FSNode::privateSetName(const std::string& _newName) {
// set right at NULL ...
m_rights = 0;
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
m_zipContent = NULL;
m_zipReadingOffset = 0;
#endif
@ -732,7 +743,7 @@ void etk::FSNode::privateSetName(const std::string& _newName) {
#endif
bool directCheckFile(std::string _tmpFileNameDirect, bool _checkInAPKIfNeeded = false) {
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
if (true == _checkInAPKIfNeeded) {
if( NULL != s_APKArchive
&& true == s_APKArchive->exist(_tmpFileNameDirect) ) {
@ -860,7 +871,7 @@ void etk::FSNode::updateFileSystemProperty() {
// File type is not knowns ...
m_typeNode=FSN_UNKNOW;
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
if( m_type == etk::FSN_TYPE_DATA
|| m_type == etk::FSN_TYPE_THEME_DATA) {
// ----------------------------------------
@ -1180,7 +1191,7 @@ const etk::FSNode& etk::FSNode::operator= (const etk::FSNode &_obj ) {
return *this;
}
if( NULL != m_PointerFile
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
|| NULL != m_zipContent
#endif
) {
@ -1188,7 +1199,7 @@ const etk::FSNode& etk::FSNode::operator= (const etk::FSNode &_obj ) {
fileClose();
m_PointerFile = NULL;
}
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
m_zipContent = NULL;
m_zipReadingOffset = 0;
#endif
@ -1323,7 +1334,7 @@ std::vector<etk::FSNode *> etk::FSNode::folderGetSubList(bool _showHidenFile, bo
if (m_typeNode != etk::FSN_FOLDER ) {
return tmpp;
}
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
if( m_type == etk::FSN_TYPE_DATA
|| m_type == etk::FSN_TYPE_THEME_DATA) {
std::vector<std::string> listAdded;
@ -1417,7 +1428,7 @@ etk::FSNode etk::FSNode::folderGetParent() {
}
void etk::FSNode::folderGetRecursiveFiles(std::vector<std::string>& _output, bool _recursiveEnable) {
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
if( m_type == etk::FSN_TYPE_DATA
|| m_type == etk::FSN_TYPE_THEME_DATA) {
std::string assetsName = "assets/";
@ -1528,7 +1539,7 @@ uint64_t etk::FSNode::fileSize() {
TK_ERROR("Request size of a non file node : " << m_typeNode);
return 0;
}
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
if( etk::FSN_TYPE_DATA == m_type
|| etk::FSN_TYPE_THEME_DATA == m_type) {
if (true == loadDataZip()) {
@ -1554,7 +1565,7 @@ uint64_t etk::FSNode::fileSize() {
bool etk::FSNode::fileOpenRead() {
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
if( etk::FSN_TYPE_DATA == m_type
|| etk::FSN_TYPE_THEME_DATA == m_type) {
if (false==loadDataZip()) {
@ -1577,7 +1588,7 @@ bool etk::FSNode::fileOpenRead() {
return true;
}
bool etk::FSNode::fileOpenWrite() {
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
if( etk::FSN_TYPE_DATA == m_type
|| etk::FSN_TYPE_THEME_DATA == m_type) {
return false;
@ -1598,7 +1609,7 @@ bool etk::FSNode::fileOpenWrite() {
}
bool etk::FSNode::fileOpenAppend() {
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
if( etk::FSN_TYPE_DATA == m_type
|| etk::FSN_TYPE_THEME_DATA == m_type) {
return false;
@ -1621,7 +1632,7 @@ bool etk::FSNode::fileOpenAppend() {
}
bool etk::FSNode::fileClose() {
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
if( etk::FSN_TYPE_DATA == m_type
|| etk::FSN_TYPE_THEME_DATA == m_type) {
if (m_zipContent == NULL) {
@ -1645,7 +1656,7 @@ bool etk::FSNode::fileClose() {
char* etk::FSNode::fileGets(char* _elementLine, int64_t _maxData) {
memset(_elementLine, 0, _maxData);
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
char * element = _elementLine;
int64_t outSize = 0;
if( m_type == etk::FSN_TYPE_DATA
@ -1715,7 +1726,7 @@ bool etk::FSNode::fileGets(std::string& _output) {
}
int64_t etk::FSNode::fileRead(void* _data, int64_t _blockSize, int64_t _nbBlock) {
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
if( m_type == etk::FSN_TYPE_DATA
|| m_type == etk::FSN_TYPE_THEME_DATA) {
if (m_zipContent == NULL) {
@ -1750,7 +1761,7 @@ bool etk::FSNode::filePuts(const std::string& _input) {
}
int64_t etk::FSNode::fileWrite(const void * _data, int64_t _blockSize, int64_t _nbBlock) {
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
if( m_type == etk::FSN_TYPE_DATA
|| m_type == etk::FSN_TYPE_THEME_DATA) {
TK_CRITICAL("Can not write on data inside APK : " << *this);
@ -1802,7 +1813,7 @@ etk::FSNode& etk::FSNode::operator<< (const float _data) {
bool etk::FSNode::fileSeek(long int _offset, enum etk::seekNode _origin)
{
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
if( m_type == etk::FSN_TYPE_DATA
|| m_type == etk::FSN_TYPE_THEME_DATA) {
if (NULL == m_zipContent) {
@ -1850,7 +1861,7 @@ bool etk::FSNode::fileSeek(long int _offset, enum etk::seekNode _origin)
}
}
int64_t etk::FSNode::fileTell() {
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
if( m_type == etk::FSN_TYPE_DATA
|| m_type == etk::FSN_TYPE_THEME_DATA) {
if (NULL == m_zipContent) {
@ -1864,7 +1875,7 @@ int64_t etk::FSNode::fileTell() {
}
void etk::FSNode::fileFlush() {
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
if( m_type == etk::FSN_TYPE_DATA
|| m_type == etk::FSN_TYPE_THEME_DATA) {
return;

View File

@ -17,7 +17,7 @@
//http://developer.android.com/guide/topics/data/data-storage.html
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
namespace etk {
class ArchiveContent;
}
@ -168,7 +168,7 @@ namespace etk {
void privateSetName(const std::u32string& _newName);
#endif
private:
#ifdef __TARGET_OS__Android
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
/**
* @brief Explocitly for Android that data are stored in the .apk that is a .zip not compressed
* @return true : Load is OK

View File

@ -60,9 +60,9 @@ def create(target):
myModule.add_export_path(tools.get_current_path(__file__) + "/binding_X11")
if target.name=="Windows":
None
pass
elif target.name=="Android":
None
pass
else:
myModule.add_export_flag_LD("-lpthread")