* Save the values of settings to the inifile. * @param ini pointer to IniFile structure * @param sd read-only SettingDesc structure which contains the unmodified, * loaded values of the configuration file and various information about it * @param grpname holds the name of the group (eg. [network]) where these will be saved * @param object pointer to the object been saved * The functio
| 703 | * these and save them. |
| 704 | */ |
| 705 | static void IniSaveSettings(IniFile &ini, const SettingTable &settings_table, std::string_view grpname, void *object, bool) |
| 706 | { |
| 707 | IniGroup *group_def = nullptr, *group; |
| 708 | |
| 709 | for (auto &desc : settings_table) { |
| 710 | const SettingDesc *sd = GetSettingDesc(desc); |
| 711 | /* If the setting is not saved to the configuration |
| 712 | * file, just continue with the next setting */ |
| 713 | if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue; |
| 714 | if (sd->flags.Test(SettingFlag::NotInConfig)) continue; |
| 715 | |
| 716 | /* XXX - wtf is this?? (group override?) */ |
| 717 | std::string s{ sd->GetName() }; |
| 718 | auto sc = s.find('.'); |
| 719 | if (sc != std::string::npos) { |
| 720 | group = &ini.GetOrCreateGroup(s.substr(0, sc)); |
| 721 | s = s.substr(sc + 1); |
| 722 | } else { |
| 723 | if (group_def == nullptr) group_def = &ini.GetOrCreateGroup(grpname); |
| 724 | group = group_def; |
| 725 | } |
| 726 | |
| 727 | IniItem &item = group->GetOrCreateItem(s); |
| 728 | |
| 729 | if (!item.value.has_value() || !sd->IsSameValue(&item, object)) { |
| 730 | /* The value is different, that means we have to write it to the ini */ |
| 731 | item.value.emplace(sd->FormatValue(object)); |
| 732 | } |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | std::string IntSettingDesc::FormatValue(const void *object) const |
| 737 | { |
no test coverage detected