From 72c539d35e1853980de1d74e65acc9a22caa63f6 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Wed, 22 Nov 2023 00:07:30 -0500 Subject: [Bug_Fix] shortcut to directory in .link files caused crash since the plugin browser is now closed when running plugins rb->set_current_file() had no valid browser context and used 'random' memory instead also adds a way to discard levels so we can load the desired directory instead of returning to the previous https://forums.rockbox.org/index.php/topic,54694.0.html Change-Id: I624246e56d42972bf6a1ce566a209b745de6f30b --- apps/plugins/shortcuts/shortcuts_view.c | 58 ++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 9 deletions(-) (limited to 'apps/plugins/shortcuts/shortcuts_view.c') diff --git a/apps/plugins/shortcuts/shortcuts_view.c b/apps/plugins/shortcuts/shortcuts_view.c index 2a7970bebe..187ed740a1 100644 --- a/apps/plugins/shortcuts/shortcuts_view.c +++ b/apps/plugins/shortcuts/shortcuts_view.c @@ -32,7 +32,7 @@ enum sc_list_action_type SCLA_USB, }; - +static size_t root_len; static char *link_filename; static bool user_file; @@ -175,6 +175,42 @@ bool goto_entry(char *file_or_dir) } #endif +static bool callback_show_item(char *name, int attr, struct tree_context *tc) +{ + (void)name; + if(attr & ATTR_DIRECTORY) + { + if ((tc->browse->flags & BROWSE_SELECTED) == 0 && + rb->strlen(tc->currdir) < root_len) + { + tc->is_browsing = false; /* exit immediately */ + } + } + + return true; +} + +bool open_browse(char *path, char *buf, size_t bufsz) +{ + struct browse_context browse = { + .dirfilter = rb->global_settings->dirfilter, + .flags = BROWSE_DIRFILTER| BROWSE_SELECTONLY | BROWSE_NO_CONTEXT_MENU, + .title = path, + .icon = Icon_Plugin, + .root = path, + .buf = buf, + .bufsize = bufsz, + .callback_show_item = callback_show_item, + }; + root_len = 0; + char *name = rb->strrchr(path, '/'); + if (name) + root_len = name - path; + rb->rockbox_browse(&browse); + + return (browse.flags & BROWSE_SELECTED); +} + int goto_entry(char *file_or_dir) { DEBUGF("Trying to go to '%s'...\n", file_or_dir); @@ -202,14 +238,18 @@ int goto_entry(char *file_or_dir) } else { - /* Set the browsers dirfilter to the global setting - * This is required in case the plugin was launched - * from the plugins browser, in which case the - * dirfilter is set to only display .rock files */ - rb->set_dirfilter(rb->global_settings->dirfilter); - - /* Change directory to the entry selected by the user */ - rb->set_current_file(file_or_dir); + if (!is_dir) + { + rb->set_current_file(file_or_dir); + return LOOP_EXIT; + } + char tmp_buf[MAX_PATH]; + if (open_browse(file_or_dir, tmp_buf, sizeof(tmp_buf))) + { + DEBUGF("Trying to load '%s'...\n", tmp_buf); + rb->set_current_file(tmp_buf); + return LOOP_EXIT; + } } return PLUGIN_OK; } -- cgit v1.2.3