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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-03-26 17:24:37 +08:00
|
|
|
NS_CC_BEGIN;
|
2010-11-03 11:01:17 +08:00
|
|
|
|
2011-03-26 17:24:37 +08:00
|
|
|
#include "CCCommon.h"
|
2010-11-03 11:01:17 +08:00
|
|
|
|
2011-02-24 19:42:45 +08:00
|
|
|
#define MAX_PATH 256
|
|
|
|
|
2010-11-03 11:01:17 +08:00
|
|
|
// record the resource path
|
2011-03-26 17:24:37 +08:00
|
|
|
static std::string s_strRelativePath = "";
|
|
|
|
static std::string s_strResourcePath = "";
|
2010-12-06 09:51:21 +08:00
|
|
|
|
|
|
|
void CCFileUtils::setRelativePath(const char* pszRelativePath)
|
|
|
|
{
|
2011-03-08 13:49:58 +08:00
|
|
|
CCAssert(pszRelativePath != NULL, "[FileUtils setRelativePath] -- wrong relative path");
|
2010-12-06 09:51:21 +08:00
|
|
|
|
|
|
|
if (! pszRelativePath)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-26 17:24:37 +08:00
|
|
|
s_strRelativePath = pszRelativePath;
|
2010-12-06 09:51:21 +08:00
|
|
|
|
|
|
|
// if the path is not ended with '/', append it
|
2011-03-26 17:24:37 +08:00
|
|
|
if (s_strRelativePath.find("/") != (strlen(s_strRelativePath.c_str()) - 1))
|
2010-12-06 09:51:21 +08:00
|
|
|
{
|
2011-03-26 17:24:37 +08:00
|
|
|
s_strRelativePath += "/";
|
2010-12-06 09:51:21 +08:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2011-03-26 17:24:37 +08:00
|
|
|
s_strResourcePath = pszResourcePath;
|
2010-11-03 11:01:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* CCFileUtils::getResourcePath()
|
|
|
|
{
|
2011-03-26 17:24:37 +08:00
|
|
|
return s_strResourcePath.c_str();
|
2010-11-03 11:01:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
|
|
|
{
|
2010-12-06 09:51:21 +08:00
|
|
|
return pszRelativePath;
|
2010-11-03 11:01:17 +08:00
|
|
|
}
|
2010-12-06 09:51:21 +08:00
|
|
|
|
2010-11-03 11:01:17 +08:00
|
|
|
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
|
|
|
|
{
|
2010-12-06 09:51:21 +08:00
|
|
|
//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();
|
|
|
|
}
|
2010-12-06 09:51:21 +08:00
|
|
|
|
2011-03-26 17:24:37 +08:00
|
|
|
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
|
|
|
{
|
|
|
|
string fullPath = s_strRelativePath + pszFileName;
|
2011-03-29 15:05:53 +08:00
|
|
|
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;
|
2011-03-26 17:24:37 +08:00
|
|
|
}
|
|
|
|
|
2011-04-25 09:40:10 +08:00
|
|
|
void CCFileUtils::setResource(const char* pszZipFileName)
|
2010-11-03 11:01:17 +08:00
|
|
|
{
|
2011-03-26 17:24:37 +08:00
|
|
|
CCAssert(0, "Have not implement!");
|
2010-11-03 11:01:17 +08:00
|
|
|
}
|
2010-12-06 09:51:21 +08:00
|
|
|
|
2011-03-26 17:24:37 +08:00
|
|
|
int CCFileUtils::ccLoadFileIntoMemory(const char *filename, unsigned char **out)
|
|
|
|
{
|
|
|
|
CCAssert(0, "Have not implement!");
|
|
|
|
return 0;
|
2010-12-06 09:51:21 +08:00
|
|
|
}
|
|
|
|
|
2011-03-26 17:24:37 +08:00
|
|
|
NS_CC_END;
|