This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 25th, 2010  |  syntax: None  |  size: 44.26 KB  |  views: 86  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java
  2. index 1416886..26b6d7e 100644
  3. --- a/android/src/org/rockbox/RockboxService.java
  4. +++ b/android/src/org/rockbox/RockboxService.java
  5. @@ -128,12 +128,12 @@ public class RockboxService extends Service
  6.             BufferedOutputStream dest = null;
  7.             BufferedInputStream is = null;
  8.             ZipEntry entry;
  9. -           File file = new File("/data/data/org.rockbox/" +
  10. -                       "lib/libmisc.so");
  11. +           String base = "/data/data/org.rockbox/";
  12. +           File file = new File("/data/data/org.rockbox/lib/libmisc.so");
  13.             /* use arbitary file to determine whether extracting is needed */
  14.             File file2 = new File("/data/data/org.rockbox/" +
  15. -                       "app_rockbox/rockbox/codecs/mpa.codec");
  16. -           if (!file2.exists() || (file.lastModified() > file2.lastModified()))
  17. +                                                    ".rockbox/codecs/mpa.codec");
  18. +           if (!file2.exists() || (file.lastModified() > file2.lastModified())*/)
  19.             {
  20.                 ZipFile zipfile = new ZipFile(file);
  21.                 Enumeration<? extends ZipEntry> e = zipfile.entries();
  22. @@ -144,8 +144,7 @@ public class RockboxService extends Service
  23.                    LOG("Extracting: " +entry);
  24.                    if (entry.isDirectory())
  25.                    {
  26. -                      folder = new File(entry.getName());
  27. -                      LOG("mkdir "+ entry);
  28. +                      folder = new File(base + entry.getName());
  29.                        try {
  30.                            folder.mkdirs();
  31.                        } catch (SecurityException ex) {
  32. @@ -157,11 +156,11 @@ public class RockboxService extends Service
  33.                            BUFFER);
  34.                    int count;
  35.                    byte data[] = new byte[BUFFER];
  36. -                  folder = new File(new File(entry.getName()).getParent());
  37. +                  folder = new File(new File(base + entry.getName()).getParent());
  38.                    LOG("" + folder.getAbsolutePath());
  39.                    if (!folder.exists())
  40.                        folder.mkdirs();
  41. -                  FileOutputStream fos = new FileOutputStream(entry.getName());
  42. +                  FileOutputStream fos = new FileOutputStream(base + entry.getName());
  43.                    dest = new BufferedOutputStream(fos, BUFFER);
  44.                    while ((count = is.read(data, 0, BUFFER)) != -1)
  45.                       dest.write(data, 0, count);
  46. diff --git a/apps/filetypes.c b/apps/filetypes.c
  47. index 28a2da6..0e0cbd8 100644
  48. --- a/apps/filetypes.c
  49. +++ b/apps/filetypes.c
  50. @@ -182,15 +182,14 @@ static void read_config(const char* config_file);
  51.   * load a colors file from a theme with:
  52.   * filetype colours: filename.colours */
  53.  void read_color_theme_file(void) {
  54. -    char buffer[MAX_PATH], dir[MAX_PATH];
  55. +    char buffer[MAX_PATH];
  56.      int fd;
  57.      char *ext, *color;
  58.      int i;
  59.      for (i = 0; i < MAX_FILETYPES+1; i++) {
  60.          custom_colors[i] = -1;
  61.      }
  62. -    snprintf(buffer, MAX_PATH, "%s/%s.colours",
  63. -             get_user_file_path(THEME_DIR, 0, dir, sizeof(dir)),
  64. +    snprintf(buffer, MAX_PATH, THEME_DIR "/%s.colours",
  65.               global_settings.colors_file);
  66.      fd = open(buffer, O_RDONLY);
  67.      if (fd < 0)
  68. @@ -273,7 +272,6 @@ void read_viewer_theme_file(void)
  69.  
  70.  void  filetype_init(void)
  71.  {
  72. -    char path[MAX_PATH];
  73.      /* set the directory item first */
  74.      filetypes[0].extension = NULL;
  75.      filetypes[0].plugin = NULL;
  76. @@ -282,7 +280,7 @@ void  filetype_init(void)
  77.      
  78.      filetype_count = 1;
  79.      read_builtin_types();
  80. -    read_config(get_user_file_path(VIEWERS_CONFIG, IS_FILE, path, sizeof(path)));
  81. +    read_config(VIEWERS_CONFIG);
  82.  #ifdef HAVE_LCD_BITMAP
  83.      read_viewer_theme_file();
  84.  #endif
  85. diff --git a/apps/gui/icon.c b/apps/gui/icon.c
  86. index b0e1ba9..43dea63 100644
  87. --- a/apps/gui/icon.c
  88. +++ b/apps/gui/icon.c
  89. @@ -238,7 +238,7 @@ static void load_icons(const char* filename, enum Iconset iconset)
  90.      {
  91.          char path[MAX_PATH];
  92.          
  93. -        snprintf(path, sizeof(path), "%s/%s.bmp", ICON_DIR, filename);
  94. +        snprintf(path, sizeof(path), ICON_DIR "/%s.bmp", filename);
  95.          size_read = read_bmp_file(path, bmp, IMG_BUFSIZE, bmpformat, NULL);
  96.          if (size_read > 0)
  97.          {
  98. diff --git a/apps/gui/skin_engine/skin_backdrops.c b/apps/gui/skin_engine/skin_backdrops.c
  99. index e337774..3e04bea 100644
  100. --- a/apps/gui/skin_engine/skin_backdrops.c
  101. +++ b/apps/gui/skin_engine/skin_backdrops.c
  102. @@ -54,7 +54,6 @@ void skin_backdrop_init(void)
  103.  int skin_backdrop_assign(char* backdrop, char *bmpdir,
  104.                           enum screen_type screen)
  105.  {
  106. -    char dir[MAX_PATH];
  107.      char filename[MAX_PATH];
  108.      int i, free = -1;
  109.      if (!backdrop)
  110. @@ -68,8 +67,7 @@ int skin_backdrop_assign(char* backdrop, char *bmpdir,
  111.      }
  112.      else
  113.      {
  114. -        const char *bd_dir = get_user_file_path(bmpdir, 0, dir, sizeof(dir));
  115. -        get_image_filename(backdrop, bd_dir, filename, sizeof(filename));
  116. +        get_image_filename(backdrop, bmpdir, filename, sizeof(filename));
  117.      }
  118.      for (i=0; i<NB_BDROPS; i++)
  119.      {
  120. @@ -115,12 +113,9 @@ bool skin_backdrops_preload(void)
  121.              if (screen == SCREEN_MAIN && global_settings.backdrop_file[0] &&
  122.                  global_settings.backdrop_file[0] != '-' && filename[0] == '-')
  123.              {
  124. -                char dir[MAX_PATH];
  125.                  char* temp = filename+2; /* slightly hacky to get a buffer */
  126.                  size_t size = sizeof(backdrops[i].name) - 2;
  127. -                snprintf(temp, size, "%s/%s.bmp",
  128. -                         get_user_file_path(BACKDROP_DIR, 0, dir, sizeof(dir)),
  129. -                         global_settings.backdrop_file);
  130. +                snprintf(temp, size, BACKDROP_DIR "/%s.bmp", global_settings.backdrop_file);
  131.                  filename = temp;
  132.              }
  133.              if (*filename && *filename != '-')
  134. @@ -161,7 +156,7 @@ void skin_backdrop_unload(int backdrop_id)
  135.  void skin_backdrop_load_setting(void)
  136.  {
  137.      int i;
  138. -    char filename[MAX_PATH], dir[MAX_PATH];
  139. +    char filename[MAX_PATH];
  140.      for(i=0;i<SKINNABLE_SCREENS_COUNT*NB_SCREENS;i++)
  141.      {
  142.          if (backdrops[i].name[0] == '-' && backdrops[i].screen == SCREEN_MAIN)
  143. @@ -171,8 +166,7 @@ void skin_backdrop_load_setting(void)
  144.              {
  145.                  if (!backdrops[i].buffer)
  146.                      backdrops[i].buffer = (char*)skin_buffer_alloc(LCD_BACKDROP_BYTES);
  147. -                snprintf(filename, sizeof filename, "%s/%s.bmp",
  148. -                         get_user_file_path(BACKDROP_DIR, 0, dir, sizeof(dir)),
  149. +                snprintf(filename, sizeof filename, BACKDROP_DIR "/%s.bmp",
  150.                           global_settings.backdrop_file);
  151.                  bool loaded = backdrops[i].buffer &&
  152.                                screens[SCREEN_MAIN].backdrop_load(filename,
  153. diff --git a/apps/gui/skin_engine/skin_engine.c b/apps/gui/skin_engine/skin_engine.c
  154. index 8bf1658..4157587 100644
  155. --- a/apps/gui/skin_engine/skin_engine.c
  156. +++ b/apps/gui/skin_engine/skin_engine.c
  157. @@ -214,9 +214,7 @@ struct gui_wps *skin_get_gwps(enum skinnable_screens skin, enum screen_type scre
  158.          buf[0] = '\0'; /* force it to reload the default */
  159.          if (strcmp(setting, "rockbox_failsafe"))
  160.          {
  161. -            snprintf(buf, sizeof buf, "%s/%s.%s",
  162. -                 get_user_file_path(WPS_DIR, false, path, sizeof(path)),
  163. -                 setting, ext);
  164. +            snprintf(buf, sizeof buf, WPS_DIR "/%s.%s", setting, ext);
  165.          }
  166.          cpu_boost(true);
  167.          skin_load(skin, screen, buf, true);
  168. diff --git a/apps/gui/skin_engine/skin_fonts.c b/apps/gui/skin_engine/skin_fonts.c
  169. index e5081e8..23255aa 100644
  170. --- a/apps/gui/skin_engine/skin_fonts.c
  171. +++ b/apps/gui/skin_engine/skin_fonts.c
  172. @@ -64,7 +64,6 @@ int skin_font_load(char* font_name, int glyphs)
  173.      struct font *pf;
  174.      struct skin_font_info *font = NULL;
  175.      char filename[MAX_PATH];
  176. -    char tmp[MAX_PATH];
  177.      
  178.      if (!strcmp(font_name, global_settings.font_file))
  179.          return FONT_UI;
  180. @@ -72,8 +71,7 @@ int skin_font_load(char* font_name, int glyphs)
  181.      if (!strcmp(font_name, global_settings.remote_font_file))
  182.          return FONT_UI_REMOTE;
  183.  #endif
  184. -    snprintf(tmp, MAX_PATH, FONT_DIR "/%s.fnt", font_name);
  185. -    get_user_file_path(tmp, FORCE_BUFFER_COPY, filename, sizeof(filename));
  186. +    snprintf(filename, MAX_PATH, FONT_DIR "/%s.fnt", font_name);
  187.      
  188.      for(i=0;i<MAXUSERFONTS;i++)
  189.      {
  190. diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
  191. index ed475ac..cec5c17 100644
  192. --- a/apps/gui/skin_engine/skin_parser.c
  193. +++ b/apps/gui/skin_engine/skin_parser.c
  194. @@ -1624,8 +1624,7 @@ bool skin_data_load(enum screen_type screen, struct wps_data *wps_data,
  195.          strlcpy(bmpdir, buf, dot - buf + 1);
  196.      }
  197.      else
  198. -    {   /* fall back to backdrop dir for built-in themes */
  199. -        /* no get_user_file_path(), assuming we ship bmps for built-in themes */
  200. +    {
  201.          snprintf(bmpdir, MAX_PATH, "%s", BACKDROP_DIR);
  202.      }
  203.      /* load the bitmaps that were found by the parsing */
  204. diff --git a/apps/main.c b/apps/main.c
  205. index 950168d..7af4cca 100644
  206. --- a/apps/main.c
  207. +++ b/apps/main.c
  208. @@ -172,13 +172,13 @@ int main(void)
  209.  #ifdef AUTOROCK
  210.      {
  211.          char filename[MAX_PATH];
  212. -        const char *file = get_user_file_path(
  213. +        const char *file =
  214.  #ifdef APPLICATION
  215.                                  ROCKBOX_DIR
  216.  #else
  217.                                  PLUGIN_APPS_DIR
  218.  #endif
  219. -            "/autostart.rock", NEED_WRITE|IS_FILE, filename, sizeof(filename));
  220. +                                    "/autostart.rock";
  221.          if(file_exists(file)) /* no complaint if it doesn't exist */
  222.          {
  223.              plugin_load(file, NULL); /* start if it does */
  224. diff --git a/apps/menus/theme_menu.c b/apps/menus/theme_menu.c
  225. index 66274e2..983eca9 100644
  226. --- a/apps/menus/theme_menu.c
  227. +++ b/apps/menus/theme_menu.c
  228. @@ -246,11 +246,9 @@ static struct browse_folder_info themes = {THEME_DIR, SHOW_CFG};
  229.  
  230.  int browse_folder(void *param)
  231.  {
  232. -    char path[MAX_PATH];
  233.      const struct browse_folder_info *info =
  234.          (const struct browse_folder_info*)param;
  235. -    return rockbox_browse(get_user_file_path(info->dir, 0, path, sizeof(path)),
  236. -                          info->show_options);
  237. +    return rockbox_browse(info->dir, info->show_options);
  238.  }
  239.  
  240.  #ifdef HAVE_LCD_BITMAP
  241. diff --git a/apps/playlist.c b/apps/playlist.c
  242. index a50dac6..6e4ae18 100644
  243. --- a/apps/playlist.c
  244. +++ b/apps/playlist.c
  245. @@ -1439,12 +1439,7 @@ static int get_next_dir(char *dir, bool is_forward, bool recursion)
  246.      /* process random folder advance */
  247.      if (global_settings.next_folder == FOLDER_ADVANCE_RANDOM)
  248.      {
  249. -        char folder_advance_list[MAX_PATH];
  250. -        get_user_file_path(ROCKBOX_DIR, FORCE_BUFFER_COPY,
  251. -                folder_advance_list, sizeof(folder_advance_list));
  252. -        strlcat(folder_advance_list, "/folder_advance_list.dat",
  253. -                sizeof(folder_advance_list));
  254. -        int fd = open(folder_advance_list, O_RDONLY);
  255. +        int fd = open(ROCKBOX_DIR "/folder_advance_list.dat", O_RDONLY);
  256.          if (fd >= 0)
  257.          {
  258.              char buffer[MAX_PATH];
  259. @@ -1914,8 +1909,7 @@ void playlist_init(void)
  260.      struct playlist_info* playlist = &current_playlist;
  261.  
  262.      playlist->current = true;
  263. -    get_user_file_path(PLAYLIST_CONTROL_FILE, IS_FILE|NEED_WRITE|FORCE_BUFFER_COPY,
  264. -            playlist->control_filename,
  265. +    strlcpy(playlist->control_filename, PLAYLIST_CONTROL_FILE,
  266.              sizeof(playlist->control_filename));
  267.      playlist->fd = -1;
  268.      playlist->control_fd = -1;
  269. diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c
  270. index 5f9f467..ff69b28 100644
  271. --- a/apps/playlist_catalog.c
  272. +++ b/apps/playlist_catalog.c
  273. @@ -81,11 +81,9 @@ static int initialize_catalog(void)
  274.          /* fall back to default directory if no or invalid config */
  275.          if (default_dir)
  276.          {
  277. -            const char *dir = get_user_file_path(PLAYLIST_CATALOG_DEFAULT_DIR,
  278. -                                    FORCE_BUFFER_COPY|NEED_WRITE,
  279. -                                    playlist_dir, sizeof(playlist_dir));
  280. -            if (!dir_exists(dir))
  281. -                mkdir(dir);
  282. +            strcpy(playlist_dir, PLAYLIST_CATALOG_DEFAULT_DIR);
  283. +            if (!dir_exists(playlist_dir))
  284. +                mkdir(playlist_dir);
  285.          }
  286.  
  287.          playlist_dir_length = strlen(playlist_dir);
  288. diff --git a/apps/settings.c b/apps/settings.c
  289. index 85b0489..848c7c1 100644
  290. --- a/apps/settings.c
  291. +++ b/apps/settings.c
  292. @@ -118,9 +118,7 @@ static bool read_nvram_data(char* buf, int max_len)
  293.      unsigned crc32 = 0xffffffff;
  294.      int var_count = 0, i = 0, buf_pos = 0;
  295.  #ifndef HAVE_RTC_RAM
  296. -    char path[MAX_PATH];
  297. -    int fd = open(get_user_file_path(NVRAM_FILE, IS_FILE|NEED_WRITE,
  298. -                  path, sizeof(path)), O_RDONLY);
  299. +    int fd = open(NVRAM_FILE, O_RDONLY);
  300.      int bytes;
  301.      if (fd < 0)
  302.          return false;
  303. @@ -174,7 +172,6 @@ static bool write_nvram_data(char* buf, int max_len)
  304.      char var_count = 0;
  305.  #ifndef HAVE_RTC_RAM
  306.      int fd;
  307. -    char path[MAX_PATH];
  308.  #endif
  309.      memset(buf,0,max_len);
  310.      /* magic, version */
  311. @@ -198,8 +195,7 @@ static bool write_nvram_data(char* buf, int max_len)
  312.                      max_len-NVRAM_DATA_START-1,0xffffffff);
  313.      memcpy(&buf[4],&crc32,4);
  314.  #ifndef HAVE_RTC_RAM
  315. -    fd = open(get_user_file_path(NVRAM_FILE, IS_FILE|NEED_WRITE,
  316. -                  path, sizeof(path)),O_CREAT|O_TRUNC|O_WRONLY, 0666);
  317. +    fd = open(NVRAM_FILE,O_CREAT|O_TRUNC|O_WRONLY, 0666);
  318.      if (fd >= 0)
  319.      {
  320.          int len = write(fd,buf,max_len);
  321. @@ -230,12 +226,8 @@ void settings_load(int which)
  322.          read_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
  323.      if (which&SETTINGS_HD)
  324.      {
  325. -        const char *file;
  326. -        char path[MAX_PATH];
  327. -        file = get_user_file_path(CONFIGFILE, IS_FILE|NEED_WRITE, path, sizeof(path));
  328. -        settings_load_config(file, false);
  329. -        file = get_user_file_path(FIXEDSETTINGSFILE, IS_FILE, path, sizeof(path));
  330. -        settings_load_config(file, false);
  331. +        settings_load_config(CONFIGFILE, false);
  332. +        settings_load_config(FIXEDSETTINGSFILE, false);
  333.      }
  334.  }
  335.  
  336. @@ -596,11 +588,8 @@ static void flush_global_status_callback(void *data)
  337.  static void flush_config_block_callback(void *data)
  338.  {
  339.      (void)data;
  340. -    char path[MAX_PATH];
  341.      write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
  342. -    settings_write_config(
  343. -            get_user_file_path(CONFIGFILE, IS_FILE|NEED_WRITE, path, sizeof(path)),
  344. -            SETTINGS_SAVE_CHANGED);
  345. +    settings_write_config(CONFIGFILE, SETTINGS_SAVE_CHANGED);
  346.  }
  347.  
  348.  /*
  349. @@ -644,7 +633,7 @@ int settings_save(void)
  350.  
  351.  bool settings_save_config(int options)
  352.  {
  353. -    char filename[MAX_PATH], path[MAX_PATH];
  354. +    char filename[MAX_PATH];
  355.      const char *folder, *namebase;
  356.      switch (options)
  357.      {
  358. @@ -673,8 +662,6 @@ bool settings_save_config(int options)
  359.              namebase = "config";
  360.              break;
  361.      }
  362. -
  363. -    folder = get_user_file_path(folder, NEED_WRITE, path, sizeof(path));
  364.      create_numbered_filename(filename, folder, namebase, ".cfg", 2
  365.                               IF_CNFN_NUM_(, NULL));
  366.  
  367. @@ -884,13 +871,11 @@ void settings_apply(bool read_disk)
  368.      {
  369.          char buf[MAX_PATH];
  370.  #ifdef HAVE_LCD_BITMAP
  371. -        char dir[MAX_PATH];
  372. -        const char *font_path = get_user_file_path(FONT_DIR, 0, dir, sizeof(dir));
  373.          /* fonts need to be loaded before the WPS */
  374.          if (global_settings.font_file[0]
  375.              && global_settings.font_file[0] != '-') {
  376.              
  377. -            snprintf(buf, sizeof buf, "%s/%s.fnt", font_path,
  378. +            snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt",
  379.                       global_settings.font_file);
  380.              CHART2(">font_load ", global_settings.font_file);
  381.              rc = font_load(NULL, buf);
  382. @@ -903,7 +888,7 @@ void settings_apply(bool read_disk)
  383.  #ifdef HAVE_REMOTE_LCD        
  384.          if ( global_settings.remote_font_file[0]
  385.              && global_settings.remote_font_file[0] != '-') {
  386. -            snprintf(buf, sizeof buf, "%s/%s.fnt", font_path,
  387. +            snprintf(buf, sizeof buf, FONT_DIR "%s.fnt",
  388.                       global_settings.remote_font_file);
  389.              CHART2(">font_load_remoteui ", global_settings.remote_font_file);
  390.              rc = font_load_remoteui(buf);
  391. @@ -915,8 +900,7 @@ void settings_apply(bool read_disk)
  392.              font_load_remoteui(NULL);
  393.  #endif
  394.          if ( global_settings.kbd_file[0]) {
  395. -            snprintf(buf, sizeof buf, "%s/%s.kbd",
  396. -                     get_user_file_path(ROCKBOX_DIR, 0, dir, sizeof(dir)),
  397. +            snprintf(buf, sizeof buf, ROCKBOX_DIR "/%s.kbd",
  398.                       global_settings.kbd_file);
  399.              CHART(">load_kbd");
  400.              load_kbd(buf);
  401. @@ -925,8 +909,6 @@ void settings_apply(bool read_disk)
  402.          else
  403.              load_kbd(NULL);
  404.  #endif /* HAVE_LCD_BITMAP */
  405. -        /* no get_user_file_path() here because we don't really support
  406. -         * langs that don't come with rockbox */
  407.          if ( global_settings.lang_file[0]) {
  408.              snprintf(buf, sizeof buf, LANG_DIR "/%s.lng",
  409.                       global_settings.lang_file);
  410. diff --git a/apps/tagcache.c b/apps/tagcache.c
  411. index 39ed99f..e0b7608 100644
  412. --- a/apps/tagcache.c
  413. +++ b/apps/tagcache.c
  414. @@ -73,9 +73,9 @@
  415.  #include "buffer.h"
  416.  #include "crc32.h"
  417.  #include "misc.h"
  418. -#include "filefuncs.h"
  419.  #include "settings.h"
  420.  #include "dir.h"
  421. +#include "filefuncs.h"
  422.  #include "structec.h"
  423.  
  424.  #ifndef __PCTOOL__
  425. @@ -293,17 +293,15 @@ static bool is_dircache_intact(void)
  426.  static int open_tag_fd(struct tagcache_header *hdr, int tag, bool write)
  427.  {
  428.      int fd;
  429. -    char buf[MAX_PATH], path[MAX_PATH];
  430. -    const char * file;
  431. +    char buf[MAX_PATH];
  432.      int rc;
  433.      
  434.      if (TAGCACHE_IS_NUMERIC(tag) || tag < 0 || tag >= TAG_COUNT)
  435.          return -1;
  436.      
  437.      snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag);
  438. -    file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path));
  439.      
  440. -    fd = open(file, write ? O_RDWR : O_RDONLY);
  441. +    fd = open(buf, write ? O_RDWR : O_RDONLY);
  442.      if (fd < 0)
  443.      {
  444.          logf("tag file open failed: tag=%d write=%d file=%s", tag, write, buf);
  445. @@ -328,12 +326,8 @@ static int open_master_fd(struct master_header *hdr, bool write)
  446.  {
  447.      int fd;
  448.      int rc;
  449. -    char path[MAX_PATH];
  450.      
  451. -    fd = open(get_user_file_path(TAGCACHE_FILE_MASTER,
  452. -                                 IS_FILE|NEED_WRITE,
  453. -                                 path, sizeof(path)),
  454. -                    write ? O_RDWR : O_RDONLY);
  455. +    fd = open(TAGCACHE_FILE_MASTER, write ? O_RDWR : O_RDONLY);
  456.      if (fd < 0)
  457.      {
  458.          logf("master file open failed for R/W");
  459. @@ -675,12 +669,10 @@ static bool open_files(struct tagcache_search *tcs, int tag)
  460.  {
  461.      if (tcs->idxfd[tag] < 0)
  462.      {
  463. -        char fn[MAX_PATH], path[MAX_PATH];
  464. -        const char *file;
  465. +        char fn[MAX_PATH];
  466.  
  467.          snprintf(fn, sizeof fn, TAGCACHE_FILE_INDEX, tag);
  468. -        file = get_user_file_path(fn, IS_FILE | NEED_WRITE, path, sizeof(path));
  469. -        tcs->idxfd[tag] = open(file, O_RDONLY);
  470. +        tcs->idxfd[tag] = open(fn, O_RDONLY);
  471.      }
  472.      
  473.      if (tcs->idxfd[tag] < 0)
  474. @@ -1168,17 +1160,14 @@ static void remove_files(void)
  475.      tc_stat.ready = false;
  476.      tc_stat.ramcache = false;
  477.      tc_stat.econ = false;
  478. -    remove(get_user_file_path(TAGCACHE_FILE_MASTER, NEED_WRITE|IS_FILE,
  479. -                              buf, sizeof(buf)));
  480. +    remove(TAGCACHE_FILE_MASTER);
  481.      for (i = 0; i < TAG_COUNT; i++)
  482.      {
  483. -        char buf2[MAX_PATH];
  484.          if (TAGCACHE_IS_NUMERIC(i))
  485.              continue;
  486. -
  487. -        /* database_%d.tcd -> database_0.tcd */
  488. +        
  489.          snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, i);
  490. -        remove(get_user_file_path(buf, NEED_WRITE | IS_FILE, buf2, sizeof(buf2)));
  491. +        remove(buf);
  492.      }
  493.  }
  494.  
  495. @@ -1329,11 +1318,10 @@ bool tagcache_search_add_clause(struct tagcache_search *tcs,
  496.      
  497.      if (!TAGCACHE_IS_NUMERIC(clause->tag) && tcs->idxfd[clause->tag] < 0)
  498.      {
  499. -        char buf[MAX_PATH], path[MAX_PATH];
  500. -        const char *file;
  501. -        snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, clause->tag);
  502. -        file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path));
  503. -        tcs->idxfd[clause->tag] = open(file, O_RDONLY);
  504. +        char buf[MAX_PATH];
  505. +
  506. +        snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, clause->tag);        
  507. +        tcs->idxfd[clause->tag] = open(buf, O_RDONLY);
  508.      }
  509.      
  510.      tcs->clause[tcs->clause_count] = clause;
  511. @@ -2357,8 +2345,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
  512.      struct master_header   tcmh;
  513.      struct index_entry idxbuf[IDX_BUF_DEPTH];
  514.      int idxbuf_pos;
  515. -    char buf[TAG_MAXLEN+32], path[MAX_PATH];
  516. -    const char *file;
  517. +    char buf[TAG_MAXLEN+32];
  518.      int fd = -1, masterfd;
  519.      bool error = false;
  520.      int init;
  521. @@ -2506,8 +2493,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
  522.           * anything whether the index type is sorted or not.
  523.           */
  524.          snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, index_type);
  525. -        file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path));
  526. -        fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  527. +        fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  528.          if (fd < 0)
  529.          {
  530.              logf("%s open fail", buf);
  531. @@ -2527,21 +2513,18 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
  532.          }
  533.      }
  534.  
  535. -    file = get_user_file_path(TAGCACHE_FILE_MASTER,
  536. -                                            IS_FILE|NEED_WRITE,
  537. -                                            buf, sizeof(buf));
  538.      /* Loading the tag lookup file as "master file". */
  539.      logf("Loading index file");
  540. -    masterfd = open(file, O_RDWR);
  541. +    masterfd = open(TAGCACHE_FILE_MASTER, O_RDWR);
  542.  
  543.      if (masterfd < 0)
  544.      {
  545.          logf("Creating new DB");
  546. -        masterfd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  547. +        masterfd = open(TAGCACHE_FILE_MASTER, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  548.  
  549.          if (masterfd < 0)
  550.          {
  551. -            logf("Failure to create index file (%s)", file);
  552. +            logf("Failure to create index file (%s)", TAGCACHE_FILE_MASTER);
  553.              close(fd);
  554.              return -2;
  555.          }
  556. @@ -2849,8 +2832,6 @@ static bool commit(void)
  557.  {
  558.      struct tagcache_header tch;
  559.      struct master_header   tcmh;
  560. -    char path[MAX_PATH];
  561. -    const char *file;
  562.      int i, len, rc;
  563.      int tmpfd;
  564.      int masterfd;
  565. @@ -2864,10 +2845,7 @@ static bool commit(void)
  566.      while (write_lock)
  567.          sleep(1);
  568.  
  569. -    file = get_user_file_path(TAGCACHE_FILE_TEMP,
  570. -                            IS_FILE|NEED_WRITE, path, sizeof(path));
  571. -
  572. -    tmpfd = open(file, O_RDONLY);
  573. +    tmpfd = open(TAGCACHE_FILE_TEMP, O_RDONLY);
  574.      if (tmpfd < 0)
  575.      {
  576.          logf("nothing to commit");
  577. @@ -2883,7 +2861,7 @@ static bool commit(void)
  578.      {
  579.          logf("incorrect tmpheader");
  580.          close(tmpfd);
  581. -        remove(file);
  582. +        remove(TAGCACHE_FILE_TEMP);
  583.          return false;
  584.      }
  585.  
  586. @@ -2891,7 +2869,7 @@ static bool commit(void)
  587.      {
  588.          logf("nothing to commit");
  589.          close(tmpfd);
  590. -        remove(file);
  591. +        remove(TAGCACHE_FILE_TEMP);
  592.          return true;
  593.      }
  594.  
  595. @@ -2899,8 +2877,7 @@ static bool commit(void)
  596.      tc_stat.ready = check_all_headers();
  597.      
  598.  #ifdef HAVE_EEPROM_SETTINGS
  599. -    remove(get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE,
  600. -                path, sizeof(path)));
  601. +    remove(TAGCACHE_STATEFILE);
  602.  #endif
  603.      
  604.      /* At first be sure to unload the ramcache! */
  605. @@ -2990,7 +2967,7 @@ static bool commit(void)
  606.      }
  607.      
  608.      close(tmpfd);
  609. -    remove(file);
  610. +    remove(TAGCACHE_FILE_TEMP);
  611.      
  612.      tc_stat.commit_step = 0;
  613.      
  614. @@ -3410,18 +3387,15 @@ bool tagcache_import_changelog(void)
  615.      struct tagcache_header tch;
  616.      int clfd;
  617.      long masterfd;
  618. -    char buf[MAX(MAX_PATH, 2048)];
  619. -    const char *file;
  620. +    char buf[2048];
  621.      
  622.      if (!tc_stat.ready)
  623.          return false;
  624.      
  625.      while (read_lock)
  626.          sleep(1);
  627. -
  628. -    file = get_user_file_path(TAGCACHE_FILE_CHANGELOG,
  629. -                                   IS_FILE|NEED_WRITE, buf, sizeof(buf));
  630. -    clfd = open(file, O_RDONLY);
  631. +    
  632. +    clfd = open(TAGCACHE_FILE_CHANGELOG, O_RDONLY);
  633.      if (clfd < 0)
  634.      {
  635.          logf("failure to open changelog");
  636. @@ -3463,8 +3437,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs)
  637.  {
  638.      struct master_header myhdr;
  639.      struct index_entry idx;
  640. -    const char *file;
  641. -    char buf[MAX(TAG_MAXLEN+32, MAX_PATH)];
  642. +    char buf[TAG_MAXLEN+32];
  643.      char temp[32];
  644.      int clfd;
  645.      int i, j;
  646. @@ -3476,9 +3449,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs)
  647.          return false;
  648.      
  649.      /* Initialize the changelog */
  650. -    file = get_user_file_path(TAGCACHE_FILE_CHANGELOG, IS_FILE | NEED_WRITE,
  651. -                              buf, sizeof(buf));
  652. -    clfd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  653. +    clfd = open(TAGCACHE_FILE_CHANGELOG, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  654.      if (clfd < 0)
  655.      {
  656.          logf("failure to open changelog");
  657. @@ -3796,15 +3767,11 @@ static bool allocate_tagcache(void)
  658.  static bool tagcache_dumpload(void)
  659.  {
  660.      struct statefile_header shdr;
  661. -    char path[MAX_PATH];
  662. -    const char *file;
  663.      int fd, rc;
  664.      long offpos;
  665.      int i;
  666. -
  667. -    file = get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE,
  668. -                                    path, sizeof(path));
  669. -    fd = open(file, O_RDONLY);
  670. +    
  671. +    fd = open(TAGCACHE_STATEFILE, O_RDONLY);
  672.      if (fd < 0)
  673.      {
  674.          logf("no tagcache statedump");
  675. @@ -3850,16 +3817,12 @@ static bool tagcache_dumpload(void)
  676.  static bool tagcache_dumpsave(void)
  677.  {
  678.      struct statefile_header shdr;
  679. -    char path[MAX_PATH];
  680. -    const char *file;
  681.      int fd;
  682.      
  683.      if (!tc_stat.ramcache)
  684.          return false;
  685.      
  686. -    file = get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE,
  687. -                                    path, sizeof(path));
  688. -    fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  689. +    fd = open(TAGCACHE_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  690.      if (fd < 0)
  691.      {
  692.          logf("failed to create a statedump");
  693. @@ -3885,8 +3848,7 @@ static bool load_tagcache(void)
  694.      long bytesleft = tc_stat.ramcache_allocated;
  695.      struct index_entry *idx;
  696.      int rc, fd;
  697. -    char *p, path[MAX_PATH];
  698. -    const char *file;
  699. +    char *p;
  700.      int i, tag;
  701.  
  702.  # ifdef HAVE_DIRCACHE
  703. @@ -3897,11 +3859,8 @@ static bool load_tagcache(void)
  704.  # endif
  705.      
  706.      logf("loading tagcache to ram...");
  707. -
  708. -    file = get_user_file_path(TAGCACHE_FILE_MASTER,
  709. -                              IS_FILE|NEED_WRITE,
  710. -                              path, sizeof(path));
  711. -    fd = open(file, O_RDONLY);
  712. +    
  713. +    fd = open(TAGCACHE_FILE_MASTER, O_RDONLY);
  714.      if (fd < 0)
  715.      {
  716.          logf("tagcache open failed");
  717. @@ -4111,14 +4070,12 @@ static bool load_tagcache(void)
  718.  static bool check_deleted_files(void)
  719.  {
  720.      int fd;
  721. -    char buf[TAG_MAXLEN+32], path[MAX_PATH];
  722. -    const char *file;
  723. +    char buf[TAG_MAXLEN+32];
  724.      struct tagfile_entry tfe;
  725.      
  726.      logf("reverse scan...");
  727.      snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag_filename);
  728. -    file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path));
  729. -    fd = open(file, O_RDONLY);
  730. +    fd = open(buf, O_RDONLY);
  731.      
  732.      if (fd < 0)
  733.      {
  734. @@ -4278,8 +4235,6 @@ void tagcache_build(const char *path)
  735.  {
  736.      struct tagcache_header header;
  737.      bool ret;
  738. -    char buf[MAX_PATH];
  739. -    const char *file;
  740.  
  741.      curpath[0] = '\0';
  742.      data_size = 0;
  743. @@ -4292,21 +4247,19 @@ void tagcache_build(const char *path)
  744.  #endif
  745.      
  746.      logf("updating tagcache");
  747. -
  748. -    file = get_user_file_path(TAGCACHE_FILE_TEMP,
  749. -                                    IS_FILE|NEED_WRITE, buf, sizeof(buf));
  750.      
  751. -
  752. -    if (file_exists(file))
  753. +    cachefd = open(TAGCACHE_FILE_TEMP, O_RDONLY);
  754. +    if (cachefd >= 0)
  755.      {
  756.          logf("skipping, cache already waiting for commit");
  757. +        close(cachefd);
  758.          return ;
  759.      }
  760.      
  761. -    cachefd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0666);
  762. +    cachefd = open(TAGCACHE_FILE_TEMP, O_RDWR | O_CREAT | O_TRUNC, 0666);
  763.      if (cachefd < 0)
  764.      {
  765. -        logf("master file open failed: %s", file);
  766. +        logf("master file open failed: %s", TAGCACHE_FILE_TEMP);
  767.          return ;
  768.      }
  769.  
  770. @@ -4350,7 +4303,7 @@ void tagcache_build(const char *path)
  771.  #endif
  772.      if (commit())
  773.      {
  774. -        remove(file);
  775. +        remove(TAGCACHE_FILE_TEMP);
  776.          logf("tagcache built!");
  777.      }
  778.  #ifdef __PCTOOL__
  779. @@ -4395,12 +4348,7 @@ void tagcache_unload_ramcache(void)
  780.  {
  781.      tc_stat.ramcache = false;
  782.      /* Just to make sure there is no statefile present. */
  783. -
  784. -#if 0
  785. -    char path[MAX_PATH];
  786. -    remove(get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE,
  787. -                path, sizeof(path)));
  788. -#endif
  789. +    // remove(TAGCACHE_STATEFILE);
  790.  }
  791.  #endif
  792.  
  793. @@ -4409,7 +4357,6 @@ static void tagcache_thread(void)
  794.  {
  795.      struct queue_event ev;
  796.      bool check_done = false;
  797. -    char path[MAX_PATH];
  798.  
  799.      /* If the previous cache build/update was interrupted, commit
  800.       * the changes first in foreground. */
  801. @@ -4426,8 +4373,7 @@ static void tagcache_thread(void)
  802.          check_done = tagcache_dumpload();
  803.      }
  804.  
  805. -    remove(get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE,
  806. -                path, sizeof(path)));
  807. +    remove(TAGCACHE_STATEFILE);
  808.  # endif
  809.      
  810.      /* Allocate space for the tagcache if found on disk. */
  811. @@ -4460,8 +4406,7 @@ static void tagcache_thread(void)
  812.              
  813.              case Q_REBUILD:
  814.                  remove_files();
  815. -                remove(get_user_file_path(TAGCACHE_FILE_TEMP,
  816. -                                IS_FILE|NEED_WRITE, path, sizeof(path)));
  817. +                remove(TAGCACHE_FILE_TEMP);
  818.                  tagcache_build("/");
  819.                  break;
  820.              
  821. diff --git a/apps/tree.c b/apps/tree.c
  822. index 86238c5..98880f0 100644
  823. --- a/apps/tree.c
  824. +++ b/apps/tree.c
  825. @@ -261,8 +261,7 @@ static int tree_voice_cb(int selected_item, void * data)
  826.  
  827.  bool check_rockboxdir(void)
  828.  {
  829. -    char path[MAX_PATH];
  830. -    if(!dir_exists(get_user_file_path(ROCKBOX_DIR, 0, path, sizeof(path))))
  831. +    if(!dir_exists(ROCKBOX_DIR))
  832.      {   /* No need to localise this message.
  833.             If .rockbox is missing, it wouldn't work anyway */
  834.          int i;
  835. diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c
  836. index 509743b..e8a5e7c 100644
  837. --- a/firmware/common/dircache.c
  838. +++ b/firmware/common/dircache.c
  839. @@ -89,13 +89,10 @@ static int fdbind_idx = 0;
  840.   */
  841.  static int open_dircache_file(unsigned flags, int permissions)
  842.  {
  843. -    char path[MAX_PATH];
  844. -    const char *file = get_user_file_path(DIRCACHE_FILE, IS_FILE|NEED_WRITE,
  845. -                                path, sizeof(path));
  846.      if (permissions != 0)
  847. -        return open(file, flags, permissions);
  848. +        return open(DIRCACHE_FILE, flags, permissions);
  849.  
  850. -    return open(file, flags);
  851. +    return open(DIRCACHE_FILE, flags);
  852.  }
  853.  
  854.  /**
  855. @@ -103,9 +100,7 @@ static int open_dircache_file(unsigned flags, int permissions)
  856.   */
  857.  static int remove_dircache_file(void)
  858.  {
  859. -    char path[MAX_PATH];
  860. -    return remove(get_user_file_path(DIRCACHE_FILE, IS_FILE|NEED_WRITE,
  861. -                                path, sizeof(path)));
  862. +    return remove(DIRCACHE_FILE);
  863.  }
  864.  #endif
  865.  /**
  866. diff --git a/firmware/common/rbpaths.c b/firmware/common/rbpaths.c
  867. index b63586c..7f85bcf 100644
  868. --- a/firmware/common/rbpaths.c
  869. +++ b/firmware/common/rbpaths.c
  870. @@ -22,6 +22,7 @@
  871.  
  872.  #include <stdio.h> /* snprintf */
  873.  #include <stdlib.h>
  874. +#include <stdarg.h>
  875.  #include "rbpaths.h"
  876.  #include "file.h" /* MAX_PATH */
  877.  #include "dir.h"
  878. @@ -29,6 +30,10 @@
  879.  #include "string-extra.h"
  880.  #include "filefuncs.h"
  881.  
  882. +#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
  883. +#undef open
  884. +#define _open open
  885. +#endif
  886.  
  887.  void paths_init(void)
  888.  {
  889. @@ -42,14 +47,28 @@ void paths_init(void)
  890.  #endif
  891.  }
  892.  
  893. -const char* get_user_file_path(const char *path,
  894. +static bool try_path(const char* filename, unsigned flags)
  895. +{
  896. +    if (flags & IS_FILE)
  897. +    {
  898. +        if (file_exists(filename))
  899. +            return true;
  900. +    }
  901. +    else
  902. +    {
  903. +        if (dir_exists(filename))
  904. +            return true;
  905. +    }
  906. +    return false;
  907. +}
  908. +
  909. +const char* _get_user_file_path(const char *path,
  910.                                 unsigned flags,
  911.                                 char* buf,
  912.                                 const size_t bufsize)
  913.  {
  914.      const char *ret = path;
  915.      const char *pos = path;
  916. -    printf("%s(): looking for %s\n", __func__, path);
  917.      /* replace ROCKBOX_DIR in path with $HOME/.config/rockbox.org */
  918.      pos += ROCKBOX_DIR_LEN;
  919.      if (*pos == '/') pos += 1;
  920. @@ -66,27 +85,38 @@ const char* get_user_file_path(const char *path,
  921.       * write access is needed */
  922.      if (flags & NEED_WRITE)
  923.          ret = buf;
  924. -    else
  925. +    else if (try_path(buf, flags))
  926. +        ret = buf;
  927. +        
  928. +    if (ret != buf) /* not found in $HOME, try ROCKBOX_BASE_DIR, !NEED_WRITE only */
  929.      {
  930. -        if (flags & IS_FILE)
  931. -        {
  932. -            if (file_exists(buf))
  933. -                ret = buf;
  934. -        }
  935. -        else
  936. -        {
  937. -            if (dir_exists(buf))
  938. -                ret = buf;
  939. -        }
  940. -    }
  941. +        if (snprintf(buf, bufsize, ROCKBOX_SHARE_PATH "/%s", pos) >= (int)bufsize)
  942. +            return NULL;
  943.  
  944. -    /* make a copy if we're about to return the path*/
  945. -    if (UNLIKELY((flags & FORCE_BUFFER_COPY) && (ret != buf)))
  946. -    {
  947. -        strlcpy(buf, ret, bufsize);
  948. -        ret = buf;
  949. +        if (try_path(buf, flags))
  950. +            ret = buf;
  951.      }
  952.  
  953. -    printf("%s(): %s\n", __func__, ret);
  954.      return ret;
  955.  }
  956. +
  957. +int application_open(const char *name, int o, ...)
  958. +{
  959. +    char realpath[MAX_PATH];
  960. +    va_list ap;
  961. +    int fd;
  962. +    
  963. +    if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
  964. +    {
  965. +        int flags = IS_FILE;
  966. +        if (o & (O_CREAT|O_RDWR))
  967. +            flags |= NEED_WRITE;
  968. +        name = _get_user_file_path(name, flags, realpath, sizeof(realpath));
  969. +    }
  970. +    va_start(ap, o);
  971. +    fd = _open(name, o, ap);
  972. +    va_end(ap);
  973. +    
  974. +    return fd;
  975. +    
  976. +}
  977. diff --git a/firmware/export/rbpaths.h b/firmware/export/rbpaths.h
  978. index cd87888..1bc2be1 100644
  979. --- a/firmware/export/rbpaths.h
  980. +++ b/firmware/export/rbpaths.h
  981. @@ -32,10 +32,6 @@
  982.  #define NEED_WRITE          (1<<0)
  983.  /* file or directory? */
  984.  #define IS_FILE             (1<<1)
  985. -/* make sure the path is copied into the passed buffer (it may return
  986. - * the passed path directly otherwise, e.g. always on target builds) */
  987. -#define FORCE_BUFFER_COPY   (1<<2)
  988. -
  989.  
  990.  
  991.  /* name of directory where configuration, fonts and other data
  992. @@ -67,32 +63,17 @@
  993.  #define REC_BASE_DIR        "/"
  994.  #define PLAYLIST_CATALOG_DEFAULT_DIR "/Playlists"
  995.  
  996. -#ifndef PLUGIN
  997. -static inline __attribute__((always_inline)) const char* get_user_file_path(const char *path,
  998. -                               unsigned flags,
  999. -                               char* buf,
  1000. -                               const size_t bufsize)
  1001. -{
  1002. -    if (flags & FORCE_BUFFER_COPY)
  1003. -    {
  1004. -        strlcpy(buf, path, bufsize);
  1005. -        return buf;
  1006. -    }
  1007. -    return path;
  1008. -}
  1009. -#endif
  1010. -
  1011.  #define paths_init()
  1012.  #else /* application */
  1013.  
  1014. -#define PLUGIN_DIR          ROCKBOX_LIBRARY_PATH "/rockbox/rocks"
  1015. -#define CODECS_DIR          ROCKBOX_LIBRARY_PATH "/rockbox/codecs"
  1016. +#define PLUGIN_DIR          ROCKBOX_LIBRARY_PATH "/rocks"
  1017. +#define CODECS_DIR          ROCKBOX_LIBRARY_PATH "/codecs"
  1018.  
  1019.  #define REC_BASE_DIR        ROCKBOX_DIR  "/"
  1020.  #define PLAYLIST_CATALOG_DEFAULT_DIR ROCKBOX_DIR "/Playlists"
  1021.  
  1022.  extern void paths_init(void);
  1023. -extern const char* get_user_file_path(const char *path,
  1024. +extern const char* _get_user_file_path(const char *path,
  1025.                                 unsigned flags,
  1026.                                 char* buf,
  1027.                                 const size_t bufsize);
  1028. diff --git a/firmware/font.c b/firmware/font.c
  1029. index e973108..cd74459 100644
  1030. --- a/firmware/font.c
  1031. +++ b/firmware/font.c
  1032. @@ -613,11 +613,7 @@ void glyph_cache_save(struct font* pf)
  1033.          pf = &font_ui;
  1034.      if (pf->fd >= 0 && pf == &font_ui)
  1035.      {
  1036. -        char path[MAX_PATH];
  1037. -        const char *file = get_user_file_path(GLYPH_CACHE_FILE, IS_FILE|NEED_WRITE,
  1038. -                                       path, sizeof(path));
  1039. -
  1040. -        cache_fd = open(file, O_WRONLY|O_CREAT|O_TRUNC, 0666);
  1041. +        cache_fd = open(GLYPH_CACHE_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666);
  1042.          if (cache_fd < 0)
  1043.              return;
  1044.  
  1045. @@ -678,7 +674,6 @@ static void glyph_cache_load(struct font* pf)
  1046.          int i, size;
  1047.          unsigned char tmp[2];
  1048.          unsigned short ch;
  1049. -        char path[MAX_PATH];
  1050.          unsigned short glyphs[MAX_SORT];
  1051.          unsigned short glyphs_lru_order[MAX_SORT];
  1052.          int glyph_file_skip=0, glyph_file_size=0;
  1053. @@ -687,8 +682,7 @@ static void glyph_cache_load(struct font* pf)
  1054.          if ( sort_size > MAX_SORT )
  1055.               sort_size = MAX_SORT;
  1056.  
  1057. -        fd = open(get_user_file_path(GLYPH_CACHE_FILE, IS_FILE|NEED_WRITE,
  1058. -                                     path, sizeof(path)), O_RDONLY|O_BINARY);
  1059. +        fd = open(GLYPH_CACHE_FILE, O_RDONLY|O_BINARY);
  1060.          if (fd >= 0) {
  1061.              
  1062.              /* only read what fits */
  1063. diff --git a/firmware/include/file.h b/firmware/include/file.h
  1064. index 8711124..45dc277 100644
  1065. --- a/firmware/include/file.h
  1066. +++ b/firmware/include/file.h
  1067. @@ -38,7 +38,8 @@
  1068.  
  1069.  #if !defined(PLUGIN) && !defined(CODEC)
  1070.  #if (CONFIG_PLATFORM & PLATFORM_SDL)
  1071. -#define open(x, ...) sim_open(x, __VA_ARGS__)
  1072. +#define open(x, ...) application_open(x, __VA_ARGS__)
  1073. +#define _open(x, ...) sim_open(x, __VA_ARGS__)
  1074.  #define creat(x,m) sim_creat(x,m)
  1075.  #define remove(x) sim_remove(x)
  1076.  #define rename(x,y) sim_rename(x,y)
  1077. @@ -51,6 +52,10 @@
  1078.  #define close(x) sim_close(x)
  1079.  extern int sim_creat(const char *pathname, mode_t mode);
  1080.  extern int sim_open(const char *pathname, int flags, ...);
  1081. +int application_open(const char *name, int o, ...);
  1082. +#elif (CONFIG_PLATFORM & PLATFORM_ANDROID)
  1083. +#define open(x, ...) application_open(x, __VA_ARGS__)
  1084. +int application_open(const char *name, int o, ...);
  1085.  #endif
  1086.  
  1087.  typedef int (*open_func)(const char* pathname, int flags, ...);
  1088. diff --git a/firmware/load_code.c b/firmware/load_code.c
  1089. index 5b5307e..2337ee5 100644
  1090. --- a/firmware/load_code.c
  1091. +++ b/firmware/load_code.c
  1092. @@ -144,17 +144,15 @@ void *lc_open_from_mem(void *addr, size_t blob_size)
  1093.      for (i = 0; i < 10; i++)
  1094.      {
  1095.  #if (CONFIG_PLATFORM & PLATFORM_ANDROID)
  1096. -        /* we need that path fixed, since get_user_file_path()
  1097. +        /* we need that path fixed, since _get_user_file_path()
  1098.           * gives us the folder on the sdcard where we cannot load libraries
  1099.           * from (no exec permissions)
  1100.           */
  1101.          snprintf(temp_filename, sizeof(temp_filename),
  1102.                   "/data/data/org.rockbox/app_rockbox/libtemp_binary_%d.so", i);
  1103.  #else
  1104. -        char name[MAX_PATH];
  1105. -        const char *_name = get_user_file_path(ROCKBOX_DIR, NEED_WRITE, name, sizeof(name));
  1106.          snprintf(temp_filename, sizeof(temp_filename),
  1107. -                 "%s/libtemp_binary_%d.dll", _name, i);
  1108. +                 ROCKBOX_DIR "/libtemp_binary_%d.dll", i);
  1109.  #endif
  1110.          fd = open(temp_filename, O_WRONLY|O_CREAT|O_TRUNC, 0700);
  1111.          if (fd >= 0)
  1112. diff --git a/firmware/target/hosted/android/fs-android.c b/firmware/target/hosted/android/fs-android.c
  1113. index 5209458..b3cda51 100644
  1114. --- a/firmware/target/hosted/android/fs-android.c
  1115. +++ b/firmware/target/hosted/android/fs-android.c
  1116. @@ -29,6 +29,7 @@
  1117.  #include "dir-target.h"
  1118.  #include "file.h"
  1119.  #include "dir.h"
  1120. +#include "rbpaths.h"
  1121.  
  1122.  
  1123.  long filesize(int fd)
  1124. @@ -61,7 +62,15 @@ struct __dir {
  1125.  
  1126.  DIR* _opendir(const char *name)
  1127.  {
  1128. -    char *buf = malloc(sizeof(struct __dir) + strlen(name)+1);
  1129. +    char temp[MAX_PATH];
  1130. +    char *buf;
  1131. +    
  1132. +    if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
  1133. +    {
  1134. +        name = _get_user_file_path(name, 0, temp, sizeof(temp));
  1135. +    }
  1136. +    
  1137. +    buf = malloc(sizeof(struct __dir) + strlen(name)+1);
  1138.      if (!buf)
  1139.          return NULL;
  1140.  
  1141. diff --git a/tools/configure b/tools/configure
  1142. index 5f148d8..84456ff 100755
  1143. --- a/tools/configure
  1144. +++ b/tools/configure
  1145. @@ -21,7 +21,6 @@ use_bootchart="#undef DO_BOOTCHART"
  1146.  scriptver=`echo '$Revision$' | sed -e 's:\\$::g' -e 's/Revision: //'`
  1147.  
  1148.  rbdir="/.rockbox"
  1149. -need_full_path=
  1150.  bindir=
  1151.  libdir=
  1152.  bindir_full=
  1153. @@ -88,13 +87,13 @@ app_get_platform() {
  1154.      # setup files and paths depending on the platform
  1155.      if [ "$app_platform" = "sdl" ]; then
  1156.          if [ -z "$PREFIX" ]; then
  1157. -            rbdir="/usr/local/share/rockbox"
  1158. +            sharedir="/usr/local/share/rockbox"
  1159.              bindir="/usr/local/bin"
  1160.              bindir_full=$bindir
  1161. -            libdir="/usr/local/lib"
  1162. +            libdir="/usr/local/lib/rockbox"
  1163.              libdir_full=$libdir
  1164.          else
  1165. -            rbdir=`realpath $PREFIX/share/rockbox`
  1166. +            sharedir=`realpath $PREFIX/share/rockbox`
  1167.              bindir="$PREFIX/bin"
  1168.              libdir="$PREFIX/lib"
  1169.              if [ -d bindir ]; then
  1170. @@ -120,10 +119,10 @@ app_get_platform() {
  1171.              echo "environment variable point to the root directory of the Android NDK."
  1172.              exit
  1173.          fi
  1174. -        rbdir="/data/data/org.rockbox/app_rockbox/rockbox"
  1175. +        sharedir="/data/data/org.rockbox/.rockbox"
  1176.          bindir="/data/data/org.rockbox/lib"
  1177.          bindir_full=$bindir
  1178. -        libdir="/data/data/org.rockbox/app_rockbox"
  1179. +        libdir="/data/data/org.rockbox/.rockbox"
  1180.          libdir_full=$libdir
  1181.          output="librockbox.so"
  1182.          bootoutput="librockbox.so"
  1183. @@ -2721,7 +2720,6 @@ fi
  1184.      modelname="application"
  1185.      target="-DAPPLICATION"
  1186.  
  1187. -    need_full_path="yes"
  1188.      app_get_platform
  1189.  
  1190.      memory=8
  1191. @@ -3119,15 +3117,11 @@ else
  1192.  fi
  1193.  
  1194.  if [ "$ARG_RBDIR" ]; then
  1195. -  if [ "$need_full_path" = "yes" ]; then
  1196. -    rbdir=`realpath $ARG_RBDIR`
  1197. -  else # prepend '/' if needed
  1198.      if [ -z `echo $ARG_RBDIR | grep '^/'` ]; then
  1199.          rbdir="/"$ARG_RBDIR
  1200.      else
  1201.          rbdir=$ARG_RBDIR
  1202.      fi
  1203. -  fi
  1204.    echo "Using alternate rockbox dir: ${rbdir}"
  1205.  fi
  1206.  
  1207. @@ -3138,6 +3132,7 @@ sed > autoconf.h \
  1208.   -e "s<@config_rtc@<$config_rtc<g" \
  1209.   -e "s<@have_rtc_alarm@<$have_rtc_alarm<g" \
  1210.   -e "s<@RBDIR@<${rbdir}<g" \
  1211. + -e "s<@sharepath@<${sharedir}<g" \
  1212.   -e "s<@binpath@<${bindir_full}<g" \
  1213.   -e "s<@libpath@<${libdir_full}<g" \
  1214.   -e "s<@have_backlight@<$have_backlight<g" \
  1215. @@ -3178,6 +3173,7 @@ sed > autoconf.h \
  1216.  
  1217.  /* root of Rockbox */
  1218.  #define ROCKBOX_DIR "@RBDIR@"
  1219. +#define ROCKBOX_SHARE_PATH "@sharepath@"
  1220.  #define ROCKBOX_BINARY_PATH "@binpath@"
  1221.  #define ROCKBOX_LIBRARY_PATH "@libpath@"
  1222.  
  1223. @@ -3306,6 +3302,7 @@ sed > Makefile \
  1224.   -e "s<@RBDIR@<${rbdir}<g" \
  1225.   -e "s<@binpath@<${bindir}<g" \
  1226.   -e "s<@libpath@<${libdir}<g" \
  1227. + -e "s<@sharepath@<${sharedir}<g" \
  1228.   -e "s<@PREFIX@<$PREFIX<g" \
  1229.   -e "s<@CMDLINE@<$cmdline<g" \
  1230.   -e "s<@SDLCONFIG@<$sdl<g" \
  1231. @@ -3373,6 +3370,7 @@ export ENC_OPTS=@ENC_OPTS@
  1232.  export ENCODER=@ENCODER@
  1233.  export USE_ELF=@USE_ELF@
  1234.  export RBDIR=@RBDIR@
  1235. +export ROCKBOX_SHARE_PATH=@sharepath@
  1236.  export ROCKBOX_BINARY_PATH=@binpath@
  1237.  export ROCKBOX_LIBRARY_PATH=@libpath@
  1238.  export SDLCONFIG=@SDLCONFIG@
  1239. diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
  1240. index 3591905..c661ea2 100644
  1241. --- a/uisimulator/common/io.c
  1242. +++ b/uisimulator/common/io.c
  1243. @@ -293,6 +293,11 @@ static const char *get_sim_pathname(const char *name)
  1244.  MYDIR *sim_opendir(const char *name)
  1245.  {
  1246.      DIR_T *dir;
  1247. +    char realpath[MAX_PATH];
  1248. +    if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
  1249. +    {
  1250. +        name = _get_user_file_path(name, 0, realpath, sizeof(realpath));
  1251. +    }
  1252.  
  1253.      dir = (DIR_T *) OPENDIR(get_sim_pathname(name));
clone this paste RAW Paste Data