tibia-client/src/framework/core/configs.cpp

38 lines
776 B
C++
Raw Normal View History

2011-07-17 02:13:53 +02:00
#include "configs.h"
#include "resources.h"
2011-07-13 23:12:36 +02:00
#include <otml/otml.h>
2011-04-06 22:53:00 +02:00
Configs g_configs;
2011-04-06 21:46:58 +02:00
bool Configs::load(const std::string& fileName)
{
m_fileName = fileName;
2011-07-13 23:12:36 +02:00
if(!g_resources.fileExists(fileName))
return false;
2011-05-19 19:11:05 +02:00
std::stringstream fin;
if(!g_resources.loadFile(fileName, fin))
return false;
2011-05-22 00:24:10 +02:00
try {
2011-07-13 23:12:36 +02:00
OTMLParser parser(fin, fileName);
parser.getDocument()->read(&m_confsMap);
} catch(OTMLException e) {
error("ERROR: Malformed config file: ", e.what());
return false;
}
return true;
}
2011-04-06 21:46:58 +02:00
void Configs::save()
{
if(!m_fileName.empty()) {
2011-07-13 23:12:36 +02:00
OTMLEmitter emitter;
emitter.createDocument()->write(m_confsMap);
2011-05-22 05:56:58 +02:00
g_resources.saveFile(m_fileName, emitter.emitDocument());
}
}