From 0dce97372987a0b25446c33c7bfd616780d9d7c0 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Sun, 7 Mar 2021 08:22:01 -0500 Subject: OpenPlugins Allow opx shortcuts Allow opx shortcuts to be run through the shortcut menu Change-Id: I6597b9485dfb224766c442257c4d9c8ac02eece4 --- apps/open_plugin.c | 33 +++++++++++++++++++++++++++------ apps/plugins/open_plugins.c | 16 +++++++++------- 2 files changed, 36 insertions(+), 13 deletions(-) (limited to 'apps') diff --git a/apps/open_plugin.c b/apps/open_plugin.c index 61778e1ce7..7448018ed9 100644 --- a/apps/open_plugin.c +++ b/apps/open_plugin.c @@ -27,6 +27,11 @@ #include "splash.h" #include "lang.h" +#define ROCK_EXT "rock" +#define ROCK_LEN 5 +#define OP_EXT "opx" +#define OP_LEN 4 + struct open_plugin_entry_t open_plugin_entry; static const int op_entry_sz = sizeof(struct open_plugin_entry_t); @@ -34,9 +39,11 @@ static const int op_entry_sz = sizeof(struct open_plugin_entry_t); uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *parameter) { int len; + bool is_valid = false; uint32_t hash; char *pos; int fd = 0; + int fd1 = 0; /*strlcpy(plug_entry.key, key, sizeof(plug_entry.key));*/ open_plugin_entry.lang_id = P2ID((unsigned char*)key); @@ -52,12 +59,9 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p pos = "\0"; len = strlcpy(open_plugin_entry.name, pos, OPEN_PLUGIN_NAMESZ); - - if(len > 5 && strcasecmp(&(pos[len-5]), ".rock") == 0) + if (len > ROCK_LEN && strcasecmp(&(pos[len-ROCK_LEN]), "." ROCK_EXT) == 0) { - fd = open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666); - if (!fd) - return 0; + is_valid = true; /* path */ strlcpy(open_plugin_entry.path, plugin, OPEN_PLUGIN_BUFSZ); @@ -66,9 +70,26 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p strlcpy(open_plugin_entry.param, parameter, OPEN_PLUGIN_BUFSZ); else open_plugin_entry.param[0] = '\0'; + } + else if (len > OP_LEN && strcasecmp(&(pos[len-OP_LEN]), "." OP_EXT) == 0) + { + is_valid = true; + /* path */ + strlcpy(open_plugin_entry.path, + VIEWERS_DATA_DIR "/open_plugins." ROCK_EXT, OPEN_PLUGIN_BUFSZ); + /* parameter */ + strlcpy(open_plugin_entry.param, plugin, OPEN_PLUGIN_BUFSZ); write(fd, &open_plugin_entry, op_entry_sz); } + + if (is_valid) + { + fd = open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666); + if (!fd) + return 0; + write(fd, &open_plugin_entry, op_entry_sz); + } else { if (open_plugin_entry.lang_id != LANG_SHORTCUTS) @@ -77,7 +98,7 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p } } - int fd1 = open(OPEN_PLUGIN_DAT, O_RDONLY); + fd1 = open(OPEN_PLUGIN_DAT, O_RDONLY); if (fd1) { while (read(fd1, &open_plugin_entry, op_entry_sz) == op_entry_sz) diff --git a/apps/plugins/open_plugins.c b/apps/plugins/open_plugins.c index 0e636a7097..f9133f91bb 100644 --- a/apps/plugins/open_plugins.c +++ b/apps/plugins/open_plugins.c @@ -36,7 +36,10 @@ #include "../open_plugin.h" #define ROCK_EXT "rock" +#define ROCK_LEN 5 + #define OP_EXT "opx" +#define OP_LEN 4 #define OP_PLUGIN_RESTART (PLUGIN_GOTO_PLUGIN | 0x8000) @@ -106,7 +109,7 @@ static int op_entry_read_opx(const char *path) int len; len = rb->strlen(path); - if(len > 4 && rb->strcasecmp(&((path)[len-4]), "." OP_EXT) == 0) + if(len > OP_LEN && rb->strcasecmp(&((path)[len-OP_LEN]), "." OP_EXT) == 0) { fd_opx = rb->open(path, O_RDONLY); if (fd_opx) @@ -136,8 +139,8 @@ static void op_entry_export(int selection) if( !rb->kbd_input( filename, MAX_PATH, NULL ) ) { len = rb->strlen(filename); - if(len > 4 && filename[len] != PATH_SEPCH && - rb->strcasecmp(&((filename)[len-4]), "." OP_EXT) != 0) + if(len > OP_LEN && filename[len] != PATH_SEPCH && + rb->strcasecmp(&((filename)[len-OP_LEN]), "." OP_EXT) != 0) { rb->strcat(filename, "." OP_EXT); } @@ -291,7 +294,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) { - int len, extlen; + int len; uint32_t hash; char *pos = "";; int fd_tmp = -1; @@ -326,8 +329,7 @@ static uint32_t op_entry_add_path(const char *key, const char *plugin, const cha rb->strlcpy(op_entry.name, pos, OPEN_PLUGIN_NAMESZ); len = rb->strlen(pos); - extlen = rb->strlen("." ROCK_EXT); - if(len > extlen && rb->strcasecmp(&(pos[len-extlen]), "." ROCK_EXT) == 0) + if(len > ROCK_LEN && rb->strcasecmp(&(pos[len-ROCK_LEN]), "." ROCK_EXT) == 0) { fd_tmp = rb->open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd_tmp < 0) @@ -478,7 +480,7 @@ static int op_entry_run(void) char* param; if (op_entry.hash != 0 && op_entry.path[0] != '\0') { - rb->splash(1, ID2P(LANG_OPEN_PLUGIN)); + //rb->splash(1, ID2P(LANG_OPEN_PLUGIN)); path = op_entry.path; param = op_entry.param; if (param[0] == '\0') -- cgit v1.2.3