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 (CONFIG_KEYPAD == SANSA_C200_PAD)
71 #define TIDY_STOP BUTTON_POWER
73 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
74 #define TIDY_STOP BUTTON_POWER
76 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
77 #define TIDY_STOP BUTTON_BACK
79 #elif CONFIG_KEYPAD == MROBE100_PAD
80 #define TIDY_STOP BUTTON_POWER
82 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
83 #define TIDY_STOP BUTTON_RC_REC
85 #elif CONFIG_KEYPAD == COWOND2_PAD
86 #define TIDY_STOP BUTTON_POWER
89 #error No keymap defined!
93 void tidy_lcd_status(const char *name
, int *removed
)
95 char text
[24]; /* "Cleaned up nnnnn items" */
97 /* display status text */
98 rb
->lcd_clear_display();
99 rb
->lcd_puts(0, 0, "Working ...");
100 rb
->lcd_puts(0, 1, name
);
101 rb
->snprintf(text
, 24, "Cleaned up %d items", *removed
);
102 #ifdef HAVE_LCD_BITMAP
103 rb
->lcd_puts(0, 2, text
);
108 void tidy_get_absolute_path(struct dirent
*entry
, char *fullname
,
111 /* gets absolute path using dirent and name */
112 rb
->strcpy(fullname
, name
);
113 if (rb
->strlen(name
) > 1)
115 rb
->strcat(fullname
, "/");
117 rb
->strcat(fullname
, entry
->d_name
);
120 enum tidy_return
tidy_removedir(const char *name
, int *removed
)
122 /* delete directory */
123 struct dirent
*entry
;
124 enum tidy_return status
= TIDY_RETURN_OK
;
127 char fullname
[MAX_PATH
];
129 /* display status text */
130 tidy_lcd_status(name
, removed
);
134 dir
= rb
->opendir(name
);
137 while((status
== TIDY_RETURN_OK
) && ((entry
= rb
->readdir(dir
)) != 0))
140 /* check for user input and usb connect */
141 button
= rb
->button_get(false);
142 if (button
== TIDY_STOP
)
145 return TIDY_RETURN_ABORT
;
147 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
150 return TIDY_RETURN_USB
;
155 /* get absolute path */
156 tidy_get_absolute_path(entry
, fullname
, name
);
158 if (entry
->attribute
& ATTR_DIRECTORY
)
160 /* dir ignore "." and ".." */
161 if ((rb
->strcmp(entry
->d_name
, ".") != 0) && \
162 (rb
->strcmp(entry
->d_name
, "..") != 0))
164 tidy_removedir(fullname
, removed
);
171 rb
->remove(fullname
);
181 status
= TIDY_RETURN_ERROR
;
186 enum tidy_return
tidy_clean(const char *name
, int *removed
, \
187 enum tidy_system system
)
189 /* deletes junk files and dirs left by system */
190 struct dirent
*entry
;
191 enum tidy_return status
= TIDY_RETURN_OK
;
193 int del
; /* has the item been deleted */
195 char fullname
[MAX_PATH
];
197 /* display status text */
198 tidy_lcd_status(name
, removed
);
202 dir
= rb
->opendir(name
);
205 while((status
== TIDY_RETURN_OK
) && ((entry
= rb
->readdir(dir
)) != 0))
208 /* check for user input and usb connect */
209 button
= rb
->button_get(false);
210 if (button
== TIDY_STOP
)
213 return TIDY_RETURN_ABORT
;
215 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
218 return TIDY_RETURN_USB
;
223 if (entry
->attribute
& ATTR_DIRECTORY
)
225 /* directory ignore "." and ".." */
226 if ((rb
->strcmp(entry
->d_name
, ".") != 0) && \
227 (rb
->strcmp(entry
->d_name
, "..") != 0))
231 /* get absolute path */
232 tidy_get_absolute_path(entry
, fullname
, name
);
234 /* check if we are in root directory "/" */
235 if (rb
->strcmp(name
, "/") == 0)
237 if ((system
== TIDY_MAC
) || (system
== TIDY_BOTH
))
239 /* mac directories */
240 if (rb
->strcmp(entry
->d_name
, ".Trashes") == 0)
243 tidy_removedir(fullname
, removed
);
250 if ((system
== TIDY_WIN
) || (system
== TIDY_BOTH
))
252 /* windows directories */
253 if (rb
->strcmp(entry
->d_name
, "Recycled") == 0 \
254 || rb
->strcmp(entry
->d_name
, "System Volume Information") == 0)
257 tidy_removedir(fullname
, removed
);
266 /* dir not deleted so clean it */
267 status
= tidy_clean(fullname
, removed
, system
);
276 if ((system
== TIDY_MAC
) || (system
== TIDY_BOTH
))
278 /* remove mac files */
279 if ((rb
->strcmp(entry
->d_name
, ".DS_Store") == 0) || \
280 (rb
->strncmp(entry
->d_name
, "._", 2) == 0))
282 *removed
+= 1; /* increment removed files counter */
284 /* get absolute path */
285 char fullname
[MAX_PATH
];
286 tidy_get_absolute_path(entry
, fullname
, name
);
289 rb
->remove(fullname
);
296 if ((system
== TIDY_WIN
) || (system
== TIDY_BOTH
))
298 /* remove windows files*/
299 if ((rb
->strcmp(entry
->d_name
, "Thumbs.db") == 0))
301 *removed
+= 1; /* increment removed files counter */
303 /* get absolute path */
304 char fullname
[MAX_PATH
];
305 tidy_get_absolute_path(entry
, fullname
, name
);
308 rb
->remove(fullname
);
320 return TIDY_RETURN_ERROR
;
324 enum plugin_status
tidy_do(enum tidy_system system
)
326 /* clean disk and display num of items removed */
328 enum tidy_return status
;
329 char text
[24]; /* "Cleaned up nnnnn items" */
331 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
335 status
= tidy_clean("/", &removed
, system
);
337 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
338 rb
->cpu_boost(false);
341 if ((status
== TIDY_RETURN_OK
) || (status
== TIDY_RETURN_ABORT
))
343 rb
->lcd_clear_display();
344 rb
->snprintf(text
, 24, "Cleaned up %d items", removed
);
345 if (status
== TIDY_RETURN_ABORT
)
347 rb
->splash(HZ
, "User aborted");
348 rb
->lcd_clear_display();
350 rb
->splash(HZ
*2, text
);
355 int tidy_lcd_menu(void)
357 int selection
, ret
= 2;
358 bool menu_quit
= false;
360 MENUITEM_STRINGLIST(menu
,"Disktidy Menu",NULL
,"Start Cleaning",
361 "Files to Clean","Quit");
363 static const struct opt_items system_option
[3] =
372 switch(rb
->do_menu(&menu
, &selection
, NULL
, false))
376 menu_quit
= true; /* start cleaning */
380 rb
->set_option("Files to Clean", &ret
, INT
, system_option
, 3, NULL
);
384 ret
= 99; /* exit plugin */
392 /* this is the plugin entry point */
393 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
395 enum tidy_system system
= TIDY_BOTH
;
396 enum tidy_return status
;
402 switch(tidy_lcd_menu())
421 status
= tidy_do(system
);
427 case TIDY_RETURN_ERROR
:
429 case TIDY_RETURN_USB
:
430 return PLUGIN_USB_CONNECTED
;
431 case TIDY_RETURN_ABORT
:
436 if (rb
->default_event_handler(rb
->button_get(false)) == SYS_USB_CONNECTED
)
437 return PLUGIN_USB_CONNECTED
;