2012-03-30 16:38:33 +00:00
|
|
|
#include "settings.hpp"
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include <OgreResourceGroupManager.h>
|
|
|
|
#include <OgreStringConverter.h>
|
|
|
|
|
|
|
|
using namespace Settings;
|
|
|
|
|
|
|
|
Ogre::ConfigFile Manager::mFile = Ogre::ConfigFile();
|
|
|
|
Ogre::ConfigFile Manager::mDefaultFile = Ogre::ConfigFile();
|
2012-04-01 14:26:42 +00:00
|
|
|
SettingCategoryVector Manager::mChangedSettings = SettingCategoryVector();
|
2012-03-30 16:38:33 +00:00
|
|
|
|
2012-03-31 11:35:40 +00:00
|
|
|
void Manager::loadUser (const std::string& file)
|
2012-03-30 16:38:33 +00:00
|
|
|
{
|
|
|
|
mFile.load(file);
|
|
|
|
}
|
|
|
|
|
2012-03-31 11:35:40 +00:00
|
|
|
void Manager::loadDefault (const std::string& file)
|
2012-03-30 16:38:33 +00:00
|
|
|
{
|
|
|
|
mDefaultFile.load(file);
|
|
|
|
}
|
|
|
|
|
2012-03-31 11:35:40 +00:00
|
|
|
void Manager::copyDefaultToUserSettings ()
|
|
|
|
{
|
|
|
|
mFile = mDefaultFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::saveUser(const std::string& file)
|
2012-03-30 16:38:33 +00:00
|
|
|
{
|
|
|
|
std::fstream fout(file.c_str(), std::ios::out);
|
|
|
|
|
|
|
|
Ogre::ConfigFile::SectionIterator seci = mFile.getSectionIterator();
|
|
|
|
|
|
|
|
while (seci.hasMoreElements())
|
|
|
|
{
|
|
|
|
Ogre::String sectionName = seci.peekNextKey();
|
|
|
|
|
|
|
|
if (sectionName.length() > 0)
|
|
|
|
fout << '\n' << '[' << seci.peekNextKey() << ']' << '\n';
|
|
|
|
|
|
|
|
Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
|
|
|
|
Ogre::ConfigFile::SettingsMultiMap::iterator i;
|
|
|
|
for (i = settings->begin(); i != settings->end(); ++i)
|
|
|
|
{
|
|
|
|
fout << i->first.c_str() << '=' << i->second.c_str() << '\n';
|
|
|
|
}
|
2012-03-31 11:35:40 +00:00
|
|
|
|
|
|
|
seci.getNext();
|
2012-03-30 16:38:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string Manager::getString (const std::string& setting, const std::string& category)
|
|
|
|
{
|
|
|
|
std::string defaultval = mDefaultFile.getSetting(setting, category);
|
|
|
|
return mFile.getSetting(setting, category, defaultval);
|
|
|
|
}
|
|
|
|
|
|
|
|
const float Manager::getFloat (const std::string& setting, const std::string& category)
|
|
|
|
{
|
|
|
|
return Ogre::StringConverter::parseReal( getString(setting, category) );
|
|
|
|
}
|
|
|
|
|
|
|
|
const int Manager::getInt (const std::string& setting, const std::string& category)
|
|
|
|
{
|
|
|
|
return Ogre::StringConverter::parseInt( getString(setting, category) );
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool Manager::getBool (const std::string& setting, const std::string& category)
|
|
|
|
{
|
|
|
|
return Ogre::StringConverter::parseBool( getString(setting, category) );
|
|
|
|
}
|
2012-03-31 11:35:40 +00:00
|
|
|
|
|
|
|
void Manager::setString (const std::string& setting, const std::string& category, const std::string& value)
|
|
|
|
{
|
2012-04-01 14:59:35 +00:00
|
|
|
bool found=false;
|
2012-03-31 11:35:40 +00:00
|
|
|
Ogre::ConfigFile::SettingsIterator it = mFile.getSettingsIterator(category);
|
|
|
|
while (it.hasMoreElements())
|
|
|
|
{
|
|
|
|
Ogre::ConfigFile::SettingsMultiMap::iterator i = it.current();
|
|
|
|
|
2012-04-01 14:26:42 +00:00
|
|
|
if ((*i).first == setting && (*i).second != value)
|
|
|
|
{
|
|
|
|
mChangedSettings.push_back(std::make_pair(setting, category));
|
2012-03-31 11:35:40 +00:00
|
|
|
(*i).second = value;
|
2012-04-01 14:59:35 +00:00
|
|
|
found = true;
|
2012-04-01 14:26:42 +00:00
|
|
|
}
|
2012-03-31 11:35:40 +00:00
|
|
|
|
|
|
|
it.getNext();
|
|
|
|
}
|
2012-04-01 14:59:35 +00:00
|
|
|
assert(found && "Attempting to change a non-existing setting");
|
2012-03-31 11:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
2012-04-01 14:26:42 +00:00
|
|
|
|
|
|
|
const SettingCategoryVector Manager::apply()
|
|
|
|
{
|
|
|
|
SettingCategoryVector vec = mChangedSettings;
|
|
|
|
mChangedSettings.clear();
|
|
|
|
return vec;
|
|
|
|
}
|