Exemplo n.º 1
0
	//-----------------------------------------------------------------------------------
	bool Utf8Archive::isBaseArchiveAlive() const
	{
		Ogre::ArchiveManager::ArchiveMapIterator it = ArchiveManager::getSingleton().getArchiveIterator();
		while(it.hasMoreElements())
		{
			const String& key = it.peekNextKey();
			Ogre::Archive* arch = it.getNext();
			if(key == mBaseArchiveName)
			{
				return true;
			}
		}
		return false;
	}
Exemplo n.º 2
0
gkBlendListIterator::gkBlendListIterator(List* list)
	:	m_list(list),
#if OGREKIT_USE_BPARSE
		m_index(0)
#else
		m_index(list ? list->first : 0)
#endif
{
}

bool gkBlendListIterator::hasMoreElements() const
{
	if (m_list == 0) return false;

#if OGREKIT_USE_BPARSE
	return m_index < m_list->size();
#else
	return m_index != 0;
#endif
}


gkBlendListIterator::ListItem* gkBlendListIterator::getNext(void)	 
{ 
#if OGREKIT_USE_BPARSE
	return m_list->at(m_index++);
#else
	ListItem* item = m_index;
	m_index = m_index->next;
	return item;
#endif
}

//--

gkBlendInternalFile::gkBlendInternalFile()
	:	m_file(0)
{
}

gkBlendInternalFile::~gkBlendInternalFile()
{
	delete m_file;
	m_file = 0;
}

bool gkBlendInternalFile::parse(const gkString& fname)
{

	if (fname.empty()) 
	{
		gkLogMessage("BlendFile: File " << fname << " loading failed. File name is empty.");
		return false;
	}

#if OGREKIT_USE_BPARSE

	utMemoryStream fs;
	fs.open(fname.c_str(), utStream::SM_READ);

	if (!fs.isOpen())
	{
		gkLogMessage("BlendFile: File " << fname << " loading failed. No such file.");
		return false;
	}

	// Write contents and inflate.
	utMemoryStream buffer(utStream::SM_WRITE);
	fs.inflate(buffer);

	m_file = new bParse::bBlenderFile((char*)buffer.ptr(), buffer.size());
	m_file->parse(false);

	if (!m_file->ok())
	{
		gkLogMessage("BlendFile: File " << fname << " loading failed. Data error.");
		return false;
	}

#else

	m_file = new fbtBlend();
	int status = m_file->parse(fname.c_str(), fbtFile::PM_COMPRESSED);
	if (status != fbtFile::FS_OK)
	{
		delete m_file;
		m_file = 0;
		gkLogMessage("BlendFile: File " << fname << " loading failed. code: " << status);
		//return false;
	}
	else 
	{
		 gkLogMessage("BlendFile: File " << fname << " loading end1" );
	    return true;
	}
	//gkLogMessage("BlendFile: File " << fname << " loading end" );
	m_file = new fbtBlend();
	Ogre::DataStreamPtr stream;
	Ogre::ArchiveManager::ArchiveMapIterator beginItera = Ogre::ArchiveManager::getSingleton().getArchiveIterator();
	while(beginItera.hasMoreElements())
	{
		typedef std::map<Ogre::String, Ogre::Archive*>::iterator ArchiveIterator;
		ArchiveIterator arch = beginItera.current();	
		if (arch->second)
		{
			 Ogre::FileInfoListPtr fileInfo = arch->second->findFileInfo(fname);
			 if (fileInfo->size() > 0)
			 {
				 stream = arch->second->open(fname);
				 gkLogMessage("BlendFile: File found create stream");
				 break;
			 }
		}
		beginItera.moveNext();
	}
	//gkLogMessage("malloc buffer");
	unsigned char * buffer = new unsigned char[stream->size()];
	//gkLogMessage(" stream->read ");
    long sizeCount = stream->read(buffer,stream->size());
    //gkLogMessage(" m_file->parse");
	if(m_file) m_file->parse(buffer,sizeCount);
	delete buffer;
	//gkLogMessage(" m_file->parse end");
#endif
	return true;
}


Blender::FileGlobal* gkBlendInternalFile::getFileGlobal()
{
	GK_ASSERT(m_file);
	
#if OGREKIT_USE_BPARSE
	return (Blender::FileGlobal*)m_file->getFileGlobal();
#else
	return m_file->m_fg;
#endif
}

int gkBlendInternalFile::getVersion()
{
	GK_ASSERT(m_file);

#if OGREKIT_USE_BPARSE
	return m_file->getMain()->getVersion();
#else
	return m_file->getVersion();
#endif
}