summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/codecs.c2
-rw-r--r--apps/fileutils.c167
-rw-r--r--apps/fileutils.h42
-rw-r--r--apps/plugins/rockpaint.c10
-rw-r--r--apps/settings.c8
-rw-r--r--apps/settings.h16
-rw-r--r--apps/settings_menu.c4
-rw-r--r--apps/talk.c2
8 files changed, 230 insertions, 21 deletions
diff --git a/apps/codecs.c b/apps/codecs.c
index b4b8c9833a..f33957eba2 100644
--- a/apps/codecs.c
+++ b/apps/codecs.c
@@ -228,7 +228,7 @@ struct codec_api ci = {
void codec_get_full_path(char *path, const char *codec_fn)
{
/* Create full codec path */
- snprintf(path, MAX_PATH-1, ROCKBOX_DIR CODECS_DIR "/%s", codec_fn);
+ snprintf(path, MAX_PATH-1, CODECS_DIR "/%s", codec_fn);
}
int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
diff --git a/apps/fileutils.c b/apps/fileutils.c
new file mode 100644
index 0000000000..625a7b53c0
--- /dev/null
+++ b/apps/fileutils.c
@@ -0,0 +1,167 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2006 Jonathan Gordon
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "playlist.h"
+#include "filetree.h"
+#include "dir.h"
+#include "tree.h"
+#include "lang.h"
+#include "fileutils.h"
+#include "settings.h"
+#include "gui/splash.h"
+#include "action.h"
+#include "debug.h"
+
+#define MAX_DEPTH 32
+
+/**
+ RETURNS: DIRWALKER_RETURN_SUCCESS if it successfully went through the directory tree
+ DIRWALKER_RETURN_ERROR if it stopped for an error
+ DIRWALKER_RETURN_FORCED if it was told to stop by one of the callbacks, or user aborted
+**/
+int dirwalker(const char *start_dir, bool recurse, bool is_forward,
+ int (*folder_callback)(const char* dir, void *param),void* folder_param,
+ int (*file_callback)(const char* folder,const char* file,
+ const int file_attr,void *param),void* file_param)
+{
+ char folder[MAX_PATH+1];
+ int current_file_stack[MAX_DEPTH];
+ int stack_top = 0;
+
+ int result = DIRWALKER_RETURN_SUCCESS;
+ int num_files = 0;
+ int i;
+ char *s;
+ struct entry *files;
+ struct tree_context* tc = tree_get_context();
+ int dirfilter = *(tc->dirfilter);
+ int sort_dir = global_settings.sort_dir;
+
+ /* sort in another direction if previous dir is requested */
+ if(!is_forward){
+ int reverse_sort_dir[5] = {4,2,1,4,0};
+ global_settings.sort_dir = reverse_sort_dir[sort_dir];
+ }
+
+ /* use the tree browser dircache to load files */
+ *(tc->dirfilter) = SHOW_ALL;
+
+ /* setup stuff */
+ strcpy(folder, start_dir);
+ current_file_stack[0] = -1;
+
+ while (!result && (stack_top>=0) )
+ {
+ if (ft_load(tc, folder) < 0)
+ {
+ gui_syncsplash(HZ*2, true,"%s %s",folder,
+ str(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR));
+ result = DIRWALKER_RETURN_ERROR;
+ }
+
+ files = (struct entry*) tc->dircache;
+ num_files = tc->filesindir;
+
+ i = current_file_stack[stack_top--]+1;
+ while ( i<num_files )
+ {
+ /* user abort */
+ if (action_userabort(TIMEOUT_NOBLOCK))
+ {
+ result = DIRWALKER_RETURN_FORCED;
+ break;
+ }
+
+ if ((files[i].attr & ATTR_DIRECTORY) && recurse)
+ {
+ bool enter_dir = true;
+ strcat(folder,"/");
+ strcat(folder,files[i].name);
+ if (folder_callback)
+ {
+ switch (folder_callback(folder,folder_param))
+ {
+ case DIRWALKER_ERROR:
+ result = DIRWALKER_RETURN_ERROR;
+ enter_dir = false;
+ break;
+ case DIRWALKER_OK:
+ enter_dir = true;
+ break;
+ case DIRWALKER_IGNORE:
+ enter_dir = false;
+ break;
+ case DIRWALKER_QUIT:
+ result = DIRWALKER_RETURN_FORCED;
+ enter_dir = false;
+ break;
+ }
+ }
+ if (enter_dir)
+ {
+ current_file_stack[++stack_top] = i;
+
+ if(ft_load(tc, folder) < 0)
+ {
+ gui_syncsplash(HZ*2, true,"%s %s",folder,
+ str(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR));
+ result = DIRWALKER_RETURN_ERROR;
+ break;
+ }
+
+ files = (struct entry*) tc->dircache;
+ num_files = tc->filesindir;
+ i=0;
+ continue;
+ }
+ else
+ {
+ s = strrchr(folder,'/');
+ if (s) *s ='\0';
+ }
+ }
+ else if (((files[i].attr & ATTR_DIRECTORY) == 0) && file_callback)
+ {
+ int ret = file_callback(folder,files[i].name,
+ files[i].attr,file_param);
+ if (ret == DIRWALKER_ERROR)
+ result = DIRWALKER_RETURN_ERROR;
+ else if (ret == DIRWALKER_LEAVEDIR)
+ break; /* break out of inner while() */
+ else if (ret == DIRWALKER_QUIT)
+ result = DIRWALKER_RETURN_FORCED;
+ }
+ i++;
+ } /* while ( i<num_files ) */
+ s = strrchr(folder,'/');
+ if (s) *s ='\0';
+ } /* while (!result && (stack_top>=0) ) */
+
+ /* we've overwritten the dircache so tree browser
+ will need to be reloaded */
+ reload_directory();
+ /* restore dirfilter */
+ *(tc->dirfilter) = dirfilter;
+ global_settings.sort_dir = sort_dir;
+
+ return result;
+}
diff --git a/apps/fileutils.h b/apps/fileutils.h
new file mode 100644
index 0000000000..4377c1436c
--- /dev/null
+++ b/apps/fileutils.h
@@ -0,0 +1,42 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2006 Jonathan Gordon
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef _FILEUTILS_H_
+#define _FILEUTILS_H_
+
+enum {
+ DIRWALKER_ERROR = -1,
+ DIRWALKER_OK = 0,
+ DIRWALKER_IGNORE, /* only valid from folder callback */
+ DIRWALKER_LEAVEDIR, /* only valid from file callback */
+ DIRWALKER_QUIT
+};
+
+enum {
+ DIRWALKER_RETURN_ERROR = -1,
+ DIRWALKER_RETURN_SUCCESS,
+ DIRWALKER_RETURN_FORCED
+};
+
+int dirwalker(const char *start_dir, bool recurse, bool is_forward,
+ int (*folder_callback)(const char* dir, void *param),void* folder_param,
+ int (*file_callback)(const char* folder,const char* file,
+ const int file_attr,void *param),void* file_param);
+
+#endif /* _FILEUTILS_H_ */
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c
index c1b3862ee2..73927ed83d 100644
--- a/apps/plugins/rockpaint.c
+++ b/apps/plugins/rockpaint.c
@@ -827,7 +827,7 @@ static bool browse_fonts( char *dst, int dst_size )
#define fontname_buf buffer.text.fontname_buf
rb->snprintf( old_font, MAX_PATH,
- ROCKBOX_DIR FONT_DIR "/%s.fnt",
+ FONT_DIR "/%s.fnt",
rb->global_settings->font_file );
while( 1 )
@@ -850,7 +850,7 @@ static bool browse_fonts( char *dst, int dst_size )
{
b_need_redraw = 0;
- d = rb->PREFIX(opendir)( ROCKBOX_DIR FONT_DIR "/" );
+ d = rb->PREFIX(opendir)( FONT_DIR "/" );
if( !d )
{
return false;
@@ -880,7 +880,7 @@ static bool browse_fonts( char *dst, int dst_size )
|| rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4,
".fnt" ) )
continue;
- rb->snprintf( bbuf, MAX_PATH, ROCKBOX_DIR FONT_DIR "/%s",
+ rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s",
de->d_name );
rb->font_load( bbuf );
rb->font_getstringsize( de->d_name, &fw, &fh, FONT_UI );
@@ -915,7 +915,7 @@ static bool browse_fonts( char *dst, int dst_size )
&& !rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4,
".fnt" ) )
{
- rb->snprintf( bbuf, MAX_PATH, ROCKBOX_DIR FONT_DIR "/%s",
+ rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s",
de->d_name );
rb->font_load( bbuf );
rb->font_getstringsize( de->d_name, NULL, &fh, FONT_UI );
@@ -1463,7 +1463,7 @@ static void draw_text( int x, int y )
{
buffer.text.text[0] = '\0';
rb->snprintf( buffer.text.old_font, MAX_PATH,
- ROCKBOX_DIR FONT_DIR "/%s.fnt",
+ FONT_DIR "/%s.fnt",
rb->global_settings->font_file );
while( 1 )
{
diff --git a/apps/settings.c b/apps/settings.c
index ee7fa36d39..d419d4ae8b 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -1210,7 +1210,7 @@ void settings_apply(void)
#ifdef HAVE_LCD_BITMAP
if ( global_settings.font_file[0] &&
global_settings.font_file[0] != 0xff ) {
- snprintf(buf, sizeof buf, ROCKBOX_DIR FONT_DIR "/%s.fnt",
+ snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt",
global_settings.font_file);
font_load(buf);
}
@@ -1238,7 +1238,7 @@ void settings_apply(void)
if ( global_settings.lang_file[0] &&
global_settings.lang_file[0] != 0xff ) {
- snprintf(buf, sizeof buf, ROCKBOX_DIR LANG_DIR "/%s.lng",
+ snprintf(buf, sizeof buf, LANG_DIR "/%s.lng",
global_settings.lang_file);
lang_load(buf);
talk_init(); /* use voice of same language */
@@ -1742,12 +1742,12 @@ bool settings_save_config(void)
#endif
if (global_settings.lang_file[0] != 0)
- fdprintf(fd, "lang: %s/%s.lng\r\n", ROCKBOX_DIR LANG_DIR,
+ fdprintf(fd, "lang: %s/%s.lng\r\n", LANG_DIR,
global_settings.lang_file);
#ifdef HAVE_LCD_BITMAP
if (global_settings.font_file[0] != 0)
- fdprintf(fd, "font: %s/%s.fnt\r\n", ROCKBOX_DIR FONT_DIR,
+ fdprintf(fd, "font: %s/%s.fnt\r\n", FONT_DIR,
global_settings.font_file);
#endif
diff --git a/apps/settings.h b/apps/settings.h
index 3e0b8fcd11..09834ec183 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -35,15 +35,15 @@
#define ROCKBOX_DIR "/.rockbox"
#define ROCKBOX_DIR_LEN 9
-#define FONT_DIR "/fonts"
-#define LANG_DIR "/langs"
-#define WPS_DIR ROCKBOX_DIR "/wps"
-#define THEME_DIR ROCKBOX_DIR "/themes"
-#define PLUGIN_DIR ROCKBOX_DIR"/rocks"
-#define BACKDROP_DIR ROCKBOX_DIR"/backdrops"
+#define FONT_DIR ROCKBOX_DIR "/fonts"
+#define LANG_DIR ROCKBOX_DIR "/langs"
+#define WPS_DIR ROCKBOX_DIR "/wps"
+#define THEME_DIR ROCKBOX_DIR "/themes"
+#define PLUGIN_DIR ROCKBOX_DIR "/rocks"
+#define BACKDROP_DIR ROCKBOX_DIR "/backdrops"
#define REC_BASE_DIR "/recordings"
-#define EQS_DIR ROCKBOX_DIR "/eqs"
-#define CODECS_DIR "/codecs"
+#define EQS_DIR ROCKBOX_DIR "/eqs"
+#define CODECS_DIR ROCKBOX_DIR"/codecs"
#define MAX_FILENAME 20
diff --git a/apps/settings_menu.c b/apps/settings_menu.c
index 27fc5653d1..b2d261492e 100644
--- a/apps/settings_menu.c
+++ b/apps/settings_menu.c
@@ -1257,7 +1257,7 @@ static bool custom_cfg_browse(void)
static bool language_browse(void)
{
- return rockbox_browse(ROCKBOX_DIR LANG_DIR, SHOW_LNG);
+ return rockbox_browse(LANG_DIR, SHOW_LNG);
}
static bool voice_menus(void)
@@ -1327,7 +1327,7 @@ static bool voice_menu(void)
#ifdef HAVE_LCD_BITMAP
static bool font_browse(void)
{
- return rockbox_browse(ROCKBOX_DIR FONT_DIR, SHOW_FONT);
+ return rockbox_browse(FONT_DIR, SHOW_FONT);
}
static bool scroll_bar(void)
diff --git a/apps/talk.c b/apps/talk.c
index 1da24153d2..a92425d439 100644
--- a/apps/talk.c
+++ b/apps/talk.c
@@ -142,7 +142,7 @@ static int open_voicefile(void)
p_lang = (char *)global_settings.lang_file;
}
- snprintf(buf, sizeof(buf), ROCKBOX_DIR LANG_DIR "/%s.voice", p_lang);
+ snprintf(buf, sizeof(buf), LANG_DIR "/%s.voice", p_lang);
return open(buf, O_RDONLY);
}