forked from len0rd/rockbox
OpenPlugins Allow opx shortcuts
Allow opx shortcuts to be run through the shortcut menu Change-Id: I6597b9485dfb224766c442257c4d9c8ac02eece4
This commit is contained in:
parent
207514fb25
commit
0dce973729
2 changed files with 36 additions and 13 deletions
|
@ -27,6 +27,11 @@
|
||||||
#include "splash.h"
|
#include "splash.h"
|
||||||
#include "lang.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;
|
struct open_plugin_entry_t open_plugin_entry;
|
||||||
|
|
||||||
static const int op_entry_sz = sizeof(struct open_plugin_entry_t);
|
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)
|
uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *parameter)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
|
bool is_valid = false;
|
||||||
uint32_t hash;
|
uint32_t hash;
|
||||||
char *pos;
|
char *pos;
|
||||||
int fd = 0;
|
int fd = 0;
|
||||||
|
int fd1 = 0;
|
||||||
|
|
||||||
/*strlcpy(plug_entry.key, key, sizeof(plug_entry.key));*/
|
/*strlcpy(plug_entry.key, key, sizeof(plug_entry.key));*/
|
||||||
open_plugin_entry.lang_id = P2ID((unsigned char*)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";
|
pos = "\0";
|
||||||
|
|
||||||
len = strlcpy(open_plugin_entry.name, pos, OPEN_PLUGIN_NAMESZ);
|
len = strlcpy(open_plugin_entry.name, pos, OPEN_PLUGIN_NAMESZ);
|
||||||
|
if (len > ROCK_LEN && strcasecmp(&(pos[len-ROCK_LEN]), "." ROCK_EXT) == 0)
|
||||||
if(len > 5 && strcasecmp(&(pos[len-5]), ".rock") == 0)
|
|
||||||
{
|
{
|
||||||
fd = open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
is_valid = true;
|
||||||
if (!fd)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* path */
|
/* path */
|
||||||
strlcpy(open_plugin_entry.path, plugin, OPEN_PLUGIN_BUFSZ);
|
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);
|
strlcpy(open_plugin_entry.param, parameter, OPEN_PLUGIN_BUFSZ);
|
||||||
else
|
else
|
||||||
open_plugin_entry.param[0] = '\0';
|
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);
|
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
|
else
|
||||||
{
|
{
|
||||||
if (open_plugin_entry.lang_id != LANG_SHORTCUTS)
|
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)
|
if (fd1)
|
||||||
{
|
{
|
||||||
while (read(fd1, &open_plugin_entry, op_entry_sz) == op_entry_sz)
|
while (read(fd1, &open_plugin_entry, op_entry_sz) == op_entry_sz)
|
||||||
|
|
|
@ -36,7 +36,10 @@
|
||||||
#include "../open_plugin.h"
|
#include "../open_plugin.h"
|
||||||
|
|
||||||
#define ROCK_EXT "rock"
|
#define ROCK_EXT "rock"
|
||||||
|
#define ROCK_LEN 5
|
||||||
|
|
||||||
#define OP_EXT "opx"
|
#define OP_EXT "opx"
|
||||||
|
#define OP_LEN 4
|
||||||
|
|
||||||
#define OP_PLUGIN_RESTART (PLUGIN_GOTO_PLUGIN | 0x8000)
|
#define OP_PLUGIN_RESTART (PLUGIN_GOTO_PLUGIN | 0x8000)
|
||||||
|
|
||||||
|
@ -106,7 +109,7 @@ static int op_entry_read_opx(const char *path)
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = rb->strlen(path);
|
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);
|
fd_opx = rb->open(path, O_RDONLY);
|
||||||
if (fd_opx)
|
if (fd_opx)
|
||||||
|
@ -136,8 +139,8 @@ static void op_entry_export(int selection)
|
||||||
if( !rb->kbd_input( filename, MAX_PATH, NULL ) )
|
if( !rb->kbd_input( filename, MAX_PATH, NULL ) )
|
||||||
{
|
{
|
||||||
len = rb->strlen(filename);
|
len = rb->strlen(filename);
|
||||||
if(len > 4 && filename[len] != PATH_SEPCH &&
|
if(len > OP_LEN && filename[len] != PATH_SEPCH &&
|
||||||
rb->strcasecmp(&((filename)[len-4]), "." OP_EXT) != 0)
|
rb->strcasecmp(&((filename)[len-OP_LEN]), "." OP_EXT) != 0)
|
||||||
{
|
{
|
||||||
rb->strcat(filename, "." OP_EXT);
|
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)
|
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;
|
uint32_t hash;
|
||||||
char *pos = "";;
|
char *pos = "";;
|
||||||
int fd_tmp = -1;
|
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);
|
rb->strlcpy(op_entry.name, pos, OPEN_PLUGIN_NAMESZ);
|
||||||
|
|
||||||
len = rb->strlen(pos);
|
len = rb->strlen(pos);
|
||||||
extlen = rb->strlen("." ROCK_EXT);
|
if(len > ROCK_LEN && rb->strcasecmp(&(pos[len-ROCK_LEN]), "." ROCK_EXT) == 0)
|
||||||
if(len > extlen && rb->strcasecmp(&(pos[len-extlen]), "." ROCK_EXT) == 0)
|
|
||||||
{
|
{
|
||||||
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)
|
||||||
|
@ -478,7 +480,7 @@ static int op_entry_run(void)
|
||||||
char* param;
|
char* param;
|
||||||
if (op_entry.hash != 0 && op_entry.path[0] != '\0')
|
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;
|
path = op_entry.path;
|
||||||
param = op_entry.param;
|
param = op_entry.param;
|
||||||
if (param[0] == '\0')
|
if (param[0] == '\0')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue