From 7912afa32f24404d3074897e34558d6e1c7870ff Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Sat, 15 Feb 2025 12:35:07 -0500 Subject: [PATCH] [BugFix] settings.c CRC calculation skipped F_CUSTOM_SETTING F_CUSTOM_SETTING write to the cfg file they do not however have a value in the settings struct to check against for the CRC at best you get the is_changed value but as Chris_S pointed out this works the first time BUT unless you are changing from DEFAULT to 'is_changed' or back there is nothing different in the CRC and thus further changes to custom settings do not get saved unless other settings change the CRC. Instead we will ask each of the custom settings to write their output and run the CRC on those values as well and allowing us to check for changes Change-Id: Ib3e7b621d676be5eb5ddc9eea00c4805292773fb --- apps/settings.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/apps/settings.c b/apps/settings.c index 0fb451f2c5..318f44b96e 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -154,6 +154,30 @@ const char* setting_get_cfgvals(const struct settings_list *setting) return NULL; } +/* calculates and stores crc of settings, returns true if settings have changed */ +static bool settings_crc_changed(void) +{ + char value[MAX_PATH]; + uint32_t custom_crc = 0xFFFFFFFF; + for(int i=0; iflags & F_CUSTOM_SETTING)) + continue; + cfg_to_string(setting, value, sizeof(value)); + custom_crc = crc_32(value, strlen(value), custom_crc); + } + + uint32_t crc = crc_32(&global_settings, sizeof(global_settings), custom_crc); + if (crc != user_settings_crc) + { + user_settings_crc = crc; + return true; + } + + return false; +} + /** Reading from a config file **/ /* * load settings from disk @@ -174,8 +198,7 @@ void settings_load(void) settings_load_config(FIXEDSETTINGSFILE, false); /* set initial CRC value - settings_save checks, if changed writes to disk */ - user_settings_crc = crc_32(&global_settings, - sizeof(global_settings), 0xFFFFFFFF); + settings_crc_changed(); } bool cfg_string_to_int(const struct settings_list *setting, int* out, const char* str) @@ -615,13 +638,11 @@ static void flush_global_status_callback(void) static void flush_config_block_callback(void) { - uint32_t crc = crc_32(&global_settings, sizeof(global_settings), 0xFFFFFFFF); - if (user_settings_crc != crc) + if (settings_crc_changed()) { DEBUGF("Writing changed user_settings to disk\n"); logf("Writing changed user_settings to disk"); - user_settings_crc = crc; /* update immediately in case we yield */ if (!settings_write_config(CONFIGFILE_TEMP, SETTINGS_SAVE_CHANGED)) { user_settings_crc = 0;