Reputation: 41
string relativePath = "scripts/test.pb"; // this is ok
string relativePath = "./scripts/test.pb"; // this can not open the file"
AAsset* asset = AAssetManager_open(FileUtilsAndroid::assetmanager,
relativePath.c_str(),
AASSET_MODE_UNKNOWN);
When i use this function to open android apk file, the "relativePath" contains "." can not work. i can not understand why? and i can not see the source code of "AAssetManager_open", so just need help.
Upvotes: 1
Views: 767
Reputation: 6557
If you look at the source code for AAssetManager_open , you will see that it calls AssetManager::open , which does this:
String8 assetName(kAssetsRoot);
assetName.appendPath(fileName);
where kAssetsRoot is a static const char* defined to hold the value "assets"
If you use "./scripts/test.pb" as the filename this will yield "assets/./scripts/test.pb" (which is a valid unix pathname, i.e. you can add as many "./" or "/" and it should still be a valid path), but inside AssetManager::openNonAssetInPathLocked it appends "assets/./scripts/test.pb" to ap.path which maybe causes problems further down the callstack i.e. in Asset::createFromFile which calls open and _FileAsset::openChunk on the given filepath.
Upvotes: 1