Merge pull request #3227 from azmeuk/file-utils

Added some guards in file utils
This commit is contained in:
James Chen 2013-07-26 05:31:02 -07:00
commit 0dce6d9cf3
10 changed files with 52 additions and 11 deletions

View File

@ -416,6 +416,7 @@ Developers:
Refactored emscripten-build.sh, it's no longer need to be edited to make emscripten work.
Creation of CCDeprecated-ext.h
Use of a single emscripten HTML template file.
Added some guards in fileutils. Fixed a bug in emscripten file utils.
elmiro
Correction of passed buffer size to readlink and verification of result return by readlink.

View File

@ -94,13 +94,14 @@ Image::~Image()
bool Image::initWithImageFile(const char * strPath, Format eImgFmt/* = eFmtPng*/)
{
bool bRet = false;
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(strPath);
#ifdef EMSCRIPTEN
// Emscripten includes a re-implementation of SDL that uses HTML5 canvas
// operations underneath. Consequently, loading images via IMG_Load (an SDL
// API) will be a lot faster than running libpng et al as compiled with
// Emscripten.
SDL_Surface *iSurf = IMG_Load(strPath);
SDL_Surface *iSurf = IMG_Load(fullPath.c_str());
int size = 4 * (iSurf->w * iSurf->h);
bRet = initWithRawData((void*)iSurf->pixels, size, iSurf->w, iSurf->h, 8, true);
@ -116,7 +117,6 @@ bool Image::initWithImageFile(const char * strPath, Format eImgFmt/* = eFmtPng*/
SDL_FreeSurface(iSurf);
#else
unsigned long nSize = 0;
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(strPath);
unsigned char* pBuffer = FileUtils::getInstance()->getFileData(fullPath.c_str(), "rb", &nSize);
if (pBuffer != NULL && nSize > 0)
{

View File

@ -59,7 +59,12 @@ FileUtils* FileUtils::getInstance()
if (s_sharedFileUtils == NULL)
{
s_sharedFileUtils = new FileUtilsAndroid();
s_sharedFileUtils->init();
if(!s_sharedFileUtils->init())
{
delete s_sharedFileUtils;
s_sharedFileUtils = NULL;
CCLOG("ERROR: Could not init CCFileUtilsAndroid");
}
}
return s_sharedFileUtils;
}

View File

@ -14,7 +14,12 @@ FileUtils* FileUtils::getInstance()
if (s_sharedFileUtils == NULL)
{
s_sharedFileUtils = new FileUtilsEmscripten();
s_sharedFileUtils->init();
if(!s_sharedFileUtils->init())
{
delete s_sharedFileUtils;
s_sharedFileUtils = NULL;
CCLOG("ERROR: Could not init CCFileUtilsEmscripten");
}
}
return s_sharedFileUtils;
}
@ -24,7 +29,7 @@ FileUtilsEmscripten::FileUtilsEmscripten()
bool FileUtilsEmscripten::init()
{
_defaultResRootPath = "app/native/Resources/";
_defaultResRootPath = "/";
return FileUtils::init();
}

View File

@ -213,7 +213,12 @@ FileUtils* FileUtils::getInstance()
if (s_sharedFileUtils == NULL)
{
s_sharedFileUtils = new FileUtilsIOS();
s_sharedFileUtils->init();
if(!s_sharedFileUtils->init())
{
delete s_sharedFileUtils;
s_sharedFileUtils = NULL;
CCLOG("ERROR: Could not init CCFileUtilsIOS");
}
}
return s_sharedFileUtils;
}

View File

@ -23,7 +23,12 @@ FileUtils* FileUtils::getInstance()
if (s_sharedFileUtils == NULL)
{
s_sharedFileUtils = new FileUtilsLinux();
s_sharedFileUtils->init();
if(!s_sharedFileUtils->init())
{
delete s_sharedFileUtils;
s_sharedFileUtils = NULL;
CCLOG("ERROR: Could not init CCFileUtilsLinux");
}
}
return s_sharedFileUtils;
}

View File

@ -210,7 +210,12 @@ FileUtils* FileUtils::getInstance()
if (s_sharedFileUtils == NULL)
{
s_sharedFileUtils = new FileUtilsMac();
s_sharedFileUtils->init();
if(!s_sharedFileUtils->init())
{
delete s_sharedFileUtils;
s_sharedFileUtils = NULL;
CCLOG("ERROR: Could not init CCFileUtilsMac");
}
}
return s_sharedFileUtils;
}

View File

@ -35,7 +35,12 @@ FileUtils* FileUtils::getInstance()
if (s_sharedFileUtils == NULL)
{
s_sharedFileUtils = new FileUtilsNaCl();
s_sharedFileUtils->init();
if(!s_sharedFileUtils->init())
{
delete s_sharedFileUtils;
s_sharedFileUtils = NULL;
CCLOG("ERROR: Could not init CCFileUtilsNacl");
}
}
return s_sharedFileUtils;
}

View File

@ -45,7 +45,12 @@ FileUtils* FileUtils::getInstance()
if (s_sharedFileUtils == NULL)
{
s_sharedFileUtils = new FileUtilsTizen();
s_sharedFileUtils->init();
if(!s_sharedFileUtils->init())
{
delete s_sharedFileUtils;
s_sharedFileUtils = NULL;
CCLOG("ERROR: Could not init CCFileUtilsTizen");
}
}
return s_sharedFileUtils;
}

View File

@ -48,7 +48,12 @@ FileUtils* FileUtils::getInstance()
if (s_sharedFileUtils == NULL)
{
s_sharedFileUtils = new FileUtilsWin32();
s_sharedFileUtils->init();
if(!s_sharedFileUtils->init())
{
delete s_sharedFileUtils;
s_sharedFileUtils = NULL;
CCLOG("ERROR: Could not init CCFileUtilsWin32");
}
}
return s_sharedFileUtils;
}