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
83 #error No keymap defined!
87 void tidy_lcd_status(const char *name
, int *removed
)
89 char text
[24]; /* "Cleaned up nnnnn items" */
91 /* display status text */
92 rb
->lcd_clear_display();
93 rb
->lcd_puts(0, 0, "Working ...");
94 rb
->lcd_puts(0, 1, name
);
95 rb
->snprintf(text
, 24, "Cleaned up %d items", *removed
);
96 #ifdef HAVE_LCD_BITMAP
97 rb
->lcd_puts(0, 2, text
);
102 void tidy_get_absolute_path(struct dirent
*entry
, char *fullname
,
105 /* gets absolute path using dirent and name */
106 rb
->strcpy(fullname
, name
);
107 if (rb
->strlen(name
) > 1)
109 rb
->strcat(fullname
, "/");
111 rb
->strcat(fullname
, entry
->d_name
);
114 enum tidy_return
tidy_removedir(const char *name
, int *removed
)
116 /* delete directory */
117 struct dirent
*entry
;
118 enum tidy_return status
= TIDY_RETURN_OK
;
121 char fullname
[MAX_PATH
];
123 /* display status text */
124 tidy_lcd_status(name
, removed
);
128 dir
= rb
->opendir(name
);
131 while((status
== TIDY_RETURN_OK
) && ((entry
= rb
->readdir(dir
)) != 0))
134 /* check for user input and usb connect */
135 button
= rb
->button_get(false);
136 if (button
== TIDY_STOP
)
139 return TIDY_RETURN_ABORT
;
141 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
144 return TIDY_RETURN_USB
;
149 /* get absolute path */
150 tidy_get_absolute_path(entry
, fullname
, name
);
152 if (entry
->attribute
& ATTR_DIRECTORY
)
154 /* dir ignore "." and ".." */
155 if ((rb
->strcmp(entry
->d_name
, ".") != 0) && \
156 (rb
->strcmp(entry
->d_name
, "..") != 0))
158 tidy_removedir(fullname
, removed
);
165 rb
->remove(fullname
);
175 status
= TIDY_RETURN_ERROR
;
180 enum tidy_return
tidy_clean(const char *name
, int *removed
, \
181 enum tidy_system system
)
183 /* deletes junk files and dirs left by system */
184 struct dirent
*entry
;
185 enum tidy_return status
= TIDY_RETURN_OK
;
187 int del
; /* has the item been deleted */
189 char fullname
[MAX_PATH
];
191 /* display status text */
192 tidy_lcd_status(name
, removed
);
196 dir
= rb
->opendir(name
);
199 while((status
== TIDY_RETURN_OK
) && ((entry
= rb
->readdir(dir
)) != 0))
202 /* check for user input and usb connect */
203 button
= rb
->button_get(false);
204 if (button
== TIDY_STOP
)
207 return TIDY_RETURN_ABORT
;
209 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
212 return TIDY_RETURN_USB
;
217 if (entry
->attribute
& ATTR_DIRECTORY
)
219 /* directory ignore "." and ".." */
220 if ((rb
->strcmp(entry
->d_name
, ".") != 0) && \
221 (rb
->strcmp(entry
->d_name
, "..") != 0))
225 /* get absolute path */
226 tidy_get_absolute_path(entry
, fullname
, name
);
228 /* check if we are in root directory "/" */
229 if (rb
->strcmp(name
, "/") == 0)
231 if ((system
== TIDY_MAC
) || (system
== TIDY_BOTH
))
233 /* mac directories */
234 if (rb
->strcmp(entry
->d_name
, ".Trashes") == 0)
237 tidy_removedir(fullname
, removed
);
244 if ((system
== TIDY_WIN
) || (system
== TIDY_BOTH
))
246 /* windows directories */
247 if (rb
->strcmp(entry
->d_name
, "Recycled") == 0 \
248 || rb
->strcmp(entry
->d_name
, "System Volume Information") == 0)
251 tidy_removedir(fullname
, removed
);
260 /* dir not deleted so clean it */
261 status
= tidy_clean(fullname
, removed
, system
);
270 if ((system
== TIDY_MAC
) || (system
== TIDY_BOTH
))
272 /* remove mac files */
273 if ((rb
->strcmp(entry
->d_name
, ".DS_Store") == 0) || \
274 (rb
->strncmp(entry
->d_name
, "._", 2) == 0))
276 *removed
+= 1; /* increment removed files counter */
278 /* get absolute path */
279 char fullname
[MAX_PATH
];
280 tidy_get_absolute_path(entry
, fullname
, name
);
283 rb
->remove(fullname
);
290 if ((system
== TIDY_WIN
) || (system
== TIDY_BOTH
))
292 /* remove windows files*/
293 if ((rb
->strcmp(entry
->d_name
, "Thumbs.db") == 0))
295 *removed
+= 1; /* increment removed files counter */
297 /* get absolute path */
298 char fullname
[MAX_PATH
];
299 tidy_get_absolute_path(entry
, fullname
, name
);
302 rb
->remove(fullname
);
314 return TIDY_RETURN_ERROR
;
318 enum plugin_status
tidy_do(enum tidy_system system
)
320 /* clean disk and display num of items removed */
322 enum tidy_return status
;
323 char text
[24]; /* "Cleaned up nnnnn items" */
325 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
329 status
= tidy_clean("/", &removed
, system
);
331 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
332 rb
->cpu_boost(false);
335 if ((status
== TIDY_RETURN_OK
) || (status
== TIDY_RETURN_ABORT
))
337 rb
->lcd_clear_display();
338 rb
->snprintf(text
, 24, "Cleaned up %d items", removed
);
339 if (status
== TIDY_RETURN_ABORT
)
341 rb
->splash(HZ
, "User aborted");
342 rb
->lcd_clear_display();
344 rb
->splash(HZ
*2, text
);
349 int tidy_lcd_menu(void)
351 int selection
, ret
= 2;
352 bool menu_quit
= false;
354 MENUITEM_STRINGLIST(menu
,"Disktidy Menu",NULL
,"Start Cleaning",
355 "Files to Clean","Quit");
357 static const struct opt_items system_option
[3] =
366 switch(rb
->do_menu(&menu
, &selection
))
370 menu_quit
= true; /* start cleaning */
374 rb
->set_option("Files to Clean", &ret
, INT
, system_option
, 3, NULL
);
378 ret
= 99; /* exit plugin */
386 /* this is the plugin entry point */
387 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
389 enum tidy_system system
= TIDY_BOTH
;
390 enum tidy_return status
;
396 switch(tidy_lcd_menu())
415 status
= tidy_do(system
);
421 case TIDY_RETURN_ERROR
:
423 case TIDY_RETURN_USB
:
424 return PLUGIN_USB_CONNECTED
;
425 case TIDY_RETURN_ABORT
:
430 if (rb
->default_event_handler(rb
->button_get(false)) == SYS_USB_CONNECTED
)
431 return PLUGIN_USB_CONNECTED
;