Using new API of getting full path for file name.

This commit is contained in:
James Chen 2013-01-25 20:51:52 +08:00
parent 4d900c2d15
commit 6f3b22031f
22 changed files with 158 additions and 178 deletions

View File

@ -177,15 +177,15 @@ void SimpleAudioEngine::end()
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
{
// Changing file path to full path
const char* fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
static_preloadBackgroundMusic(fullPath);
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
static_preloadBackgroundMusic(fullPath.c_str());
}
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
{
// Changing file path to full path
const char* fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
static_playBackgroundMusic(fullPath, bLoop);
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
static_playBackgroundMusic(fullPath.c_str(), bLoop);
}
void SimpleAudioEngine::stopBackgroundMusic(bool bReleaseData)
@ -241,8 +241,8 @@ void SimpleAudioEngine::setEffectsVolume(float volume)
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
{
// Changing file path to full path
const char* fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
return static_playEffect(fullPath, bLoop);
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
return static_playEffect(fullPath.c_str(), bLoop);
}
void SimpleAudioEngine::stopEffect(unsigned int nSoundId)
@ -253,15 +253,15 @@ void SimpleAudioEngine::stopEffect(unsigned int nSoundId)
void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
{
// Changing file path to full path
const char* fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
static_preloadEffect(fullPath);
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
static_preloadEffect(fullPath.c_str());
}
void SimpleAudioEngine::unloadEffect(const char* pszFilePath)
{
// Changing file path to full path
const char* fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
static_unloadEffect(fullPath);
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
static_unloadEffect(fullPath.c_str());
}
void SimpleAudioEngine::pauseEffect(unsigned int uSoundId)

View File

