diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index 157de0b4d..500d3c6e6 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -10,17 +10,22 @@ using namespace Settings; Ogre::ConfigFile Manager::mFile = Ogre::ConfigFile(); Ogre::ConfigFile Manager::mDefaultFile = Ogre::ConfigFile(); -void Manager::load(const std::string& file) +void Manager::loadUser (const std::string& file) { mFile.load(file); } -void Manager::loadDefault(const std::string& file) +void Manager::loadDefault (const std::string& file) { mDefaultFile.load(file); } -void Manager::save(const std::string& file) +void Manager::copyDefaultToUserSettings () +{ + mFile = mDefaultFile; +} + +void Manager::saveUser(const std::string& file) { std::fstream fout(file.c_str(), std::ios::out); @@ -39,6 +44,8 @@ void Manager::save(const std::string& file) { fout << i->first.c_str() << '=' << i->second.c_str() << '\n'; } + + seci.getNext(); } } @@ -62,3 +69,32 @@ const bool Manager::getBool (const std::string& setting, const std::string& cate { return Ogre::StringConverter::parseBool( getString(setting, category) ); } + +void Manager::setString (const std::string& setting, const std::string& category, const std::string& value) +{ + Ogre::ConfigFile::SettingsIterator it = mFile.getSettingsIterator(category); + while (it.hasMoreElements()) + { + Ogre::ConfigFile::SettingsMultiMap::iterator i = it.current(); + + if ((*i).first == setting) + (*i).second = value; + + it.getNext(); + } +} + +void Manager::setInt (const std::string& setting, const std::string& category, const int value) +{ + setString(setting, category, Ogre::StringConverter::toString(value)); +} + +void Manager::setFloat (const std::string& setting, const std::string& category, const float value) +{ + setString(setting, category, Ogre::StringConverter::toString(value)); +} + +void Manager::setBool (const std::string& setting, const std::string& category, const bool value) +{ + setString(setting, category, Ogre::StringConverter::toString(value)); +} diff --git a/components/settings/settings.hpp b/components/settings/settings.hpp index ae6f1a9de..46f8139c4 100644 --- a/components/settings/settings.hpp +++ b/components/settings/settings.hpp @@ -18,16 +18,24 @@ namespace Settings void loadDefault (const std::string& file); ///< load file as the default settings (can be overridden by user settings) - void load (const std::string& file); + void copyDefaultToUserSettings (); + ///< copy the default settings to the user settings (useful when there are no user settings yet) + + void loadUser (const std::string& file); ///< load file as user settings - void save (const std::string& file); - ///< save to file + void saveUser (const std::string& file); + ///< save user settings to file static const int getInt (const std::string& setting, const std::string& category); static const float getFloat (const std::string& setting, const std::string& category); static const std::string getString (const std::string& setting, const std::string& category); static const bool getBool (const std::string& setting, const std::string& category); + + static void setInt (const std::string& setting, const std::string& category, const int value); + static void setFloat (const std::string& setting, const std::string& category, const float value); + static void setString (const std::string& setting, const std::string& category, const std::string& value); + static void setBool (const std::string& setting, const std::string& category, const bool value); }; }