diff options
-rw-r--r-- | apps/plugins/lib/configfile.c | 24 | ||||
-rw-r--r-- | apps/plugins/lib/configfile.h | 6 |
2 files changed, 25 insertions, 5 deletions
diff --git a/apps/plugins/lib/configfile.c b/apps/plugins/lib/configfile.c index ffa325038c..ff4809a3f4 100644 --- a/apps/plugins/lib/configfile.c +++ b/apps/plugins/lib/configfile.c @@ -26,7 +26,8 @@ void configfile_init(struct plugin_api* newrb) cfg_rb = newrb; } -int configfile_save(char *filename, struct configdata *cfg, int num_items) +int configfile_save(const char *filename, struct configdata *cfg, + int num_items, int version) { int fd; int i; @@ -37,6 +38,8 @@ int configfile_save(char *filename, struct configdata *cfg, int num_items) if(fd < 0) return fd*10 - 1; + cfg_rb->fprintf(fd, "file version: %d\n", version); + for(i = 0;i < num_items;i++) { switch(cfg[i].type) { case TYPE_INT: @@ -64,13 +67,16 @@ int configfile_save(char *filename, struct configdata *cfg, int num_items) return 0; } -int configfile_load(char *filename, struct configdata *cfg, int num_items) +int configfile_load(const char *filename, struct configdata *cfg, + int num_items, int min_version) { int fd; int i, j; char *name; char *val; char buf[MAX_PATH]; + int file_version = -1; + int tmp; cfg_rb->snprintf(buf, MAX_PATH, "/.rockbox/rocks/%s", filename); fd = cfg_rb->open(buf, O_RDONLY); @@ -79,12 +85,24 @@ int configfile_load(char *filename, struct configdata *cfg, int num_items) while(cfg_rb->read_line(fd, buf, MAX_PATH) > 0) { cfg_rb->settings_parseline(buf, &name, &val); + + /* Bail out if the file version is too old */ + if(!cfg_rb->strcmp("file version", name)) { + file_version = cfg_rb->atoi(val); + if(file_version < min_version) { + cfg_rb->close(fd); + return -1; + } + } for(i = 0;i < num_items;i++) { if(!cfg_rb->strcmp(cfg[i].name, name)) { switch(cfg[i].type) { case TYPE_INT: - *cfg[i].val = cfg_rb->atoi(val); + tmp = cfg_rb->atoi(val); + /* Only set it if it's within range */ + if(tmp >= cfg[i].min && tmp <= cfg[i].max) + *cfg[i].val = tmp; break; case TYPE_ENUM: diff --git a/apps/plugins/lib/configfile.h b/apps/plugins/lib/configfile.h index 78cc8b1b6c..fcce7de275 100644 --- a/apps/plugins/lib/configfile.h +++ b/apps/plugins/lib/configfile.h @@ -38,7 +38,9 @@ struct configdata }; void configfile_init(struct plugin_api* newrb); -int configfile_save(char *filename, struct configdata *cfg, int num_items); -int configfile_load(char *filename, struct configdata *cfg, int num_items); +int configfile_save(const char *filename, struct configdata *cfg, + int num_items, int version); +int configfile_load(const char *filename, struct configdata *cfg, + int num_items, int min_version); #endif |