summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorDan Everton <dan@iocaine.org>2006-08-08 10:46:39 +0000
committerDan Everton <dan@iocaine.org>2006-08-08 10:46:39 +0000
commit5814551865df5cfb172f1e401c6807b463766bf8 (patch)
tree638288d6922df180eba0c4abe7285041b9c21e67 /apps
parente7aeebf0bfe5f673818f30757b23fea7b8436b81 (diff)
downloadrockbox-5814551865df5cfb172f1e401c6807b463766bf8.tar.gz
rockbox-5814551865df5cfb172f1e401c6807b463766bf8.zip
Add disktidy plugin (FS#2596).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10482 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/plugin.c2
-rw-r--r--apps/plugin.h3
-rw-r--r--apps/plugins/SOURCES1
-rw-r--r--apps/plugins/disktidy.c479
4 files changed, 484 insertions, 1 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index 96d55abfd1..4474d0d5ee 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -467,6 +467,8 @@ static const struct plugin_api rockbox_api = {
467 !defined(SIMULATOR) 467 !defined(SIMULATOR)
468 lcd_yuv_blit, 468 lcd_yuv_blit,
469#endif 469#endif
470
471 PREFIX(rmdir),
470}; 472};
471 473
472int plugin_load(const char* plugin, void* parameter) 474int plugin_load(const char* plugin, void* parameter)
diff --git a/apps/plugin.h b/apps/plugin.h
index 69fbea9a22..b764d860c3 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -104,7 +104,7 @@
104#define PLUGIN_MAGIC 0x526F634B /* RocK */ 104#define PLUGIN_MAGIC 0x526F634B /* RocK */
105 105
106/* increase this every time the api struct changes */ 106/* increase this every time the api struct changes */
107#define PLUGIN_API_VERSION 26 107#define PLUGIN_API_VERSION 27
108 108
109/* update this to latest version if a change to the api struct breaks 109/* update this to latest version if a change to the api struct breaks
110 backwards compatibility (and please take the opportunity to sort in any 110 backwards compatibility (and please take the opportunity to sort in any
@@ -546,6 +546,7 @@ struct plugin_api {
546 int x, int y, int width, int height); 546 int x, int y, int width, int height);
547#endif 547#endif
548 548
549 int (*PREFIX(rmdir))(const char *name);
549}; 550};
550 551
551/* plugin header */ 552/* plugin header */
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES
index 6f6d2e74b8..f60877e643 100644
--- a/apps/plugins/SOURCES
+++ b/apps/plugins/SOURCES
@@ -25,6 +25,7 @@ wavplay.c
25#ifndef IRIVER_IFP7XX_SERIES /* Temporarily disable plugins for iFP7xx */ 25#ifndef IRIVER_IFP7XX_SERIES /* Temporarily disable plugins for iFP7xx */
26dice.c 26dice.c
27#ifdef HAVE_LCD_BITMAP /* Not for the Player */ 27#ifdef HAVE_LCD_BITMAP /* Not for the Player */
28disktidy.c
28text_editor.c 29text_editor.c
29 30
30/* Plugins needing the grayscale lib on low-depth LCDs */ 31/* Plugins needing the grayscale lib on low-depth LCDs */
diff --git a/apps/plugins/disktidy.c b/apps/plugins/disktidy.c
new file mode 100644
index 0000000000..321a1b4b31
--- /dev/null
+++ b/apps/plugins/disktidy.c
@@ -0,0 +1,479 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 David Dent
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "plugin.h"
20
21PLUGIN_HEADER
22static struct plugin_api* rb;
23
24/* function return values */
25enum tidy_return
26{
27 TIDY_RETURN_OK = 0,
28 TIDY_RETURN_ERROR = 1,
29 TIDY_RETURN_USB = 2,
30 TIDY_RETURN_ABORT = 3,
31};
32
33/* Which systems junk are we removing */
34enum tidy_system
35{
36 TIDY_MAC = 0,
37 TIDY_WIN = 1,
38 TIDY_BOTH = 2,
39};
40
41/* variable button definitions */
42#if CONFIG_KEYPAD == RECORDER_PAD
43#define TIDY_DO BUTTON_ON
44#define TIDY_STOP BUTTON_OFF
45#define TIDY_LEFT BUTTON_LEFT
46#define TIDY_RIGHT BUTTON_RIGHT
47
48#elif CONFIG_KEYPAD == ONDIO_PAD
49#define TIDY_DO BUTTON_MENU
50#define TIDY_STOP BUTTON_OFF
51#define TIDY_LEFT BUTTON_LEFT
52#define TIDY_RIGHT BUTTON_RIGHT
53
54#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
55 (CONFIG_KEYPAD == IRIVER_H300_PAD)
56#define TIDY_DO BUTTON_SELECT
57#define TIDY_STOP BUTTON_OFF
58#define TIDY_LEFT BUTTON_LEFT
59#define TIDY_RIGHT BUTTON_RIGHT
60
61#elif (CONFIG_KEYPAD == IPOD_3G_PAD) || \
62 (CONFIG_KEYPAD == IPOD_4G_PAD)
63#define TIDY_DO BUTTON_SELECT
64#define TIDY_STOP BUTTON_MENU
65#define TIDY_LEFT BUTTON_LEFT
66#define TIDY_RIGHT BUTTON_RIGHT
67
68#elif (CONFIG_KEYPAD == IAUDIO_X5_PAD)
69#define TIDY_DO BUTTON_PLAY
70#define TIDY_STOP BUTTON_POWER
71#define TIDY_LEFT BUTTON_LEFT
72#define TIDY_RIGHT BUTTON_RIGHT
73
74#elif (CONFIG_KEYPAD == IAUDIO_X5_PAD)
75#define TIDY_DO BUTTON_PLAY
76#define TIDY_STOP BUTTON_POWER
77#define TIDY_LEFT BUTTON_LEFT
78#define TIDY_RIGHT BUTTON_RIGHT
79
80#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
81#define TIDY_DO BUTTON_SELECT
82#define TIDY_STOP BUTTON_A
83#define TIDY_LEFT BUTTON_LEFT
84#define TIDY_RIGHT BUTTON_RIGHT
85
86#else
87 #error DISKTIDY: Unsupported keypad
88#endif
89
90
91void tidy_lcd_status(const char *name, int *removed)
92{
93 char text[24]; /* "Cleaned up nnnnn items" */
94
95 /* display status text */
96 rb->lcd_clear_display();
97 rb->lcd_puts(0, 0, "Working ...");
98 rb->lcd_puts(0, 1, name);
99 rb->snprintf(text, 24, "Cleaned up %d items", *removed);
100 rb->lcd_puts(0, 2, text);
101 rb->lcd_update();
102}
103
104void tidy_get_absolute_path(struct dirent *entry, char *fullname,
105 const char* name)
106{
107 /* gets absolute path using dirent and name */
108 rb->strcpy(fullname, name);
109 if (rb->strlen(name) > 1)
110 {
111 rb->strcat(fullname, "/");
112 }
113 rb->strcat(fullname, entry->d_name);
114}
115
116enum tidy_return tidy_removedir(const char *name, int *removed)
117{
118 /* delete directory */
119 struct dirent *entry;
120 enum tidy_return status = TIDY_RETURN_OK;
121 int button;
122 DIR *dir;
123 char fullname[MAX_PATH];
124
125 /* display status text */
126 tidy_lcd_status(name, removed);
127
128 rb->yield();
129
130 dir = rb->opendir(name);
131 if (dir)
132 {
133 while((status == TIDY_RETURN_OK) && ((entry = rb->readdir(dir)) != 0))
134 /* walk directory */
135 {
136 /* check for user input and usb connect */
137 button = rb->button_get(false);
138 if (button == TIDY_STOP)
139 {
140 rb->closedir(dir);
141 return TIDY_RETURN_ABORT;
142 }
143 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
144 {
145 rb->closedir(dir);
146 return TIDY_RETURN_USB;
147 }
148
149 rb->yield();
150
151 /* get absolute path */
152 tidy_get_absolute_path(entry, fullname, name);
153
154 if (entry->attribute & ATTR_DIRECTORY)
155 {
156 /* dir ignore "." and ".." */
157 if ((rb->strcmp(entry->d_name, ".") != 0) && \
158 (rb->strcmp(entry->d_name, "..") != 0))
159 {
160 tidy_removedir(fullname, removed);
161 }
162 }
163 else
164 {
165 /* file */
166 *removed += 1;
167 rb->remove(fullname);
168 }
169 }
170 rb->closedir(dir);
171 /* rmdir */
172 *removed += 1;
173 rb->rmdir(name);
174 }
175 else
176 {
177 status = TIDY_RETURN_ERROR;
178 }
179 return status;
180}
181
182enum tidy_return tidy_clean(const char *name, int *removed, \
183 enum tidy_system system)
184{
185 /* deletes junk files and dirs left by system */
186 struct dirent *entry;
187 enum tidy_return status = TIDY_RETURN_OK;
188 int button;
189 int del; /* has the item been deleted */
190 DIR *dir;
191 char fullname[MAX_PATH];
192
193 /* display status text */
194 tidy_lcd_status(name, removed);
195
196 rb->yield();
197
198 dir = rb->opendir(name);
199 if (dir)
200 {
201 while((status == TIDY_RETURN_OK) && ((entry = rb->readdir(dir)) != 0))
202 /* walk directory */
203 {
204 /* check for user input and usb connect */
205 button = rb->button_get(false);
206 if (button == TIDY_STOP)
207 {
208 rb->closedir(dir);
209 return TIDY_RETURN_ABORT;
210 }
211 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
212 {
213 rb->closedir(dir);
214 return TIDY_RETURN_USB;
215 }
216
217 rb->yield();
218
219 if (entry->attribute & ATTR_DIRECTORY)
220 {
221 /* directory ignore "." and ".." */
222 if ((rb->strcmp(entry->d_name, ".") != 0) && \
223 (rb->strcmp(entry->d_name, "..") != 0))
224 {
225 del = 0;
226
227 /* get absolute path */
228 tidy_get_absolute_path(entry, fullname, name);
229
230 /* check if we are in root directory "/" */
231 if (rb->strcmp(name, "/") == 0)
232 {
233 if ((system == TIDY_MAC) || (system == TIDY_BOTH))
234 {
235 /* mac directories */
236 if (rb->strcmp(entry->d_name, ".Trashes") == 0)
237 {
238 /* delete dir */
239 tidy_removedir(fullname, removed);
240 del = 1;
241 }
242 }
243
244 if (del == 0)
245 {
246 if ((system == TIDY_WIN) || (system == TIDY_BOTH))
247 {
248 /* windows directories */
249 if (rb->strcmp(entry->d_name, "Recycled") == 0 \
250 || rb->strcmp(entry->d_name, "System Volume Information") == 0)
251 {
252 /* delete dir */
253 tidy_removedir(fullname, removed);
254 del = 1;
255 }
256 }
257 }
258 }
259
260 if (del == 0)
261 {
262 /* dir not deleted so clean it */
263 status = tidy_clean(fullname, removed, system);
264 }
265 }
266 }
267 else
268 {
269 /* file */
270 del = 0;
271
272 if ((system == TIDY_MAC) || (system == TIDY_BOTH))
273 {
274 /* remove mac files */
275 if ((rb->strcmp(entry->d_name, ".DS_Store") == 0) || \
276 (rb->strncmp(entry->d_name, "._", 2) == 0))
277 {
278 *removed += 1; /* increment removed files counter */
279
280 /* get absolute path */
281 char fullname[MAX_PATH];
282 tidy_get_absolute_path(entry, fullname, name);
283
284 /* delete file */
285 rb->remove(fullname);
286 del = 1;
287 }
288 }
289
290 if (del == 0)
291 {
292 if ((system == TIDY_WIN) || (system == TIDY_BOTH))
293 {
294 /* remove windows files*/
295 if ((rb->strcmp(entry->d_name, "Thumbs.db") == 0))
296 {
297 *removed += 1; /* increment removed files counter */
298
299 /* get absolute path */
300 char fullname[MAX_PATH];
301 tidy_get_absolute_path(entry, fullname, name);
302
303 /* delete file */
304 rb->remove(fullname);
305 del = 1;
306 }
307 }
308 }
309 }
310 }
311 rb->closedir(dir);
312 return status;
313 }
314 else
315 {
316 return TIDY_RETURN_ERROR;
317 }
318}
319
320enum plugin_status tidy_do(enum tidy_system system)
321{
322 /* clean disk and display num of items removed */
323 int removed = 0;
324 enum tidy_return status;
325 char text[24]; /* "Cleaned up nnnnn items" */
326
327#ifdef HAVE_ADJUSTABLE_CPU_FREQ
328 rb->cpu_boost(true);
329#endif
330
331 status = tidy_clean("/", &removed, system);
332
333#ifdef HAVE_ADJUSTABLE_CPU_FREQ
334 rb->cpu_boost(false);
335#endif
336
337 if ((status == TIDY_RETURN_OK) || (status == TIDY_RETURN_ABORT))
338 {
339 rb->lcd_clear_display();
340 rb->snprintf(text, 24, "Cleaned up %d items", removed);
341 if (status == TIDY_RETURN_ABORT)
342 {
343 rb->splash(HZ, true, "User aborted");
344 rb->lcd_clear_display();
345 }
346 rb->splash(HZ*2, true, text);
347 }
348 return status;
349}
350
351void tidy_lcd_menu(enum tidy_system system)
352{
353 /* show menu text */
354 rb->lcd_clear_display();
355
356 /* show keys */
357#if CONFIG_KEYPAD == RECORDER_PAD
358 rb->lcd_puts(0, 0, "[On] to clean up");
359 rb->lcd_puts(0, 1, "[Off] to exit/abort");
360#elif CONFIG_KEYPAD == ONDIO_PAD
361 rb->lcd_puts(0, 0, "[Menu] to clean up");
362 rb->lcd_puts(0, 1, "[Off] to exit/abort");
363#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
364 (CONFIG_KEYPAD == IRIVER_H300_PAD)
365 rb->lcd_puts(0, 0, "[Navi] to clean up");
366 rb->lcd_puts(0, 1, "[Off] to exit/abort");
367#elif (CONFIG_KEYPAD == IPOD_3G_PAD) || \
368 (CONFIG_KEYPAD == IPOD_4G_PAD)
369 rb->lcd_puts(0, 0, "[Select] to clean up");
370 rb->lcd_puts(0, 1, "[Menu] to exit/abort");
371#elif (CONFIG_KEYPAD == IAUDIO_X5_PAD)
372 rb->lcd_puts(0, 0, "[Play] to clean up");
373 rb->lcd_puts(0, 1, "[Power] to exit/abort");
374#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
375 rb->lcd_puts(0, 0, "[Select] to clean up");
376 rb->lcd_puts(0, 1, "[A] to exit/abort");
377#else
378 #error DISKTIDY: Unsupported model
379#endif
380
381 /* show selcted system */
382 switch (system)
383 {
384 case TIDY_MAC:
385 rb->lcd_puts(0, 2, "< Mac >");
386 rb->lcd_puts(0, 3, "Deletes");
387 rb->lcd_puts(0, 4, "._* .DS_Store");
388 rb->lcd_puts(0, 5, "/.Trashes/");
389 break;
390 case TIDY_WIN:
391 rb->lcd_puts(0, 2, "< Win >");
392 rb->lcd_puts(0, 3, "Deletes");
393 rb->lcd_puts(0, 4, "Thumbs.db /Recycled/");
394 rb->lcd_puts(0, 5, "/System Volume Information/");
395 break;
396 case TIDY_BOTH:
397 rb->lcd_puts(0, 2, "< Both >");
398 break;
399
400 }
401 rb->lcd_update();
402}
403
404/* this is the plugin entry point */
405enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
406{
407 enum tidy_system system = TIDY_MAC;
408 enum tidy_return status;
409 int button;
410
411 (void)parameter;
412
413 rb = api;
414
415 tidy_lcd_menu(system);
416
417 while (1)
418 {
419 button = rb->button_get(false);
420
421 if (button == TIDY_LEFT)
422 {
423 if (system == 0)
424 {
425 system = 2;
426 }
427 else
428 {
429 system --;
430 }
431 tidy_lcd_menu(system);
432 }
433
434 if (button == TIDY_RIGHT)
435 {
436 if (system == 2)
437 {
438 system = 0;
439 }
440 else
441 {
442 system ++;
443 }
444 tidy_lcd_menu(system);
445 }
446
447 if (button == TIDY_DO)
448 {
449
450 status = tidy_do(system);
451
452 switch (status)
453 {
454 case TIDY_RETURN_OK:
455 return PLUGIN_OK;
456 case TIDY_RETURN_ERROR:
457 return PLUGIN_ERROR;
458 case TIDY_RETURN_USB:
459 return PLUGIN_USB_CONNECTED;
460 case TIDY_RETURN_ABORT:
461 return PLUGIN_OK;
462 }
463 }
464
465 if (button == TIDY_STOP)
466 {
467 return PLUGIN_OK;
468 }
469
470 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
471 {
472 return PLUGIN_USB_CONNECTED;
473 }
474
475 rb->yield();
476 }
477
478 return PLUGIN_OK;
479}