summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2007-08-05 02:33:15 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2007-08-05 02:33:15 +0000
commit7c54ad647bcb07fa0f449c56b0a63e66f973ad73 (patch)
tree9e4a53adb3ecafca53c749b01da17c1612ea758e
parent68c83e51bb1f188fd8759c34d90f46c7d2b38b74 (diff)
downloadrockbox-7c54ad647bcb07fa0f449c56b0a63e66f973ad73.tar.gz
rockbox-7c54ad647bcb07fa0f449c56b0a63e66f973ad73.zip
Accept FS#7074 - choose which folders should be scanned and ignored using the /.rockbox/folder_advance_dir.txt (paths prefixed by - will be skipped, otherwise they will be scanned)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14186 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/random_folder_advance_config.c116
1 files changed, 112 insertions, 4 deletions
diff --git a/apps/plugins/random_folder_advance_config.c b/apps/plugins/random_folder_advance_config.c
index 27e8c0b294..6ed36c6065 100644
--- a/apps/plugins/random_folder_advance_config.c
+++ b/apps/plugins/random_folder_advance_config.c
@@ -27,8 +27,13 @@ static int fd;
27static int dirs_count; 27static int dirs_count;
28static int lasttick; 28static int lasttick;
29#define RFA_FILE ROCKBOX_DIR "/folder_advance_list.dat" 29#define RFA_FILE ROCKBOX_DIR "/folder_advance_list.dat"
30#define RFADIR_FILE ROCKBOX_DIR "/folder_advance_dir.txt"
31#define MAX_REMOVED_DIRS 10
32
30char *buffer = NULL; 33char *buffer = NULL;
31ssize_t buffer_size; 34ssize_t buffer_size;
35int num_replaced_dirs = 0;
36char removed_dirs[MAX_REMOVED_DIRS][MAX_PATH];
32struct file_format { 37struct file_format {
33 int count; 38 int count;
34 char folder[][MAX_PATH]; 39 char folder[][MAX_PATH];
@@ -77,8 +82,9 @@ void traversedir(char* location, char* name)
77{ 82{
78 struct dirent *entry; 83 struct dirent *entry;
79 DIR* dir; 84 DIR* dir;
80 char fullpath[MAX_PATH]; 85 char fullpath[MAX_PATH], path[MAX_PATH];
81 bool check = false; 86 bool check = false;
87 int i;
82 88
83 rb->snprintf(fullpath, sizeof(fullpath), "%s/%s", location, name); 89 rb->snprintf(fullpath, sizeof(fullpath), "%s/%s", location, name);
84 dir = rb->opendir(fullpath); 90 dir = rb->opendir(fullpath);
@@ -97,11 +103,24 @@ void traversedir(char* location, char* name)
97 else check = true; 103 else check = true;
98 } 104 }
99 else check = true; 105 else check = true;
100 106
107 /* check if path is removed directory, if so dont enter it */
108 rb->snprintf(path, MAX_PATH, "%s/%s", fullpath, entry->d_name);
109 while(path[0] == '/')
110 rb->strncpy(path, path + 1, rb->strlen(path));
111 for(i = 0; i < num_replaced_dirs; i++)
112 {
113 if(!rb->strcmp(path, removed_dirs[i]))
114 {
115 check = false;
116 break;
117 }
118 }
119
101 if (check) 120 if (check)
102 { 121 {
103 if (entry->attribute & ATTR_DIRECTORY) { 122 if (entry->attribute & ATTR_DIRECTORY) {
104 char *start, path[MAX_PATH]; 123 char *start;
105 dirs_count++; 124 dirs_count++;
106 rb->snprintf(path,MAX_PATH,"%s/%s",fullpath,entry->d_name); 125 rb->snprintf(path,MAX_PATH,"%s/%s",fullpath,entry->d_name);
107 start = &path[rb->strlen(path)]; 126 start = &path[rb->strlen(path)];
@@ -125,6 +144,93 @@ void traversedir(char* location, char* name)
125 rb->closedir(dir); 144 rb->closedir(dir);
126 } 145 }
127} 146}
147
148bool custom_dir(void)
149{
150 DIR* dir_check;
151 char *starts, line[MAX_PATH], formatted_line[MAX_PATH];
152 static int fd2;
153 char buf[11];
154 int i, errors = 0;
155
156 /* populate removed dirs array */
157 if((fd2 = rb->open(RFADIR_FILE,O_RDONLY)) > 0)
158 {
159 while ((rb->read_line(fd2, line, MAX_PATH - 1)) > 0)
160 {
161 if ((line[0] == '-') && (line[1] == '/') &&
162 (num_replaced_dirs < MAX_REMOVED_DIRS))
163 {
164 num_replaced_dirs ++;
165 rb->strncpy(removed_dirs[num_replaced_dirs - 1], line + 2,
166 rb->strlen(line));
167 }
168 }
169 rb->close(fd2);
170 }
171
172 if((fd2 = rb->open(RFADIR_FILE,O_RDONLY)) > 0)
173 {
174 while ((rb->read_line(fd2, line, MAX_PATH - 1)) > 0)
175 {
176 /* blank lines and removed dirs ignored */
177 if (rb->strlen(line) && ((line[0] != '-') || (line[1] != '/')))
178 {
179 /* remove preceeding '/'s from the line */
180 while(line[0] == '/')
181 rb->strncpy(line, line + 1, rb->strlen(line));
182
183 rb->snprintf(formatted_line, MAX_PATH, "/%s", line);
184
185 dir_check = rb->opendir(formatted_line);
186
187 if (dir_check)
188 {
189 rb->closedir(dir_check);
190 starts = &formatted_line[rb->strlen(formatted_line)];
191 rb->memset(starts, 0, &formatted_line[MAX_PATH-1]-starts);
192 bool write_line = true;
193
194 for(i = 0; i < num_replaced_dirs; i++)
195 {
196 if(!rb->strcmp(line, removed_dirs[i]))
197 {
198 write_line = false;
199 break;
200 }
201 }
202
203 if(write_line)
204 {
205 dirs_count++;
206 rb->write(fd, formatted_line, MAX_PATH);
207 }
208
209 traversedir("", line);
210 }
211 else
212 {
213 errors ++;
214 rb->snprintf(buf,sizeof(buf),"Not found:");
215 FOR_NB_SCREENS(i)
216 {
217 rb->screens[i]->puts(0,0,buf);
218 rb->screens[i]->puts(0, errors, line);
219 }
220 update_screen(false);
221 }
222 }
223 }
224 rb->close(fd2);
225 if(errors)
226 /* Press button to continue */
227 rb->get_action(CONTEXT_STD, TIMEOUT_BLOCK);
228 }
229 else
230 return false;
231 return true;
232}
233
128void generate(void) 234void generate(void)
129{ 235{
130 dirs_count = 0; 236 dirs_count = 0;
@@ -141,7 +247,9 @@ void generate(void)
141#endif 247#endif
142 lasttick = *rb->current_tick; 248 lasttick = *rb->current_tick;
143 249
144 traversedir("", ""); 250 if(!custom_dir())
251 traversedir("", "");
252
145 rb->lseek(fd,0,SEEK_SET); 253 rb->lseek(fd,0,SEEK_SET);
146 rb->write(fd,&dirs_count,sizeof(int)); 254 rb->write(fd,&dirs_count,sizeof(int));
147 rb->close(fd); 255 rb->close(fd);