Remember invalid settings
This is handy when multiple cores have independent sets of settings
This commit is contained in:
parent
4a328231d3
commit
e825585871
5 changed files with 45 additions and 1 deletions
|
@ -108,6 +108,16 @@ public:
|
|||
* Get set of all settings.
|
||||
*/
|
||||
static std::set<std::string> get_settings_set() throw(std::bad_alloc);
|
||||
/**
|
||||
* Enable/Disable storage mode.
|
||||
*
|
||||
* In storage mode, invalid values are stored in addition to being rejected.
|
||||
*/
|
||||
static void set_storage_mode(bool enable) throw();
|
||||
/**
|
||||
* Get invalid settings cache.
|
||||
*/
|
||||
static std::map<std::string, std::string> get_invalid_values() throw(std::bad_alloc);
|
||||
/**
|
||||
* Lock holder
|
||||
*/
|
||||
|
@ -123,6 +133,8 @@ protected:
|
|||
std::string settingname;
|
||||
private:
|
||||
static setting* get_by_name(const std::string& name);
|
||||
static std::map<std::string, std::string> invalid_values;
|
||||
static bool storage_mode;
|
||||
mutex* mut;
|
||||
};
|
||||
|
||||
|
|
|
@ -69,6 +69,9 @@ namespace
|
|||
};
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> setting::invalid_values;
|
||||
bool setting::storage_mode = false;
|
||||
|
||||
setting::setting(const std::string& name) throw(std::bad_alloc)
|
||||
{
|
||||
stlock_hold lck;
|
||||
|
@ -93,16 +96,26 @@ setting* setting::get_by_name(const std::string& name)
|
|||
|
||||
void setting::set(const std::string& _setting, const std::string& value) throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
setting* tochange = get_by_name(_setting);
|
||||
setting* tochange;
|
||||
try {
|
||||
tochange = get_by_name(_setting);
|
||||
} catch(...) {
|
||||
if(storage_mode)
|
||||
invalid_values[_setting] = value;
|
||||
throw;
|
||||
}
|
||||
try {
|
||||
{
|
||||
lock_holder lck(tochange);
|
||||
tochange->set(value);
|
||||
invalid_values.erase(_setting);
|
||||
}
|
||||
information_dispatch::do_setting_change(_setting, value);
|
||||
} catch(std::bad_alloc& e) {
|
||||
throw;
|
||||
} catch(std::exception& e) {
|
||||
if(storage_mode)
|
||||
invalid_values[_setting] = value;
|
||||
throw std::runtime_error("Can't set setting '" + _setting + "': " + e.what());
|
||||
}
|
||||
}
|
||||
|
@ -133,6 +146,7 @@ void setting::blank(const std::string& _setting) throw(std::bad_alloc, std::runt
|
|||
lock_holder lck(tochange);
|
||||
if(!tochange->blank(true))
|
||||
throw std::runtime_error("This setting can't be cleared");
|
||||
invalid_values.erase(_setting);
|
||||
}
|
||||
information_dispatch::do_setting_clear(_setting);
|
||||
} catch(std::bad_alloc& e) {
|
||||
|
@ -168,6 +182,16 @@ std::set<std::string> setting::get_settings_set() throw(std::bad_alloc)
|
|||
return r;
|
||||
}
|
||||
|
||||
void setting::set_storage_mode(bool enable) throw()
|
||||
{
|
||||
storage_mode = enable;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> setting::get_invalid_values() throw(std::bad_alloc)
|
||||
{
|
||||
return invalid_values;
|
||||
}
|
||||
|
||||
|
||||
numeric_setting::numeric_setting(const std::string& sname, int32_t minv, int32_t maxv, int32_t dflt)
|
||||
throw(std::bad_alloc)
|
||||
|
|
|
@ -161,7 +161,9 @@ int main(int argc, char** argv)
|
|||
create_lsnesrc();
|
||||
messages << "Saving per-user data to: " << get_config_path() << std::endl;
|
||||
messages << "--- Running lsnesrc --- " << std::endl;
|
||||
setting::set_storage_mode(true);
|
||||
command::invokeC("run-script " + cfgpath + "/lsnes.rc");
|
||||
setting::set_storage_mode(false);
|
||||
messages << "--- End running lsnesrc --- " << std::endl;
|
||||
|
||||
run_extra_scripts(cmdline);
|
||||
|
|
|
@ -44,6 +44,8 @@ namespace
|
|||
else
|
||||
cfgfile << "set-setting " << i << " " << setting::get(i) << std::endl;
|
||||
}
|
||||
for(auto i : setting::get_invalid_values())
|
||||
cfgfile << "set-setting " << i.first << " " << i.second << std::endl;
|
||||
//Aliases.
|
||||
for(auto i : command::get_aliases()) {
|
||||
std::string old_alias_value = command::get_alias_for(i);
|
||||
|
|
|
@ -193,6 +193,8 @@ end:
|
|||
else
|
||||
cfgfile << "set-setting " << i << " " << setting::get(i) << std::endl;
|
||||
}
|
||||
for(auto i : setting::get_invalid_values())
|
||||
cfgfile << "set-setting " << i.first << " " << i.second << std::endl;
|
||||
//Aliases.
|
||||
for(auto i : command::get_aliases()) {
|
||||
std::string old_alias_value = command::get_alias_for(i);
|
||||
|
@ -360,7 +362,9 @@ bool lsnes_app::OnInit()
|
|||
std::string cfgpath = get_config_path();
|
||||
messages << "Saving per-user data to: " << get_config_path() << std::endl;
|
||||
messages << "--- Running lsnesrc --- " << std::endl;
|
||||
setting::set_storage_mode(true);
|
||||
command::invokeC("run-script " + cfgpath + "/lsneswxw.rc");
|
||||
setting::set_storage_mode(false);
|
||||
messages << "--- End running lsnesrc --- " << std::endl;
|
||||
|
||||
if(settings_mode) {
|
||||
|
|
Loading…
Add table
Reference in a new issue