Merge pull request #2457 from dumganhar/master

Fixing a bug in CCFileUtilsIOS::isFileExist(). Improving performance of isFileExist for all platforms.
This commit is contained in:
James Chen 2013-04-25 07:09:15 -07:00
commit b648d392ba
8 changed files with 55 additions and 10 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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

View File

@ -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.

View File

@ -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] != '/')

View File

@ -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;
}

View File

@ -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.

View File

@ -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.