diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2007-02-01 13:57:14 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2007-02-01 13:57:14 +0000 |
commit | f0d2861fc58a81ad6dc520279c42710b1d02e20a (patch) | |
tree | 0fce27f201cc74d4fff6f19701f21a49c3c39722 /apps/settings.c | |
parent | c47172a48059c473350b78a68c25b0cbf368fac1 (diff) |
when saving config.cfg, only save settings which are not the same as
default, hopefully will give a small boost to saving and loading times.
Doing a manual save from "manage settings" > "write config" will save
every
setting.
Adds an option to save a cfg file from only the settings needed in a
theme .cfg (I may have missed some so let me know).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12172 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/settings.c')
-rw-r--r-- | apps/settings.c | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/apps/settings.c b/apps/settings.c index faf1f92773..f0833a65c2 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -402,8 +402,41 @@ static bool cfg_int_to_string(int setting_id, int val, char* buf) } return true; } +static bool is_changed(int setting_id) +{ + const struct settings_list *setting = &settings[setting_id]; + switch (setting->flags&F_T_MASK) + { + case F_T_INT: + case F_T_UINT: + if (setting->flags&F_DEF_ISFUNC) + { + if (*(int*)setting->setting == setting->default_val.func()) + return false; + } + else if (setting->flags&F_T_SOUND) + { + if (*(int*)setting->setting == + sound_default(setting->sound_setting->setting)) + return false; + } + else if (*(int*)setting->setting == setting->default_val.int_) + return false; + break; + case F_T_BOOL: + if (*(bool*)setting->setting == setting->default_val.bool_) + return false; + break; + case F_T_CHARPTR: + case F_T_UCHARPTR: + if (!strcmp((char*)setting->setting, setting->default_val.charptr)) + return false; + break; + } + return true; +} -bool settings_write_config(char* filename) +static bool settings_write_config(char* filename, int options) { int i; int fd; @@ -418,6 +451,14 @@ bool settings_write_config(char* filename) if (settings[i].cfg_name == NULL) continue; value[0] = '\0'; + + if ((options == SETTINGS_SAVE_CHANGED) && + !is_changed(i)) + continue; + else if ((options == SETTINGS_SAVE_THEME) && + ((settings[i].flags&F_THEMESETTING) == 0)) + continue; + switch (settings[i].flags&F_T_MASK) { case F_T_INT: @@ -477,7 +518,7 @@ static bool flush_config_block_callback(void) { bool r1, r2; r1 = write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); - r2 = settings_write_config(CONFIGFILE); + r2 = settings_write_config(CONFIGFILE, SETTINGS_SAVE_CHANGED); return r1 || r2; } @@ -536,7 +577,7 @@ int settings_save( void ) } return 0; } -bool settings_save_config(void) +bool settings_save_config(int options) { char filename[MAX_PATH]; @@ -554,7 +595,7 @@ bool settings_save_config(void) } } - if (settings_write_config(filename)) + if (settings_write_config(filename, options)) gui_syncsplash(HZ, true, str(LANG_SETTINGS_SAVED)); else gui_syncsplash(HZ, true, str(LANG_FAILED)); return true; |