Merge pull request #978 from minggo/iss1202_remove_CCFileData

fixed #1202:remove CCFileData
This commit is contained in:
minggo 2012-06-06 23:15:05 -07:00
commit 2b55a76970
8 changed files with 35 additions and 55 deletions

View File

@ -44,9 +44,8 @@ CCData::~CCData(void)
CCData* CCData::dataWithContentsOfFile(const string &strPath)
{
CCFileData data(strPath.c_str(), "rb");
unsigned long nSize = data.getSize();
unsigned char* pBuffer = data.getBuffer();
unsigned long nSize;
unsigned char *pBuffer = CCFileUtils::getFileData(strPath.c_str(), "rb", &nSize);
if (! pBuffer)
{

View File

@ -473,10 +473,9 @@ void CCBMFontConfiguration::purgeFontDefDictionary()
void CCBMFontConfiguration::parseConfigFile(const char *controlFile)
{
std::string fullpath = CCFileUtils::fullPathFromRelativePath(controlFile);
CCFileData data(fullpath.c_str(), "rb");
unsigned long nBufSize = data.getSize();
char* pBuffer = (char*) data.getBuffer();
unsigned long nBufSize;
char *pBuffer = (char*)CCFileUtils::getFileData(fullpath.c_str(), "rb", &nBufSize);
CCAssert(pBuffer, "CCBMFontConfiguration::parseConfigFile | Open file error.");

View File

@ -163,32 +163,6 @@ public:
static int ccLoadFileIntoMemory(const char *filename, unsigned char **out);
};
class CCFileData
{
public:
CCFileData(const char* pszFileName, const char* pszMode)
: m_pBuffer(0)
, m_uSize(0)
{
m_pBuffer = CCFileUtils::getFileData(pszFileName, pszMode, &m_uSize);
}
~CCFileData()
{
CC_SAFE_DELETE_ARRAY(m_pBuffer);
}
bool reset(const char* pszFileName, const char* pszMode)
{
CC_SAFE_DELETE_ARRAY(m_pBuffer);
m_uSize = 0;
m_pBuffer = CCFileUtils::getFileData(pszFileName, pszMode, &m_uSize);
return (m_pBuffer) ? true : false;
}
CC_SYNTHESIZE_READONLY(unsigned char *, m_pBuffer, Buffer);
CC_SYNTHESIZE_READONLY(unsigned long , m_uSize, Size);
};
NS_CC_END
#endif // __CC_FILEUTILS_PLATFORM_H__

View File

@ -95,15 +95,21 @@ CCImage::~CCImage()
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/)
{
CC_UNUSED_PARAM(eImgFmt);
CCFileData data(CCFileUtils::fullPathFromRelativePath(strPath), "rb");
return initWithImageData(data.getBuffer(), data.getSize(), eImgFmt);
unsigned long nSize;
unsigned char *pBuffer = CCFileUtils::getFileData(CCFileUtils::fullPathFromRelativePath(strPath), "rb", &nSize);
return initWithImageData(pBuffer, nSize, eImgFmt);
}
bool CCImage::initWithImageFileThreadSafe(const char *fullpath, EImageFormat imageType)
{
CC_UNUSED_PARAM(imageType);
CCFileData data(fullpath, "rb");
return initWithImageData(data.getBuffer(), data.getSize(), imageType);
unsigned long nSize;
unsigned char *pBuffer = CCFileUtils::getFileData(fullpath, "rb", &nSize);
return initWithImageData(pBuffer, nSize, imageType);
}
bool CCImage::initWithImageData(void * pData,

View File

@ -83,9 +83,8 @@ bool CCSAXParser::parse(const char* pXMLData, unsigned int uDataLength)
bool CCSAXParser::parse(const char *pszFile)
{
CCFileData data(pszFile, "rt");
unsigned long size = data.getSize();
char *pBuffer = (char*) data.getBuffer();
unsigned long size;
char *pBuffer = (char*)CCFileUtils::getFileData(pszFile, "rt", &size);
if (!pBuffer)
{

View File

@ -347,8 +347,10 @@ CCImage::~CCImage()
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/)
{
CCFileData data(CCFileUtils::fullPathFromRelativePath(strPath), "rb");
return initWithImageData(data.getBuffer(), data.getSize(), eImgFmt);
unsigned long nSize;
unsigned char *pBuffer = CCFileUtils::getFileData(CCFileUtils::fullPathFromRelativePath(strPath), "rb", &nSize);
return initWithImageData(pBuffer, nSize, eImgFmt);
}
bool CCImage::initWithImageFileThreadSafe(const char *fullpath, EImageFormat imageType)
@ -356,9 +358,11 @@ bool CCImage::initWithImageFileThreadSafe(const char *fullpath, EImageFormat ima
CC_UNUSED_PARAM(imageType);
/*
* CCFileUtils::fullPathFromRelativePath() is not thread-safe, it use autorelease().
*/
CCFileData data(fullpath, "rb");
return initWithImageData(data.getBuffer(), data.getSize(), imageType);
*/
unsigned long nSize;
unsigned char *pBuffer = CCFileUtils::getFileData(fullpath, "rb", &nSize);
return initWithImageData(pBuffer, nSize, imageType);
}
bool CCImage::initWithImageData(void * pData,

View File

@ -197,9 +197,9 @@ tImageTGA * tgaLoad(const char *pszFilename)
{
int mode,total;
tImageTGA *info = NULL;
CCFileData data(pszFilename, "rb");
unsigned long nSize = data.getSize();
unsigned char* pBuffer = data.getBuffer();
unsigned long nSize;
unsigned char *pBuffer = CCFileUtils::getFileData(pszFilename, "rb", &nSize);
do
{

View File

@ -438,10 +438,9 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
eImageFormat = CCImage::kFmtTiff;
}
CCImage image;
CCFileData data(fullpath.c_str(), "rb");
unsigned long nSize = data.getSize();
unsigned char* pBuffer = data.getBuffer();
CCImage image;
unsigned long nSize;
unsigned char *pBuffer = CCFileUtils::getFileData(fullpath.c_str(), "rb", &nSize);
CC_BREAK_IF(! image.initWithImageData((void*)pBuffer, nSize, eImageFormat));
texture = new CCTexture2D();
@ -851,9 +850,9 @@ void VolatileTexture::reloadAllTextures()
}
else
{
CCFileData data(vt->m_strFileName.c_str(), "rb");
unsigned long nSize = data.getSize();
unsigned char* pBuffer = data.getBuffer();
unsigned long nSize;
unsigned char *pBuffer = CCFileUtils::getFileData(vt->m_strFileName.c_str(), "rb", &nSize);
if (image.initWithImageData((void*)pBuffer, nSize, vt->m_FmtImage))
{