add iOS support

This commit is contained in:
2017-05-07 23:49:46 +01:00
parent b50011babf
commit d1ce547abd
16 changed files with 682 additions and 20 deletions

View File

@@ -2,14 +2,19 @@
#include "log.h"
#include "asset.h"
#ifdef __IOS__
#include <Foundation/Foundation.h>
#endif
#ifdef __ANDROID__
AAssetManager* Asset::m_am;
#endif
bool Asset::open(const char* path)
{
//LOG("Asset::open %s", path);
LOG("Asset::open %s", path);
m_current_path = path;
std::string file_path = path;
#ifdef __ANDROID__
if (!(m_asset = AAssetManager_open(m_am, path, AASSET_MODE_RANDOM)))
{
@@ -19,8 +24,16 @@ bool Asset::open(const char* path)
m_len = (int)AAsset_getLength(m_asset);
m_data = (uint8_t*)AAsset_getBuffer(m_asset);
#else
if (!(m_fp = fopen(path, "rb")))
#ifdef __IOS__
NSString* bundle_path = [[NSBundle mainBundle] bundlePath];
std::string base = [bundle_path cStringUsingEncoding:1];
file_path = base + "/" + path;
#endif
if (!(m_fp = fopen(file_path.c_str(), "rb")))
{
LOG("errno = %d", errno);
return false;
}
fseek(m_fp, 0, SEEK_END);
m_len = (int)ftell(m_fp);
fseek(m_fp, 0, SEEK_SET);