diff --git a/CocosDenshion/ios/SimpleAudioEngine.mm b/CocosDenshion/ios/SimpleAudioEngine.mm index adb5a853d9..8efdf79288 100644 --- a/CocosDenshion/ios/SimpleAudioEngine.mm +++ b/CocosDenshion/ios/SimpleAudioEngine.mm @@ -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) diff --git a/cocos2dx/label_nodes/CCLabelAtlas.cpp b/cocos2dx/label_nodes/CCLabelAtlas.cpp index 4465f749cd..318f1477a2 100644 --- a/cocos2dx/label_nodes/CCLabelAtlas.cpp +++ b/cocos2dx/label_nodes/CCLabelAtlas.cpp @@ -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()); diff --git a/cocos2dx/label_nodes/CCLabelBMFont.cpp b/cocos2dx/label_nodes/CCLabelBMFont.cpp index c029394490..f97aabdf35 100644 --- a/cocos2dx/label_nodes/CCLabelBMFont.cpp +++ b/cocos2dx/label_nodes/CCLabelBMFont.cpp @@ -472,7 +472,7 @@ void CCBMFontConfiguration::purgeFontDefDictionary() std::set* 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."); diff --git a/cocos2dx/particle_nodes/CCParticleSystem.cpp b/cocos2dx/particle_nodes/CCParticleSystem.cpp index 9a9f5c1141..76392eadba 100644 --- a/cocos2dx/particle_nodes/CCParticleSystem.cpp +++ b/cocos2dx/particle_nodes/CCParticleSystem.cpp @@ -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"); diff --git a/cocos2dx/platform/CCFileUtils.h b/cocos2dx/platform/CCFileUtils.h index b66cf2b9c2..a150e0a68b 100644 --- a/cocos2dx/platform/CCFileUtils.h +++ b/cocos2dx/platform/CCFileUtils.h @@ -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: * * * - * ios + * filenames * * sounds/click.wav * sounds/click.caf @@ -119,15 +119,6 @@ public: * sounds/gem-0.wav * sounds/gem-0.caf * - * android - * - * sounds/click.wav - * sounds/click.ogg - * sounds/endgame.wav - * sounds/endgame.ogg - * sounds/gem-0.wav - * sounds/gem-0.ogg - * * metadata * * version @@ -205,7 +196,6 @@ public: void setPopupNotify(bool bNotify); bool isPopupNotify(); - std::string getAbsoluteFilenamePath(const char *filename); protected: CCFileUtils(void) : m_pFilenameLookupDict(NULL) diff --git a/cocos2dx/platform/CCFileUtilsCommon_cpp.h b/cocos2dx/platform/CCFileUtilsCommon_cpp.h index f691be10e5..94491ca8e8 100644 --- a/cocos2dx/platform/CCFileUtilsCommon_cpp.h +++ b/cocos2dx/platform/CCFileUtilsCommon_cpp.h @@ -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. ////////////////////////////////////////////////////////////////////////// diff --git a/cocos2dx/platform/CCImageCommon_cpp.h b/cocos2dx/platform/CCImageCommon_cpp.h index 7339754a0c..ab814dee46 100644 --- a/cocos2dx/platform/CCImageCommon_cpp.h +++ b/cocos2dx/platform/CCImageCommon_cpp.h @@ -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); diff --git a/cocos2dx/platform/android/CCFileUtils.cpp b/cocos2dx/platform/android/CCFileUtils.cpp index af8bf0f0b0..555ffb8731 100644 --- a/cocos2dx/platform/android/CCFileUtils.cpp +++ b/cocos2dx/platform/android/CCFileUtils.cpp @@ -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()); } diff --git a/cocos2dx/platform/ios/CCFileUtils.mm b/cocos2dx/platform/ios/CCFileUtils.mm index fb4ca70b9e..d93dda5116 100644 --- a/cocos2dx/platform/ios/CCFileUtils.mm +++ b/cocos2dx/platform/ios/CCFileUtils.mm @@ -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); diff --git a/cocos2dx/platform/ios/CCImage.mm b/cocos2dx/platform/ios/CCImage.mm index d01967d48a..69a35d6806 100644 --- a/cocos2dx/platform/ios/CCImage.mm +++ b/cocos2dx/platform/ios/CCImage.mm @@ -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); diff --git a/cocos2dx/shaders/CCGLProgram.cpp b/cocos2dx/shaders/CCGLProgram.cpp index f41bff55fc..4a75612d00 100644 --- a/cocos2dx/shaders/CCGLProgram.cpp +++ b/cocos2dx/shaders/CCGLProgram.cpp @@ -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); } diff --git a/cocos2dx/sprite_nodes/CCAnimationCache.cpp b/cocos2dx/sprite_nodes/CCAnimationCache.cpp index 219cc5282e..5273019d32 100644 --- a/cocos2dx/sprite_nodes/CCAnimationCache.cpp +++ b/cocos2dx/sprite_nodes/CCAnimationCache.cpp @@ -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"); diff --git a/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp b/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp index 5bbd348b19..de55c8f892 100644 --- a/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp +++ b/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp @@ -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); diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index c4a35586ba..0ad7c50ae9 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -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() diff --git a/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.cpp b/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.cpp index b02eeb3d02..ac220d9b07 100644 --- a/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.cpp +++ b/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.cpp @@ -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()); } diff --git a/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.cpp b/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.cpp index 2c6b9cb7bb..76dea79acf 100644 --- a/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.cpp +++ b/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.cpp @@ -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 ) { diff --git a/extensions/CCBReader/CCBReader.cpp b/extensions/CCBReader/CCBReader.cpp index 4fd939da8c..2b81748091 100644 --- a/extensions/CCBReader/CCBReader.cpp +++ b/extensions/CCBReader/CCBReader.cpp @@ -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); diff --git a/extensions/CCBReader/CCNodeLoader.cpp b/extensions/CCBReader/CCNodeLoader.cpp index 5759d7f785..599cd79d7b 100644 --- a/extensions/CCBReader/CCNodeLoader.cpp +++ b/extensions/CCBReader/CCNodeLoader.cpp @@ -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(); diff --git a/samples/Javascript/CocosPlayer/Classes/AppDelegate.cpp b/samples/Javascript/CocosPlayer/Classes/AppDelegate.cpp index 4dcaf87869..537ff70a5f 100644 --- a/samples/Javascript/CocosPlayer/Classes/AppDelegate.cpp +++ b/samples/Javascript/CocosPlayer/Classes/AppDelegate.cpp @@ -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)); diff --git a/samples/Javascript/CocosPlayer/Classes/MainSceneHelper.cpp b/samples/Javascript/CocosPlayer/Classes/MainSceneHelper.cpp index 6384edcb11..deef52ebc3 100644 --- a/samples/Javascript/CocosPlayer/Classes/MainSceneHelper.cpp +++ b/samples/Javascript/CocosPlayer/Classes/MainSceneHelper.cpp @@ -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; diff --git a/samples/Javascript/CrystalCraze/Classes/AppDelegate.cpp b/samples/Javascript/CrystalCraze/Classes/AppDelegate.cpp index f67991e487..51c2c24bf2 100644 --- a/samples/Javascript/CrystalCraze/Classes/AppDelegate.cpp +++ b/samples/Javascript/CrystalCraze/Classes/AppDelegate.cpp @@ -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)); diff --git a/scripting/javascript/bindings/ScriptingCore.cpp b/scripting/javascript/bindings/ScriptingCore.cpp index 63f5aefb8d..d63cfe5477 100644 --- a/scripting/javascript/bindings/ScriptingCore.cpp +++ b/scripting/javascript/bindings/ScriptingCore.cpp @@ -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_;