MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / IniLoadSettings

Function IniLoadSettings

src/settings.cpp:620–659  ·  view source on GitHub ↗

* Load values from a group of an IniFile structure into the internal representation * @param ini pointer to IniFile structure that holds administrative information * @param settings_table table with SettingDesc structures whose internally pointed variables will * be given values * @param grpname the group of the IniFile to search in for the new values * @param object pointer to the obj

Source from the content-addressed store, hash-verified

618 * @param only_startup load only the startup settings set
619 */
620static void IniLoadSettings(IniFile &ini, const SettingTable &settings_table, std::string_view grpname, void *object, bool only_startup)
621{
622 const IniGroup *group;
623 const IniGroup *group_def = ini.GetGroup(grpname);
624
625 for (auto &desc : settings_table) {
626 const SettingDesc *sd = GetSettingDesc(desc);
627 if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
628 if (sd->startup != only_startup) continue;
629
630 /* For settings.xx.yy load the settings from [xx] yy = ? */
631 std::string s{ sd->GetName() };
632 auto sc = s.find('.');
633 if (sc != std::string::npos) {
634 group = ini.GetGroup(s.substr(0, sc));
635 if (group == nullptr) group = group_def;
636 s = s.substr(sc + 1);
637 } else {
638 group = group_def;
639 }
640
641 const IniItem *item = nullptr;
642 if (group != nullptr) item = group->GetItem(s);
643 if (item == nullptr && group != group_def && group_def != nullptr) {
644 /* For settings.xx.yy load the settings from [settings] yy = ? in case the previous
645 * did not exist (e.g. loading old config files with a [settings] section */
646 item = group_def->GetItem(s);
647 }
648 if (item == nullptr) {
649 /* For settings.xx.zz.yy load the settings from [zz] yy = ? in case the previous
650 * did not exist (e.g. loading old config files with a [yapf] section */
651 sc = s.find('.');
652 if (sc != std::string::npos) {
653 if (group = ini.GetGroup(s.substr(0, sc)); group != nullptr) item = group->GetItem(s.substr(sc + 1));
654 }
655 }
656
657 sd->ParseValue(item, object);
658 }
659}
660
661void IntSettingDesc::ParseValue(const IniItem *item, void *object) const
662{

Callers 2

IniLoadWindowSettingsFunction · 0.85
LoadFromConfigFunction · 0.85

Calls 8

GetSettingDescFunction · 0.85
SlIsObjectCurrentlyValidFunction · 0.85
GetGroupMethod · 0.80
substrMethod · 0.80
GetItemMethod · 0.80
GetNameMethod · 0.45
findMethod · 0.45
ParseValueMethod · 0.45

Tested by

no test coverage detected