mirror of
https://github.com/edubart/otclient.git
synced 2025-04-30 01:29:21 +02:00
...
This commit is contained in:
parent
e51c29702c
commit
be21321393
35
src/framework/core/configs.cpp
Normal file
35
src/framework/core/configs.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "configs.h"
|
||||
#include "resourcemanager.h"
|
||||
|
||||
#include <framework/otml/otml.h>
|
||||
|
||||
Configs g_configs;
|
||||
|
||||
bool Configs::load(const std::string& fileName)
|
||||
{
|
||||
m_fileName = fileName;
|
||||
|
||||
if(!g_resources.fileExists(fileName))
|
||||
return false;
|
||||
|
||||
try {
|
||||
OTMLDocumentPtr doc = OTMLDocument::parse(fileName);
|
||||
for(const OTMLNodePtr& child : doc->childNodes())
|
||||
m_confsMap[child->tag()] = child->value();
|
||||
} catch(std::exception& e) {
|
||||
logError("ERROR: could not load configurations: ", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configs::save()
|
||||
{
|
||||
if(!m_fileName.empty()) {
|
||||
OTMLDocumentPtr doc = OTMLDocument::create();
|
||||
doc->write(m_confsMap);
|
||||
return doc->save(m_fileName);
|
||||
}
|
||||
return false;
|
||||
}
|
22
src/framework/core/configs.h
Normal file
22
src/framework/core/configs.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef CONFIGMANAGER_H
|
||||
#define CONFIGMANAGER_H
|
||||
|
||||
#include "declarations.h"
|
||||
|
||||
class Configs
|
||||
{
|
||||
public:
|
||||
bool load(const std::string& fileName);
|
||||
bool save();
|
||||
|
||||
void set(const std::string& key, const std::string& value) { m_confsMap[key] = value; }
|
||||
std::string get(const std::string& key) { return m_confsMap[key]; }
|
||||
|
||||
private:
|
||||
std::string m_fileName;
|
||||
std::map<std::string, std::string> m_confsMap;
|
||||
};
|
||||
|
||||
extern Configs g_configs;
|
||||
|
||||
#endif
|
BIN
src/otclient/core/.spritemanager.cpp.kate-swp
Normal file
BIN
src/otclient/core/.spritemanager.cpp.kate-swp
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user