summaryrefslogtreecommitdiffstats
path: root/apps/plugins/random_folder_advance_config.c
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 /apps/plugins/random_folder_advance_config.c
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
Diffstat (limited to 'apps/plugins/random_folder_advance_config.c')
-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;
static int dirs_count;
static int lasttick;
#define RFA_FILE ROCKBOX_DIR "/folder_advance_list.dat"
+#define RFADIR_FILE ROCKBOX_DIR "/folder_advance_dir.txt"
+#define MAX_REMOVED_DIRS 10
+
char *buffer = NULL;
ssize_t buffer_size;
+int num_replaced_dirs = 0;
+char removed_dirs[MAX_REMOVED_DIRS][MAX_PATH];
struct file_format {
int count;
char folder[][MAX_PATH];
@@ -77,8 +82,9 @@ void traversedir(char* location, char* name)
{
struct dirent *entry;
DIR* dir;
- char fullpath[MAX_PATH];
+ char fullpath[MAX_PATH], path[MAX_PATH];
bool check = false;
+ int i;
rb->snprintf(fullpath, sizeof(fullpath), "%s/%s", location, name);
dir = rb->opendir(fullpath);
@@ -97,11 +103,24 @@ void traversedir(char* location, char* name)
else check = true;
}
else check = true;
-
+
+ /* check if path is removed directory, if so dont enter it */
+ rb->snprintf(path, MAX_PATH, "%s/%s", fullpath, entry->d_name);
+ while(path[0] == '/')
+ rb->strncpy(path, path + 1, rb->strlen(path));
+ for(i = 0; i < num_replaced_dirs; i++)
+ {
+ if(!rb->strcmp(path, removed_dirs[i]))
+ {
+ check = false;
+ break;
+ }
+ }
+
if (check)
{
if (entry->attribute & ATTR_DIRECTORY) {
- char *start, path[MAX_PATH];
+ char *start;
dirs_count++;
rb->snprintf(path,MAX_PATH,"%s/%s",fullpath,entry->d_name);
start = &path[rb->strlen(path)];
@@ -125,6 +144,93 @@ void traversedir(char* location, char* name)
rb->closedir(dir);
}
}
+
+bool custom_dir(void)
+{
+ DIR* dir_check;
+ char *starts, line[MAX_PATH], formatted_line[MAX_PATH];
+ static int fd2;
+ char buf[11];
+ int i, errors = 0;
+
+ /* populate removed dirs array */
+ if((fd2 = rb->open(RFADIR_FILE,O_RDONLY)) > 0)
+ {
+ while ((rb->read_line(fd2, line, MAX_PATH - 1)) > 0)
+ {
+ if ((line[0] == '-') && (line[1] == '/') &&
+ (num_replaced_dirs < MAX_REMOVED_DIRS))
+ {
+ num_replaced_dirs ++;
+ rb->strncpy(removed_dirs[num_replaced_dirs - 1], line + 2,
+ rb->strlen(line));
+ }
+ }
+ rb->close(fd2);
+ }
+
+ if((fd2 = rb->open(RFADIR_FILE,O_RDONLY)) > 0)
+ {
+ while ((rb->read_line(fd2, line, MAX_PATH - 1)) > 0)
+ {
+ /* blank lines and removed dirs ignored */
+ if (rb->strlen(line) && ((line[0] != '-') || (line[1] != '/')))
+ {
+ /* remove preceeding '/'s from the line */
+ while(line[0] == '/')
+ rb->strncpy(line, line + 1, rb->strlen(line));
+
+ rb->snprintf(formatted_line, MAX_PATH, "/%s", line);
+
+ dir_check = rb->opendir(formatted_line);
+
+ if (dir_check)
+ {
+ rb->closedir(dir_check);
+ starts = &formatted_line[rb->strlen(formatted_line)];
+ rb->memset(starts, 0, &formatted_line[MAX_PATH-1]-starts);
+ bool write_line = true;
+
+ for(i = 0; i < num_replaced_dirs; i++)
+ {
+ if(!rb->strcmp(line, removed_dirs[i]))
+ {
+ write_line = false;
+ break;
+ }
+ }
+
+ if(write_line)
+ {
+ dirs_count++;
+ rb->write(fd, formatted_line, MAX_PATH);
+ }
+
+ traversedir("", line);
+ }
+ else
+ {
+ errors ++;
+ rb->snprintf(buf,sizeof(buf),"Not found:");
+ FOR_NB_SCREENS(i)
+ {
+ rb->screens[i]->puts(0,0,buf);
+ rb->screens[i]->puts(0, errors, line);
+ }
+ update_screen(false);
+ }
+ }
+ }
+ rb->close(fd2);
+ if(errors)
+ /* Press button to continue */
+ rb->get_action(CONTEXT_STD, TIMEOUT_BLOCK);
+ }
+ else
+ return false;
+ return true;
+}
+
void generate(void)
{
dirs_count = 0;
@@ -141,7 +247,9 @@ void generate(void)
#endif
lasttick = *rb->current_tick;
- traversedir("", "");
+ if(!custom_dir())
+ traversedir("", "");
+
rb->lseek(fd,0,SEEK_SET);
rb->write(fd,&dirs_count,sizeof(int));
rb->close(fd);