| 59 | } |
| 60 | |
| 61 | bool AssetReadFile(AAssetManager* assetManager, std::string& assetName, |
| 62 | std::vector<uint8_t>& buf) { |
| 63 | if (!assetName.length()) return false; |
| 64 | AAsset* assetDescriptor = |
| 65 | AAssetManager_open(assetManager, assetName.c_str(), AASSET_MODE_BUFFER); |
| 66 | ASSERT(assetDescriptor, "%s does not exist in %s", assetName.c_str(), |
| 67 | __FUNCTION__); |
| 68 | size_t remaining = AAsset_getLength(assetDescriptor); |
| 69 | |
| 70 | buf.resize(remaining); |
| 71 | size_t idx = 0; |
| 72 | |
| 73 | while (remaining > 0) { |
| 74 | int readSize = AAsset_read(assetDescriptor, &buf[idx], remaining); |
| 75 | if (readSize < 0) { |
| 76 | LOGE("AAsset_read of %s failed", assetName.c_str()); |
| 77 | return false; |
| 78 | } |
| 79 | idx += readSize; |
| 80 | remaining -= readSize; |
| 81 | } |
| 82 | |
| 83 | AAsset_close(assetDescriptor); |
| 84 | return true; |
| 85 | } |