diff options
author | Thomas Martitz <kugel@rockbox.org> | 2010-08-01 16:15:27 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2010-08-01 16:15:27 +0000 |
commit | 9c0b2479f7025a84444adf08e3be8ced60dad013 (patch) | |
tree | f3d328dd73f46d599f0432cc43ae206798cbe4f6 /apps/settings.c | |
parent | 2e7d92fef707a2cd30820fd0053c539c3ac8e2b3 (diff) | |
download | rockbox-9c0b2479f7025a84444adf08e3be8ced60dad013.tar.gz rockbox-9c0b2479f7025a84444adf08e3be8ced60dad013.zip |
Rockbox as an application: add get_user_file_path().
For RaaA it evaluates user paths at runtime. For everything but codecs/plugins it will give the path under $HOME/.config/rockbox.org if write access is needed or if the file/folder in question exists there (otherwise it gives /usr/local/share/rockbox).
This allows for installing themes under $HOME as well as having config.cfg and other important files there while installing the application (and default themes) under /usr/local.
On the DAPs it's a no-op, returing /.rockbox directly.
Not converted to use get_user_file_path() are plugins themselves, because RaaA doesn't build plugins yet.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27656 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/settings.c')
-rw-r--r-- | apps/settings.c | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/apps/settings.c b/apps/settings.c index 6f1fd7ad2e..58585d60e1 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <limits.h> | 25 | #include <limits.h> |
26 | #include "inttypes.h" | 26 | #include "inttypes.h" |
27 | #include "config.h" | 27 | #include "config.h" |
28 | #include "rbpaths.h" | ||
28 | #include "action.h" | 29 | #include "action.h" |
29 | #include "crc32.h" | 30 | #include "crc32.h" |
30 | #include "sound.h" | 31 | #include "sound.h" |
@@ -110,7 +111,6 @@ long lasttime = 0; | |||
110 | [8-NVRAM_BLOCK_SIZE] data | 111 | [8-NVRAM_BLOCK_SIZE] data |
111 | */ | 112 | */ |
112 | #define NVRAM_DATA_START 8 | 113 | #define NVRAM_DATA_START 8 |
113 | #define NVRAM_FILE ROCKBOX_DIR "/nvram.bin" | ||
114 | static char nvram_buffer[NVRAM_BLOCK_SIZE]; | 114 | static char nvram_buffer[NVRAM_BLOCK_SIZE]; |
115 | 115 | ||
116 | static bool read_nvram_data(char* buf, int max_len) | 116 | static bool read_nvram_data(char* buf, int max_len) |
@@ -118,7 +118,9 @@ static bool read_nvram_data(char* buf, int max_len) | |||
118 | unsigned crc32 = 0xffffffff; | 118 | unsigned crc32 = 0xffffffff; |
119 | int var_count = 0, i = 0, buf_pos = 0; | 119 | int var_count = 0, i = 0, buf_pos = 0; |
120 | #ifndef HAVE_RTC_RAM | 120 | #ifndef HAVE_RTC_RAM |
121 | int fd = open(NVRAM_FILE,O_RDONLY); | 121 | char path[MAX_PATH]; |
122 | int fd = open(get_user_file_path(NVRAM_FILE, IS_FILE|NEED_WRITE, | ||
123 | path, sizeof(path)), O_RDONLY); | ||
122 | int bytes; | 124 | int bytes; |
123 | if (fd < 0) | 125 | if (fd < 0) |
124 | return false; | 126 | return false; |
@@ -172,6 +174,7 @@ static bool write_nvram_data(char* buf, int max_len) | |||
172 | char var_count = 0; | 174 | char var_count = 0; |
173 | #ifndef HAVE_RTC_RAM | 175 | #ifndef HAVE_RTC_RAM |
174 | int fd; | 176 | int fd; |
177 | char path[MAX_PATH]; | ||
175 | #endif | 178 | #endif |
176 | memset(buf,0,max_len); | 179 | memset(buf,0,max_len); |
177 | /* magic, version */ | 180 | /* magic, version */ |
@@ -195,7 +198,8 @@ static bool write_nvram_data(char* buf, int max_len) | |||
195 | max_len-NVRAM_DATA_START-1,0xffffffff); | 198 | max_len-NVRAM_DATA_START-1,0xffffffff); |
196 | memcpy(&buf[4],&crc32,4); | 199 | memcpy(&buf[4],&crc32,4); |
197 | #ifndef HAVE_RTC_RAM | 200 | #ifndef HAVE_RTC_RAM |
198 | fd = open(NVRAM_FILE,O_CREAT|O_TRUNC|O_WRONLY, 0666); | 201 | fd = open(get_user_file_path(NVRAM_FILE, IS_FILE|NEED_WRITE, |
202 | path, sizeof(path)),O_CREAT|O_TRUNC|O_WRONLY, 0666); | ||
199 | if (fd >= 0) | 203 | if (fd >= 0) |
200 | { | 204 | { |
201 | int len = write(fd,buf,max_len); | 205 | int len = write(fd,buf,max_len); |
@@ -226,8 +230,12 @@ void settings_load(int which) | |||
226 | read_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); | 230 | read_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); |
227 | if (which&SETTINGS_HD) | 231 | if (which&SETTINGS_HD) |
228 | { | 232 | { |
229 | settings_load_config(CONFIGFILE,false); | 233 | const char *file; |
230 | settings_load_config(FIXEDSETTINGSFILE,false); | 234 | char path[MAX_PATH]; |
235 | file = get_user_file_path(CONFIGFILE, IS_FILE|NEED_WRITE, path, sizeof(path)); | ||
236 | settings_load_config(file, false); | ||
237 | file = get_user_file_path(FIXEDSETTINGSFILE, IS_FILE, path, sizeof(path)); | ||
238 | settings_load_config(file, false); | ||
231 | } | 239 | } |
232 | } | 240 | } |
233 | 241 | ||
@@ -334,10 +342,12 @@ bool settings_load_config(const char* file, bool apply) | |||
334 | char storage[MAX_PATH]; | 342 | char storage[MAX_PATH]; |
335 | if (settings[i].filename_setting->prefix) | 343 | if (settings[i].filename_setting->prefix) |
336 | { | 344 | { |
337 | int len = strlen(settings[i].filename_setting->prefix); | 345 | char prefix_dir[MAX_PATH]; |
338 | if (!strncasecmp(value, | 346 | const char *dir = get_user_file_path( |
339 | settings[i].filename_setting->prefix, | 347 | settings[i].filename_setting->prefix, |
340 | len)) | 348 | 0, prefix_dir, sizeof(prefix_dir)); |
349 | int len = strlen(dir); | ||
350 | if (!strncasecmp(value, dir, len)) | ||
341 | { | 351 | { |
342 | strlcpy(storage, &value[len], MAX_PATH); | 352 | strlcpy(storage, &value[len], MAX_PATH); |
343 | } | 353 | } |
@@ -470,6 +480,10 @@ bool cfg_to_string(int i/*setting_id*/, char* buf, int buf_len) | |||
470 | if (((char*)settings[i].setting)[0] | 480 | if (((char*)settings[i].setting)[0] |
471 | && settings[i].filename_setting->prefix) | 481 | && settings[i].filename_setting->prefix) |
472 | { | 482 | { |
483 | char path[MAX_PATH]; | ||
484 | const char *prefix = get_user_file_path( | ||
485 | settings[i].filename_setting->prefix, 0, | ||
486 | path, sizeof(path)); | ||
473 | if (((char*)settings[i].setting)[0] == '-') | 487 | if (((char*)settings[i].setting)[0] == '-') |
474 | { | 488 | { |
475 | buf[0] = '-'; | 489 | buf[0] = '-'; |
@@ -477,8 +491,7 @@ bool cfg_to_string(int i/*setting_id*/, char* buf, int buf_len) | |||
477 | } | 491 | } |
478 | else | 492 | else |
479 | { | 493 | { |
480 | snprintf(buf,buf_len,"%s%s%s", | 494 | snprintf(buf,buf_len,"%s%s%s", prefix, |
481 | settings[i].filename_setting->prefix, | ||
482 | (char*)settings[i].setting, | 495 | (char*)settings[i].setting, |
483 | settings[i].filename_setting->suffix); | 496 | settings[i].filename_setting->suffix); |
484 | } | 497 | } |
@@ -589,8 +602,11 @@ static void flush_global_status_callback(void *data) | |||
589 | static void flush_config_block_callback(void *data) | 602 | static void flush_config_block_callback(void *data) |
590 | { | 603 | { |
591 | (void)data; | 604 | (void)data; |
605 | char path[MAX_PATH]; | ||
592 | write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); | 606 | write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); |
593 | settings_write_config(CONFIGFILE, SETTINGS_SAVE_CHANGED); | 607 | settings_write_config( |
608 | get_user_file_path(CONFIGFILE, IS_FILE|NEED_WRITE, path, sizeof(path)), | ||
609 | SETTINGS_SAVE_CHANGED); | ||
594 | } | 610 | } |
595 | 611 | ||
596 | /* | 612 | /* |
@@ -634,8 +650,8 @@ int settings_save(void) | |||
634 | 650 | ||
635 | bool settings_save_config(int options) | 651 | bool settings_save_config(int options) |
636 | { | 652 | { |
637 | char filename[MAX_PATH]; | 653 | char filename[MAX_PATH], path[MAX_PATH]; |
638 | char *folder, *namebase; | 654 | const char *folder, *namebase; |
639 | switch (options) | 655 | switch (options) |
640 | { | 656 | { |
641 | case SETTINGS_SAVE_THEME: | 657 | case SETTINGS_SAVE_THEME: |
@@ -663,6 +679,8 @@ bool settings_save_config(int options) | |||
663 | namebase = "config"; | 679 | namebase = "config"; |
664 | break; | 680 | break; |
665 | } | 681 | } |
682 | |||
683 | folder = get_user_file_path(folder, NEED_WRITE, path, sizeof(path)); | ||
666 | create_numbered_filename(filename, folder, namebase, ".cfg", 2 | 684 | create_numbered_filename(filename, folder, namebase, ".cfg", 2 |
667 | IF_CNFN_NUM_(, NULL)); | 685 | IF_CNFN_NUM_(, NULL)); |
668 | 686 | ||
@@ -1180,6 +1198,7 @@ bool set_option(const char* string, const void* variable, enum optiontype type, | |||
1180 | if (!option_screen(&item, NULL, false, NULL)) | 1198 | if (!option_screen(&item, NULL, false, NULL)) |
1181 | { | 1199 | { |
1182 | if (type == BOOL) | 1200 | if (type == BOOL) |
1201 | |||
1183 | *(bool*)variable = (temp == 1); | 1202 | *(bool*)variable = (temp == 1); |
1184 | else | 1203 | else |
1185 | *(int*)variable = temp; | 1204 | *(int*)variable = temp; |