minimize writes to config file

This commit is contained in:
Flyinghead 2019-10-29 14:34:29 +01:00
parent 5d6ac0acbb
commit 4cc199b2b7
3 changed files with 19 additions and 17 deletions

View File

@ -11,6 +11,7 @@
static string cfgPath;
static bool save_config = true;
static bool autoSave = true;
static emucfg::ConfigFile cfgdb;
static string game_id;
@ -44,10 +45,9 @@ void cfgSaveStr(const wchar * Section, const wchar * Key, const wchar * String)
}
else
cfgdb.set(section, key, value);
if(save_config)
{
if (save_config && autoSave)
savecfgf();
}
}
//New config code
@ -205,3 +205,10 @@ void cfgDeleteGameSpecificConfig()
has_game_specific_config = false;
cfgdb.delete_section(game_id);
}
void cfgSetAutoSave(bool autoSave)
{
::autoSave = autoSave;
if (autoSave)
savecfgf();
}

View File

@ -26,3 +26,4 @@ const char *cfgGetGameId();
bool cfgHasGameSpecificConfig();
void cfgMakeGameSpecificConfig();
void cfgDeleteGameSpecificConfig();
void cfgSetAutoSave(bool autoSave);

View File

@ -899,6 +899,7 @@ void LoadCustom()
void SaveSettings()
{
cfgSetAutoSave(false);
cfgSaveBool("config", "Dynarec.Enabled", settings.dynarec.Enable);
if (forced_game_cable == -1 || forced_game_cable != settings.dreamcast.cable)
cfgSaveInt("config", "Dreamcast.Cable", settings.dreamcast.cable);
@ -922,21 +923,12 @@ void SaveSettings()
// Write backend specific settings
// std::map<std::string, std::map<std::string, std::string>>
for (std::map<std::string, std::map<std::string, std::string>>::iterator it = settings.audio.options.begin(); it != settings.audio.options.end(); ++it)
for (const auto& pair : settings.audio.options)
{
std::pair<std::string, std::map<std::string, std::string>> p = (std::pair<std::string, std::map<std::string, std::string>>)*it;
std::string section = p.first;
std::map<std::string, std::string> options = p.second;
for (std::map<std::string, std::string>::iterator it2 = options.begin(); it2 != options.end(); ++it2)
{
std::pair<std::string, std::string> p2 = (std::pair<std::string, std::string>)*it2;
std::string key = p2.first;
std::string val = p2.second;
cfgSaveStr(section.c_str(), key.c_str(), val.c_str());
}
const std::string& section = pair.first;
const auto& options = pair.second;
for (const auto& option : options)
cfgSaveStr(section.c_str(), option.first.c_str(), option.second.c_str());
}
cfgSaveBool("config", "rend.WideScreen", settings.rend.WideScreen);
@ -997,6 +989,8 @@ void SaveSettings()
void SaveAndroidSettings();
SaveAndroidSettings();
#endif
cfgSetAutoSave(true);
}
void dc_resume()