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>
|
2010-11-21 22:48:58 +01:00
|
|
|
|
2011-04-06 22:53:00 +02:00
|
|
|
Configs g_configs;
|
2010-11-21 22:48:58 +01:00
|
|
|
|
2011-04-06 21:46:58 +02:00
|
|
|
bool Configs::load(const std::string& fileName)
|
2010-11-21 22:48:58 +01:00
|
|
|
{
|
2010-11-22 02:19:20 +01:00
|
|
|
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))
|
2010-11-22 02:19:20 +01:00
|
|
|
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());
|
2010-11-21 22:48:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
2011-05-21 20:15:46 +02:00
|
|
|
|
|
|
|
return true;
|
2010-11-21 22:48:58 +01:00
|
|
|
}
|
|
|
|
|
2011-04-06 21:46:58 +02:00
|
|
|
void Configs::save()
|
2010-11-21 22:48:58 +01:00
|
|
|
{
|
2010-11-25 00:36:15 +01:00
|
|
|
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());
|
2010-11-25 00:36:15 +01:00
|
|
|
}
|
2010-11-21 22:48:58 +01:00
|
|
|
}
|