summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/disktidy.c428
-rw-r--r--apps/plugins/disktidy.config19
2 files changed, 266 insertions, 181 deletions
diff --git a/apps/plugins/disktidy.c b/apps/plugins/disktidy.c
index ed29206d6b..bb4c45e977 100644
--- a/apps/plugins/disktidy.c
+++ b/apps/plugins/disktidy.c
@@ -20,6 +20,7 @@
20 20
21PLUGIN_HEADER 21PLUGIN_HEADER
22static const struct plugin_api* rb; 22static const struct plugin_api* rb;
23MEM_FUNCTION_WRAPPERS(rb)
23 24
24/* function return values */ 25/* function return values */
25enum tidy_return 26enum tidy_return
@@ -30,66 +31,131 @@ enum tidy_return
30 TIDY_RETURN_ABORT = 3, 31 TIDY_RETURN_ABORT = 3,
31}; 32};
32 33
33/* Which systems junk are we removing */ 34#define MAX_TYPES 64
34enum tidy_system 35struct tidy_type {
36 char filestring[64];
37 bool directory;
38 bool remove;
39} tidy_types[MAX_TYPES];
40int tidy_type_count;
41bool tidy_loaded_and_changed = false;
42
43#define DEFAULT_FILES PLUGIN_APPS_DIR "/disktidy.config"
44#define CUSTOM_FILES PLUGIN_APPS_DIR "/disktidy_custom.config"
45void add_item(const char* name, int index)
35{ 46{
36 TIDY_MAC = 0, 47 rb->strcpy(tidy_types[index].filestring, name);
37 TIDY_WIN = 1, 48 if (name[rb->strlen(name)-1] == '/')
38 TIDY_NIX = 2, 49 {
39 TIDY_ALL = 3, 50 tidy_types[index].directory = true;
40}; 51 tidy_types[index].filestring[rb->strlen(name)-1] = '\0';
41 52 }
42/* variable button definitions */ 53 else
43#if CONFIG_KEYPAD == PLAYER_PAD 54 tidy_types[index].directory = false;
44#define TIDY_STOP BUTTON_STOP 55}
45 56static int find_file_string(const char *file, char *last_group)
46#elif CONFIG_KEYPAD == RECORDER_PAD 57{
47#define TIDY_STOP BUTTON_OFF 58 char temp[MAX_PATH];
48 59 int i = 0, idx_last_group = -1;
49#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD 60 bool folder = false;
50#define TIDY_STOP BUTTON_OFF 61 rb->strcpy(temp, file);
51 62 if (temp[rb->strlen(temp)-1] == '/')
52#elif CONFIG_KEYPAD == ONDIO_PAD 63 {
53#define TIDY_STOP BUTTON_OFF 64 folder = true;
54 65 temp[rb->strlen(temp)-1] = '\0';
55#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ 66 }
56 (CONFIG_KEYPAD == IRIVER_H300_PAD) 67 while (i<tidy_type_count)
57#define TIDY_STOP BUTTON_OFF 68 {
58 69 if (!rb->strcmp(tidy_types[i].filestring, temp) &&
59#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \ 70 folder == tidy_types[i].directory)
60 (CONFIG_KEYPAD == IPOD_3G_PAD) || \ 71 return i;
61 (CONFIG_KEYPAD == IPOD_1G2G_PAD) 72 else if (!rb->strcmp(tidy_types[i].filestring, last_group))
62#define TIDY_STOP BUTTON_MENU 73 idx_last_group = i;
63 74 i++;
64#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD 75 }
65#define TIDY_STOP BUTTON_POWER 76 /* not found, so insert it into its group */
66 77 if (file[0] != '<' && idx_last_group != -1)
67#elif CONFIG_KEYPAD == GIGABEAT_PAD 78 {
68#define TIDY_STOP BUTTON_POWER 79 for (i=idx_last_group; i<tidy_type_count; i++)
69 80 {
70#elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \ 81 if (tidy_types[i].filestring[0] == '<')
71(CONFIG_KEYPAD == SANSA_C200_PAD) 82 {
72#define TIDY_STOP BUTTON_POWER 83 idx_last_group = i;
73 84 break;
74#elif CONFIG_KEYPAD == IRIVER_H10_PAD 85 }
75#define TIDY_STOP BUTTON_POWER 86 }
76 87 /* shift items up one */
77#elif CONFIG_KEYPAD == GIGABEAT_S_PAD 88 for (i=tidy_type_count;i>idx_last_group;i--)
78#define TIDY_STOP BUTTON_BACK 89 {
79 90 rb->strcpy(tidy_types[i].filestring, tidy_types[i-1].filestring);
80#elif CONFIG_KEYPAD == MROBE100_PAD 91 tidy_types[i].directory = tidy_types[i-1].directory;
81#define TIDY_STOP BUTTON_POWER 92 tidy_types[i].remove = tidy_types[i-1].remove;
82 93 }
83#elif CONFIG_KEYPAD == IAUDIO_M3_PAD 94 tidy_type_count++;
84#define TIDY_STOP BUTTON_RC_REC 95 add_item(file, idx_last_group+1);
85 96 return idx_last_group+1;
86#elif CONFIG_KEYPAD == COWOND2_PAD 97 }
87#define TIDY_STOP BUTTON_POWER 98 return i;
99}
88 100
89#else 101bool tidy_load_file(const char* file)
90#error No keymap defined! 102{
91#endif 103 int fd = rb->open(file, O_RDONLY), i;
104 char buf[MAX_PATH], *str, *remove;
105 char last_group[MAX_PATH] = "";
106 bool new;
107 if (fd < 0)
108 return false;
109 while ((tidy_type_count < MAX_TYPES) &&
110 rb->read_line(fd, buf, MAX_PATH))
111 {
112 if (rb->settings_parseline(buf, &str, &remove))
113 {
114 i = find_file_string(str, last_group);
115 new = (i >= tidy_type_count);
116 if (!rb->strcmp(remove, "yes"))
117 tidy_types[i].remove = true;
118 else tidy_types[i].remove = false;
119 if (new)
120 {
121 i = tidy_type_count;
122 add_item(str, i);
123 tidy_type_count++;
124 }
125 if (str[0] == '<')
126 rb->strcpy(last_group, str);
127 }
128 }
129 rb->close(fd);
130 return true;
131}
92 132
133bool tidy_remove_item(char *item, int attr)
134{
135 int i;
136 char *file;
137 bool ret = false, rem = false;
138 for (i=0; ret == false && i < tidy_type_count; i++)
139 {
140 file = tidy_types[i].filestring;
141 if (file[rb->strlen(file)-1] == '*')
142 {
143 if (!rb->strncmp(file, item, rb->strlen(file)-1))
144 rem = true;
145 }
146 else if (!rb->strcmp(file, item))
147 rem = true;
148 if (rem)
149 {
150 if (!tidy_types[i].remove)
151 return false;
152 if (attr&ATTR_DIRECTORY)
153 ret = tidy_types[i].directory;
154 else ret = true;
155 }
156 }
157 return ret;
158}
93 159
94void tidy_lcd_status(const char *name, int *removed) 160void tidy_lcd_status(const char *name, int *removed)
95{ 161{
@@ -139,8 +205,8 @@ enum tidy_return tidy_removedir(const char *name, int *removed)
139 /* walk directory */ 205 /* walk directory */
140 { 206 {
141 /* check for user input and usb connect */ 207 /* check for user input and usb connect */
142 button = rb->button_get(false); 208 button = rb->get_action(CONTEXT_STD, TIMEOUT_NOBLOCK);
143 if (button == TIDY_STOP) 209 if (button == ACTION_STD_CANCEL)
144 { 210 {
145 rb->closedir(dir); 211 rb->closedir(dir);
146 return TIDY_RETURN_ABORT; 212 return TIDY_RETURN_ABORT;
@@ -184,8 +250,7 @@ enum tidy_return tidy_removedir(const char *name, int *removed)
184 return status; 250 return status;
185} 251}
186 252
187enum tidy_return tidy_clean(const char *name, int *removed, \ 253enum tidy_return tidy_clean(const char *name, int *removed)
188 enum tidy_system system)
189{ 254{
190 /* deletes junk files and dirs left by system */ 255 /* deletes junk files and dirs left by system */
191 struct dirent *entry; 256 struct dirent *entry;
@@ -207,8 +272,8 @@ enum tidy_return tidy_clean(const char *name, int *removed, \
207 /* walk directory */ 272 /* walk directory */
208 { 273 {
209 /* check for user input and usb connect */ 274 /* check for user input and usb connect */
210 button = rb->button_get(false); 275 button = rb->get_action(CONTEXT_STD, TIMEOUT_NOBLOCK);
211 if (button == TIDY_STOP) 276 if (button == ACTION_STD_CANCEL)
212 { 277 {
213 rb->closedir(dir); 278 rb->closedir(dir);
214 return TIDY_RETURN_ABORT; 279 return TIDY_RETURN_ABORT;
@@ -232,40 +297,17 @@ enum tidy_return tidy_clean(const char *name, int *removed, \
232 /* get absolute path */ 297 /* get absolute path */
233 tidy_get_absolute_path(entry, fullname, name); 298 tidy_get_absolute_path(entry, fullname, name);
234 299
235 /* check if we are in root directory "/" */ 300 if (tidy_remove_item(entry->d_name, entry->attribute))
236 if (rb->strcmp(name, "/") == 0)
237 { 301 {
238 if ((system == TIDY_MAC) || (system == TIDY_ALL)) 302 /* delete dir */
239 { 303 tidy_removedir(fullname, removed);
240 /* mac directories */ 304 del = 1;
241 if (rb->strcmp(entry->d_name, ".Trashes") == 0)
242 {
243 /* delete dir */
244 tidy_removedir(fullname, removed);
245 del = 1;
246 }
247 }
248
249 if (del == 0)
250 {
251 if ((system == TIDY_WIN) || (system == TIDY_ALL))
252 {
253 /* windows directories */
254 if (rb->strcmp(entry->d_name, "Recycled") == 0 \
255 || rb->strcmp(entry->d_name, "System Volume Information") == 0)
256 {
257 /* delete dir */
258 tidy_removedir(fullname, removed);
259 del = 1;
260 }
261 }
262 }
263 } 305 }
264 306
265 if (del == 0) 307 if (del == 0)
266 { 308 {
267 /* dir not deleted so clean it */ 309 /* dir not deleted so clean it */
268 status = tidy_clean(fullname, removed, system); 310 status = tidy_clean(fullname, removed);
269 } 311 }
270 } 312 }
271 } 313 }
@@ -273,63 +315,17 @@ enum tidy_return tidy_clean(const char *name, int *removed, \
273 { 315 {
274 /* file */ 316 /* file */
275 del = 0; 317 del = 0;
276 318 if (tidy_remove_item(entry->d_name, entry->attribute))
277 if ((system == TIDY_MAC) || (system == TIDY_ALL))
278 {
279 /* remove mac files */
280 if ((rb->strcmp(entry->d_name, ".DS_Store") == 0) || \
281 (rb->strncmp(entry->d_name, "._", 2) == 0))
282 {
283 *removed += 1; /* increment removed files counter */
284
285 /* get absolute path */
286 char fullname[MAX_PATH];
287 tidy_get_absolute_path(entry, fullname, name);
288
289 /* delete file */
290 rb->remove(fullname);
291 del = 1;
292 }
293 }
294
295 if (del == 0)
296 { 319 {
297 if ((system == TIDY_WIN) || (system == TIDY_ALL)) 320 *removed += 1; /* increment removed files counter */
298 { 321
299 /* remove windows files*/ 322 /* get absolute path */
300 if ((rb->strcmp(entry->d_name, "Thumbs.db") == 0)) 323 char fullname[MAX_PATH];
301 { 324 tidy_get_absolute_path(entry, fullname, name);
302 *removed += 1; /* increment removed files counter */ 325
303 326 /* delete file */
304 /* get absolute path */ 327 rb->remove(fullname);
305 char fullname[MAX_PATH]; 328 del = 1;
306 tidy_get_absolute_path(entry, fullname, name);
307
308 /* delete file */
309 rb->remove(fullname);
310 del = 1;
311 }
312 }
313 }
314 if (del == 0)
315 {
316 if ((system ==TIDY_NIX) || (system == TIDY_ALL))
317 {
318 /* remove linux files*/
319 if ((rb->strcmp(entry->d_name, ".dolphinview") == 0) || \
320 (rb->strncmp(entry->d_name, ".d3lphinview", 2) == 0))
321 {
322 *removed += 1; /* increment removed files counter */
323
324 /* get absolute path */
325 char fullname[MAX_PATH];
326 tidy_get_absolute_path(entry, fullname, name);
327
328 /* delete file */
329 rb->remove(fullname);
330 del = 1;
331 }
332 }
333 } 329 }
334 } 330 }
335 } 331 }
@@ -342,7 +338,7 @@ enum tidy_return tidy_clean(const char *name, int *removed, \
342 } 338 }
343} 339}
344 340
345enum plugin_status tidy_do(enum tidy_system system) 341enum plugin_status tidy_do(void)
346{ 342{
347 /* clean disk and display num of items removed */ 343 /* clean disk and display num of items removed */
348 int removed = 0; 344 int removed = 0;
@@ -353,7 +349,7 @@ enum plugin_status tidy_do(enum tidy_system system)
353 rb->cpu_boost(true); 349 rb->cpu_boost(true);
354#endif 350#endif
355 351
356 status = tidy_clean("/", &removed, system); 352 status = tidy_clean("/", &removed);
357 353
358#ifdef HAVE_ADJUSTABLE_CPU_FREQ 354#ifdef HAVE_ADJUSTABLE_CPU_FREQ
359 rb->cpu_boost(false); 355 rb->cpu_boost(false);
@@ -373,6 +369,73 @@ enum plugin_status tidy_do(enum tidy_system system)
373 return status; 369 return status;
374} 370}
375 371
372enum themable_icons get_icon(int item, void * data)
373{
374 (void)data;
375 if (tidy_types[item].filestring[0] == '<') /* special type */
376 return Icon_Folder;
377 else if (tidy_types[item].remove)
378 return Icon_Cursor;
379 else
380 return Icon_NOICON;
381}
382
383char * get_name(int selected_item, void * data,
384 char * buffer, size_t buffer_len)
385{
386 (void)data;
387 if (tidy_types[selected_item].directory)
388 {
389 rb->snprintf(buffer, buffer_len, "%s/",
390 tidy_types[selected_item].filestring);
391 return buffer;
392 }
393 return tidy_types[selected_item].filestring;
394}
395
396int list_action_callback(int action, struct gui_synclist *lists)
397{
398 if (action == ACTION_STD_OK)
399 {
400 int selection = rb->gui_synclist_get_sel_pos(lists);
401 if (tidy_types[selection].filestring[0] == '<')
402 {
403 int i;
404 if (!rb->strcmp(tidy_types[selection].filestring, "< ALL >"))
405 {
406 for (i=0; i<tidy_type_count; i++)
407 {
408 if (tidy_types[i].filestring[0] != '<')
409 tidy_types[i].remove = true;
410 }
411 }
412 else if (!rb->strcmp(tidy_types[selection].filestring, "< NONE >"))
413 {
414 for (i=0; i<tidy_type_count; i++)
415 {
416 if (tidy_types[i].filestring[0] != '<')
417 tidy_types[i].remove = false;
418 }
419 }
420 else /* toggle all untill the next <> */
421 {
422 selection++;
423 while (selection < tidy_type_count &&
424 tidy_types[selection].filestring[0] != '<')
425 {
426 tidy_types[selection].remove = !tidy_types[selection].remove;
427 selection++;
428 }
429 }
430 }
431 else
432 tidy_types[selection].remove = !tidy_types[selection].remove;
433 tidy_loaded_and_changed = true;
434 return ACTION_REDRAW;
435 }
436 return action;
437}
438
376int tidy_lcd_menu(void) 439int tidy_lcd_menu(void)
377{ 440{
378 int selection, ret = 3; 441 int selection, ret = 3;
@@ -381,14 +444,6 @@ int tidy_lcd_menu(void)
381 MENUITEM_STRINGLIST(menu,"Disktidy Menu",NULL,"Start Cleaning", 444 MENUITEM_STRINGLIST(menu,"Disktidy Menu",NULL,"Start Cleaning",
382 "Files to Clean","Quit"); 445 "Files to Clean","Quit");
383 446
384 static const struct opt_items system_option[] =
385 {
386 { "Mac", -1 },
387 { "Windows", -1 },
388 { "Linux", -1 },
389 { "All", -1 }
390 };
391
392 while (!menu_quit) 447 while (!menu_quit)
393 { 448 {
394 switch(rb->do_menu(&menu, &selection, NULL, false)) 449 switch(rb->do_menu(&menu, &selection, NULL, false))
@@ -399,8 +454,15 @@ int tidy_lcd_menu(void)
399 break; 454 break;
400 455
401 case 1: 456 case 1:
402 rb->set_option("Files to Clean", &ret, INT, system_option, 4, NULL); 457 {
403 break; 458 struct simplelist_info list;
459 rb->simplelist_info_init(&list, "Files to Clean", tidy_type_count, NULL);
460 list.get_icon = get_icon;
461 list.get_name = get_name;
462 list.action_callback = list_action_callback;
463 rb->simplelist_show_list(&list);
464 }
465 break;
404 466
405 default: 467 default:
406 ret = 99; /* exit plugin */ 468 ret = 99; /* exit plugin */
@@ -414,36 +476,40 @@ int tidy_lcd_menu(void)
414/* this is the plugin entry point */ 476/* this is the plugin entry point */
415enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter) 477enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
416{ 478{
417 enum tidy_system system = TIDY_ALL;
418 enum tidy_return status; 479 enum tidy_return status;
419 480 int ret;
420 (void)parameter; 481 (void)parameter;
421 482
422 rb = api; 483 rb = api;
423 484 tidy_type_count = 0;
424 switch(tidy_lcd_menu()) 485 tidy_load_file(DEFAULT_FILES);
486 tidy_load_file(CUSTOM_FILES);
487 if (tidy_type_count == 0)
425 { 488 {
426 case 0: 489 rb->splash(3*HZ, "Missing disktidy.config file");
427 system = TIDY_MAC; 490 return PLUGIN_ERROR;
428 break;
429 case 1:
430 system = TIDY_WIN;
431 break;
432 case 2:
433 system = TIDY_NIX;
434 break;
435 case 3:
436 system = TIDY_ALL;
437 break;
438 case 99:
439 return PLUGIN_OK;
440 default:
441 system = TIDY_ALL;
442 } 491 }
443 492 ret = tidy_lcd_menu();
493 if (tidy_loaded_and_changed)
494 {
495 int fd = rb->creat(CUSTOM_FILES);
496 int i;
497 if (fd >= 0)
498 {
499 for(i=0;i<tidy_type_count;i++)
500 {
501 rb->fdprintf(fd, "%s%c: %s\n", tidy_types[i].filestring,
502 tidy_types[i].directory?'/':'\0',
503 tidy_types[i].remove?"yes":"no");
504 }
505 rb->close(fd);
506 }
507 }
508 if (ret == 99)
509 return PLUGIN_OK;
444 while (true) 510 while (true)
445 { 511 {
446 status = tidy_do(system); 512 status = tidy_do();
447 513
448 switch (status) 514 switch (status)
449 { 515 {
diff --git a/apps/plugins/disktidy.config b/apps/plugins/disktidy.config
new file mode 100644
index 0000000000..0c062e700f
--- /dev/null
+++ b/apps/plugins/disktidy.config
@@ -0,0 +1,19 @@
1# Disktidy config
2# When adding a new file, make sure its NOT enabled
3< ALL >: no
4< NONE >: no
5< Windows >: no
6 desktop.ini: no
7 Thumbs.db: no
8 Recycled/: no
9 $RECYCLE.BIN/: no
10 System Volume Information/: no
11< Mac OSX >: no
12 .Trashes/: no
13 .DS_Store: no
14 ._*: no
15< Linux/BSD >: no
16 .Trash-*/: no
17 .dolphinview: no
18 .d3lphinview: no
19< Other >: no