diff options
Diffstat (limited to 'apps/plugins/open_plugins.c')
-rw-r--r-- | apps/plugins/open_plugins.c | 73 |
1 files changed, 44 insertions, 29 deletions
diff --git a/apps/plugins/open_plugins.c b/apps/plugins/open_plugins.c index 3a0c34d8d6..b608aff789 100644 --- a/apps/plugins/open_plugins.c +++ b/apps/plugins/open_plugins.c @@ -87,14 +87,23 @@ static size_t pathbasename(const char *name, const char **nameptr) *nameptr = q; return r - q; } +static int op_entry_checksum(void) +{ + if (op_entry.checksum != open_plugin_csum + + (op_entry.lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY)) + { + return 0; + } + return 1; +} static bool op_entry_read(int fd, int selected_item, off_t data_sz) { rb->memset(&op_entry, 0, op_entry_sz); op_entry.lang_id = -1; - return ((selected_item >= 0) && + return ((selected_item >= 0) && (fd >= 0) && (rb->lseek(fd, selected_item * op_entry_sz, SEEK_SET) >= 0) && - (rb->read(fd, &op_entry, data_sz) == data_sz)); + (rb->read(fd, &op_entry, data_sz) == data_sz) && op_entry_checksum() > 0); } static bool op_entry_read_name(int fd, int selected_item) @@ -102,15 +111,6 @@ static bool op_entry_read_name(int fd, int selected_item) return op_entry_read(fd, selected_item, op_name_sz); } -static int op_entry_checksum(void) -{ - if (op_entry.checksum != open_plugin_csum) - { - return 0; - } - return 1; -} - static int op_entry_read_opx(const char *path) { int ret = -1; @@ -174,7 +174,8 @@ failure: static void op_entry_set_checksum(void) { - op_entry.checksum = open_plugin_csum; + op_entry.checksum = open_plugin_csum + + (op_entry.lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY); } static void op_entry_set_name(void) @@ -188,17 +189,20 @@ static void op_entry_set_name(void) static int op_entry_set_path(void) { int ret = 0; - struct browse_context browse; char tmp_buf[OPEN_PLUGIN_BUFSZ+1]; if (op_entry.path[0] == '\0') rb->strcpy(op_entry.path, PLUGIN_DIR"/"); - rb->browse_context_init(&browse, SHOW_ALL, BROWSE_SELECTONLY, rb->str(LANG_ADD), - Icon_Plugin, op_entry.path, NULL); - - browse.buf = tmp_buf; - browse.bufsize = OPEN_PLUGIN_BUFSZ; + struct browse_context browse = { + .dirfilter = SHOW_ALL, + .flags = BROWSE_SELECTONLY | BROWSE_DIRFILTER, + .title = rb->str(LANG_ADD), + .icon = Icon_Plugin, + .root = op_entry.path, + .buf = tmp_buf, + .bufsize = sizeof(tmp_buf), + }; if (rb->rockbox_browse(&browse) == GO_TO_PREVIOUS) { @@ -212,7 +216,6 @@ static int op_entry_set_path(void) static int op_entry_set_param_path(void) { int ret = 0; - struct browse_context browse; char tmp_buf[OPEN_PLUGIN_BUFSZ+1]; if (op_entry.param[0] == '\0') @@ -220,11 +223,15 @@ static int op_entry_set_param_path(void) else rb->strcpy(tmp_buf, op_entry.param); - rb->browse_context_init(&browse, SHOW_ALL, BROWSE_SELECTONLY, "", - Icon_Plugin, tmp_buf, NULL); - - browse.buf = tmp_buf; - browse.bufsize = OPEN_PLUGIN_BUFSZ; + struct browse_context browse = { + .dirfilter = SHOW_ALL, + .flags = BROWSE_SELECTONLY | BROWSE_DIRFILTER, + .title = rb->str(LANG_PARAMETER), + .icon = Icon_Plugin, + .root = tmp_buf, + .buf = tmp_buf, + .bufsize = sizeof(tmp_buf), + }; if (rb->rockbox_browse(&browse) == GO_TO_PREVIOUS) { @@ -405,6 +412,7 @@ static uint32_t op_entry_add_path(const char *key, const char *plugin, const cha { rb->close(fd_tmp); rb->close(fd_dat); + fd_dat = -1; rb->remove(OPEN_PLUGIN_DAT); rb->rename(OPEN_PLUGIN_DAT ".tmp", OPEN_PLUGIN_DAT); } @@ -461,12 +469,12 @@ static void op_entry_remove(int selection) static void op_entry_remove_empty(void) { bool resave = false; - if (fd_dat && rb->lseek(fd_dat, 0, SEEK_SET) == 0) + if (fd_dat >= 0 && rb->lseek(fd_dat, 0, SEEK_SET) == 0) { while (resave == false && rb->read(fd_dat, &op_entry, op_entry_sz) == op_entry_sz) { - if (op_entry.hash == 0) + if (op_entry.hash == 0 || !op_entry_checksum()) resave = true; } } @@ -482,6 +490,7 @@ static void op_entry_remove_empty(void) { rb->close(fd_tmp); rb->close(fd_dat); + fd_dat = -1; rb->remove(OPEN_PLUGIN_DAT); rb->rename(OPEN_PLUGIN_DAT ".tmp", OPEN_PLUGIN_DAT); } @@ -623,7 +632,6 @@ static void synclist_set(char* menu_id, int selection, int items, int sel_size) rb->gui_synclist_set_icon_callback(&lists,NULL); rb->gui_synclist_set_voice_callback(&lists, list_voice_cb); rb->gui_synclist_set_nb_items(&lists,items); - rb->gui_synclist_limit_scroll(&lists,true); rb->gui_synclist_select_item(&lists, selection); list_voice_cb(selection, menu_id); } @@ -682,7 +690,7 @@ static void edit_menu(int selection) { action = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK); - if (rb->gui_synclist_do_button(&lists,&action,LIST_WRAP_UNLESS_HELD)) + if (rb->gui_synclist_do_button(&lists, &action)) continue; selected_item = rb->gui_synclist_get_sel_pos(&lists); switch (action) @@ -840,6 +848,12 @@ reopen_datfile: }/* OP_EXT */ } + for (int i = items - 1; i > 0 && !exit; i--) + { + if (!op_entry_read(fd_dat, i, op_entry_sz)) + items--; + } + if (items < 1 && !exit) { char* cur_filename = rb->plugin_get_current_filename(); @@ -865,7 +879,7 @@ reopen_datfile: { action = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK); - if (rb->gui_synclist_do_button(&lists,&action,LIST_WRAP_UNLESS_HELD)) + if (rb->gui_synclist_do_button(&lists, &action)) continue; selection = rb->gui_synclist_get_sel_pos(&lists); switch (action) @@ -892,6 +906,7 @@ reopen_datfile: } break; case ACTION_STD_CANCEL: + case ACTION_STD_MENU: { selection = -2; exit = true; |