From 2ddb1847c5ee127e7ddc4056404c0de1cf61e005 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 15 Oct 2015 14:07:42 +0200 Subject: [PATCH] Added ability to save to ConfigFile --- include/Core/ConfigFile.h | 26 +++++++++++++++++++------- src/game/Core/ConfigFile.cpp | 14 ++++++++++++-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/include/Core/ConfigFile.h b/include/Core/ConfigFile.h index dd91578..9089d0e 100755 --- a/include/Core/ConfigFile.h +++ b/include/Core/ConfigFile.h @@ -7,7 +7,6 @@ #include "ResourceManager.h" - namespace dd { @@ -20,15 +19,28 @@ private: public: template - T GetValue(std::string key, T defaultValue) - { - return m_ptree.get(key, defaultValue); - } + T GetValue(std::string key, T defaultValue); + template + void SetValue(std::string key, T value); + + void SaveToDisk(); private: - boost::property_tree::ptree m_ptree; - + std::string m_Path; + boost::property_tree::ptree m_Ptree; }; +template +T ConfigFile::GetValue(std::string key, T defaultValue) +{ + return m_Ptree.get(key, defaultValue); +} + +template +void ConfigFile::SetValue(std::string key, T value) +{ + m_Ptree.put(key, value); +} + }; #endif // ConfigFile_h__ diff --git a/src/game/Core/ConfigFile.cpp b/src/game/Core/ConfigFile.cpp index 6a9abeb..18db4c4 100755 --- a/src/game/Core/ConfigFile.cpp +++ b/src/game/Core/ConfigFile.cpp @@ -3,5 +3,15 @@ dd::ConfigFile::ConfigFile(std::string path) { - boost::property_tree::ini_parser::read_ini(path, m_ptree); -} \ No newline at end of file + m_Path = path; + try { + boost::property_tree::ini_parser::read_ini(path, m_Ptree); + } catch (boost::property_tree::ptree_error& e) { + LOG_ERROR("Failed to load %s", path.c_str()); + } +} + +void dd::ConfigFile::SaveToDisk() +{ + boost::property_tree::ini_parser::write_ini(m_Path, m_Ptree); +}