2006-08-08 10:46:39 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 David Dent
|
|
|
|
*
|
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-08-08 10:46:39 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "plugin.h"
|
|
|
|
|
|
|
|
PLUGIN_HEADER
|
2008-05-13 09:57:56 +00:00
|
|
|
static const struct plugin_api* rb;
|
2008-05-18 07:27:10 +00:00
|
|
|
MEM_FUNCTION_WRAPPERS(rb)
|
2006-08-08 10:46:39 +00:00
|
|
|
|
|
|
|
/* function return values */
|
|
|
|
enum tidy_return
|
|
|
|
{
|
|
|
|
TIDY_RETURN_OK = 0,
|
|
|
|
TIDY_RETURN_ERROR = 1,
|
|
|
|
TIDY_RETURN_USB = 2,
|
|
|
|
TIDY_RETURN_ABORT = 3,
|
|
|
|
};
|
|
|
|
|
2008-05-18 07:27:10 +00:00
|
|
|
#define MAX_TYPES 64
|
|
|
|
struct tidy_type {
|
|
|
|
char filestring[64];
|
|
|
|
bool directory;
|
|
|
|
bool remove;
|
|
|
|
} tidy_types[MAX_TYPES];
|
|
|
|
int tidy_type_count;
|
|
|
|
bool tidy_loaded_and_changed = false;
|
|
|
|
|
|
|
|
#define DEFAULT_FILES PLUGIN_APPS_DIR "/disktidy.config"
|
|
|
|
#define CUSTOM_FILES PLUGIN_APPS_DIR "/disktidy_custom.config"
|
|
|
|
void add_item(const char* name, int index)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
2008-05-18 07:27:10 +00:00
|
|
|
rb->strcpy(tidy_types[index].filestring, name);
|
|
|
|
if (name[rb->strlen(name)-1] == '/')
|
|
|
|
{
|
|
|
|
tidy_types[index].directory = true;
|
|
|
|
tidy_types[index].filestring[rb->strlen(name)-1] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tidy_types[index].directory = false;
|
|
|
|
}
|
|
|
|
static int find_file_string(const char *file, char *last_group)
|
|
|
|
{
|
|
|
|
char temp[MAX_PATH];
|
|
|
|
int i = 0, idx_last_group = -1;
|
|
|
|
bool folder = false;
|
|
|
|
rb->strcpy(temp, file);
|
|
|
|
if (temp[rb->strlen(temp)-1] == '/')
|
|
|
|
{
|
|
|
|
folder = true;
|
|
|
|
temp[rb->strlen(temp)-1] = '\0';
|
|
|
|
}
|
|
|
|
while (i<tidy_type_count)
|
|
|
|
{
|
|
|
|
if (!rb->strcmp(tidy_types[i].filestring, temp) &&
|
|
|
|
folder == tidy_types[i].directory)
|
|
|
|
return i;
|
|
|
|
else if (!rb->strcmp(tidy_types[i].filestring, last_group))
|
|
|
|
idx_last_group = i;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
/* not found, so insert it into its group */
|
|
|
|
if (file[0] != '<' && idx_last_group != -1)
|
|
|
|
{
|
|
|
|
for (i=idx_last_group; i<tidy_type_count; i++)
|
|
|
|
{
|
|
|
|
if (tidy_types[i].filestring[0] == '<')
|
|
|
|
{
|
|
|
|
idx_last_group = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* shift items up one */
|
|
|
|
for (i=tidy_type_count;i>idx_last_group;i--)
|
|
|
|
{
|
|
|
|
rb->strcpy(tidy_types[i].filestring, tidy_types[i-1].filestring);
|
|
|
|
tidy_types[i].directory = tidy_types[i-1].directory;
|
|
|
|
tidy_types[i].remove = tidy_types[i-1].remove;
|
|
|
|
}
|
|
|
|
tidy_type_count++;
|
|
|
|
add_item(file, idx_last_group+1);
|
|
|
|
return idx_last_group+1;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
2008-03-22 22:03:34 +00:00
|
|
|
|
2008-05-18 07:27:10 +00:00
|
|
|
bool tidy_load_file(const char* file)
|
|
|
|
{
|
|
|
|
int fd = rb->open(file, O_RDONLY), i;
|
|
|
|
char buf[MAX_PATH], *str, *remove;
|
|
|
|
char last_group[MAX_PATH] = "";
|
|
|
|
bool new;
|
|
|
|
if (fd < 0)
|
|
|
|
return false;
|
|
|
|
while ((tidy_type_count < MAX_TYPES) &&
|
|
|
|
rb->read_line(fd, buf, MAX_PATH))
|
|
|
|
{
|
|
|
|
if (rb->settings_parseline(buf, &str, &remove))
|
|
|
|
{
|
|
|
|
i = find_file_string(str, last_group);
|
|
|
|
new = (i >= tidy_type_count);
|
|
|
|
if (!rb->strcmp(remove, "yes"))
|
|
|
|
tidy_types[i].remove = true;
|
|
|
|
else tidy_types[i].remove = false;
|
|
|
|
if (new)
|
|
|
|
{
|
|
|
|
i = tidy_type_count;
|
|
|
|
add_item(str, i);
|
|
|
|
tidy_type_count++;
|
|
|
|
}
|
|
|
|
if (str[0] == '<')
|
|
|
|
rb->strcpy(last_group, str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb->close(fd);
|
|
|
|
return true;
|
|
|
|
}
|
2006-08-08 10:46:39 +00:00
|
|
|
|
2008-05-18 07:27:10 +00:00
|
|
|
bool tidy_remove_item(char *item, int attr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *file;
|
|
|
|
bool ret = false, rem = false;
|
|
|
|
for (i=0; ret == false && i < tidy_type_count; i++)
|
|
|
|
{
|
|
|
|
file = tidy_types[i].filestring;
|
|
|
|
if (file[rb->strlen(file)-1] == '*')
|
|
|
|
{
|
|
|
|
if (!rb->strncmp(file, item, rb->strlen(file)-1))
|
|
|
|
rem = true;
|
|
|
|
}
|
|
|
|
else if (!rb->strcmp(file, item))
|
|
|
|
rem = true;
|
|
|
|
if (rem)
|
|
|
|
{
|
|
|
|
if (!tidy_types[i].remove)
|
|
|
|
return false;
|
|
|
|
if (attr&ATTR_DIRECTORY)
|
|
|
|
ret = tidy_types[i].directory;
|
|
|
|
else ret = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2006-08-08 10:46:39 +00:00
|
|
|
|
|
|
|
void tidy_lcd_status(const char *name, int *removed)
|
|
|
|
{
|
|
|
|
char text[24]; /* "Cleaned up nnnnn items" */
|
|
|
|
|
|
|
|
/* display status text */
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts(0, 0, "Working ...");
|
|
|
|
rb->lcd_puts(0, 1, name);
|
|
|
|
rb->snprintf(text, 24, "Cleaned up %d items", *removed);
|
2007-01-18 01:38:50 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-08-08 10:46:39 +00:00
|
|
|
rb->lcd_puts(0, 2, text);
|
2007-01-18 01:38:50 +00:00
|
|
|
#endif
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_update();
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tidy_get_absolute_path(struct dirent *entry, char *fullname,
|
|
|
|
const char* name)
|
|
|
|
{
|
|
|
|
/* gets absolute path using dirent and name */
|
|
|
|
rb->strcpy(fullname, name);
|
|
|
|
if (rb->strlen(name) > 1)
|
|
|
|
{
|
|
|
|
rb->strcat(fullname, "/");
|
|
|
|
}
|
|
|
|
rb->strcat(fullname, entry->d_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum tidy_return tidy_removedir(const char *name, int *removed)
|
|
|
|
{
|
|
|
|
/* delete directory */
|
|
|
|
struct dirent *entry;
|
|
|
|
enum tidy_return status = TIDY_RETURN_OK;
|
|
|
|
int button;
|
|
|
|
DIR *dir;
|
|
|
|
char fullname[MAX_PATH];
|
|
|
|
|
|
|
|
/* display status text */
|
|
|
|
tidy_lcd_status(name, removed);
|
|
|
|
|
|
|
|
rb->yield();
|
|
|
|
|
|
|
|
dir = rb->opendir(name);
|
|
|
|
if (dir)
|
|
|
|
{
|
|
|
|
while((status == TIDY_RETURN_OK) && ((entry = rb->readdir(dir)) != 0))
|
|
|
|
/* walk directory */
|
|
|
|
{
|
|
|
|
/* check for user input and usb connect */
|
2008-05-18 07:27:10 +00:00
|
|
|
button = rb->get_action(CONTEXT_STD, TIMEOUT_NOBLOCK);
|
|
|
|
if (button == ACTION_STD_CANCEL)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
|
|
|
rb->closedir(dir);
|
|
|
|
return TIDY_RETURN_ABORT;
|
|
|
|
}
|
|
|
|
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
2008-04-21 20:16:45 +00:00
|
|
|
{
|
|
|
|
rb->closedir(dir);
|
|
|
|
return TIDY_RETURN_USB;
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rb->yield();
|
|
|
|
|
|
|
|
/* get absolute path */
|
|
|
|
tidy_get_absolute_path(entry, fullname, name);
|
|
|
|
|
|
|
|
if (entry->attribute & ATTR_DIRECTORY)
|
|
|
|
{
|
|
|
|
/* dir ignore "." and ".." */
|
|
|
|
if ((rb->strcmp(entry->d_name, ".") != 0) && \
|
|
|
|
(rb->strcmp(entry->d_name, "..") != 0))
|
|
|
|
{
|
|
|
|
tidy_removedir(fullname, removed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* file */
|
|
|
|
*removed += 1;
|
|
|
|
rb->remove(fullname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb->closedir(dir);
|
|
|
|
/* rmdir */
|
|
|
|
*removed += 1;
|
|
|
|
rb->rmdir(name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = TIDY_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-05-18 07:27:10 +00:00
|
|
|
enum tidy_return tidy_clean(const char *name, int *removed)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
|
|
|
/* deletes junk files and dirs left by system */
|
|
|
|
struct dirent *entry;
|
|
|
|
enum tidy_return status = TIDY_RETURN_OK;
|
|
|
|
int button;
|
|
|
|
int del; /* has the item been deleted */
|
|
|
|
DIR *dir;
|
|
|
|
char fullname[MAX_PATH];
|
|
|
|
|
|
|
|
/* display status text */
|
|
|
|
tidy_lcd_status(name, removed);
|
|
|
|
|
|
|
|
rb->yield();
|
|
|
|
|
|
|
|
dir = rb->opendir(name);
|
|
|
|
if (dir)
|
|
|
|
{
|
|
|
|
while((status == TIDY_RETURN_OK) && ((entry = rb->readdir(dir)) != 0))
|
|
|
|
/* walk directory */
|
|
|
|
{
|
|
|
|
/* check for user input and usb connect */
|
2008-05-18 07:27:10 +00:00
|
|
|
button = rb->get_action(CONTEXT_STD, TIMEOUT_NOBLOCK);
|
|
|
|
if (button == ACTION_STD_CANCEL)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
|
|
|
rb->closedir(dir);
|
|
|
|
return TIDY_RETURN_ABORT;
|
|
|
|
}
|
|
|
|
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
2008-04-21 20:16:45 +00:00
|
|
|
{
|
|
|
|
rb->closedir(dir);
|
|
|
|
return TIDY_RETURN_USB;
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rb->yield();
|
|
|
|
|
|
|
|
if (entry->attribute & ATTR_DIRECTORY)
|
|
|
|
{
|
|
|
|
/* directory ignore "." and ".." */
|
|
|
|
if ((rb->strcmp(entry->d_name, ".") != 0) && \
|
|
|
|
(rb->strcmp(entry->d_name, "..") != 0))
|
|
|
|
{
|
|
|
|
del = 0;
|
|
|
|
|
|
|
|
/* get absolute path */
|
|
|
|
tidy_get_absolute_path(entry, fullname, name);
|
|
|
|
|
2008-05-18 07:27:10 +00:00
|
|
|
if (tidy_remove_item(entry->d_name, entry->attribute))
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
2008-05-18 07:27:10 +00:00
|
|
|
/* delete dir */
|
|
|
|
tidy_removedir(fullname, removed);
|
|
|
|
del = 1;
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (del == 0)
|
|
|
|
{
|
|
|
|
/* dir not deleted so clean it */
|
2008-05-18 07:27:10 +00:00
|
|
|
status = tidy_clean(fullname, removed);
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* file */
|
|
|
|
del = 0;
|
2008-05-18 07:27:10 +00:00
|
|
|
if (tidy_remove_item(entry->d_name, entry->attribute))
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
2008-05-18 07:27:10 +00:00
|
|
|
*removed += 1; /* increment removed files counter */
|
|
|
|
|
|
|
|
/* get absolute path */
|
|
|
|
char fullname[MAX_PATH];
|
|
|
|
tidy_get_absolute_path(entry, fullname, name);
|
|
|
|
|
|
|
|
/* delete file */
|
|
|
|
rb->remove(fullname);
|
|
|
|
del = 1;
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
2008-04-21 20:16:45 +00:00
|
|
|
}
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
|
|
|
rb->closedir(dir);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return TIDY_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-18 07:27:10 +00:00
|
|
|
enum plugin_status tidy_do(void)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
|
|
|
/* clean disk and display num of items removed */
|
|
|
|
int removed = 0;
|
|
|
|
enum tidy_return status;
|
|
|
|
char text[24]; /* "Cleaned up nnnnn items" */
|
|
|
|
|
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
rb->cpu_boost(true);
|
|
|
|
#endif
|
|
|
|
|
2008-05-18 07:27:10 +00:00
|
|
|
status = tidy_clean("/", &removed);
|
2006-08-08 10:46:39 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
rb->cpu_boost(false);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((status == TIDY_RETURN_OK) || (status == TIDY_RETURN_ABORT))
|
|
|
|
{
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->snprintf(text, 24, "Cleaned up %d items", removed);
|
|
|
|
if (status == TIDY_RETURN_ABORT)
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "User aborted");
|
2006-08-08 10:46:39 +00:00
|
|
|
rb->lcd_clear_display();
|
|
|
|
}
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*2, text);
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-05-18 07:27:10 +00:00
|
|
|
enum themable_icons get_icon(int item, void * data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
if (tidy_types[item].filestring[0] == '<') /* special type */
|
|
|
|
return Icon_Folder;
|
|
|
|
else if (tidy_types[item].remove)
|
|
|
|
return Icon_Cursor;
|
|
|
|
else
|
|
|
|
return Icon_NOICON;
|
|
|
|
}
|
|
|
|
|
|
|
|
char * get_name(int selected_item, void * data,
|
|
|
|
char * buffer, size_t buffer_len)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
if (tidy_types[selected_item].directory)
|
|
|
|
{
|
|
|
|
rb->snprintf(buffer, buffer_len, "%s/",
|
|
|
|
tidy_types[selected_item].filestring);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
return tidy_types[selected_item].filestring;
|
|
|
|
}
|
|
|
|
|
|
|
|
int list_action_callback(int action, struct gui_synclist *lists)
|
|
|
|
{
|
|
|
|
if (action == ACTION_STD_OK)
|
|
|
|
{
|
|
|
|
int selection = rb->gui_synclist_get_sel_pos(lists);
|
|
|
|
if (tidy_types[selection].filestring[0] == '<')
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (!rb->strcmp(tidy_types[selection].filestring, "< ALL >"))
|
|
|
|
{
|
|
|
|
for (i=0; i<tidy_type_count; i++)
|
|
|
|
{
|
|
|
|
if (tidy_types[i].filestring[0] != '<')
|
|
|
|
tidy_types[i].remove = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!rb->strcmp(tidy_types[selection].filestring, "< NONE >"))
|
|
|
|
{
|
|
|
|
for (i=0; i<tidy_type_count; i++)
|
|
|
|
{
|
|
|
|
if (tidy_types[i].filestring[0] != '<')
|
|
|
|
tidy_types[i].remove = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* toggle all untill the next <> */
|
|
|
|
{
|
|
|
|
selection++;
|
|
|
|
while (selection < tidy_type_count &&
|
|
|
|
tidy_types[selection].filestring[0] != '<')
|
|
|
|
{
|
|
|
|
tidy_types[selection].remove = !tidy_types[selection].remove;
|
|
|
|
selection++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tidy_types[selection].remove = !tidy_types[selection].remove;
|
|
|
|
tidy_loaded_and_changed = true;
|
|
|
|
return ACTION_REDRAW;
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2007-01-18 01:38:50 +00:00
|
|
|
int tidy_lcd_menu(void)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
2008-04-21 20:16:45 +00:00
|
|
|
int selection, ret = 3;
|
2007-01-18 23:37:51 +00:00
|
|
|
bool menu_quit = false;
|
2006-08-08 10:46:39 +00:00
|
|
|
|
2007-03-28 07:33:18 +00:00
|
|
|
MENUITEM_STRINGLIST(menu,"Disktidy Menu",NULL,"Start Cleaning",
|
|
|
|
"Files to Clean","Quit");
|
2006-08-08 10:46:39 +00:00
|
|
|
|
2007-01-18 23:37:51 +00:00
|
|
|
while (!menu_quit)
|
2007-01-18 01:38:50 +00:00
|
|
|
{
|
2008-03-26 03:35:24 +00:00
|
|
|
switch(rb->do_menu(&menu, &selection, NULL, false))
|
2007-01-18 01:38:50 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
case 0:
|
2007-01-18 23:37:51 +00:00
|
|
|
menu_quit = true; /* start cleaning */
|
|
|
|
break;
|
2007-01-18 01:38:50 +00:00
|
|
|
|
|
|
|
case 1:
|
2008-05-18 07:27:10 +00:00
|
|
|
{
|
2008-05-22 03:39:59 +00:00
|
|
|
bool show_icons = rb->global_settings->show_icons;
|
2008-05-18 07:27:10 +00:00
|
|
|
struct simplelist_info list;
|
2008-05-22 03:39:59 +00:00
|
|
|
rb->global_settings->show_icons = true; /* force the icons so its readable */
|
2008-05-18 07:27:10 +00:00
|
|
|
rb->simplelist_info_init(&list, "Files to Clean", tidy_type_count, NULL);
|
|
|
|
list.get_icon = get_icon;
|
|
|
|
list.get_name = get_name;
|
|
|
|
list.action_callback = list_action_callback;
|
|
|
|
rb->simplelist_show_list(&list);
|
2008-05-22 03:39:59 +00:00
|
|
|
rb->global_settings->show_icons = show_icons;
|
2008-05-18 07:27:10 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-01-18 01:38:50 +00:00
|
|
|
|
2007-03-28 07:33:18 +00:00
|
|
|
default:
|
2007-01-18 23:37:51 +00:00
|
|
|
ret = 99; /* exit plugin */
|
|
|
|
menu_quit = true;
|
|
|
|
break;
|
2007-01-18 01:38:50 +00:00
|
|
|
}
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
2007-01-18 23:37:51 +00:00
|
|
|
return ret;
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this is the plugin entry point */
|
2008-05-13 09:57:56 +00:00
|
|
|
enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
|
|
|
enum tidy_return status;
|
2008-05-18 07:27:10 +00:00
|
|
|
int ret;
|
2006-08-08 10:46:39 +00:00
|
|
|
(void)parameter;
|
|
|
|
|
|
|
|
rb = api;
|
2008-05-18 07:27:10 +00:00
|
|
|
tidy_type_count = 0;
|
|
|
|
tidy_load_file(DEFAULT_FILES);
|
|
|
|
tidy_load_file(CUSTOM_FILES);
|
|
|
|
if (tidy_type_count == 0)
|
2007-01-18 01:38:50 +00:00
|
|
|
{
|
2008-05-18 07:27:10 +00:00
|
|
|
rb->splash(3*HZ, "Missing disktidy.config file");
|
|
|
|
return PLUGIN_ERROR;
|
2007-01-18 01:38:50 +00:00
|
|
|
}
|
2008-05-18 07:27:10 +00:00
|
|
|
ret = tidy_lcd_menu();
|
|
|
|
if (tidy_loaded_and_changed)
|
|
|
|
{
|
|
|
|
int fd = rb->creat(CUSTOM_FILES);
|
|
|
|
int i;
|
|
|
|
if (fd >= 0)
|
|
|
|
{
|
|
|
|
for(i=0;i<tidy_type_count;i++)
|
|
|
|
{
|
|
|
|
rb->fdprintf(fd, "%s%c: %s\n", tidy_types[i].filestring,
|
|
|
|
tidy_types[i].directory?'/':'\0',
|
|
|
|
tidy_types[i].remove?"yes":"no");
|
|
|
|
}
|
|
|
|
rb->close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret == 99)
|
|
|
|
return PLUGIN_OK;
|
2007-01-18 02:28:57 +00:00
|
|
|
while (true)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
2008-05-18 07:27:10 +00:00
|
|
|
status = tidy_do();
|
2006-08-08 10:46:39 +00:00
|
|
|
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case TIDY_RETURN_OK:
|
|
|
|
return PLUGIN_OK;
|
|
|
|
case TIDY_RETURN_ERROR:
|
|
|
|
return PLUGIN_ERROR;
|
|
|
|
case TIDY_RETURN_USB:
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
case TIDY_RETURN_ABORT:
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
2007-01-18 01:38:50 +00:00
|
|
|
}
|
2006-08-08 10:46:39 +00:00
|
|
|
|
2007-01-18 02:28:57 +00:00
|
|
|
if (rb->default_event_handler(rb->button_get(false)) == SYS_USB_CONNECTED)
|
2007-01-18 01:38:50 +00:00
|
|
|
return PLUGIN_USB_CONNECTED;
|
2006-08-08 10:46:39 +00:00
|
|
|
|
2007-01-18 01:38:50 +00:00
|
|
|
rb->yield();
|
|
|
|
|
2006-08-08 10:46:39 +00:00
|
|
|
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|