diff --git a/cocos2dx/platform/airplay/CCFileUtils_airplay.cpp b/cocos2dx/platform/airplay/CCFileUtils_airplay.cpp index 1660a2b67d..6dbebcdfc8 100644 --- a/cocos2dx/platform/airplay/CCFileUtils_airplay.cpp +++ b/cocos2dx/platform/airplay/CCFileUtils_airplay.cpp @@ -226,8 +226,10 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz s3eFile* pFile = s3eFileOpen(pszFileName, pszMode); - - IwAssertMsg(GAME, pFile, ("Open file %s Failed. s3eFileError Code : %i", pszFileName, s3eFileGetError())); + if (! pFile && getIsPopupNotify()) + { + IwAssertMsg(GAME, pFile, ("Open file %s Failed. s3eFileError Code : %i", pszFileName, s3eFileGetError())); + } int32 fileSize = s3eFileGetSize(pFile); *pSize=fileSize; @@ -264,5 +266,20 @@ std::string& CCFileUtils::ccRemoveHDSuffixFromFile(std::string& 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; diff --git a/cocos2dx/platform/airplay/CCImage_airplay.cpp b/cocos2dx/platform/airplay/CCImage_airplay.cpp index 145bb8f005..c4e505dc47 100644 --- a/cocos2dx/platform/airplay/CCImage_airplay.cpp +++ b/cocos2dx/platform/airplay/CCImage_airplay.cpp @@ -24,6 +24,7 @@ #include "CCImage.h" #include "CCCommon.h" #include "CCStdC.h" +#include "CCFileUtils.h" #include "s3eFile.h" #include "IwImage.h" #include "IwUtil.h" @@ -61,52 +62,8 @@ CCImage::~CCImage() bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/) { IW_CALLSTACK("UIImage::initWithImageFile"); - - bool bRet = false; - 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; + CCFileData data(CCFileUtils::fullPathFromRelativePath(strPath), "rb"); + return initWithImageData(data.getBuffer(), data.getSize(), eImgFmt); } 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); 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) { diff --git a/cocos2dx/platform/ios/CCFileUtils_ios.mm b/cocos2dx/platform/ios/CCFileUtils_ios.mm index 34028e496b..a95f51fd76 100644 --- a/cocos2dx/platform/ios/CCFileUtils_ios.mm +++ b/cocos2dx/platform/ios/CCFileUtils_ios.mm @@ -336,7 +336,7 @@ public: } unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize) { - unsigned char * Buffer = NULL; + unsigned char * pBuffer = NULL; do { @@ -347,12 +347,20 @@ public: fseek(fp,0,SEEK_END); *pSize = ftell(fp); fseek(fp,0,SEEK_SET); - Buffer = new unsigned char[*pSize]; - *pSize = fread(Buffer,sizeof(unsigned char), *pSize,fp); + pBuffer = new unsigned char[*pSize]; + *pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp); fclose(fp); } 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) { @@ -362,4 +370,18 @@ public: { CCAssert(0, "Have not implement!"); } + + // 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 diff --git a/cocos2dx/platform/ios/CCImage_ios.mm b/cocos2dx/platform/ios/CCImage_ios.mm index ed7e04cbf3..21b932e794 100644 --- a/cocos2dx/platform/ios/CCImage_ios.mm +++ b/cocos2dx/platform/ios/CCImage_ios.mm @@ -24,6 +24,7 @@ THE SOFTWARE. #include #include #include "CCImage.h" +#include "CCFileUtils.h" #include typedef struct @@ -448,13 +449,6 @@ static bool _initWithString(const char * pText, cocos2d::CCImage::ETextAlign eAl NS_CC_BEGIN; -static bool s_bPopupNotify = true; - -void CCMessageBox(const std::string& msg, const std::string& title) -{ - -} - CCImage::CCImage() : m_nWidth(0) , m_nHeight(0) @@ -473,30 +467,8 @@ CCImage::~CCImage() bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/) { - bool bRet = false; - tImageInfo info = {0}; - - 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; + CCFileData data(CCFileUtils::fullPathFromRelativePath(strPath), "rb"); + return initWithImageData(data.getBuffer(), data.getSize(), eImgFmt); } bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/* = eSrcFmtPng*/) @@ -546,15 +518,5 @@ bool CCImage::initWithString( return true; } -void CCImage::setIsPopupNotify(bool bNotify) -{ - s_bPopupNotify = bNotify; -} - -bool CCImage::getIsPopupNotify() -{ - return s_bPopupNotify; -} - NS_CC_END; diff --git a/tests/test.android/build_native.sh b/tests/test.android/build_native.sh index 5c29a9bcbf..acb8c9b15b 100644 --- a/tests/test.android/build_native.sh +++ b/tests/test.android/build_native.sh @@ -1,6 +1,6 @@ # set params -ANDROID_NDK_ROOT=/cygdrive/e/android-ndk-r4-crystax -COCOS2DX_ROOT=/cygdrive/d/Work7/cocos2d-x +ANDROID_NDK_ROOT=$ANDROID_NDK_ROOT +COCOS2DX_ROOT=/cygdrive/d/Work7/cocos2d-x.yangws TESTS_ROOT=$COCOS2DX_ROOT/tests/test.android # make sure assets is exist