More cleanups

This commit is contained in:
Ahmed Samy 2013-08-23 02:12:36 +02:00
parent b27352c321
commit 644d4daeea
2 changed files with 75 additions and 58 deletions

View File

@ -223,6 +223,7 @@ void CreatureManager::loadSpawns(const std::string& fileName)
return; return;
} }
try {
TiXmlDocument doc; TiXmlDocument doc;
doc.Parse(g_resources.readFileContents(fileName).c_str()); doc.Parse(g_resources.readFileContents(fileName).c_str());
if(doc.Error()) if(doc.Error())
@ -242,10 +243,14 @@ void CreatureManager::loadSpawns(const std::string& fileName)
} }
doc.Clear(); doc.Clear();
m_spawnLoaded = true; m_spawnLoaded = true;
} catch(std::exception& e) {
g_logger.error(stdext::format("Failed to load '%s': %s", fileName, e.what()));
}
} }
void CreatureManager::saveSpawns(const std::string& fileName) void CreatureManager::saveSpawns(const std::string& fileName)
{ {
try {
TiXmlDocument doc; TiXmlDocument doc;
doc.SetTabSize(2); doc.SetTabSize(2);
@ -264,6 +269,9 @@ void CreatureManager::saveSpawns(const std::string& fileName)
std::string savePath = g_resources.getRealPath(fileName); std::string savePath = g_resources.getRealPath(fileName);
if(!doc.SaveFile(savePath)) if(!doc.SaveFile(savePath))
stdext::throw_exception(stdext::format("failed to save spawns XML %s: %s", savePath, doc.ErrorDesc())); stdext::throw_exception(stdext::format("failed to save spawns XML %s: %s", savePath, doc.ErrorDesc()));
} catch(std::exception& e) {
g_logger.error(stdext::format("Failed to save '%s': %s", fileName, e.what()));
}
} }
void CreatureManager::loadCreatureBuffer(const std::string& buffer) void CreatureManager::loadCreatureBuffer(const std::string& buffer)

View File

@ -134,6 +134,7 @@ HousePtr HouseManager::getHouseByName(std::string name)
void HouseManager::load(const std::string& fileName) void HouseManager::load(const std::string& fileName)
{ {
try {
TiXmlDocument doc; TiXmlDocument doc;
doc.Parse(g_resources.readFileContents(fileName).c_str()); doc.Parse(g_resources.readFileContents(fileName).c_str());
if(doc.Error()) if(doc.Error())
@ -154,10 +155,14 @@ void HouseManager::load(const std::string& fileName)
house->load(elem); house->load(elem);
} }
} catch(std::exception& e) {
g_logger.error(stdext::format("Failed to load '%s': %s", fileName, e.what()));
}
} }
void HouseManager::save(const std::string& fileName) void HouseManager::save(const std::string& fileName)
{ {
try {
TiXmlDocument doc; TiXmlDocument doc;
doc.SetTabSize(2); doc.SetTabSize(2);
@ -176,6 +181,9 @@ void HouseManager::save(const std::string& fileName)
std::string savePath = g_resources.getRealPath(fileName); std::string savePath = g_resources.getRealPath(fileName);
if(!doc.SaveFile(savePath)) if(!doc.SaveFile(savePath))
stdext::throw_exception(stdext::format("failed to save houses XML %s: %s", savePath, doc.ErrorDesc())); stdext::throw_exception(stdext::format("failed to save houses XML %s: %s", savePath, doc.ErrorDesc()));
} catch(std::exception& e) {
g_logger.error(stdext::format("Failed to save '%s': %s", fileName, e.what()));
}
} }
HouseList HouseManager::filterHouses(uint32 townId) HouseList HouseManager::filterHouses(uint32 townId)
@ -193,3 +201,4 @@ HouseList::iterator HouseManager::findHouse(uint32 houseId)
[=] (const HousePtr& house) -> bool { return house->getId() == houseId; }); [=] (const HousePtr& house) -> bool { return house->getId() == houseId; });
} }
/* vim: set ts=4 sw=4 et: */