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"
|
2010-01-20 21:24:19 +00:00
|
|
|
#include "errno.h"
|
2006-08-08 10:46:39 +00:00
|
|
|
|
2010-08-24 14:30:46 +00:00
|
|
|
|
2010-08-28 22:01:44 +00:00
|
|
|
static int removed = 0; /* number of items removed */
|
2011-12-14 04:42:03 +00:00
|
|
|
static bool user_abort;
|
2006-08-08 10:46:39 +00:00
|
|
|
|
2008-05-18 07:27:10 +00:00
|
|
|
struct tidy_type {
|
|
|
|
char filestring[64];
|
2010-10-31 13:02:59 +00:00
|
|
|
int pre;
|
|
|
|
int post;
|
2008-05-18 07:27:10 +00:00
|
|
|
bool directory;
|
|
|
|
bool remove;
|
2011-12-14 04:38:30 +00:00
|
|
|
} tidy_types[64];
|
|
|
|
|
|
|
|
static size_t tidy_type_count;
|
|
|
|
|
2008-05-18 07:27:10 +00:00
|
|
|
bool tidy_loaded_and_changed = false;
|
|
|
|
|
2011-03-02 23:43:54 +00:00
|
|
|
#define DEFAULT_FILES PLUGIN_APPS_DATA_DIR "/disktidy.config"
|
|
|
|
#define CUSTOM_FILES PLUGIN_APPS_DATA_DIR "/disktidy_custom.config"
|
2010-12-25 21:11:40 +00:00
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static void add_item(const char* name, int index)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
2011-12-14 04:38:30 +00:00
|
|
|
struct tidy_type *entry = &tidy_types[index];
|
2010-12-25 21:11:40 +00:00
|
|
|
rb->strcpy(entry->filestring, name);
|
2008-05-18 07:27:10 +00:00
|
|
|
if (name[rb->strlen(name)-1] == '/')
|
|
|
|
{
|
2010-12-25 21:11:40 +00:00
|
|
|
entry->directory = true;
|
|
|
|
entry->filestring[rb->strlen(name)-1] = '\0';
|
2008-05-18 07:27:10 +00:00
|
|
|
}
|
|
|
|
else
|
2010-12-25 21:11:40 +00:00
|
|
|
entry->directory = false;
|
2011-12-14 04:38:30 +00:00
|
|
|
|
|
|
|
char *a = rb->strchr(entry->filestring, '*');
|
2010-10-31 13:02:59 +00:00
|
|
|
if (a)
|
|
|
|
{
|
2010-12-25 22:22:50 +00:00
|
|
|
entry->pre = a - entry->filestring;
|
2010-12-25 21:11:40 +00:00
|
|
|
entry->post = rb->strlen(a+1);
|
2010-10-31 13:02:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-25 21:11:40 +00:00
|
|
|
entry->pre = -1;
|
|
|
|
entry->post = -1;
|
2010-10-31 13:02:59 +00:00
|
|
|
}
|
2008-05-18 07:27:10 +00:00
|
|
|
}
|
2010-12-25 21:11:40 +00:00
|
|
|
|
2008-05-18 07:27:10 +00:00
|
|
|
static int find_file_string(const char *file, char *last_group)
|
|
|
|
{
|
|
|
|
char temp[MAX_PATH];
|
2011-12-14 04:38:30 +00:00
|
|
|
int idx_last_group = -1;
|
2008-05-18 07:27:10 +00:00
|
|
|
bool folder = false;
|
|
|
|
rb->strcpy(temp, file);
|
|
|
|
if (temp[rb->strlen(temp)-1] == '/')
|
|
|
|
{
|
|
|
|
folder = true;
|
|
|
|
temp[rb->strlen(temp)-1] = '\0';
|
|
|
|
}
|
2011-12-14 04:38:30 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < tidy_type_count; i++)
|
|
|
|
if (!rb->strcmp(tidy_types[i].filestring, temp) && folder == tidy_types[i].directory)
|
2008-05-18 07:27:10 +00:00
|
|
|
return i;
|
|
|
|
else if (!rb->strcmp(tidy_types[i].filestring, last_group))
|
|
|
|
idx_last_group = i;
|
2011-12-14 04:38:30 +00:00
|
|
|
|
|
|
|
if (file[0] == '<' || idx_last_group == -1)
|
|
|
|
return tidy_type_count;
|
|
|
|
|
|
|
|
|
2008-05-18 07:27:10 +00:00
|
|
|
/* not found, so insert it into its group */
|
2011-12-14 04:38:30 +00:00
|
|
|
for (unsigned i=idx_last_group; i<tidy_type_count; i++)
|
|
|
|
if (tidy_types[i].filestring[0] == '<')
|
2008-05-18 07:27:10 +00:00
|
|
|
{
|
2011-12-14 04:38:30 +00:00
|
|
|
idx_last_group = i;
|
|
|
|
break;
|
2008-05-18 07:27:10 +00:00
|
|
|
}
|
2011-12-14 04:38:30 +00:00
|
|
|
|
|
|
|
/* shift items up one */
|
|
|
|
for (int i=tidy_type_count;i>idx_last_group;i--)
|
|
|
|
rb->memcpy(&tidy_types[i], &tidy_types[i-1], sizeof(struct tidy_type));
|
|
|
|
|
|
|
|
tidy_type_count++;
|
|
|
|
add_item(file, idx_last_group+1);
|
|
|
|
return idx_last_group+1;
|
2008-05-18 07:27:10 +00:00
|
|
|
}
|
2008-03-22 22:03:34 +00:00
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
static void tidy_load_file(const char* file)
|
2008-05-18 07:27:10 +00:00
|
|
|
{
|
2011-12-14 04:38:30 +00:00
|
|
|
int fd = rb->open(file, O_RDONLY);
|
2008-05-18 07:27:10 +00:00
|
|
|
char buf[MAX_PATH], *str, *remove;
|
|
|
|
char last_group[MAX_PATH] = "";
|
|
|
|
if (fd < 0)
|
2011-12-14 04:38:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
while ((tidy_type_count < sizeof(tidy_types) / sizeof(tidy_types[0])) && rb->read_line(fd, buf, MAX_PATH))
|
2008-05-18 07:27:10 +00:00
|
|
|
{
|
2011-12-14 04:38:30 +00:00
|
|
|
if (!rb->settings_parseline(buf, &str, &remove))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (*str == '\\') /* escape first character ? */
|
|
|
|
str++;
|
|
|
|
unsigned i = find_file_string(str, last_group);
|
|
|
|
|
|
|
|
tidy_types[i].remove = rb->strcmp(remove, "yes");
|
|
|
|
|
|
|
|
if (i >= tidy_type_count)
|
2008-05-18 07:27:10 +00:00
|
|
|
{
|
2011-12-14 04:38:30 +00:00
|
|
|
i = tidy_type_count;
|
|
|
|
add_item(str, i);
|
|
|
|
tidy_type_count++;
|
2008-05-18 07:27:10 +00:00
|
|
|
}
|
2011-12-14 04:38:30 +00:00
|
|
|
if (str[0] == '<')
|
|
|
|
rb->strcpy(last_group, str);
|
2008-05-18 07:27:10 +00:00
|
|
|
}
|
|
|
|
rb->close(fd);
|
|
|
|
}
|
2006-08-08 10:46:39 +00:00
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
static bool match(struct tidy_type *tidy_type, const char *string, int len)
|
2010-10-31 13:02:59 +00:00
|
|
|
{
|
|
|
|
char *pattern = tidy_type->filestring;
|
2011-12-14 04:38:30 +00:00
|
|
|
|
|
|
|
if (tidy_type->pre < 0) /* no '*', just compare. */
|
|
|
|
return !rb->strcmp(pattern, string);
|
|
|
|
|
2010-10-31 13:02:59 +00:00
|
|
|
/* pattern is too long for the string. avoid 'ab*bc' matching 'abc'. */
|
|
|
|
if (len < tidy_type->pre + tidy_type->post)
|
|
|
|
return false;
|
2011-12-14 04:38:30 +00:00
|
|
|
|
2010-10-31 13:02:59 +00:00
|
|
|
/* pattern has '*', compare former part of '*' to the begining of
|
|
|
|
the string and compare next part of '*' to the end of string. */
|
2011-12-14 04:38:30 +00:00
|
|
|
return !rb->strncmp(pattern, string, tidy_type->pre) &&
|
|
|
|
!rb->strcmp(pattern + tidy_type->pre + 1, string + len - tidy_type->post);
|
2010-10-31 13:02:59 +00:00
|
|
|
}
|
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
static bool tidy_remove_item(const char *item, int attr)
|
2008-05-18 07:27:10 +00:00
|
|
|
{
|
2011-12-14 04:38:30 +00:00
|
|
|
for (struct tidy_type *t = &tidy_types[0]; t < &tidy_types[tidy_type_count]; t++)
|
|
|
|
if (match(t, item, rb->strlen(item)))
|
|
|
|
return t->remove && ((!!(attr&ATTR_DIRECTORY)) == t->directory);
|
|
|
|
|
|
|
|
return false;
|
2008-05-18 07:27:10 +00:00
|
|
|
}
|
2006-08-08 10:46:39 +00:00
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static void tidy_lcd_status(const char *name)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
|
|
|
/* display status text */
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts(0, 0, "Working ...");
|
|
|
|
rb->lcd_puts(0, 1, name);
|
2007-01-18 01:38:50 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-08-28 22:01:44 +00:00
|
|
|
rb->lcd_putsf(0, 2, "Cleaned up %d items", removed);
|
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
|
|
|
}
|
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static int tidy_path_append_entry(char *path, struct dirent *entry, int *path_length)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
2010-01-20 21:24:19 +00:00
|
|
|
int name_len = rb->strlen(entry->d_name);
|
|
|
|
/* for the special case of path="/" this is one bigger but it's not a problem */
|
|
|
|
int new_length = *path_length + name_len + 1;
|
2011-12-14 04:38:30 +00:00
|
|
|
|
2010-01-20 21:24:19 +00:00
|
|
|
/* check overflow (keep space for trailing zero) */
|
|
|
|
if(new_length >= MAX_PATH)
|
|
|
|
return 0;
|
2011-12-14 04:38:30 +00:00
|
|
|
|
2010-01-20 21:24:19 +00:00
|
|
|
/* special case for path <> "/" */
|
|
|
|
if(rb->strcmp(path, "/") != 0)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
2010-01-20 21:24:19 +00:00
|
|
|
rb->strcat(path + *path_length, "/");
|
|
|
|
(*path_length)++;
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
2010-01-20 21:24:19 +00:00
|
|
|
/* strcat is unsafe but the previous check normally avoid any problem */
|
|
|
|
/* use path_length to optimise */
|
2011-12-14 04:38:30 +00:00
|
|
|
|
2010-01-20 21:24:19 +00:00
|
|
|
rb->strcat(path + *path_length, entry->d_name);
|
|
|
|
*path_length += name_len;
|
2011-12-14 04:38:30 +00:00
|
|
|
|
2010-01-20 21:24:19 +00:00
|
|
|
return 1;
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static void tidy_path_remove_entry(char *path, int old_path_length, int *path_length)
|
2010-01-20 21:24:19 +00:00
|
|
|
{
|
|
|
|
path[old_path_length] = '\0';
|
|
|
|
*path_length = old_path_length;
|
|
|
|
}
|
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
/* path is assumed to be array of size MAX_PATH. */
|
|
|
|
static enum plugin_status tidy_clean(char *path, int *path_length, bool rmdir)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
2010-01-20 21:24:19 +00:00
|
|
|
int old_path_length = *path_length;
|
2009-08-06 12:44:12 +00:00
|
|
|
|
2010-08-28 22:01:44 +00:00
|
|
|
tidy_lcd_status(path);
|
2009-08-06 12:44:12 +00:00
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
DIR *dir = rb->opendir(path);
|
|
|
|
if (!dir)
|
|
|
|
return PLUGIN_ERROR;
|
2009-08-06 12:44:12 +00:00
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
struct dirent *entry;
|
|
|
|
while ((entry = rb->readdir(dir)))
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
2011-12-14 04:38:30 +00:00
|
|
|
/* check for user input and usb connect */
|
|
|
|
int button = rb->get_action(CONTEXT_STD, TIMEOUT_NOBLOCK);
|
|
|
|
if (button == ACTION_STD_CANCEL)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
2011-12-14 04:38:30 +00:00
|
|
|
rb->closedir(dir);
|
2011-12-14 04:42:03 +00:00
|
|
|
user_abort = true;
|
2011-12-14 04:38:30 +00:00
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
|
|
|
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
|
|
|
{
|
|
|
|
rb->closedir(dir);
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
rb->yield();
|
2009-08-06 12:44:12 +00:00
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
struct dirinfo info = rb->dir_get_info(dir, entry);
|
|
|
|
if (!rmdir && !tidy_remove_item(entry->d_name, info.attribute))
|
|
|
|
continue;
|
2009-08-06 12:44:12 +00:00
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
/* get absolute path, returns an error if path is too long */
|
|
|
|
if(!tidy_path_append_entry(path, entry, path_length))
|
|
|
|
continue; /* silent error */
|
2009-08-06 12:44:12 +00:00
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
if (info.attribute & ATTR_DIRECTORY)
|
|
|
|
{
|
|
|
|
/* dir ignore "." and ".." */
|
|
|
|
if (rb->strcmp(entry->d_name, ".") && rb->strcmp(entry->d_name, ".."))
|
|
|
|
tidy_clean(path, path_length, true);
|
|
|
|
}
|
|
|
|
else
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
2011-12-14 04:38:30 +00:00
|
|
|
removed++;
|
|
|
|
rb->remove(path);
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
2011-12-14 04:38:30 +00:00
|
|
|
|
|
|
|
/* restore path */
|
|
|
|
tidy_path_remove_entry(path, old_path_length, path_length);
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
2011-12-14 04:38:30 +00:00
|
|
|
rb->closedir(dir);
|
|
|
|
|
|
|
|
if (rmdir)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
2011-12-14 04:38:30 +00:00
|
|
|
removed++;
|
|
|
|
rb->rmdir(path);
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
2011-12-14 04:38:30 +00:00
|
|
|
|
|
|
|
return PLUGIN_OK;
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
static enum plugin_status tidy_do(void)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
|
|
|
/* clean disk and display num of items removed */
|
2010-01-20 21:24:19 +00:00
|
|
|
char path[MAX_PATH];
|
2009-08-06 12:44:12 +00:00
|
|
|
|
2006-08-08 10:46:39 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
rb->cpu_boost(true);
|
|
|
|
#endif
|
2009-08-06 12:44:12 +00:00
|
|
|
|
2010-01-20 21:24:19 +00:00
|
|
|
rb->strcpy(path, "/");
|
2011-12-14 04:38:30 +00:00
|
|
|
int path_length = rb->strlen(path);
|
|
|
|
enum plugin_status status = tidy_clean(path, &path_length, false);
|
2009-08-06 12:44:12 +00:00
|
|
|
|
2006-08-08 10:46:39 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
rb->cpu_boost(false);
|
|
|
|
#endif
|
2009-08-06 12:44:12 +00:00
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
if (status == PLUGIN_OK)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
|
|
|
rb->lcd_clear_display();
|
2011-12-14 04:42:03 +00:00
|
|
|
if (user_abort)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
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();
|
|
|
|
}
|
2010-08-28 22:01:44 +00:00
|
|
|
rb->splashf(HZ*2, "Cleaned up %d items", removed);
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static enum themable_icons get_icon(int item, void * data)
|
2008-05-18 07:27:10 +00:00
|
|
|
{
|
|
|
|
(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;
|
|
|
|
}
|
|
|
|
|
2009-08-20 16:47:44 +00:00
|
|
|
static const char* get_name(int selected_item, void * data,
|
|
|
|
char * buffer, size_t buffer_len)
|
2008-05-18 07:27:10 +00:00
|
|
|
{
|
|
|
|
(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;
|
|
|
|
}
|
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static int list_action_callback(int action, struct gui_synclist *lists)
|
2008-05-18 07:27:10 +00:00
|
|
|
{
|
2011-12-14 04:38:30 +00:00
|
|
|
if (action != ACTION_STD_OK)
|
|
|
|
return action;
|
|
|
|
|
|
|
|
unsigned selection = rb->gui_synclist_get_sel_pos(lists);
|
|
|
|
if (tidy_types[selection].filestring[0] == '<')
|
2008-05-18 07:27:10 +00:00
|
|
|
{
|
2011-12-14 04:38:30 +00:00
|
|
|
bool all = !rb->strcmp(tidy_types[selection].filestring, "< ALL >");
|
|
|
|
bool none= !rb->strcmp(tidy_types[selection].filestring, "< NONE >");
|
|
|
|
|
|
|
|
if (all || none)
|
2008-05-18 07:27:10 +00:00
|
|
|
{
|
2011-12-14 04:38:30 +00:00
|
|
|
for (unsigned i=0; i<tidy_type_count; i++)
|
|
|
|
if (tidy_types[i].filestring[0] != '<')
|
|
|
|
tidy_types[i].remove = all;
|
2008-05-18 07:27:10 +00:00
|
|
|
}
|
2011-12-14 04:38:30 +00:00
|
|
|
else /* toggle all untill the next <> */
|
|
|
|
while (++selection < tidy_type_count && tidy_types[selection].filestring[0] != '<')
|
|
|
|
tidy_types[selection].remove = !tidy_types[selection].remove;
|
2008-05-18 07:27:10 +00:00
|
|
|
}
|
2011-12-14 04:38:30 +00:00
|
|
|
else
|
|
|
|
tidy_types[selection].remove = !tidy_types[selection].remove;
|
|
|
|
tidy_loaded_and_changed = true;
|
|
|
|
return ACTION_REDRAW;
|
2008-05-18 07:27:10 +00:00
|
|
|
}
|
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
static void tidy_lcd_menu(void)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
2009-08-06 12:44:12 +00:00
|
|
|
int selection = 0;
|
2011-12-14 04:38:30 +00:00
|
|
|
struct simplelist_info list;
|
2009-08-06 12:44:12 +00:00
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, "Disktidy Menu", NULL, "Start Cleaning",
|
|
|
|
"Files to Clean", "Quit");
|
2009-08-06 12:44:12 +00:00
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
for(;;)
|
2008-03-26 03:35:24 +00:00
|
|
|
switch(rb->do_menu(&menu, &selection, NULL, false))
|
2007-01-18 01:38:50 +00:00
|
|
|
{
|
2011-12-14 04:38:30 +00:00
|
|
|
default:
|
2011-12-14 04:42:03 +00:00
|
|
|
user_abort = true;
|
2011-12-14 04:38:30 +00:00
|
|
|
case 0:
|
|
|
|
return; /* start cleaning */
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
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-18 07:27:10 +00:00
|
|
|
break;
|
2007-01-18 01:38:50 +00:00
|
|
|
}
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|
|
|
|
|
2010-12-25 21:01:07 +00:00
|
|
|
/* Creates a file and writes information about what files to
|
|
|
|
delete and what to keep to it.
|
|
|
|
*/
|
2011-12-14 04:38:30 +00:00
|
|
|
static void save_config(void)
|
2010-12-25 21:01:07 +00:00
|
|
|
{
|
2011-12-14 04:38:30 +00:00
|
|
|
int fd = rb->creat(CUSTOM_FILES, 0666);
|
|
|
|
if (fd < 0)
|
|
|
|
return;
|
2010-12-25 21:01:07 +00:00
|
|
|
|
2011-12-14 04:38:30 +00:00
|
|
|
for (unsigned i=0; i<tidy_type_count; i++)
|
|
|
|
rb->fdprintf(fd, "%s%s%s: %s\n",
|
|
|
|
tidy_types[i].filestring[0] == '#' ? "\\" : "",
|
|
|
|
tidy_types[i].filestring,
|
2011-05-08 21:21:02 +00:00
|
|
|
tidy_types[i].directory ? "/" : "",
|
|
|
|
tidy_types[i].remove ? "yes" : "no");
|
2011-12-14 04:38:30 +00:00
|
|
|
rb->close(fd);
|
2010-12-25 21:01:07 +00:00
|
|
|
}
|
|
|
|
|
2006-08-08 10:46:39 +00:00
|
|
|
/* this is the plugin entry point */
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2006-08-08 10:46:39 +00:00
|
|
|
{
|
|
|
|
(void)parameter;
|
|
|
|
|
2008-05-18 07:27:10 +00:00
|
|
|
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
|
|
|
}
|
2011-12-14 04:38:30 +00:00
|
|
|
tidy_lcd_menu();
|
2008-05-18 07:27:10 +00:00
|
|
|
if (tidy_loaded_and_changed)
|
2011-12-14 04:38:30 +00:00
|
|
|
save_config();
|
2009-08-06 12:44:12 +00:00
|
|
|
|
2011-12-14 04:42:03 +00:00
|
|
|
return user_abort ? PLUGIN_OK : tidy_do();
|
2006-08-08 10:46:39 +00:00
|
|
|
}
|