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; }
bool CIwGameFile::Seek(int offset, s3eFileSeekOrigin origin) { if (File == NULL) return false; if (s3eFileSeek(File, offset, origin) != S3E_RESULT_SUCCESS) return false; return true; }
bool CIwGamePlatformFileMarm::Seek(CxFile file, int offset, CxFileSeekOrigin origin) { s3eFileSeekOrigin o = S3E_FILESEEK_CUR; if (origin == FileSeek_Set) o = S3E_FILESEEK_SET; else if (origin == FileSeek_End) o = S3E_FILESEEK_END; return s3eFileSeek((s3eFile*)file, offset, o) == S3E_RESULT_SUCCESS; }
AKRESULT s3eIOHook::Read(AkFileDesc &in_fileDesc, const AkIoHeuristics &, void *out_pBuffer, AkIOTransferInfo &io_transferInfo) { int32 position = (int32)io_transferInfo.uFilePosition; if( s3eFileSeek((s3eFile *)in_fileDesc.hFile, position, S3E_FILESEEK_SET) == S3E_RESULT_SUCCESS ) { uint32 itemsRead = s3eFileRead(out_pBuffer, 1, io_transferInfo.uRequestedSize, (s3eFile *)in_fileDesc.hFile); if( itemsRead > 0 ) return AK_Success; } return AK_Fail; }
AKRESULT s3eIOHook::Write(AkFileDesc &in_fileDesc, const AkIoHeuristics &, void *in_pData, AkIOTransferInfo &io_transferInfo) { int32 position = (int32)io_transferInfo.uFilePosition; if( s3eFileSeek((s3eFile *)in_fileDesc.hFile, position, S3E_FILESEEK_SET) == S3E_RESULT_SUCCESS ) { uint32 itemsWritten = s3eFileWrite( in_pData, 1, io_transferInfo.uRequestedSize, (s3eFile *)in_fileDesc.hFile ); if( itemsWritten > 0 ) { s3eFileFlush( (s3eFile *)in_fileDesc.hFile ); return AK_Success; } } return AK_Fail; }
int COggVorbisFileHelper::seek_func(void *datasource, ogg_int64_t offset, int whence) { return s3eFileSeek((s3eFile*)datasource, (int)offset, (s3eFileSeekOrigin)whence); }
//------------------------------------------------------------------------- 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; }