//////////////////////////////////////////////////////////////////////////
// low level function, reads directly from the file
// TODO: remove all those pOSSaveReader parameter chains and make it a member, passing it along is not needed anymore
void CReader::ReadDataFromFileInternal( IPlatformOS::ISaveReaderPtr& pOSSaveReader, void* pDst, uint32 numBytes )
{
	assert( pOSSaveReader.get() );
	
	if (!m_errorReading)
	{
		IPlatformOS::EFileOperationCode code = pOSSaveReader->ReadBytes( pDst, numBytes );
		CheckErrorFlag( code );
	}
}
Пример #2
0
bool CXmlLoadGame::Init( const char * name )
{
#ifdef XML_LOADGAME_USE_COMPRESSION
	#if defined(XENON) || defined(PS3)
		CryWarning(VALIDATOR_MODULE_GAME,VALIDATOR_ERROR, "CXmlLoadGame::Init  not supported yet, strings cannot grow beyond 32767 chars\n");
		return false;
	#endif

	const unsigned int nFileSizeBits = GetISystem()->GetCompressedFileSize(name);
	const unsigned int nFileSizeBytes = nFileSizeBits / 8 + ((nFileSizeBits & 7) + 7) / 8;
	if (nFileSizeBytes <= 0)
	{
		return false;
	}

	char* const pXmlData = new char[nFileSizeBytes+16];
	GetISystem()->ReadCompressedFile(name, pXmlData,nFileSizeBits);

	m_pImpl->root = GetISystem()->LoadXmlFromBuffer(pXmlData, nFileSizeBytes);

	delete []pXmlData;
#else
	if (GetISystem()->GetPlatformOS()->UsePlatformSavingAPI() )
	{
		IPlatformOS::ISaveReaderPtr pSaveReader = GetISystem()->GetPlatformOS()->SaveGetReader(name);
		if (!pSaveReader)
		{
			return false;
		}

		size_t nFileSize;

		if ((pSaveReader->GetNumBytes(nFileSize) == IPlatformOS::eFOC_Failure) || (nFileSize <= 0))
		{
			return false;
		}

		std::vector<char> xmlData;
		xmlData.resize(nFileSize);
		
		if (pSaveReader->ReadBytes(&xmlData[0], nFileSize) == IPlatformOS::eFOC_Failure)
		{
			return false;
		}

		m_pImpl->root = GetISystem()->LoadXmlFromBuffer(&xmlData[0], nFileSize);
	}
	else
	{
		m_pImpl->root = GetISystem()->LoadXmlFromFile(name);
	}
#endif

	if (!m_pImpl->root)
		return false;

	m_pImpl->inputFile = name;

	m_pImpl->metadata = m_pImpl->root->findChild("Metadata");
	if (!m_pImpl->metadata)
		return false;

	return true;
}