Using full path in CCFileUtils::getFileData.

This commit is contained in:
James Chen 2013-01-28 23:37:04 +08:00
parent 7c89086173
commit c160d3ed0a
6 changed files with 55 additions and 49 deletions

View File

@ -161,13 +161,14 @@ const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{
unsigned char *buffer = 0;
std::string full_path(pszFileName);
if (!pszFileName || !pszMode)
{
return 0;
}
std::string full_path = fullPathForFilename(pszFileName);
do
{
// read from other path than user set it

View File

@ -425,7 +425,7 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
do
{
// read the file from hardware
std::string fullPath = pszFileName;
std::string fullPath = fullPathForFilename(pszFileName);
FILE *fp = fopen(fullPath.c_str(), pszMode);
CC_BREAK_IF(!fp);

View File

@ -171,8 +171,9 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
do
{
std::string fullPath = fullPathForFilename(pszFileName);
// read rrom other path than user set it
FILE *fp = fopen(pszFileName, pszMode);
FILE *fp = fopen(fullPath.c_str(), pszMode);
CC_BREAK_IF(!fp);
fseek(fp,0,SEEK_END);

View File

@ -424,8 +424,9 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
*pSize = 0;
do
{
std::string fullPath = fullPathForFilename(pszFileName);
// read the file from hardware
FILE *fp = fopen(pszFileName, pszMode);
FILE *fp = fopen(fullPath.c_str(), pszMode);
CC_BREAK_IF(!fp);
fseek(fp,0,SEEK_END);

View File

@ -166,7 +166,9 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
{
IW_CALLSTACK("CCFileUtils::getFileData");
s3eFile* pFile = s3eFileOpen(pszFileName, pszMode);
std::string fullPath = fullPathForFilename(pszFileName);
s3eFile* pFile = s3eFileOpen(fullPath.c_str(), pszMode);
if (! pFile && isPopupNotify())
{

View File

@ -182,8 +182,9 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
*pSize = 0;
do
{
std::string fullPath = fullPathForFilename(pszFileName);
// read the file from hardware
FILE *fp = fopen(pszFileName, pszMode);
FILE *fp = fopen(fullPath.c_str(), pszMode);
CC_BREAK_IF(!fp);
fseek(fp,0,SEEK_END);
@ -205,48 +206,48 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
return pBuffer;
}
void CCFileUtils::setResourceDirectory(const char* pszResourceDirectory)
{
if (pszResourceDirectory == NULL) return;
m_obDirectory = pszResourceDirectory;
std::vector<std::string> searchPaths = this->getSearchPath();;
searchPaths.insert(searchPaths.begin(), pszResourceDirectory);
this->setSearchPath(searchPaths);
}
void CCFileUtils::setSearchPath(const std::vector<std::string>& searchPaths)
{
bool bExistDefaultRootPath = false;
m_searchPathArray.clear();
for (std::vector<std::string>::const_iterator iter = searchPaths.begin(); iter != searchPaths.end(); ++iter)
{
std::string strPrefix;
std::string path;
if (iter->length() > 1 && (*iter)[1] != ':')
{ // Not an absolute path
if (iter->find(m_strDefaultResRootPath) != 0)
{ // The path contains no default resource root path, insert the root path.
strPrefix = m_strDefaultResRootPath;
}
}
path = strPrefix+(*iter);
if (path.length() > 0 && path[path.length()-1] != '/' && path[path.length()-1] != '\\')
{
path += "/";
}
if (!bExistDefaultRootPath && path == m_strDefaultResRootPath)
{
bExistDefaultRootPath = true;
}
m_searchPathArray.push_back(path);
}
if (!bExistDefaultRootPath)
{
CCLOG("Default root path doesn't exist, adding it.");
m_searchPathArray.push_back(m_strDefaultResRootPath);
}
void CCFileUtils::setResourceDirectory(const char* pszResourceDirectory)
{
if (pszResourceDirectory == NULL) return;
m_obDirectory = pszResourceDirectory;
std::vector<std::string> searchPaths = this->getSearchPath();;
searchPaths.insert(searchPaths.begin(), pszResourceDirectory);
this->setSearchPath(searchPaths);
}
void CCFileUtils::setSearchPath(const std::vector<std::string>& searchPaths)
{
bool bExistDefaultRootPath = false;
m_searchPathArray.clear();
for (std::vector<std::string>::const_iterator iter = searchPaths.begin(); iter != searchPaths.end(); ++iter)
{
std::string strPrefix;
std::string path;
if (iter->length() > 1 && (*iter)[1] != ':')
{ // Not an absolute path
if (iter->find(m_strDefaultResRootPath) != 0)
{ // The path contains no default resource root path, insert the root path.
strPrefix = m_strDefaultResRootPath;
}
}
path = strPrefix+(*iter);
if (path.length() > 0 && path[path.length()-1] != '/' && path[path.length()-1] != '\\')
{
path += "/";
}
if (!bExistDefaultRootPath && path == m_strDefaultResRootPath)
{
bExistDefaultRootPath = true;
}
m_searchPathArray.push_back(path);
}
if (!bExistDefaultRootPath)
{
CCLOG("Default root path doesn't exist, adding it.");
m_searchPathArray.push_back(m_strDefaultResRootPath);
}
}
string CCFileUtils::getWriteablePath()