mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 05:49:56 +00:00
123 lines
2.8 KiB
C++
123 lines
2.8 KiB
C++
|
|
#include "state.hpp"
|
|
|
|
#include <stdexcept>
|
|
#include <algorithm>
|
|
|
|
CSMPrefs::State *CSMPrefs::State::sThis = 0;
|
|
|
|
void CSMPrefs::State::load()
|
|
{
|
|
// default settings file
|
|
boost::filesystem::path local = mConfigurationManager.getLocalPath() / mConfigFile;
|
|
boost::filesystem::path global = mConfigurationManager.getGlobalPath() / mConfigFile;
|
|
|
|
if (boost::filesystem::exists (local))
|
|
mSettings.loadDefault (local.string());
|
|
else if (boost::filesystem::exists (global))
|
|
mSettings.loadDefault (global.string());
|
|
else
|
|
throw std::runtime_error ("No default settings file found! Make sure the file \"opencs.ini\" was properly installed.");
|
|
|
|
// user settings file
|
|
boost::filesystem::path user = mConfigurationManager.getUserConfigPath() / mConfigFile;
|
|
|
|
if (boost::filesystem::exists (user))
|
|
mSettings.loadUser (user.string());
|
|
}
|
|
|
|
void CSMPrefs::State::declare()
|
|
{
|
|
declareCategory ("Windows");
|
|
|
|
declareCategory ("Records");
|
|
|
|
declareCategory ("ID Tables");
|
|
|
|
declareCategory ("ID Dialogues");
|
|
|
|
declareCategory ("Reports");
|
|
|
|
declareCategory ("Search & Replace");
|
|
|
|
declareCategory ("Scripts");
|
|
|
|
declareCategory ("General Input");
|
|
|
|
declareCategory ("3D Scene Input");
|
|
|
|
declareCategory ("Tooltips");
|
|
}
|
|
|
|
void CSMPrefs::State::declareCategory (const std::string& key)
|
|
{
|
|
std::map<std::string, Category>::iterator iter = mCategories.find (key);
|
|
|
|
if (iter!=mCategories.end())
|
|
{
|
|
mCurrentCategory = iter;
|
|
}
|
|
else
|
|
{
|
|
mCurrentCategory =
|
|
mCategories.insert (std::make_pair (key, Category (this, key))).first;
|
|
}
|
|
}
|
|
|
|
CSMPrefs::State::State (const Files::ConfigurationManager& configurationManager)
|
|
: mConfigFile ("opencs.ini"), mConfigurationManager (configurationManager),
|
|
mCurrentCategory (mCategories.end())
|
|
{
|
|
if (sThis)
|
|
throw std::logic_error ("An instance of CSMPRefs::State already exists");
|
|
|
|
load();
|
|
declare();
|
|
|
|
sThis = this;
|
|
}
|
|
|
|
CSMPrefs::State::~State()
|
|
{
|
|
sThis = 0;
|
|
}
|
|
|
|
void CSMPrefs::State::save()
|
|
{
|
|
boost::filesystem::path user = mConfigurationManager.getUserConfigPath() / mConfigFile;
|
|
mSettings.saveUser (user.string());
|
|
}
|
|
|
|
CSMPrefs::State::Iterator CSMPrefs::State::begin()
|
|
{
|
|
return mCategories.begin();
|
|
}
|
|
|
|
CSMPrefs::State::Iterator CSMPrefs::State::end()
|
|
{
|
|
return mCategories.end();
|
|
}
|
|
|
|
CSMPrefs::Category& CSMPrefs::State::getCategory (const std::string& key)
|
|
{
|
|
Iterator iter = mCategories.find (key);
|
|
|
|
if (iter==mCategories.end())
|
|
throw std::logic_error ("Invalid user settings category: " + key);
|
|
|
|
return iter->second;
|
|
}
|
|
|
|
CSMPrefs::State& CSMPrefs::State::get()
|
|
{
|
|
if (!sThis)
|
|
throw std::logic_error ("No instance of CSMPrefs::State");
|
|
|
|
return *sThis;
|
|
}
|
|
|
|
|
|
CSMPrefs::State& CSMPrefs::get()
|
|
{
|
|
return State::get();
|
|
}
|