diff options
Diffstat (limited to 'src/settings.cpp')
-rw-r--r-- | src/settings.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/settings.cpp b/src/settings.cpp index 97b4629e0..9e7a561c5 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -62,6 +62,7 @@ #include "blitter/factory.hpp" #include "gamelog.h" #include "station_func.h" +#include "settings_func.h" #include "table/strings.h" @@ -2101,6 +2102,55 @@ void SaveToConfig() ini_free(ini); } +void GetGRFPresetList(GRFPresetList *list) +{ + list->Clear(); + + IniFile *ini = ini_load(_config_file); + IniGroup *group; + for (group = ini->group; group != NULL; group = group->next) { + if (strncmp(group->name, "preset-", 7) == 0) { + *list->Append() = strdup(group->name + 7); + } + } + + ini_free(ini); +} + +GRFConfig *LoadGRFPresetFromConfig(const char *config_name) +{ + char *section = (char*)alloca(strlen(config_name) + 8); + sprintf(section, "preset-%s", config_name); + + IniFile *ini = ini_load(_config_file); + GRFConfig *config = GRFLoadConfig(ini, section, false); + ini_free(ini); + + return config; +} + +void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config) +{ + char *section = (char*)alloca(strlen(config_name) + 8); + sprintf(section, "preset-%s", config_name); + + IniFile *ini = ini_load(_config_file); + GRFSaveConfig(ini, section, config); + ini_save(_config_file, ini); + ini_free(ini); +} + +void DeleteGRFPresetFromConfig(const char *config_name) +{ + char *section = (char*)alloca(strlen(config_name) + 8); + sprintf(section, "preset-%s", config_name); + + IniFile *ini = ini_load(_config_file); + ini_removegroup(ini, section); + ini_save(_config_file, ini); + ini_free(ini); +} + static const SettingDesc *GetSettingDescription(uint index) { if (index >= lengthof(_patch_settings)) return NULL; |