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 | |
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')
-rw-r--r-- | apps/codecs.c | 4 | ||||
-rw-r--r-- | apps/filetree.c | 5 | ||||
-rw-r--r-- | apps/filetypes.c | 7 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_fonts.c | 2 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_parser.c | 3 | ||||
-rw-r--r-- | apps/gui/theme_settings.c | 4 | ||||
-rw-r--r-- | apps/main.c | 17 | ||||
-rw-r--r-- | apps/menus/main_menu.c | 5 | ||||
-rw-r--r-- | apps/menus/theme_menu.c | 4 | ||||
-rw-r--r-- | apps/misc.c | 29 | ||||
-rw-r--r-- | apps/misc.h | 2 | ||||
-rw-r--r-- | apps/playlist.c | 12 | ||||
-rw-r--r-- | apps/playlist_catalog.c | 10 | ||||
-rw-r--r-- | apps/plugin.c | 1 | ||||
-rw-r--r-- | apps/plugin.h | 1 | ||||
-rw-r--r-- | apps/radio/presets.c | 1 | ||||
-rw-r--r-- | apps/radio/radioart.c | 1 | ||||
-rw-r--r-- | apps/recorder/albumart.c | 1 | ||||
-rw-r--r-- | apps/recorder/recording.c | 2 | ||||
-rw-r--r-- | apps/root_menu.c | 10 | ||||
-rw-r--r-- | apps/scrobbler.c | 2 | ||||
-rw-r--r-- | apps/settings.c | 47 | ||||
-rw-r--r-- | apps/settings.h | 45 | ||||
-rw-r--r-- | apps/tagcache.c | 142 | ||||
-rw-r--r-- | apps/tree.c | 4 |
25 files changed, 203 insertions, 158 deletions
diff --git a/apps/codecs.c b/apps/codecs.c index 154faa3f3f..29a664425a 100644 --- a/apps/codecs.c +++ b/apps/codecs.c | |||
@@ -193,8 +193,8 @@ struct codec_api ci = { | |||
193 | 193 | ||
194 | void codec_get_full_path(char *path, const char *codec_root_fn) | 194 | void codec_get_full_path(char *path, const char *codec_root_fn) |
195 | { | 195 | { |
196 | snprintf(path, MAX_PATH-1, CODECS_DIR "/%s." CODEC_EXTENSION, | 196 | snprintf(path, MAX_PATH-1, "%s/%s." CODEC_EXTENSION, |
197 | codec_root_fn); | 197 | CODECS_DIR, codec_root_fn); |
198 | } | 198 | } |
199 | 199 | ||
200 | static int codec_load_ram(int size, struct codec_api *api) | 200 | static int codec_load_ram(int size, struct codec_api *api) |
diff --git a/apps/filetree.c b/apps/filetree.c index 460ab9e453..fa942b263d 100644 --- a/apps/filetree.c +++ b/apps/filetree.c | |||
@@ -609,11 +609,12 @@ int ft_enter(struct tree_context* c) | |||
609 | case FILE_ATTR_ROCK: | 609 | case FILE_ATTR_ROCK: |
610 | case FILE_ATTR_LUA: | 610 | case FILE_ATTR_LUA: |
611 | { | 611 | { |
612 | char *plugin = buf, *argument = NULL; | 612 | char *plugin = buf, *argument = NULL, lua_path[MAX_PATH]; |
613 | int ret; | 613 | int ret; |
614 | 614 | ||
615 | if ((file->attr & FILE_ATTR_MASK) == FILE_ATTR_LUA) { | 615 | if ((file->attr & FILE_ATTR_MASK) == FILE_ATTR_LUA) { |
616 | plugin = VIEWERS_DIR "/lua.rock"; /* Use a #define here ? */ | 616 | snprintf(lua_path, sizeof(lua_path)-1, "%s/lua.rock", VIEWERS_DIR); /* Use a #define here ? */ |
617 | plugin = lua_path; | ||
617 | argument = buf; | 618 | argument = buf; |
618 | } | 619 | } |
619 | 620 | ||
diff --git a/apps/filetypes.c b/apps/filetypes.c index 4be2437a29..67a4c176fb 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c | |||
@@ -175,7 +175,7 @@ static char *filetypes_strdup(char* string) | |||
175 | return buffer; | 175 | return buffer; |
176 | } | 176 | } |
177 | static void read_builtin_types(void); | 177 | static void read_builtin_types(void); |
178 | static void read_config(char* config_file); | 178 | static void read_config(const char* config_file); |
179 | #ifdef HAVE_LCD_COLOR | 179 | #ifdef HAVE_LCD_COLOR |
180 | /* Colors file format is similar to icons: | 180 | /* Colors file format is similar to icons: |
181 | * ext:hex_color | 181 | * ext:hex_color |
@@ -272,6 +272,7 @@ void read_viewer_theme_file(void) | |||
272 | 272 | ||
273 | void filetype_init(void) | 273 | void filetype_init(void) |
274 | { | 274 | { |
275 | char path[MAX_PATH]; | ||
275 | /* set the directory item first */ | 276 | /* set the directory item first */ |
276 | filetypes[0].extension = NULL; | 277 | filetypes[0].extension = NULL; |
277 | filetypes[0].plugin = NULL; | 278 | filetypes[0].plugin = NULL; |
@@ -280,7 +281,7 @@ void filetype_init(void) | |||
280 | 281 | ||
281 | filetype_count = 1; | 282 | filetype_count = 1; |
282 | read_builtin_types(); | 283 | read_builtin_types(); |
283 | read_config(VIEWERS_CONFIG); | 284 | read_config(get_user_file_path(VIEWERS_CONFIG, IS_FILE, path, sizeof(path))); |
284 | #ifdef HAVE_LCD_BITMAP | 285 | #ifdef HAVE_LCD_BITMAP |
285 | read_viewer_theme_file(); | 286 | read_viewer_theme_file(); |
286 | #endif | 287 | #endif |
@@ -320,7 +321,7 @@ static void read_builtin_types(void) | |||
320 | } | 321 | } |
321 | } | 322 | } |
322 | 323 | ||
323 | static void read_config(char* config_file) | 324 | static void read_config(const char* config_file) |
324 | { | 325 | { |
325 | char line[64], *s, *e; | 326 | char line[64], *s, *e; |
326 | char extension[8], plugin[32]; | 327 | char extension[8], plugin[32]; |
diff --git a/apps/gui/skin_engine/skin_fonts.c b/apps/gui/skin_engine/skin_fonts.c index 92a6a22ccf..b3b4df2c92 100644 --- a/apps/gui/skin_engine/skin_fonts.c +++ b/apps/gui/skin_engine/skin_fonts.c | |||
@@ -100,7 +100,7 @@ int skin_font_load(char* font_name) | |||
100 | pf->buffer_size = SKIN_FONT_SIZE; | 100 | pf->buffer_size = SKIN_FONT_SIZE; |
101 | 101 | ||
102 | snprintf(filename, MAX_PATH, FONT_DIR "/%s.fnt", font_name); | 102 | snprintf(filename, MAX_PATH, FONT_DIR "/%s.fnt", font_name); |
103 | strcpy(font->name, font_name); | 103 | get_user_file_path(filename, FORCE_BUFFER_COPY, font->name, sizeof(font->name)); |
104 | 104 | ||
105 | pf->fd = -1; | 105 | pf->fd = -1; |
106 | font->font_id = font_load(pf, filename); | 106 | font->font_id = font_load(pf, filename); |
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index e5c89ab2b1..d0194c669b 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c | |||
@@ -1452,7 +1452,8 @@ bool skin_data_load(enum screen_type screen, struct wps_data *wps_data, | |||
1452 | strlcpy(bmpdir, buf, dot - buf + 1); | 1452 | strlcpy(bmpdir, buf, dot - buf + 1); |
1453 | } | 1453 | } |
1454 | else | 1454 | else |
1455 | { | 1455 | { /* fall back to backdrop dir for built-in themes */ |
1456 | /* no get_user_file_path(), assuming we ship bmps for built-in themes */ | ||
1456 | snprintf(bmpdir, MAX_PATH, "%s", BACKDROP_DIR); | 1457 | snprintf(bmpdir, MAX_PATH, "%s", BACKDROP_DIR); |
1457 | } | 1458 | } |
1458 | /* load the bitmaps that were found by the parsing */ | 1459 | /* load the bitmaps that were found by the parsing */ |
diff --git a/apps/gui/theme_settings.c b/apps/gui/theme_settings.c index e9862eda3a..a975c218cd 100644 --- a/apps/gui/theme_settings.c +++ b/apps/gui/theme_settings.c | |||
@@ -97,7 +97,9 @@ void settings_apply_skins(void) | |||
97 | CHART2(">skin load ", skins[i].suffix); | 97 | CHART2(">skin load ", skins[i].suffix); |
98 | if (skins[i].setting[0] && skins[i].setting[0] != '-') | 98 | if (skins[i].setting[0] && skins[i].setting[0] != '-') |
99 | { | 99 | { |
100 | snprintf(buf, sizeof buf, WPS_DIR "/%s.%s", | 100 | char path[MAX_PATH]; |
101 | snprintf(buf, sizeof buf, "%s/%s.%s", | ||
102 | get_user_file_path(WPS_DIR, false, path, sizeof(path)), | ||
101 | skins[i].setting, skins[i].suffix); | 103 | skins[i].setting, skins[i].suffix); |
102 | skins[i].loadfunc(screen, buf, true); | 104 | skins[i].loadfunc(screen, buf, true); |
103 | } | 105 | } |
diff --git a/apps/main.c b/apps/main.c index 6c6d09cbaa..67cd6d2f0d 100644 --- a/apps/main.c +++ b/apps/main.c | |||
@@ -131,6 +131,9 @@ static void init(void); | |||
131 | #endif | 131 | #endif |
132 | int main(int argc, char *argv[]) | 132 | int main(int argc, char *argv[]) |
133 | { | 133 | { |
134 | #ifdef APPLICATION | ||
135 | paths_init(); | ||
136 | #endif | ||
134 | sys_handle_argv(argc, argv); | 137 | sys_handle_argv(argc, argv); |
135 | #else | 138 | #else |
136 | /* main(), and various functions called by main() and init() may be | 139 | /* main(), and various functions called by main() and init() may be |
@@ -163,11 +166,17 @@ int main(void) | |||
163 | 166 | ||
164 | #ifdef AUTOROCK | 167 | #ifdef AUTOROCK |
165 | { | 168 | { |
166 | static const char filename[] = PLUGIN_APPS_DIR "/autostart.rock"; | 169 | char filename[MAX_PATH]; |
167 | 170 | const char *file = get_user_file_path( | |
168 | if(file_exists(filename)) /* no complaint if it doesn't exist */ | 171 | #ifdef APPLICATION |
172 | ROCKBOX_DIR | ||
173 | #else | ||
174 | PLUGIN_APPS_DIR | ||
175 | #endif | ||
176 | "/autostart.rock", NEED_WRITE|IS_FILE, filename, sizeof(filename)); | ||
177 | if(file_exists(file)) /* no complaint if it doesn't exist */ | ||
169 | { | 178 | { |
170 | plugin_load((char*)filename, NULL); /* start if it does */ | 179 | plugin_load(file, NULL); /* start if it does */ |
171 | } | 180 | } |
172 | } | 181 | } |
173 | #endif /* #ifdef AUTOROCK */ | 182 | #endif /* #ifdef AUTOROCK */ |
diff --git a/apps/menus/main_menu.c b/apps/menus/main_menu.c index a64b1f8e47..1d22dba7ea 100644 --- a/apps/menus/main_menu.c +++ b/apps/menus/main_menu.c | |||
@@ -110,9 +110,12 @@ MAKE_MENU(manage_settings, ID2P(LANG_MANAGE_MENU), NULL, Icon_Config, | |||
110 | /***********************************/ | 110 | /***********************************/ |
111 | /* INFO MENU */ | 111 | /* INFO MENU */ |
112 | 112 | ||
113 | |||
113 | static bool show_credits(void) | 114 | static bool show_credits(void) |
114 | { | 115 | { |
115 | if (plugin_load(VIEWERS_DIR "/credits.rock",NULL) != PLUGIN_OK) | 116 | char credits[MAX_PATH] = { '\0' }; |
117 | snprintf(credits, MAX_PATH, "%s/credits.rock", VIEWERS_DIR); | ||
118 | if (plugin_load(credits, NULL) != PLUGIN_OK) | ||
116 | { | 119 | { |
117 | /* show the rockbox logo and version untill a button is pressed */ | 120 | /* show the rockbox logo and version untill a button is pressed */ |
118 | show_logo(); | 121 | show_logo(); |
diff --git a/apps/menus/theme_menu.c b/apps/menus/theme_menu.c index f8fb06b22f..c6553728a1 100644 --- a/apps/menus/theme_menu.c +++ b/apps/menus/theme_menu.c | |||
@@ -241,9 +241,11 @@ static struct browse_folder_info themes = {THEME_DIR, SHOW_CFG}; | |||
241 | 241 | ||
242 | int browse_folder(void *param) | 242 | int browse_folder(void *param) |
243 | { | 243 | { |
244 | char path[MAX_PATH]; | ||
244 | const struct browse_folder_info *info = | 245 | const struct browse_folder_info *info = |
245 | (const struct browse_folder_info*)param; | 246 | (const struct browse_folder_info*)param; |
246 | return rockbox_browse(info->dir, info->show_options); | 247 | return rockbox_browse(get_user_file_path(info->dir, 0, path, sizeof(path)), |
248 | info->show_options); | ||
247 | } | 249 | } |
248 | 250 | ||
249 | #ifdef HAVE_LCD_BITMAP | 251 | #ifdef HAVE_LCD_BITMAP |
diff --git a/apps/misc.c b/apps/misc.c index c378133ab2..39f17be298 100644 --- a/apps/misc.c +++ b/apps/misc.c | |||
@@ -742,35 +742,6 @@ char* strrsplt(char* str, int c) | |||
742 | return s; | 742 | return s; |
743 | } | 743 | } |
744 | 744 | ||
745 | /* Test file existence, using dircache of possible */ | ||
746 | bool file_exists(const char *file) | ||
747 | { | ||
748 | int fd; | ||
749 | |||
750 | if (!file || strlen(file) <= 0) | ||
751 | return false; | ||
752 | |||
753 | #ifdef HAVE_DIRCACHE | ||
754 | if (dircache_is_enabled()) | ||
755 | return (dircache_get_entry_ptr(file) != NULL); | ||
756 | #endif | ||
757 | |||
758 | fd = open(file, O_RDONLY); | ||
759 | if (fd < 0) | ||
760 | return false; | ||
761 | close(fd); | ||
762 | return true; | ||
763 | } | ||
764 | |||
765 | bool dir_exists(const char *path) | ||
766 | { | ||
767 | DIR* d = opendir(path); | ||
768 | if (!d) | ||
769 | return false; | ||
770 | closedir(d); | ||
771 | return true; | ||
772 | } | ||
773 | |||
774 | /* | 745 | /* |
775 | * removes the extension of filename (if it doesn't start with a .) | 746 | * removes the extension of filename (if it doesn't start with a .) |
776 | * puts the result in buffer | 747 | * puts the result in buffer |
diff --git a/apps/misc.h b/apps/misc.h index 58a9085d55..0de68a001c 100644 --- a/apps/misc.h +++ b/apps/misc.h | |||
@@ -84,8 +84,6 @@ int hex_to_rgb(const char* hex, int* color); | |||
84 | 84 | ||
85 | char* strrsplt(char* str, int c); | 85 | char* strrsplt(char* str, int c); |
86 | char* skip_whitespace(char* const str); | 86 | char* skip_whitespace(char* const str); |
87 | bool file_exists(const char *file); | ||
88 | bool dir_exists(const char *path); | ||
89 | 87 | ||
90 | /* | 88 | /* |
91 | * removes the extension of filename (if it doesn't start with a .) | 89 | * removes the extension of filename (if it doesn't start with a .) |
diff --git a/apps/playlist.c b/apps/playlist.c index 4a6db883f7..2896f62e76 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -86,6 +86,7 @@ | |||
86 | #include "screens.h" | 86 | #include "screens.h" |
87 | #include "buffer.h" | 87 | #include "buffer.h" |
88 | #include "misc.h" | 88 | #include "misc.h" |
89 | #include "filefuncs.h" | ||
89 | #include "button.h" | 90 | #include "button.h" |
90 | #include "filetree.h" | 91 | #include "filetree.h" |
91 | #include "abrepeat.h" | 92 | #include "abrepeat.h" |
@@ -103,7 +104,6 @@ | |||
103 | #include "rbunicode.h" | 104 | #include "rbunicode.h" |
104 | #include "root_menu.h" | 105 | #include "root_menu.h" |
105 | 106 | ||
106 | #define PLAYLIST_CONTROL_FILE ROCKBOX_DIR "/.playlist_control" | ||
107 | #define PLAYLIST_CONTROL_FILE_VERSION 2 | 107 | #define PLAYLIST_CONTROL_FILE_VERSION 2 |
108 | 108 | ||
109 | /* | 109 | /* |
@@ -1440,7 +1440,12 @@ static int get_next_dir(char *dir, bool is_forward, bool recursion) | |||
1440 | /* process random folder advance */ | 1440 | /* process random folder advance */ |
1441 | if (global_settings.next_folder == FOLDER_ADVANCE_RANDOM) | 1441 | if (global_settings.next_folder == FOLDER_ADVANCE_RANDOM) |
1442 | { | 1442 | { |
1443 | int fd = open(ROCKBOX_DIR "/folder_advance_list.dat", O_RDONLY); | 1443 | char folder_advance_list[MAX_PATH]; |
1444 | get_user_file_path(ROCKBOX_DIR, FORCE_BUFFER_COPY, | ||
1445 | folder_advance_list, sizeof(folder_advance_list)); | ||
1446 | strlcat(folder_advance_list, "/folder_advance_list.dat", | ||
1447 | sizeof(folder_advance_list)); | ||
1448 | int fd = open(folder_advance_list, O_RDONLY); | ||
1444 | if (fd >= 0) | 1449 | if (fd >= 0) |
1445 | { | 1450 | { |
1446 | char buffer[MAX_PATH]; | 1451 | char buffer[MAX_PATH]; |
@@ -1910,7 +1915,8 @@ void playlist_init(void) | |||
1910 | struct playlist_info* playlist = ¤t_playlist; | 1915 | struct playlist_info* playlist = ¤t_playlist; |
1911 | 1916 | ||
1912 | playlist->current = true; | 1917 | playlist->current = true; |
1913 | strlcpy(playlist->control_filename, PLAYLIST_CONTROL_FILE, | 1918 | get_user_file_path(PLAYLIST_CONTROL_FILE, IS_FILE|NEED_WRITE|FORCE_BUFFER_COPY, |
1919 | playlist->control_filename, | ||
1914 | sizeof(playlist->control_filename)); | 1920 | sizeof(playlist->control_filename)); |
1915 | playlist->fd = -1; | 1921 | playlist->fd = -1; |
1916 | playlist->control_fd = -1; | 1922 | playlist->control_fd = -1; |
diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c index f9a43da411..2fbffdaa3c 100644 --- a/apps/playlist_catalog.c +++ b/apps/playlist_catalog.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "lang.h" | 32 | #include "lang.h" |
33 | #include "list.h" | 33 | #include "list.h" |
34 | #include "misc.h" | 34 | #include "misc.h" |
35 | #include "filefuncs.h" | ||
35 | #include "onplay.h" | 36 | #include "onplay.h" |
36 | #include "playlist.h" | 37 | #include "playlist.h" |
37 | #include "settings.h" | 38 | #include "settings.h" |
@@ -77,8 +78,13 @@ static int initialize_catalog(void) | |||
77 | 78 | ||
78 | /* fall back to default directory if no or invalid config */ | 79 | /* fall back to default directory if no or invalid config */ |
79 | if (default_dir) | 80 | if (default_dir) |
80 | strlcpy(playlist_dir, PLAYLIST_CATALOG_DEFAULT_DIR, | 81 | { |
81 | sizeof(playlist_dir)); | 82 | const char *dir = get_user_file_path(PLAYLIST_CATALOG_DEFAULT_DIR, |
83 | FORCE_BUFFER_COPY|NEED_WRITE, | ||
84 | playlist_dir, sizeof(playlist_dir)); | ||
85 | if (!dir_exists(dir)) | ||
86 | mkdir(dir); | ||
87 | } | ||
82 | 88 | ||
83 | playlist_dir_length = strlen(playlist_dir); | 89 | playlist_dir_length = strlen(playlist_dir); |
84 | 90 | ||
diff --git a/apps/plugin.c b/apps/plugin.c index 81ba006af7..b3baea757c 100644 --- a/apps/plugin.c +++ b/apps/plugin.c | |||
@@ -41,6 +41,7 @@ | |||
41 | #include "pcmbuf.h" | 41 | #include "pcmbuf.h" |
42 | #include "errno.h" | 42 | #include "errno.h" |
43 | #include "diacritic.h" | 43 | #include "diacritic.h" |
44 | #include "filefuncs.h" | ||
44 | 45 | ||
45 | #if CONFIG_CHARGING | 46 | #if CONFIG_CHARGING |
46 | #include "power.h" | 47 | #include "power.h" |
diff --git a/apps/plugin.h b/apps/plugin.h index cf1fd77426..5ee18d0078 100644 --- a/apps/plugin.h +++ b/apps/plugin.h | |||
@@ -66,6 +66,7 @@ void* plugin_get_buffer(size_t *buffer_size); | |||
66 | #include "profile.h" | 66 | #include "profile.h" |
67 | #endif | 67 | #endif |
68 | #include "misc.h" | 68 | #include "misc.h" |
69 | #include "filefuncs.h" | ||
69 | #if (CONFIG_CODEC == SWCODEC) | 70 | #if (CONFIG_CODEC == SWCODEC) |
70 | #include "dsp.h" | 71 | #include "dsp.h" |
71 | #include "codecs.h" | 72 | #include "codecs.h" |
diff --git a/apps/radio/presets.c b/apps/radio/presets.c index aa265bcc74..e900afe734 100644 --- a/apps/radio/presets.c +++ b/apps/radio/presets.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "file.h" | 30 | #include "file.h" |
31 | #include "string-extra.h" | 31 | #include "string-extra.h" |
32 | #include "misc.h" | 32 | #include "misc.h" |
33 | #include "filefuncs.h" | ||
33 | #include "lang.h" | 34 | #include "lang.h" |
34 | #include "action.h" | 35 | #include "action.h" |
35 | #include "list.h" | 36 | #include "list.h" |
diff --git a/apps/radio/radioart.c b/apps/radio/radioart.c index 7ba9881d84..85397c16b6 100644 --- a/apps/radio/radioart.c +++ b/apps/radio/radioart.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "kernel.h" | 30 | #include "kernel.h" |
31 | #include "string-extra.h" | 31 | #include "string-extra.h" |
32 | #include "misc.h" | 32 | #include "misc.h" |
33 | #include "filefuncs.h" | ||
33 | 34 | ||
34 | #define MAX_RADIOART_IMAGES 10 | 35 | #define MAX_RADIOART_IMAGES 10 |
35 | struct radioart { | 36 | struct radioart { |
diff --git a/apps/recorder/albumart.c b/apps/recorder/albumart.c index 5eca713542..6b43576698 100644 --- a/apps/recorder/albumart.c +++ b/apps/recorder/albumart.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "buffering.h" | 26 | #include "buffering.h" |
27 | #include "dircache.h" | 27 | #include "dircache.h" |
28 | #include "misc.h" | 28 | #include "misc.h" |
29 | #include "filefuncs.h" | ||
29 | #include "settings.h" | 30 | #include "settings.h" |
30 | #include "wps.h" | 31 | #include "wps.h" |
31 | 32 | ||
diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index ab7e7c9b32..0098d6bf78 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c | |||
@@ -56,7 +56,7 @@ | |||
56 | #include "sound_menu.h" | 56 | #include "sound_menu.h" |
57 | #include "timefuncs.h" | 57 | #include "timefuncs.h" |
58 | #include "debug.h" | 58 | #include "debug.h" |
59 | #include "misc.h" | 59 | #include "filefuncs.h" |
60 | #include "tree.h" | 60 | #include "tree.h" |
61 | #include "string.h" | 61 | #include "string.h" |
62 | #include "dir.h" | 62 | #include "dir.h" |
diff --git a/apps/root_menu.c b/apps/root_menu.c index 53c522a773..7965673b67 100644 --- a/apps/root_menu.c +++ b/apps/root_menu.c | |||
@@ -341,7 +341,7 @@ static int plugins_menu(void* param) | |||
341 | MENUITEM_STRINGLIST(plugins_menu_items, ID2P(LANG_PLUGINS), NULL, | 341 | MENUITEM_STRINGLIST(plugins_menu_items, ID2P(LANG_PLUGINS), NULL, |
342 | ID2P(LANG_PLUGIN_GAMES), | 342 | ID2P(LANG_PLUGIN_GAMES), |
343 | ID2P(LANG_PLUGIN_APPS), ID2P(LANG_PLUGIN_DEMOS)); | 343 | ID2P(LANG_PLUGIN_APPS), ID2P(LANG_PLUGIN_DEMOS)); |
344 | char *folder; | 344 | const char *folder; |
345 | int retval = GO_TO_PREVIOUS; | 345 | int retval = GO_TO_PREVIOUS; |
346 | int selection = 0, current = 0; | 346 | int selection = 0, current = 0; |
347 | while (retval == GO_TO_PREVIOUS) | 347 | while (retval == GO_TO_PREVIOUS) |
@@ -646,7 +646,13 @@ void root_menu(void) | |||
646 | if ( action_userabort(HZ/5) ) | 646 | if ( action_userabort(HZ/5) ) |
647 | break; | 647 | break; |
648 | } | 648 | } |
649 | next_screen = load_plugin_screen(PLUGIN_DEMOS_DIR "/pictureflow.rock"); | 649 | { |
650 | char pf_path[MAX_PATH]; | ||
651 | snprintf(pf_path, sizeof(pf_path), | ||
652 | "%s/pictureflow.rock", | ||
653 | PLUGIN_DEMOS_DIR); | ||
654 | next_screen = load_plugin_screen(pf_path); | ||
655 | } | ||
650 | previous_browser = GO_TO_PICTUREFLOW; | 656 | previous_browser = GO_TO_PICTUREFLOW; |
651 | break; | 657 | break; |
652 | #endif | 658 | #endif |
diff --git a/apps/scrobbler.c b/apps/scrobbler.c index 8d9f694ec2..9b0decfb68 100644 --- a/apps/scrobbler.c +++ b/apps/scrobbler.c | |||
@@ -33,7 +33,7 @@ http://www.audioscrobbler.net/wiki/Portable_Player_Logging | |||
33 | #include "buffer.h" | 33 | #include "buffer.h" |
34 | #include "settings.h" | 34 | #include "settings.h" |
35 | #include "ata_idle_notify.h" | 35 | #include "ata_idle_notify.h" |
36 | #include "misc.h" | 36 | #include "filefuncs.h" |
37 | #include "appevents.h" | 37 | #include "appevents.h" |
38 | 38 | ||
39 | #if CONFIG_RTC | 39 | #if CONFIG_RTC |
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; |
diff --git a/apps/settings.h b/apps/settings.h index 63305b5ae7..7deb2def41 100644 --- a/apps/settings.h +++ b/apps/settings.h | |||
@@ -33,6 +33,7 @@ | |||
33 | #if CONFIG_CODEC == SWCODEC | 33 | #if CONFIG_CODEC == SWCODEC |
34 | #include "audio.h" | 34 | #include "audio.h" |
35 | #endif | 35 | #endif |
36 | #include "rbpaths.h" | ||
36 | 37 | ||
37 | struct opt_items { | 38 | struct opt_items { |
38 | unsigned const char* string; | 39 | unsigned const char* string; |
@@ -40,50 +41,6 @@ struct opt_items { | |||
40 | }; | 41 | }; |
41 | 42 | ||
42 | /** Setting values defines **/ | 43 | /** Setting values defines **/ |
43 | |||
44 | /* name of directory where configuration, fonts and other data | ||
45 | * files are stored */ | ||
46 | #ifdef __PCTOOL__ | ||
47 | #undef ROCKBOX_DIR | ||
48 | #undef ROCKBOX_DIR_LEN | ||
49 | #undef WPS_DIR | ||
50 | #define ROCKBOX_DIR "." | ||
51 | #define ROCKBOX_DIR_LEN 1 | ||
52 | #else | ||
53 | |||
54 | /* ROCKBOX_DIR is now defined in autoconf.h for flexible build types */ | ||
55 | #ifndef ROCKBOX_DIR | ||
56 | #error ROCKBOX_DIR not defined (should be in autoconf.h) | ||
57 | #endif | ||
58 | #define ROCKBOX_DIR_LEN (sizeof(ROCKBOX_DIR)-1) | ||
59 | #endif /* def __PCTOOL__ */ | ||
60 | |||
61 | |||
62 | #define FONT_DIR ROCKBOX_DIR "/fonts" | ||
63 | #define LANG_DIR ROCKBOX_DIR "/langs" | ||
64 | #define WPS_DIR ROCKBOX_DIR "/wps" | ||
65 | #define SBS_DIR WPS_DIR | ||
66 | #define THEME_DIR ROCKBOX_DIR "/themes" | ||
67 | #define ICON_DIR ROCKBOX_DIR "/icons" | ||
68 | |||
69 | #define PLUGIN_DIR ROCKBOX_DIR "/rocks" | ||
70 | #define PLUGIN_GAMES_DIR PLUGIN_DIR "/games" | ||
71 | #define PLUGIN_APPS_DIR PLUGIN_DIR "/apps" | ||
72 | #define PLUGIN_DEMOS_DIR PLUGIN_DIR "/demos" | ||
73 | #define VIEWERS_DIR PLUGIN_DIR "/viewers" | ||
74 | |||
75 | #define BACKDROP_DIR ROCKBOX_DIR "/backdrops" | ||
76 | #define REC_BASE_DIR "/" | ||
77 | #define EQS_DIR ROCKBOX_DIR "/eqs" | ||
78 | #define CODECS_DIR ROCKBOX_DIR "/codecs" | ||
79 | #define RECPRESETS_DIR ROCKBOX_DIR "/recpresets" | ||
80 | #define FMPRESET_PATH ROCKBOX_DIR "/fmpresets" | ||
81 | #define PLAYLIST_CATALOG_DEFAULT_DIR "/Playlists" | ||
82 | |||
83 | #define VIEWERS_CONFIG ROCKBOX_DIR "/viewers.config" | ||
84 | #define CONFIGFILE ROCKBOX_DIR "/config.cfg" | ||
85 | #define FIXEDSETTINGSFILE ROCKBOX_DIR "/fixed.cfg" | ||
86 | |||
87 | #define MAX_FILENAME 32 | 44 | #define MAX_FILENAME 32 |
88 | 45 | ||
89 | 46 | ||
diff --git a/apps/tagcache.c b/apps/tagcache.c index 1094c92a97..898263ef23 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -73,6 +73,7 @@ | |||
73 | #include "buffer.h" | 73 | #include "buffer.h" |
74 | #include "crc32.h" | 74 | #include "crc32.h" |
75 | #include "misc.h" | 75 | #include "misc.h" |
76 | #include "filefuncs.h" | ||
76 | #include "settings.h" | 77 | #include "settings.h" |
77 | #include "dir.h" | 78 | #include "dir.h" |
78 | #include "structec.h" | 79 | #include "structec.h" |
@@ -292,15 +293,17 @@ static bool is_dircache_intact(void) | |||
292 | static int open_tag_fd(struct tagcache_header *hdr, int tag, bool write) | 293 | static int open_tag_fd(struct tagcache_header *hdr, int tag, bool write) |
293 | { | 294 | { |
294 | int fd; | 295 | int fd; |
295 | char buf[MAX_PATH]; | 296 | char buf[MAX_PATH], path[MAX_PATH]; |
297 | const char * file; | ||
296 | int rc; | 298 | int rc; |
297 | 299 | ||
298 | if (TAGCACHE_IS_NUMERIC(tag) || tag < 0 || tag >= TAG_COUNT) | 300 | if (TAGCACHE_IS_NUMERIC(tag) || tag < 0 || tag >= TAG_COUNT) |
299 | return -1; | 301 | return -1; |
300 | 302 | ||
301 | snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag); | 303 | snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag); |
304 | file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path)); | ||
302 | 305 | ||
303 | fd = open(buf, write ? O_RDWR : O_RDONLY); | 306 | fd = open(file, write ? O_RDWR : O_RDONLY); |
304 | if (fd < 0) | 307 | if (fd < 0) |
305 | { | 308 | { |
306 | logf("tag file open failed: tag=%d write=%d file=%s", tag, write, buf); | 309 | logf("tag file open failed: tag=%d write=%d file=%s", tag, write, buf); |
@@ -325,8 +328,12 @@ static int open_master_fd(struct master_header *hdr, bool write) | |||
325 | { | 328 | { |
326 | int fd; | 329 | int fd; |
327 | int rc; | 330 | int rc; |
331 | char path[MAX_PATH]; | ||
328 | 332 | ||
329 | fd = open(TAGCACHE_FILE_MASTER, write ? O_RDWR : O_RDONLY); | 333 | fd = open(get_user_file_path(TAGCACHE_FILE_MASTER, |
334 | IS_FILE|NEED_WRITE, | ||
335 | path, sizeof(path)), | ||
336 | write ? O_RDWR : O_RDONLY); | ||
330 | if (fd < 0) | 337 | if (fd < 0) |
331 | { | 338 | { |
332 | logf("master file open failed for R/W"); | 339 | logf("master file open failed for R/W"); |
@@ -668,9 +675,11 @@ static bool open_files(struct tagcache_search *tcs, int tag) | |||
668 | { | 675 | { |
669 | if (tcs->idxfd[tag] < 0) | 676 | if (tcs->idxfd[tag] < 0) |
670 | { | 677 | { |
671 | char fn[MAX_PATH]; | 678 | char fn[MAX_PATH], path[MAX_PATH]; |
679 | const char *file; | ||
672 | 680 | ||
673 | snprintf(fn, sizeof fn, TAGCACHE_FILE_INDEX, tag); | 681 | snprintf(fn, sizeof fn, TAGCACHE_FILE_INDEX, tag); |
682 | file = get_user_file_path(fn, IS_FILE | NEED_WRITE, path, sizeof(path)); | ||
674 | tcs->idxfd[tag] = open(fn, O_RDONLY); | 683 | tcs->idxfd[tag] = open(fn, O_RDONLY); |
675 | } | 684 | } |
676 | 685 | ||
@@ -1159,14 +1168,17 @@ static void remove_files(void) | |||
1159 | tc_stat.ready = false; | 1168 | tc_stat.ready = false; |
1160 | tc_stat.ramcache = false; | 1169 | tc_stat.ramcache = false; |
1161 | tc_stat.econ = false; | 1170 | tc_stat.econ = false; |
1162 | remove(TAGCACHE_FILE_MASTER); | 1171 | remove(get_user_file_path(TAGCACHE_FILE_MASTER, NEED_WRITE|IS_FILE, |
1172 | buf, sizeof(buf))); | ||
1163 | for (i = 0; i < TAG_COUNT; i++) | 1173 | for (i = 0; i < TAG_COUNT; i++) |
1164 | { | 1174 | { |
1175 | char buf2[MAX_PATH]; | ||
1165 | if (TAGCACHE_IS_NUMERIC(i)) | 1176 | if (TAGCACHE_IS_NUMERIC(i)) |
1166 | continue; | 1177 | continue; |
1167 | 1178 | ||
1179 | /* database_%d.tcd -> database_0.tcd */ | ||
1168 | snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, i); | 1180 | snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, i); |
1169 | remove(buf); | 1181 | remove(get_user_file_path(buf, NEED_WRITE | IS_FILE, buf2, sizeof(buf2))); |
1170 | } | 1182 | } |
1171 | } | 1183 | } |
1172 | 1184 | ||
@@ -1317,10 +1329,11 @@ bool tagcache_search_add_clause(struct tagcache_search *tcs, | |||
1317 | 1329 | ||
1318 | if (!TAGCACHE_IS_NUMERIC(clause->tag) && tcs->idxfd[clause->tag] < 0) | 1330 | if (!TAGCACHE_IS_NUMERIC(clause->tag) && tcs->idxfd[clause->tag] < 0) |
1319 | { | 1331 | { |
1320 | char buf[MAX_PATH]; | 1332 | char buf[MAX_PATH], path[MAX_PATH]; |
1321 | 1333 | const char *file; | |
1322 | snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, clause->tag); | 1334 | snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, clause->tag); |
1323 | tcs->idxfd[clause->tag] = open(buf, O_RDONLY); | 1335 | file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path)); |
1336 | tcs->idxfd[clause->tag] = open(file, O_RDONLY); | ||
1324 | } | 1337 | } |
1325 | 1338 | ||
1326 | tcs->clause[tcs->clause_count] = clause; | 1339 | tcs->clause[tcs->clause_count] = clause; |
@@ -2344,7 +2357,8 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) | |||
2344 | struct master_header tcmh; | 2357 | struct master_header tcmh; |
2345 | struct index_entry idxbuf[IDX_BUF_DEPTH]; | 2358 | struct index_entry idxbuf[IDX_BUF_DEPTH]; |
2346 | int idxbuf_pos; | 2359 | int idxbuf_pos; |
2347 | char buf[TAG_MAXLEN+32]; | 2360 | char buf[TAG_MAXLEN+32], path[MAX_PATH]; |
2361 | const char *file; | ||
2348 | int fd = -1, masterfd; | 2362 | int fd = -1, masterfd; |
2349 | bool error = false; | 2363 | bool error = false; |
2350 | int init; | 2364 | int init; |
@@ -2492,7 +2506,8 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) | |||
2492 | * anything whether the index type is sorted or not. | 2506 | * anything whether the index type is sorted or not. |
2493 | */ | 2507 | */ |
2494 | snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, index_type); | 2508 | snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, index_type); |
2495 | fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0666); | 2509 | file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path)); |
2510 | fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); | ||
2496 | if (fd < 0) | 2511 | if (fd < 0) |
2497 | { | 2512 | { |
2498 | logf("%s open fail", buf); | 2513 | logf("%s open fail", buf); |
@@ -2512,18 +2527,21 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) | |||
2512 | } | 2527 | } |
2513 | } | 2528 | } |
2514 | 2529 | ||
2530 | file = get_user_file_path(TAGCACHE_FILE_MASTER, | ||
2531 | IS_FILE|NEED_WRITE, | ||
2532 | buf, sizeof(buf)); | ||
2515 | /* Loading the tag lookup file as "master file". */ | 2533 | /* Loading the tag lookup file as "master file". */ |
2516 | logf("Loading index file"); | 2534 | logf("Loading index file"); |
2517 | masterfd = open(TAGCACHE_FILE_MASTER, O_RDWR); | 2535 | masterfd = open(file, O_RDWR); |
2518 | 2536 | ||
2519 | if (masterfd < 0) | 2537 | if (masterfd < 0) |
2520 | { | 2538 | { |
2521 | logf("Creating new DB"); | 2539 | logf("Creating new DB"); |
2522 | masterfd = open(TAGCACHE_FILE_MASTER, O_WRONLY | O_CREAT | O_TRUNC, 0666); | 2540 | masterfd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
2523 | 2541 | ||
2524 | if (masterfd < 0) | 2542 | if (masterfd < 0) |
2525 | { | 2543 | { |
2526 | logf("Failure to create index file (%s)", TAGCACHE_FILE_MASTER); | 2544 | logf("Failure to create index file (%s)", file); |
2527 | close(fd); | 2545 | close(fd); |
2528 | return -2; | 2546 | return -2; |
2529 | } | 2547 | } |
@@ -2831,6 +2849,8 @@ static bool commit(void) | |||
2831 | { | 2849 | { |
2832 | struct tagcache_header tch; | 2850 | struct tagcache_header tch; |
2833 | struct master_header tcmh; | 2851 | struct master_header tcmh; |
2852 | char path[MAX_PATH]; | ||
2853 | const char *file; | ||
2834 | int i, len, rc; | 2854 | int i, len, rc; |
2835 | int tmpfd; | 2855 | int tmpfd; |
2836 | int masterfd; | 2856 | int masterfd; |
@@ -2844,7 +2864,10 @@ static bool commit(void) | |||
2844 | while (write_lock) | 2864 | while (write_lock) |
2845 | sleep(1); | 2865 | sleep(1); |
2846 | 2866 | ||
2847 | tmpfd = open(TAGCACHE_FILE_TEMP, O_RDONLY); | 2867 | file = get_user_file_path(TAGCACHE_FILE_TEMP, |
2868 | IS_FILE|NEED_WRITE, path, sizeof(path)); | ||
2869 | |||
2870 | tmpfd = open(file, O_RDONLY); | ||
2848 | if (tmpfd < 0) | 2871 | if (tmpfd < 0) |
2849 | { | 2872 | { |
2850 | logf("nothing to commit"); | 2873 | logf("nothing to commit"); |
@@ -2860,7 +2883,7 @@ static bool commit(void) | |||
2860 | { | 2883 | { |
2861 | logf("incorrect tmpheader"); | 2884 | logf("incorrect tmpheader"); |
2862 | close(tmpfd); | 2885 | close(tmpfd); |
2863 | remove(TAGCACHE_FILE_TEMP); | 2886 | remove(file); |
2864 | return false; | 2887 | return false; |
2865 | } | 2888 | } |
2866 | 2889 | ||
@@ -2868,7 +2891,7 @@ static bool commit(void) | |||
2868 | { | 2891 | { |
2869 | logf("nothing to commit"); | 2892 | logf("nothing to commit"); |
2870 | close(tmpfd); | 2893 | close(tmpfd); |
2871 | remove(TAGCACHE_FILE_TEMP); | 2894 | remove(file); |
2872 | return true; | 2895 | return true; |
2873 | } | 2896 | } |
2874 | 2897 | ||
@@ -2876,7 +2899,8 @@ static bool commit(void) | |||
2876 | tc_stat.ready = check_all_headers(); | 2899 | tc_stat.ready = check_all_headers(); |
2877 | 2900 | ||
2878 | #ifdef HAVE_EEPROM_SETTINGS | 2901 | #ifdef HAVE_EEPROM_SETTINGS |
2879 | remove(TAGCACHE_STATEFILE); | 2902 | remove(get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, |
2903 | path, sizeof(path))); | ||
2880 | #endif | 2904 | #endif |
2881 | 2905 | ||
2882 | /* At first be sure to unload the ramcache! */ | 2906 | /* At first be sure to unload the ramcache! */ |
@@ -2966,7 +2990,7 @@ static bool commit(void) | |||
2966 | } | 2990 | } |
2967 | 2991 | ||
2968 | close(tmpfd); | 2992 | close(tmpfd); |
2969 | remove(TAGCACHE_FILE_TEMP); | 2993 | remove(file); |
2970 | 2994 | ||
2971 | tc_stat.commit_step = 0; | 2995 | tc_stat.commit_step = 0; |
2972 | 2996 | ||
@@ -3386,15 +3410,18 @@ bool tagcache_import_changelog(void) | |||
3386 | struct tagcache_header tch; | 3410 | struct tagcache_header tch; |
3387 | int clfd; | 3411 | int clfd; |
3388 | long masterfd; | 3412 | long masterfd; |
3389 | char buf[2048]; | 3413 | char buf[MAX(MAX_PATH, 2048)]; |
3414 | const char *file; | ||
3390 | 3415 | ||
3391 | if (!tc_stat.ready) | 3416 | if (!tc_stat.ready) |
3392 | return false; | 3417 | return false; |
3393 | 3418 | ||
3394 | while (read_lock) | 3419 | while (read_lock) |
3395 | sleep(1); | 3420 | sleep(1); |
3396 | 3421 | ||
3397 | clfd = open(TAGCACHE_FILE_CHANGELOG, O_RDONLY); | 3422 | file = get_user_file_path(TAGCACHE_FILE_CHANGELOG, |
3423 | IS_FILE|NEED_WRITE, buf, sizeof(buf)); | ||
3424 | clfd = open(file, O_RDONLY); | ||
3398 | if (clfd < 0) | 3425 | if (clfd < 0) |
3399 | { | 3426 | { |
3400 | logf("failure to open changelog"); | 3427 | logf("failure to open changelog"); |
@@ -3436,7 +3463,8 @@ bool tagcache_create_changelog(struct tagcache_search *tcs) | |||
3436 | { | 3463 | { |
3437 | struct master_header myhdr; | 3464 | struct master_header myhdr; |
3438 | struct index_entry idx; | 3465 | struct index_entry idx; |
3439 | char buf[TAG_MAXLEN+32]; | 3466 | const char *file; |
3467 | char buf[MAX(TAG_MAXLEN+32, MAX_PATH)]; | ||
3440 | char temp[32]; | 3468 | char temp[32]; |
3441 | int clfd; | 3469 | int clfd; |
3442 | int i, j; | 3470 | int i, j; |
@@ -3448,7 +3476,9 @@ bool tagcache_create_changelog(struct tagcache_search *tcs) | |||
3448 | return false; | 3476 | return false; |
3449 | 3477 | ||
3450 | /* Initialize the changelog */ | 3478 | /* Initialize the changelog */ |
3451 | clfd = open(TAGCACHE_FILE_CHANGELOG, O_WRONLY | O_CREAT | O_TRUNC, 0666); | 3479 | file = get_user_file_path(TAGCACHE_FILE_CHANGELOG, IS_FILE | NEED_WRITE, |
3480 | buf, sizeof(buf)); | ||
3481 | clfd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); | ||
3452 | if (clfd < 0) | 3482 | if (clfd < 0) |
3453 | { | 3483 | { |
3454 | logf("failure to open changelog"); | 3484 | logf("failure to open changelog"); |
@@ -3766,11 +3796,15 @@ static bool allocate_tagcache(void) | |||
3766 | static bool tagcache_dumpload(void) | 3796 | static bool tagcache_dumpload(void) |
3767 | { | 3797 | { |
3768 | struct statefile_header shdr; | 3798 | struct statefile_header shdr; |
3799 | char path[MAX_PATH]; | ||
3800 | const char *file; | ||
3769 | int fd, rc; | 3801 | int fd, rc; |
3770 | long offpos; | 3802 | long offpos; |
3771 | int i; | 3803 | int i; |
3772 | 3804 | ||
3773 | fd = open(TAGCACHE_STATEFILE, O_RDONLY); | 3805 | file = get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, |
3806 | path, sizeof(path)); | ||
3807 | fd = open(file, O_RDONLY); | ||
3774 | if (fd < 0) | 3808 | if (fd < 0) |
3775 | { | 3809 | { |
3776 | logf("no tagcache statedump"); | 3810 | logf("no tagcache statedump"); |
@@ -3816,12 +3850,16 @@ static bool tagcache_dumpload(void) | |||
3816 | static bool tagcache_dumpsave(void) | 3850 | static bool tagcache_dumpsave(void) |
3817 | { | 3851 | { |
3818 | struct statefile_header shdr; | 3852 | struct statefile_header shdr; |
3853 | char path[MAX_PATH]; | ||
3854 | const char *file; | ||
3819 | int fd; | 3855 | int fd; |
3820 | 3856 | ||
3821 | if (!tc_stat.ramcache) | 3857 | if (!tc_stat.ramcache) |
3822 | return false; | 3858 | return false; |
3823 | 3859 | ||
3824 | fd = open(TAGCACHE_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC, 0666); | 3860 | file = get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, |
3861 | path, sizeof(path)); | ||
3862 | fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); | ||
3825 | if (fd < 0) | 3863 | if (fd < 0) |
3826 | { | 3864 | { |
3827 | logf("failed to create a statedump"); | 3865 | logf("failed to create a statedump"); |
@@ -3847,7 +3885,8 @@ static bool load_tagcache(void) | |||
3847 | long bytesleft = tc_stat.ramcache_allocated; | 3885 | long bytesleft = tc_stat.ramcache_allocated; |
3848 | struct index_entry *idx; | 3886 | struct index_entry *idx; |
3849 | int rc, fd; | 3887 | int rc, fd; |
3850 | char *p; | 3888 | char *p, path[MAX_PATH]; |
3889 | const char *file; | ||
3851 | int i, tag; | 3890 | int i, tag; |
3852 | 3891 | ||
3853 | # ifdef HAVE_DIRCACHE | 3892 | # ifdef HAVE_DIRCACHE |
@@ -3858,8 +3897,11 @@ static bool load_tagcache(void) | |||
3858 | # endif | 3897 | # endif |
3859 | 3898 | ||
3860 | logf("loading tagcache to ram..."); | 3899 | logf("loading tagcache to ram..."); |
3861 | 3900 | ||
3862 | fd = open(TAGCACHE_FILE_MASTER, O_RDONLY); | 3901 | file = get_user_file_path(TAGCACHE_FILE_MASTER, |
3902 | IS_FILE|NEED_WRITE, | ||
3903 | path, sizeof(path)); | ||
3904 | fd = open(file, O_RDONLY); | ||
3863 | if (fd < 0) | 3905 | if (fd < 0) |
3864 | { | 3906 | { |
3865 | logf("tagcache open failed"); | 3907 | logf("tagcache open failed"); |
@@ -4069,12 +4111,14 @@ static bool load_tagcache(void) | |||
4069 | static bool check_deleted_files(void) | 4111 | static bool check_deleted_files(void) |
4070 | { | 4112 | { |
4071 | int fd; | 4113 | int fd; |
4072 | char buf[TAG_MAXLEN+32]; | 4114 | char buf[TAG_MAXLEN+32], path[MAX_PATH]; |
4115 | const char *file; | ||
4073 | struct tagfile_entry tfe; | 4116 | struct tagfile_entry tfe; |
4074 | 4117 | ||
4075 | logf("reverse scan..."); | 4118 | logf("reverse scan..."); |
4076 | snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag_filename); | 4119 | snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag_filename); |
4077 | fd = open(buf, O_RDONLY); | 4120 | file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path)); |
4121 | fd = open(file, O_RDONLY); | ||
4078 | 4122 | ||
4079 | if (fd < 0) | 4123 | if (fd < 0) |
4080 | { | 4124 | { |
@@ -4232,6 +4276,8 @@ void tagcache_build(const char *path) | |||
4232 | { | 4276 | { |
4233 | struct tagcache_header header; | 4277 | struct tagcache_header header; |
4234 | bool ret; | 4278 | bool ret; |
4279 | char buf[MAX_PATH]; | ||
4280 | const char *file; | ||
4235 | 4281 | ||
4236 | curpath[0] = '\0'; | 4282 | curpath[0] = '\0'; |
4237 | data_size = 0; | 4283 | data_size = 0; |
@@ -4244,19 +4290,21 @@ void tagcache_build(const char *path) | |||
4244 | #endif | 4290 | #endif |
4245 | 4291 | ||
4246 | logf("updating tagcache"); | 4292 | logf("updating tagcache"); |
4293 | |||
4294 | file = get_user_file_path(TAGCACHE_FILE_TEMP, | ||
4295 | IS_FILE|NEED_WRITE, buf, sizeof(buf)); | ||
4247 | 4296 | ||
4248 | cachefd = open(TAGCACHE_FILE_TEMP, O_RDONLY); | 4297 | |
4249 | if (cachefd >= 0) | 4298 | if (file_exists(file)) |
4250 | { | 4299 | { |
4251 | logf("skipping, cache already waiting for commit"); | 4300 | logf("skipping, cache already waiting for commit"); |
4252 | close(cachefd); | ||
4253 | return ; | 4301 | return ; |
4254 | } | 4302 | } |
4255 | 4303 | ||
4256 | cachefd = open(TAGCACHE_FILE_TEMP, O_RDWR | O_CREAT | O_TRUNC, 0666); | 4304 | cachefd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0666); |
4257 | if (cachefd < 0) | 4305 | if (cachefd < 0) |
4258 | { | 4306 | { |
4259 | logf("master file open failed: %s", TAGCACHE_FILE_TEMP); | 4307 | logf("master file open failed: %s", file); |
4260 | return ; | 4308 | return ; |
4261 | } | 4309 | } |
4262 | 4310 | ||
@@ -4300,7 +4348,7 @@ void tagcache_build(const char *path) | |||
4300 | #endif | 4348 | #endif |
4301 | if (commit()) | 4349 | if (commit()) |
4302 | { | 4350 | { |
4303 | remove(TAGCACHE_FILE_TEMP); | 4351 | remove(file); |
4304 | logf("tagcache built!"); | 4352 | logf("tagcache built!"); |
4305 | } | 4353 | } |
4306 | #ifdef __PCTOOL__ | 4354 | #ifdef __PCTOOL__ |
@@ -4345,7 +4393,12 @@ void tagcache_unload_ramcache(void) | |||
4345 | { | 4393 | { |
4346 | tc_stat.ramcache = false; | 4394 | tc_stat.ramcache = false; |
4347 | /* Just to make sure there is no statefile present. */ | 4395 | /* Just to make sure there is no statefile present. */ |
4348 | // remove(TAGCACHE_STATEFILE); | 4396 | |
4397 | #if 0 | ||
4398 | char path[MAX_PATH]; | ||
4399 | remove(get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, | ||
4400 | path, sizeof(path))); | ||
4401 | #endif | ||
4349 | } | 4402 | } |
4350 | #endif | 4403 | #endif |
4351 | 4404 | ||
@@ -4354,6 +4407,7 @@ static void tagcache_thread(void) | |||
4354 | { | 4407 | { |
4355 | struct queue_event ev; | 4408 | struct queue_event ev; |
4356 | bool check_done = false; | 4409 | bool check_done = false; |
4410 | char path[MAX_PATH]; | ||
4357 | 4411 | ||
4358 | /* If the previous cache build/update was interrupted, commit | 4412 | /* If the previous cache build/update was interrupted, commit |
4359 | * the changes first in foreground. */ | 4413 | * the changes first in foreground. */ |
@@ -4370,7 +4424,8 @@ static void tagcache_thread(void) | |||
4370 | check_done = tagcache_dumpload(); | 4424 | check_done = tagcache_dumpload(); |
4371 | } | 4425 | } |
4372 | 4426 | ||
4373 | remove(TAGCACHE_STATEFILE); | 4427 | remove(get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, |
4428 | buf, sizeof(buf))); | ||
4374 | # endif | 4429 | # endif |
4375 | 4430 | ||
4376 | /* Allocate space for the tagcache if found on disk. */ | 4431 | /* Allocate space for the tagcache if found on disk. */ |
@@ -4403,7 +4458,8 @@ static void tagcache_thread(void) | |||
4403 | 4458 | ||
4404 | case Q_REBUILD: | 4459 | case Q_REBUILD: |
4405 | remove_files(); | 4460 | remove_files(); |
4406 | remove(TAGCACHE_FILE_TEMP); | 4461 | remove(get_user_file_path(TAGCACHE_FILE_TEMP, |
4462 | IS_FILE|NEED_WRITE, path, sizeof(path))); | ||
4407 | tagcache_build("/"); | 4463 | tagcache_build("/"); |
4408 | break; | 4464 | break; |
4409 | 4465 | ||
diff --git a/apps/tree.c b/apps/tree.c index d63ddd448c..ed8e4d20bd 100644 --- a/apps/tree.c +++ b/apps/tree.c | |||
@@ -52,6 +52,7 @@ | |||
52 | #include "talk.h" | 52 | #include "talk.h" |
53 | #include "filetypes.h" | 53 | #include "filetypes.h" |
54 | #include "misc.h" | 54 | #include "misc.h" |
55 | #include "filefuncs.h" | ||
55 | #include "filetree.h" | 56 | #include "filetree.h" |
56 | #include "tagtree.h" | 57 | #include "tagtree.h" |
57 | #ifdef HAVE_RECORDING | 58 | #ifdef HAVE_RECORDING |
@@ -260,7 +261,8 @@ static int tree_voice_cb(int selected_item, void * data) | |||
260 | 261 | ||
261 | bool check_rockboxdir(void) | 262 | bool check_rockboxdir(void) |
262 | { | 263 | { |
263 | if(!dir_exists(ROCKBOX_DIR)) | 264 | char path[MAX_PATH]; |
265 | if(!dir_exists(get_user_file_path(ROCKBOX_DIR, 0, path, sizeof(path)))) | ||
264 | { /* No need to localise this message. | 266 | { /* No need to localise this message. |
265 | If .rockbox is missing, it wouldn't work anyway */ | 267 | If .rockbox is missing, it wouldn't work anyway */ |
266 | int i; | 268 | int i; |