summaryrefslogtreecommitdiffstats
path: root/apps/filetypes.c
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2021-10-21 00:03:52 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2021-10-21 01:45:47 -0400
commitaf573708ed7acf476ed49ff94243a94b27aa33a0 (patch)
treeef04b79dc016966431a35387f8d4496292f93d79 /apps/filetypes.c
parent9878226e4dec1ee7bb1434249214d6d8161b439f (diff)
downloadrockbox-af573708ed7acf476ed49ff94243a94b27aa33a0.tar.gz
rockbox-af573708ed7acf476ed49ff94243a94b27aa33a0.zip
extend filetype_get_plugin() search for viewer by fileext
I noticed the way filetree switch was modified for the lua (and then) opx and open plugin viewers since builtin files are assumed to be handled in the filetree switch what if instead filetype_get_plugin() could search the available viewers this could probably be extended further with selectable defaults Change-Id: I40f74cd698f4b788a0adcbebf32c08a970df29a5
Diffstat (limited to 'apps/filetypes.c')
-rw-r--r--apps/filetypes.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c
index 3724f57a9b..ed90be755f 100644
--- a/apps/filetypes.c
+++ b/apps/filetypes.c
@@ -536,10 +536,31 @@ char* filetype_get_plugin(const struct entry* file, char *buffer, size_t buffer_
int index = find_attr(file->attr);
if (index < 0 || !buffer)
return NULL;
- if (filetypes[index].plugin == NULL)
+ struct file_type *ft_indexed = &filetypes[index];
+
+ /* attempt to find a suitable viewer by file extension */
+ if(ft_indexed->plugin == NULL && ft_indexed->extension != NULL)
+ {
+ struct file_type *ft;
+ int i = filetype_count;
+ while (--i > index)
+ {
+ ft = &filetypes[i];
+ if (ft->plugin == NULL || ft->extension == NULL)
+ continue;
+ else if (strcmp(ft->extension, ft_indexed->extension) == 0)
+ {
+ /*splashf(HZ*3, "Found %d %s %s", i, ft->extension, ft->plugin);*/
+ ft_indexed = ft;
+ break;
+ }
+ }
+ }
+ if (ft_indexed->plugin == NULL)
return NULL;
- snprintf(buffer, buffer_len, "%s/%s.%s",
- PLUGIN_DIR, filetypes[index].plugin, ROCK_EXTENSION);
+
+ snprintf(buffer, buffer_len, "%s/%s." ROCK_EXTENSION,
+ PLUGIN_DIR, ft_indexed->plugin);
return buffer;
}
@@ -573,8 +594,8 @@ static int openwith_get_talk(int selected_item, void * data)
{
(void)data;
char viewer_filename[MAX_FILENAME];
- snprintf(viewer_filename, MAX_FILENAME, "%s.%s",
- filetypes[viewers[selected_item]].plugin, ROCK_EXTENSION);
+ snprintf(viewer_filename, MAX_FILENAME, "%s." ROCK_EXTENSION,
+ filetypes[viewers[selected_item]].plugin);
talk_file_or_spell(PLUGIN_DIR, viewer_filename,
NULL, false);
return 0;
@@ -588,8 +609,8 @@ static int openwith_action_callback(int action, struct gui_synclist *lists)
{
char plugin[MAX_PATH];
i = viewers[gui_synclist_get_sel_pos(lists)];
- snprintf(plugin, MAX_PATH, "%s/%s.%s",
- PLUGIN_DIR, filetypes[i].plugin, ROCK_EXTENSION);
+ snprintf(plugin, MAX_PATH, "%s/%s." ROCK_EXTENSION,
+ PLUGIN_DIR, filetypes[i].plugin);
plugin_load(plugin, info->current_file);
return ACTION_STD_CANCEL;
}
@@ -630,7 +651,7 @@ int filetype_load_plugin(const char* plugin, const char* file)
}
if (i >= filetype_count)
return PLUGIN_ERROR;
- snprintf(plugin_name, MAX_PATH, "%s/%s.%s",
- PLUGIN_DIR, filetypes[i].plugin, ROCK_EXTENSION);
+ snprintf(plugin_name, MAX_PATH, "%s/%s." ROCK_EXTENSION,
+ PLUGIN_DIR, filetypes[i].plugin);
return plugin_load(plugin_name, file);
}