[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
This commit is contained in:
William Wilgus 2024-05-06 16:39:57 -04:00
parent 30482bd908
commit ee840709d3
8 changed files with 49 additions and 20 deletions

View file

@ -755,7 +755,7 @@ int ft_enter(struct tree_context* c)
return rc; 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) if (plugin)
{ {
#ifdef PLUGINS_RUN_IN_BROWSER /* Stay in the filetree to run a plugin */ #ifdef PLUGINS_RUN_IN_BROWSER /* Stay in the filetree to run a plugin */

View file

@ -604,9 +604,9 @@ int filetype_get_icon(int attr)
return filetypes[index].icon; 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) if (index < 0 || !buffer)
return NULL; return NULL;
struct file_type *ft_indexed = &filetypes[index]; struct file_type *ft_indexed = &filetypes[index];

View file

@ -74,7 +74,7 @@ int filetype_get_color(const char* name, int attr);
#endif #endif
int filetype_get_icon(int attr); int filetype_get_icon(int attr);
/* return the plugin filename associated with the file */ /* 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 */ /* returns true if the attr is supported */
bool filetype_supported(int attr); bool filetype_supported(int attr);

View file

@ -26,16 +26,12 @@
#include "pathfuncs.h" #include "pathfuncs.h"
#include "splash.h" #include "splash.h"
#include "lang.h" #include "lang.h"
#include "filetypes.h"
/* Define LOGF_ENABLE to enable logf output in this file */ /* Define LOGF_ENABLE to enable logf output in this file */
/*#define LOGF_ENABLE*/ /*#define LOGF_ENABLE*/
#include "logf.h" #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 uint32_t open_plugin_csum = OPEN_PLUGIN_CHECKSUM;
static const int op_entry_sz = sizeof(struct open_plugin_entry_t); 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) uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *parameter)
{ {
size_t len;
uint32_t hash; uint32_t hash;
int32_t lang_id; int32_t lang_id;
char *pos = "\0"; char *pos = "\0";
@ -306,12 +301,15 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p
while (plugin) while (plugin)
{ {
int fattr = filetype_get_attr(plugin);
/* name */ /* name */
if (path_basename(plugin, (const char **)&pos) == 0) if (path_basename(plugin, (const char **)&pos) == 0)
pos = "\0"; pos = "\0";
len = strlcpy(op_entry->name, pos, OPEN_PLUGIN_NAMESZ); strlcpy(op_entry->name, pos, OPEN_PLUGIN_NAMESZ);
if (len > ROCK_LEN && strcasecmp(&(pos[len-ROCK_LEN]), "." ROCK_EXT) == 0)
if (fattr == FILE_ATTR_ROCK)
{ {
/* path */ /* path */
strmemccpy(op_entry->path, plugin, OPEN_PLUGIN_BUFSZ); 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 = ""; parameter = "";
strmemccpy(op_entry->param, parameter, OPEN_PLUGIN_BUFSZ); 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 */ /* get the entry from the opx file */
op_load_entry(0, OPEN_PLUGIN_LANG_IGNORE, op_entry, plugin); 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 else
{ {
break; 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) static bool callback_show_item(char *name, int attr, struct tree_context *tc)
{ {
(void)name; (void)name;
(void)tc;
#if 0
if(attr & ATTR_DIRECTORY) if(attr & ATTR_DIRECTORY)
{ {
if (strstr(tc->currdir, PLUGIN_DIR) != NULL) 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 true;
} }
return false; return false;
#endif
return attr & ATTR_DIRECTORY ||
(filetype_supported(attr) && (attr & FILE_ATTR_AUDIO) == 0);
} }
/* open_plugin_browse() /* open_plugin_browse()

View file

@ -837,6 +837,7 @@ static const struct plugin_api rockbox_api = {
#endif #endif
playlist_get_first_index, playlist_get_first_index,
playlist_get_display_index, playlist_get_display_index,
filetype_get_plugin,
}; };
static int plugin_buffer_handle; static int plugin_buffer_handle;

View file

@ -974,6 +974,7 @@ struct plugin_api {
#endif #endif
int (*playlist_get_first_index)(const struct playlist_info* playlist); int (*playlist_get_first_index)(const struct playlist_info* playlist);
int (*playlist_get_display_index)(void); int (*playlist_get_display_index)(void);
char* (*filetype_get_plugin)(int attr, char *buffer, size_t buffer_len);
}; };
/* plugin header */ /* plugin header */

View file

@ -1033,7 +1033,7 @@ enum plugin_status plugin_start(const void* parameter)
long greysize; /* helper */ long greysize; /* helper */
#endif #endif
if(!parameter) return PLUGIN_ERROR; if(!parameter) {rb->splash(HZ*2, "No file"); return PLUGIN_ERROR; }
rb->strcpy(np_file, parameter); rb->strcpy(np_file, parameter);
if (get_image_type(np_file, false) == IMAGE_UNKNOWN) if (get_image_type(np_file, false) == IMAGE_UNKNOWN)
@ -1051,8 +1051,6 @@ enum plugin_status plugin_start(const void* parameter)
get_pic_list(); get_pic_list();
if(!entries) return PLUGIN_ERROR;
#ifdef USEGSLIB #ifdef USEGSLIB
if (!grey_init(buf, buf_size, GREY_ON_COP, if (!grey_init(buf, buf_size, GREY_ON_COP,
LCD_WIDTH, LCD_HEIGHT, &greysize)) LCD_WIDTH, LCD_HEIGHT, &greysize))

View file

@ -118,8 +118,7 @@ static int op_entry_read_opx(const char *path)
int fd_opx; int fd_opx;
int len; int len;
len = rb->strlen(path); if(rb->filetype_get_attr(path) == FILE_ATTR_OPX)
if(len > OP_LEN && rb->strcasecmp(&((path)[len-OP_LEN]), "." OP_EXT) == 0)
{ {
fd_opx = rb->open(path, O_RDONLY); fd_opx = rb->open(path, O_RDONLY);
if (fd_opx >= 0) 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) 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; int len;
uint32_t hash; uint32_t hash;
uint32_t newhash; uint32_t newhash;
@ -339,8 +339,11 @@ static uint32_t op_entry_add_path(const char *key, const char *plugin, const cha
else else
hash = op_entry.hash; hash = op_entry.hash;
if (plugin) if (plugin)
{ {
int fattr = rb->filetype_get_attr(plugin);
/* name */ /* name */
if (use_key) 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) if (op_entry.name[0] == '\0' || op_entry.lang_id >= 0)
rb->strlcpy(op_entry.name, pos, OPEN_PLUGIN_NAMESZ); 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); fd_tmp = rb->open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd_tmp < 0) if (fd_tmp < 0)