summaryrefslogtreecommitdiff
path: root/apps/plugins/open_plugins.c
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2022-11-17 01:25:41 -0500
committerWilliam Wilgus <wilgus.william@gmail.com>2022-11-17 01:43:16 -0500
commit0b7a387671a56a1b526b3672cd695b5764597f3e (patch)
tree07c9c337f002a647c5e6c7eaf0a6b3c5245097cb /apps/plugins/open_plugins.c
parent4c3937591c510a22c724d18dae9367bb1b786698 (diff)
downloadrockbox-0b7a387671a56a1b526b3672cd695b5764597f3e.tar.gz
rockbox-0b7a387671a56a1b526b3672cd695b5764597f3e.zip
open_plugins add name when plugin can't open & check LANG_LAST_INDEX_IN_ARRAY
can't open '' was confusing for users so pass the key to open plugin in theory you could have a plugin that defaulted to these lang_ids run but its good enough to tell the user what failed to open IMO lang_id changes mess with open_plugin since it uses them as look-up keys so add checks for LANG_LAST_INDEX_IN_ARRAY to the checksum the plugin now removes entries with an invalid checksum devices with harddrives only append their .dat file so have them skip entries with invalid checksums and only notify user if a valid entry wasn't found (these users can run the open_plugins plugin to remove invalid entries) Change-Id: Icf157675beaccda785643d5a9ed032a7cde30f12
Diffstat (limited to 'apps/plugins/open_plugins.c')
-rw-r--r--apps/plugins/open_plugins.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/apps/plugins/open_plugins.c b/apps/plugins/open_plugins.c
index 7230387efb..6deaf80f7d 100644
--- a/apps/plugins/open_plugins.c
+++ b/apps/plugins/open_plugins.c
@@ -87,6 +87,15 @@ static size_t pathbasename(const char *name, const char **nameptr)
87 *nameptr = q; 87 *nameptr = q;
88 return r - q; 88 return r - q;
89} 89}
90static int op_entry_checksum(void)
91{
92 if (op_entry.checksum != open_plugin_csum +
93 (op_entry.lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY))
94 {
95 return 0;
96 }
97 return 1;
98}
90 99
91static bool op_entry_read(int fd, int selected_item, off_t data_sz) 100static bool op_entry_read(int fd, int selected_item, off_t data_sz)
92{ 101{
@@ -94,7 +103,7 @@ static bool op_entry_read(int fd, int selected_item, off_t data_sz)
94 op_entry.lang_id = -1; 103 op_entry.lang_id = -1;
95 return ((selected_item >= 0) && 104 return ((selected_item >= 0) &&
96 (rb->lseek(fd, selected_item * op_entry_sz, SEEK_SET) >= 0) && 105 (rb->lseek(fd, selected_item * op_entry_sz, SEEK_SET) >= 0) &&
97 (rb->read(fd, &op_entry, data_sz) == data_sz)); 106 (rb->read(fd, &op_entry, data_sz) == data_sz) && op_entry_checksum() > 0);
98} 107}
99 108
100static bool op_entry_read_name(int fd, int selected_item) 109static bool op_entry_read_name(int fd, int selected_item)
@@ -102,15 +111,6 @@ static bool op_entry_read_name(int fd, int selected_item)
102 return op_entry_read(fd, selected_item, op_name_sz); 111 return op_entry_read(fd, selected_item, op_name_sz);
103} 112}
104 113
105static int op_entry_checksum(void)
106{
107 if (op_entry.checksum != open_plugin_csum)
108 {
109 return 0;
110 }
111 return 1;
112}
113
114static int op_entry_read_opx(const char *path) 114static int op_entry_read_opx(const char *path)
115{ 115{
116 int ret = -1; 116 int ret = -1;
@@ -174,7 +174,8 @@ failure:
174 174
175static void op_entry_set_checksum(void) 175static void op_entry_set_checksum(void)
176{ 176{
177 op_entry.checksum = open_plugin_csum; 177 op_entry.checksum = open_plugin_csum +
178 (op_entry.lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY);
178} 179}
179 180
180static void op_entry_set_name(void) 181static void op_entry_set_name(void)
@@ -466,7 +467,7 @@ static void op_entry_remove_empty(void)
466 while (resave == false && 467 while (resave == false &&
467 rb->read(fd_dat, &op_entry, op_entry_sz) == op_entry_sz) 468 rb->read(fd_dat, &op_entry, op_entry_sz) == op_entry_sz)
468 { 469 {
469 if (op_entry.hash == 0) 470 if (op_entry.hash == 0 || !op_entry_checksum())
470 resave = true; 471 resave = true;
471 } 472 }
472 } 473 }
@@ -839,6 +840,12 @@ reopen_datfile:
839 }/* OP_EXT */ 840 }/* OP_EXT */
840 } 841 }
841 842
843 for (int i = items - 1; i > 0 && !exit; i--)
844 {
845 if (!op_entry_read(fd_dat, i, op_entry_sz))
846 items--;
847 }
848
842 if (items < 1 && !exit) 849 if (items < 1 && !exit)
843 { 850 {
844 char* cur_filename = rb->plugin_get_current_filename(); 851 char* cur_filename = rb->plugin_get_current_filename();