Exemplo n.º 1
0
bool CLevel::OpenXmlFile( const char * path, TiXmlDocument * doc )
{
	if ( doc == NULL )
	{
		return false;
	}
	s3eFile * file = s3eFileOpen(path, "r");
	if ( file != NULL )
	{
		s3eFileSeek(file, 0, S3E_FILESEEK_END);
		long len = s3eFileTell( file );
		s3eFileSeek(file, 0, S3E_FILESEEK_SET);

		char * buff = new char[len];
		s3eFileRead(buff, sizeof(char), len, file);

		doc->Parse(buff);

		SAFE_DELETE_ARRAY( buff );
	}
	else
	{
		IwAssertMsg(GAME, false, ("can't open file '%s'", path));
		return false;
	}
	s3eFileClose(file);

	return true;
}
bool CCSAXParser::parse(const char *pszFile)
{
	bool bRet = false;
	char* buf = NULL;
	s3eFile* file = NULL;
	
	do
	{
		file = s3eFileOpen(pszFile, "r");
		
		if (!file)
		{
			IwAssertMsg(GAME, file, ("Open file %s Failed. s3eFileError Code : %i", pszFile, s3eFileGetError()));
			break;
		}
		
		s3eFileSeek(file, 0, S3E_FILESEEK_END);
		int	size = s3eFileTell(file);
		s3eFileSeek(file, 0,  S3E_FILESEEK_SET);
		buf = new char[size];
		int done =0;
		int len = (int)s3eFileRead(buf, 1, size, file);
		if (XML_Parse(s_pParser, buf, len, 1) == XML_STATUS_ERROR)
		{
			CCLog("GAME: cocos2d: plist err: %s at line %d", XML_ErrorString(XML_GetErrorCode(s_pParser)), XML_GetCurrentLineNumber(s_pParser));
			break;
		}
		
		bRet = true;
		
	} while(0);
	
	// cleanup
	if (file)
	{
		s3eFileClose(file);
	}
	if (buf)
	{
		delete []buf;
	}
	
	return bRet;

}
Exemplo n.º 3
0
long COggVorbisFileHelper::tell_func(void *datasource)
{
	return s3eFileTell((s3eFile*)datasource);
}
Exemplo n.º 4
0
//-------------------------------------------------------------------------
CIwSoundData* CIwSoundWAV::Create(const CIwStringL& pathname, void* buffer, u_int file_size)
{
    IW_CALLSTACK("CIwSoundWAV::Create")

    CIwSoundData* pData = NULL; // Object to return

    // Open file
    s3eFile* pFile = NULL;
	
	if (buffer != NULL)
		pFile = s3eFileOpenFromMemory(buffer, file_size);
	else
		pFile = IwFileOpenPrefixed(pathname.c_str(), "rb");

    IwAssertMsg(SOUND, pFile, ("Could not load file %s", pathname.c_str()));
    if (!pFile)
        return NULL;

    // Read RIFF header - Gives the file size and checks that this is a WAVE
    // file as expected
    IwRIFFHeader riffHeader;
    if ((s3eFileRead(&riffHeader, sizeof(IwRIFFHeader), 1, pFile) != 1)
        || (strncmp(riffHeader.typeID, "RIFF", 4) != 0)
        || (strncmp(riffHeader.subTypeID, "WAVE", 4) != 0))
    {
        IwAssertMsg(SOUND, false, ("Invalid header in %s (RIFF Header)", pathname.c_str()));
        s3eFileClose(pFile);
        return NULL;
    }

    // Read in RIFF chunks until we reach the end of the file
    // Read the RIFF chunk header. This tells us what type of chunk follows.
    IwRIFFChunkHeader chunkHeader;
    bool readData = false;
    uint32 fileSize = s3eFileGetSize(pFile);

    while (ReadChunkHeader(chunkHeader, *(s3eFile*)pFile))
    {
        uint32 chunkStartPos = s3eFileTell(pFile);

        // Next action depends on chunk type. The order of this is important and we may fail
        // if an unexpected chunk type is found
        if (!strncmp(chunkHeader.typeID, "fmt ", 4))
        {
            // Read WAVE info chunk
            if (!ReadChunkFormat(pathname, chunkHeader, pData, *(s3eFile*)pFile))
            {
                s3eFileClose(pFile);
                return NULL;
            }
        }
        else if (!strncmp(chunkHeader.typeID, "data", 4))
        {
            if (!ReadChunkData(pathname, chunkHeader, pData, *(s3eFile*)pFile))
            {
                s3eFileClose(pFile);
                return NULL;
            }
            readData = true;
        }
        else if (!strncmp(chunkHeader.typeID, "fact", 4))
        {
            if (!ReadChunkFact(pathname, chunkHeader, pData, *(s3eFile*)pFile))
            {
                s3eFileClose(pFile);
                return NULL;
            }
        }
        else
        {
            // Unknown chunk type
            // Make a proper string from the chunk type info
            char typeID[5];
            strncpy(typeID, chunkHeader.typeID, 4);
            typeID[4] = 0;  // Terminate

            const char* g_IgnoreTypes = "LIST" //LIST is just copyright info etc.
                "DISP";  //DISP seems to be info about what package exported it

            IwAssertMsg(SOUND, strstr(g_IgnoreTypes, typeID), ("Unhandled chunk type '%s' in %s. Ignoring this data.", typeID, pathname.c_str()));
        }

        // Exit if at end of file
        if (chunkStartPos + chunkHeader.length >= fileSize)
            break;

        // Move to next chunk
        s3eFileSeek(pFile, chunkStartPos + chunkHeader.length, S3E_FILESEEK_SET);
    }

    // Check that we have read the sample data
    IwAssertMsg(SOUND, readData, ("No data chunk read in %s", pathname.c_str()));
    s3eFileClose(pFile);
    return pData;
}