mirror of https://github.com/axmolengine/axmol.git
Merge branch 'yangws-439'
This commit is contained in:
commit
70eb85e6df
|
@ -46,9 +46,9 @@ CCData::~CCData(void)
|
||||||
|
|
||||||
CCData* CCData::dataWithContentsOfFile(const string &strPath)
|
CCData* CCData::dataWithContentsOfFile(const string &strPath)
|
||||||
{
|
{
|
||||||
FileData data;
|
CCFileData data(strPath.c_str(), "rb");
|
||||||
unsigned long nSize = 0;
|
unsigned long nSize = data.getSize();
|
||||||
unsigned char* pBuffer = data.getFileData(strPath.c_str(), "rb", &nSize);
|
unsigned char* pBuffer = data.getBuffer();
|
||||||
|
|
||||||
if (! pBuffer)
|
if (! pBuffer)
|
||||||
{
|
{
|
||||||
|
|
|
@ -125,9 +125,9 @@ namespace cocos2d{
|
||||||
{
|
{
|
||||||
std::string fullpath = CCFileUtils::fullPathFromRelativePath(controlFile);
|
std::string fullpath = CCFileUtils::fullPathFromRelativePath(controlFile);
|
||||||
|
|
||||||
FileData data;
|
CCFileData data(controlFile, "rb");
|
||||||
unsigned long nBufSize = 0;
|
unsigned long nBufSize = data.getSize();
|
||||||
char* pBuffer = (char*) data.getFileData(fullpath.c_str(), "r", &nBufSize);
|
char* pBuffer = (char*) data.getBuffer();
|
||||||
|
|
||||||
CCAssert(pBuffer, "CCBMFontConfiguration::parseConfigFile | Open file error.");
|
CCAssert(pBuffer, "CCBMFontConfiguration::parseConfigFile | Open file error.");
|
||||||
|
|
||||||
|
|
|
@ -262,12 +262,12 @@ bool CCParticleSystem::initWithDictionary(CCDictionary<std::string, CCObject*> *
|
||||||
if (strlen(textureName) > 0)
|
if (strlen(textureName) > 0)
|
||||||
{
|
{
|
||||||
// set not pop-up message box when load image failed
|
// set not pop-up message box when load image failed
|
||||||
bool bNotify = CCImage::getIsPopupNotify();
|
bool bNotify = CCFileUtils::getIsPopupNotify();
|
||||||
CCImage::setIsPopupNotify(false);
|
CCFileUtils::setIsPopupNotify(false);
|
||||||
this->m_pTexture = CCTextureCache::sharedTextureCache()->addImage(fullpath.c_str());
|
this->m_pTexture = CCTextureCache::sharedTextureCache()->addImage(fullpath.c_str());
|
||||||
|
|
||||||
// reset the value of UIImage notify
|
// reset the value of UIImage notify
|
||||||
CCImage::setIsPopupNotify(bNotify);
|
CCFileUtils::setIsPopupNotify(bNotify);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it fails, try to get it from the base64-gzipped data
|
// if it fails, try to get it from the base64-gzipped data
|
||||||
|
|
|
@ -48,6 +48,11 @@ void CCLog(const char * pszFormat, ...)
|
||||||
OutputDebugStringA("\n");
|
OutputDebugStringA("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCMessageBox(const char * pszMsg, const char * pszTitle)
|
||||||
|
{
|
||||||
|
MessageBoxA(NULL, pszMsg, pszTitle, MB_OK);
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END;
|
NS_CC_END;
|
||||||
|
|
||||||
#endif // CC_PLATFORM_WIN32
|
#endif // CC_PLATFORM_WIN32
|
||||||
|
@ -94,6 +99,16 @@ void CCLog(const char * pszFormat, ...)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCMessageBox(const char * pszMsg, const char * pszTitle)
|
||||||
|
{
|
||||||
|
TUChar tszMsg[MAX_LEN] = { 0 };
|
||||||
|
TUChar tszTitle[MAX_LEN] = { 0 };
|
||||||
|
TUString::StrUtf8ToStrUnicode(tszMsg,(Char*)pszMsg);
|
||||||
|
TUString::StrUtf8ToStrUnicode(tszTitle,(Char*)pszTitle);
|
||||||
|
TMessageBox box(tszMsg, tszTitle, WMB_OK);
|
||||||
|
box.Show();
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END;
|
NS_CC_END;
|
||||||
|
|
||||||
#endif // CC_PLATFORM_WOPHONE
|
#endif // CC_PLATFORM_WOPHONE
|
||||||
|
@ -121,6 +136,12 @@ void CCLog(const char * pszFormat, ...)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ios no MessageBox, use CCLog instead
|
||||||
|
void CCMessageBox(const char * pszMsg, const char * pszTitle)
|
||||||
|
{
|
||||||
|
CCLog("%s: %s", pszTitle, pszMsg);
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END;
|
NS_CC_END;
|
||||||
|
|
||||||
#endif // CC_PLATFORM_IOS
|
#endif // CC_PLATFORM_IOS
|
||||||
|
@ -147,6 +168,12 @@ void CCLog(const char * pszFormat, ...)
|
||||||
__android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", buf);
|
__android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// android no MessageBox, use CCLog instead
|
||||||
|
void CCMessageBox(const char * pszMsg, const char * pszTitle)
|
||||||
|
{
|
||||||
|
CCLog("%s: %s", pszTitle, pszMsg);
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END;
|
NS_CC_END;
|
||||||
|
|
||||||
#endif // CC_PLATFORM_ANDROID
|
#endif // CC_PLATFORM_ANDROID
|
||||||
|
@ -174,8 +201,13 @@ void CCLog(const char * pszFormat, ...)
|
||||||
|
|
||||||
IwTrace(GAME, (buf));
|
IwTrace(GAME, (buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// airplay no MessageBox, use CCLog instead
|
||||||
|
void CCMessageBox(const char * pszMsg, const char * pszTitle)
|
||||||
|
{
|
||||||
|
CCLog("%s: %s", pszTitle, pszMsg);
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END;
|
NS_CC_END;
|
||||||
|
|
||||||
#endif // CC_PLATFORM_AIRPLAY
|
#endif // CC_PLATFORM_AIRPLAY
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ static const int kMaxLogLen = 255;
|
||||||
@brief Output Debug message.
|
@brief Output Debug message.
|
||||||
*/
|
*/
|
||||||
void CC_DLL CCLog(const char * pszFormat, ...);
|
void CC_DLL CCLog(const char * pszFormat, ...);
|
||||||
|
void CC_DLL CCMessageBox(const char * pszMsg, const char * pszTitle);
|
||||||
|
|
||||||
NS_CC_END;
|
NS_CC_END;
|
||||||
|
|
||||||
|
|
|
@ -287,6 +287,21 @@ unsigned char* CCFileUtils::getFileDataFromZip(const char* pszZipFilePath, const
|
||||||
return pBuffer;
|
return pBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Notification support when getFileData from invalid file path.
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
static bool s_bPopupNotify = true;
|
||||||
|
|
||||||
|
void CCFileUtils::setIsPopupNotify(bool bNotify)
|
||||||
|
{
|
||||||
|
s_bPopupNotify = bNotify;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCFileUtils::getIsPopupNotify()
|
||||||
|
{
|
||||||
|
return s_bPopupNotify;
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END;
|
NS_CC_END;
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||||
|
@ -301,4 +316,4 @@ NS_CC_END;
|
||||||
#include "android/CCFileUtils_android.cpp"
|
#include "android/CCFileUtils_android.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_IOS)
|
#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_IOS && CC_TARGET_PLATFORM != CC_PLATFORM_AIRPLAY)
|
||||||
|
|
|
@ -86,6 +86,12 @@ public:
|
||||||
*/
|
*/
|
||||||
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName);
|
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Set/Get whether pop-up a message box when the image load failed
|
||||||
|
*/
|
||||||
|
static void setIsPopupNotify(bool bNotify);
|
||||||
|
static bool getIsPopupNotify();
|
||||||
|
|
||||||
///////////////////////////////////////////////////
|
///////////////////////////////////////////////////
|
||||||
// interfaces on wophone
|
// interfaces on wophone
|
||||||
///////////////////////////////////////////////////
|
///////////////////////////////////////////////////
|
||||||
|
@ -108,33 +114,30 @@ public:
|
||||||
int ccLoadFileIntoMemory(const char *filename, unsigned char **out);
|
int ccLoadFileIntoMemory(const char *filename, unsigned char **out);
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileData
|
class CCFileData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileData() : m_pBuffer(NULL) {}
|
CCFileData(const char* pszFileName, const char* pszMode)
|
||||||
~FileData()
|
: m_pBuffer(0)
|
||||||
|
, m_uSize(0)
|
||||||
{
|
{
|
||||||
if (m_pBuffer)
|
m_pBuffer = CCFileUtils::getFileData(pszFileName, pszMode, &m_uSize);
|
||||||
{
|
}
|
||||||
delete [] m_pBuffer;
|
~CCFileData()
|
||||||
m_pBuffer = NULL;
|
{
|
||||||
}
|
CC_SAFE_DELETE_ARRAY(m_pBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
bool reset(const char* pszFileName, const char* pszMode)
|
||||||
{
|
{
|
||||||
if (m_pBuffer)
|
CC_SAFE_DELETE_ARRAY(m_pBuffer);
|
||||||
{
|
m_uSize = 0;
|
||||||
delete [] m_pBuffer;
|
m_pBuffer = CCFileUtils::getFileData(pszFileName, pszMode, &m_uSize);
|
||||||
m_pBuffer = NULL;
|
return (m_pBuffer) ? true : false;
|
||||||
}
|
|
||||||
|
|
||||||
m_pBuffer = CCFileUtils::getFileData(pszFileName, pszMode, pSize);
|
|
||||||
return m_pBuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
CC_SYNTHESIZE_READONLY(unsigned char *, m_pBuffer, Buffer);
|
||||||
unsigned char* m_pBuffer;
|
CC_SYNTHESIZE_READONLY(unsigned long , m_uSize, Size);
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END;
|
NS_CC_END;
|
||||||
|
|
|
@ -26,6 +26,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCCommon.h"
|
#include "CCCommon.h"
|
||||||
#include "CCStdC.h"
|
#include "CCStdC.h"
|
||||||
|
#include "CCFileUtils.h"
|
||||||
#include "png.h"
|
#include "png.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -63,8 +64,6 @@ static void pngReadCallback(png_structp png_ptr, png_bytep data, png_size_t leng
|
||||||
|
|
||||||
NS_CC_BEGIN;
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
static void CCMessageBox(const std::string& msg, const std::string& title);
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// Impliment CCImage
|
// Impliment CCImage
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -87,51 +86,8 @@ CCImage::~CCImage()
|
||||||
|
|
||||||
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/)
|
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
CCFileData data(CCFileUtils::fullPathFromRelativePath(strPath), "rb");
|
||||||
FILE *fp = 0;
|
return initWithImageData(data.getBuffer(), data.getSize());
|
||||||
unsigned char *buffer = NULL;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
// open file
|
|
||||||
fp = fopen(strPath, "rb");
|
|
||||||
CC_BREAK_IF(! fp);
|
|
||||||
|
|
||||||
// compute the length of file
|
|
||||||
fseek(fp,0,SEEK_END);
|
|
||||||
int size = ftell(fp);
|
|
||||||
fseek(fp,0,SEEK_SET);
|
|
||||||
|
|
||||||
// allocate enough memory to save the data of file
|
|
||||||
buffer = new unsigned char[size];
|
|
||||||
CC_BREAK_IF(! buffer);
|
|
||||||
|
|
||||||
// read data
|
|
||||||
size = fread(buffer, sizeof(unsigned char), size, fp);
|
|
||||||
|
|
||||||
if (kFmtJpg == eImgFmt)
|
|
||||||
{
|
|
||||||
bRet = _initWithJpgData(buffer, size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bRet = _initWithPngData(buffer, size);
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
CC_SAFE_DELETE_ARRAY(buffer);
|
|
||||||
if (fp)
|
|
||||||
{
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
if (! bRet && CCImage::getIsPopupNotify())
|
|
||||||
{
|
|
||||||
std::string title = "cocos2d-x error!";
|
|
||||||
std::string msg = "Load ";
|
|
||||||
msg.append(strPath).append(" failed!");
|
|
||||||
|
|
||||||
CCMessageBox(msg, title);
|
|
||||||
}
|
|
||||||
return bRet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/* = eSrcFmtPng*/)
|
bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/* = eSrcFmtPng*/)
|
||||||
|
@ -155,18 +111,6 @@ bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/*
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool s_bPopupNotify = true;
|
|
||||||
|
|
||||||
void CCImage::setIsPopupNotify(bool bNotify)
|
|
||||||
{
|
|
||||||
s_bPopupNotify = bNotify;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CCImage::getIsPopupNotify()
|
|
||||||
{
|
|
||||||
return s_bPopupNotify;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CCImage::_initWithJpgData(void * data, int nSize)
|
bool CCImage::_initWithJpgData(void * data, int nSize)
|
||||||
{
|
{
|
||||||
/* these are standard libjpeg structures for reading(decompression) */
|
/* these are standard libjpeg structures for reading(decompression) */
|
||||||
|
|
|
@ -107,13 +107,6 @@ public:
|
||||||
CC_SYNTHESIZE_READONLY(short, m_nHeight, Height);
|
CC_SYNTHESIZE_READONLY(short, m_nHeight, Height);
|
||||||
CC_SYNTHESIZE_READONLY(int, m_nBitsPerComponent, BitsPerComponent);
|
CC_SYNTHESIZE_READONLY(int, m_nBitsPerComponent, BitsPerComponent);
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
@brief Set/Get whether pop-up a message box when the image load failed
|
|
||||||
*/
|
|
||||||
static void setIsPopupNotify(bool bNotify);
|
|
||||||
static bool getIsPopupNotify();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool _initWithJpgData(void * pData, int nDatalen);
|
bool _initWithJpgData(void * pData, int nDatalen);
|
||||||
bool _initWithPngData(void * pData, int nDatalen);
|
bool _initWithPngData(void * pData, int nDatalen);
|
||||||
|
|
|
@ -49,9 +49,9 @@ bool CCSAXParser::init(const char *pszEncoding)
|
||||||
|
|
||||||
bool CCSAXParser::parse(const char *pszFile)
|
bool CCSAXParser::parse(const char *pszFile)
|
||||||
{
|
{
|
||||||
FileData data;
|
CCFileData data(pszFile, "rt");
|
||||||
unsigned long size = 0;
|
unsigned long size = data.getSize();
|
||||||
char *pBuffer = (char*) data.getFileData(pszFile, "r", &size);
|
char *pBuffer = (char*) data.getBuffer();
|
||||||
|
|
||||||
if (!pBuffer)
|
if (!pBuffer)
|
||||||
{
|
{
|
||||||
|
|
|
@ -281,9 +281,15 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
|
||||||
|
|
||||||
s3eFile* pFile = s3eFileOpen(pszFileName, pszMode);
|
s3eFile* pFile = s3eFileOpen(pszFileName, pszMode);
|
||||||
|
|
||||||
|
if (! pFile && getIsPopupNotify())
|
||||||
IwAssertMsg(GAME, pFile, ("Open file %s Failed. s3eFileError Code : %i", pszFileName, s3eFileGetError()));
|
{
|
||||||
|
IwAssertMsg(GAME, pFile, ("Open file %s Failed. s3eFileError Code : %i", pszFileName, s3eFileGetError()));
|
||||||
|
}
|
||||||
|
if (! pFile)
|
||||||
|
{
|
||||||
|
*pSize = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int32 fileSize = s3eFileGetSize(pFile);
|
int32 fileSize = s3eFileGetSize(pFile);
|
||||||
*pSize=fileSize;
|
*pSize=fileSize;
|
||||||
|
|
||||||
|
@ -319,5 +325,20 @@ std::string& CCFileUtils::ccRemoveHDSuffixFromFile(std::string& path)
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Notification support when getFileData from a invalid file
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
static bool s_bPopupNotify = true;
|
||||||
|
|
||||||
|
void CCFileUtils::setIsPopupNotify(bool bNotify)
|
||||||
|
{
|
||||||
|
s_bPopupNotify = bNotify;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCFileUtils::getIsPopupNotify()
|
||||||
|
{
|
||||||
|
return s_bPopupNotify;
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END;
|
NS_CC_END;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "CCImage.h"
|
#include "CCImage.h"
|
||||||
#include "CCCommon.h"
|
#include "CCCommon.h"
|
||||||
#include "CCStdC.h"
|
#include "CCStdC.h"
|
||||||
|
#include "CCFileUtils.h"
|
||||||
#include "s3eFile.h"
|
#include "s3eFile.h"
|
||||||
#include "IwImage.h"
|
#include "IwImage.h"
|
||||||
#include "IwUtil.h"
|
#include "IwUtil.h"
|
||||||
|
@ -61,52 +62,8 @@ CCImage::~CCImage()
|
||||||
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/)
|
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/)
|
||||||
{
|
{
|
||||||
IW_CALLSTACK("UIImage::initWithImageFile");
|
IW_CALLSTACK("UIImage::initWithImageFile");
|
||||||
|
CCFileData data(CCFileUtils::fullPathFromRelativePath(strPath), "rb");
|
||||||
bool bRet = false;
|
return initWithImageData(data.getBuffer(), data.getSize(), eImgFmt);
|
||||||
FILE *fp = 0;
|
|
||||||
unsigned char *buffer = NULL;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
// open file
|
|
||||||
fp = fopen(strPath, "rb");
|
|
||||||
CC_BREAK_IF(! fp);
|
|
||||||
|
|
||||||
// compute the length of file
|
|
||||||
fseek(fp,0,SEEK_END);
|
|
||||||
int size = ftell(fp);
|
|
||||||
fseek(fp,0,SEEK_SET);
|
|
||||||
|
|
||||||
// allocate enough memory to save the data of file
|
|
||||||
buffer = new unsigned char[size];
|
|
||||||
CC_BREAK_IF(! buffer);
|
|
||||||
|
|
||||||
// read data
|
|
||||||
size = fread(buffer, sizeof(unsigned char), size, fp);
|
|
||||||
|
|
||||||
if (kFmtJpg == eImgFmt)
|
|
||||||
{
|
|
||||||
bRet = _initWithJpgData(buffer, size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bRet = _initWithPngData(buffer, size);
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
CC_SAFE_DELETE_ARRAY(buffer);
|
|
||||||
if (fp)
|
|
||||||
{
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
if (! bRet && CCImage::getIsPopupNotify())
|
|
||||||
{
|
|
||||||
std::string title = "cocos2d-x error!";
|
|
||||||
std::string msg = "Load ";
|
|
||||||
msg.append(strPath).append(" failed!");
|
|
||||||
|
|
||||||
IwError(("cocos2d-x error! Load %s failed", strPath));
|
|
||||||
}
|
|
||||||
return bRet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/* = eSrcFmtPng*/)
|
bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/* = eSrcFmtPng*/)
|
||||||
|
@ -129,16 +86,6 @@ bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/*
|
||||||
} while (0);
|
} while (0);
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
static bool s_bPopupNotify = true;
|
|
||||||
void CCImage::setIsPopupNotify(bool bNotify)
|
|
||||||
{
|
|
||||||
s_bPopupNotify = bNotify;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CCImage::getIsPopupNotify()
|
|
||||||
{
|
|
||||||
return s_bPopupNotify;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CCImage::_initWithJpgData(void * data, int nSize)
|
bool CCImage::_initWithJpgData(void * data, int nSize)
|
||||||
{
|
{
|
||||||
|
|
|
@ -82,7 +82,15 @@ const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const
|
||||||
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
||||||
{
|
{
|
||||||
string fullPath = s_strRelativePath + pszFileName;
|
string fullPath = s_strRelativePath + pszFileName;
|
||||||
return CCFileUtils::getFileDataFromZip(s_strResourcePath.c_str(), fullPath.c_str(), pSize);
|
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, const char* pszResPath)
|
void CCFileUtils::setResource(const char* pszZipFileName, const char* pszResPath)
|
||||||
|
|
|
@ -42,12 +42,6 @@ static int sk_atomic_dec(int *value)
|
||||||
|
|
||||||
NS_CC_BEGIN;
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
// android not support
|
|
||||||
void CCMessageBox(const std::string& msg, const std::string& title)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class BitmapDC
|
class BitmapDC
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -38,83 +38,83 @@ THE SOFTWARE.
|
||||||
static const char *static_ccRemoveHDSuffixFromFile( const char *pszPath)
|
static const char *static_ccRemoveHDSuffixFromFile( const char *pszPath)
|
||||||
{
|
{
|
||||||
#if CC_IS_RETINA_DISPLAY_SUPPORTED
|
#if CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||||
|
|
||||||
if(cocos2d::CC_CONTENT_SCALE_FACTOR() == 2 ) {
|
if(cocos2d::CC_CONTENT_SCALE_FACTOR() == 2 ) {
|
||||||
NSString *path = [NSString stringWithUTF8String: pszPath];
|
NSString *path = [NSString stringWithUTF8String: pszPath];
|
||||||
NSString *name = [path lastPathComponent];
|
NSString *name = [path lastPathComponent];
|
||||||
NSString *suffix = [NSString stringWithUTF8String: CC_RETINA_DISPLAY_FILENAME_SUFFIX];
|
NSString *suffix = [NSString stringWithUTF8String: CC_RETINA_DISPLAY_FILENAME_SUFFIX];
|
||||||
|
|
||||||
// check if path already has the suffix.
|
// check if path already has the suffix.
|
||||||
if( [name rangeOfString: suffix].location != NSNotFound ) {
|
if( [name rangeOfString: suffix].location != NSNotFound ) {
|
||||||
|
|
||||||
CCLOG("cocos2d: Filename(%@) contains %@ suffix. Removing it. See cocos2d issue #1040", path, CC_RETINA_DISPLAY_FILENAME_SUFFIX);
|
CCLOG("cocos2d: Filename(%@) contains %@ suffix. Removing it. See cocos2d issue #1040", path, CC_RETINA_DISPLAY_FILENAME_SUFFIX);
|
||||||
|
|
||||||
NSString *newLastname = [name stringByReplacingOccurrencesOfString: suffix withString:@""];
|
NSString *newLastname = [name stringByReplacingOccurrencesOfString: suffix withString:@""];
|
||||||
|
|
||||||
NSString *pathWithoutLastname = [path stringByDeletingLastPathComponent];
|
NSString *pathWithoutLastname = [path stringByDeletingLastPathComponent];
|
||||||
return [[pathWithoutLastname stringByAppendingPathComponent:newLastname] UTF8String];
|
return [[pathWithoutLastname stringByAppendingPathComponent:newLastname] UTF8String];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||||
|
|
||||||
return pszPath;
|
return pszPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NSString* getDoubleResolutionImage(NSString* path)
|
static NSString* getDoubleResolutionImage(NSString* path)
|
||||||
{
|
{
|
||||||
#if CC_IS_RETINA_DISPLAY_SUPPORTED
|
#if CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||||
|
|
||||||
if( cocos2d::CC_CONTENT_SCALE_FACTOR() == 2 )
|
if( cocos2d::CC_CONTENT_SCALE_FACTOR() == 2 )
|
||||||
{
|
{
|
||||||
|
|
||||||
NSString *pathWithoutExtension = [path stringByDeletingPathExtension];
|
NSString *pathWithoutExtension = [path stringByDeletingPathExtension];
|
||||||
NSString *name = [pathWithoutExtension lastPathComponent];
|
NSString *name = [pathWithoutExtension lastPathComponent];
|
||||||
NSString *suffix = [NSString stringWithUTF8String: CC_RETINA_DISPLAY_FILENAME_SUFFIX];
|
NSString *suffix = [NSString stringWithUTF8String: CC_RETINA_DISPLAY_FILENAME_SUFFIX];
|
||||||
|
|
||||||
// check if path already has the suffix.
|
// check if path already has the suffix.
|
||||||
if( [name rangeOfString: suffix].location != NSNotFound ) {
|
if( [name rangeOfString: suffix].location != NSNotFound ) {
|
||||||
|
|
||||||
CCLOG("cocos2d: WARNING Filename(%@) already has the suffix %@. Using it.", name, CC_RETINA_DISPLAY_FILENAME_SUFFIX);
|
CCLOG("cocos2d: WARNING Filename(%@) already has the suffix %@. Using it.", name, CC_RETINA_DISPLAY_FILENAME_SUFFIX);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NSString *extension = [path pathExtension];
|
NSString *extension = [path pathExtension];
|
||||||
|
|
||||||
if( [extension isEqualToString:@"ccz"] || [extension isEqualToString:@"gz"] )
|
if( [extension isEqualToString:@"ccz"] || [extension isEqualToString:@"gz"] )
|
||||||
{
|
{
|
||||||
// All ccz / gz files should be in the format filename.xxx.ccz
|
// All ccz / gz files should be in the format filename.xxx.ccz
|
||||||
// so we need to pull off the .xxx part of the extension as well
|
// so we need to pull off the .xxx part of the extension as well
|
||||||
extension = [NSString stringWithFormat:@"%@.%@", [pathWithoutExtension pathExtension], extension];
|
extension = [NSString stringWithFormat:@"%@.%@", [pathWithoutExtension pathExtension], extension];
|
||||||
pathWithoutExtension = [pathWithoutExtension stringByDeletingPathExtension];
|
pathWithoutExtension = [pathWithoutExtension stringByDeletingPathExtension];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NSString *retinaName = [pathWithoutExtension stringByAppendingString: suffix];
|
NSString *retinaName = [pathWithoutExtension stringByAppendingString: suffix];
|
||||||
retinaName = [retinaName stringByAppendingPathExtension:extension];
|
retinaName = [retinaName stringByAppendingPathExtension:extension];
|
||||||
|
|
||||||
NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];
|
NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];
|
||||||
if( [fileManager fileExistsAtPath:retinaName] )
|
if( [fileManager fileExistsAtPath:retinaName] )
|
||||||
return retinaName;
|
return retinaName;
|
||||||
|
|
||||||
CCLOG("cocos2d: CCFileUtils: Warning HD file not found: %@", [retinaName lastPathComponent] );
|
CCLOG("cocos2d: CCFileUtils: Warning HD file not found: %@", [retinaName lastPathComponent] );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* static_fullPathFromRelativePath(const char *pszRelativePath)
|
static const char* static_fullPathFromRelativePath(const char *pszRelativePath)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
// NSAssert(pszRelativePath != nil, @"CCFileUtils: Invalid path");
|
// NSAssert(pszRelativePath != nil, @"CCFileUtils: Invalid path");
|
||||||
|
|
||||||
// do not convert an absolute path (starting with '/')
|
// do not convert an absolute path (starting with '/')
|
||||||
NSString *relPath = [NSString stringWithUTF8String: pszRelativePath];
|
NSString *relPath = [NSString stringWithUTF8String: pszRelativePath];
|
||||||
NSString *fullpath = nil;
|
NSString *fullpath = nil;
|
||||||
|
|
||||||
// only if it is not an absolute path
|
// only if it is not an absolute path
|
||||||
if( ! [relPath isAbsolutePath] )
|
if( ! [relPath isAbsolutePath] )
|
||||||
|
@ -319,15 +319,15 @@ public:
|
||||||
|
|
||||||
// record the resource path
|
// record the resource path
|
||||||
static char s_pszResourcePath[MAX_PATH] = {0};
|
static char s_pszResourcePath[MAX_PATH] = {0};
|
||||||
|
|
||||||
void CCFileUtils::setResourcePath(const char *pszResourcePath)
|
void CCFileUtils::setResourcePath(const char *pszResourcePath)
|
||||||
{
|
{
|
||||||
// NSAssert(pszResourcePath != NULL, "[FileUtils setResourcePath] -- wrong resource path");
|
// NSAssert(pszResourcePath != NULL, "[FileUtils setResourcePath] -- wrong resource path");
|
||||||
// NSAssert(strlen(pszResourcePath) <= MAX_PATH, "[FileUtils setResourcePath] -- resource path too long");
|
// NSAssert(strlen(pszResourcePath) <= MAX_PATH, "[FileUtils setResourcePath] -- resource path too long");
|
||||||
|
|
||||||
strcpy(s_pszResourcePath, pszResourcePath);
|
strcpy(s_pszResourcePath, pszResourcePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CCFileUtils::getResourcePath()
|
const char* CCFileUtils::getResourcePath()
|
||||||
{
|
{
|
||||||
return s_pszResourcePath;
|
return s_pszResourcePath;
|
||||||
|
@ -337,18 +337,18 @@ public:
|
||||||
{
|
{
|
||||||
assert( out );
|
assert( out );
|
||||||
assert( &*out );
|
assert( &*out );
|
||||||
|
|
||||||
int size = 0;
|
int size = 0;
|
||||||
FILE *f = fopen(filename, "rb");
|
FILE *f = fopen(filename, "rb");
|
||||||
if( !f ) {
|
if( !f ) {
|
||||||
*out = NULL;
|
*out = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
size = ftell(f);
|
size = ftell(f);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
|
|
||||||
*out = (unsigned char*)malloc(size);
|
*out = (unsigned char*)malloc(size);
|
||||||
int read = fread(*out, 1, size, f);
|
int read = fread(*out, 1, size, f);
|
||||||
if( read != size ) {
|
if( read != size ) {
|
||||||
|
@ -356,23 +356,23 @@ public:
|
||||||
*out = NULL;
|
*out = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string& CCFileUtils::ccRemoveHDSuffixFromFile(std::string& path )
|
std::string& CCFileUtils::ccRemoveHDSuffixFromFile(std::string& path )
|
||||||
{
|
{
|
||||||
path = static_ccRemoveHDSuffixFromFile(path.c_str());
|
path = static_ccRemoveHDSuffixFromFile(path.c_str());
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
||||||
{
|
{
|
||||||
return static_fullPathFromRelativePath(pszRelativePath);
|
return static_fullPathFromRelativePath(pszRelativePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
|
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
|
||||||
{
|
{
|
||||||
std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
|
std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
|
||||||
|
@ -389,7 +389,7 @@ public:
|
||||||
}
|
}
|
||||||
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
||||||
{
|
{
|
||||||
unsigned char * Buffer = NULL;
|
unsigned char * pBuffer = NULL;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -400,12 +400,20 @@ public:
|
||||||
fseek(fp,0,SEEK_END);
|
fseek(fp,0,SEEK_END);
|
||||||
*pSize = ftell(fp);
|
*pSize = ftell(fp);
|
||||||
fseek(fp,0,SEEK_SET);
|
fseek(fp,0,SEEK_SET);
|
||||||
Buffer = new unsigned char[*pSize];
|
pBuffer = new unsigned char[*pSize];
|
||||||
*pSize = fread(Buffer,sizeof(unsigned char), *pSize,fp);
|
*pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
return Buffer;
|
if (! pBuffer && 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 pBuffer;
|
||||||
}
|
}
|
||||||
void CCFileUtils::setResource(const char* pszZipFileName, const char* pszResPath)
|
void CCFileUtils::setResource(const char* pszZipFileName, const char* pszResPath)
|
||||||
{
|
{
|
||||||
|
@ -415,4 +423,19 @@ public:
|
||||||
{
|
{
|
||||||
CCAssert(0, "Have not implement!");
|
CCAssert(0, "Have not implement!");
|
||||||
}
|
}
|
||||||
}//namespace cocos2d
|
|
||||||
|
// notification support when getFileData from a invalid file
|
||||||
|
static bool s_bPopupNotify = true;
|
||||||
|
|
||||||
|
void CCFileUtils::setIsPopupNotify(bool bNotify)
|
||||||
|
{
|
||||||
|
s_bPopupNotify = bNotify;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCFileUtils::getIsPopupNotify()
|
||||||
|
{
|
||||||
|
return s_bPopupNotify;
|
||||||
|
}
|
||||||
|
|
||||||
|
}//namespace cocos2d
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ THE SOFTWARE.
|
||||||
#include <Foundation/Foundation.h>
|
#include <Foundation/Foundation.h>
|
||||||
#include <UIKit/UIKit.h>
|
#include <UIKit/UIKit.h>
|
||||||
#include "CCImage.h"
|
#include "CCImage.h"
|
||||||
|
#include "CCFileUtils.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -448,13 +449,6 @@ static bool _initWithString(const char * pText, cocos2d::CCImage::ETextAlign eAl
|
||||||
|
|
||||||
NS_CC_BEGIN;
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
static bool s_bPopupNotify = true;
|
|
||||||
|
|
||||||
void CCMessageBox(const std::string& msg, const std::string& title)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
CCImage::CCImage()
|
CCImage::CCImage()
|
||||||
: m_nWidth(0)
|
: m_nWidth(0)
|
||||||
, m_nHeight(0)
|
, m_nHeight(0)
|
||||||
|
@ -473,30 +467,8 @@ CCImage::~CCImage()
|
||||||
|
|
||||||
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/)
|
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
CCFileData data(CCFileUtils::fullPathFromRelativePath(strPath), "rb");
|
||||||
tImageInfo info = {0};
|
return initWithImageData(data.getBuffer(), data.getSize(), eImgFmt);
|
||||||
|
|
||||||
switch (eImgFmt)
|
|
||||||
{
|
|
||||||
case kFmtPng:
|
|
||||||
case kFmtJpg:
|
|
||||||
bRet = _initWithFile(strPath, &info);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// unsupported image type
|
|
||||||
bRet = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (bRet)
|
|
||||||
{
|
|
||||||
m_nHeight = (short)info.height;
|
|
||||||
m_nWidth = (short)info.width;
|
|
||||||
m_nBitsPerComponent = info.bitsPerComponent;
|
|
||||||
m_bHasAlpha = info.hasAlpha;
|
|
||||||
m_bPreMulti = info.isPremultipliedAlpha;
|
|
||||||
m_pData = info.data;
|
|
||||||
}
|
|
||||||
return bRet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/* = eSrcFmtPng*/)
|
bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/* = eSrcFmtPng*/)
|
||||||
|
@ -546,15 +518,5 @@ bool CCImage::initWithString(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCImage::setIsPopupNotify(bool bNotify)
|
|
||||||
{
|
|
||||||
s_bPopupNotify = bNotify;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CCImage::getIsPopupNotify()
|
|
||||||
{
|
|
||||||
return s_bPopupNotify;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_CC_END;
|
NS_CC_END;
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const
|
||||||
|
|
||||||
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
||||||
{
|
{
|
||||||
unsigned char * Buffer = NULL;
|
unsigned char * pBuffer = NULL;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -126,12 +126,20 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
|
||||||
fseek(fp,0,SEEK_END);
|
fseek(fp,0,SEEK_END);
|
||||||
*pSize = ftell(fp);
|
*pSize = ftell(fp);
|
||||||
fseek(fp,0,SEEK_SET);
|
fseek(fp,0,SEEK_SET);
|
||||||
Buffer = new unsigned char[*pSize];
|
pBuffer = new unsigned char[*pSize];
|
||||||
*pSize = fread(Buffer,sizeof(unsigned char), *pSize,fp);
|
*pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
return Buffer;
|
if (! pBuffer && 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 pBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCFileUtils::setResource(const char* pszZipFileName, const char* pszResPath)
|
void CCFileUtils::setResource(const char* pszZipFileName, const char* pszResPath)
|
||||||
|
|
|
@ -24,11 +24,6 @@ THE SOFTWARE.
|
||||||
|
|
||||||
NS_CC_BEGIN;
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
void CCMessageBox(const std::string& msg, const std::string& title)
|
|
||||||
{
|
|
||||||
MessageBoxA(NULL, msg.c_str(), title.c_str(), MB_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief A memory DC which uses to draw text on bitmap.
|
@brief A memory DC which uses to draw text on bitmap.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -277,7 +277,7 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (strlen(s_pszZipFilePath) != 0)
|
if (0 != s_pszZipFilePath[0])
|
||||||
{
|
{
|
||||||
// if specify the zip file,load from it first
|
// if specify the zip file,load from it first
|
||||||
pBuffer = getFileDataFromZip(s_pszZipFilePath, pszFileName, pSize);
|
pBuffer = getFileDataFromZip(s_pszZipFilePath, pszFileName, pSize);
|
||||||
|
@ -292,10 +292,24 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
|
||||||
*pSize = ftell(fp);
|
*pSize = ftell(fp);
|
||||||
fseek(fp,0,SEEK_SET);
|
fseek(fp,0,SEEK_SET);
|
||||||
pBuffer = new unsigned char[*pSize];
|
pBuffer = new unsigned char[*pSize];
|
||||||
fread(pBuffer,sizeof(unsigned char), *pSize,fp);
|
*pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
|
if (! pBuffer && getIsPopupNotify())
|
||||||
|
{
|
||||||
|
std::string title = "Notification";
|
||||||
|
std::string msg = "Get data from file(";
|
||||||
|
msg.append(pszFileName);
|
||||||
|
if (0 != s_pszZipFilePath[0])
|
||||||
|
{
|
||||||
|
msg.append(") in zip archive(").append(s_pszZipFilePath);
|
||||||
|
}
|
||||||
|
msg.append(") failed!");
|
||||||
|
|
||||||
|
CCMessageBox(msg.c_str(), title.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
return pBuffer;
|
return pBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,14 +29,6 @@ NS_CC_BEGIN
|
||||||
|
|
||||||
typedef std::basic_string<TUChar> stdTUString;
|
typedef std::basic_string<TUChar> stdTUString;
|
||||||
|
|
||||||
void CCMessageBox(const std::string& msg, const std::string& title)
|
|
||||||
{
|
|
||||||
TUChar szText[256] = { 0 };
|
|
||||||
TUString::StrUtf8ToStrUnicode(szText,(Char*)msg.c_str());
|
|
||||||
TMessageBox box(szText, NULL, WMB_OK);
|
|
||||||
box.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
class BitmapDC
|
class BitmapDC
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -1065,11 +1065,15 @@
|
||||||
Name="makefile"
|
Name="makefile"
|
||||||
>
|
>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\Lib_Cocos2d_Arm_Wophone.TMK3"
|
RelativePath=".\cocos2d-wophone.TMK3"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\Makefile.ARM"
|
RelativePath=".\Makefile-dynamic.ARM"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\Makefile.ARM"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
|
|
@ -194,9 +194,9 @@ tImageTGA * tgaLoad(const char *pszFilename)
|
||||||
{
|
{
|
||||||
int mode,total;
|
int mode,total;
|
||||||
tImageTGA *info = NULL;
|
tImageTGA *info = NULL;
|
||||||
FileData data;
|
CCFileData data(pszFilename, "rb");
|
||||||
unsigned long nSize = 0;
|
unsigned long nSize = data.getSize();
|
||||||
unsigned char* pBuffer = data.getFileData(pszFilename, "rb", &nSize);
|
unsigned char* pBuffer = data.getBuffer();
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
|
@ -208,18 +208,14 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
||||||
// Issue #886: TEMPORARY FIX FOR TRANSPARENT JPEGS IN IOS4
|
// Issue #886: TEMPORARY FIX FOR TRANSPARENT JPEGS IN IOS4
|
||||||
else if (std::string::npos != lowerCase.find(".jpg") || std::string::npos != lowerCase.find(".jpeg"))
|
else if (std::string::npos != lowerCase.find(".jpg") || std::string::npos != lowerCase.find(".jpeg"))
|
||||||
{
|
{
|
||||||
CCImage * image = new CCImage();
|
CCImage image;
|
||||||
FileData data;
|
CCFileData data(fullpath.c_str(), "rb");
|
||||||
unsigned long nSize = 0;
|
unsigned long nSize = data.getSize();
|
||||||
unsigned char* pBuffer = data.getFileData(fullpath.c_str(), "rb", &nSize);
|
unsigned char* pBuffer = data.getBuffer();
|
||||||
if(! image->initWithImageData((void*)pBuffer, nSize, CCImage::kFmtJpg))
|
CC_BREAK_IF(! image.initWithImageData((void*)pBuffer, nSize, CCImage::kFmtJpg));
|
||||||
{
|
|
||||||
delete image;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
texture = new CCTexture2D();
|
texture = new CCTexture2D();
|
||||||
texture->initWithImage(image);
|
texture->initWithImage(&image);
|
||||||
CC_SAFE_DELETE(image);// image->release();
|
|
||||||
|
|
||||||
if( texture )
|
if( texture )
|
||||||
{
|
{
|
||||||
|
@ -239,18 +235,14 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
||||||
tex = [ [CCTexture2D alloc] initWithImage: image ];
|
tex = [ [CCTexture2D alloc] initWithImage: image ];
|
||||||
#else
|
#else
|
||||||
// prevents overloading the autorelease pool
|
// prevents overloading the autorelease pool
|
||||||
CCImage * image = new CCImage();
|
CCImage image;
|
||||||
FileData data;
|
CCFileData data(fullpath.c_str(), "rb");
|
||||||
unsigned long nSize = 0;
|
unsigned long nSize = data.getSize();
|
||||||
unsigned char* pBuffer = data.getFileData(fullpath.c_str(), "rb", &nSize);
|
unsigned char* pBuffer = data.getBuffer();
|
||||||
if(! image->initWithImageData((void*)pBuffer, nSize, CCImage::kFmtPng))
|
CC_BREAK_IF(! image.initWithImageData((void*)pBuffer, nSize, CCImage::kFmtPng));
|
||||||
{
|
|
||||||
delete image;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
texture = new CCTexture2D();
|
texture = new CCTexture2D();
|
||||||
texture->initWithImage(image);
|
texture->initWithImage(&image);
|
||||||
CC_SAFE_DELETE(image);// image->release();
|
|
||||||
#endif
|
#endif
|
||||||
if( texture )
|
if( texture )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue