mirror of https://github.com/axmolengine/axmol.git
fixed #656: remove unneeded methods & android can let user set resource path
This commit is contained in:
parent
eaca1d4a71
commit
76da5f2e84
|
@ -8,8 +8,6 @@
|
|||
|
||||
using namespace cocos2d;
|
||||
|
||||
#define IMG_PATH "assets"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
|
@ -23,8 +21,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
view->create(480, 320);
|
||||
cocos2d::CCDirector::sharedDirector()->setOpenGLView(view);
|
||||
|
||||
CCFileUtils::setRelativePath(IMG_PATH);
|
||||
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
cocos2d::CCApplication::sharedApplication().run();
|
||||
}
|
||||
|
|
|
@ -40,6 +40,9 @@ bool AppDelegate::initInstance()
|
|||
// OpenGLView initialized in HelloWorld/android/jni/helloworld/main.cpp
|
||||
// the default setting is to create a fullscreen view
|
||||
// if you want to use auto-scale, please enable view->create(320,480) in main.cpp
|
||||
// if the resources under '/sdcard" or other writeable path, set it.
|
||||
// warning: the audio source should in assets/
|
||||
// cocos2d::CCFileUtils::setResourcePath("/sdcard");
|
||||
|
||||
#endif // CC_PLATFORM_ANDROID
|
||||
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
using namespace cocos2d;
|
||||
|
||||
#define IMG_PATH "assets"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
|
@ -23,8 +21,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
// view->create(480, 320);
|
||||
cocos2d::CCDirector::sharedDirector()->setOpenGLView(view);
|
||||
|
||||
CCFileUtils::setRelativePath(IMG_PATH);
|
||||
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
cocos2d::CCApplication::sharedApplication().run();
|
||||
}
|
||||
|
|
|
@ -107,12 +107,6 @@ public:
|
|||
*/
|
||||
static void setResource(const char* pszZipFileName);
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
// interfaces on android
|
||||
///////////////////////////////////////////////////
|
||||
static const char* getResourcePath(void);
|
||||
static void setRelativePath(const char* pszRelativePath);
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
// interfaces on ios
|
||||
///////////////////////////////////////////////////
|
||||
|
|
|
@ -29,49 +29,49 @@ NS_CC_BEGIN;
|
|||
|
||||
#define MAX_PATH 256
|
||||
|
||||
using namespace std;
|
||||
|
||||
// record the resource path
|
||||
static std::string s_strRelativePath = "";
|
||||
static std::string s_strResourcePath = "";
|
||||
static string s_strResourcePath = "";
|
||||
|
||||
void CCFileUtils::setRelativePath(const char* pszRelativePath)
|
||||
void CCFileUtils::setResourcePath(const char* pszResourcePath)
|
||||
{
|
||||
CCAssert(pszRelativePath != NULL, "[FileUtils setRelativePath] -- wrong relative path");
|
||||
CCAssert(pszResourcePath != NULL, "[FileUtils setRelativePath] -- wrong relative path");
|
||||
|
||||
if (! pszRelativePath)
|
||||
if (! pszResourcePath)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
s_strRelativePath = pszRelativePath;
|
||||
|
||||
// if the path is not ended with '/', append it
|
||||
if (s_strRelativePath.find("/") != (strlen(s_strRelativePath.c_str()) - 1))
|
||||
s_strResourcePath = pszResourcePath;
|
||||
|
||||
/*
|
||||
* If the path is set by user, and not end with "/", append it
|
||||
*/
|
||||
if (s_strResourcePath.find(".apk") == string::npos
|
||||
&& s_strResourcePath.find_last_of("/") != s_strResourcePath.length() - 1)
|
||||
{
|
||||
s_strRelativePath += "/";
|
||||
s_strResourcePath += "/";
|
||||
}
|
||||
}
|
||||
|
||||
void CCFileUtils::setResourcePath(const char *pszResourcePath)
|
||||
{
|
||||
CCAssert(pszResourcePath != NULL, "[FileUtils setResourcePath] -- wrong resource path");
|
||||
CCAssert(strlen(pszResourcePath) <= MAX_PATH, "[FileUtils setResourcePath] -- resource path too long");
|
||||
|
||||
s_strResourcePath = pszResourcePath;
|
||||
}
|
||||
|
||||
const char* CCFileUtils::getResourcePath()
|
||||
{
|
||||
return s_strResourcePath.c_str();
|
||||
}
|
||||
|
||||
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
||||
{
|
||||
return pszRelativePath;
|
||||
if (s_strResourcePath.find(".apk") != string::npos)
|
||||
{
|
||||
return pszRelativePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
CCString *pRet = new CCString();
|
||||
pRet->autorelease();
|
||||
pRet->m_sString = s_strResourcePath + pszRelativePath;
|
||||
return pRet->m_sString.c_str();
|
||||
}
|
||||
}
|
||||
|
||||
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
|
||||
{
|
||||
//std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
|
||||
std::string relativeFile = pszRelativeFile;
|
||||
CCString *pRet = new CCString();
|
||||
pRet->autorelease();
|
||||
|
@ -81,14 +81,38 @@ const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const
|
|||
}
|
||||
|
||||
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
||||
{
|
||||
string fullPath = s_strRelativePath + pszFileName;
|
||||
unsigned char * pData = CCFileUtils::getFileDataFromZip(s_strResourcePath.c_str(), fullPath.c_str(), pSize);
|
||||
{
|
||||
string fullPath = pszFileName;
|
||||
unsigned char * pData = 0;
|
||||
|
||||
if (s_strResourcePath.find(".apk") != string::npos)
|
||||
{
|
||||
// read from apk
|
||||
fullPath.insert(0, "assets/");
|
||||
pData = CCFileUtils::getFileDataFromZip(s_strResourcePath.c_str(), fullPath.c_str(), pSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
// read rrom other path than user set it
|
||||
FILE *fp = fopen(pszFileName, pszMode);
|
||||
CC_BREAK_IF(!fp);
|
||||
|
||||
fseek(fp,0,SEEK_END);
|
||||
*pSize = ftell(fp);
|
||||
fseek(fp,0,SEEK_SET);
|
||||
pData = new unsigned char[*pSize];
|
||||
*pSize = fread(pData,sizeof(unsigned char), *pSize,fp);
|
||||
fclose(fp);
|
||||
} while (0);
|
||||
}
|
||||
|
||||
if (! pData && getIsPopupNotify())
|
||||
{
|
||||
std::string title = "Notification";
|
||||
std::string msg = "Get data from file(";
|
||||
msg.append(pszFileName).append(") failed!");
|
||||
msg.append(fullPath.c_str()).append(") failed!");
|
||||
CCMessageBox(msg.c_str(), title.c_str());
|
||||
}
|
||||
return pData;
|
||||
|
|
|
@ -247,12 +247,7 @@ namespace cocos2d {
|
|||
|
||||
strcpy(s_pszResourcePath, pszResourcePath);
|
||||
}
|
||||
|
||||
const char* CCFileUtils::getResourcePath()
|
||||
{
|
||||
return s_pszResourcePath;
|
||||
}
|
||||
|
||||
|
||||
int CCFileUtils::ccLoadFileIntoMemory(const char *filename, unsigned char **out)
|
||||
{
|
||||
CCAssert( out, "ccLoadFileIntoMemory: invalid 'out' parameter");
|
||||
|
@ -347,10 +342,6 @@ namespace cocos2d {
|
|||
{
|
||||
CCAssert(0, "Have not implement!");
|
||||
}
|
||||
void CCFileUtils::setRelativePath(const char* pszRelativePath)
|
||||
{
|
||||
CCAssert(0, "Have not implement!");
|
||||
}
|
||||
|
||||
// notification support when getFileData from a invalid file
|
||||
static bool s_bPopupNotify = true;
|
||||
|
|
|
@ -148,18 +148,6 @@ void CCFileUtils::setResource(const char* pszZipFileName)
|
|||
CCAssert(0, "Have not implement!");
|
||||
}
|
||||
|
||||
const char* CCFileUtils::getResourcePath(void)
|
||||
{
|
||||
CCAssert(0, "Have not implement!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CCFileUtils::setRelativePath(const char* pszRelativePath)
|
||||
{
|
||||
CC_UNUSED_PARAM(pszRelativePath);
|
||||
CCAssert(0, "Have not implement!");
|
||||
}
|
||||
|
||||
string CCFileUtils::getWriteablePath()
|
||||
{
|
||||
// return the path that the exe file saved in
|
||||
|
|
|
@ -247,17 +247,6 @@ void CCFileUtils::setResourcePath(const char *pszResourcePath)
|
|||
CCAssert(0, "Have not implement!");
|
||||
}
|
||||
|
||||
const char* CCFileUtils::getResourcePath(void)
|
||||
{
|
||||
CCAssert(0, "Have not implement!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CCFileUtils::setRelativePath(const char* pszRelativePath)
|
||||
{
|
||||
CCAssert(0, "Have not implement!");
|
||||
}
|
||||
|
||||
string CCFileUtils::getWriteablePath()
|
||||
{
|
||||
return string(CCApplication::sharedApplication().getAppWritablePath());
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
using namespace cocos2d;
|
||||
|
||||
#define IMG_PATH "assets"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
|
@ -23,8 +21,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
// view->create(480, 320);
|
||||
cocos2d::CCDirector::sharedDirector()->setOpenGLView(view);
|
||||
|
||||
CCFileUtils::setRelativePath(IMG_PATH);
|
||||
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
cocos2d::CCApplication::sharedApplication().run();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue