Ejemplo n.º 1
0
//**********************************************************************************************
void CIGInfo::load(TShapeCache &shapeCache)
{
	if (Loaded) return;
	Loaded = true; // even if loading fails, don't try twice to load it
	try
	{
		CIFile stream;
		stream.open(Path);
		printf(Path.c_str());
		CSmartPtr<CInstanceGroup> ig = new CInstanceGroup;
		ig->serial(stream);
		IG = ig; // commit
	}
	catch(EStream &e)
	{
		nlwarning(e.what());
	}
	if (IG)
	{
		// complete cache
		for(uint k = 0; k < IG->getNumInstance(); ++k)
		{
			std::string shapeName = standardizeShapeName(IG->getShapeName(k));			
			if (NLMISC::strlwr(CFile::getExtension(shapeName)) == "pacs_prim")
			{
				continue;
			}
			TShapeCache::iterator it = shapeCache.find(shapeName);
			CShapeInfo si;			
			bool buildOK = false;
			if (it == shapeCache.end())
			{
				CShapeStream ss;
				try
				{
					
					CIFile stream;
					std::string path = CPath::lookup(shapeName, false, false);
					if (!path.empty())
					{
						stream.open(path);
						ss.serial(stream);
						CShapeInfo si;
						si.build(*ss.getShapePointer());
						delete ss.getShapePointer();
						shapeCache[shapeName].swap(si);						
					}
				}
				catch (EStream &e)
				{
					// shape not loaded
					nlwarning(e.what());
				}
			}			
		}				
	}
}
Ejemplo n.º 2
0
// ---------------------------------------------------------------------------
CZoneRegion *loadLand (const string &filename)
{
	CZoneRegion *ZoneRegion = NULL;
	try
	{
		CIFile fileIn;
		if (fileIn.open (filename))
		{
			// Xml
			CIXml xml (true);
			nlverify (xml.init (fileIn));

			ZoneRegion = new CZoneRegion;
			ZoneRegion->serial (xml);
		}
		else
		{
			string sTmp = string("Can't open the land file : ") + filename;
			outString (sTmp);
		}
	}
	catch (const Exception& e)
	{
		string sTmp = string("Error in land file : ") + e.what();
		outString (sTmp);
	}
	return ZoneRegion;
}
Ejemplo n.º 3
0
// ***************************************************************************
CInstanceGroup* LoadInstanceGroup (const char* sFilename)
{
	CIFile file;
	CInstanceGroup *newIG = new CInstanceGroup;

	if( file.open( sFilename ) )
	{
		try
		{
			newIG->serial (file);
		}
		catch (const Exception &)
		{
			// Cannot save the file
			delete newIG;
			return NULL;
		}
	}
	else
	{
		delete newIG;
		return NULL;
	}
	return newIG;
}
Ejemplo n.º 4
0
// ---------------------------------------------------------------------------
NLMISC::CBitmap *CDataBase::loadBitmap (const std::string &fileName)
{
	NLMISC::CBitmap *pBitmap = new NLMISC::CBitmap();

	try
	{
		CIFile fileIn;
		if (fileIn.open (fileName))
		{
			pBitmap->load (fileIn);
		}
		else
		{
			pBitmap->makeDummy();
			nlwarning ("Bitmap not found : %s", fileName.c_str());
		}
	}
	catch (Exception& e)
	{
		pBitmap->makeDummy();
		theApp.errorMessage ("Error while loading bitmap %s : %s", fileName.c_str(), e.what());
	}

	return pBitmap;
}
Ejemplo n.º 5
0
void CIGLoader::load()
{
	for (int i=sizeof(IGFiles)/sizeof(IGFiles[0]);i--;)
	{
		try
		{
			uint k;
			CInstanceGroup ig;
			CIFile inputStream;
			if (!inputStream.open(IGFiles[i]))
			{
				nlinfo("unable to open %s", argv[1]);
				return -1;
			}
			ig.serial(inputStream);
			CVector gpos = ig.getGlobalPos(); // the origin for the ig
			for(k = 0; k < ig._InstancesInfos.size(); ++k)
			{
				nlinfo("instance %s : x = %.1f, y = %.1f, z = %.1f, sx = %.1f, sy = %.1f, sz = %.1f", ig._InstancesInfos[k].Name.c_str(), ig._InstancesInfos[k].Pos.x + gpos.x, ig._InstancesInfos[k].Pos.y + gpos.y, ig._InstancesInfos[k].Pos.z + gpos.z, ig._InstancesInfos[k].Scale.x, ig._InstancesInfos[k].Scale.y, ig._InstancesInfos[k].Scale.z);
			}
		}
		catch (std::exception &e)
		{
			nlinfo(e.what());
		}
	}
}
Ejemplo n.º 6
0
/**
 * updateShardOpenFromFile()
 * Update ShardOpen from a file.
 * Read a line of text in the file, converts it to int (atoi), then casts into bool for ShardOpen.
 */
void	updateShardOpenFromFile(const std::string& filename)
{
	CIFile	f;

	if (!f.open(filename))
	{
		nlwarning("Failed to update ShardOpen from file '%s', couldn't open file", filename.c_str());
		return;
	}

	try
	{
		char	readBuffer[256];
		f.getline(readBuffer, 256);
		sint state;
		NLMISC::fromString(std::string(readBuffer), state);

		setShardOpenState((TShardOpenState)state);

		nlinfo("Updated ShardOpen state to '%u' from file '%s'", ShardOpen.get(), filename.c_str());
	}
	catch (const Exception& e)
	{
		nlwarning("Failed to update ShardOpen from file '%s', exception raised while getline() '%s'", filename.c_str(), e.what());
	}
}
Ejemplo n.º 7
0
/*
 * Load State
 */
bool	CDatabaseState::load(const std::string& rootpath, bool usePrevious)
{
	CIFile		f;
	CIXml		ixml;

	string		filename = CPath::standardizePath(rootpath);
	if (usePrevious)
		filename += "previous_state";
	else
		filename += "state";

	if (!f.open(filename) || !ixml.init(f))
		return false;

	try
	{
		serial(ixml);
	}
	catch (const Exception&)
	{
		return false;
	}

	return true;
}
Ejemplo n.º 8
0
void CSoundAnimation::load()
{
	CIFile file;

	// Open the file
	if (!file.open(_Filename.c_str()))
	{
		throw NLMISC::Exception("Can't open the file for reading");
	}

	// Create the XML stream
	CIXml input;

	// Init
	if (input.init (file))
	{
		xmlNodePtr animNode = input.getRootNode ();
		xmlNodePtr markerNode = input.getFirstChildNode(animNode, "MARKER");

		while (markerNode != 0)
		{
			CSoundAnimMarker* marker = new CSoundAnimMarker();

			const char *time = (const char*) xmlGetProp(markerNode, (xmlChar*) "time");
			if (time == 0)
			{
				throw NLMISC::Exception("Invalid sound animation marker");
			}

			marker->setTime((float) atof(time));
			xmlFree ((void*)time);


			xmlNodePtr soundNode = input.getFirstChildNode(markerNode, "SOUND");

			while (soundNode != 0)
			{
				char *name = (char*) xmlGetProp(soundNode, (xmlChar*) "name");
				if (name == 0)
				{
					throw NLMISC::Exception("Invalid sound animation marker");
				}

				marker->addSound(NLMISC::CSheetId(string(name), "sound"));

				xmlFree ((void*)name);

				soundNode = input.getNextChildNode(soundNode, "SOUND");
			}

			addMarker(marker);

			markerNode = input.getNextChildNode(markerNode, "MARKER");
		}
	}

	// Close the file
	file.close ();
	_Dirty = false;
}
Ejemplo n.º 9
0
	bool loadLand (const string &filename)
	{
		try
		{
			CIFile fileIn;
			if (fileIn.open (filename))
			{
				CIXml xml (true);
				xml.init (fileIn);
				ZoneRegion = new CZoneRegion;
				ZoneRegion->serial (xml);
			}
			else
			{
				string sTmp = string("Can't open file : ") + filename;
				outString (sTmp);
				return false;
			}
		}
		catch (Exception& e)
		{
			string sTmp = string("Error in land file : ") + e.what();
			outString (sTmp);
			return false;
		}
		return true;
	}
Ejemplo n.º 10
0
// ***************************************************************************
void			CSkills::load(std::string configFileName)
{

    _Updated=false;
    CIFile f;
    try
    {
        if (f.open(configFileName+".skills"))
        {
            printf("reading skills for %s\n", configFileName.c_str());
            serial(f);
            f.close();
            _MyName=configFileName;
        }
        else
        {
            printf("Serialized file not found: %s.skills\n", configFileName.c_str());
            printf("Entering skills createFromConfigFile file.");
            createFromConfigFile(configFileName);
            printf("I have saved the file\n");
            printf("Serialized file is done and written");
            f.close();
            _MyName=configFileName;
        }
    }
    catch(exception &e)
    {
        printf ("My T3 Error %s\n", e.what ());
    }


}
Ejemplo n.º 11
0
int main(int argc, char* argv[])
{
	// Arg ?
	if (argc<3)
	{
		// Doc
		printf ("build_smallbank [input.bank] [output.smallbank] [new_absolute_path]\n");
	}
	else
	{
		try
		{
			// Load the bank
			CTileBank bank;

			// Input file
			CIFile input;
			if (input.open (argv[1]))
			{
				// Serial the bank
				bank.serial (input);

				// Make a small bank
				bank.cleanUnusedData ();

				// Absolute path ?
				if (argc>3)
					bank.setAbsPath (argv[3]);

				// Output file
				COFile output;
				if (output.open (argv[2]))
				{
					// Serial the bank
					bank.serial (output);
				}
				else
				{
					// Error
					nlwarning ("ERROR can't open the file %s for writing", argv[2]);
				}
			}
			else
			{
				// Error
				nlwarning ("ERROR can't open the file %s for reading", argv[1]);
			}

		}
		catch (const Exception& e)
		{
			// Error
			nlwarning ("ERROR fatal error: %s", e.what());
		}
	}
	return 0;
}
Ejemplo n.º 12
0
//-----------------------------------------------
// loadDump :
// Create a file with the current state of the client (good to report a bug).
//-----------------------------------------------
void loadDump(const std::string &name)
{
	CVectorD currentPos;

	// Load information to start as the version
	CIFile fStart;
	if(fStart.open(name + "_start.rec", false))
	{
		fStart.serialVersion(RecordVersion);
		fStart.serial(currentPos);
		// Close the File.
		fStart.close();
	}
	else
		nlwarning("loadDump: cannot open the file '%s_start.rec'.", name.c_str());

	// Update the position for the vision.
	NetMngr.setReferencePosition(currentPos);

	// Select the closest continent from the new position.
	class CDummyProgress : public IProgressCallback
	{
		void progress (float /* value */) {}
	};
	CDummyProgress dummy;
	ContinentMngr.select(currentPos, dummy);

	// Load the DB
	IngameDbMngr.read(name + "_db.rec");

	// Open the file.
	CIFile f;
	if(f.open(name + ".rec", false))
	{
		// Dump entities.
		EntitiesMngr.dump(f);

		// Close the File.
		f.close();
	}
	else
		nlwarning("loadDump: cannot open '%s.rec'.", name.c_str());
}// loadDump //
Ejemplo n.º 13
0
int main(int argc, char *argv[])
{
	if(argc != 4)
	{
		usage();
		return -1;
	}
	else
	{
		CBitmap		btmp;
		CIFile		inFile;
		COFile		outFile;

		uint	divideRatio;
		NLMISC::fromString(argv[3], divideRatio);
		if(divideRatio==0 || !isPowerOf2(divideRatio))
		{
			printf("divideRatio must be a powerOf2 (1, 2, 4, 8 ...) \n");
			return 0;
		}

		try
		{
			// read.
			if (!inFile.open(argv[1]))
			{
				printf("Can't open input file %s \n", argv[1]);
				return -1;
			}
			uint8	depth= btmp.load(inFile);
			if(depth==0)
				throw Exception("Bad File Format");
			inFile.close();

			// resize.
			btmp.resample(btmp.getWidth() / divideRatio, btmp.getHeight() / divideRatio);

			// output.
			if (!outFile.open(argv[2]))
			{
				printf("Can't open output file %s \n", argv[2]);
				return -1;
			}
			btmp.writeTGA(outFile, depth);
		}
		catch (const Exception &e)
		{
			printf("Error: %s\n", e.what());
				return -1;
		}

		return 0;
	}
}
Ejemplo n.º 14
0
//-----------------------------------------------------------------------------
CGmTpPendingCommand::CGmTpPendingCommand()
{
	CIFile f;
	string fileName = Bsi.getLocalPath() + toString("gm_pending_tp.bin");
	bool open = f.open(fileName);
	if( open )
	{
		f.serialCont( _CharacterTpPending );
	}
	f.close();
}
/// Play from memory.
bool CMusicChannelFMod::playSync(const std::string &filepath, bool loop)
{
    CIFile ifile;
    ifile.allowBNPCacheFileOnOpen(false);
    ifile.setCacheFileOnOpen(false);
    ifile.open(filepath);

    // try to load the music in memory
    uint32 fs = ifile.getFileSize();
    if (!fs) {
        nlwarning("NLSOUND FMod Driver: Empty music file");
        return false;
    }

    // read Buffer
    nlassert(!_MusicBuffer);
    _MusicBuffer = new uint8[fs];
    try {
        ifile.serialBuffer(_MusicBuffer, fs);
    }
    catch (...)
    {
        nlwarning("NLSOUND FMod Driver: Error while reading music file");
        delete[] _MusicBuffer;
        _MusicBuffer = NULL;
        return false;
    }

    // open FMOD stream
    _MusicStream = FSOUND_Stream_Open((const char*)_MusicBuffer,
                                      FSOUND_2D | FSOUND_LOADMEMORY | (loop ? FSOUND_LOOP_NORMAL : FSOUND_LOOP_OFF), 0, fs);
    if (!_MusicStream)
    {
        nlwarning("NLSOUND FMod Driver: Error while creating the FMOD stream for music file");
        delete[] _MusicBuffer;
        _MusicBuffer = NULL;
        return false;
    }

    if (!playStream())
    {
        nlwarning("NLSOUND FMod Driver: Error While trying to play sync music file");
        FSOUND_Stream_Close(_MusicStream);
        _MusicStream = NULL;
        delete[] _MusicBuffer;
        _MusicBuffer = NULL;
        return false;
    }

    return true;
}
/** Load the given zone (name without extension)
  * return a pointer to the zone, or NULL if not found
  * Throw an exception if a read error occured
  */
static CZone *LoadZone(uint16 xPos, uint16 yPos, std::string zoneExt)
{
	std::string zoneName;
	::getZoneNameByCoord(xPos, yPos, zoneName);
	std::auto_ptr<CZone> zone(new CZone);		
	std::string lookedUpZoneName = CPath::lookup(zoneName + zoneExt, false, false, false);
	if (lookedUpZoneName.empty()) return NULL;
	CIFile iF;
	if (!iF.open(lookedUpZoneName))
	{
		throw EFileNotOpened(lookedUpZoneName);
	}
	zone->serial(iF);
	iF.close();
	return zone.release();
}
Ejemplo n.º 17
0
CGuiToc *CGuiToc::Load(const string &filename)
{

	nlinfo("Loading TOC : %s",filename.c_str());

	xmlNodePtr node;
	CGuiToc *res;
	CIFile file;
	if (file.open(CPath::lookup(filename, false).c_str()))
	{
		res = new CGuiToc;
		if (res->doc.init(file))
		{
			node = res->doc.getRootNode();
		}		
		else
		{
			nlassert(false);
			delete res;
			return 0;
		}
	}
	else
	{
		nlassert(false);
		return 0;
	}

	for( node = res->doc.getFirstChildNode(node,"gui");node;node = res->doc.getNextChildNode(node,"gui") )
	{
		string xmlFilename;
		const char *value = (const char*)xmlGetProp (node, (xmlChar*)"filename");
		if (value)
		{
			xmlFilename = value;
			nlinfo("found : %s",xmlFilename.c_str());
			res->xml = CGuiXmlManager::Load(xmlFilename,res->LuaState);
			
			//CGuiObjectManager::getInstance().objects.push_back(res->xml->getRoot());
			break;
		}
		//filenameList.push_back(filename);
	}


	return res;
}
// ***************************************************************************
bool CInputHandlerManager::readInputConfigFile(const std::string & fileName)
{
	// parse the XML input config file to build the events to actions map
	CIXml read;
	CIFile file;
	xmlNodePtr root;
	if (!file.open(fileName))
	{
		nlinfo(" could not open file %s",fileName.c_str());
	}
	try
	{
		read.init (file);
		root = read.getRootNode();

	}
	catch (Exception &e)
	{
		// Output error
		root = NULL;
		nlwarning ("CFormLoader: Error while loading the xml input file : %s", e.what());
	}
	if (!root)
	{
		nlinfo ("no root element in xml file %s",fileName.c_str());
		return false;
	}
	//the root node name should be input_config
	if (strcmp( (char*)root->name,"input_config") )
	{
		nlinfo("in a xml input config, the root node must be <input_config>");
		return false;
	}

	//get all system nodes
	xmlNodePtr cur = root->xmlChildrenNode;
	while (cur)
	{
		// Read all combo_key_chat setup.
		if ( !strcmp((char*)cur->name,"combo_key_chat") )
			parseComboKeyChat(cur);

		cur= cur->next;
	}

	return true;
}
Ejemplo n.º 19
0
// init
void	CGenericXmlMsgHeaderManager::init(const string &filename)
{
	// open xml file
	CIFile file;
	if (!file.open (filename))
	{
		nlwarning("Cannot open xml file '%s', unable to initialize generic messages", filename.c_str());
		return;
	}

	// Init an xml stream
	CIXml read;
	read.init (file);

	// create root node from root xml node
	_Root = new CNode(read.getRootNode(), 0);
}
Ejemplo n.º 20
0
void	CMailForumService::checkFile(const std::string& file)
{
	uint	fsz = CFile::getFileSize(file);

	if (fsz == 0)
		return;

	vector<uint8>	buffer(fsz);

	CIFile	fi;
	if (!fi.open(file))
		return;

	fi.serialBuffer(&(buffer[0]), fsz);
	fi.close();

	char*	pb = (char*)(&(buffer[0]));
	char*	pt = pb;

	while (*pt != '\0' && strncmp(pt, "$$$$", 4))
		++pt;

	// file contents "$$$$" -> end of file marker, file is complete, can be deleted
	if (pt != '\0')
	{
		CFile::deleteFile(file);

		int		shard_id;
		char	to_username[256];
		char	from_username[256];

		int		scanned = sscanf(pb, "shard=%d to=%s from=%s", &shard_id, to_username, from_username);

		CMessage	msgout("MAIL_NOTIF");

		uint32	shardId = (uint32)shard_id;
		string	toUserName = to_username;
		string	fromUserName = from_username;

		nldebug("MAIL: sent notification for user '%s' on shard '%d'", toUserName.c_str(), shardId);

		msgout.serial(shardId, toUserName, fromUserName);

		CUnifiedNetwork::getInstance()->send("EGS", msgout);
	}
}
Ejemplo n.º 21
0
/*
 *		load()
 */
bool	CPrimChecker::load(const string &outputDirectory)
{
	string	outputfname = CPath::standardizePath(outputDirectory)+"pacs.packed_prims";

	CIFile	f;
	if (f.open(outputfname))
	{
		f.serial(_Grid);
		f.serialCont(_WaterHeight);
	}
	else
	{
		nlwarning("Couldn't load pacs.packed_prims file '%s'", outputfname.c_str());
		return false;
	}

	return true;
}
Ejemplo n.º 22
0
NL3D::CTextureBlank *CPrimBitmap::getTexture () const
{
	// Not loaded
	if (!_Loaded)
	{	
		// Get the filename
		string filename;
		if (getPropertyByName ("filename", filename))
		{
			_Texture = new CTextureBlank ();
			_Texture->setWrapS (ITexture::Clamp);
			_Texture->setWrapT (ITexture::Clamp);
			_Texture->setReleasable (false);
			try
			{
				CIFile iFile;
				if (iFile.open (filename))
				{
					// Load the texture
					_Texture->load (iFile);

					// Power of 2 texture
					uint width = raiseToNextPowerOf2 (_Texture->getWidth ());
					uint height = raiseToNextPowerOf2 (_Texture->getHeight());
					if ((width != _Texture->getWidth ()) || (height != _Texture->getHeight ()))
					{
						_Texture->resample (width, height);
					}
				}
				else
				{
					theApp.errorMessage ("Can't read bitmap %s", filename.c_str ());
				}
			}
			catch (Exception &e)
			{
				theApp.errorMessage ("Error reading bitmap %s : %s", filename.c_str (), e.what ());
			}
		}
	}
	_Loaded = true;

	return _Texture;
}
Ejemplo n.º 23
0
/*
 * Load a Reference index file
 */
bool	CRefIndex::load(const string& filename)
{
	CIFile		reffile;
	CIXml		ixml;

	if (!reffile.open(filename) || !ixml.init(reffile))
		return false;

	try
	{
		serial(ixml);
	}
	catch (const Exception&)
	{
		return false;
	}

	return true;
}
/** Load and compute the bbox of the models that are located in a given zone
  * \param the zone whose bbox must be computed
  * \param result the result bbox
  * \param shapeMap for speedup (avoid loading the same shape twice)
  * \param additionnalIG a map that gives an additionnal ig for a zone from its name (ryzom specific : used to compute village bbox)
  * \return true if the computed bbox is valid
  */
static void computeZoneIGBBox(const char *zoneName, CLightingBBox &result, TShapeMap &shapeMap, const TString2LightingBBox &additionnalIG)
{
	result = CLightingBBox(); // starts with a void box	
	std::string lcZoneName = NLMISC::toLower(std::string(zoneName));
	TString2LightingBBox::const_iterator zoneIt = additionnalIG.find(lcZoneName);
	if (zoneIt != additionnalIG.end())
	{		
		result = zoneIt->second;		
	}

	std::string igFileName = zoneName + std::string(".ig");
	std::string pathName = CPath::lookup(igFileName, false, false);

	if (pathName.empty())
	{
		// nlwarning("unable to find instance group of zone : %s", zoneName);
		return;
	}


	/// Load the instance group of this zone
	CIFile igFile;
	if (!igFile.open(pathName))
	{
		nlwarning("unable to open file : %s", pathName.c_str());
		return;
	}

	NL3D::CInstanceGroup ig;
	try
	{		
		ig.serial(igFile);
	}
	catch (NLMISC::Exception &e)
	{
		nlwarning("Error while reading an instance group file : %s \n reason : %s", pathName.c_str(), e.what());
		return;
	}
	CLightingBBox tmpBBox;
	computeIGBBox(ig, tmpBBox, shapeMap);		
	result.makeUnion(tmpBBox);	
}
Ejemplo n.º 25
0
void CTile_edit_dlg::on_loadPushButton_clicked()
{
	QFileDialog::Options options;
	QString selectedFilter;
	QString fileName = QFileDialog::getOpenFileName(this, tr("Open Bank"), ui.absolutePathPushButton->text() , tr("NeL tile bank files (*.bank);;All Files (*.*);;"), &selectedFilter, options);
	
	if (!fileName.isEmpty())
	{
		CIFile stream;
		if ( stream.open( fileName.toUtf8().constData() ) )
		{
			ui.landListWidget->clear();
			ui.tileSetListWidget->clear();
			tileBank.clear();
			tileBank.serial (stream);
		}
		
		int i;
		QStringList lands;
		for (i=0; i<tileBank.getLandCount(); i++)
		{
			// Add to the list
			lands.append( QString(tileBank.getLand(i)->getName().c_str()) );
		}
		ui.landListWidget->addItems(lands);


		QStringList tileSets;
		for (i=0; i<tileBank.getTileSetCount(); i++)
		{
			// Add to the list
			tileSets.append( QString( tileBank.getTileSet(i)->getName().c_str() ) );
		}
		ui.tileSetListWidget->addItems(tileSets);

		// Set MainFile
		mainFile = QFileInfo(fileName);

		ui.savePushButton->setEnabled(true);
		ui.absolutePathPushButton->setText( QString( tileBank.getAbsPath().c_str() ) );
	}
}
Ejemplo n.º 26
0
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
CInstanceGroup* LoadInstanceGroup(const char* sFilename)
{
	CIFile file;
	CInstanceGroup *newIG = new CInstanceGroup;

	if( file.open( CPath::lookup( string(sFilename) ) ) )
	{
		try
		{
			// Serial the skeleton
			newIG->serial (file);
			// All is good
		}
		catch (const Exception &)
		{
			// Cannot save the file
			delete newIG;
			return NULL;
		}
	}
	return newIG;
}
Ejemplo n.º 27
0
// *************************************************************************************************
CBitmap *buildSharedBitmap(const std::string &filename,
					 std::map<std::string, CBitmap *> &bitmapByName,
					 std::vector<CBitmap *> &builtBitmaps,
					 bool &alreadyBuilt
					)
{
	alreadyBuilt = false;
	if (filename.empty()) return NULL;
	std::string lcBMFilename = strlwr(CFile::getFilenameWithoutExtension(filename));
	std::map<std::string, CBitmap *>::iterator it = bitmapByName.find(lcBMFilename);
	if (it != bitmapByName.end())
	{
		alreadyBuilt = true;
		// bitmap already loaded so reuse it
		return it->second;
	}
	else
	{
		// load the bitmap
		std::string path = CPath::lookup(filename, false);
		if (path.empty()) return NULL;
		std::auto_ptr<CBitmap> bm(new CBitmap);
		try
		{
			CIFile f;
			f.open(path);
			if (bm->load(f, 0) == 0) return NULL;
			builtBitmaps.push_back(bm.release());
			bitmapByName[lcBMFilename] = builtBitmaps.back();
			// dump bitmap fisrt line
			return builtBitmaps.back();
		}
		catch(const EStream &)
		{
			return NULL;
		}
	}
}
Ejemplo n.º 28
0
/*
 * Load the ranges from a data file
 */
void				CRangeMirrorManager::loadRanges()
{
	try
	{
		CIFile file;
		if ( file.open( RANGE_MANAGER_BACKUP_FILE ) )
		{
			CIXml input;
			if ( input.init( file ) )
			{
				input.serialCont( _RangeListByDataSet );
			}
			file.close();
		}
		else
			throw EFileNotOpened( RANGE_MANAGER_BACKUP_FILE );
		nlinfo( "RangeMirrorManager: successfully loaded ranges" );
	}
	catch ( Exception& e )
	{
		nlinfo( "Can't load ranges: %s", e.what() ); // Info because not a problem
	}
}
//-----------------------------------------------
//	init
//
//-----------------------------------------------
void CCDBSynchronised::init( const string &fileName, NLMISC::IProgressCallback &progressCallBack )
{
	try
	{
		CIFile file;
		if (file.open (fileName))
		{
			// Init an xml stream
			CIXml read;
			read.init (file);

			//Parse the parser output!!!
			CCDBNodeBranch::resetNodeBankMapping(); // in case the game is restarted from start
			_Database = new CCDBNodeBranch("SERVER");
			_Database->init( read.getRootNode (), progressCallBack, true );
		}
	}
	catch (Exception &e)
	{
		// Output error
		nlwarning ("CFormLoader: Error while loading the form %s: %s", fileName.c_str(), e.what());
	}
}
Ejemplo n.º 30
0
// ***************************************************************************
bool CLuaState::executeFile(const std::string &pathName)
{
	//H_AUTO(Lua_CLuaState_executeFile)

	CIFile	inputFile;
	if(!inputFile.open(pathName))
		return false;

	#ifdef LUA_NEVRAX_VERSION
		if (LuaDebuggerIDE)
		{
			std::string path = NLMISC::CPath::getCurrentPath() + "/" + pathName.c_str();
			path = CPath::standardizeDosPath(path);
			LuaDebuggerIDE->addFile(path.c_str());
		}
	#endif

	// load the script text
	string	script;
	/*
	while(!inputFile.eof())
	{
		char	tmpBuff[5000];
		inputFile.getline(tmpBuff,   5000);
		script+= tmpBuff;
		script+= "\n";
	}
	*/
	script.resize(CFile::getFileSize(pathName));
	inputFile.serialBuffer((uint8 *) &script[0],  (uint)script.size());


	// execute the script text,   with dbgSrc==filename (use @ for lua internal purpose)
	executeScriptInternal(script,   string("@") + CFile::getFilename(pathName));

	return true;
}