axmol/cocos2dx/platform/android/CCFileUtils_android.cpp

116 lines
3.8 KiB
C++
Raw Normal View History

2010-11-03 11:01:17 +08:00
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
NS_CC_BEGIN;
2010-11-03 11:01:17 +08:00
#include "CCCommon.h"
2010-11-03 11:01:17 +08:00
#define MAX_PATH 256
2010-11-03 11:01:17 +08:00
// record the resource path
static std::string s_strRelativePath = "";
static std::string s_strResourcePath = "";
void CCFileUtils::setRelativePath(const char* pszRelativePath)
{
2011-03-08 13:49:58 +08:00
CCAssert(pszRelativePath != NULL, "[FileUtils setRelativePath] -- wrong relative path");
if (! pszRelativePath)
{
return;
}
s_strRelativePath = pszRelativePath;
// if the path is not ended with '/', append it
if (s_strRelativePath.find("/") != (strlen(s_strRelativePath.c_str()) - 1))
{
s_strRelativePath += "/";
}
}
2010-11-03 11:01:17 +08:00
void CCFileUtils::setResourcePath(const char *pszResourcePath)
{
2011-03-08 13:49:58 +08:00
CCAssert(pszResourcePath != NULL, "[FileUtils setResourcePath] -- wrong resource path");
CCAssert(strlen(pszResourcePath) <= MAX_PATH, "[FileUtils setResourcePath] -- resource path too long");
2010-11-03 11:01:17 +08:00
s_strResourcePath = pszResourcePath;
2010-11-03 11:01:17 +08:00
}
const char* CCFileUtils::getResourcePath()
{
return s_strResourcePath.c_str();
2010-11-03 11:01:17 +08:00
}
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
return pszRelativePath;
2010-11-03 11:01:17 +08:00
}
2010-11-03 11:01:17 +08:00
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
{
//std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
std::string relativeFile = pszRelativeFile;
2011-03-08 13:49:58 +08:00
CCString *pRet = new CCString();
2010-11-03 11:01:17 +08:00
pRet->autorelease();
pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1);
pRet->m_sString += pszFilename;
return pRet->m_sString.c_str();
}
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);
if (! pData && getIsPopupNotify())
{
std::string title = "Notification";
std::string msg = "Get data from file(";
msg.append(pszFileName).append(") failed!");
CCMessageBox(msg.c_str(), title.c_str());
}
return pData;
}
void CCFileUtils::setResource(const char* pszZipFileName)
2010-11-03 11:01:17 +08:00
{
CCAssert(0, "Have not implement!");
2010-11-03 11:01:17 +08:00
}
int CCFileUtils::ccLoadFileIntoMemory(const char *filename, unsigned char **out)
{
CCAssert(0, "Have not implement!");
return 0;
}
const string CCFileUtils::getWriteablePath()
{
// the path is: /data/data/ + package name
string dir("/data/data");
size_t length = s_strResourcePath.rfind(".") - s_strResourcePath.rfind("/");
return dir + s_strResourcePath.substr(s_strResourcePath.rfind("/"), length) + "/" ;
}
NS_CC_END;