@ -86,7 +86,7 @@ CCLabelAtlas* CCLabelAtlas::create(const char *string, const char *fntFile)
bool CCLabelAtlas::initWithString(const char *theString, const char *fntFile)
{
std::string pathStr = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(fntFile);
std::string pathStr = CCFileUtils::sharedFileUtils()->fullPathForFilename(fntFile);
std::string relPathStr = pathStr.substr(0, pathStr.find_last_of("/"))+"/";
CCDictionary *dict = CCDictionary::createWithContentsOfFile(pathStr.c_str());

View File

@ -472,7 +472,7 @@ void CCBMFontConfiguration::purgeFontDefDictionary()
std::set<unsigned int>* CCBMFontConfiguration::parseConfigFile(const char *controlFile)
{
std::string fullpath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(controlFile);
std::string fullpath = CCFileUtils::sharedFileUtils()->fullPathForFilename(controlFile);
CCString *contents = CCString::createWithContentsOfFile(fullpath.c_str());
CCAssert(contents, "CCBMFontConfiguration::parseConfigFile | Open file error.");

View File

@ -167,7 +167,7 @@ bool CCParticleSystem::init()
bool CCParticleSystem::initWithFile(const char *plistFile)
{
bool bRet = false;
m_sPlistFile = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(plistFile);
m_sPlistFile = CCFileUtils::sharedFileUtils()->fullPathForFilename(plistFile);
CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(m_sPlistFile.c_str());
CCAssert( dict != NULL, "Particles: file not found");

View File

@ -100,7 +100,7 @@ public:
@since v2.1
*/
const char* fullPathForFilename(const char* filename);
std::string fullPathForFilename(const char* filename);
/**
* Loads the filenameLookup dictionary from the contents of a filename.
@ -110,7 +110,7 @@ public:
* <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
* <plist version="1.0">
* <dict>
* <key>ios</key>
* <key>filenames</key>
* <dict>
* <key>sounds/click.wav</key>
* <string>sounds/click.caf</string>
@ -119,15 +119,6 @@ public:
* <key>sounds/gem-0.wav</key>
* <string>sounds/gem-0.caf</string>
* </dict>
* <key>android</key>
* <dict>
* <key>sounds/click.wav</key>
* <string>sounds/click.ogg</string>
* <key>sounds/endgame.wav</key>
* <string>sounds/endgame.ogg</string>
* <key>sounds/gem-0.wav</key>
* <string>sounds/gem-0.ogg</string>
* </dict>
* <key>metadata</key>
* <dict>
* <key>version</key>
@ -205,7 +196,6 @@ public:
void setPopupNotify(bool bNotify);
bool isPopupNotify();
std::string getAbsoluteFilenamePath(const char *filename);
protected:
CCFileUtils(void)
: m_pFilenameLookupDict(NULL)

View File

@ -403,9 +403,6 @@ void CCFileUtils::setSearchPath(CCArray* pSearchPaths)
CC_SAFE_RETAIN(pSearchPaths);
CC_SAFE_RELEASE(m_pSearchPathArray);
m_pSearchPathArray = pSearchPaths;
if(m_pSearchPathArray) {
m_pSearchPathArray->addObject(CCString::create("assets/"));
}
}
CCArray* CCFileUtils::getSearchPath()
@ -435,6 +432,27 @@ void CCFileUtils::setFilenameLookupDictionary(CCDictionary* pFilenameLookupDict)
CC_SAFE_RETAIN(m_pFilenameLookupDict);
}
void CCFileUtils::loadFilenameLookupDictionaryFromFile(const char* filename)
{
std::string fullPath = this->fullPathForFilename(filename);
if (fullPath.length() > 0)
{
CCDictionary* pDict = CCDictionary::createWithContentsOfFile(fullPath.c_str());
if (pDict)
{
CCDictionary* pMetadata = (CCDictionary*)pDict->objectForKey("metadata");
int version = ((CCString*)pMetadata->objectForKey("version"))->intValue();
if (version != 1)
{
CCLOG("cocos2d: ERROR: Invalid filenameLookup dictionary version: %ld. Filename: %s", (long)version, filename);
return;
}
setFilenameLookupDictionary((CCDictionary*)pDict->objectForKey("filenames"));
}
}
}
//////////////////////////////////////////////////////////////////////////
// Notification support when getFileData from invalid file path.
//////////////////////////////////////////////////////////////////////////

View File

@ -94,7 +94,8 @@ bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = e
{
bool bRet = false;
unsigned long nSize = 0;
unsigned char* pBuffer = CCFileUtils::sharedFileUtils()->getFileData(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(strPath), "rb", &nSize);
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(strPath);
unsigned char* pBuffer = CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(), "rb", &nSize);
if (pBuffer != NULL && nSize > 0)
{
bRet = initWithImageData(pBuffer, nSize, eImgFmt);

View File

@ -66,10 +66,11 @@ void CCFileUtils::purgeFileUtils()
if (s_pFileUtils != NULL)
{
s_pFileUtils->purgeCachedEntries();
CC_SAFE_RELEASE(s_pFileUtils->m_pFilenameLookupDict);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchPathArray);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchResolutionsOrderArray);
}
CC_SAFE_RELEASE(s_pFileUtils->m_pFilenameLookupDict);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchPathArray);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchResolutionsOrderArray);
CC_SAFE_DELETE(s_pZipFile);
CC_SAFE_DELETE(s_pFileUtils);
}
@ -81,47 +82,68 @@ void CCFileUtils::purgeCachedEntries()
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
return fullPathForFilename(pszRelativePath);
CCString* pRet = CCString::create("");
pRet->m_sString = fullPathForFilename(pszRelativePath);
return pRet->getCString();
}
const char* CCFileUtils::fullPathForFilename(const char* pszFileName)
std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
{
if (pszFileName == NULL || pszFileName[0] == '\0') {
if (pszFileName == NULL || pszFileName[0] == '\0' || pszFileName[0] == '/') {
return pszFileName;
}
// Get the new file name.
std::string newFilename = getNewFilename(pszFileName);
return CCString::create(getNewFilename(pszFileName).c_str())->getCString();
string fullpath = "";
bool bFound = false;
CCObject* pSearchObj = NULL;
CCARRAY_FOREACH(m_pSearchPathArray, pSearchObj)
{
CCString* pSearchPath = (CCString*)pSearchObj;
CCObject* pResourceDirObj = NULL;
CCARRAY_FOREACH(m_pSearchResolutionsOrderArray, pResourceDirObj)
{
CCString* pResourceDirectory = (CCString*)pResourceDirObj;
CCLOG("\n\nSEARCHING: %s, %s, %s", pszFileName, pResourceDirectory->getCString(), pSearchPath->getCString());
fullpath = this->getPathForFilename(pszFileName, pResourceDirectory->getCString(), pSearchPath->getCString());
// Check whether file exists in apk.
if (s_pZipFile->fileExists(fullpath))
{
bFound = true;
}
else
{
FILE *fp = fopen(fullpath.c_str(), "r");
if(fp)
{
bFound = true;
fclose(fp);
}
}
if (bFound)
{
CCLOG("Returning path: %s", fullpath.c_str());
return fullpath;
}
}
}
return pszFileName;
}
const char* CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
{
std::string relativeFile = pszRelativeFile;
CCString *pRet = new CCString();
pRet->autorelease();
CCString *pRet = CCString::create("");
pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1);
pRet->m_sString += getNewFilename(pszFilename);
return pRet->m_sString.c_str();
}
void CCFileUtils::loadFilenameLookupDictionaryFromFile(const char* filename)
{
const char* pFullPath = this->fullPathForFilename(filename);
if (pFullPath)
{
CCDictionary* pDict = CCDictionary::createWithContentsOfFile(filename);
if (pDict)
{
CCDictionary* pMetadata = (CCDictionary*)pDict->objectForKey("metadata");
int version = ((CCString*)pMetadata->objectForKey("version"))->intValue();
if (version != 1)
{
CCLOG("cocos2d: ERROR: Invalid filenameLookup dictionary version: %ld. Filename: %s", (long)version, filename);
return;
}
setFilenameLookupDictionary((CCDictionary*)pDict->objectForKey("filenames"));
}
}
return pRet->getCString();
}
std::string CCFileUtils::getPathForFilename(const std::string& filename, const std::string& resourceDirectory, const std::string& searchPath)
@ -152,60 +174,10 @@ std::string CCFileUtils::getPathForFilename(const std::string& filename, const s
path += file;
ret += path;
CCLog("full path = %s", ret.c_str());
CCLOG("getPathForFilename, fullPath = %s", ret.c_str());
return ret;
}
string CCFileUtils::getAbsoluteFilenamePath(const char *pszFileName) {
string fullpath = "";
if (pszFileName[0] != '/')
{
// read from apk
bool bFound = false;
CCObject* pSearchObj = NULL;
CCARRAY_FOREACH(m_pSearchPathArray, pSearchObj)
{
CCString* pSearchPath = (CCString*)pSearchObj;
CCObject* pResourceDirObj = NULL;
CCARRAY_FOREACH(m_pSearchResolutionsOrderArray, pResourceDirObj)
{
CCString* pResourceDirectory = (CCString*)pResourceDirObj;
// Search in subdirectories
CCLOG("\n\nSEARCHING: %s, %s, %s", pszFileName, pResourceDirectory->getCString(), pSearchPath->getCString());
fullpath = this->getPathForFilename(pszFileName, pResourceDirectory->getCString(), pSearchPath->getCString());
unsigned char * pData = 0;
unsigned long * pSize;
pData = s_pZipFile->getFileData(fullpath.c_str(), pSize);
if (pData)
{
bFound = true;
} else {
FILE *fp = fopen(fullpath.c_str(), "r");
if(fp) {
bFound = true;
fclose(fp);
}
}
if (bFound)
{
CCLOG("Returning path: %s", fullpath.c_str());
return fullpath;
}
}
}
} else {
return pszFileName;
}
return "";
}
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{
unsigned char * pData = 0;
@ -215,21 +187,18 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
return 0;
}
string fullpath;
string fullFilename = getAbsoluteFilenamePath(pszFileName);
if (fullFilename[0] != '/') {
CCLOG("GETTING FILE RELATIVE DATA: %s", pszFileName);
pData = s_pZipFile->getFileData(fullFilename.c_str(), pSize);
if (pszFileName[0] != '/')
{
CCLOG("GETTING FILE RELATIVE DATA: %s", pszFileName);
pData = s_pZipFile->getFileData(pszFileName, pSize);
}
else
{
do
{
// read rrom other path than user set it
CCLOG("GETTING FILE ABSOLUTE DATA: %s", fullFilename.c_str());
FILE *fp = fopen(fullFilename.c_str(), pszMode);
CCLOG("GETTING FILE ABSOLUTE DATA: %s", pszFileName);
FILE *fp = fopen(pszFileName, pszMode);
CC_BREAK_IF(!fp);
unsigned long size;
@ -251,7 +220,7 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
{
std::string title = "Notification";
std::string msg = "Get data from file(";
msg.append(fullpath.c_str()).append(") failed!");
msg.append(pszFileName).append(") failed!");
CCMessageBox(msg.c_str(), title.c_str());
}

View File

@ -227,7 +227,9 @@ const char* CCFileUtils::getResourceDirectory()
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
return fullPathForFilename(pszRelativePath);
CCString* pRet = CCString::create("");
pRet->m_sString = fullPathForFilename(pszRelativePath);
return pRet->getCString();
}
std::string CCFileUtils::getNewFilename(const char* pszFileName)
@ -279,7 +281,7 @@ std::string CCFileUtils::getPathForFilename(const std::string& filename, const s
return ret;
}
const char* CCFileUtils::fullPathForFilename(const char* filename)
std::string CCFileUtils::fullPathForFilename(const char* filename)
{
CCAssert(filename != NULL, "CCFileUtils: Invalid path");
@ -309,21 +311,19 @@ const char* CCFileUtils::fullPathForFilename(const char* filename)
if (found)
{
return CCString::create(fullpath.c_str())->getCString();
return fullpath;
}
}
}
}
return filename;
}
void CCFileUtils::loadFilenameLookupDictionaryFromFile(const char* filename)
{
const char* pFullPath = this->fullPathForFilename(filename);
if (pFullPath)
std::string pFullPath = this->fullPathForFilename(filename);
if (pFullPath.length() > 0)
{
CCDictionary* pDict = CCDictionary::createWithContentsOfFile(filename);
if (pDict)
@ -350,7 +350,7 @@ void CCFileUtils::setFilenameLookupDictionary(CCDictionary* pFilenameLookupDict)
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
{
std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
std::string relativeFile = fullPathForFilename(pszRelativeFile);
CCString *pRet = new CCString();
pRet->autorelease();
pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1);
@ -360,8 +360,8 @@ const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const
CCDictionary* ccFileUtils_dictionaryWithContentsOfFileThreadSafe(const char *pFileName)
{
const char* pszFullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(pFileName);
NSString* pPath = [NSString stringWithUTF8String:pszFullPath];
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pFileName);
NSString* pPath = [NSString stringWithUTF8String:fullPath.c_str()];
NSDictionary* pDict = [NSDictionary dictionaryWithContentsOfFile:pPath];
CCDictionary* pRet = new CCDictionary();
@ -380,8 +380,8 @@ CCArray* ccFileUtils_arrayWithContentsOfFileThreadSafe(const char* pFileName)
// pPath = [pPath stringByDeletingPathExtension];
// pPath = [[NSBundle mainBundle] pathForResource:pPath ofType:pathExtension];
// fixing cannot read data using CCArray::createWithContentsOfFile
const char* pszFullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(pFileName);
NSString* pPath = [NSString stringWithUTF8String:pszFullPath];
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pFileName);
NSString* pPath = [NSString stringWithUTF8String:fullPath.c_str()];
NSArray* pArray = [NSArray arrayWithContentsOfFile:pPath];
CCArray* pRet = new CCArray();
@ -400,7 +400,7 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
do
{
// read the file from hardware
std::string fullPath = fullPathFromRelativePath(pszFileName);
std::string fullPath = pszFileName;
FILE *fp = fopen(fullPath.c_str(), pszMode);
CC_BREAK_IF(!fp);

View File

@ -344,7 +344,7 @@ bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = e
bool bRet = false;
unsigned long nSize = 0;
unsigned char* pBuffer = CCFileUtils::sharedFileUtils()->getFileData(
CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(strPath),
CCFileUtils::sharedFileUtils()->fullPathForFilename(strPath).c_str(),
"rb",
&nSize);

View File

@ -122,8 +122,8 @@ bool CCGLProgram::initWithVertexShaderByteArray(const GLchar* vShaderByteArray,
bool CCGLProgram::initWithVertexShaderFilename(const char* vShaderFilename, const char* fShaderFilename)
{
const GLchar * vertexSource = (GLchar*) CCString::createWithContentsOfFile(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(vShaderFilename))->getCString();
const GLchar * fragmentSource = (GLchar*) CCString::createWithContentsOfFile(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(fShaderFilename))->getCString();
const GLchar * vertexSource = (GLchar*) CCString::createWithContentsOfFile(CCFileUtils::sharedFileUtils()->fullPathForFilename(vShaderFilename).c_str())->getCString();
const GLchar * fragmentSource = (GLchar*) CCString::createWithContentsOfFile(CCFileUtils::sharedFileUtils()->fullPathForFilename(fShaderFilename).c_str())->getCString();
return initWithVertexShaderByteArray(vertexSource, fragmentSource);
}

View File

@ -244,8 +244,8 @@ void CCAnimationCache::addAnimationsWithFile(const char* plist)
{
CCAssert( plist, "Invalid texture file name");
const char* path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(plist);
CCDictionary* dict = CCDictionary::createWithContentsOfFile(path);
std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(plist);
CCDictionary* dict = CCDictionary::createWithContentsOfFile(path.c_str());
CCAssert( dict, "CCAnimationCache: File could not be found");

View File

@ -203,8 +203,8 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary* dictionary,
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist, CCTexture2D *pobTexture)
{
const char *pszPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(pszPlist);
CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(pszPath);
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszPlist);
CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(fullPath.c_str());
addSpriteFramesWithDictionary(dict, pobTexture);
@ -232,8 +232,8 @@ void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
if (m_pLoadedFileNames->find(pszPlist) == m_pLoadedFileNames->end())
{
const char *pszPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(pszPlist);
CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(pszPath);
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszPlist);
CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(fullPath.c_str());
string texturePath("");
@ -246,8 +246,8 @@ void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
if (! texturePath.empty())
{
// build texture path relative to plist file
texturePath = CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile(texturePath.c_str(), pszPlist);
// build texture path relative to plist file
texturePath = CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile(texturePath.c_str(), pszPlist);
}
else
{
@ -343,8 +343,8 @@ void CCSpriteFrameCache::removeSpriteFrameByName(const char *pszName)
void CCSpriteFrameCache::removeSpriteFramesFromFile(const char* plist)
{
const char* path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(plist);
CCDictionary* dict = CCDictionary::createWithContentsOfFileThreadSafe(path);
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(plist);
CCDictionary* dict = CCDictionary::createWithContentsOfFileThreadSafe(fullPath.c_str());
removeSpriteFramesFromDictionary((CCDictionary*)dict);

View File

@ -258,7 +258,7 @@ void CCTextureCache::addImageAsync(const char *path, CCObject *target, SEL_CallF
std::string pathKey = path;
pathKey = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(pathKey.c_str());
pathKey = CCFileUtils::sharedFileUtils()->fullPathForFilename(pathKey.c_str());
texture = (CCTexture2D*)m_pTextures->objectForKey(pathKey.c_str());
std::string fullpath = pathKey;
@ -401,7 +401,7 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
// remove possible -HD suffix to prevent caching the same image twice (issue #1040)
std::string pathKey = path;
pathKey = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(pathKey.c_str());
pathKey = CCFileUtils::sharedFileUtils()->fullPathForFilename(pathKey.c_str());
texture = (CCTexture2D*)m_pTextures->objectForKey(pathKey.c_str());
std::string fullpath = pathKey; // (CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(path));
@ -487,7 +487,7 @@ CCTexture2D* CCTextureCache::addPVRTCImage(const char* path, int bpp, bool hasAl
}
// Split up directory and filename
std::string fullpath( CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(path) );
std::string fullpath( CCFileUtils::sharedFileUtils()->fullPathForFilename(path) );
unsigned long nLen = 0;
unsigned char* pData = CCFileUtils::sharedFileUtils()->getFileData(fullpath.c_str(), "rb", &nLen);
@ -523,7 +523,7 @@ CCTexture2D * CCTextureCache::addPVRImage(const char* path)
}
// Split up directory and filename
std::string fullpath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(key.c_str());
std::string fullpath = CCFileUtils::sharedFileUtils()->fullPathForFilename(key.c_str());
texture = new CCTexture2D();
if(texture != NULL && texture->initWithPVRFile(fullpath.c_str()) )
{
@ -552,7 +552,7 @@ CCTexture2D* CCTextureCache::addUIImage(CCImage *image, const char *key)
std::string forKey;
if (key)
{
forKey = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(key);
forKey = CCFileUtils::sharedFileUtils()->fullPathForFilename(key);
}
// Don't have to lock here, because addImageAsync() will not
@ -656,13 +656,13 @@ void CCTextureCache::removeTextureForKey(const char *textureKeyName)
return;
}
string fullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(textureKeyName);
m_pTextures->removeObjectForKey(fullPath.c_str());
string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(textureKeyName);
m_pTextures->removeObjectForKey(fullPath);
}
CCTexture2D* CCTextureCache::textureForKey(const char* key)
{
return (CCTexture2D*)m_pTextures->objectForKey(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(key));
return (CCTexture2D*)m_pTextures->objectForKey(CCFileUtils::sharedFileUtils()->fullPathForFilename(key));
}
void CCTextureCache::reloadAllTextures()

View File

@ -157,7 +157,7 @@ void CCTMXMapInfo::internalInit(const char* tmxFileName, const char* resourcePat
if (tmxFileName != NULL)
{
m_sTMXFileName = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(tmxFileName);
m_sTMXFileName = CCFileUtils::sharedFileUtils()->fullPathForFilename(tmxFileName);
}
if (resourcePath != NULL)
@ -358,7 +358,7 @@ void CCTMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
{
externalTilesetFilename = m_sResources + "/" + externalTilesetFilename;
}
externalTilesetFilename = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(externalTilesetFilename.c_str());
externalTilesetFilename = CCFileUtils::sharedFileUtils()->fullPathForFilename(externalTilesetFilename.c_str());
pTMXMapInfo->parseXMLFile(externalTilesetFilename.c_str());
}

View File

@ -116,14 +116,14 @@ void CCTileMapAtlas::loadTGAfile(const char *file)
{
CCAssert( file != NULL, "file must be non-nil");
const char* pPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(file);
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(file);
// //Find the path of the file
// NSBundle *mainBndl = [CCDirector sharedDirector].loadingBundle;
// CCString *resourcePath = [mainBndl resourcePath];
// CCString * path = [resourcePath stringByAppendingPathComponent:file];
m_pTGAInfo = tgaLoad( pPath );
m_pTGAInfo = tgaLoad( fullPath.c_str() );
#if 1
if( m_pTGAInfo->status != TGA_OK )
{

View File

@ -246,7 +246,7 @@ CCNode* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, CCObject *pOw
strCCBFileName += strSuffix;
}
std::string strPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(strCCBFileName.c_str());
std::string strPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(strCCBFileName.c_str());
unsigned long size = 0;
unsigned char * pBytes = CCFileUtils::sharedFileUtils()->getFileData(strPath.c_str(), "rb", &size);

View File

@ -840,9 +840,9 @@ CCNode * CCNodeLoader::parsePropTypeCCBFile(CCNode * pNode, CCNode * pParent, CC
ccbFileName = ccbFileWithoutPathExtension + ".ccbi";
// Load sub file
const char *path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(ccbFileName.c_str());
std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(ccbFileName.c_str());
unsigned long size = 0;
unsigned char * pBytes = CCFileUtils::sharedFileUtils()->getFileData(path, "rb", &size);
unsigned char * pBytes = CCFileUtils::sharedFileUtils()->getFileData(path.c_str(), "rb", &size);
CCBReader * ccbReader = new CCBReader(pCCBReader);
ccbReader->autorelease();

View File

@ -66,13 +66,14 @@ bool AppDelegate::applicationDidFinishLaunching()
CCSize resourceSize = CCSizeMake(320, 480);
string res = "xlarge";
if (screenSize.height > 1024)
{
resourceSize = CCSizeMake(1280, 1920);
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-xlarge"), CCString::create(""), NULL));
res = "xlarge";
}
else if (screenSize.height > 960)
// if (screenSize.height > 1024)
// {
// resourceSize = CCSizeMake(1280, 1920);
// CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-xlarge"), CCString::create(""), NULL));
// res = "xlarge";
// }
// else
if (screenSize.height > 960)
{
resourceSize = CCSizeMake(640, 960);
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-large"), CCString::create(""), NULL));

View File

@ -77,7 +77,7 @@ void CCBHelper::setPairMessage(std::string str) {
}
bool CCBHelper::isMainJSPresent() {
std::string path = CCFileUtils::sharedFileUtils()->getAbsoluteFilenamePath(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("main.js"));
std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("main.js");
CCLOG("PATH RETURNED: %s", path.c_str());
if(path == "") {
return false;

View File

@ -50,13 +50,14 @@ bool AppDelegate::applicationDidFinishLaunching()
}
else if (platform == kTargetAndroid || platform == kTargetWindows)
{
CCFileUtils::sharedFileUtils()->setSearchPath(CCArray::create(CCString::create(""), NULL));
if (screenSize.height > 1024)
{
resourceSize = CCSizeMake(1280, 1920);
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-xlarge"), CCString::create("resources-large"), CCString::create(""), NULL));
}
else if (screenSize.height > 960)
// Comments it since opengles2.0 only supports texture size within 2048x2048.
// if (screenSize.height > 1024)
// {
// resourceSize = CCSizeMake(1280, 1920);
// CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-xlarge"), CCString::create("resources-large"), CCString::create(""), NULL));
// }
// else
if (screenSize.height > 960)
{
resourceSize = CCSizeMake(640, 960);
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-large"), CCString::create("resources-medium"), CCString::create(""), NULL));

View File

@ -446,7 +446,7 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c
if (path[0] == '/') {
rpath = path;
} else {
rpath = futil->getAbsoluteFilenamePath(futil->fullPathFromRelativePath(path));
rpath = futil->fullPathForFilename(path);
}
if (global == NULL) {
global = global_;