2011-08-16 15:06:16 +02:00
|
|
|
#include "configs.h"
|
|
|
|
#include "resourcemanager.h"
|
|
|
|
|
|
|
|
#include <framework/otml/otml.h>
|
|
|
|
|
|
|
|
Configs g_configs;
|
|
|
|
|
2011-08-20 22:30:41 +02:00
|
|
|
bool Configs::load(const std::string& file)
|
2011-08-16 15:06:16 +02:00
|
|
|
{
|
2011-08-20 22:30:41 +02:00
|
|
|
m_fileName = file;
|
|
|
|
|
|
|
|
if(!g_resources.fileExists(file))
|
|
|
|
return false;
|
2011-08-16 15:06:16 +02:00
|
|
|
|
|
|
|
try {
|
2011-08-20 22:30:41 +02:00
|
|
|
OTMLDocumentPtr doc = OTMLDocument::parse(file);
|
2011-08-19 20:53:23 +02:00
|
|
|
for(const OTMLNodePtr& child : doc->children())
|
2011-08-16 15:06:16 +02:00
|
|
|
m_confsMap[child->tag()] = child->value();
|
2011-08-19 20:53:23 +02:00
|
|
|
return true;
|
2011-08-16 15:06:16 +02:00
|
|
|
} catch(std::exception& e) {
|
2011-08-20 22:30:41 +02:00
|
|
|
logError("could not load configurations: ", e.what());
|
2011-08-16 15:06:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Configs::save()
|
|
|
|
{
|
2011-08-19 20:53:23 +02:00
|
|
|
OTMLDocumentPtr doc = OTMLDocument::create();
|
|
|
|
for(auto it : m_confsMap) {
|
|
|
|
OTMLNodePtr node = OTMLNode::create(it.first, it.second);
|
|
|
|
doc->addChild(node);
|
2011-08-16 15:06:16 +02:00
|
|
|
}
|
2011-08-19 20:53:23 +02:00
|
|
|
return doc->save(m_fileName);
|
2011-08-16 15:06:16 +02:00
|
|
|
}
|