diff --git a/cocos2dx/platform/CCFileUtilsCommon_cpp.h b/cocos2dx/platform/CCFileUtilsCommon_cpp.h index 06cffd1adc..63efba2b5e 100644 --- a/cocos2dx/platform/CCFileUtilsCommon_cpp.h +++ b/cocos2dx/platform/CCFileUtilsCommon_cpp.h @@ -372,14 +372,13 @@ unsigned char* CCFileUtils::getFileDataFromZip(const char* pszZipFilePath, const return pBuffer; } -void CCFileUtils::setResourceDirectory(const char* pszResourceDirectory, bool isWorkingDir) +void CCFileUtils::setResourceDirectory(const char* pszResourceDirectory) { m_obDirectory = pszResourceDirectory; if (m_obDirectory.size() > 0 && m_obDirectory[m_obDirectory.size() - 1] != '/') { m_obDirectory.append("/"); } - m_isWorkingDirectory = isWorkingDir; } const char* CCFileUtils::getResourceDirectory() diff --git a/cocos2dx/platform/win32/CCApplication.cpp b/cocos2dx/platform/win32/CCApplication.cpp index d77a93a85b..0507355813 100644 --- a/cocos2dx/platform/win32/CCApplication.cpp +++ b/cocos2dx/platform/win32/CCApplication.cpp @@ -1,6 +1,7 @@ #include "CCApplication.h" #include "CCEGLView.h" #include "CCDirector.h" +#include /** @brief This function change the PVRFrame show/hide setting in register. @@ -142,6 +143,22 @@ TargetPlatform CCApplication::getTargetPlatform() return kTargetWindows; } +void CCApplication::setResourceRootPath(const std::string& rootResDir) +{ + m_resourceRootPath = rootResDir; + std::replace(m_resourceRootPath.begin(), m_resourceRootPath.end(), '\\', '/'); + if (m_resourceRootPath[m_resourceRootPath.length() - 1] != '/') + { + m_resourceRootPath += '/'; + } +} + +void CCApplication::setStartupScriptFilename(const std::string& startupScriptFile) +{ + m_startupScriptFilename = startupScriptFile; + std::replace(m_startupScriptFilename.begin(), m_startupScriptFilename.end(), '\\', '/'); +} + NS_CC_END ////////////////////////////////////////////////////////////////////////// diff --git a/cocos2dx/platform/win32/CCApplication.h b/cocos2dx/platform/win32/CCApplication.h index 8e05740002..f10b7231e9 100644 --- a/cocos2dx/platform/win32/CCApplication.h +++ b/cocos2dx/platform/win32/CCApplication.h @@ -4,6 +4,7 @@ #include #include "platform/CCCommon.h" #include "platform/CCApplicationProtocol.h" +#include NS_CC_BEGIN @@ -35,10 +36,28 @@ public: */ virtual TargetPlatform getTargetPlatform(); + /* set the Resource root path */ + void setResourceRootPath(const std::string& rootResDir); + + /* get the Resource root path */ + const std::string& getResourceRootPath(void) + { + return m_resourceRootPath; + } + + void setStartupScriptFilename(const std::string& startupScriptFile); + + const std::string& getStartupScriptFilename(void) + { + return m_startupScriptFilename; + } + protected: HINSTANCE m_hInstance; HACCEL m_hAccelTable; LARGE_INTEGER m_nAnimationInterval; + std::string m_resourceRootPath; + std::string m_startupScriptFilename; static CCApplication * sm_pSharedApplication; }; diff --git a/cocos2dx/platform/win32/CCFileUtils.cpp b/cocos2dx/platform/win32/CCFileUtils.cpp index 7d7ff128af..4e6e19d8f8 100644 --- a/cocos2dx/platform/win32/CCFileUtils.cpp +++ b/cocos2dx/platform/win32/CCFileUtils.cpp @@ -25,6 +25,7 @@ THE SOFTWARE. #include "platform/CCFileUtilsCommon_cpp.h" #include #include "CCDirector.h" +#include "CCApplication.h" using namespace std; @@ -78,6 +79,7 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) const char* resDir = m_obDirectory.c_str(); CCString* pRet = CCString::create(""); + const std::string& resourceRootPath = CCApplication::sharedApplication()->getResourceRootPath(); if ((strlen(pszRelativePath) > 1 && pszRelativePath[1] == ':')) { // path start with "x:", is absolute path @@ -91,9 +93,9 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) pRet->m_sString = szDriver; pRet->m_sString += pszRelativePath; } - else if (m_isWorkingDirectory) + else if (resourceRootPath.length() > 0) { - pRet->m_sString = m_obDirectory; + pRet->m_sString = resourceRootPath.c_str(); pRet->m_sString += pszRelativePath; } else