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,10 +204,6 @@ 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,13 +215,14 @@ 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 // find it in apk's assets dir
// Found "assets/" at the beginning of the path and we don't want it // Found "assets/" at the beginning of the path and we don't want it
CCLOG("find in apk dirPath(%s)", s); CCLOG("find in apk dirPath(%s)", s);
if (startWithAssets) if (dirPath.find(ASSETS_FOLDER_NAME) == 0)
{ {
s += lenOfAssets; s += ASSETS_FOLDER_NAME_LENGTH;
} }
if (FileUtilsAndroid::assetmanager) if (FileUtilsAndroid::assetmanager)
{ {
@ -233,6 +233,8 @@ bool FileUtilsAndroid::isDirectoryExistInternal(const std::string& dirPath) cons
return true; return true;
} }
} }
}
return false; return false;
} }