summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2005-10-07 17:38:05 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2005-10-07 17:38:05 +0000
commitab78b0468088e9011273edc32d59145db9030a7e (patch)
tree5dc785c1f3eec456592b210d1aad39b6f5cf6880 /apps
parent86e31d5558704b8ab83d2e5d5c9dca691a5f768a (diff)
downloadrockbox-ab78b0468088e9011273edc32d59145db9030a7e.tar.gz
rockbox-ab78b0468088e9011273edc32d59145db9030a7e.zip
Implemented directory caching. No more waiting for disk to spin up while
browsing when cache is enabled (system -> disk -> enable directory cache). Cache building on boot is transparent except the first boot. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7588 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/filetree.c21
-rw-r--r--apps/lang/english.lang18
-rw-r--r--apps/lang/finnish.lang18
-rw-r--r--apps/main.c37
-rw-r--r--apps/settings.c6
-rw-r--r--apps/settings.h5
-rw-r--r--apps/settings_menu.c22
-rw-r--r--apps/tree.c27
8 files changed, 137 insertions, 17 deletions
diff --git a/apps/filetree.c b/apps/filetree.c
index 8ecdc0c93d..37a66c60ee 100644
--- a/apps/filetree.c
+++ b/apps/filetree.c
@@ -38,6 +38,7 @@
#include "plugin.h"
#include "rolo.h"
#include "sprintf.h"
+#include "dircache.h"
#ifndef SIMULATOR
static int boot_size = 0;
@@ -75,11 +76,11 @@ int ft_build_playlist(struct tree_context* c, int start_index)
static void check_file_thumbnails(struct tree_context* c)
{
int i;
- struct dirent *entry;
+ struct dircache_entry *entry;
struct entry* dircache = c->dircache;
- DIR *dir;
+ DIRCACHED *dir;
- dir = opendir(c->currdir);
+ dir = opendir_cached(c->currdir);
if(!dir)
return;
@@ -100,7 +101,7 @@ static void check_file_thumbnails(struct tree_context* c)
}
}
- while((entry = readdir(dir)) != 0) /* walk directory */
+ while((entry = readdir_cached(dir)) != 0) /* walk directory */
{
int ext_pos;
@@ -126,7 +127,7 @@ static void check_file_thumbnails(struct tree_context* c)
}
}
}
- closedir(dir);
+ closedir_cached(dir);
}
/* support function for qsort() */
@@ -191,12 +192,12 @@ int ft_load(struct tree_context* c, const char* tempdir)
{
int i;
int name_buffer_used = 0;
- DIR *dir;
+ DIRCACHED *dir;
if (tempdir)
- dir = opendir(tempdir);
+ dir = opendir_cached(tempdir);
else
- dir = opendir(c->currdir);
+ dir = opendir_cached(c->currdir);
if(!dir)
return -1; /* not a directory */
@@ -205,7 +206,7 @@ int ft_load(struct tree_context* c, const char* tempdir)
for ( i=0; i < global_settings.max_files_in_dir; i++ ) {
int len;
- struct dirent *entry = readdir(dir);
+ struct dircache_entry *entry = readdir_cached(dir);
struct entry* dptr =
(struct entry*)(c->dircache + i * sizeof(struct entry));
if (!entry)
@@ -292,7 +293,7 @@ int ft_load(struct tree_context* c, const char* tempdir)
}
c->filesindir = i;
c->dirlength = i;
- closedir(dir);
+ closedir_cached(dir);
qsort(c->dircache,i,sizeof(struct entry),compare);
diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index 97f714609d..fbba81250f 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -3298,3 +3298,21 @@ desc: use track gain if shuffle mode is on, album gain otherwise
eng: "Track gain if shuffling"
voice: "Track gain if shuffling"
new:
+
+id: LANG_DIRCACHE_ENABLE
+desc: in directory cache settings
+eng: "Enable directory cache"
+voice: "Enable directory cache"
+new:
+
+id: LANG_DIRCACHE_REBOOT
+desc: when activating directory cache
+eng: "Please reboot to enable the cache"
+voice: "Please reboot to enable the cache"
+new:
+
+id: LANG_DIRCACHE_BUILDING
+desc: when booting up and rebuilding the cache
+eng: "Scanning disk..."
+voice: ""
+new:
diff --git a/apps/lang/finnish.lang b/apps/lang/finnish.lang
index 24c46b3bce..1e6a7eb52e 100644
--- a/apps/lang/finnish.lang
+++ b/apps/lang/finnish.lang
@@ -3329,3 +3329,21 @@ desc: repeat one song
eng: "A-B"
voice: "A-B"
new: "A-B"
+
+id: LANG_DIRCACHE_ENABLE
+desc: in directory cache settings
+eng: "Enable directory cache"
+voice: "Hakemistopuun lataus muistiin"
+new: "Hakemistopuun lataus muistiin"
+
+id: LANG_DIRCACHE_REBOOT
+desc: when activating directory cache
+eng: "Please reboot to enable the cache"
+voice: "Käynnistä laite uudelleen"
+new: "Käynnistä laite uudelleen"
+
+id: LANG_DIRCACHE_BUILDING
+desc: when booting up and rebuilding the cache
+eng: "Scanning disk..."
+voice: ""
+new: "Ladataan hakemistopuu..."
diff --git a/apps/main.c b/apps/main.c
index c272dba57e..73bf614cb3 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -59,6 +59,9 @@
#include "plugin.h"
#include "misc.h"
#include "database.h"
+#include "dircache.h"
+#include "lang.h"
+#include "string.h"
#if (CONFIG_CODEC == SWCODEC)
#include "pcmbuf.h"
@@ -92,6 +95,33 @@ void app_main(void)
browse_root();
}
+#ifdef HAVE_DIRCACHE
+void init_dircache(void)
+{
+ int font_w, font_h;
+
+ dircache_init();
+ if (global_settings.dircache)
+ {
+ /* Print "Scanning disk..." to the display. */
+ lcd_getstringsize("A", &font_w, &font_h);
+ lcd_putsxy((LCD_WIDTH/2) - ((strlen(str(LANG_DIRCACHE_BUILDING))*font_w)/2),
+ LCD_HEIGHT-font_h*3, str(LANG_DIRCACHE_BUILDING));
+ lcd_update();
+
+ dircache_build(global_settings.dircache_size);
+
+ /* Clean the text when we are done. */
+ lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
+ lcd_fillrect(0, LCD_HEIGHT-font_h*3, LCD_WIDTH, font_h);
+ lcd_set_drawmode(DRMODE_SOLID);
+ lcd_update();
+ }
+}
+#else
+# define init_dircache(...)
+#endif
+
#ifdef SIMULATOR
void init(void)
@@ -110,6 +140,7 @@ void init(void)
settings_calc_config_sector();
settings_load(SETTINGS_ALL);
settings_apply();
+ init_dircache();
sleep(HZ/2);
tree_init();
playlist_init();
@@ -261,13 +292,15 @@ void init(void)
}
}
+ settings_calc_config_sector();
+ settings_load(SETTINGS_ALL);
+ init_dircache();
+
/* On software codec platforms we have to init audio before
calling audio_set_buffer_margin(). */
#if (CONFIG_CODEC == SWCODEC)
audio_init();
#endif
- settings_calc_config_sector();
- settings_load(SETTINGS_ALL);
settings_apply();
status_init();
diff --git a/apps/settings.c b/apps/settings.c
index 5495ca7098..6935f35eb5 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -67,6 +67,8 @@
#include "version.h"
#include "rtc.h"
#include "sound.h"
+#include "dircache.h"
+
#if CONFIG_CODEC == MAS3507D
void dac_line_in(bool enable);
#endif
@@ -439,6 +441,10 @@ static const struct bit_entry hd_bits[] =
{8 | SIGNED, S_O(replaygain_preamp), 0, "replaygain preamp", NULL },
{2, S_O(beep), 0, "off,weak,moderate,strong", NULL },
#endif
+#ifdef HAVE_DIRCACHE
+ {1, S_O(dircache), false, "dircache", off_on },
+ {22, S_O(dircache_size), 0, NULL, NULL },
+#endif
/* If values are just added to the end, no need to bump the version. */
/* new stuff to be added at the end */
diff --git a/apps/settings.h b/apps/settings.h
index dafa7bcd34..99254e377f 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -23,6 +23,7 @@
#include <stdbool.h>
#include "config.h"
#include "file.h"
+#include "dircache.h"
#include "timefuncs.h"
#include "abrepeat.h"
@@ -339,6 +340,10 @@ struct user_settings
int replaygain_preamp; /* scale replaygained tracks by this */
int beep; /* system beep volume when changing tracks etc. */
#endif
+#ifdef HAVE_DIRCACHE
+ bool dircache; /* enable directory cache */
+ int dircache_size; /* directory cache structure last size, 22 bits */
+#endif
};
enum optiontype { INT, BOOL };
diff --git a/apps/settings_menu.c b/apps/settings_menu.c
index 8a1fa72415..6ad5274f0f 100644
--- a/apps/settings_menu.c
+++ b/apps/settings_menu.c
@@ -49,6 +49,8 @@
#include "abrepeat.h"
#include "power.h"
#include "database.h"
+#include "dir.h"
+#include "dircache.h"
#ifdef HAVE_LCD_BITMAP
#include "peakmeter.h"
@@ -1259,6 +1261,23 @@ static bool beep(void)
}
#endif
+#ifdef HAVE_DIRCACHE
+static bool dircache(void)
+{
+ bool result = set_bool(str(LANG_DIRCACHE_ENABLE),
+ &global_settings.dircache);
+
+ if (!dircache_is_enabled() && global_settings.dircache)
+ splash(HZ*2, true, str(LANG_DIRCACHE_REBOOT));
+
+ if (!result)
+ dircache_disable();
+
+ return result;
+}
+
+#endif /* HAVE_DIRCACHE */
+
static bool playback_settings_menu(void)
{
int m;
@@ -1574,6 +1593,9 @@ static bool disk_settings_menu(void)
#ifdef HAVE_ATA_POWER_OFF
{ ID2P(LANG_POWEROFF), poweroff },
#endif
+#ifdef HAVE_DIRCACHE
+ { ID2P(LANG_DIRCACHE_ENABLE), dircache },
+#endif
};
m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
diff --git a/apps/tree.c b/apps/tree.c
index a52d453081..bfaf7b8304 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -61,6 +61,7 @@
#include "dbtree.h"
#include "recorder/recording.h"
#include "rtc.h"
+#include "dircache.h"
#ifdef HAVE_LCD_BITMAP
#include "widgets.h"
@@ -1324,7 +1325,7 @@ static int plsize = 0;
static bool add_dir(char* dirname, int len, int fd)
{
bool abort = false;
- DIR* dir;
+ DIRCACHED* dir;
/* check for user abort */
#ifdef BUTTON_STOP
@@ -1334,14 +1335,14 @@ static bool add_dir(char* dirname, int len, int fd)
#endif
return true;
- dir = opendir(dirname);
+ dir = opendir_cached(dirname);
if(!dir)
return true;
while (true) {
- struct dirent *entry;
+ struct dircache_entry *entry;
- entry = readdir(dir);
+ entry = readdir_cached(dir);
if (!entry)
break;
if (entry->attribute & ATTR_DIRECTORY) {
@@ -1409,7 +1410,7 @@ static bool add_dir(char* dirname, int len, int fd)
}
}
}
- closedir(dir);
+ closedir_cached(dir);
return abort;
}
@@ -1634,10 +1635,26 @@ void tree_flush(void)
{
rundb_shutdown();
tagdb_shutdown();
+#ifdef HAVE_DIRCACHE
+ if (global_settings.dircache)
+ {
+ global_settings.dircache_size = dircache_get_cache_size();
+ dircache_disable();
+ }
+ else
+ {
+ global_settings.dircache_size = 0;
+ }
+ settings_save();
+#endif
}
void tree_restore(void)
{
tagdb_init();
rundb_init();
+#ifdef HAVE_DIRCACHE
+ if (global_settings.dircache)
+ dircache_build(global_settings.dircache_size);
+#endif
}