diff options
author | William Wilgus <wilgus.william@gmail.com> | 2020-08-19 00:39:23 -0400 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2020-08-19 02:06:16 -0400 |
commit | 8ee035b6c884142f936b03b7419d14e9102515d9 (patch) | |
tree | 09c65904fe37dac707d2a8c4e4b1e29ee5d5060e /apps | |
parent | 889bcc0f763fcb31b9ac66a23199ce31746664ed (diff) | |
download | rockbox-8ee035b6c884142f936b03b7419d14e9102515d9.tar.gz rockbox-8ee035b6c884142f936b03b7419d14e9102515d9.zip |
Open_plugin add ability to import opx shortcuts, bug fix
shortcuts can be exported as .opx; now they can import as well
if parameter is a valid file..
plugins with parameters are now hashed on the parameter path
fix bug with empty parameters not overwriting last valid parameter
Change-Id: I149519811f07cb4ba22b7113449e2f89f77f1eee
Diffstat (limited to 'apps')
-rw-r--r-- | apps/open_plugin.c | 2 | ||||
-rw-r--r-- | apps/plugins/open_plugins.c | 99 |
2 files changed, 66 insertions, 35 deletions
diff --git a/apps/open_plugin.c b/apps/open_plugin.c index 5bca829708..61778e1ce7 100644 --- a/apps/open_plugin.c +++ b/apps/open_plugin.c | |||
@@ -64,6 +64,8 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p | |||
64 | 64 | ||
65 | if(parameter) | 65 | if(parameter) |
66 | strlcpy(open_plugin_entry.param, parameter, OPEN_PLUGIN_BUFSZ); | 66 | strlcpy(open_plugin_entry.param, parameter, OPEN_PLUGIN_BUFSZ); |
67 | else | ||
68 | open_plugin_entry.param[0] = '\0'; | ||
67 | 69 | ||
68 | write(fd, &open_plugin_entry, op_entry_sz); | 70 | write(fd, &open_plugin_entry, op_entry_sz); |
69 | } | 71 | } |
diff --git a/apps/plugins/open_plugins.c b/apps/plugins/open_plugins.c index f06a790d02..7a888b6af2 100644 --- a/apps/plugins/open_plugins.c +++ b/apps/plugins/open_plugins.c | |||
@@ -98,6 +98,30 @@ static bool op_entry_read_name(int fd, int selected_item) | |||
98 | return op_entry_read(fd, selected_item, op_name_sz); | 98 | return op_entry_read(fd, selected_item, op_name_sz); |
99 | } | 99 | } |
100 | 100 | ||
101 | static int op_entry_read_opx(const char *path) | ||
102 | { | ||
103 | int ret = -1; | ||
104 | off_t filesize; | ||
105 | int fd_opx; | ||
106 | int len; | ||
107 | |||
108 | len = rb->strlen(path); | ||
109 | if(len > 4 && rb->strcasecmp(&((path)[len-4]), "." OP_EXT) == 0) | ||
110 | { | ||
111 | fd_opx = rb->open(path, O_RDONLY); | ||
112 | if (fd_opx) | ||
113 | { | ||
114 | filesize = rb->filesize(fd_opx); | ||
115 | ret = filesize; | ||
116 | if (filesize == op_entry_sz && !op_entry_read(fd_opx, 0, op_entry_sz)) | ||
117 | ret = 0; | ||
118 | |||
119 | rb->close(fd_opx); | ||
120 | } | ||
121 | } | ||
122 | return ret; | ||
123 | } | ||
124 | |||
101 | static void op_entry_export(int selection) | 125 | static void op_entry_export(int selection) |
102 | { | 126 | { |
103 | int len; | 127 | int len; |
@@ -312,12 +336,32 @@ static uint32_t op_entry_add_path(const char *key, const char *plugin, const cha | |||
312 | { | 336 | { |
313 | op_entry_set_param(); | 337 | op_entry_set_param(); |
314 | } | 338 | } |
315 | else | 339 | else if (parameter != op_entry.param) |
316 | rb->strlcpy(op_entry.param, parameter, OPEN_PLUGIN_BUFSZ); | 340 | rb->strlcpy(op_entry.param, parameter, OPEN_PLUGIN_BUFSZ); |
341 | |||
342 | /* hash on the parameter path if it is a file */ | ||
343 | if (op_entry.lang_id <0 && key == op_entry.path && | ||
344 | rb->file_exists(op_entry.param)) | ||
345 | open_plugin_get_hash(op_entry.path, &op_entry.hash); | ||
317 | } | 346 | } |
318 | 347 | ||
319 | rb->write(fd_tmp, &op_entry, op_entry_sz); /* add new entry first */ | 348 | rb->write(fd_tmp, &op_entry, op_entry_sz); /* add new entry first */ |
320 | } | 349 | } |
350 | else if(op_entry_read_opx(plugin) == op_entry_sz) | ||
351 | { | ||
352 | fd_tmp = rb->open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666); | ||
353 | if (fd_tmp < 0) | ||
354 | return 0; | ||
355 | |||
356 | if (op_entry.lang_id <0 && rb->file_exists(op_entry.param)) | ||
357 | open_plugin_get_hash(op_entry.param, &hash); | ||
358 | else | ||
359 | open_plugin_get_hash(op_entry.path, &hash); | ||
360 | |||
361 | op_entry.hash = hash; | ||
362 | |||
363 | rb->write(fd_tmp, &op_entry, op_entry_sz); /* add new entry first */ | ||
364 | } | ||
321 | else | 365 | else |
322 | { | 366 | { |
323 | if (op_entry.lang_id != LANG_SHORTCUTS) | 367 | if (op_entry.lang_id != LANG_SHORTCUTS) |
@@ -402,8 +446,8 @@ static void op_entry_remove_empty(void) | |||
402 | if (fd_tmp < 0) | 446 | if (fd_tmp < 0) |
403 | return; | 447 | return; |
404 | 448 | ||
405 | if ((op_entry_transfer(fd_dat, fd_tmp, &op_et_exclude_builtin, NULL) | 449 | if ((op_entry_transfer(fd_dat, fd_tmp, &op_et_exclude_user, NULL) |
406 | + op_entry_transfer(fd_dat, fd_tmp, &op_et_exclude_user, NULL)) > 0) | 450 | + op_entry_transfer(fd_dat, fd_tmp, &op_et_exclude_builtin, NULL)) > 0) |
407 | { | 451 | { |
408 | rb->close(fd_tmp); | 452 | rb->close(fd_tmp); |
409 | rb->close(fd_dat); | 453 | rb->close(fd_dat); |
@@ -688,9 +732,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
688 | int selection = -1; | 732 | int selection = -1; |
689 | int action; | 733 | int action; |
690 | int items; | 734 | int items; |
691 | int len; | 735 | int res; |
692 | int fd_opx; | ||
693 | off_t filesize; | ||
694 | char *path; | 736 | char *path; |
695 | bool exit = false; | 737 | bool exit = false; |
696 | 738 | ||
@@ -710,28 +752,13 @@ enum plugin_status plugin_start(const void* parameter) | |||
710 | if (parameter) | 752 | if (parameter) |
711 | { | 753 | { |
712 | path = (char*)parameter; | 754 | path = (char*)parameter; |
713 | len = rb->strlen(path); | 755 | res = op_entry_read_opx(path); |
714 | if(len > 4 && rb->strcasecmp(&((path)[len-4]), "." OP_EXT) == 0) | 756 | if (res >= 0) |
715 | { | 757 | { |
716 | fd_opx = rb->open(path, O_RDONLY, 0666); | 758 | if (res == op_entry_sz) |
717 | if (fd_opx) | ||
718 | { | 759 | { |
719 | filesize = rb->filesize(fd_opx); | 760 | exit = true; |
720 | if (filesize == op_entry_sz) | 761 | ret = op_entry_run(); |
721 | { | ||
722 | |||
723 | if (op_entry_read(fd_opx, 0, op_entry_sz)) | ||
724 | { | ||
725 | exit = true; | ||
726 | ret = op_entry_run(); | ||
727 | } | ||
728 | else | ||
729 | rb->splashf(HZ, rb->str(LANG_READ_FAILED), path); | ||
730 | } | ||
731 | else if (filesize != 0) | ||
732 | rb->splashf(2 * HZ, rb->str(LANG_OPEN_PLUGIN_NOT_A_PLUGIN), path); | ||
733 | |||
734 | rb->close(fd_opx); | ||
735 | } | 762 | } |
736 | } | 763 | } |
737 | else | 764 | else |
@@ -752,22 +779,24 @@ enum plugin_status plugin_start(const void* parameter) | |||
752 | { | 779 | { |
753 | if (op_entry_read(fd_dat, selection, op_entry_sz)) | 780 | if (op_entry_read(fd_dat, selection, op_entry_sz)) |
754 | { | 781 | { |
755 | if (op_entry_run() == PLUGIN_GOTO_PLUGIN) | 782 | ret = op_entry_run(); |
756 | return PLUGIN_GOTO_PLUGIN; | 783 | if (ret == PLUGIN_GOTO_PLUGIN) |
784 | exit = true; | ||
757 | } | 785 | } |
758 | } | 786 | } |
759 | else | 787 | else |
760 | { | 788 | { |
761 | op_entry_read(fd_dat, selection, op_entry_sz); | 789 | op_entry_read(fd_dat, selection, op_entry_sz); |
762 | op_entry_add_path(parameter, parameter, "\0"); | 790 | if (op_entry_add_path(parameter, parameter, "\0") > 0) |
763 | selection = 0; | 791 | { |
764 | items++; | 792 | selection = 0; |
765 | fd_dat = rb->open(OPEN_PLUGIN_DAT, creat_flags, 0666); | 793 | items++; |
766 | if (!fd_dat) | 794 | fd_dat = rb->open(OPEN_PLUGIN_DAT, creat_flags, 0666); |
767 | exit = true; | 795 | if (!fd_dat) |
796 | exit = true; | ||
797 | } | ||
768 | } | 798 | } |
769 | }/* OP_EXT */ | 799 | }/* OP_EXT */ |
770 | |||
771 | } | 800 | } |
772 | 801 | ||
773 | if (!exit) | 802 | if (!exit) |