forked from teamnwah/openmw-tes3coop
added untested interface
parent
8d7bf34348
commit
ff85006e71
@ -0,0 +1,64 @@
|
||||
#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();
|
||||
|
||||
void Manager::load(const std::string& file)
|
||||
{
|
||||
mFile.load(file);
|
||||
}
|
||||
|
||||
void Manager::loadDefault(const std::string& file)
|
||||
{
|
||||
mDefaultFile.load(file);
|
||||
}
|
||||
|
||||
void Manager::save(const std::string& file)
|
||||
{
|
||||
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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) );
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
#ifndef _COMPONENTS_SETTINGS_H
|
||||
#define _COMPONENTS_SETTINGS_H
|
||||
|
||||
#include <OgreConfigFile.h>
|
||||
|
||||
namespace Settings
|
||||
{
|
||||
|
||||
///
|
||||
/// \brief Settings management (can change during runtime)
|
||||
///
|
||||
class Manager
|
||||
{
|
||||
public:
|
||||
static Ogre::ConfigFile mFile;
|
||||
static Ogre::ConfigFile mDefaultFile;
|
||||
|
||||
void loadDefault (const std::string& file);
|
||||
///< load file as the default settings (can be overridden by user settings)
|
||||
|
||||
void load (const std::string& file);
|
||||
///< load file as user settings
|
||||
|
||||
void save (const std::string& file);
|
||||
///< save 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);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // _COMPONENTS_SETTINGS_H
|
Loading…
Reference in New Issue