2006-10-09 10:54:17 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Jonathan Gordon
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-10-09 10:54:17 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2011-02-24 23:59:24 +00:00
|
|
|
#include "config.h"
|
2006-10-09 10:54:17 +00:00
|
|
|
#include "plugin.h"
|
2009-07-01 16:59:43 +00:00
|
|
|
#include "file.h"
|
2006-10-09 10:54:17 +00:00
|
|
|
|
2010-08-24 14:30:46 +00:00
|
|
|
|
2006-10-09 10:54:17 +00:00
|
|
|
|
2010-05-06 21:04:40 +00:00
|
|
|
static bool cancel;
|
2006-10-09 10:54:17 +00:00
|
|
|
static int fd;
|
|
|
|
static int dirs_count;
|
|
|
|
static int lasttick;
|
|
|
|
#define RFA_FILE ROCKBOX_DIR "/folder_advance_list.dat"
|
2007-08-05 02:33:15 +00:00
|
|
|
#define RFADIR_FILE ROCKBOX_DIR "/folder_advance_dir.txt"
|
2008-04-24 10:59:56 +00:00
|
|
|
#define RFA_FILE_TEXT ROCKBOX_DIR "/folder_advance_list.txt"
|
2007-08-05 02:33:15 +00:00
|
|
|
#define MAX_REMOVED_DIRS 10
|
|
|
|
|
2006-10-09 10:54:17 +00:00
|
|
|
char *buffer = NULL;
|
2010-05-07 19:27:42 +00:00
|
|
|
size_t buffer_size;
|
2007-08-05 02:33:15 +00:00
|
|
|
int num_replaced_dirs = 0;
|
|
|
|
char removed_dirs[MAX_REMOVED_DIRS][MAX_PATH];
|
2006-10-09 10:54:17 +00:00
|
|
|
struct file_format {
|
|
|
|
int count;
|
|
|
|
char folder[][MAX_PATH];
|
|
|
|
};
|
|
|
|
struct file_format *list = NULL;
|
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static void update_screen(bool clear)
|
2006-10-09 10:54:17 +00:00
|
|
|
{
|
|
|
|
char buf[15];
|
2007-04-06 22:55:00 +00:00
|
|
|
|
|
|
|
rb->snprintf(buf,sizeof(buf),"Folders: %d",dirs_count);
|
2006-10-09 10:54:17 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
2006-10-09 14:40:15 +00:00
|
|
|
if(clear)
|
|
|
|
rb->screens[i]->clear_display();
|
2006-10-09 10:54:17 +00:00
|
|
|
rb->screens[i]->putsxy(0,0,buf);
|
|
|
|
rb->screens[i]->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static void traversedir(char* location, char* name)
|
2006-10-09 10:54:17 +00:00
|
|
|
{
|
|
|
|
struct dirent *entry;
|
|
|
|
DIR* dir;
|
2007-08-05 02:33:15 +00:00
|
|
|
char fullpath[MAX_PATH], path[MAX_PATH];
|
2006-10-09 10:54:17 +00:00
|
|
|
bool check = false;
|
2007-08-05 02:33:15 +00:00
|
|
|
int i;
|
2006-10-09 10:54:17 +00:00
|
|
|
|
2012-03-19 09:56:38 +00:00
|
|
|
/* behave differently if we're at root to avoid
|
|
|
|
duplication of the initial slash later on */
|
|
|
|
if (location[0] == '\0' && name[0] == '\0') {
|
|
|
|
rb->strcpy(fullpath, "");
|
|
|
|
dir = rb->opendir("/");
|
|
|
|
} else {
|
|
|
|
rb->snprintf(fullpath, sizeof(fullpath), "%s/%s", location, name);
|
|
|
|
dir = rb->opendir(fullpath);
|
|
|
|
}
|
2006-10-09 10:54:17 +00:00
|
|
|
if (dir) {
|
|
|
|
entry = rb->readdir(dir);
|
|
|
|
while (entry) {
|
2010-05-06 21:04:40 +00:00
|
|
|
if (cancel)
|
2006-10-09 10:54:17 +00:00
|
|
|
break;
|
|
|
|
/* Skip .. and . */
|
|
|
|
if (entry->d_name[0] == '.')
|
|
|
|
{
|
|
|
|
if ( !rb->strcmp(entry->d_name,".")
|
|
|
|
|| !rb->strcmp(entry->d_name,"..")
|
|
|
|
|| !rb->strcmp(entry->d_name,".rockbox"))
|
|
|
|
check = false;
|
|
|
|
else check = true;
|
|
|
|
}
|
|
|
|
else check = true;
|
2007-08-05 02:33:15 +00:00
|
|
|
|
|
|
|
/* 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] == '/')
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(path, path + 1, sizeof(path));
|
2007-08-05 02:33:15 +00:00
|
|
|
for(i = 0; i < num_replaced_dirs; i++)
|
|
|
|
{
|
|
|
|
if(!rb->strcmp(path, removed_dirs[i]))
|
|
|
|
{
|
|
|
|
check = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-09 10:54:17 +00:00
|
|
|
if (check)
|
|
|
|
{
|
2010-09-01 21:29:34 +00:00
|
|
|
struct dirinfo info = rb->dir_get_info(dir, entry);
|
|
|
|
if (info.attribute & ATTR_DIRECTORY) {
|
2007-08-05 02:33:15 +00:00
|
|
|
char *start;
|
2006-10-09 10:54:17 +00:00
|
|
|
dirs_count++;
|
|
|
|
rb->snprintf(path,MAX_PATH,"%s/%s",fullpath,entry->d_name);
|
|
|
|
start = &path[rb->strlen(path)];
|
|
|
|
rb->memset(start,0,&path[MAX_PATH-1]-start);
|
|
|
|
rb->write(fd,path,MAX_PATH);
|
|
|
|
traversedir(fullpath, entry->d_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*rb->current_tick - lasttick > (HZ/2)) {
|
2006-10-09 14:40:15 +00:00
|
|
|
update_screen(false);
|
2006-10-09 10:54:17 +00:00
|
|
|
lasttick = *rb->current_tick;
|
|
|
|
if (rb->action_userabort(TIMEOUT_NOBLOCK))
|
|
|
|
{
|
2010-05-06 21:04:40 +00:00
|
|
|
cancel = true;
|
2006-10-09 10:54:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = rb->readdir(dir);
|
|
|
|
}
|
|
|
|
rb->closedir(dir);
|
|
|
|
}
|
|
|
|
}
|
2007-08-05 02:33:15 +00:00
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static bool custom_dir(void)
|
2007-08-05 02:33:15 +00:00
|
|
|
{
|
|
|
|
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 */
|
2009-12-06 13:52:28 +00:00
|
|
|
if((fd2 = rb->open(RFADIR_FILE,O_RDONLY)) >= 0)
|
2007-08-05 02:33:15 +00:00
|
|
|
{
|
|
|
|
while ((rb->read_line(fd2, line, MAX_PATH - 1)) > 0)
|
|
|
|
{
|
|
|
|
if ((line[0] == '-') && (line[1] == '/') &&
|
|
|
|
(num_replaced_dirs < MAX_REMOVED_DIRS))
|
|
|
|
{
|
|
|
|
num_replaced_dirs ++;
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(removed_dirs[num_replaced_dirs - 1], line + 2,
|
|
|
|
sizeof(line));
|
2007-08-05 02:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
rb->close(fd2);
|
|
|
|
}
|
|
|
|
|
2009-12-06 13:52:28 +00:00
|
|
|
if((fd2 = rb->open(RFADIR_FILE,O_RDONLY)) >= 0)
|
2007-08-05 02:33:15 +00:00
|
|
|
{
|
|
|
|
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] == '/')
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(line, line + 1, sizeof(line));
|
2007-08-05 02:33:15 +00:00
|
|
|
|
|
|
|
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 */
|
2021-10-21 20:42:01 +00:00
|
|
|
rb->get_action(CONTEXT_STD, TIMEOUT_BLOCK);
|
2007-08-05 02:33:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static void generate(void)
|
2006-10-09 10:54:17 +00:00
|
|
|
{
|
|
|
|
dirs_count = 0;
|
2010-05-06 21:04:40 +00:00
|
|
|
cancel = false;
|
2010-05-06 17:35:13 +00:00
|
|
|
fd = rb->open(RFA_FILE,O_CREAT|O_WRONLY, 0666);
|
2006-10-09 10:54:17 +00:00
|
|
|
rb->write(fd,&dirs_count,sizeof(int));
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
rb->splashf(HZ, "Couldnt open %s", RFA_FILE);
|
2006-10-09 10:54:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-10-09 14:40:15 +00:00
|
|
|
update_screen(true);
|
2006-10-09 10:54:17 +00:00
|
|
|
lasttick = *rb->current_tick;
|
|
|
|
|
2007-08-05 02:33:15 +00:00
|
|
|
if(!custom_dir())
|
|
|
|
traversedir("", "");
|
|
|
|
|
2006-10-09 10:54:17 +00:00
|
|
|
rb->lseek(fd,0,SEEK_SET);
|
|
|
|
rb->write(fd,&dirs_count,sizeof(int));
|
|
|
|
rb->close(fd);
|
2008-04-24 10:59:56 +00:00
|
|
|
rb->splash(HZ, "Done");
|
2006-10-09 10:54:17 +00:00
|
|
|
}
|
2009-08-20 16:47:44 +00:00
|
|
|
|
|
|
|
static const char* list_get_name_cb(int selected_item, void* data,
|
|
|
|
char* buf, size_t buf_len)
|
2006-10-09 10:54:17 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(buf, list->folder[selected_item], buf_len);
|
2006-10-09 10:54:17 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static int load_list(void)
|
2008-04-24 10:59:56 +00:00
|
|
|
{
|
|
|
|
int myfd = rb->open(RFA_FILE,O_RDONLY);
|
|
|
|
if (myfd < 0)
|
|
|
|
return -1;
|
2010-05-07 19:27:42 +00:00
|
|
|
buffer = rb->plugin_get_audio_buffer(&buffer_size);
|
2008-04-24 10:59:56 +00:00
|
|
|
if (!buffer)
|
|
|
|
{
|
|
|
|
return -2;
|
|
|
|
}
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2008-04-24 10:59:56 +00:00
|
|
|
rb->read(myfd,buffer,buffer_size);
|
|
|
|
rb->close(myfd);
|
|
|
|
list = (struct file_format *)buffer;
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2008-04-24 10:59:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static int save_list(void)
|
2008-04-24 10:59:56 +00:00
|
|
|
{
|
2010-05-06 17:35:04 +00:00
|
|
|
int myfd = rb->creat(RFA_FILE, 0666);
|
2008-04-24 10:59:56 +00:00
|
|
|
if (myfd < 0)
|
|
|
|
{
|
|
|
|
rb->splash(HZ, "Could Not Open " RFA_FILE);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
int dirs_count = 0, i = 0;
|
|
|
|
rb->write(myfd,&dirs_count,sizeof(int));
|
|
|
|
for ( ;i<list->count;i++)
|
|
|
|
{
|
|
|
|
if (list->folder[i][0] != ' ')
|
|
|
|
{
|
|
|
|
dirs_count++;
|
|
|
|
rb->write(myfd,list->folder[i],MAX_PATH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb->lseek(myfd,0,SEEK_SET);
|
|
|
|
rb->write(myfd,&dirs_count,sizeof(int));
|
|
|
|
rb->close(myfd);
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2008-04-24 10:59:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static int edit_list(void)
|
2006-10-09 10:54:17 +00:00
|
|
|
{
|
|
|
|
struct gui_synclist lists;
|
|
|
|
bool exit = false;
|
|
|
|
int button,i;
|
2008-06-29 02:39:09 +00:00
|
|
|
int selection, ret = 0;
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2008-04-24 10:59:56 +00:00
|
|
|
/* load the dat file if not already done */
|
|
|
|
if ((list == NULL || list->count == 0) && (i = load_list()) != 0)
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
rb->splashf(HZ*2, "Could not load %s, rv = %d", RFA_FILE, i);
|
2008-06-29 02:39:09 +00:00
|
|
|
return -1;
|
2008-04-24 10:59:56 +00:00
|
|
|
}
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2006-10-09 14:40:15 +00:00
|
|
|
dirs_count = list->count;
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2008-03-26 03:35:24 +00:00
|
|
|
rb->gui_synclist_init(&lists,list_get_name_cb,0, false, 1, NULL);
|
2006-10-09 10:54:17 +00:00
|
|
|
rb->gui_synclist_set_icon_callback(&lists,NULL);
|
|
|
|
rb->gui_synclist_set_nb_items(&lists,list->count);
|
|
|
|
rb->gui_synclist_limit_scroll(&lists,true);
|
|
|
|
rb->gui_synclist_select_item(&lists, 0);
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2006-10-09 10:54:17 +00:00
|
|
|
while (!exit)
|
|
|
|
{
|
2006-10-09 14:40:15 +00:00
|
|
|
rb->gui_synclist_draw(&lists);
|
2006-10-09 10:54:17 +00:00
|
|
|
button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
|
2007-09-17 10:08:50 +00:00
|
|
|
if (rb->gui_synclist_do_button(&lists,&button,LIST_WRAP_UNLESS_HELD))
|
2006-10-09 10:54:17 +00:00
|
|
|
continue;
|
|
|
|
selection = rb->gui_synclist_get_sel_pos(&lists);
|
|
|
|
switch (button)
|
|
|
|
{
|
|
|
|
case ACTION_STD_OK:
|
|
|
|
list->folder[selection][0] = ' ';
|
|
|
|
list->folder[selection][1] = '\0';
|
|
|
|
break;
|
|
|
|
case ACTION_STD_CONTEXT:
|
|
|
|
{
|
2009-06-16 04:25:21 +00:00
|
|
|
int len;
|
|
|
|
MENUITEM_STRINGLIST(menu, "Remove Menu", NULL,
|
|
|
|
"Remove Folder", "Remove Folder Tree");
|
|
|
|
|
|
|
|
switch (rb->do_menu(&menu, NULL, NULL, false))
|
2006-10-09 10:54:17 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
list->folder[selection][0] = ' ';
|
|
|
|
list->folder[selection][1] = '\0';
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
char temp[MAX_PATH];
|
|
|
|
rb->strcpy(temp,list->folder[selection]);
|
|
|
|
len = rb->strlen(temp);
|
|
|
|
for (i=0;i<list->count;i++)
|
|
|
|
{
|
|
|
|
if (!rb->strncmp(list->folder[i],temp,len))
|
|
|
|
{
|
|
|
|
list->folder[i][0] = ' ';
|
|
|
|
list->folder[i][1] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-26 03:05:24 +00:00
|
|
|
break;
|
2006-10-09 10:54:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ACTION_STD_CANCEL:
|
|
|
|
{
|
2009-06-16 04:25:21 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, "Exit Menu", NULL,
|
|
|
|
"Save and Exit", "Ignore Changes and Exit");
|
|
|
|
|
|
|
|
switch (rb->do_menu(&menu, NULL, NULL, false))
|
2006-10-09 10:54:17 +00:00
|
|
|
{
|
|
|
|
case 0:
|
2008-04-24 10:59:56 +00:00
|
|
|
save_list();
|
2021-07-24 14:39:01 +00:00
|
|
|
/* fallthrough */
|
2006-10-09 10:54:17 +00:00
|
|
|
case 1:
|
|
|
|
exit = true;
|
2008-06-29 02:39:09 +00:00
|
|
|
ret = -2;
|
2006-10-09 10:54:17 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-26 03:05:24 +00:00
|
|
|
break;
|
2006-10-09 10:54:17 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-29 02:39:09 +00:00
|
|
|
return ret;
|
2006-10-09 10:54:17 +00:00
|
|
|
}
|
2008-04-24 10:59:56 +00:00
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static int export_list_to_file_text(void)
|
2008-04-24 10:59:56 +00:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
/* load the dat file if not already done */
|
|
|
|
if ((list == NULL || list->count == 0) && (i = load_list()) != 0)
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
rb->splashf(HZ*2, "Could not load %s, rv = %d", RFA_FILE, i);
|
2008-04-24 10:59:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2008-04-24 10:59:56 +00:00
|
|
|
if (list->count <= 0)
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
rb->splashf(HZ*2, "no dirs in list file: %s", RFA_FILE);
|
2008-04-24 10:59:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2008-04-24 10:59:56 +00:00
|
|
|
/* create and open the file */
|
2010-05-06 17:35:04 +00:00
|
|
|
int myfd = rb->creat(RFA_FILE_TEXT, 0666);
|
2008-04-24 10:59:56 +00:00
|
|
|
if (myfd < 0)
|
|
|
|
{
|
2021-10-21 20:42:01 +00:00
|
|
|
rb->splashf(HZ*4, "failed to open: fd = %d, file = %s",
|
2008-04-24 10:59:56 +00:00
|
|
|
myfd, RFA_FILE_TEXT);
|
|
|
|
return -1;
|
|
|
|
}
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2008-04-24 10:59:56 +00:00
|
|
|
/* write each directory to file */
|
|
|
|
for (i = 0; i < list->count; i++)
|
|
|
|
{
|
|
|
|
if (list->folder[i][0] != ' ')
|
|
|
|
{
|
|
|
|
rb->fdprintf(myfd, "%s\n", list->folder[i]);
|
|
|
|
}
|
|
|
|
}
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2008-04-24 10:59:56 +00:00
|
|
|
rb->close(myfd);
|
|
|
|
rb->splash(HZ, "Done");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static int import_list_from_file_text(void)
|
2008-04-24 10:59:56 +00:00
|
|
|
{
|
|
|
|
char line[MAX_PATH];
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2010-05-07 19:27:42 +00:00
|
|
|
buffer = rb->plugin_get_audio_buffer(&buffer_size);
|
2008-04-24 10:59:56 +00:00
|
|
|
if (buffer == NULL)
|
|
|
|
{
|
|
|
|
rb->splash(HZ*2, "failed to get audio buffer");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int myfd = rb->open(RFA_FILE_TEXT, O_RDONLY);
|
|
|
|
if (myfd < 0)
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
rb->splashf(HZ*2, "failed to open: %s", RFA_FILE_TEXT);
|
2008-04-24 10:59:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2008-04-24 10:59:56 +00:00
|
|
|
/* set the list structure, and initialize count */
|
|
|
|
list = (struct file_format *)buffer;
|
|
|
|
list->count = 0;
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2008-04-24 10:59:56 +00:00
|
|
|
while ((rb->read_line(myfd, line, MAX_PATH - 1)) > 0)
|
|
|
|
{
|
|
|
|
/* copy the dir name, and skip the newline */
|
|
|
|
int len = rb->strlen(line);
|
|
|
|
/* remove CRs */
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
if (line[len-1] == 0x0A || line[len-1] == 0x0D)
|
|
|
|
line[len-1] = 0x00;
|
2021-10-21 20:42:01 +00:00
|
|
|
if (len > 1 &&
|
2008-04-24 10:59:56 +00:00
|
|
|
(line[len-2] == 0x0A || line[len-2] == 0x0D))
|
|
|
|
line[len-2] = 0x00;
|
|
|
|
}
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2008-04-24 10:59:56 +00:00
|
|
|
rb->strcpy(list->folder[list->count++], line);
|
|
|
|
}
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2008-04-24 10:59:56 +00:00
|
|
|
rb->close(myfd);
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2008-04-24 10:59:56 +00:00
|
|
|
if (list->count == 0)
|
|
|
|
{
|
|
|
|
load_list();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
save_list();
|
|
|
|
}
|
|
|
|
rb->splash(HZ, "Done");
|
|
|
|
return list->count;
|
|
|
|
}
|
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static int start_shuffled_play(void)
|
2009-07-01 16:59:43 +00:00
|
|
|
{
|
2009-07-01 18:42:51 +00:00
|
|
|
int *order;
|
|
|
|
size_t max_shuffle_size;
|
2009-07-01 16:59:43 +00:00
|
|
|
int i = 0;
|
2009-07-01 18:42:51 +00:00
|
|
|
|
|
|
|
/* get memory for shuffling */
|
|
|
|
order=rb->plugin_get_buffer(&max_shuffle_size);
|
|
|
|
max_shuffle_size/=sizeof(int);
|
|
|
|
if (order==NULL || max_shuffle_size==0)
|
|
|
|
{
|
|
|
|
rb->splashf(HZ*2, "Not enough memory for shuffling");
|
|
|
|
return 0;
|
|
|
|
}
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2009-07-01 16:59:43 +00:00
|
|
|
/* load the dat file if not already done */
|
|
|
|
if ((list == NULL || list->count == 0) && (i = load_list()) != 0)
|
|
|
|
{
|
|
|
|
rb->splashf(HZ*2, "Could not load %s, rv = %d", RFA_FILE, i);
|
|
|
|
return 0;
|
|
|
|
}
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2009-07-01 16:59:43 +00:00
|
|
|
if (list->count <= 0)
|
|
|
|
{
|
|
|
|
rb->splashf(HZ*2, "no dirs in list file: %s", RFA_FILE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* shuffle the thing */
|
|
|
|
rb->srand(*rb->current_tick);
|
2009-07-01 18:42:51 +00:00
|
|
|
if(list->count>(int)max_shuffle_size)
|
2009-07-01 16:59:43 +00:00
|
|
|
{
|
2009-07-01 18:49:51 +00:00
|
|
|
rb->splashf(HZ*2, "Too many folders: %d (room for %d)", list->count,(int)max_shuffle_size);
|
2009-07-01 16:59:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
for(i=0;i<list->count;i++)
|
|
|
|
order[i]=i;
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2009-07-01 16:59:43 +00:00
|
|
|
for(i = list->count - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
/* the rand is from 0 to RAND_MAX, so adjust to our value range */
|
|
|
|
int candidate = rb->rand() % (i + 1);
|
|
|
|
|
|
|
|
/* now swap the values at the 'i' and 'candidate' positions */
|
|
|
|
int store = order[candidate];
|
|
|
|
order[candidate] = order[i];
|
|
|
|
order[i] = store;
|
|
|
|
}
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2009-07-01 16:59:43 +00:00
|
|
|
/* We don't want whatever is playing */
|
|
|
|
if (!(rb->playlist_remove_all_tracks(NULL) == 0
|
|
|
|
&& rb->playlist_create(NULL, NULL) == 0))
|
|
|
|
{
|
|
|
|
rb->splashf(HZ*2, "Could not clear playlist");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add the lot to the playlist */
|
|
|
|
for (i = 0; i < list->count; i++)
|
|
|
|
{
|
|
|
|
if (list->folder[order[i]][0] != ' ')
|
|
|
|
{
|
|
|
|
rb->playlist_insert_directory(NULL,list->folder[order[i]],PLAYLIST_INSERT_LAST,false,false);
|
|
|
|
}
|
|
|
|
if (rb->action_userabort(TIMEOUT_NOBLOCK))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb->splash(HZ, "Done");
|
2014-04-09 07:00:36 +00:00
|
|
|
/* the core needs the audio buffer back in order to start playback. */
|
|
|
|
list = NULL;
|
|
|
|
rb->plugin_release_audio_buffer();
|
2013-07-14 11:59:39 +00:00
|
|
|
rb->playlist_start(0, 0, 0);
|
2009-07-01 16:59:43 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static enum plugin_status main_menu(void)
|
2006-10-09 10:54:17 +00:00
|
|
|
{
|
2009-07-06 00:07:25 +00:00
|
|
|
bool exit = false;
|
2009-06-16 04:25:21 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, "Main Menu", NULL,
|
|
|
|
"Generate Folder List",
|
|
|
|
"Edit Folder List",
|
|
|
|
"Export List To Textfile",
|
|
|
|
"Import List From Textfile",
|
2009-07-01 16:59:43 +00:00
|
|
|
"Play Shuffled",
|
2009-06-16 04:25:21 +00:00
|
|
|
"Quit");
|
|
|
|
|
2009-07-06 00:07:25 +00:00
|
|
|
while (!exit)
|
2006-10-09 10:54:17 +00:00
|
|
|
{
|
2009-07-05 22:15:04 +00:00
|
|
|
switch (rb->do_menu(&menu, NULL, NULL, false))
|
|
|
|
{
|
|
|
|
case 0: /* generate */
|
2006-10-09 10:54:17 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->cpu_boost(true);
|
2006-10-09 10:54:17 +00:00
|
|
|
#endif
|
2009-07-05 22:15:04 +00:00
|
|
|
generate();
|
2006-10-09 10:54:17 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->cpu_boost(false);
|
2006-10-09 10:54:17 +00:00
|
|
|
#endif
|
2020-07-24 22:14:32 +00:00
|
|
|
#ifdef HAVE_BACKLIGHT
|
2006-10-09 10:54:17 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->remote_backlight_on();
|
2006-10-09 10:54:17 +00:00
|
|
|
#endif
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->backlight_on();
|
2020-07-24 22:14:32 +00:00
|
|
|
#endif
|
2009-07-05 22:15:04 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2006-10-09 10:54:17 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->cpu_boost(true);
|
2006-10-09 10:54:17 +00:00
|
|
|
#endif
|
2009-07-05 22:15:04 +00:00
|
|
|
if (edit_list() < 0)
|
2009-07-06 00:07:25 +00:00
|
|
|
exit = true;
|
2006-10-09 10:54:17 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->cpu_boost(false);
|
2006-10-09 10:54:17 +00:00
|
|
|
#endif
|
2020-07-24 22:14:32 +00:00
|
|
|
#ifdef HAVE_BACKLIGHT
|
2006-10-09 10:54:17 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->remote_backlight_on();
|
2006-10-09 10:54:17 +00:00
|
|
|
#endif
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->backlight_on();
|
2020-07-24 22:14:32 +00:00
|
|
|
#endif
|
2009-07-05 22:15:04 +00:00
|
|
|
break;
|
|
|
|
case 2: /* export to textfile */
|
2008-04-24 10:59:56 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->cpu_boost(true);
|
2008-04-24 10:59:56 +00:00
|
|
|
#endif
|
2009-07-05 22:15:04 +00:00
|
|
|
export_list_to_file_text();
|
2008-04-24 10:59:56 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->cpu_boost(false);
|
2008-04-24 10:59:56 +00:00
|
|
|
#endif
|
2020-07-24 22:14:32 +00:00
|
|
|
#ifdef HAVE_BACKLIGHT
|
2008-04-24 10:59:56 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->remote_backlight_on();
|
2008-04-24 10:59:56 +00:00
|
|
|
#endif
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->backlight_on();
|
2020-07-24 22:14:32 +00:00
|
|
|
#endif
|
2009-07-05 22:15:04 +00:00
|
|
|
break;
|
|
|
|
case 3: /* import from textfile */
|
2008-04-24 10:59:56 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->cpu_boost(true);
|
2008-04-24 10:59:56 +00:00
|
|
|
#endif
|
2009-07-05 22:15:04 +00:00
|
|
|
import_list_from_file_text();
|
2008-04-24 10:59:56 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->cpu_boost(false);
|
2008-04-24 10:59:56 +00:00
|
|
|
#endif
|
2020-07-24 22:14:32 +00:00
|
|
|
#ifdef HAVE_BACKLIGHT
|
2008-04-24 10:59:56 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->remote_backlight_on();
|
2008-04-24 10:59:56 +00:00
|
|
|
#endif
|
2009-07-05 22:15:04 +00:00
|
|
|
rb->backlight_on();
|
2020-07-24 22:14:32 +00:00
|
|
|
#endif
|
2009-07-05 22:15:04 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (!start_shuffled_play())
|
|
|
|
return PLUGIN_ERROR;
|
|
|
|
else
|
|
|
|
return PLUGIN_GOTO_WPS;
|
|
|
|
case 5:
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
2006-10-09 10:54:17 +00:00
|
|
|
}
|
2009-07-06 00:07:25 +00:00
|
|
|
return PLUGIN_OK;
|
2006-10-09 10:54:17 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2006-10-09 10:54:17 +00:00
|
|
|
{
|
|
|
|
(void)parameter;
|
2011-02-27 09:30:33 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
rb->touchscreen_set_mode(rb->global_settings->touch_mode);
|
|
|
|
#endif
|
2006-10-09 10:54:17 +00:00
|
|
|
|
2010-05-06 21:04:40 +00:00
|
|
|
cancel = false;
|
2021-10-21 20:42:01 +00:00
|
|
|
|
2009-07-05 22:15:04 +00:00
|
|
|
return main_menu();
|
2006-10-09 10:54:17 +00:00
|
|
|
}
|