1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 David Dent
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
22 static struct plugin_api
* rb
;
24 /* function return values */
28 TIDY_RETURN_ERROR
= 1,
30 TIDY_RETURN_ABORT
= 3,
33 /* Which systems junk are we removing */
41 /* variable button definitions */
42 #if CONFIG_KEYPAD == PLAYER_PAD
43 #define TIDY_STOP BUTTON_STOP
45 #elif CONFIG_KEYPAD == RECORDER_PAD
46 #define TIDY_STOP BUTTON_OFF
48 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
49 #define TIDY_STOP BUTTON_OFF
51 #elif CONFIG_KEYPAD == ONDIO_PAD
52 #define TIDY_STOP BUTTON_OFF
54 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
55 (CONFIG_KEYPAD == IRIVER_H300_PAD)
56 #define TIDY_STOP BUTTON_OFF
58 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
59 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
60 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
61 #define TIDY_STOP BUTTON_MENU
63 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
64 #define TIDY_STOP BUTTON_POWER
66 #elif CONFIG_KEYPAD == GIGABEAT_PAD
67 #define TIDY_STOP BUTTON_POWER
69 #elif CONFIG_KEYPAD == SANSA_E200_PAD
70 #define TIDY_STOP BUTTON_POWER
72 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
73 #define TIDY_STOP BUTTON_POWER
76 #error DISKTIDY: Unsupported keypad
80 void tidy_lcd_status(const char *name
, int *removed
)
82 char text
[24]; /* "Cleaned up nnnnn items" */
84 /* display status text */
85 rb
->lcd_clear_display();
86 rb
->lcd_puts(0, 0, "Working ...");
87 rb
->lcd_puts(0, 1, name
);
88 rb
->snprintf(text
, 24, "Cleaned up %d items", *removed
);
89 #ifdef HAVE_LCD_BITMAP
90 rb
->lcd_puts(0, 2, text
);
95 void tidy_get_absolute_path(struct dirent
*entry
, char *fullname
,
98 /* gets absolute path using dirent and name */
99 rb
->strcpy(fullname
, name
);
100 if (rb
->strlen(name
) > 1)
102 rb
->strcat(fullname
, "/");
104 rb
->strcat(fullname
, entry
->d_name
);
107 enum tidy_return
tidy_removedir(const char *name
, int *removed
)
109 /* delete directory */
110 struct dirent
*entry
;
111 enum tidy_return status
= TIDY_RETURN_OK
;
114 char fullname
[MAX_PATH
];
116 /* display status text */
117 tidy_lcd_status(name
, removed
);
121 dir
= rb
->opendir(name
);
124 while((status
== TIDY_RETURN_OK
) && ((entry
= rb
->readdir(dir
)) != 0))
127 /* check for user input and usb connect */
128 button
= rb
->button_get(false);
129 if (button
== TIDY_STOP
)
132 return TIDY_RETURN_ABORT
;
134 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
137 return TIDY_RETURN_USB
;
142 /* get absolute path */
143 tidy_get_absolute_path(entry
, fullname
, name
);
145 if (entry
->attribute
& ATTR_DIRECTORY
)
147 /* dir ignore "." and ".." */
148 if ((rb
->strcmp(entry
->d_name
, ".") != 0) && \
149 (rb
->strcmp(entry
->d_name
, "..") != 0))
151 tidy_removedir(fullname
, removed
);
158 rb
->remove(fullname
);
168 status
= TIDY_RETURN_ERROR
;
173 enum tidy_return
tidy_clean(const char *name
, int *removed
, \
174 enum tidy_system system
)
176 /* deletes junk files and dirs left by system */
177 struct dirent
*entry
;
178 enum tidy_return status
= TIDY_RETURN_OK
;
180 int del
; /* has the item been deleted */
182 char fullname
[MAX_PATH
];
184 /* display status text */
185 tidy_lcd_status(name
, removed
);
189 dir
= rb
->opendir(name
);
192 while((status
== TIDY_RETURN_OK
) && ((entry
= rb
->readdir(dir
)) != 0))
195 /* check for user input and usb connect */
196 button
= rb
->button_get(false);
197 if (button
== TIDY_STOP
)
200 return TIDY_RETURN_ABORT
;
202 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
205 return TIDY_RETURN_USB
;
210 if (entry
->attribute
& ATTR_DIRECTORY
)
212 /* directory ignore "." and ".." */
213 if ((rb
->strcmp(entry
->d_name
, ".") != 0) && \
214 (rb
->strcmp(entry
->d_name
, "..") != 0))
218 /* get absolute path */
219 tidy_get_absolute_path(entry
, fullname
, name
);
221 /* check if we are in root directory "/" */
222 if (rb
->strcmp(name
, "/") == 0)
224 if ((system
== TIDY_MAC
) || (system
== TIDY_BOTH
))
226 /* mac directories */
227 if (rb
->strcmp(entry
->d_name
, ".Trashes") == 0)
230 tidy_removedir(fullname
, removed
);
237 if ((system
== TIDY_WIN
) || (system
== TIDY_BOTH
))
239 /* windows directories */
240 if (rb
->strcmp(entry
->d_name
, "Recycled") == 0 \
241 || rb
->strcmp(entry
->d_name
, "System Volume Information") == 0)
244 tidy_removedir(fullname
, removed
);
253 /* dir not deleted so clean it */
254 status
= tidy_clean(fullname
, removed
, system
);
263 if ((system
== TIDY_MAC
) || (system
== TIDY_BOTH
))
265 /* remove mac files */
266 if ((rb
->strcmp(entry
->d_name
, ".DS_Store") == 0) || \
267 (rb
->strncmp(entry
->d_name
, "._", 2) == 0))
269 *removed
+= 1; /* increment removed files counter */
271 /* get absolute path */
272 char fullname
[MAX_PATH
];
273 tidy_get_absolute_path(entry
, fullname
, name
);
276 rb
->remove(fullname
);
283 if ((system
== TIDY_WIN
) || (system
== TIDY_BOTH
))
285 /* remove windows files*/
286 if ((rb
->strcmp(entry
->d_name
, "Thumbs.db") == 0))
288 *removed
+= 1; /* increment removed files counter */
290 /* get absolute path */
291 char fullname
[MAX_PATH
];
292 tidy_get_absolute_path(entry
, fullname
, name
);
295 rb
->remove(fullname
);
307 return TIDY_RETURN_ERROR
;
311 enum plugin_status
tidy_do(enum tidy_system system
)
313 /* clean disk and display num of items removed */
315 enum tidy_return status
;
316 char text
[24]; /* "Cleaned up nnnnn items" */
318 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
322 status
= tidy_clean("/", &removed
, system
);
324 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
325 rb
->cpu_boost(false);
328 if ((status
== TIDY_RETURN_OK
) || (status
== TIDY_RETURN_ABORT
))
330 rb
->lcd_clear_display();
331 rb
->snprintf(text
, 24, "Cleaned up %d items", removed
);
332 if (status
== TIDY_RETURN_ABORT
)
334 rb
->splash(HZ
, "User aborted");
335 rb
->lcd_clear_display();
337 rb
->splash(HZ
*2, text
);
342 int tidy_lcd_menu(void)
344 int selection
, ret
= 2;
345 bool menu_quit
= false;
347 MENUITEM_STRINGLIST(menu
,"Disktidy Menu",NULL
,"Start Cleaning",
348 "Files to Clean","Quit");
350 static const struct opt_items system_option
[3] =
359 switch(rb
->do_menu(&menu
, &selection
))
363 menu_quit
= true; /* start cleaning */
367 rb
->set_option("Files to Clean", &ret
, INT
, system_option
, 3, NULL
);
371 ret
= 99; /* exit plugin */
379 /* this is the plugin entry point */
380 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
382 enum tidy_system system
= TIDY_BOTH
;
383 enum tidy_return status
;
389 switch(tidy_lcd_menu())
408 status
= tidy_do(system
);
414 case TIDY_RETURN_ERROR
:
416 case TIDY_RETURN_USB
:
417 return PLUGIN_USB_CONNECTED
;
418 case TIDY_RETURN_ABORT
:
423 if (rb
->default_event_handler(rb
->button_get(false)) == SYS_USB_CONNECTED
)
424 return PLUGIN_USB_CONNECTED
;