// ***************************************************************************
void CInterfaceConfig::streamToDataBase (NLMISC::IStream &f, uint32 uiDbSaveVersion)
{
	if (!f.isReading())
	{
		nlwarning("stream is not in reading mode");
		return;
	}

	sint32 begPos = f.getPos();
	f.seek (0, NLMISC::IStream::end);
	sint32 endPos = f.getPos();
	if ((begPos - endPos) == 0) return;
	f.seek (begPos, NLMISC::IStream::begin);

	CInterfaceManager *pIM = CInterfaceManager::getInstance();

	// Load branch of the database
	SDBLeaf leafTmp;
	CCDBNodeBranch *pDB = pIM->getDbBranch ("UI:SAVE");
	if (pDB != NULL)
	{
		// Number of leaf to save
		uint32 nbLeaves = 0;
		f.serial(nbLeaves);

		for (uint32 i = 0; i < nbLeaves; ++i)
		{
			f.serial(leafTmp);

			// If there is a define RESET_VER_dbName that exist for this DB, check if version is OK
			bool	wantRead= true;
			// Format dbName for version check
			string	defVerId= "RESET_VER_";
			defVerId+= leafTmp.Name;
			for(uint i=0;i<defVerId.size();i++)
			{
				if(defVerId[i]==':')
					defVerId[i]='_';
			}
			// check if exist
			if(pIM->isDefineExist(defVerId))
			{
				uint32	dbVer;
				fromString(pIM->getDefine(defVerId), dbVer);
				// if the version in the file is older than the version this db want, abort read
				if(uiDbSaveVersion<dbVer)
					wantRead= false;
			}

			// if want read the value from file, read it, else keep the default one
			if(wantRead)
			{
				CCDBNodeLeaf *pNL = pIM->getDbProp(leafTmp.Name,false);
				if (pNL != NULL)
					leafTmp.setTo(pNL);
			}
		}
	}
}
Exemplo n.º 2
0
size_t vorbisReadFunc(void *ptr, size_t size, size_t nmemb, void *datasource)
{
    CAudioDecoderVorbis *audio_decoder_vorbis = (CAudioDecoderVorbis *)datasource;
    NLMISC::IStream *stream = audio_decoder_vorbis->getStream();
    nlassert(stream->isReading());
    sint32 length = (sint32)(size * nmemb);
    if (length > audio_decoder_vorbis->getStreamSize() - stream->getPos())
        length = audio_decoder_vorbis->getStreamSize() - stream->getPos();
    stream->serialBuffer((uint8 *)ptr, length);
    return length;
}
// ***************************************************************************
void CInterfaceConfig::CDesktopImage::read(NLMISC::IStream &f)
{
	nlassert(f.isReading());
	f.serialVersion(Version);
	f.serialCont(GCImages);
	// extra datas go until the end of stream
	sint32 begPos = f.getPos();
	f.seek (0, NLMISC::IStream::end);
	sint32 endPos = f.getPos();
	f.seek (begPos, NLMISC::IStream::begin);
	NLMISC::contReset(ExtraDatas);
	if (ExtraDatas.isReading())
	{
		ExtraDatas.invert();
	}
	sint32 length = endPos - begPos;
	if (length > 0)
	{
		uint8 *pBuffer = new uint8[length];
		f.serialBuffer(pBuffer, length); // read buffer from file
		ExtraDatas.serialBuffer(pBuffer, length); // copy buffer to memstream
		delete [] pBuffer;
	}
}