fix utf-16 reading and make it work on android
This commit is contained in:
@@ -139,13 +139,25 @@ bool Asset::open(const char* path)
|
||||
m_current_path = path;
|
||||
std::string file_path = path;
|
||||
#ifdef __ANDROID__
|
||||
if (!(m_asset = AAssetManager_open(m_am, path, AASSET_MODE_RANDOM)))
|
||||
if (is_asset(path))
|
||||
{
|
||||
LOG("AAssetManager_open failed %s", path);
|
||||
return false;
|
||||
if (!(m_asset = AAssetManager_open(m_am, path, AASSET_MODE_RANDOM)))
|
||||
{
|
||||
LOG("AAssetManager_open failed %s", path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(m_fp = fopen(file_path.c_str(), "rb")))
|
||||
{
|
||||
LOG("asset open errno = %d, %s", errno, path);
|
||||
return false;
|
||||
}
|
||||
fseek(m_fp, 0, SEEK_END);
|
||||
m_len = (int)ftell(m_fp);
|
||||
fseek(m_fp, 0, SEEK_SET);
|
||||
}
|
||||
m_len = (int)AAsset_getLength(m_asset);
|
||||
m_data = (uint8_t*)AAsset_getBuffer(m_asset);
|
||||
#else
|
||||
#ifdef __APPLE__
|
||||
NSString* bundle_path = [[NSBundle mainBundle] resourcePath];
|
||||
@@ -168,6 +180,24 @@ bool Asset::open(const char* path)
|
||||
glm::uint8_t* Asset::read_all()
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
if (!m_data)
|
||||
{
|
||||
if (is_asset(m_current_path))
|
||||
{
|
||||
m_len = (int)AAsset_getLength(m_asset);
|
||||
m_data = (uint8_t*)AAsset_getBuffer(m_asset);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_data = new uint8_t[m_len];
|
||||
if (m_len != fread(m_data, 1, m_len, m_fp))
|
||||
{
|
||||
LOG("ASSET READ FAILED for %s", m_current_path.c_str());
|
||||
delete[] m_data;
|
||||
m_data = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return m_data;
|
||||
#else
|
||||
if (!m_data)
|
||||
|
||||
Reference in New Issue
Block a user