mirror of https://github.com/axmolengine/axmol.git
Merge pull request #3227 from azmeuk/file-utils
Added some guards in file utils
This commit is contained in:
commit
0dce6d9cf3
1
AUTHORS
1
AUTHORS
|
@ -416,6 +416,7 @@ Developers:
|
||||||
Refactored emscripten-build.sh, it's no longer need to be edited to make emscripten work.
|
Refactored emscripten-build.sh, it's no longer need to be edited to make emscripten work.
|
||||||
Creation of CCDeprecated-ext.h
|
Creation of CCDeprecated-ext.h
|
||||||
Use of a single emscripten HTML template file.
|
Use of a single emscripten HTML template file.
|
||||||
|
Added some guards in fileutils. Fixed a bug in emscripten file utils.
|
||||||
|
|
||||||
elmiro
|
elmiro
|
||||||
Correction of passed buffer size to readlink and verification of result return by readlink.
|
Correction of passed buffer size to readlink and verification of result return by readlink.
|
||||||
|
|
|
@ -94,13 +94,14 @@ Image::~Image()
|
||||||
bool Image::initWithImageFile(const char * strPath, Format eImgFmt/* = eFmtPng*/)
|
bool Image::initWithImageFile(const char * strPath, Format eImgFmt/* = eFmtPng*/)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(strPath);
|
||||||
|
|
||||||
#ifdef EMSCRIPTEN
|
#ifdef EMSCRIPTEN
|
||||||
// Emscripten includes a re-implementation of SDL that uses HTML5 canvas
|
// Emscripten includes a re-implementation of SDL that uses HTML5 canvas
|
||||||
// operations underneath. Consequently, loading images via IMG_Load (an SDL
|
// operations underneath. Consequently, loading images via IMG_Load (an SDL
|
||||||
// API) will be a lot faster than running libpng et al as compiled with
|
// API) will be a lot faster than running libpng et al as compiled with
|
||||||
// Emscripten.
|
// Emscripten.
|
||||||
SDL_Surface *iSurf = IMG_Load(strPath);
|
SDL_Surface *iSurf = IMG_Load(fullPath.c_str());
|
||||||
|
|
||||||
int size = 4 * (iSurf->w * iSurf->h);
|
int size = 4 * (iSurf->w * iSurf->h);
|
||||||
bRet = initWithRawData((void*)iSurf->pixels, size, iSurf->w, iSurf->h, 8, true);
|
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);
|
SDL_FreeSurface(iSurf);
|
||||||
#else
|
#else
|
||||||
unsigned long nSize = 0;
|
unsigned long nSize = 0;
|
||||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(strPath);
|
|
||||||
unsigned char* pBuffer = FileUtils::getInstance()->getFileData(fullPath.c_str(), "rb", &nSize);
|
unsigned char* pBuffer = FileUtils::getInstance()->getFileData(fullPath.c_str(), "rb", &nSize);
|
||||||
if (pBuffer != NULL && nSize > 0)
|
if (pBuffer != NULL && nSize > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -59,7 +59,12 @@ FileUtils* FileUtils::getInstance()
|
||||||
if (s_sharedFileUtils == NULL)
|
if (s_sharedFileUtils == NULL)
|
||||||
{
|
{
|
||||||
s_sharedFileUtils = new FileUtilsAndroid();
|
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;
|
return s_sharedFileUtils;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,12 @@ FileUtils* FileUtils::getInstance()
|
||||||
if (s_sharedFileUtils == NULL)
|
if (s_sharedFileUtils == NULL)
|
||||||
{
|
{
|
||||||
s_sharedFileUtils = new FileUtilsEmscripten();
|
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;
|
return s_sharedFileUtils;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +29,7 @@ FileUtilsEmscripten::FileUtilsEmscripten()
|
||||||
|
|
||||||
bool FileUtilsEmscripten::init()
|
bool FileUtilsEmscripten::init()
|
||||||
{
|
{
|
||||||
_defaultResRootPath = "app/native/Resources/";
|
_defaultResRootPath = "/";
|
||||||
return FileUtils::init();
|
return FileUtils::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,12 @@ FileUtils* FileUtils::getInstance()
|
||||||
if (s_sharedFileUtils == NULL)
|
if (s_sharedFileUtils == NULL)
|
||||||
{
|
{
|
||||||
s_sharedFileUtils = new FileUtilsIOS();
|
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;
|
return s_sharedFileUtils;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,12 @@ FileUtils* FileUtils::getInstance()
|
||||||
if (s_sharedFileUtils == NULL)
|
if (s_sharedFileUtils == NULL)
|
||||||
{
|
{
|
||||||
s_sharedFileUtils = new FileUtilsLinux();
|
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;
|
return s_sharedFileUtils;
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,7 +210,12 @@ FileUtils* FileUtils::getInstance()
|
||||||
if (s_sharedFileUtils == NULL)
|
if (s_sharedFileUtils == NULL)
|
||||||
{
|
{
|
||||||
s_sharedFileUtils = new FileUtilsMac();
|
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;
|
return s_sharedFileUtils;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,12 @@ FileUtils* FileUtils::getInstance()
|
||||||
if (s_sharedFileUtils == NULL)
|
if (s_sharedFileUtils == NULL)
|
||||||
{
|
{
|
||||||
s_sharedFileUtils = new FileUtilsNaCl();
|
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;
|
return s_sharedFileUtils;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,12 @@ FileUtils* FileUtils::getInstance()
|
||||||
if (s_sharedFileUtils == NULL)
|
if (s_sharedFileUtils == NULL)
|
||||||
{
|
{
|
||||||
s_sharedFileUtils = new FileUtilsTizen();
|
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;
|
return s_sharedFileUtils;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,12 @@ FileUtils* FileUtils::getInstance()
|
||||||
if (s_sharedFileUtils == NULL)
|
if (s_sharedFileUtils == NULL)
|
||||||
{
|
{
|
||||||
s_sharedFileUtils = new FileUtilsWin32();
|
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;
|
return s_sharedFileUtils;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue