Settings: Only write out config on setting change for persistent changes

This commit is contained in:
Jonathan G Rennison
2023-08-24 17:27:47 +01:00
parent f8c8ba2670
commit 547c00b465
8 changed files with 81 additions and 38 deletions

View File

@@ -15,6 +15,8 @@
#include <functional>
#include <vector>
enum SaveToConfigFlags : uint32;
enum SettingFlag : uint32 {
SF_NONE = 0,
SF_GUI_0_IS_SPECIAL = 1 << 0, ///< A value of zero is possible and has a custom string (the one after "strval").
@@ -40,6 +42,8 @@ enum SettingFlag : uint32 {
SF_ENUM_PRE_CB_VALIDATE = 1 << 20, ///< Call the pre_check callback for enum incoming value validation
SF_CONVERT_BOOL_TO_INT = 1 << 21, ///< Accept a boolean value when loading an int-type setting from the config file
SF_ENABLE_UPSTREAM_LOAD = 1 << 22, ///< Enable loading from upstream mode savegames even when patx_name is set
SF_PRIVATE = 1 << 23, ///< Setting is in private ini
SF_SECRET = 1 << 24, ///< Setting is in secrets ini
};
DECLARE_ENUM_AS_BIT_SET(SettingFlag)
@@ -217,7 +221,7 @@ struct IntSettingDesc : SettingDesc {
virtual bool IsBoolSetting() const { return false; }
bool IsIntSetting() const override { return true; }
void ChangeValue(const void *object, int32 newvalue) const;
void ChangeValue(const void *object, int32 newvalue, SaveToConfigFlags ini_save_flags) const;
void MakeValueValidAndWrite(const void *object, int32 value) const;
virtual size_t ParseValue(const char *str) const;
@@ -308,7 +312,7 @@ struct StringSettingDesc : SettingDesc {
PostChangeCallback *post_callback; ///< Callback when the setting has been changed.
bool IsStringSetting() const override { return true; }
void ChangeValue(const void *object, std::string &newval) const;
void ChangeValue(const void *object, std::string &newval, SaveToConfigFlags ini_save_flags) const;
void FormatValue(char *buf, const char *last, const void *object) const override;
void ParseValue(const IniItem *item, void *object) const override;