diff options
-rw-r--r-- | apps/settings.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/apps/settings.c b/apps/settings.c index 45e2a4e99f..5dad1a4ff6 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -259,11 +259,20 @@ static int hex_to_rgb(const char* hex) | |||
259 | return 0; | 259 | return 0; |
260 | } | 260 | } |
261 | #endif | 261 | #endif |
262 | #define MAX_PERSISTANT_VARS 8 | ||
263 | struct persistant_vars { | ||
264 | char setting[MAX_FILENAME]; | ||
265 | char value[MAX_FILENAME]; | ||
266 | }; | ||
267 | static struct persistant_vars persistant_vars[MAX_PERSISTANT_VARS]; | ||
268 | static int persistant_vars_count = 0; | ||
262 | bool settings_write_config(char* filename) | 269 | bool settings_write_config(char* filename) |
263 | { | 270 | { |
264 | int i; | 271 | int i; |
265 | int fd; | 272 | int fd; |
266 | char value[MAX_FILENAME * 3]; /* More than enough for all current values */ | 273 | bool check_persistant = !strcmp(filename, CONFIGFILE) && |
274 | persistant_vars_count; | ||
275 | char value[MAX_PATH]; | ||
267 | fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY); | 276 | fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY); |
268 | if (fd < 0) | 277 | if (fd < 0) |
269 | return false; | 278 | return false; |
@@ -273,6 +282,23 @@ bool settings_write_config(char* filename) | |||
273 | { | 282 | { |
274 | if (settings[i].cfg_name == NULL) | 283 | if (settings[i].cfg_name == NULL) |
275 | continue; | 284 | continue; |
285 | if (check_persistant) | ||
286 | { | ||
287 | int j; | ||
288 | bool found = false; | ||
289 | for(j=0; j<persistant_vars_count; j++) | ||
290 | { | ||
291 | if (!strcmp(persistant_vars[j].setting, settings[i].cfg_name)) | ||
292 | { | ||
293 | fdprintf(fd,"~%s: %s\r\n", settings[i].cfg_name, | ||
294 | persistant_vars[j].value); | ||
295 | found = true; | ||
296 | break; | ||
297 | } | ||
298 | } | ||
299 | if (found) | ||
300 | continue; | ||
301 | } | ||
276 | switch (settings[i].flags&F_T_MASK) | 302 | switch (settings[i].flags&F_T_MASK) |
277 | { | 303 | { |
278 | case F_T_INT: | 304 | case F_T_INT: |
@@ -721,7 +747,7 @@ bool settings_load_config(const char* file, bool apply) | |||
721 | char* name; | 747 | char* name; |
722 | char* value; | 748 | char* value; |
723 | int i; | 749 | int i; |
724 | 750 | bool check_persistant = !strcmp(file, CONFIGFILE); | |
725 | fd = open(file, O_RDONLY); | 751 | fd = open(file, O_RDONLY); |
726 | if (fd < 0) | 752 | if (fd < 0) |
727 | return false; | 753 | return false; |
@@ -730,7 +756,14 @@ bool settings_load_config(const char* file, bool apply) | |||
730 | { | 756 | { |
731 | if (!settings_parseline(line, &name, &value)) | 757 | if (!settings_parseline(line, &name, &value)) |
732 | continue; | 758 | continue; |
733 | 759 | if (check_persistant && (name[0] == '~') | |
760 | && (persistant_vars_count<MAX_PERSISTANT_VARS)) | ||
761 | { | ||
762 | name++; | ||
763 | strcpy(persistant_vars[persistant_vars_count].setting, name); | ||
764 | strcpy(persistant_vars[persistant_vars_count].value, value); | ||
765 | persistant_vars_count++; | ||
766 | } | ||
734 | for(i=0; i<nb_settings; i++) | 767 | for(i=0; i<nb_settings; i++) |
735 | { | 768 | { |
736 | if (settings[i].cfg_name == NULL) | 769 | if (settings[i].cfg_name == NULL) |