summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Menes <rmenes@rockbox.org>2010-10-31 13:02:59 +0000
committerRobert Menes <rmenes@rockbox.org>2010-10-31 13:02:59 +0000
commit1e47628a9f5d51218d2e385b7f85e09dd75df860 (patch)
tree61045271cf82f685f8e94f67d86317bbbee4b847
parente26d0c62e07d1b1c1087a065242ed7ab1a2c522f (diff)
downloadrockbox-1e47628a9f5d51218d2e385b7f85e09dd75df860.tar.gz
rockbox-1e47628a9f5d51218d2e385b7f85e09dd75df860.zip
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
-rw-r--r--apps/plugins/disktidy.c51
-rw-r--r--apps/plugins/disktidy.config2
-rw-r--r--manual/plugins/disktidy.tex7
3 files changed, 46 insertions, 14 deletions
diff --git a/apps/plugins/disktidy.c b/apps/plugins/disktidy.c
index df0076f93d..92232bf17a 100644
--- a/apps/plugins/disktidy.c
+++ b/apps/plugins/disktidy.c
@@ -36,6 +36,8 @@ enum tidy_return
36#define MAX_TYPES 64 36#define MAX_TYPES 64
37struct tidy_type { 37struct tidy_type {
38 char filestring[64]; 38 char filestring[64];
39 int pre;
40 int post;
39 bool directory; 41 bool directory;
40 bool remove; 42 bool remove;
41} tidy_types[MAX_TYPES]; 43} tidy_types[MAX_TYPES];
@@ -46,6 +48,7 @@ bool tidy_loaded_and_changed = false;
46#define CUSTOM_FILES PLUGIN_APPS_DIR "/disktidy_custom.config" 48#define CUSTOM_FILES PLUGIN_APPS_DIR "/disktidy_custom.config"
47void add_item(const char* name, int index) 49void add_item(const char* name, int index)
48{ 50{
51 char *a;
49 rb->strcpy(tidy_types[index].filestring, name); 52 rb->strcpy(tidy_types[index].filestring, name);
50 if (name[rb->strlen(name)-1] == '/') 53 if (name[rb->strlen(name)-1] == '/')
51 { 54 {
@@ -54,6 +57,17 @@ void add_item(const char* name, int index)
54 } 57 }
55 else 58 else
56 tidy_types[index].directory = false; 59 tidy_types[index].directory = false;
60 a = rb->strchr(name, '*');
61 if (a)
62 {
63 tidy_types[index].pre = a - name;
64 tidy_types[index].post = rb->strlen(a+1);
65 }
66 else
67 {
68 tidy_types[index].pre = -1;
69 tidy_types[index].post = -1;
70 }
57} 71}
58static int find_file_string(const char *file, char *last_group) 72static int find_file_string(const char *file, char *last_group)
59{ 73{
@@ -89,9 +103,7 @@ static int find_file_string(const char *file, char *last_group)
89 /* shift items up one */ 103 /* shift items up one */
90 for (i=tidy_type_count;i>idx_last_group;i--) 104 for (i=tidy_type_count;i>idx_last_group;i--)
91 { 105 {
92 rb->strcpy(tidy_types[i].filestring, tidy_types[i-1].filestring); 106 rb->memcpy(&tidy_types[i], &tidy_types[i-1], sizeof(struct tidy_type));
93 tidy_types[i].directory = tidy_types[i-1].directory;
94 tidy_types[i].remove = tidy_types[i-1].remove;
95 } 107 }
96 tidy_type_count++; 108 tidy_type_count++;
97 add_item(file, idx_last_group+1); 109 add_item(file, idx_last_group+1);
@@ -132,22 +144,33 @@ bool tidy_load_file(const char* file)
132 return true; 144 return true;
133} 145}
134 146
147static bool match(struct tidy_type *tidy_type, char *string, int len)
148{
149 char *pattern = tidy_type->filestring;
150 if (tidy_type->pre < 0)
151 {
152 /* no '*', just compare. */
153 return (rb->strcmp(pattern, string) == 0);
154 }
155 /* pattern is too long for the string. avoid 'ab*bc' matching 'abc'. */
156 if (len < tidy_type->pre + tidy_type->post)
157 return false;
158 /* pattern has '*', compare former part of '*' to the begining of
159 the string and compare next part of '*' to the end of string. */
160 return (rb->strncmp(pattern, string, tidy_type->pre) == 0 &&
161 rb->strcmp(pattern + tidy_type->pre + 1,
162 string + len - tidy_type->post) == 0);
163}
164
135bool tidy_remove_item(char *item, int attr) 165bool tidy_remove_item(char *item, int attr)
136{ 166{
137 int i; 167 int i;
138 char *file; 168 int len;
139 bool ret = false, rem = false; 169 bool ret = false;
170 len = rb->strlen(item);
140 for (i=0; ret == false && i < tidy_type_count; i++) 171 for (i=0; ret == false && i < tidy_type_count; i++)
141 { 172 {
142 file = tidy_types[i].filestring; 173 if (match(&tidy_types[i], item, len))
143 if (file[rb->strlen(file)-1] == '*')
144 {
145 if (!rb->strncmp(file, item, rb->strlen(file)-1))
146 rem = true;
147 }
148 else if (!rb->strcmp(file, item))
149 rem = true;
150 if (rem)
151 { 174 {
152 if (!tidy_types[i].remove) 175 if (!tidy_types[i].remove)
153 return false; 176 return false;
diff --git a/apps/plugins/disktidy.config b/apps/plugins/disktidy.config
index 0c062e700f..1de2451e30 100644
--- a/apps/plugins/disktidy.config
+++ b/apps/plugins/disktidy.config
@@ -1,5 +1,7 @@
1# Disktidy config 1# Disktidy config
2# When adding a new file, make sure its NOT enabled 2# When adding a new file, make sure its NOT enabled
3# WARNING: Be careful when you use custom entries.
4# You could accidentally delete important files.
3< ALL >: no 5< ALL >: no
4< NONE >: no 6< NONE >: no
5< Windows >: no 7< Windows >: no
diff --git a/manual/plugins/disktidy.tex b/manual/plugins/disktidy.tex
index c1c58271ea..c0d429cb7f 100644
--- a/manual/plugins/disktidy.tex
+++ b/manual/plugins/disktidy.tex
@@ -5,6 +5,13 @@
5 menu and select `Start Cleaning' to begin to process. The settings 5 menu and select `Start Cleaning' to begin to process. The settings
6 are stored in \fname{.rockbox/rocks/apps/disktidy.config}, in a plain text 6 are stored in \fname{.rockbox/rocks/apps/disktidy.config}, in a plain text
7 file that is user-modifiable to allow more entries to be added. 7 file that is user-modifiable to allow more entries to be added.
8
9 You can use up to one '*' as a wild-card character which matches any string.
10 the first '*' is recognized as a wild-card character and any additional '*' are
11 literal '*'.
12
13 \warn{Be careful when you use custom entries.
14 You could accidentally delete important files.}
8 15
9 \subsubsection{Available Options} 16 \subsubsection{Available Options}
10 \begin{description} 17 \begin{description}