From ee840709d3d93376f9b5da6c34572424079304b8 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Mon, 6 May 2024 16:39:57 -0400 Subject: [Feature] Open plugins now recognizes known filetypes and can run them now you can run your lua files without having to add the viewer to the shortcut or if you want a bmp file to be displayed when you start the device that can be done as well Change-Id: Ia56b566789623a2ca78d9e4583086db6e2cd689b --- apps/filetree.c | 2 +- apps/filetypes.c | 4 ++-- apps/filetypes.h | 2 +- apps/open_plugin.c | 31 ++++++++++++++++++++++--------- apps/plugin.c | 1 + apps/plugin.h | 1 + apps/plugins/imageviewer/imageviewer.c | 4 +--- apps/plugins/open_plugins.c | 24 ++++++++++++++++++++---- 8 files changed, 49 insertions(+), 20 deletions(-) (limited to 'apps') diff --git a/apps/filetree.c b/apps/filetree.c index 594a0bd6f1..9550adbac2 100644 --- a/apps/filetree.c +++ b/apps/filetree.c @@ -755,7 +755,7 @@ int ft_enter(struct tree_context* c) return rc; } - plugin = filetype_get_plugin(file, plugin_path, sizeof(plugin_path)); + plugin = filetype_get_plugin(file->attr, plugin_path, sizeof(plugin_path)); if (plugin) { #ifdef PLUGINS_RUN_IN_BROWSER /* Stay in the filetree to run a plugin */ diff --git a/apps/filetypes.c b/apps/filetypes.c index bda7018381..e992b86060 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c @@ -604,9 +604,9 @@ int filetype_get_icon(int attr) return filetypes[index].icon; } -char* filetype_get_plugin(const struct entry* file, char *buffer, size_t buffer_len) +char* filetype_get_plugin(int attr, char *buffer, size_t buffer_len) { - int index = find_attr(file->attr); + int index = find_attr(attr); if (index < 0 || !buffer) return NULL; struct file_type *ft_indexed = &filetypes[index]; diff --git a/apps/filetypes.h b/apps/filetypes.h index 2886fa2850..36d9009a87 100644 --- a/apps/filetypes.h +++ b/apps/filetypes.h @@ -74,7 +74,7 @@ int filetype_get_color(const char* name, int attr); #endif int filetype_get_icon(int attr); /* return the plugin filename associated with the file */ -char* filetype_get_plugin(const struct entry* file, char *buffer, size_t buffer_len); +char* filetype_get_plugin(int attr, char *buffer, size_t buffer_len); /* returns true if the attr is supported */ bool filetype_supported(int attr); diff --git a/apps/open_plugin.c b/apps/open_plugin.c index afe59b38e3..e10463d260 100644 --- a/apps/open_plugin.c +++ b/apps/open_plugin.c @@ -26,16 +26,12 @@ #include "pathfuncs.h" #include "splash.h" #include "lang.h" +#include "filetypes.h" /* Define LOGF_ENABLE to enable logf output in this file */ /*#define LOGF_ENABLE*/ #include "logf.h" -#define ROCK_EXT "rock" -#define ROCK_LEN sizeof(ROCK_EXT) -#define OP_EXT "opx" -#define OP_LEN sizeof(OP_EXT) - static const uint32_t open_plugin_csum = OPEN_PLUGIN_CHECKSUM; static const int op_entry_sz = sizeof(struct open_plugin_entry_t); @@ -279,7 +275,6 @@ struct open_plugin_entry_t * open_plugin_get_entry(void) */ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *parameter) { - size_t len; uint32_t hash; int32_t lang_id; char *pos = "\0"; @@ -306,12 +301,15 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p while (plugin) { + int fattr = filetype_get_attr(plugin); + /* name */ if (path_basename(plugin, (const char **)&pos) == 0) pos = "\0"; - len = strlcpy(op_entry->name, pos, OPEN_PLUGIN_NAMESZ); - if (len > ROCK_LEN && strcasecmp(&(pos[len-ROCK_LEN]), "." ROCK_EXT) == 0) + strlcpy(op_entry->name, pos, OPEN_PLUGIN_NAMESZ); + + if (fattr == FILE_ATTR_ROCK) { /* path */ strmemccpy(op_entry->path, plugin, OPEN_PLUGIN_BUFSZ); @@ -320,11 +318,21 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p parameter = ""; strmemccpy(op_entry->param, parameter, OPEN_PLUGIN_BUFSZ); } - else if (len > OP_LEN && strcasecmp(&(pos[len-OP_LEN]), "." OP_EXT) == 0) + else if (fattr == FILE_ATTR_OPX) { /* get the entry from the opx file */ op_load_entry(0, OPEN_PLUGIN_LANG_IGNORE, op_entry, plugin); } + else if(!parameter) + { + strmemccpy(op_entry->param, plugin, OPEN_PLUGIN_BUFSZ); + plugin = filetype_get_plugin(fattr, op_entry->path, OPEN_PLUGIN_BUFSZ); + if (!plugin) + { + logf("OP no plugin found to run %s", op_entry->param); + break; + } + } else { break; @@ -349,6 +357,8 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p static bool callback_show_item(char *name, int attr, struct tree_context *tc) { (void)name; + (void)tc; +#if 0 if(attr & ATTR_DIRECTORY) { if (strstr(tc->currdir, PLUGIN_DIR) != NULL) @@ -364,6 +374,9 @@ static bool callback_show_item(char *name, int attr, struct tree_context *tc) return true; } return false; +#endif + return attr & ATTR_DIRECTORY || + (filetype_supported(attr) && (attr & FILE_ATTR_AUDIO) == 0); } /* open_plugin_browse() diff --git a/apps/plugin.c b/apps/plugin.c index bd93cb8b5c..931b8f1fd4 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -837,6 +837,7 @@ static const struct plugin_api rockbox_api = { #endif playlist_get_first_index, playlist_get_display_index, + filetype_get_plugin, }; static int plugin_buffer_handle; diff --git a/apps/plugin.h b/apps/plugin.h index 24eb28b2bd..df519f28cf 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -974,6 +974,7 @@ struct plugin_api { #endif int (*playlist_get_first_index)(const struct playlist_info* playlist); int (*playlist_get_display_index)(void); + char* (*filetype_get_plugin)(int attr, char *buffer, size_t buffer_len); }; /* plugin header */ diff --git a/apps/plugins/imageviewer/imageviewer.c b/apps/plugins/imageviewer/imageviewer.c index d1a512c4fd..9d5aea7f15 100644 --- a/apps/plugins/imageviewer/imageviewer.c +++ b/apps/plugins/imageviewer/imageviewer.c @@ -1033,7 +1033,7 @@ enum plugin_status plugin_start(const void* parameter) long greysize; /* helper */ #endif - if(!parameter) return PLUGIN_ERROR; + if(!parameter) {rb->splash(HZ*2, "No file"); return PLUGIN_ERROR; } rb->strcpy(np_file, parameter); if (get_image_type(np_file, false) == IMAGE_UNKNOWN) @@ -1051,8 +1051,6 @@ enum plugin_status plugin_start(const void* parameter) get_pic_list(); - if(!entries) return PLUGIN_ERROR; - #ifdef USEGSLIB if (!grey_init(buf, buf_size, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, &greysize)) diff --git a/apps/plugins/open_plugins.c b/apps/plugins/open_plugins.c index b608aff789..9d58433fdf 100644 --- a/apps/plugins/open_plugins.c +++ b/apps/plugins/open_plugins.c @@ -118,8 +118,7 @@ static int op_entry_read_opx(const char *path) int fd_opx; int len; - len = rb->strlen(path); - if(len > OP_LEN && rb->strcasecmp(&((path)[len-OP_LEN]), "." OP_EXT) == 0) + if(rb->filetype_get_attr(path) == FILE_ATTR_OPX) { fd_opx = rb->open(path, O_RDONLY); if (fd_opx >= 0) @@ -317,6 +316,7 @@ static int op_entry_transfer(int fd, int fd_tmp, static uint32_t op_entry_add_path(const char *key, const char *plugin, const char *parameter, bool use_key) { + char buf[MAX_PATH]; int len; uint32_t hash; uint32_t newhash; @@ -339,8 +339,11 @@ static uint32_t op_entry_add_path(const char *key, const char *plugin, const cha else hash = op_entry.hash; + + if (plugin) { + int fattr = rb->filetype_get_attr(plugin); /* name */ if (use_key) { @@ -353,8 +356,21 @@ static uint32_t op_entry_add_path(const char *key, const char *plugin, const cha if (op_entry.name[0] == '\0' || op_entry.lang_id >= 0) rb->strlcpy(op_entry.name, pos, OPEN_PLUGIN_NAMESZ); - len = rb->strlen(pos); - if(len > ROCK_LEN && rb->strcasecmp(&(pos[len-ROCK_LEN]), "." ROCK_EXT) == 0) + + + if ((!parameter || parameter[0] == '\0') && fattr != FILE_ATTR_ROCK && fattr != FILE_ATTR_OPX) + { + rb->strlcpy(op_entry.param, plugin, OPEN_PLUGIN_BUFSZ); + parameter = op_entry.param; + plugin = rb->filetype_get_plugin(fattr, buf, sizeof(buf)); + if (!plugin) + { + rb->splashf(HZ * 2, rb->str(LANG_OPEN_PLUGIN_NOT_A_PLUGIN), pos); + return 0; + } + } + + if(fattr == FILE_ATTR_ROCK) { fd_tmp = rb->open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd_tmp < 0) -- cgit v1.2.3