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)
|
||||
{
|
||||
FileData data;
|
||||
unsigned long nSize = 0;
|
||||
unsigned char* pBuffer = data.getFileData(strPath.c_str(), "rb", &nSize);
|
||||
CCFileData data(strPath.c_str(), "rb");
|
||||
unsigned long nSize = data.getSize();
|
||||
unsigned char* pBuffer = data.getBuffer();
|
||||
|
||||
if (! pBuffer)
|
||||
{
|
||||
|
|
|
@ -125,9 +125,9 @@ namespace cocos2d{
|
|||
{
|
||||
std::string fullpath = CCFileUtils::fullPathFromRelativePath(controlFile);
|
||||
|
||||
FileData data;
|
||||
unsigned long nBufSize = 0;
|
||||
char* pBuffer = (char*) data.getFileData(fullpath.c_str(), "r", &nBufSize);
|
||||
CCFileData data(controlFile, "rb");
|
||||
unsigned long nBufSize = data.getSize();
|
||||
char* pBuffer = (char*) data.getBuffer();
|
||||
|
||||
CCAssert(pBuffer, "CCBMFontConfiguration::parseConfigFile | Open file error.");
|
||||
|
||||
|
|
|
@ -262,12 +262,12 @@ bool CCParticleSystem::initWithDictionary(CCDictionary<std::string, CCObject*> *
|
|||
if (strlen(textureName) > 0)
|
||||
{
|
||||
// set not pop-up message box when load image failed
|
||||
bool bNotify = CCImage::getIsPopupNotify();
|
||||
CCImage::setIsPopupNotify(false);
|
||||
bool bNotify = CCFileUtils::getIsPopupNotify();
|
||||
CCFileUtils::setIsPopupNotify(false);
|
||||
this->m_pTexture = CCTextureCache::sharedTextureCache()->addImage(fullpath.c_str());
|
||||
|
||||
// reset the value of UIImage notify
|
||||
CCImage::setIsPopupNotify(bNotify);
|
||||
CCFileUtils::setIsPopupNotify(bNotify);
|
||||
}
|
||||
|
||||
// if it fails, try to get it from the base64-gzipped data
|
||||
|
|
|
@ -48,6 +48,11 @@ void CCLog(const char * pszFormat, ...)
|
|||
OutputDebugStringA("\n");
|
||||
}
|
||||
|
||||
void CCMessageBox(const char * pszMsg, const char * pszTitle)
|
||||
{
|
||||
MessageBoxA(NULL, pszMsg, pszTitle, MB_OK);
|
||||
}
|
||||
|
||||
NS_CC_END;
|
||||
|
||||
#endif // CC_PLATFORM_WIN32
|
||||
|
@ -94,6 +99,16 @@ void CCLog(const char * pszFormat, ...)
|
|||
#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;
|
||||
|
||||
#endif // CC_PLATFORM_WOPHONE
|
||||
|
@ -121,6 +136,12 @@ void CCLog(const char * pszFormat, ...)
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
// ios no MessageBox, use CCLog instead
|
||||
void CCMessageBox(const char * pszMsg, const char * pszTitle)
|
||||
{
|
||||
CCLog("%s: %s", pszTitle, pszMsg);
|
||||
}
|
||||
|
||||
NS_CC_END;
|
||||
|
||||
#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 no MessageBox, use CCLog instead
|
||||
void CCMessageBox(const char * pszMsg, const char * pszTitle)
|
||||
{
|
||||
CCLog("%s: %s", pszTitle, pszMsg);
|
||||
}
|
||||
|
||||
NS_CC_END;
|
||||
|
||||
#endif // CC_PLATFORM_ANDROID
|
||||
|
@ -174,8 +201,13 @@ void CCLog(const char * pszFormat, ...)
|
|||
|
||||
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;
|
||||
|
||||
#endif // CC_PLATFORM_AIRPLAY
|
||||
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ static const int kMaxLogLen = 255;
|
|||
@brief Output Debug message.
|
||||
*/
|
||||
void CC_DLL CCLog(const char * pszFormat, ...);
|
||||
void CC_DLL CCMessageBox(const char * pszMsg, const char * pszTitle);
|
||||
|
||||
NS_CC_END;
|
||||
|
||||
|
|
|
@ -287,6 +287,21 @@ unsigned char* CCFileUtils::getFileDataFromZip(const char* pszZipFilePath, const
|
|||
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;
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
|
@ -301,4 +316,4 @@ NS_CC_END;
|
|||
#include "android/CCFileUtils_android.cpp"
|
||||
#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);
|
||||
|
||||
/**
|
||||
@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
|
||||
///////////////////////////////////////////////////
|
||||
|
@ -108,33 +114,30 @@ public:
|
|||
int ccLoadFileIntoMemory(const char *filename, unsigned char **out);
|
||||
};
|
||||
|
||||
class FileData
|
||||
class CCFileData
|
||||
{
|
||||
public:
|
||||
FileData() : m_pBuffer(NULL) {}
|
||||
~FileData()
|
||||
CCFileData(const char* pszFileName, const char* pszMode)
|
||||
: m_pBuffer(0)
|
||||
, m_uSize(0)
|
||||
{
|
||||
if (m_pBuffer)
|
||||
{
|
||||
delete [] m_pBuffer;
|
||||
m_pBuffer = NULL;
|
||||
}
|
||||
m_pBuffer = CCFileUtils::getFileData(pszFileName, pszMode, &m_uSize);
|
||||
}
|
||||
~CCFileData()
|
||||
{
|
||||
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)
|
||||
{
|
||||
delete [] m_pBuffer;
|
||||
m_pBuffer = NULL;
|
||||
}
|
||||
|
||||
m_pBuffer = CCFileUtils::getFileData(pszFileName, pszMode, pSize);
|
||||
return m_pBuffer;
|
||||
CC_SAFE_DELETE_ARRAY(m_pBuffer);
|
||||
m_uSize = 0;
|
||||
m_pBuffer = CCFileUtils::getFileData(pszFileName, pszMode, &m_uSize);
|
||||
return (m_pBuffer) ? true : false;
|
||||
}
|
||||
|
||||
protected:
|
||||
unsigned char* m_pBuffer;
|
||||
CC_SYNTHESIZE_READONLY(unsigned char *, m_pBuffer, Buffer);
|
||||
CC_SYNTHESIZE_READONLY(unsigned long , m_uSize, Size);
|
||||
};
|
||||
|
||||
NS_CC_END;
|
||||
|
|
|
@ -26,6 +26,7 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCCommon.h"
|
||||
#include "CCStdC.h"
|
||||
#include "CCFileUtils.h"
|
||||
#include "png.h"
|
||||
#include <string>
|
||||
|
||||
|
@ -63,8 +64,6 @@ static void pngReadCallback(png_structp png_ptr, png_bytep data, png_size_t leng
|
|||
|
||||
NS_CC_BEGIN;
|
||||
|
||||
static void CCMessageBox(const std::string& msg, const std::string& title);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Impliment CCImage
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -87,51 +86,8 @@ CCImage::~CCImage()
|
|||
|
||||
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/)
|
||||
{
|
||||
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!");
|
||||
|
||||
CCMessageBox(msg, title);
|
||||
}
|
||||
return bRet;
|
||||
CCFileData data(CCFileUtils::fullPathFromRelativePath(strPath), "rb");
|
||||
return initWithImageData(data.getBuffer(), data.getSize());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
/* these are standard libjpeg structures for reading(decompression) */
|
||||
|
|
|
@ -107,13 +107,6 @@ public:
|
|||
CC_SYNTHESIZE_READONLY(short, m_nHeight, Height);
|
||||
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:
|
||||
bool _initWithJpgData(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)
|
||||
{
|
||||
FileData data;
|
||||
unsigned long size = 0;
|
||||
char *pBuffer = (char*) data.getFileData(pszFile, "r", &size);
|
||||
CCFileData data(pszFile, "rt");
|
||||
unsigned long size = data.getSize();
|
||||
char *pBuffer = (char*) data.getBuffer();
|
||||
|
||||
if (!pBuffer)
|
||||
{
|
||||
|
|
|
@ -281,9 +281,15 @@ 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()));
|
||||
}
|
||||
if (! pFile)
|
||||
{
|
||||
*pSize = 0;
|
||||
return 0;
|
||||
}
|
||||
int32 fileSize = s3eFileGetSize(pFile);
|
||||
*pSize=fileSize;
|
||||
|
||||
|
@ -319,5 +325,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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
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)
|
||||
|
|
|
@ -42,12 +42,6 @@ static int sk_atomic_dec(int *value)
|
|||
|
||||
NS_CC_BEGIN;
|
||||
|
||||
// android not support
|
||||
void CCMessageBox(const std::string& msg, const std::string& title)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class BitmapDC
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -38,83 +38,83 @@ THE SOFTWARE.
|
|||
static const char *static_ccRemoveHDSuffixFromFile( const char *pszPath)
|
||||
{
|
||||
#if CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
if(cocos2d::CC_CONTENT_SCALE_FACTOR() == 2 ) {
|
||||
NSString *path = [NSString stringWithUTF8String: pszPath];
|
||||
NSString *name = [path lastPathComponent];
|
||||
NSString *suffix = [NSString stringWithUTF8String: CC_RETINA_DISPLAY_FILENAME_SUFFIX];
|
||||
|
||||
// check if path already has the suffix.
|
||||
if( [name rangeOfString: suffix].location != NSNotFound ) {
|
||||
|
||||
CCLOG("cocos2d: Filename(%@) contains %@ suffix. Removing it. See cocos2d issue #1040", path, CC_RETINA_DISPLAY_FILENAME_SUFFIX);
|
||||
|
||||
NSString *newLastname = [name stringByReplacingOccurrencesOfString: suffix withString:@""];
|
||||
|
||||
NSString *pathWithoutLastname = [path stringByDeletingLastPathComponent];
|
||||
return [[pathWithoutLastname stringByAppendingPathComponent:newLastname] UTF8String];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(cocos2d::CC_CONTENT_SCALE_FACTOR() == 2 ) {
|
||||
NSString *path = [NSString stringWithUTF8String: pszPath];
|
||||
NSString *name = [path lastPathComponent];
|
||||
NSString *suffix = [NSString stringWithUTF8String: CC_RETINA_DISPLAY_FILENAME_SUFFIX];
|
||||
|
||||
// check if path already has the suffix.
|
||||
if( [name rangeOfString: suffix].location != NSNotFound ) {
|
||||
|
||||
CCLOG("cocos2d: Filename(%@) contains %@ suffix. Removing it. See cocos2d issue #1040", path, CC_RETINA_DISPLAY_FILENAME_SUFFIX);
|
||||
|
||||
NSString *newLastname = [name stringByReplacingOccurrencesOfString: suffix withString:@""];
|
||||
|
||||
NSString *pathWithoutLastname = [path stringByDeletingLastPathComponent];
|
||||
return [[pathWithoutLastname stringByAppendingPathComponent:newLastname] UTF8String];
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
return pszPath;
|
||||
|
||||
return pszPath;
|
||||
}
|
||||
|
||||
static NSString* getDoubleResolutionImage(NSString* path)
|
||||
{
|
||||
#if CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
if( cocos2d::CC_CONTENT_SCALE_FACTOR() == 2 )
|
||||
{
|
||||
|
||||
NSString *pathWithoutExtension = [path stringByDeletingPathExtension];
|
||||
NSString *name = [pathWithoutExtension lastPathComponent];
|
||||
NSString *suffix = [NSString stringWithUTF8String: CC_RETINA_DISPLAY_FILENAME_SUFFIX];
|
||||
|
||||
// check if path already has the suffix.
|
||||
if( [name rangeOfString: suffix].location != NSNotFound ) {
|
||||
|
||||
CCLOG("cocos2d: WARNING Filename(%@) already has the suffix %@. Using it.", name, CC_RETINA_DISPLAY_FILENAME_SUFFIX);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
NSString *extension = [path pathExtension];
|
||||
|
||||
if( [extension isEqualToString:@"ccz"] || [extension isEqualToString:@"gz"] )
|
||||
{
|
||||
// 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
|
||||
extension = [NSString stringWithFormat:@"%@.%@", [pathWithoutExtension pathExtension], extension];
|
||||
pathWithoutExtension = [pathWithoutExtension stringByDeletingPathExtension];
|
||||
}
|
||||
|
||||
|
||||
NSString *retinaName = [pathWithoutExtension stringByAppendingString: suffix];
|
||||
retinaName = [retinaName stringByAppendingPathExtension:extension];
|
||||
|
||||
NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];
|
||||
if( [fileManager fileExistsAtPath:retinaName] )
|
||||
return retinaName;
|
||||
|
||||
CCLOG("cocos2d: CCFileUtils: Warning HD file not found: %@", [retinaName lastPathComponent] );
|
||||
}
|
||||
|
||||
|
||||
if( cocos2d::CC_CONTENT_SCALE_FACTOR() == 2 )
|
||||
{
|
||||
|
||||
NSString *pathWithoutExtension = [path stringByDeletingPathExtension];
|
||||
NSString *name = [pathWithoutExtension lastPathComponent];
|
||||
NSString *suffix = [NSString stringWithUTF8String: CC_RETINA_DISPLAY_FILENAME_SUFFIX];
|
||||
|
||||
// check if path already has the suffix.
|
||||
if( [name rangeOfString: suffix].location != NSNotFound ) {
|
||||
|
||||
CCLOG("cocos2d: WARNING Filename(%@) already has the suffix %@. Using it.", name, CC_RETINA_DISPLAY_FILENAME_SUFFIX);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
NSString *extension = [path pathExtension];
|
||||
|
||||
if( [extension isEqualToString:@"ccz"] || [extension isEqualToString:@"gz"] )
|
||||
{
|
||||
// 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
|
||||
extension = [NSString stringWithFormat:@"%@.%@", [pathWithoutExtension pathExtension], extension];
|
||||
pathWithoutExtension = [pathWithoutExtension stringByDeletingPathExtension];
|
||||
}
|
||||
|
||||
|
||||
NSString *retinaName = [pathWithoutExtension stringByAppendingString: suffix];
|
||||
retinaName = [retinaName stringByAppendingPathExtension:extension];
|
||||
|
||||
NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];
|
||||
if( [fileManager fileExistsAtPath:retinaName] )
|
||||
return retinaName;
|
||||
|
||||
CCLOG("cocos2d: CCFileUtils: Warning HD file not found: %@", [retinaName lastPathComponent] );
|
||||
}
|
||||
|
||||
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
return path;
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
static const char* static_fullPathFromRelativePath(const char *pszRelativePath)
|
||||
|
||||
{
|
||||
|
||||
// NSAssert(pszRelativePath != nil, @"CCFileUtils: Invalid path");
|
||||
|
||||
// do not convert an absolute path (starting with '/')
|
||||
NSString *relPath = [NSString stringWithUTF8String: pszRelativePath];
|
||||
NSString *fullpath = nil;
|
||||
|
||||
// NSAssert(pszRelativePath != nil, @"CCFileUtils: Invalid path");
|
||||
|
||||
// do not convert an absolute path (starting with '/')
|
||||
NSString *relPath = [NSString stringWithUTF8String: pszRelativePath];
|
||||
NSString *fullpath = nil;
|
||||
|
||||
// only if it is not an absolute path
|
||||
if( ! [relPath isAbsolutePath] )
|
||||
|
@ -319,15 +319,15 @@ public:
|
|||
|
||||
// record the resource path
|
||||
static char s_pszResourcePath[MAX_PATH] = {0};
|
||||
|
||||
|
||||
void CCFileUtils::setResourcePath(const char *pszResourcePath)
|
||||
{
|
||||
// NSAssert(pszResourcePath != NULL, "[FileUtils setResourcePath] -- wrong resource path");
|
||||
// NSAssert(strlen(pszResourcePath) <= MAX_PATH, "[FileUtils setResourcePath] -- resource path too long");
|
||||
|
||||
// NSAssert(pszResourcePath != NULL, "[FileUtils setResourcePath] -- wrong resource path");
|
||||
// NSAssert(strlen(pszResourcePath) <= MAX_PATH, "[FileUtils setResourcePath] -- resource path too long");
|
||||
|
||||
strcpy(s_pszResourcePath, pszResourcePath);
|
||||
}
|
||||
|
||||
|
||||
const char* CCFileUtils::getResourcePath()
|
||||
{
|
||||
return s_pszResourcePath;
|
||||
|
@ -337,18 +337,18 @@ public:
|
|||
{
|
||||
assert( out );
|
||||
assert( &*out );
|
||||
|
||||
|
||||
int size = 0;
|
||||
FILE *f = fopen(filename, "rb");
|
||||
if( !f ) {
|
||||
*out = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
|
||||
*out = (unsigned char*)malloc(size);
|
||||
int read = fread(*out, 1, size, f);
|
||||
if( read != size ) {
|
||||
|
@ -356,23 +356,23 @@ public:
|
|||
*out = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
fclose(f);
|
||||
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
std::string& CCFileUtils::ccRemoveHDSuffixFromFile(std::string& path )
|
||||
{
|
||||
path = static_ccRemoveHDSuffixFromFile(path.c_str());
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
||||
{
|
||||
return static_fullPathFromRelativePath(pszRelativePath);
|
||||
}
|
||||
|
||||
|
||||
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *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 * Buffer = NULL;
|
||||
unsigned char * pBuffer = NULL;
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -400,12 +400,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)
|
||||
{
|
||||
|
@ -415,4 +423,19 @@ public:
|
|||
{
|
||||
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 <UIKit/UIKit.h>
|
||||
#include "CCImage.h"
|
||||
#include "CCFileUtils.h"
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -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 * Buffer = NULL;
|
||||
unsigned char * pBuffer = NULL;
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -126,12 +126,20 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
|
|||
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)
|
||||
|
|
|
@ -24,11 +24,6 @@ THE SOFTWARE.
|
|||
|
||||
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.
|
||||
*/
|
||||
|
|
|
@ -277,7 +277,7 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
|
|||
|
||||
do
|
||||
{
|
||||
if (strlen(s_pszZipFilePath) != 0)
|
||||
if (0 != s_pszZipFilePath[0])
|
||||
{
|
||||
// if specify the zip file,load from it first
|
||||
pBuffer = getFileDataFromZip(s_pszZipFilePath, pszFileName, pSize);
|
||||
|
@ -292,10 +292,24 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
|
|||
*pSize = ftell(fp);
|
||||
fseek(fp,0,SEEK_SET);
|
||||
pBuffer = new unsigned char[*pSize];
|
||||
fread(pBuffer,sizeof(unsigned char), *pSize,fp);
|
||||
*pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp);
|
||||
fclose(fp);
|
||||
} 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,14 +29,6 @@ NS_CC_BEGIN
|
|||
|
||||
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
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -1065,11 +1065,15 @@
|
|||
Name="makefile"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\Lib_Cocos2d_Arm_Wophone.TMK3"
|
||||
RelativePath=".\cocos2d-wophone.TMK3"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\Makefile.ARM"
|
||||
RelativePath=".\Makefile-dynamic.ARM"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Makefile.ARM"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
|
|
|
@ -194,9 +194,9 @@ tImageTGA * tgaLoad(const char *pszFilename)
|
|||
{
|
||||
int mode,total;
|
||||
tImageTGA *info = NULL;
|
||||
FileData data;
|
||||
unsigned long nSize = 0;
|
||||
unsigned char* pBuffer = data.getFileData(pszFilename, "rb", &nSize);
|
||||
CCFileData data(pszFilename, "rb");
|
||||
unsigned long nSize = data.getSize();
|
||||
unsigned char* pBuffer = data.getBuffer();
|
||||
|
||||
do
|
||||
{
|
||||
|
|
|
@ -208,18 +208,14 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
|||
// Issue #886: TEMPORARY FIX FOR TRANSPARENT JPEGS IN IOS4
|
||||
else if (std::string::npos != lowerCase.find(".jpg") || std::string::npos != lowerCase.find(".jpeg"))
|
||||
{
|
||||
CCImage * image = new CCImage();
|
||||
FileData data;
|
||||
unsigned long nSize = 0;
|
||||
unsigned char* pBuffer = data.getFileData(fullpath.c_str(), "rb", &nSize);
|
||||
if(! image->initWithImageData((void*)pBuffer, nSize, CCImage::kFmtJpg))
|
||||
{
|
||||
delete image;
|
||||
break;
|
||||
}
|
||||
CCImage image;
|
||||
CCFileData data(fullpath.c_str(), "rb");
|
||||
unsigned long nSize = data.getSize();
|
||||
unsigned char* pBuffer = data.getBuffer();
|
||||
CC_BREAK_IF(! image.initWithImageData((void*)pBuffer, nSize, CCImage::kFmtJpg));
|
||||
|
||||
texture = new CCTexture2D();
|
||||
texture->initWithImage(image);
|
||||
CC_SAFE_DELETE(image);// image->release();
|
||||
texture->initWithImage(&image);
|
||||
|
||||
if( texture )
|
||||
{
|
||||
|
@ -239,18 +235,14 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
|||
tex = [ [CCTexture2D alloc] initWithImage: image ];
|
||||
#else
|
||||
// prevents overloading the autorelease pool
|
||||
CCImage * image = new CCImage();
|
||||
FileData data;
|
||||
unsigned long nSize = 0;
|
||||
unsigned char* pBuffer = data.getFileData(fullpath.c_str(), "rb", &nSize);
|
||||
if(! image->initWithImageData((void*)pBuffer, nSize, CCImage::kFmtPng))
|
||||
{
|
||||
delete image;
|
||||
break;
|
||||
}
|
||||
CCImage image;
|
||||
CCFileData data(fullpath.c_str(), "rb");
|
||||
unsigned long nSize = data.getSize();
|
||||
unsigned char* pBuffer = data.getBuffer();
|
||||
CC_BREAK_IF(! image.initWithImageData((void*)pBuffer, nSize, CCImage::kFmtPng));
|
||||
|
||||
texture = new CCTexture2D();
|
||||
texture->initWithImage(image);
|
||||
CC_SAFE_DELETE(image);// image->release();
|
||||
texture->initWithImage(&image);
|
||||
#endif
|
||||
if( texture )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue