From 0b7a387671a56a1b526b3672cd695b5764597f3e Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Thu, 17 Nov 2022 01:25:41 -0500 Subject: 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 --- apps/open_plugin.c | 32 ++++++++++++++++++++++++++------ apps/open_plugin.h | 5 +++-- apps/plugins/open_plugins.c | 31 +++++++++++++++++++------------ apps/root_menu.c | 2 ++ 4 files changed, 50 insertions(+), 20 deletions(-) diff --git a/apps/open_plugin.c b/apps/open_plugin.c index 67b6f6d318..45dd7cdd2c 100644 --- a/apps/open_plugin.c +++ b/apps/open_plugin.c @@ -28,7 +28,7 @@ #include "lang.h" /* Define LOGF_ENABLE to enable logf output in this file */ -//#define LOGF_ENABLE +/*#define LOGF_ENABLE*/ #include "logf.h" #define ROCK_EXT "rock" @@ -60,8 +60,12 @@ static inline void op_clear_entry(struct open_plugin_entry_t *entry) static int op_entry_checksum(struct open_plugin_entry_t *entry) { - if (entry == NULL || entry->checksum != open_plugin_csum) + if (entry == NULL || entry->checksum != open_plugin_csum + + (entry->lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY)) + { + logf("OP entry bad checksum"); return 0; + } return 1; } @@ -81,6 +85,14 @@ static int op_find_entry(int fd, struct open_plugin_entry_t *entry, if (entry->lang_id == lang_id || entry->hash == hash || (lang_id == OPEN_PLUGIN_LANG_IGNOREALL))/* return first entry found */ { +#if (CONFIG_STORAGE & STORAGE_ATA) + /* may have invalid entries but we append the file so continue looking*/ + if (op_entry_checksum(entry) <= 0) + { + ret = OPEN_PLUGIN_INVALID_ENTRY; + continue; + } +#endif ret = record; /* NULL terminate fields NOTE -- all are actually +1 larger */ entry->name[OPEN_PLUGIN_NAMESZ] = '\0'; @@ -98,7 +110,12 @@ static int op_find_entry(int fd, struct open_plugin_entry_t *entry, } /* sanity check */ - if (ret > OPEN_PLUGIN_NOT_FOUND && op_entry_checksum(entry) <= 0) +#if (CONFIG_STORAGE & STORAGE_ATA) + if (ret == OPEN_PLUGIN_INVALID_ENTRY || +#else + if( +#endif + (ret > OPEN_PLUGIN_NOT_FOUND && op_entry_checksum(entry) <= 0)) { splash(HZ * 2, "OpenPlugin Invalid entry"); ret = OPEN_PLUGIN_NOT_FOUND; @@ -144,7 +161,7 @@ static int op_update_dat(struct open_plugin_entry_t *entry, bool clear) hash_langid_csum[2] == open_plugin_csum) { logf("OP update *Entry Exists* hash: %x langid: %d", - hash_langid_csum[0], (int32_t)hash_langid[1]); + hash_langid_csum[0], (int32_t)hash_langid_csum[1]); lseek(fd, 0-hlc_sz, SEEK_CUR);/* back to the start of record */ break; } @@ -261,7 +278,8 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p { open_plugin_entry.hash = hash; open_plugin_entry.lang_id = lang_id; - open_plugin_entry.checksum = open_plugin_csum; + open_plugin_entry.checksum = open_plugin_csum + + (lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY); /* name */ if (path_basename(plugin, (const char **)&pos) == 0) pos = "\0"; @@ -337,7 +355,7 @@ int open_plugin_get_entry(const char *key, struct open_plugin_entry_t *entry) opret = op_get_entry(hash, lang_id, entry, OPEN_PLUGIN_DAT); logf("OP entry hash: %x lang id: %d ret: %d key: %s", hash, lang_id, opret, skey); - if (opret == OPEN_PLUGIN_NOT_FOUND && lang_id > OPEN_PLUGIN_LANG_INVALID) + if (opret == OPEN_PLUGIN_NOT_FOUND && lang_id > OPEN_PLUGIN_LANG_INVALID) { /* try rb defaults */ opret = op_get_entry(hash, lang_id, entry, OPEN_RBPLUGIN_DAT); logf("OP rb_entry hash: %x lang id: %d ret: %d key: %s", hash, lang_id, opret, skey); @@ -364,6 +382,8 @@ int open_plugin_run(const char *key) if (param[0] == '\0') param = NULL; + if (path[0] == '\0' && key) + path = P2STR((unsigned char *)key); ret = plugin_load(path, param); diff --git a/apps/open_plugin.h b/apps/open_plugin.h index d16be2052c..62e3662849 100644 --- a/apps/open_plugin.h +++ b/apps/open_plugin.h @@ -40,8 +40,9 @@ enum { OPEN_PLUGIN_LANG_INVALID = (-1), OPEN_PLUGIN_LANG_IGNORE = (-2), OPEN_PLUGIN_LANG_IGNOREALL = (-3), - OPEN_PLUGIN_NOT_FOUND = (-1), - OPEN_PLUGIN_NEEDS_FLUSHED = (-2), + OPEN_PLUGIN_INVALID_ENTRY = (-1), + OPEN_PLUGIN_NOT_FOUND = (-2), + OPEN_PLUGIN_NEEDS_FLUSHED = (-3), }; struct open_plugin_entry_t 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) *nameptr = q; return r - q; } +static int op_entry_checksum(void) +{ + if (op_entry.checksum != open_plugin_csum + + (op_entry.lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY)) + { + return 0; + } + return 1; +} static bool op_entry_read(int fd, int selected_item, off_t data_sz) { @@ -94,7 +103,7 @@ static bool op_entry_read(int fd, int selected_item, off_t data_sz) op_entry.lang_id = -1; return ((selected_item >= 0) && (rb->lseek(fd, selected_item * op_entry_sz, SEEK_SET) >= 0) && - (rb->read(fd, &op_entry, data_sz) == data_sz)); + (rb->read(fd, &op_entry, data_sz) == data_sz) && op_entry_checksum() > 0); } static 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) return op_entry_read(fd, selected_item, op_name_sz); } -static int op_entry_checksum(void) -{ - if (op_entry.checksum != open_plugin_csum) - { - return 0; - } - return 1; -} - static int op_entry_read_opx(const char *path) { int ret = -1; @@ -174,7 +174,8 @@ failure: static void op_entry_set_checksum(void) { - op_entry.checksum = open_plugin_csum; + op_entry.checksum = open_plugin_csum + + (op_entry.lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY); } static void op_entry_set_name(void) @@ -466,7 +467,7 @@ static void op_entry_remove_empty(void) while (resave == false && rb->read(fd_dat, &op_entry, op_entry_sz) == op_entry_sz) { - if (op_entry.hash == 0) + if (op_entry.hash == 0 || !op_entry_checksum()) resave = true; } } @@ -839,6 +840,12 @@ reopen_datfile: }/* OP_EXT */ } + for (int i = items - 1; i > 0 && !exit; i--) + { + if (!op_entry_read(fd_dat, i, op_entry_sz)) + items--; + } + if (items < 1 && !exit) { char* cur_filename = rb->plugin_get_current_filename(); diff --git a/apps/root_menu.c b/apps/root_menu.c index ae3d1b39b0..c70237fdf7 100644 --- a/apps/root_menu.c +++ b/apps/root_menu.c @@ -730,6 +730,8 @@ static int load_plugin_screen(char *key) char *param = open_plugin_entry.param; if (param[0] == '\0') param = NULL; + if (path[0] == '\0' && key) + path = P2STR((unsigned char *)key); int ret = plugin_load(path, param); -- cgit v1.2.3