diff --git a/cocos2dx/platform/android/CCFileUtilsAndroid.cpp b/cocos2dx/platform/android/CCFileUtilsAndroid.cpp index 9e54d9a8a4..2bcf2397ea 100644 --- a/cocos2dx/platform/android/CCFileUtilsAndroid.cpp +++ b/cocos2dx/platform/android/CCFileUtilsAndroid.cpp @@ -62,6 +62,11 @@ bool CCFileUtilsAndroid::init() bool CCFileUtilsAndroid::isFileExist(const std::string& strFilePath) { + if (0 == strFilePath.length()) + { + return false; + } + bool bFound = false; // Check whether file exists in apk. diff --git a/cocos2dx/platform/blackberry/CCFileUtilsBlackberry.cpp b/cocos2dx/platform/blackberry/CCFileUtilsBlackberry.cpp index 9589f561ef..04770ec350 100644 --- a/cocos2dx/platform/blackberry/CCFileUtilsBlackberry.cpp +++ b/cocos2dx/platform/blackberry/CCFileUtilsBlackberry.cpp @@ -53,6 +53,11 @@ bool CCFileUtilsBlackberry::isAbsolutePath(const std::string& strPath) bool CCFileUtilsBlackberry::isFileExist(const std::string& strFilePath) { + if (0 == strFilePath.length()) + { + return false; + } + std::string strPath = strFilePath; if (strPath[0] != '/') { // Not absolute path, add the default root path at the beginning. diff --git a/cocos2dx/platform/ios/CCFileUtilsIOS.mm b/cocos2dx/platform/ios/CCFileUtilsIOS.mm index 62e566d89d..baaf4caca6 100644 --- a/cocos2dx/platform/ios/CCFileUtilsIOS.mm +++ b/cocos2dx/platform/ios/CCFileUtilsIOS.mm @@ -161,23 +161,33 @@ std::string CCFileUtilsIOS::getWritablePath() bool CCFileUtilsIOS::isFileExist(const std::string& strFilePath) { + if (0 == strFilePath.length()) + { + return false; + } + bool bRet = false; if (strFilePath[0] != '/') { - std::string path = strFilePath; + std::string path; std::string file; - size_t pos = path.find_last_of("/"); + size_t pos = strFilePath.find_last_of("/"); if (pos != std::string::npos) { - file = path.substr(pos+1); - path = path.substr(0, pos+1); - NSString* fullpath = [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:file.c_str()] - ofType:nil - inDirectory:[NSString stringWithUTF8String:path.c_str()]]; - if (fullpath != nil) { - bRet = true; - } + file = strFilePath.substr(pos+1); + path = strFilePath.substr(0, pos+1); + } + else + { + file = strFilePath; + } + + NSString* fullpath = [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:file.c_str()] + ofType:nil + inDirectory:[NSString stringWithUTF8String:path.c_str()]]; + if (fullpath != nil) { + bRet = true; } } else diff --git a/cocos2dx/platform/linux/CCFileUtilsLinux.cpp b/cocos2dx/platform/linux/CCFileUtilsLinux.cpp index 8f96052be2..fb055d1b3f 100644 --- a/cocos2dx/platform/linux/CCFileUtilsLinux.cpp +++ b/cocos2dx/platform/linux/CCFileUtilsLinux.cpp @@ -75,6 +75,11 @@ string CCFileUtilsLinux::getWritablePath() bool CCFileUtilsLinux::isFileExist(const std::string& strFilePath) { + if (0 == strFilePath.length()) + { + return false; + } + std::string strPath = strFilePath; if (!isAbsolutePath(strPath)) { // Not absolute path, add the default root path at the beginning. diff --git a/cocos2dx/platform/mac/CCFileUtilsMac.mm b/cocos2dx/platform/mac/CCFileUtilsMac.mm index 2bedb5db0b..8ea8cb9e5f 100644 --- a/cocos2dx/platform/mac/CCFileUtilsMac.mm +++ b/cocos2dx/platform/mac/CCFileUtilsMac.mm @@ -158,6 +158,11 @@ std::string CCFileUtilsMac::getWritablePath() bool CCFileUtilsMac::isFileExist(const std::string& strFilePath) { + if (0 == strFilePath.length()) + { + return false; + } + bool bRet = false; if (strFilePath[0] != '/') diff --git a/cocos2dx/platform/marmalade/CCFileUtilsMarmalade.cpp b/cocos2dx/platform/marmalade/CCFileUtilsMarmalade.cpp index 15c58183af..e0fc348e1b 100644 --- a/cocos2dx/platform/marmalade/CCFileUtilsMarmalade.cpp +++ b/cocos2dx/platform/marmalade/CCFileUtilsMarmalade.cpp @@ -30,6 +30,11 @@ string CCFileUtilsMarmalade::getWritablePath() bool CCFileUtilsMarmalade::isFileExist(const std::string& strFilePath) { + if (0 == strFilePath.length()) + { + return false; + } + return s3eFileCheckExists(strFilePath.c_str()) == S3E_TRUE ? true : false; } diff --git a/cocos2dx/platform/nacl/CCFileUtilsNaCl.cpp b/cocos2dx/platform/nacl/CCFileUtilsNaCl.cpp index c432cd7d3e..38517069e9 100644 --- a/cocos2dx/platform/nacl/CCFileUtilsNaCl.cpp +++ b/cocos2dx/platform/nacl/CCFileUtilsNaCl.cpp @@ -48,6 +48,11 @@ std::string CCFileUtilsNaCl::getWritablePath() bool CCFileUtilsNaCl::isFileExist(const std::string& strFilePath) { + if (0 == strFilePath.length()) + { + return false; + } + std::string strPath = strFilePath; if (!isAbsolutePath(strPath)) { // Not absolute path, add the default root path at the beginning. diff --git a/cocos2dx/platform/win32/CCFileUtilsWin32.cpp b/cocos2dx/platform/win32/CCFileUtilsWin32.cpp index da558e3b98..43e747af10 100644 --- a/cocos2dx/platform/win32/CCFileUtilsWin32.cpp +++ b/cocos2dx/platform/win32/CCFileUtilsWin32.cpp @@ -66,6 +66,11 @@ bool CCFileUtilsWin32::init() bool CCFileUtilsWin32::isFileExist(const std::string& strFilePath) { + if (0 == strFilePath.length()) + { + return false; + } + std::string strPath = strFilePath; if (!isAbsolutePath(strPath)) { // Not absolute path, add the default root path at the beginning.