[DEBUG] correct android multiple interface of FSNode
This commit is contained in:
parent
14ccfbc7d7
commit
324acb431d
@ -15,6 +15,7 @@ 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 {
|
||||||
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
size_t id = 0;
|
size_t id = 0;
|
||||||
for (auto &it : m_content) {
|
for (auto &it : m_content) {
|
||||||
if (id == _id) {
|
if (id == _id) {
|
||||||
@ -27,6 +28,7 @@ const std::string& etk::Archive::getName(size_t _id) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const etk::ArchiveContent& etk::Archive::getContent(size_t _id) const {
|
const etk::ArchiveContent& etk::Archive::getContent(size_t _id) const {
|
||||||
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
size_t id = 0;
|
size_t id = 0;
|
||||||
for (auto &it : m_content) {
|
for (auto &it : m_content) {
|
||||||
if (id == _id) {
|
if (id == _id) {
|
||||||
@ -38,6 +40,7 @@ const etk::ArchiveContent& etk::Archive::getContent(size_t _id) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const etk::ArchiveContent& etk::Archive::getContent(const std::string& _key) const {
|
const etk::ArchiveContent& etk::Archive::getContent(const std::string& _key) const {
|
||||||
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
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;
|
||||||
@ -47,11 +50,12 @@ const etk::ArchiveContent& etk::Archive::getContent(const std::string& _key) con
|
|||||||
|
|
||||||
|
|
||||||
bool etk::Archive::exist(const std::string& _key) const {
|
bool etk::Archive::exist(const std::string& _key) const {
|
||||||
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
return m_content.find(_key) != m_content.end();
|
return m_content.find(_key) != m_content.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void etk::Archive::display()
|
void etk::Archive::display() {
|
||||||
{
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
for (auto &it : m_content) {
|
for (auto &it : m_content) {
|
||||||
int32_t size = it.second.getTheoricSize();
|
int32_t size = it.second.getTheoricSize();
|
||||||
int32_t sizeR = it.second.size();
|
int32_t sizeR = it.second.size();
|
||||||
@ -110,6 +114,7 @@ etk::Archive* etk::Archive::loadPackage(const std::string& _fileName) {
|
|||||||
|
|
||||||
|
|
||||||
void etk::Archive::open(const std::string& _key) {
|
void etk::Archive::open(const std::string& _key) {
|
||||||
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
auto it = m_content.find(_key);
|
auto it = m_content.find(_key);
|
||||||
if (it == m_content.end()) {
|
if (it == m_content.end()) {
|
||||||
TK_ERROR("Try open an unexistant file : '" << _key << "'");
|
TK_ERROR("Try open an unexistant file : '" << _key << "'");
|
||||||
@ -123,6 +128,7 @@ void etk::Archive::open(const std::string& _key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void etk::Archive::close(const std::string& _key) {
|
void etk::Archive::close(const std::string& _key) {
|
||||||
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
auto it = m_content.find(_key);
|
auto it = m_content.find(_key);
|
||||||
if (it == m_content.end()) {
|
if (it == m_content.end()) {
|
||||||
TK_ERROR("Try close an unexistant file : '" << _key << "'");
|
TK_ERROR("Try close an unexistant file : '" << _key << "'");
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#define __ETK_ARCHIVE_H__
|
#define __ETK_ARCHIVE_H__
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <mutex>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace etk {
|
namespace etk {
|
||||||
class ArchiveContent {
|
class ArchiveContent {
|
||||||
@ -51,6 +53,8 @@ namespace etk {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
class Archive {
|
class Archive {
|
||||||
|
private:
|
||||||
|
mutable std::mutex m_mutex;
|
||||||
public:
|
public:
|
||||||
Archive(const std::string& _fileName) :
|
Archive(const std::string& _fileName) :
|
||||||
m_fileName(_fileName) {
|
m_fileName(_fileName) {
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <etk/tool.h>
|
#include <etk/tool.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <mutex>
|
||||||
#ifdef __TARGET_OS__Windows
|
#ifdef __TARGET_OS__Windows
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -126,7 +127,10 @@ std::string etk::simplifyPath(std::string _input) {
|
|||||||
return _input;
|
return _input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::mutex& getNodeMutex() {
|
||||||
|
static std::mutex g_nodeMutex;
|
||||||
|
return g_nodeMutex;
|
||||||
|
}
|
||||||
|
|
||||||
// zip file of the apk file for Android ==> set to zip file apk access
|
// zip file of the apk file for Android ==> set to zip file apk access
|
||||||
static std::string s_fileAPK = "";
|
static std::string s_fileAPK = "";
|
||||||
@ -156,9 +160,9 @@ std::string etk::FSNodeGetApplicationName() {
|
|||||||
|
|
||||||
#ifdef __TARGET_OS__Android
|
#ifdef __TARGET_OS__Android
|
||||||
static etk::Archive* s_APKArchive = nullptr;
|
static etk::Archive* s_APKArchive = nullptr;
|
||||||
static void loadAPK(std::string& _apkPath)
|
static void loadAPK(std::string& _apkPath) {
|
||||||
{
|
std::unique_lock<std::mutex> lock(getNodeMutex());
|
||||||
TK_DEBUG("Loading APK \"" << _apkPath << "\"");
|
TK_INFO("Loading APK \"" << _apkPath << "\"");
|
||||||
s_APKArchive = etk::Archive::load(_apkPath);
|
s_APKArchive = etk::Archive::load(_apkPath);
|
||||||
TK_ASSERT(s_APKArchive != nullptr, "Error loading APK ... \"" << _apkPath << "\"");
|
TK_ASSERT(s_APKArchive != nullptr, "Error loading APK ... \"" << _apkPath << "\"");
|
||||||
//Just for debug, print APK contents
|
//Just for debug, print APK contents
|
||||||
@ -166,8 +170,8 @@ std::string etk::FSNodeGetApplicationName() {
|
|||||||
}
|
}
|
||||||
#elif defined(__TARGET_OS__Windows)
|
#elif defined(__TARGET_OS__Windows)
|
||||||
static etk::Archive* s_APKArchive = nullptr;
|
static etk::Archive* s_APKArchive = nullptr;
|
||||||
static void loadAPK(std::string& _apkPath)
|
static void loadAPK(std::string& _apkPath) {
|
||||||
{
|
std::unique_lock<std::mutex> lock(getNodeMutex());
|
||||||
TK_DEBUG("Loading APK \"" << _apkPath << "\"");
|
TK_DEBUG("Loading APK \"" << _apkPath << "\"");
|
||||||
s_APKArchive = etk::Archive::loadPackage(_apkPath);
|
s_APKArchive = etk::Archive::loadPackage(_apkPath);
|
||||||
TK_ASSERT(s_APKArchive != nullptr, "Error loading APK ... \"" << _apkPath << "\"");
|
TK_ASSERT(s_APKArchive != nullptr, "Error loading APK ... \"" << _apkPath << "\"");
|
||||||
@ -177,19 +181,21 @@ std::string etk::FSNodeGetApplicationName() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// for specific device contraint :
|
// for specific device contraint :
|
||||||
void etk::setBaseFolderData(const char* _folder)
|
void etk::setBaseFolderData(const char* _folder) {
|
||||||
{
|
|
||||||
#ifdef __TARGET_OS__Android
|
#ifdef __TARGET_OS__Android
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(getNodeMutex());
|
||||||
baseFolderData = "assets/";
|
baseFolderData = "assets/";
|
||||||
s_fileAPK = _folder;
|
s_fileAPK = _folder;
|
||||||
|
}
|
||||||
loadAPK(s_fileAPK);
|
loadAPK(s_fileAPK);
|
||||||
#else
|
#else
|
||||||
TK_WARNING("Not Availlable Outside Android");
|
TK_WARNING("Not Availlable Outside Android");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void etk::setBaseFolderDataUser(const char* _folder)
|
void etk::setBaseFolderDataUser(const char* _folder) {
|
||||||
{
|
std::unique_lock<std::mutex> lock(getNodeMutex());
|
||||||
#ifdef __TARGET_OS__Android
|
#ifdef __TARGET_OS__Android
|
||||||
baseFolderDataUser = _folder;
|
baseFolderDataUser = _folder;
|
||||||
#else
|
#else
|
||||||
@ -197,8 +203,8 @@ void etk::setBaseFolderDataUser(const char* _folder)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void etk::setBaseFolderCache(const char* _folder)
|
void etk::setBaseFolderCache(const char* _folder) {
|
||||||
{
|
std::unique_lock<std::mutex> lock(getNodeMutex());
|
||||||
#ifdef __TARGET_OS__Android
|
#ifdef __TARGET_OS__Android
|
||||||
baseFolderCache = _folder;
|
baseFolderCache = _folder;
|
||||||
#else
|
#else
|
||||||
@ -208,6 +214,7 @@ void etk::setBaseFolderCache(const char* _folder)
|
|||||||
|
|
||||||
std::string l_argZero = "";
|
std::string l_argZero = "";
|
||||||
void etk::setArgZero(const std::string& _val) {
|
void etk::setArgZero(const std::string& _val) {
|
||||||
|
std::unique_lock<std::mutex> lock(getNodeMutex());
|
||||||
l_argZero = _val;
|
l_argZero = _val;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -439,6 +446,7 @@ std::string etk::getUserRunFolder() {
|
|||||||
|
|
||||||
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
|
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__Windows))
|
||||||
bool etk::FSNode::loadDataZip() {
|
bool etk::FSNode::loadDataZip() {
|
||||||
|
std::unique_lock<std::mutex> lock(getNodeMutex());
|
||||||
if (s_APKArchive == nullptr) {
|
if (s_APKArchive == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1574,6 +1582,7 @@ bool etk::FSNode::fileOpenRead() {
|
|||||||
if (false==loadDataZip()) {
|
if (false==loadDataZip()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
std::unique_lock<std::mutex> lock(getNodeMutex());
|
||||||
s_APKArchive->open(m_systemFileName);
|
s_APKArchive->open(m_systemFileName);
|
||||||
return m_zipContent->getTheoricSize() == m_zipContent->size();
|
return m_zipContent->getTheoricSize() == m_zipContent->size();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user