unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{
	IW_CALLSTACK("CCFileUtils::getFileData");

	s3eFile* pFile = s3eFileOpen(pszFileName, pszMode);
	
    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;

	static int32* pDataToBeReadBinary;

	pDataToBeReadBinary = (int32*)s3eMallocBase(fileSize);
	memset(pDataToBeReadBinary, 0, fileSize);
	s3eFileRead(pDataToBeReadBinary, fileSize, 1, pFile);
	s3eFileClose(pFile);
	
	return (unsigned char*)pDataToBeReadBinary;
}
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{	
	string fullPath = s_strRelativePath + pszFileName;
	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;
}
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{	
	unsigned char * buffer = NULL;

	std::string full_path = pszFileName;

	// If it is not inside resource path
	if (full_path.find(s_strResourcePath) == std::string::npos) 
    {
			full_path = s_strResourcePath + pszFileName;
	}

	// if specify the zip file,load from it first
	if (s_pszZipFilePath[0] != 0)
	{
		buffer = getFileDataFromZip(s_pszZipFilePath.c_str(), full_path.c_str(), pSize);
	}

	// if that failed then let's try and load the file ourselves
	if (!buffer)
	{
		// read the file from hardware
		FILE *fp = fopen(full_path.c_str(), pszMode);
		if (fp)
		{
			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);
			fclose(fp);
		}
	}

	// we couldn't find the file
	if (!buffer && getIsPopupNotify())
	{
		std::string title = "Notification";
		std::string msg = "Get data from file(";
		msg.append(full_path);
		if (s_pszZipFilePath[0] != 0)
		{
			msg.append(") in zip archive(").append(s_pszZipFilePath);
		}
		msg.append(") failed!");

		CCMessageBox(msg.c_str(), title.c_str());
	}

	return buffer;
}
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{	
	unsigned char * pData = 0;
	string fullPath(pszFileName);

	if ((! pszFileName) || (! pszMode))
	{
		return 0;
	}

	if (pszFileName[0] != '/')
	{
		// read from apk
		fullPath.insert(0, "assets/");
		pData =  CCFileUtils::getFileDataFromZip(s_strResourcePath.c_str(), fullPath.c_str(), pSize);
	}
	else
	{
		do 
		{
			// read rrom other path than user set it
			FILE *fp = fopen(pszFileName, pszMode);
			CC_BREAK_IF(!fp);

			unsigned long size;
			fseek(fp,0,SEEK_END);
			size = ftell(fp);
			fseek(fp,0,SEEK_SET);
			pData = new unsigned char[size+1];
            pData[size] = '\0';
			size = fread(pData,sizeof(unsigned char), size,fp);
			fclose(fp);

			if (pSize)
			{
				*pSize = size;
			}			
		} while (0);		
	}

    if (! pData && getIsPopupNotify())
    {
        std::string title = "Notification";
        std::string msg = "Get data from file(";
        msg.append(fullPath.c_str()).append(") failed!");
        CCMessageBox(msg.c_str(), title.c_str());
    }

    return pData;
}