diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java index 1416886..26b6d7e 100644 --- a/android/src/org/rockbox/RockboxService.java +++ b/android/src/org/rockbox/RockboxService.java @@ -128,12 +128,12 @@ public class RockboxService extends Service BufferedOutputStream dest = null; BufferedInputStream is = null; ZipEntry entry; - File file = new File("/data/data/org.rockbox/" + - "lib/libmisc.so"); + String base = "/data/data/org.rockbox/"; + File file = new File("/data/data/org.rockbox/lib/libmisc.so"); /* use arbitary file to determine whether extracting is needed */ File file2 = new File("/data/data/org.rockbox/" + - "app_rockbox/rockbox/codecs/mpa.codec"); - if (!file2.exists() || (file.lastModified() > file2.lastModified())) + ".rockbox/codecs/mpa.codec"); + if (!file2.exists() || (file.lastModified() > file2.lastModified())*/) { ZipFile zipfile = new ZipFile(file); Enumeration e = zipfile.entries(); @@ -144,8 +144,7 @@ public class RockboxService extends Service LOG("Extracting: " +entry); if (entry.isDirectory()) { - folder = new File(entry.getName()); - LOG("mkdir "+ entry); + folder = new File(base + entry.getName()); try { folder.mkdirs(); } catch (SecurityException ex) { @@ -157,11 +156,11 @@ public class RockboxService extends Service BUFFER); int count; byte data[] = new byte[BUFFER]; - folder = new File(new File(entry.getName()).getParent()); + folder = new File(new File(base + entry.getName()).getParent()); LOG("" + folder.getAbsolutePath()); if (!folder.exists()) folder.mkdirs(); - FileOutputStream fos = new FileOutputStream(entry.getName()); + FileOutputStream fos = new FileOutputStream(base + entry.getName()); dest = new BufferedOutputStream(fos, BUFFER); while ((count = is.read(data, 0, BUFFER)) != -1) dest.write(data, 0, count); diff --git a/apps/filetypes.c b/apps/filetypes.c index 28a2da6..0e0cbd8 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c @@ -182,15 +182,14 @@ static void read_config(const char* config_file); * load a colors file from a theme with: * filetype colours: filename.colours */ void read_color_theme_file(void) { - char buffer[MAX_PATH], dir[MAX_PATH]; + char buffer[MAX_PATH]; int fd; char *ext, *color; int i; for (i = 0; i < MAX_FILETYPES+1; i++) { custom_colors[i] = -1; } - snprintf(buffer, MAX_PATH, "%s/%s.colours", - get_user_file_path(THEME_DIR, 0, dir, sizeof(dir)), + snprintf(buffer, MAX_PATH, THEME_DIR "/%s.colours", global_settings.colors_file); fd = open(buffer, O_RDONLY); if (fd < 0) @@ -273,7 +272,6 @@ void read_viewer_theme_file(void) void filetype_init(void) { - char path[MAX_PATH]; /* set the directory item first */ filetypes[0].extension = NULL; filetypes[0].plugin = NULL; @@ -282,7 +280,7 @@ void filetype_init(void) filetype_count = 1; read_builtin_types(); - read_config(get_user_file_path(VIEWERS_CONFIG, IS_FILE, path, sizeof(path))); + read_config(VIEWERS_CONFIG); #ifdef HAVE_LCD_BITMAP read_viewer_theme_file(); #endif diff --git a/apps/gui/icon.c b/apps/gui/icon.c index b0e1ba9..43dea63 100644 --- a/apps/gui/icon.c +++ b/apps/gui/icon.c @@ -238,7 +238,7 @@ static void load_icons(const char* filename, enum Iconset iconset) { char path[MAX_PATH]; - snprintf(path, sizeof(path), "%s/%s.bmp", ICON_DIR, filename); + snprintf(path, sizeof(path), ICON_DIR "/%s.bmp", filename); size_read = read_bmp_file(path, bmp, IMG_BUFSIZE, bmpformat, NULL); if (size_read > 0) { diff --git a/apps/gui/skin_engine/skin_backdrops.c b/apps/gui/skin_engine/skin_backdrops.c index e337774..3e04bea 100644 --- a/apps/gui/skin_engine/skin_backdrops.c +++ b/apps/gui/skin_engine/skin_backdrops.c @@ -54,7 +54,6 @@ void skin_backdrop_init(void) int skin_backdrop_assign(char* backdrop, char *bmpdir, enum screen_type screen) { - char dir[MAX_PATH]; char filename[MAX_PATH]; int i, free = -1; if (!backdrop) @@ -68,8 +67,7 @@ int skin_backdrop_assign(char* backdrop, char *bmpdir, } else { - const char *bd_dir = get_user_file_path(bmpdir, 0, dir, sizeof(dir)); - get_image_filename(backdrop, bd_dir, filename, sizeof(filename)); + get_image_filename(backdrop, bmpdir, filename, sizeof(filename)); } for (i=0; idir, 0, path, sizeof(path)), - info->show_options); + return rockbox_browse(info->dir, info->show_options); } #ifdef HAVE_LCD_BITMAP diff --git a/apps/playlist.c b/apps/playlist.c index a50dac6..6e4ae18 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -1439,12 +1439,7 @@ static int get_next_dir(char *dir, bool is_forward, bool recursion) /* process random folder advance */ if (global_settings.next_folder == FOLDER_ADVANCE_RANDOM) { - char folder_advance_list[MAX_PATH]; - get_user_file_path(ROCKBOX_DIR, FORCE_BUFFER_COPY, - folder_advance_list, sizeof(folder_advance_list)); - strlcat(folder_advance_list, "/folder_advance_list.dat", - sizeof(folder_advance_list)); - int fd = open(folder_advance_list, O_RDONLY); + int fd = open(ROCKBOX_DIR "/folder_advance_list.dat", O_RDONLY); if (fd >= 0) { char buffer[MAX_PATH]; @@ -1914,8 +1909,7 @@ void playlist_init(void) struct playlist_info* playlist = ¤t_playlist; playlist->current = true; - get_user_file_path(PLAYLIST_CONTROL_FILE, IS_FILE|NEED_WRITE|FORCE_BUFFER_COPY, - playlist->control_filename, + strlcpy(playlist->control_filename, PLAYLIST_CONTROL_FILE, sizeof(playlist->control_filename)); playlist->fd = -1; playlist->control_fd = -1; diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c index 5f9f467..ff69b28 100644 --- a/apps/playlist_catalog.c +++ b/apps/playlist_catalog.c @@ -81,11 +81,9 @@ static int initialize_catalog(void) /* fall back to default directory if no or invalid config */ if (default_dir) { - const char *dir = get_user_file_path(PLAYLIST_CATALOG_DEFAULT_DIR, - FORCE_BUFFER_COPY|NEED_WRITE, - playlist_dir, sizeof(playlist_dir)); - if (!dir_exists(dir)) - mkdir(dir); + strcpy(playlist_dir, PLAYLIST_CATALOG_DEFAULT_DIR); + if (!dir_exists(playlist_dir)) + mkdir(playlist_dir); } playlist_dir_length = strlen(playlist_dir); diff --git a/apps/settings.c b/apps/settings.c index 85b0489..848c7c1 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -118,9 +118,7 @@ static bool read_nvram_data(char* buf, int max_len) unsigned crc32 = 0xffffffff; int var_count = 0, i = 0, buf_pos = 0; #ifndef HAVE_RTC_RAM - char path[MAX_PATH]; - int fd = open(get_user_file_path(NVRAM_FILE, IS_FILE|NEED_WRITE, - path, sizeof(path)), O_RDONLY); + int fd = open(NVRAM_FILE, O_RDONLY); int bytes; if (fd < 0) return false; @@ -174,7 +172,6 @@ static bool write_nvram_data(char* buf, int max_len) char var_count = 0; #ifndef HAVE_RTC_RAM int fd; - char path[MAX_PATH]; #endif memset(buf,0,max_len); /* magic, version */ @@ -198,8 +195,7 @@ static bool write_nvram_data(char* buf, int max_len) max_len-NVRAM_DATA_START-1,0xffffffff); memcpy(&buf[4],&crc32,4); #ifndef HAVE_RTC_RAM - fd = open(get_user_file_path(NVRAM_FILE, IS_FILE|NEED_WRITE, - path, sizeof(path)),O_CREAT|O_TRUNC|O_WRONLY, 0666); + fd = open(NVRAM_FILE,O_CREAT|O_TRUNC|O_WRONLY, 0666); if (fd >= 0) { int len = write(fd,buf,max_len); @@ -230,12 +226,8 @@ void settings_load(int which) read_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); if (which&SETTINGS_HD) { - const char *file; - char path[MAX_PATH]; - file = get_user_file_path(CONFIGFILE, IS_FILE|NEED_WRITE, path, sizeof(path)); - settings_load_config(file, false); - file = get_user_file_path(FIXEDSETTINGSFILE, IS_FILE, path, sizeof(path)); - settings_load_config(file, false); + settings_load_config(CONFIGFILE, false); + settings_load_config(FIXEDSETTINGSFILE, false); } } @@ -596,11 +588,8 @@ static void flush_global_status_callback(void *data) static void flush_config_block_callback(void *data) { (void)data; - char path[MAX_PATH]; write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); - settings_write_config( - get_user_file_path(CONFIGFILE, IS_FILE|NEED_WRITE, path, sizeof(path)), - SETTINGS_SAVE_CHANGED); + settings_write_config(CONFIGFILE, SETTINGS_SAVE_CHANGED); } /* @@ -644,7 +633,7 @@ int settings_save(void) bool settings_save_config(int options) { - char filename[MAX_PATH], path[MAX_PATH]; + char filename[MAX_PATH]; const char *folder, *namebase; switch (options) { @@ -673,8 +662,6 @@ bool settings_save_config(int options) namebase = "config"; break; } - - folder = get_user_file_path(folder, NEED_WRITE, path, sizeof(path)); create_numbered_filename(filename, folder, namebase, ".cfg", 2 IF_CNFN_NUM_(, NULL)); @@ -884,13 +871,11 @@ void settings_apply(bool read_disk) { char buf[MAX_PATH]; #ifdef HAVE_LCD_BITMAP - char dir[MAX_PATH]; - const char *font_path = get_user_file_path(FONT_DIR, 0, dir, sizeof(dir)); /* fonts need to be loaded before the WPS */ if (global_settings.font_file[0] && global_settings.font_file[0] != '-') { - snprintf(buf, sizeof buf, "%s/%s.fnt", font_path, + snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", global_settings.font_file); CHART2(">font_load ", global_settings.font_file); rc = font_load(NULL, buf); @@ -903,7 +888,7 @@ void settings_apply(bool read_disk) #ifdef HAVE_REMOTE_LCD if ( global_settings.remote_font_file[0] && global_settings.remote_font_file[0] != '-') { - snprintf(buf, sizeof buf, "%s/%s.fnt", font_path, + snprintf(buf, sizeof buf, FONT_DIR "%s.fnt", global_settings.remote_font_file); CHART2(">font_load_remoteui ", global_settings.remote_font_file); rc = font_load_remoteui(buf); @@ -915,8 +900,7 @@ void settings_apply(bool read_disk) font_load_remoteui(NULL); #endif if ( global_settings.kbd_file[0]) { - snprintf(buf, sizeof buf, "%s/%s.kbd", - get_user_file_path(ROCKBOX_DIR, 0, dir, sizeof(dir)), + snprintf(buf, sizeof buf, ROCKBOX_DIR "/%s.kbd", global_settings.kbd_file); CHART(">load_kbd"); load_kbd(buf); @@ -925,8 +909,6 @@ void settings_apply(bool read_disk) else load_kbd(NULL); #endif /* HAVE_LCD_BITMAP */ - /* no get_user_file_path() here because we don't really support - * langs that don't come with rockbox */ if ( global_settings.lang_file[0]) { snprintf(buf, sizeof buf, LANG_DIR "/%s.lng", global_settings.lang_file); diff --git a/apps/tagcache.c b/apps/tagcache.c index 39ed99f..e0b7608 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -73,9 +73,9 @@ #include "buffer.h" #include "crc32.h" #include "misc.h" -#include "filefuncs.h" #include "settings.h" #include "dir.h" +#include "filefuncs.h" #include "structec.h" #ifndef __PCTOOL__ @@ -293,17 +293,15 @@ static bool is_dircache_intact(void) static int open_tag_fd(struct tagcache_header *hdr, int tag, bool write) { int fd; - char buf[MAX_PATH], path[MAX_PATH]; - const char * file; + char buf[MAX_PATH]; int rc; if (TAGCACHE_IS_NUMERIC(tag) || tag < 0 || tag >= TAG_COUNT) return -1; snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag); - file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path)); - fd = open(file, write ? O_RDWR : O_RDONLY); + fd = open(buf, write ? O_RDWR : O_RDONLY); if (fd < 0) { logf("tag file open failed: tag=%d write=%d file=%s", tag, write, buf); @@ -328,12 +326,8 @@ static int open_master_fd(struct master_header *hdr, bool write) { int fd; int rc; - char path[MAX_PATH]; - fd = open(get_user_file_path(TAGCACHE_FILE_MASTER, - IS_FILE|NEED_WRITE, - path, sizeof(path)), - write ? O_RDWR : O_RDONLY); + fd = open(TAGCACHE_FILE_MASTER, write ? O_RDWR : O_RDONLY); if (fd < 0) { logf("master file open failed for R/W"); @@ -675,12 +669,10 @@ static bool open_files(struct tagcache_search *tcs, int tag) { if (tcs->idxfd[tag] < 0) { - char fn[MAX_PATH], path[MAX_PATH]; - const char *file; + char fn[MAX_PATH]; snprintf(fn, sizeof fn, TAGCACHE_FILE_INDEX, tag); - file = get_user_file_path(fn, IS_FILE | NEED_WRITE, path, sizeof(path)); - tcs->idxfd[tag] = open(file, O_RDONLY); + tcs->idxfd[tag] = open(fn, O_RDONLY); } if (tcs->idxfd[tag] < 0) @@ -1168,17 +1160,14 @@ static void remove_files(void) tc_stat.ready = false; tc_stat.ramcache = false; tc_stat.econ = false; - remove(get_user_file_path(TAGCACHE_FILE_MASTER, NEED_WRITE|IS_FILE, - buf, sizeof(buf))); + remove(TAGCACHE_FILE_MASTER); for (i = 0; i < TAG_COUNT; i++) { - char buf2[MAX_PATH]; if (TAGCACHE_IS_NUMERIC(i)) continue; - - /* database_%d.tcd -> database_0.tcd */ + snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, i); - remove(get_user_file_path(buf, NEED_WRITE | IS_FILE, buf2, sizeof(buf2))); + remove(buf); } } @@ -1329,11 +1318,10 @@ bool tagcache_search_add_clause(struct tagcache_search *tcs, if (!TAGCACHE_IS_NUMERIC(clause->tag) && tcs->idxfd[clause->tag] < 0) { - char buf[MAX_PATH], path[MAX_PATH]; - const char *file; - snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, clause->tag); - file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path)); - tcs->idxfd[clause->tag] = open(file, O_RDONLY); + char buf[MAX_PATH]; + + snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, clause->tag); + tcs->idxfd[clause->tag] = open(buf, O_RDONLY); } tcs->clause[tcs->clause_count] = clause; @@ -2357,8 +2345,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) struct master_header tcmh; struct index_entry idxbuf[IDX_BUF_DEPTH]; int idxbuf_pos; - char buf[TAG_MAXLEN+32], path[MAX_PATH]; - const char *file; + char buf[TAG_MAXLEN+32]; int fd = -1, masterfd; bool error = false; int init; @@ -2506,8 +2493,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) * anything whether the index type is sorted or not. */ snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, index_type); - file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path)); - fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); + fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) { logf("%s open fail", buf); @@ -2527,21 +2513,18 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) } } - file = get_user_file_path(TAGCACHE_FILE_MASTER, - IS_FILE|NEED_WRITE, - buf, sizeof(buf)); /* Loading the tag lookup file as "master file". */ logf("Loading index file"); - masterfd = open(file, O_RDWR); + masterfd = open(TAGCACHE_FILE_MASTER, O_RDWR); if (masterfd < 0) { logf("Creating new DB"); - masterfd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); + masterfd = open(TAGCACHE_FILE_MASTER, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (masterfd < 0) { - logf("Failure to create index file (%s)", file); + logf("Failure to create index file (%s)", TAGCACHE_FILE_MASTER); close(fd); return -2; } @@ -2849,8 +2832,6 @@ static bool commit(void) { struct tagcache_header tch; struct master_header tcmh; - char path[MAX_PATH]; - const char *file; int i, len, rc; int tmpfd; int masterfd; @@ -2864,10 +2845,7 @@ static bool commit(void) while (write_lock) sleep(1); - file = get_user_file_path(TAGCACHE_FILE_TEMP, - IS_FILE|NEED_WRITE, path, sizeof(path)); - - tmpfd = open(file, O_RDONLY); + tmpfd = open(TAGCACHE_FILE_TEMP, O_RDONLY); if (tmpfd < 0) { logf("nothing to commit"); @@ -2883,7 +2861,7 @@ static bool commit(void) { logf("incorrect tmpheader"); close(tmpfd); - remove(file); + remove(TAGCACHE_FILE_TEMP); return false; } @@ -2891,7 +2869,7 @@ static bool commit(void) { logf("nothing to commit"); close(tmpfd); - remove(file); + remove(TAGCACHE_FILE_TEMP); return true; } @@ -2899,8 +2877,7 @@ static bool commit(void) tc_stat.ready = check_all_headers(); #ifdef HAVE_EEPROM_SETTINGS - remove(get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, - path, sizeof(path))); + remove(TAGCACHE_STATEFILE); #endif /* At first be sure to unload the ramcache! */ @@ -2990,7 +2967,7 @@ static bool commit(void) } close(tmpfd); - remove(file); + remove(TAGCACHE_FILE_TEMP); tc_stat.commit_step = 0; @@ -3410,18 +3387,15 @@ bool tagcache_import_changelog(void) struct tagcache_header tch; int clfd; long masterfd; - char buf[MAX(MAX_PATH, 2048)]; - const char *file; + char buf[2048]; if (!tc_stat.ready) return false; while (read_lock) sleep(1); - - file = get_user_file_path(TAGCACHE_FILE_CHANGELOG, - IS_FILE|NEED_WRITE, buf, sizeof(buf)); - clfd = open(file, O_RDONLY); + + clfd = open(TAGCACHE_FILE_CHANGELOG, O_RDONLY); if (clfd < 0) { logf("failure to open changelog"); @@ -3463,8 +3437,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs) { struct master_header myhdr; struct index_entry idx; - const char *file; - char buf[MAX(TAG_MAXLEN+32, MAX_PATH)]; + char buf[TAG_MAXLEN+32]; char temp[32]; int clfd; int i, j; @@ -3476,9 +3449,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs) return false; /* Initialize the changelog */ - file = get_user_file_path(TAGCACHE_FILE_CHANGELOG, IS_FILE | NEED_WRITE, - buf, sizeof(buf)); - clfd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); + clfd = open(TAGCACHE_FILE_CHANGELOG, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (clfd < 0) { logf("failure to open changelog"); @@ -3796,15 +3767,11 @@ static bool allocate_tagcache(void) static bool tagcache_dumpload(void) { struct statefile_header shdr; - char path[MAX_PATH]; - const char *file; int fd, rc; long offpos; int i; - - file = get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, - path, sizeof(path)); - fd = open(file, O_RDONLY); + + fd = open(TAGCACHE_STATEFILE, O_RDONLY); if (fd < 0) { logf("no tagcache statedump"); @@ -3850,16 +3817,12 @@ static bool tagcache_dumpload(void) static bool tagcache_dumpsave(void) { struct statefile_header shdr; - char path[MAX_PATH]; - const char *file; int fd; if (!tc_stat.ramcache) return false; - file = get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, - path, sizeof(path)); - fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); + fd = open(TAGCACHE_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) { logf("failed to create a statedump"); @@ -3885,8 +3848,7 @@ static bool load_tagcache(void) long bytesleft = tc_stat.ramcache_allocated; struct index_entry *idx; int rc, fd; - char *p, path[MAX_PATH]; - const char *file; + char *p; int i, tag; # ifdef HAVE_DIRCACHE @@ -3897,11 +3859,8 @@ static bool load_tagcache(void) # endif logf("loading tagcache to ram..."); - - file = get_user_file_path(TAGCACHE_FILE_MASTER, - IS_FILE|NEED_WRITE, - path, sizeof(path)); - fd = open(file, O_RDONLY); + + fd = open(TAGCACHE_FILE_MASTER, O_RDONLY); if (fd < 0) { logf("tagcache open failed"); @@ -4111,14 +4070,12 @@ static bool load_tagcache(void) static bool check_deleted_files(void) { int fd; - char buf[TAG_MAXLEN+32], path[MAX_PATH]; - const char *file; + char buf[TAG_MAXLEN+32]; struct tagfile_entry tfe; logf("reverse scan..."); snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag_filename); - file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path)); - fd = open(file, O_RDONLY); + fd = open(buf, O_RDONLY); if (fd < 0) { @@ -4278,8 +4235,6 @@ void tagcache_build(const char *path) { struct tagcache_header header; bool ret; - char buf[MAX_PATH]; - const char *file; curpath[0] = '\0'; data_size = 0; @@ -4292,21 +4247,19 @@ void tagcache_build(const char *path) #endif logf("updating tagcache"); - - file = get_user_file_path(TAGCACHE_FILE_TEMP, - IS_FILE|NEED_WRITE, buf, sizeof(buf)); - - if (file_exists(file)) + cachefd = open(TAGCACHE_FILE_TEMP, O_RDONLY); + if (cachefd >= 0) { logf("skipping, cache already waiting for commit"); + close(cachefd); return ; } - cachefd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0666); + cachefd = open(TAGCACHE_FILE_TEMP, O_RDWR | O_CREAT | O_TRUNC, 0666); if (cachefd < 0) { - logf("master file open failed: %s", file); + logf("master file open failed: %s", TAGCACHE_FILE_TEMP); return ; } @@ -4350,7 +4303,7 @@ void tagcache_build(const char *path) #endif if (commit()) { - remove(file); + remove(TAGCACHE_FILE_TEMP); logf("tagcache built!"); } #ifdef __PCTOOL__ @@ -4395,12 +4348,7 @@ void tagcache_unload_ramcache(void) { tc_stat.ramcache = false; /* Just to make sure there is no statefile present. */ - -#if 0 - char path[MAX_PATH]; - remove(get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, - path, sizeof(path))); -#endif + // remove(TAGCACHE_STATEFILE); } #endif @@ -4409,7 +4357,6 @@ static void tagcache_thread(void) { struct queue_event ev; bool check_done = false; - char path[MAX_PATH]; /* If the previous cache build/update was interrupted, commit * the changes first in foreground. */ @@ -4426,8 +4373,7 @@ static void tagcache_thread(void) check_done = tagcache_dumpload(); } - remove(get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, - path, sizeof(path))); + remove(TAGCACHE_STATEFILE); # endif /* Allocate space for the tagcache if found on disk. */ @@ -4460,8 +4406,7 @@ static void tagcache_thread(void) case Q_REBUILD: remove_files(); - remove(get_user_file_path(TAGCACHE_FILE_TEMP, - IS_FILE|NEED_WRITE, path, sizeof(path))); + remove(TAGCACHE_FILE_TEMP); tagcache_build("/"); break; diff --git a/apps/tree.c b/apps/tree.c index 86238c5..98880f0 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -261,8 +261,7 @@ static int tree_voice_cb(int selected_item, void * data) bool check_rockboxdir(void) { - char path[MAX_PATH]; - if(!dir_exists(get_user_file_path(ROCKBOX_DIR, 0, path, sizeof(path)))) + if(!dir_exists(ROCKBOX_DIR)) { /* No need to localise this message. If .rockbox is missing, it wouldn't work anyway */ int i; diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c index 509743b..e8a5e7c 100644 --- a/firmware/common/dircache.c +++ b/firmware/common/dircache.c @@ -89,13 +89,10 @@ static int fdbind_idx = 0; */ static int open_dircache_file(unsigned flags, int permissions) { - char path[MAX_PATH]; - const char *file = get_user_file_path(DIRCACHE_FILE, IS_FILE|NEED_WRITE, - path, sizeof(path)); if (permissions != 0) - return open(file, flags, permissions); + return open(DIRCACHE_FILE, flags, permissions); - return open(file, flags); + return open(DIRCACHE_FILE, flags); } /** @@ -103,9 +100,7 @@ static int open_dircache_file(unsigned flags, int permissions) */ static int remove_dircache_file(void) { - char path[MAX_PATH]; - return remove(get_user_file_path(DIRCACHE_FILE, IS_FILE|NEED_WRITE, - path, sizeof(path))); + return remove(DIRCACHE_FILE); } #endif /** diff --git a/firmware/common/rbpaths.c b/firmware/common/rbpaths.c index b63586c..7f85bcf 100644 --- a/firmware/common/rbpaths.c +++ b/firmware/common/rbpaths.c @@ -22,6 +22,7 @@ #include /* snprintf */ #include +#include #include "rbpaths.h" #include "file.h" /* MAX_PATH */ #include "dir.h" @@ -29,6 +30,10 @@ #include "string-extra.h" #include "filefuncs.h" +#if (CONFIG_PLATFORM & PLATFORM_ANDROID) +#undef open +#define _open open +#endif void paths_init(void) { @@ -42,14 +47,28 @@ void paths_init(void) #endif } -const char* get_user_file_path(const char *path, +static bool try_path(const char* filename, unsigned flags) +{ + if (flags & IS_FILE) + { + if (file_exists(filename)) + return true; + } + else + { + if (dir_exists(filename)) + return true; + } + return false; +} + +const char* _get_user_file_path(const char *path, unsigned flags, char* buf, const size_t bufsize) { const char *ret = path; const char *pos = path; - printf("%s(): looking for %s\n", __func__, path); /* replace ROCKBOX_DIR in path with $HOME/.config/rockbox.org */ pos += ROCKBOX_DIR_LEN; if (*pos == '/') pos += 1; @@ -66,27 +85,38 @@ const char* get_user_file_path(const char *path, * write access is needed */ if (flags & NEED_WRITE) ret = buf; - else + else if (try_path(buf, flags)) + ret = buf; + + if (ret != buf) /* not found in $HOME, try ROCKBOX_BASE_DIR, !NEED_WRITE only */ { - if (flags & IS_FILE) - { - if (file_exists(buf)) - ret = buf; - } - else - { - if (dir_exists(buf)) - ret = buf; - } - } + if (snprintf(buf, bufsize, ROCKBOX_SHARE_PATH "/%s", pos) >= (int)bufsize) + return NULL; - /* make a copy if we're about to return the path*/ - if (UNLIKELY((flags & FORCE_BUFFER_COPY) && (ret != buf))) - { - strlcpy(buf, ret, bufsize); - ret = buf; + if (try_path(buf, flags)) + ret = buf; } - printf("%s(): %s\n", __func__, ret); return ret; } + +int application_open(const char *name, int o, ...) +{ + char realpath[MAX_PATH]; + va_list ap; + int fd; + + if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN)) + { + int flags = IS_FILE; + if (o & (O_CREAT|O_RDWR)) + flags |= NEED_WRITE; + name = _get_user_file_path(name, flags, realpath, sizeof(realpath)); + } + va_start(ap, o); + fd = _open(name, o, ap); + va_end(ap); + + return fd; + +} diff --git a/firmware/export/rbpaths.h b/firmware/export/rbpaths.h index cd87888..1bc2be1 100644 --- a/firmware/export/rbpaths.h +++ b/firmware/export/rbpaths.h @@ -32,10 +32,6 @@ #define NEED_WRITE (1<<0) /* file or directory? */ #define IS_FILE (1<<1) -/* make sure the path is copied into the passed buffer (it may return - * the passed path directly otherwise, e.g. always on target builds) */ -#define FORCE_BUFFER_COPY (1<<2) - /* name of directory where configuration, fonts and other data @@ -67,32 +63,17 @@ #define REC_BASE_DIR "/" #define PLAYLIST_CATALOG_DEFAULT_DIR "/Playlists" -#ifndef PLUGIN -static inline __attribute__((always_inline)) const char* get_user_file_path(const char *path, - unsigned flags, - char* buf, - const size_t bufsize) -{ - if (flags & FORCE_BUFFER_COPY) - { - strlcpy(buf, path, bufsize); - return buf; - } - return path; -} -#endif - #define paths_init() #else /* application */ -#define PLUGIN_DIR ROCKBOX_LIBRARY_PATH "/rockbox/rocks" -#define CODECS_DIR ROCKBOX_LIBRARY_PATH "/rockbox/codecs" +#define PLUGIN_DIR ROCKBOX_LIBRARY_PATH "/rocks" +#define CODECS_DIR ROCKBOX_LIBRARY_PATH "/codecs" #define REC_BASE_DIR ROCKBOX_DIR "/" #define PLAYLIST_CATALOG_DEFAULT_DIR ROCKBOX_DIR "/Playlists" extern void paths_init(void); -extern const char* get_user_file_path(const char *path, +extern const char* _get_user_file_path(const char *path, unsigned flags, char* buf, const size_t bufsize); diff --git a/firmware/font.c b/firmware/font.c index e973108..cd74459 100644 --- a/firmware/font.c +++ b/firmware/font.c @@ -613,11 +613,7 @@ void glyph_cache_save(struct font* pf) pf = &font_ui; if (pf->fd >= 0 && pf == &font_ui) { - char path[MAX_PATH]; - const char *file = get_user_file_path(GLYPH_CACHE_FILE, IS_FILE|NEED_WRITE, - path, sizeof(path)); - - cache_fd = open(file, O_WRONLY|O_CREAT|O_TRUNC, 0666); + cache_fd = open(GLYPH_CACHE_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666); if (cache_fd < 0) return; @@ -678,7 +674,6 @@ static void glyph_cache_load(struct font* pf) int i, size; unsigned char tmp[2]; unsigned short ch; - char path[MAX_PATH]; unsigned short glyphs[MAX_SORT]; unsigned short glyphs_lru_order[MAX_SORT]; int glyph_file_skip=0, glyph_file_size=0; @@ -687,8 +682,7 @@ static void glyph_cache_load(struct font* pf) if ( sort_size > MAX_SORT ) sort_size = MAX_SORT; - fd = open(get_user_file_path(GLYPH_CACHE_FILE, IS_FILE|NEED_WRITE, - path, sizeof(path)), O_RDONLY|O_BINARY); + fd = open(GLYPH_CACHE_FILE, O_RDONLY|O_BINARY); if (fd >= 0) { /* only read what fits */ diff --git a/firmware/include/file.h b/firmware/include/file.h index 8711124..45dc277 100644 --- a/firmware/include/file.h +++ b/firmware/include/file.h @@ -38,7 +38,8 @@ #if !defined(PLUGIN) && !defined(CODEC) #if (CONFIG_PLATFORM & PLATFORM_SDL) -#define open(x, ...) sim_open(x, __VA_ARGS__) +#define open(x, ...) application_open(x, __VA_ARGS__) +#define _open(x, ...) sim_open(x, __VA_ARGS__) #define creat(x,m) sim_creat(x,m) #define remove(x) sim_remove(x) #define rename(x,y) sim_rename(x,y) @@ -51,6 +52,10 @@ #define close(x) sim_close(x) extern int sim_creat(const char *pathname, mode_t mode); extern int sim_open(const char *pathname, int flags, ...); +int application_open(const char *name, int o, ...); +#elif (CONFIG_PLATFORM & PLATFORM_ANDROID) +#define open(x, ...) application_open(x, __VA_ARGS__) +int application_open(const char *name, int o, ...); #endif typedef int (*open_func)(const char* pathname, int flags, ...); diff --git a/firmware/load_code.c b/firmware/load_code.c index 5b5307e..2337ee5 100644 --- a/firmware/load_code.c +++ b/firmware/load_code.c @@ -144,17 +144,15 @@ void *lc_open_from_mem(void *addr, size_t blob_size) for (i = 0; i < 10; i++) { #if (CONFIG_PLATFORM & PLATFORM_ANDROID) - /* we need that path fixed, since get_user_file_path() + /* we need that path fixed, since _get_user_file_path() * gives us the folder on the sdcard where we cannot load libraries * from (no exec permissions) */ snprintf(temp_filename, sizeof(temp_filename), "/data/data/org.rockbox/app_rockbox/libtemp_binary_%d.so", i); #else - char name[MAX_PATH]; - const char *_name = get_user_file_path(ROCKBOX_DIR, NEED_WRITE, name, sizeof(name)); snprintf(temp_filename, sizeof(temp_filename), - "%s/libtemp_binary_%d.dll", _name, i); + ROCKBOX_DIR "/libtemp_binary_%d.dll", i); #endif fd = open(temp_filename, O_WRONLY|O_CREAT|O_TRUNC, 0700); if (fd >= 0) diff --git a/firmware/target/hosted/android/fs-android.c b/firmware/target/hosted/android/fs-android.c index 5209458..b3cda51 100644 --- a/firmware/target/hosted/android/fs-android.c +++ b/firmware/target/hosted/android/fs-android.c @@ -29,6 +29,7 @@ #include "dir-target.h" #include "file.h" #include "dir.h" +#include "rbpaths.h" long filesize(int fd) @@ -61,7 +62,15 @@ struct __dir { DIR* _opendir(const char *name) { - char *buf = malloc(sizeof(struct __dir) + strlen(name)+1); + char temp[MAX_PATH]; + char *buf; + + if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN)) + { + name = _get_user_file_path(name, 0, temp, sizeof(temp)); + } + + buf = malloc(sizeof(struct __dir) + strlen(name)+1); if (!buf) return NULL; diff --git a/tools/configure b/tools/configure index 5f148d8..84456ff 100755 --- a/tools/configure +++ b/tools/configure @@ -21,7 +21,6 @@ use_bootchart="#undef DO_BOOTCHART" scriptver=`echo '$Revision$' | sed -e 's:\\$::g' -e 's/Revision: //'` rbdir="/.rockbox" -need_full_path= bindir= libdir= bindir_full= @@ -88,13 +87,13 @@ app_get_platform() { # setup files and paths depending on the platform if [ "$app_platform" = "sdl" ]; then if [ -z "$PREFIX" ]; then - rbdir="/usr/local/share/rockbox" + sharedir="/usr/local/share/rockbox" bindir="/usr/local/bin" bindir_full=$bindir - libdir="/usr/local/lib" + libdir="/usr/local/lib/rockbox" libdir_full=$libdir else - rbdir=`realpath $PREFIX/share/rockbox` + sharedir=`realpath $PREFIX/share/rockbox` bindir="$PREFIX/bin" libdir="$PREFIX/lib" if [ -d bindir ]; then @@ -120,10 +119,10 @@ app_get_platform() { echo "environment variable point to the root directory of the Android NDK." exit fi - rbdir="/data/data/org.rockbox/app_rockbox/rockbox" + sharedir="/data/data/org.rockbox/.rockbox" bindir="/data/data/org.rockbox/lib" bindir_full=$bindir - libdir="/data/data/org.rockbox/app_rockbox" + libdir="/data/data/org.rockbox/.rockbox" libdir_full=$libdir output="librockbox.so" bootoutput="librockbox.so" @@ -2721,7 +2720,6 @@ fi modelname="application" target="-DAPPLICATION" - need_full_path="yes" app_get_platform memory=8 @@ -3119,15 +3117,11 @@ else fi if [ "$ARG_RBDIR" ]; then - if [ "$need_full_path" = "yes" ]; then - rbdir=`realpath $ARG_RBDIR` - else # prepend '/' if needed if [ -z `echo $ARG_RBDIR | grep '^/'` ]; then rbdir="/"$ARG_RBDIR else rbdir=$ARG_RBDIR fi - fi echo "Using alternate rockbox dir: ${rbdir}" fi @@ -3138,6 +3132,7 @@ sed > autoconf.h \ -e "s<@config_rtc@<$config_rtc autoconf.h \ /* root of Rockbox */ #define ROCKBOX_DIR "@RBDIR@" +#define ROCKBOX_SHARE_PATH "@sharepath@" #define ROCKBOX_BINARY_PATH "@binpath@" #define ROCKBOX_LIBRARY_PATH "@libpath@" @@ -3306,6 +3302,7 @@ sed > Makefile \ -e "s<@RBDIR@<${rbdir}