summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/open_plugins.c55
1 files changed, 43 insertions, 12 deletions
diff --git a/apps/plugins/open_plugins.c b/apps/plugins/open_plugins.c
index 84d594ca9a..6f3295f8e3 100644
--- a/apps/plugins/open_plugins.c
+++ b/apps/plugins/open_plugins.c
@@ -51,7 +51,7 @@ const off_t op_entry_sz = sizeof(struct open_plugin_entry_t);
51/* we only need the names for the first menu so don't bother reading paths yet */ 51/* we only need the names for the first menu so don't bother reading paths yet */
52const off_t op_name_sz = OPEN_PLUGIN_NAMESZ + (op_entry.name - (char*)&op_entry); 52const off_t op_name_sz = OPEN_PLUGIN_NAMESZ + (op_entry.name - (char*)&op_entry);
53 53
54static uint32_t op_entry_add_path(const char *key, const char *plugin, const char *parameter); 54static uint32_t op_entry_add_path(const char *key, const char *plugin, const char *parameter, bool use_key);
55 55
56static bool _yesno_pop(const char* text) 56static bool _yesno_pop(const char* text)
57{ 57{
@@ -175,7 +175,7 @@ static int op_entry_set_path(void)
175 if (op_entry.path[0] == '\0') 175 if (op_entry.path[0] == '\0')
176 rb->strcpy(op_entry.path, PLUGIN_DIR"/"); 176 rb->strcpy(op_entry.path, PLUGIN_DIR"/");
177 177
178 rb->browse_context_init(&browse, SHOW_ALL, BROWSE_SELECTONLY, "", 178 rb->browse_context_init(&browse, SHOW_ALL, BROWSE_SELECTONLY, rb->str(LANG_ADD),
179 Icon_Plugin, op_entry.path, NULL); 179 Icon_Plugin, op_entry.path, NULL);
180 180
181 browse.buf = tmp_buf; 181 browse.buf = tmp_buf;
@@ -289,12 +289,13 @@ static int op_entry_transfer(int fd, int fd_tmp,
289 return entries + 1; 289 return entries + 1;
290} 290}
291 291
292static uint32_t op_entry_add_path(const char *key, const char *plugin, const char *parameter) 292static uint32_t op_entry_add_path(const char *key, const char *plugin, const char *parameter, bool use_key)
293{ 293{
294 int len; 294 int len, extlen;
295 uint32_t hash; 295 uint32_t hash;
296 char *pos = "";; 296 char *pos = "";;
297 int fd_tmp = -1; 297 int fd_tmp = -1;
298 use_key = (use_key == true && key != NULL);
298 299
299 if (key) 300 if (key)
300 { 301 {
@@ -313,13 +314,20 @@ static uint32_t op_entry_add_path(const char *key, const char *plugin, const cha
313 if (plugin) 314 if (plugin)
314 { 315 {
315 /* name */ 316 /* name */
317 if (use_key)
318 {
319 op_entry.lang_id = -1;
320 rb->strlcpy(op_entry.name, key, OPEN_PLUGIN_NAMESZ);
321 }
322
316 if (pathbasename(plugin, (const char **)&pos) == 0) 323 if (pathbasename(plugin, (const char **)&pos) == 0)
317 pos = "\0"; 324 pos = "\0";
318 if (op_entry.name[0] == '\0' || op_entry.lang_id >= 0) 325 if (op_entry.name[0] == '\0' || op_entry.lang_id >= 0)
319 rb->strlcpy(op_entry.name, pos, OPEN_PLUGIN_NAMESZ); 326 rb->strlcpy(op_entry.name, pos, OPEN_PLUGIN_NAMESZ);
320 327
321 len = rb->strlen(pos); 328 len = rb->strlen(pos);
322 if(len > 5 && rb->strcasecmp(&(pos[len-5]), "." ROCK_EXT) == 0) 329 extlen = rb->strlen("." ROCK_EXT);
330 if(len > extlen && rb->strcasecmp(&(pos[len-extlen]), "." ROCK_EXT) == 0)
323 { 331 {
324 fd_tmp = rb->open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666); 332 fd_tmp = rb->open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666);
325 if (fd_tmp < 0) 333 if (fd_tmp < 0)
@@ -398,7 +406,7 @@ void op_entry_browse_add(int selection)
398 else 406 else
399 key = op_entry.path; 407 key = op_entry.path;
400 408
401 op_entry_add_path(key, op_entry.path, NULL); 409 op_entry_add_path(key, op_entry.path, NULL, false);
402 } 410 }
403} 411}
404 412
@@ -681,7 +689,7 @@ static void edit_menu(int selection)
681 if (param[0] == '\0') 689 if (param[0] == '\0')
682 param = NULL; 690 param = NULL;
683 691
684 op_entry_add_path(NULL, op_entry.path, param); 692 op_entry_add_path(NULL, op_entry.path, param, false);
685 fd_dat = rb->open(OPEN_PLUGIN_DAT, O_RDWR, 0666); 693 fd_dat = rb->open(OPEN_PLUGIN_DAT, O_RDWR, 0666);
686 } 694 }
687} 695}
@@ -737,11 +745,27 @@ enum plugin_status plugin_start(const void* parameter)
737 bool exit = false; 745 bool exit = false;
738 746
739 const int creat_flags = O_RDWR | O_CREAT; 747 const int creat_flags = O_RDWR | O_CREAT;
748
749reopen_datfile:
740 fd_dat = rb->open(OPEN_PLUGIN_DAT, creat_flags, 0666); 750 fd_dat = rb->open(OPEN_PLUGIN_DAT, creat_flags, 0666);
741 if (!fd_dat) 751 if (!fd_dat)
742 exit = true; 752 exit = true;
743 753
744 items = rb->lseek(fd_dat, 0, SEEK_END) / op_entry_sz; 754 items = rb->lseek(fd_dat, 0, SEEK_END) / op_entry_sz;
755 if (parameter)
756 {
757 path = (char*)parameter;
758 while (path[0] == ' ')
759 path++;
760
761 if (strncasecmp(path, "-add", 4) == 0)
762 {
763 parameter = NULL;
764 op_entry_browse_add(-1);
765 rb->close(fd_dat);
766 goto reopen_datfile;
767 }
768 }
745 769
746 if (parameter) 770 if (parameter)
747 { 771 {
@@ -781,7 +805,7 @@ enum plugin_status plugin_start(const void* parameter)
781 else 805 else
782 { 806 {
783 op_entry_read(fd_dat, selection, op_entry_sz); 807 op_entry_read(fd_dat, selection, op_entry_sz);
784 if (op_entry_add_path(parameter, parameter, "\0") > 0) 808 if (op_entry_add_path(parameter, parameter, "\0", false) > 0)
785 { 809 {
786 selection = 0; 810 selection = 0;
787 items++; 811 items++;
@@ -792,12 +816,19 @@ enum plugin_status plugin_start(const void* parameter)
792 } 816 }
793 }/* OP_EXT */ 817 }/* OP_EXT */
794 } 818 }
795 819
796 if (items == 0 && !exit) 820 if (items < 1 && !exit)
797 { 821 {
798 rb->plugin_open(rb->plugin_get_current_filename(), NULL); 822 char* cur_filename = rb->plugin_get_current_filename();
823
824 if (op_entry_add_path(rb->str(LANG_ADD), cur_filename, "-add", true))
825 {
826 rb->close(fd_dat);
827 parameter = NULL;
828 goto reopen_datfile;
829 }
799 rb->close(fd_dat); 830 rb->close(fd_dat);
800 return PLUGIN_GOTO_PLUGIN; 831 return PLUGIN_ERROR;
801 } 832 }
802 833
803 834