Merge pull request #16017 from minggo/issue-15978

don't search APK if the path is absolute
This commit is contained in:
minggo 2016-07-01 17:21:37 +08:00 committed by GitHub
commit c1949be617
1 changed files with 21 additions and 19 deletions

View File

@ -39,6 +39,9 @@ THE SOFTWARE.
#define LOG_TAG "CCFileUtils-android.cpp" #define LOG_TAG "CCFileUtils-android.cpp"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define ASSETS_FOLDER_NAME "assets/"
#define ASSETS_FOLDER_NAME_LENGTH 7
using namespace std; using namespace std;
NS_CC_BEGIN NS_CC_BEGIN
@ -85,7 +88,7 @@ FileUtilsAndroid::~FileUtilsAndroid()
bool FileUtilsAndroid::init() bool FileUtilsAndroid::init()
{ {
_defaultResRootPath = "assets/"; _defaultResRootPath = ASSETS_FOLDER_NAME;
std::string assetsPath(getApkPath()); std::string assetsPath(getApkPath());
if (assetsPath.find("/obb/") != std::string::npos) if (assetsPath.find("/obb/") != std::string::npos)
@ -201,11 +204,7 @@ bool FileUtilsAndroid::isDirectoryExistInternal(const std::string& dirPath) cons
} }
const char* s = dirPath.c_str(); const char* s = dirPath.c_str();
bool startWithAssets = (dirPath.find("assets/") == 0);
int lenOfAssets = 7;
std::string tmpStr;
// find absolute path in flash memory // find absolute path in flash memory
if (s[0] == '/') if (s[0] == '/')
{ {
@ -216,23 +215,26 @@ bool FileUtilsAndroid::isDirectoryExistInternal(const std::string& dirPath) cons
return S_ISDIR(st.st_mode); return S_ISDIR(st.st_mode);
} }
} }
else
// find it in apk's assets dir
// Found "assets/" at the beginning of the path and we don't want it
CCLOG("find in apk dirPath(%s)", s);
if (startWithAssets)
{ {
s += lenOfAssets; // find it in apk's assets dir
} // Found "assets/" at the beginning of the path and we don't want it
if (FileUtilsAndroid::assetmanager) CCLOG("find in apk dirPath(%s)", s);
{ if (dirPath.find(ASSETS_FOLDER_NAME) == 0)
AAssetDir* aa = AAssetManager_openDir(FileUtilsAndroid::assetmanager, s);
if (aa && AAssetDir_getNextFileName(aa))
{ {
AAssetDir_close(aa); s += ASSETS_FOLDER_NAME_LENGTH;
return true; }
if (FileUtilsAndroid::assetmanager)
{
AAssetDir* aa = AAssetManager_openDir(FileUtilsAndroid::assetmanager, s);
if (aa && AAssetDir_getNextFileName(aa))
{
AAssetDir_close(aa);
return true;
}
} }
} }
return false; return false;
} }