CCFileUtils::fullPathFromRelativePath() works correct

This commit is contained in:
minggo 2012-04-08 14:52:47 +08:00
parent 9e62841adb
commit 86b13a64c4
6 changed files with 29 additions and 21 deletions

View File

@ -271,23 +271,23 @@ public:
};
std::string& CCFileUtils::removeSuffixFromFile(std::string& path)
{
// XXX win32 now can only support iphone retina, because
// we don't know it is ipad retina or iphone retina.
// fixe me later
if( CC_CONTENT_SCALE_FACTOR() == 2 )
{
std::string::size_type pos = path.rfind("/") + 1; // the begin index of last part of path
std::string::size_type suffixPos = path.rfind(__suffixiPhoneRetinaDisplay);
{
// XXX win32 now can only support iphone retina, because
// we don't know it is ipad retina or iphone retina.
// fixe me later
if( CC_CONTENT_SCALE_FACTOR() == 2 )
{
std::string::size_type pos = path.rfind("/") + 1; // the begin index of last part of path
std::string::size_type suffixPos = path.rfind(__suffixiPhoneRetinaDisplay);
if (std::string::npos != suffixPos && suffixPos > pos)
{
CCLog("cocos2d: FilePath(%s) contains suffix(%s), remove it.", path.c_str(),
__suffixiPhoneRetinaDisplay);
path.replace(suffixPos, strlen(__suffixiPhoneRetinaDisplay), "");
}
}
}
return path;
}
@ -331,7 +331,7 @@ unsigned char* CCFileUtils::getFileDataFromZip(const char* pszZipFilePath, const
CC_BREAK_IF(UNZ_OK != nRet);
pBuffer = new unsigned char[FileInfo.uncompressed_size];
int nSize = 0;
int nSize = 0;
nSize = unzReadCurrentFile(pFile, pBuffer, FileInfo.uncompressed_size);
CCAssert(nSize == 0 || nSize == (int)FileInfo.uncompressed_size, "the file size is wrong");
@ -348,13 +348,13 @@ unsigned char* CCFileUtils::getFileDataFromZip(const char* pszZipFilePath, const
}
/// functions iOS specific
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath, ccResolutionType *pResolutionType)
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
assert(0);
return "";
ccResolutionType ignore;
return fullPathFromRelativePath(pszRelativePath, &ignore);
}
/// functions iOS specific
void CCFileUtils::setiPhoneRetinaDisplaySuffix(const char *suffix)
{
assert(0);

View File

@ -49,7 +49,8 @@ void CCFileUtils::setResourcePath(const char* pszResourcePath)
s_strResourcePath = pszResourcePath;
}
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath,
ccResolutionType *pResolutionType)
{
return pszRelativePath;
}

View File

@ -38,7 +38,7 @@ void CCFileUtils::setResourcePath(const char* pszResourcePath)
s_strResourcePath = pszResourcePath;
}
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath, ccResolutionType *pResolutionType)
{
int len = 0;
if (pszRelativePath == NULL || (len = strlen(pszRelativePath)) <= 0)

View File

@ -33,7 +33,7 @@ NS_CC_BEGIN;
static char s_pszResourcePath[S3E_FILE_MAX_PATH] = {0};
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath, ccResolutionType *pResolutionType)
{
IwAssert(GAME, pszRelativePath);

View File

@ -53,7 +53,7 @@ void CCFileUtils::setResourcePath(const char *pszResourcePath)
}
}
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath, ccResolutionType *pResolutionType)
{
// It works like this: if the relative path already includes the resource path
// it will be returned as it is

View File

@ -56,7 +56,7 @@ void CCFileUtils::setResourcePath(const char *pszResourcePath)
strcpy(s_pszResourcePath, pszResourcePath);
}
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath, ccResolutionType *pResolutionType)
{
_CheckPath();
@ -88,6 +88,7 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
std::string hiRes = pRet->m_sString.c_str();
std::string::size_type pos = hiRes.find_last_of("/\\");
std::string::size_type dotPos = hiRes.find_last_of(".");
*pResolutionType = kCCResolutioniPhone;
if (isIpad)
{
@ -103,6 +104,8 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
hiRes.append(CC_IPAD_FILENAME_SUFFIX);
}
*pResolutionType = kCCResolutioniPad;
}
else
{
@ -116,6 +119,8 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
hiRes.append(CC_IPAD_DISPLAY_RETINA_SUPPFIX);
}
*pResolutionType = kCCResolutioniPadRetinaDisplay;
}
}
else
@ -132,6 +137,8 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
hiRes.append(CC_RETINA_DISPLAY_FILENAME_SUFFIX);
}
*pResolutionType = kCCResolutioniPhoneRetinaDisplay;
}
}