mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-09 13:12:37 -05:00
[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
This commit is contained in:
parent
5471f58fb1
commit
7912afa32f
1 changed files with 26 additions and 5 deletions
|
|
@ -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; i<nb_settings; i++)
|
||||
{
|
||||
const struct settings_list *setting = &settings[i];
|
||||
if (!(setting->flags & 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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue