diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2006-10-03 10:38:27 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2006-10-03 10:38:27 +0000 |
commit | 7ae8e44c9556daa07813a3bfd1ace6b0fb0a2aa8 (patch) | |
tree | 3ab6dcbeecc43379a776f07e671e03057d7d56e7 /apps/fileutils.c | |
parent | f5452c0bded3147dfc91dc89580e65a879bc50e8 (diff) | |
download | rockbox-7ae8e44c9556daa07813a3bfd1ace6b0fb0a2aa8.tar.gz rockbox-7ae8e44c9556daa07813a3bfd1ace6b0fb0a2aa8.zip |
add some consistancy to the path #defines
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11114 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/fileutils.c')
-rw-r--r-- | apps/fileutils.c | 167 |
1 files changed, 167 insertions, 0 deletions
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 | **/ | ||
41 | int 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 | } | ||