summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-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 = {
228void codec_get_full_path(char *path, const char *codec_fn) 228void codec_get_full_path(char *path, const char *codec_fn)
229{ 229{
230 /* Create full codec path */ 230 /* Create full codec path */
231 snprintf(path, MAX_PATH-1, ROCKBOX_DIR CODECS_DIR "/%s", codec_fn); 231 snprintf(path, MAX_PATH-1, CODECS_DIR "/%s", codec_fn);
232} 232}
233 233
234int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap, 234int 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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Jonathan Gordon
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include "playlist.h"
24#include "filetree.h"
25#include "dir.h"
26#include "tree.h"
27#include "lang.h"
28#include "fileutils.h"
29#include "settings.h"
30#include "gui/splash.h"
31#include "action.h"
32#include "debug.h"
33
34#define MAX_DEPTH 32
35
36/**
37 RETURNS: DIRWALKER_RETURN_SUCCESS if it successfully went through the directory tree
38 DIRWALKER_RETURN_ERROR if it stopped for an error
39 DIRWALKER_RETURN_FORCED if it was told to stop by one of the callbacks, or user aborted
40**/
41int dirwalker(const char *start_dir, bool recurse, bool is_forward,
42 int (*folder_callback)(const char* dir, void *param),void* folder_param,
43 int (*file_callback)(const char* folder,const char* file,
44 const int file_attr,void *param),void* file_param)
45{
46 char folder[MAX_PATH+1];
47 int current_file_stack[MAX_DEPTH];
48 int stack_top = 0;
49
50 int result = DIRWALKER_RETURN_SUCCESS;
51 int num_files = 0;
52 int i;
53 char *s;
54 struct entry *files;
55 struct tree_context* tc = tree_get_context();
56 int dirfilter = *(tc->dirfilter);
57 int sort_dir = global_settings.sort_dir;
58
59 /* sort in another direction if previous dir is requested */
60 if(!is_forward){
61 int reverse_sort_dir[5] = {4,2,1,4,0};
62 global_settings.sort_dir = reverse_sort_dir[sort_dir];
63 }
64
65 /* use the tree browser dircache to load files */
66 *(tc->dirfilter) = SHOW_ALL;
67
68 /* setup stuff */
69 strcpy(folder, start_dir);
70 current_file_stack[0] = -1;
71
72 while (!result && (stack_top>=0) )
73 {
74 if (ft_load(tc, folder) < 0)
75 {
76 gui_syncsplash(HZ*2, true,"%s %s",folder,
77 str(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR));
78 result = DIRWALKER_RETURN_ERROR;
79 }
80
81 files = (struct entry*) tc->dircache;
82 num_files = tc->filesindir;
83
84 i = current_file_stack[stack_top--]+1;
85 while ( i<num_files )
86 {
87 /* user abort */
88 if (action_userabort(TIMEOUT_NOBLOCK))
89 {
90 result = DIRWALKER_RETURN_FORCED;
91 break;
92 }
93
94 if ((files[i].attr & ATTR_DIRECTORY) && recurse)
95 {
96 bool enter_dir = true;
97 strcat(folder,"/");
98 strcat(folder,files[i].name);
99 if (folder_callback)
100 {
101 switch (folder_callback(folder,folder_param))
102 {
103 case DIRWALKER_ERROR:
104 result = DIRWALKER_RETURN_ERROR;
105 enter_dir = false;
106 break;
107 case DIRWALKER_OK:
108 enter_dir = true;
109 break;
110 case DIRWALKER_IGNORE:
111 enter_dir = false;
112 break;
113 case DIRWALKER_QUIT:
114 result = DIRWALKER_RETURN_FORCED;
115 enter_dir = false;
116 break;
117 }
118 }
119 if (enter_dir)
120 {
121 current_file_stack[++stack_top] = i;
122
123 if(ft_load(tc, folder) < 0)
124 {
125 gui_syncsplash(HZ*2, true,"%s %s",folder,
126 str(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR));
127 result = DIRWALKER_RETURN_ERROR;
128 break;
129 }
130
131 files = (struct entry*) tc->dircache;
132 num_files = tc->filesindir;
133 i=0;
134 continue;
135 }
136 else
137 {
138 s = strrchr(folder,'/');
139 if (s) *s ='\0';
140 }
141 }
142 else if (((files[i].attr & ATTR_DIRECTORY) == 0) && file_callback)
143 {
144 int ret = file_callback(folder,files[i].name,
145 files[i].attr,file_param);
146 if (ret == DIRWALKER_ERROR)
147 result = DIRWALKER_RETURN_ERROR;
148 else if (ret == DIRWALKER_LEAVEDIR)
149 break; /* break out of inner while() */
150 else if (ret == DIRWALKER_QUIT)
151 result = DIRWALKER_RETURN_FORCED;
152 }
153 i++;
154 } /* while ( i<num_files ) */
155 s = strrchr(folder,'/');
156 if (s) *s ='\0';
157 } /* while (!result && (stack_top>=0) ) */
158
159 /* we've overwritten the dircache so tree browser
160 will need to be reloaded */
161 reload_directory();
162 /* restore dirfilter */
163 *(tc->dirfilter) = dirfilter;
164 global_settings.sort_dir = sort_dir;
165
166 return result;
167}
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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Jonathan Gordon
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef _FILEUTILS_H_
21#define _FILEUTILS_H_
22
23enum {
24 DIRWALKER_ERROR = -1,
25 DIRWALKER_OK = 0,
26 DIRWALKER_IGNORE, /* only valid from folder callback */
27 DIRWALKER_LEAVEDIR, /* only valid from file callback */
28 DIRWALKER_QUIT
29};
30
31enum {
32 DIRWALKER_RETURN_ERROR = -1,
33 DIRWALKER_RETURN_SUCCESS,
34 DIRWALKER_RETURN_FORCED
35};
36
37int dirwalker(const char *start_dir, bool recurse, bool is_forward,
38 int (*folder_callback)(const char* dir, void *param),void* folder_param,
39 int (*file_callback)(const char* folder,const char* file,
40 const int file_attr,void *param),void* file_param);
41
42#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 )
827 #define fontname_buf buffer.text.fontname_buf 827 #define fontname_buf buffer.text.fontname_buf
828 828
829 rb->snprintf( old_font, MAX_PATH, 829 rb->snprintf( old_font, MAX_PATH,
830 ROCKBOX_DIR FONT_DIR "/%s.fnt", 830 FONT_DIR "/%s.fnt",
831 rb->global_settings->font_file ); 831 rb->global_settings->font_file );
832 832
833 while( 1 ) 833 while( 1 )
@@ -850,7 +850,7 @@ static bool browse_fonts( char *dst, int dst_size )
850 { 850 {
851 b_need_redraw = 0; 851 b_need_redraw = 0;
852 852
853 d = rb->PREFIX(opendir)( ROCKBOX_DIR FONT_DIR "/" ); 853 d = rb->PREFIX(opendir)( FONT_DIR "/" );
854 if( !d ) 854 if( !d )
855 { 855 {
856 return false; 856 return false;
@@ -880,7 +880,7 @@ static bool browse_fonts( char *dst, int dst_size )
880 || rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4, 880 || rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4,
881 ".fnt" ) ) 881 ".fnt" ) )
882 continue; 882 continue;
883 rb->snprintf( bbuf, MAX_PATH, ROCKBOX_DIR FONT_DIR "/%s", 883 rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s",
884 de->d_name ); 884 de->d_name );
885 rb->font_load( bbuf ); 885 rb->font_load( bbuf );
886 rb->font_getstringsize( de->d_name, &fw, &fh, FONT_UI ); 886 rb->font_getstringsize( de->d_name, &fw, &fh, FONT_UI );
@@ -915,7 +915,7 @@ static bool browse_fonts( char *dst, int dst_size )
915 && !rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4, 915 && !rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4,
916 ".fnt" ) ) 916 ".fnt" ) )
917 { 917 {
918 rb->snprintf( bbuf, MAX_PATH, ROCKBOX_DIR FONT_DIR "/%s", 918 rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s",
919 de->d_name ); 919 de->d_name );
920 rb->font_load( bbuf ); 920 rb->font_load( bbuf );
921 rb->font_getstringsize( de->d_name, NULL, &fh, FONT_UI ); 921 rb->font_getstringsize( de->d_name, NULL, &fh, FONT_UI );
@@ -1463,7 +1463,7 @@ static void draw_text( int x, int y )
1463{ 1463{
1464 buffer.text.text[0] = '\0'; 1464 buffer.text.text[0] = '\0';
1465 rb->snprintf( buffer.text.old_font, MAX_PATH, 1465 rb->snprintf( buffer.text.old_font, MAX_PATH,
1466 ROCKBOX_DIR FONT_DIR "/%s.fnt", 1466 FONT_DIR "/%s.fnt",
1467 rb->global_settings->font_file ); 1467 rb->global_settings->font_file );
1468 while( 1 ) 1468 while( 1 )
1469 { 1469 {
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)
1210#ifdef HAVE_LCD_BITMAP 1210#ifdef HAVE_LCD_BITMAP
1211 if ( global_settings.font_file[0] && 1211 if ( global_settings.font_file[0] &&
1212 global_settings.font_file[0] != 0xff ) { 1212 global_settings.font_file[0] != 0xff ) {
1213 snprintf(buf, sizeof buf, ROCKBOX_DIR FONT_DIR "/%s.fnt", 1213 snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt",
1214 global_settings.font_file); 1214 global_settings.font_file);
1215 font_load(buf); 1215 font_load(buf);
1216 } 1216 }
@@ -1238,7 +1238,7 @@ void settings_apply(void)
1238 1238
1239 if ( global_settings.lang_file[0] && 1239 if ( global_settings.lang_file[0] &&
1240 global_settings.lang_file[0] != 0xff ) { 1240 global_settings.lang_file[0] != 0xff ) {
1241 snprintf(buf, sizeof buf, ROCKBOX_DIR LANG_DIR "/%s.lng", 1241 snprintf(buf, sizeof buf, LANG_DIR "/%s.lng",
1242 global_settings.lang_file); 1242 global_settings.lang_file);
1243 lang_load(buf); 1243 lang_load(buf);
1244 talk_init(); /* use voice of same language */ 1244 talk_init(); /* use voice of same language */
@@ -1742,12 +1742,12 @@ bool settings_save_config(void)
1742#endif 1742#endif
1743 1743
1744 if (global_settings.lang_file[0] != 0) 1744 if (global_settings.lang_file[0] != 0)
1745 fdprintf(fd, "lang: %s/%s.lng\r\n", ROCKBOX_DIR LANG_DIR, 1745 fdprintf(fd, "lang: %s/%s.lng\r\n", LANG_DIR,
1746 global_settings.lang_file); 1746 global_settings.lang_file);
1747 1747
1748#ifdef HAVE_LCD_BITMAP 1748#ifdef HAVE_LCD_BITMAP
1749 if (global_settings.font_file[0] != 0) 1749 if (global_settings.font_file[0] != 0)
1750 fdprintf(fd, "font: %s/%s.fnt\r\n", ROCKBOX_DIR FONT_DIR, 1750 fdprintf(fd, "font: %s/%s.fnt\r\n", FONT_DIR,
1751 global_settings.font_file); 1751 global_settings.font_file);
1752#endif 1752#endif
1753 1753
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 @@
35 35
36#define ROCKBOX_DIR "/.rockbox" 36#define ROCKBOX_DIR "/.rockbox"
37#define ROCKBOX_DIR_LEN 9 37#define ROCKBOX_DIR_LEN 9
38#define FONT_DIR "/fonts" 38#define FONT_DIR ROCKBOX_DIR "/fonts"
39#define LANG_DIR "/langs" 39#define LANG_DIR ROCKBOX_DIR "/langs"
40#define WPS_DIR ROCKBOX_DIR "/wps" 40#define WPS_DIR ROCKBOX_DIR "/wps"
41#define THEME_DIR ROCKBOX_DIR "/themes" 41#define THEME_DIR ROCKBOX_DIR "/themes"
42#define PLUGIN_DIR ROCKBOX_DIR"/rocks" 42#define PLUGIN_DIR ROCKBOX_DIR "/rocks"
43#define BACKDROP_DIR ROCKBOX_DIR"/backdrops" 43#define BACKDROP_DIR ROCKBOX_DIR "/backdrops"
44#define REC_BASE_DIR "/recordings" 44#define REC_BASE_DIR "/recordings"
45#define EQS_DIR ROCKBOX_DIR "/eqs" 45#define EQS_DIR ROCKBOX_DIR "/eqs"
46#define CODECS_DIR "/codecs" 46#define CODECS_DIR ROCKBOX_DIR"/codecs"
47 47
48#define MAX_FILENAME 20 48#define MAX_FILENAME 20
49 49
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)
1257 1257
1258static bool language_browse(void) 1258static bool language_browse(void)
1259{ 1259{
1260 return rockbox_browse(ROCKBOX_DIR LANG_DIR, SHOW_LNG); 1260 return rockbox_browse(LANG_DIR, SHOW_LNG);
1261} 1261}
1262 1262
1263static bool voice_menus(void) 1263static bool voice_menus(void)
@@ -1327,7 +1327,7 @@ static bool voice_menu(void)
1327#ifdef HAVE_LCD_BITMAP 1327#ifdef HAVE_LCD_BITMAP
1328static bool font_browse(void) 1328static bool font_browse(void)
1329{ 1329{
1330 return rockbox_browse(ROCKBOX_DIR FONT_DIR, SHOW_FONT); 1330 return rockbox_browse(FONT_DIR, SHOW_FONT);
1331} 1331}
1332 1332
1333static bool scroll_bar(void) 1333static 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)
142 p_lang = (char *)global_settings.lang_file; 142 p_lang = (char *)global_settings.lang_file;
143 } 143 }
144 144
145 snprintf(buf, sizeof(buf), ROCKBOX_DIR LANG_DIR "/%s.voice", p_lang); 145 snprintf(buf, sizeof(buf), LANG_DIR "/%s.voice", p_lang);
146 146
147 return open(buf, O_RDONLY); 147 return open(buf, O_RDONLY);
148} 148}