1
0
Fork 0
forked from len0rd/rockbox

Commit FS #11682 by Teruaki Kawashima: fix the disktidy plugin

not cleaning custo


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28414 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Menes 2010-10-31 13:02:59 +00:00
parent e26d0c62e0
commit 1e47628a9f
3 changed files with 46 additions and 14 deletions

View file

@ -36,6 +36,8 @@ enum tidy_return
#define MAX_TYPES 64 #define MAX_TYPES 64
struct tidy_type { struct tidy_type {
char filestring[64]; char filestring[64];
int pre;
int post;
bool directory; bool directory;
bool remove; bool remove;
} tidy_types[MAX_TYPES]; } tidy_types[MAX_TYPES];
@ -46,6 +48,7 @@ bool tidy_loaded_and_changed = false;
#define CUSTOM_FILES PLUGIN_APPS_DIR "/disktidy_custom.config" #define CUSTOM_FILES PLUGIN_APPS_DIR "/disktidy_custom.config"
void add_item(const char* name, int index) void add_item(const char* name, int index)
{ {
char *a;
rb->strcpy(tidy_types[index].filestring, name); rb->strcpy(tidy_types[index].filestring, name);
if (name[rb->strlen(name)-1] == '/') if (name[rb->strlen(name)-1] == '/')
{ {
@ -54,6 +57,17 @@ void add_item(const char* name, int index)
} }
else else
tidy_types[index].directory = false; tidy_types[index].directory = false;
a = rb->strchr(name, '*');
if (a)
{
tidy_types[index].pre = a - name;
tidy_types[index].post = rb->strlen(a+1);
}
else
{
tidy_types[index].pre = -1;
tidy_types[index].post = -1;
}
} }
static int find_file_string(const char *file, char *last_group) static int find_file_string(const char *file, char *last_group)
{ {
@ -89,9 +103,7 @@ static int find_file_string(const char *file, char *last_group)
/* shift items up one */ /* shift items up one */
for (i=tidy_type_count;i>idx_last_group;i--) for (i=tidy_type_count;i>idx_last_group;i--)
{ {
rb->strcpy(tidy_types[i].filestring, tidy_types[i-1].filestring); rb->memcpy(&tidy_types[i], &tidy_types[i-1], sizeof(struct tidy_type));
tidy_types[i].directory = tidy_types[i-1].directory;
tidy_types[i].remove = tidy_types[i-1].remove;
} }
tidy_type_count++; tidy_type_count++;
add_item(file, idx_last_group+1); add_item(file, idx_last_group+1);
@ -132,22 +144,33 @@ bool tidy_load_file(const char* file)
return true; return true;
} }
static bool match(struct tidy_type *tidy_type, char *string, int len)
{
char *pattern = tidy_type->filestring;
if (tidy_type->pre < 0)
{
/* no '*', just compare. */
return (rb->strcmp(pattern, string) == 0);
}
/* pattern is too long for the string. avoid 'ab*bc' matching 'abc'. */
if (len < tidy_type->pre + tidy_type->post)
return false;
/* pattern has '*', compare former part of '*' to the begining of
the string and compare next part of '*' to the end of string. */
return (rb->strncmp(pattern, string, tidy_type->pre) == 0 &&
rb->strcmp(pattern + tidy_type->pre + 1,
string + len - tidy_type->post) == 0);
}
bool tidy_remove_item(char *item, int attr) bool tidy_remove_item(char *item, int attr)
{ {
int i; int i;
char *file; int len;
bool ret = false, rem = false; bool ret = false;
len = rb->strlen(item);
for (i=0; ret == false && i < tidy_type_count; i++) for (i=0; ret == false && i < tidy_type_count; i++)
{ {
file = tidy_types[i].filestring; if (match(&tidy_types[i], item, len))
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) if (!tidy_types[i].remove)
return false; return false;

View file

@ -1,5 +1,7 @@
# Disktidy config # Disktidy config
# When adding a new file, make sure its NOT enabled # When adding a new file, make sure its NOT enabled
# WARNING: Be careful when you use custom entries.
# You could accidentally delete important files.
< ALL >: no < ALL >: no
< NONE >: no < NONE >: no
< Windows >: no < Windows >: no

View file

@ -6,6 +6,13 @@
are stored in \fname{.rockbox/rocks/apps/disktidy.config}, in a plain text are stored in \fname{.rockbox/rocks/apps/disktidy.config}, in a plain text
file that is user-modifiable to allow more entries to be added. file that is user-modifiable to allow more entries to be added.
You can use up to one '*' as a wild-card character which matches any string.
the first '*' is recognized as a wild-card character and any additional '*' are
literal '*'.
\warn{Be careful when you use custom entries.
You could accidentally delete important files.}
\subsubsection{Available Options} \subsubsection{Available Options}
\begin{description} \begin{description}
\item[All] selects all Linux, OS X, and Windows files. \item[All] selects all Linux, OS X, and Windows files.