Index: apps/plugins/viewers.config =================================================================== --- apps/plugins/viewers.config (revision 17437) +++ apps/plugins/viewers.config (working copy) @@ -36,8 +36,8 @@ sna,viewers/zxbox,12 tzx,viewers/zxbox,12 z80,viewers/zxbox,12 -*,viewers/properties,- colours,apps/text_editor,11 ssg,games/superdom,- link,viewers/shortcuts_view,- *,viewers/shortcuts_append,- +*,viewers/properties,- Index: apps/plugins/disktidy.c =================================================================== --- apps/plugins/disktidy.c (revision 17437) +++ apps/plugins/disktidy.c (working copy) @@ -39,6 +39,7 @@ TIDY_ALL = 3, }; + /* variable button definitions */ #if CONFIG_KEYPAD == PLAYER_PAD #define TIDY_STOP BUTTON_STOP @@ -90,7 +91,86 @@ #error No keymap defined! #endif +#define MAX_TYPES 32 +struct tidy_type { + char filestring[64]; + bool directory; + bool remove; +} tidy_types[MAX_TYPES]; +int tidy_type_count; +bool tidy_loaded_and_changed = false; +/* in the config file, directories have a trailing / */ +static struct tidy_type tidy_type_defaults[] = { + {"< ALL >", false, false}, + {"< NONE >", false, false}, + {"< Windows >", false, false}, + {"Desktop.ini", false, true}, + {"Thumbs.db", false, true}, + {"Recycled", true, true}, + {"System Volume Information", true, true}, + {"< Mac OSX >", false, false}, + {".Trashes", true, true}, + {".DS_Store", false, true}, + {"._*", false, true}, + {"< Linux/BSD >", false, false}, + {".Trash-*", true, true}, + {".dolphinview", false, true}, + {".d3lphinview", false, true}, + {"< Other >", false, false}, +}; + +bool tidy_load_file(const char* file) +{ + int fd = rb->open(file, O_RDONLY); + char buf[MAX_PATH], *str, *remove; + if (fd < 0) + return false; + tidy_type_count = 0; + while ((tidy_type_count < MAX_TYPES) && + rb->read_line(fd, buf, MAX_PATH)) + { + if (rb->settings_parseline(buf, &str, &remove)) + { + rb->strcpy(tidy_types[tidy_type_count].filestring, str); + if (!rb->strcmp(remove, "yes")) + tidy_types[tidy_type_count].remove = true; + else tidy_types[tidy_type_count].remove = false; + if (str[rb->strlen(str)-1] == '/') + { + tidy_types[tidy_type_count].directory = true; + tidy_types[tidy_type_count].filestring[rb->strlen(str)-1] = '\0'; + } + else + tidy_types[tidy_type_count].directory = false; + tidy_type_count++; + } + } + rb->close(fd); + return true; +} + +bool tidy_remove_item(char *item, int attr) +{ + int i; + char *file; + bool ret = false; + for (i=0; ret == false && i < tidy_type_count; i++) + { + file = tidy_types[i].filestring; + if ( ( (file[rb->strlen(file)-1] == '*') && + (!rb->strncmp(file, item, rb->strlen(file)-1)) ) || + ( (file[rb->strlen(file)-1] != '*') && + (!rb->strcmp(file, item)) ) ) + { + if (attr&ATTR_DIRECTORY) + ret = tidy_types[i].directory; + else ret = true; + } + } + return ret; +} + void tidy_lcd_status(const char *name, int *removed) { char text[24]; /* "Cleaned up nnnnn items" */ @@ -232,34 +312,11 @@ /* get absolute path */ tidy_get_absolute_path(entry, fullname, name); - /* check if we are in root directory "/" */ - if (rb->strcmp(name, "/") == 0) + if (tidy_remove_item(entry->d_name, entry->attribute)) { - if ((system == TIDY_MAC) || (system == TIDY_ALL)) - { - /* mac directories */ - if (rb->strcmp(entry->d_name, ".Trashes") == 0) - { - /* delete dir */ - tidy_removedir(fullname, removed); - del = 1; - } - } - - if (del == 0) - { - if ((system == TIDY_WIN) || (system == TIDY_ALL)) - { - /* windows directories */ - if (rb->strcmp(entry->d_name, "Recycled") == 0 \ - || rb->strcmp(entry->d_name, "System Volume Information") == 0) - { - /* delete dir */ - tidy_removedir(fullname, removed); - del = 1; - } - } - } + /* delete dir */ + tidy_removedir(fullname, removed); + del = 1; } if (del == 0) @@ -273,64 +330,18 @@ { /* file */ del = 0; - - if ((system == TIDY_MAC) || (system == TIDY_ALL)) + if (tidy_remove_item(entry->d_name, entry->attribute)) { - /* remove mac files */ - if ((rb->strcmp(entry->d_name, ".DS_Store") == 0) || \ - (rb->strncmp(entry->d_name, "._", 2) == 0)) - { - *removed += 1; /* increment removed files counter */ - - /* get absolute path */ - char fullname[MAX_PATH]; - tidy_get_absolute_path(entry, fullname, name); - - /* delete file */ - rb->remove(fullname); - del = 1; - } + *removed += 1; /* increment removed files counter */ + + /* get absolute path */ + char fullname[MAX_PATH]; + tidy_get_absolute_path(entry, fullname, name); + + /* delete file */ + rb->remove(fullname); + del = 1; } - - if (del == 0) - { - if ((system == TIDY_WIN) || (system == TIDY_ALL)) - { - /* remove windows files*/ - if ((rb->strcmp(entry->d_name, "Thumbs.db") == 0)) - { - *removed += 1; /* increment removed files counter */ - - /* get absolute path */ - char fullname[MAX_PATH]; - tidy_get_absolute_path(entry, fullname, name); - - /* delete file */ - rb->remove(fullname); - del = 1; - } - } - } - if (del == 0) - { - if ((system ==TIDY_NIX) || (system == TIDY_ALL)) - { - /* remove linux files*/ - if ((rb->strcmp(entry->d_name, ".dolphinview") == 0) || \ - (rb->strncmp(entry->d_name, ".d3lphinview", 2) == 0)) - { - *removed += 1; /* increment removed files counter */ - - /* get absolute path */ - char fullname[MAX_PATH]; - tidy_get_absolute_path(entry, fullname, name); - - /* delete file */ - rb->remove(fullname); - del = 1; - } - } - } } } rb->closedir(dir); @@ -373,6 +384,67 @@ return status; } +enum themable_icons get_icon(int item, void * data) +{ + (void)data; + if (tidy_types[item].filestring[0] == '<') /* special type */ + return Icon_Folder; + else if (tidy_types[item].remove) + return Icon_Cursor; + else + return Icon_NOICON; +} + +char * get_name(int selected_item, void * data, + char * buffer, size_t buffer_len) +{ + (void)data; (void)buffer; (void)buffer_len; + return tidy_types[selected_item].filestring; +} + +int list_action_callback(int action, struct gui_synclist *lists) +{ + if (action == ACTION_STD_OK) + { + int selection = rb->gui_synclist_get_sel_pos(lists); + if (tidy_types[selection].filestring[0] == '<') + { + int i; + if (!rb->strcmp(tidy_types[selection].filestring, "< ALL >")) + { + for (i=0; istrcmp(tidy_types[selection].filestring, "< NONE >")) + { + for (i=0; i */ + { + selection++; + while (selection < tidy_type_count && + tidy_types[selection].filestring[0] != '<') + { + tidy_types[selection].remove = !tidy_types[selection].remove; + selection++; + } + } + } + else + tidy_types[selection].remove = !tidy_types[selection].remove; + tidy_loaded_and_changed = true; + return ACTION_REDRAW; + } + return action; +} + int tidy_lcd_menu(void) { int selection, ret = 3; @@ -381,27 +453,23 @@ MENUITEM_STRINGLIST(menu,"Disktidy Menu",NULL,"Start Cleaning", "Files to Clean","Quit"); - static const struct opt_items system_option[] = - { - { "Mac", -1 }, - { "Windows", -1 }, - { "Linux", -1 }, - { "All", -1 } - }; - while (!menu_quit) { switch(rb->do_menu(&menu, &selection, NULL, false)) { - case 0: menu_quit = true; /* start cleaning */ break; - case 1: - rb->set_option("Files to Clean", &ret, INT, system_option, 4, NULL); - break; - + { + struct simplelist_info list; + rb->simplelist_info_init(&list, "Files to Clean", tidy_type_count, NULL); + list.get_icon = get_icon; + list.get_name = get_name; + list.action_callback = list_action_callback; + rb->simplelist_show_list(&list); + } + break; default: ret = 99; /* exit plugin */ menu_quit = true; @@ -416,53 +484,39 @@ { enum tidy_system system = TIDY_ALL; enum tidy_return status; - + int ret; (void)parameter; + unsigned int i = 0; rb = api; - - switch(tidy_lcd_menu()) + + for(i=0;istrcpy(tidy_types[i].filestring, + tidy_type_defaults[i].filestring); + tidy_types[i].directory = tidy_type_defaults[i].directory; + tidy_types[i].remove = tidy_type_defaults[i].remove; } - + + ret = tidy_lcd_menu(); + + if (ret == 99) + return PLUGIN_OK; while (true) { - status = tidy_do(system); + status = tidy_do(system); - switch (status) - { - case TIDY_RETURN_OK: - return PLUGIN_OK; - case TIDY_RETURN_ERROR: - return PLUGIN_ERROR; - case TIDY_RETURN_USB: - return PLUGIN_USB_CONNECTED; - case TIDY_RETURN_ABORT: - return PLUGIN_OK; - } + switch (status) + { + case TIDY_RETURN_OK: + return PLUGIN_OK; + case TIDY_RETURN_ERROR: + return PLUGIN_ERROR; + case TIDY_RETURN_USB: + return PLUGIN_USB_CONNECTED; + case TIDY_RETURN_ABORT: + return PLUGIN_OK; + } } - - if (rb->default_event_handler(rb->button_get(false)) == SYS_USB_CONNECTED) - return PLUGIN_USB_CONNECTED; - - rb->yield(); - - return PLUGIN_OK; } Index: apps/plugin.c =================================================================== --- apps/plugin.c (revision 17437) +++ apps/plugin.c (working copy) @@ -598,6 +598,8 @@ buttonlight_set_brightness, #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */ #endif /* HAVE_BUTTON_LIGHT */ + simplelist_info_init, + simplelist_show_list, }; int plugin_load(const char* plugin, void* parameter) Index: apps/plugin.h =================================================================== --- apps/plugin.h (revision 17437) +++ apps/plugin.h (working copy) @@ -120,7 +120,7 @@ #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 111 +#define PLUGIN_API_VERSION 112 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any @@ -745,6 +745,9 @@ void (*buttonlight_set_brightness)(int val); #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */ #endif /* HAVE_BUTTON_LIGHT */ + void (*simplelist_info_init)(struct simplelist_info *info, char* title, + int count, void* data); + bool (*simplelist_show_list)(struct simplelist_info *info); }; /* plugin header */