From a53680a57eca4fea1fbaae45c352412e786335a1 Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 4 Oct 2013 17:33:21 +0200 Subject: [PATCH 1/2] Resolve libretro core names in RGUI. --- frontend/menu/menu_common.c | 19 +++++++++++++++++ frontend/menu/rgui.c | 36 +++++++++++++++++++++++++++++++++ frontend/menu/rguidisp_bitmap.c | 19 +++++++++++++++++ frontend/menu/utils/file_list.h | 5 +++++ 4 files changed, 79 insertions(+) diff --git a/frontend/menu/menu_common.c b/frontend/menu/menu_common.c index c5dfd931c8..9035ac9391 100644 --- a/frontend/menu/menu_common.c +++ b/frontend/menu/menu_common.c @@ -189,6 +189,7 @@ void shader_manager_get_str(struct gfx_shader *shader, struct rgui_file { char *path; + char *alt; unsigned type; size_t directory_ptr; }; @@ -209,6 +210,7 @@ void rgui_list_push(void *userdata, } list->list[list->size].path = strdup(path); + list->list[list->size].alt = NULL; list->list[list->size].type = type; list->list[list->size].directory_ptr = directory_ptr; list->size++; @@ -234,10 +236,27 @@ void rgui_list_free(rgui_list_t *list) void rgui_list_clear(rgui_list_t *list) { for (size_t i = 0; i < list->size; i++) + { free(list->list[i].path); + free(list->list[i].alt); + } list->size = 0; } +void rgui_list_set_alt_at_offset(rgui_list_t *list, size_t index, + const char *alt) +{ + free(list->list[index].alt); + list->list[index].alt = strdup(alt); +} + +void rgui_list_get_alt_at_offset(const rgui_list_t *list, size_t index, + const char **alt) +{ + if (alt) + *alt = list->list[index].alt ? list->list[index].alt : list->list[index].path; +} + void rgui_list_get_at_offset(const rgui_list_t *list, size_t index, const char **path, unsigned *file_type) { diff --git a/frontend/menu/rgui.c b/frontend/menu/rgui.c index 38b34833ec..766bd3c1b6 100644 --- a/frontend/menu/rgui.c +++ b/frontend/menu/rgui.c @@ -200,6 +200,37 @@ static int rgui_core_setting_toggle(unsigned setting, rgui_action_t action) return 0; } +#ifdef HAVE_DYNAMIC +static void rgui_resolve_libretro_names(rgui_list_t *list, const char *dir) +{ + for (size_t i = 0; i < list->size; i++) + { + const char *path; + unsigned type = 0; + rgui_list_get_at_offset(list, i, &path, &type); + + char core_path[PATH_MAX]; + fill_pathname_join(core_path, dir, path, sizeof(core_path)); + + if (type != RGUI_FILE_PLAIN) + continue; + + // TODO: If we standardize on .info files later, we could use them here perhaps. + + struct retro_system_info info = {0}; + // Have to employ some heuristics on which cores to load. + // Loading arbitrary libraries is dangerous (some libs can crash in global constructors ...) + if (strstr(path, "retro") && libretro_get_system_info(core_path, &info, NULL)) + { + char desc[256]; + snprintf(desc, sizeof(desc), "%s %s", info.library_name, info.library_version); + libretro_free_system_info(&info); + rgui_list_set_alt_at_offset(rgui->selection_buf, i, desc); + } + } +} +#endif + static int rgui_settings_toggle_setting(rgui_handle_t *rgui, unsigned setting, rgui_action_t action, unsigned menu_type) { #ifdef HAVE_SHADER_MANAGER @@ -1314,6 +1345,11 @@ static int rgui_iterate(void *data, unsigned action) else rgui_directory_parse(rgui, dir, menu_type, rgui->selection_buf); +#ifdef HAVE_DYNAMIC + if (menu_type == RGUI_SETTINGS_CORE) + rgui_resolve_libretro_names(rgui->selection_buf, dir); +#endif + // Before a refresh, we could have deleted a file on disk, causing // selection_ptr to suddendly be out of range. Ensure it doesn't overflow. if (rgui->selection_ptr >= rgui->selection_buf->size && rgui->selection_buf->size) diff --git a/frontend/menu/rguidisp_bitmap.c b/frontend/menu/rguidisp_bitmap.c index 1a26173a96..8b9332801d 100644 --- a/frontend/menu/rguidisp_bitmap.c +++ b/frontend/menu/rguidisp_bitmap.c @@ -359,6 +359,25 @@ static void render_text(rgui_handle_t *rgui) shader_manager_get_str(&rgui->shader, type_str, sizeof(type_str), type); } else +#endif +#ifdef HAVE_DYNAMIC + // Pretty-print libretro cores from menu. + if (menu_type == RGUI_SETTINGS_CORE) + { + if (type == RGUI_FILE_PLAIN) + { + strlcpy(type_str, "(CORE)", sizeof(type_str)); + rgui_list_get_alt_at_offset(rgui->selection_buf, i, &path); + w = 6; + } + else + { + strlcpy(type_str, "(DIR)", sizeof(type_str)); + type = RGUI_FILE_DIRECTORY; + w = 5; + } + } + else #endif if (menu_type == RGUI_SETTINGS_CORE || menu_type == RGUI_SETTINGS_CONFIG || diff --git a/frontend/menu/utils/file_list.h b/frontend/menu/utils/file_list.h index c482f0e5aa..62fb8cc1db 100644 --- a/frontend/menu/utils/file_list.h +++ b/frontend/menu/utils/file_list.h @@ -43,6 +43,11 @@ void rgui_list_get_last(const rgui_list_t *list, void rgui_list_get_at_offset(const rgui_list_t *list, size_t index, const char **path, unsigned *type); +void rgui_list_set_alt_at_offset(rgui_list_t *list, size_t index, + const char *alt); +void rgui_list_get_alt_at_offset(const rgui_list_t *list, size_t index, + const char **alt); + #ifdef __cplusplus } #endif From 091a6379eb4e84a44d95d693f3f59b557c0654aa Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 4 Oct 2013 18:10:03 +0200 Subject: [PATCH 2/2] Use info files to resolve libretro names. --- frontend/menu/rgui.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/frontend/menu/rgui.c b/frontend/menu/rgui.c index 766bd3c1b6..20e07b24a9 100644 --- a/frontend/menu/rgui.c +++ b/frontend/menu/rgui.c @@ -200,7 +200,6 @@ static int rgui_core_setting_toggle(unsigned setting, rgui_action_t action) return 0; } -#ifdef HAVE_DYNAMIC static void rgui_resolve_libretro_names(rgui_list_t *list, const char *dir) { for (size_t i = 0; i < list->size; i++) @@ -208,28 +207,24 @@ static void rgui_resolve_libretro_names(rgui_list_t *list, const char *dir) const char *path; unsigned type = 0; rgui_list_get_at_offset(list, i, &path, &type); - - char core_path[PATH_MAX]; - fill_pathname_join(core_path, dir, path, sizeof(core_path)); - if (type != RGUI_FILE_PLAIN) continue; - // TODO: If we standardize on .info files later, we could use them here perhaps. + char core_path[PATH_MAX]; + fill_pathname_join(core_path, dir, path, sizeof(core_path)); + char info_path[PATH_MAX]; + fill_pathname(info_path, core_path, ".info", sizeof(info_path)); - struct retro_system_info info = {0}; - // Have to employ some heuristics on which cores to load. - // Loading arbitrary libraries is dangerous (some libs can crash in global constructors ...) - if (strstr(path, "retro") && libretro_get_system_info(core_path, &info, NULL)) - { - char desc[256]; - snprintf(desc, sizeof(desc), "%s %s", info.library_name, info.library_version); - libretro_free_system_info(&info); - rgui_list_set_alt_at_offset(rgui->selection_buf, i, desc); - } + config_file_t *conf = config_file_new(info_path); + if (!conf) + continue; + + char display_name[256]; + if (config_get_array(conf, "display_name", display_name, sizeof(display_name))) + rgui_list_set_alt_at_offset(list, i, display_name); + config_file_free(conf); } } -#endif static int rgui_settings_toggle_setting(rgui_handle_t *rgui, unsigned setting, rgui_action_t action, unsigned menu_type) { @@ -1345,10 +1340,8 @@ static int rgui_iterate(void *data, unsigned action) else rgui_directory_parse(rgui, dir, menu_type, rgui->selection_buf); -#ifdef HAVE_DYNAMIC if (menu_type == RGUI_SETTINGS_CORE) rgui_resolve_libretro_names(rgui->selection_buf, dir); -#endif // Before a refresh, we could have deleted a file on disk, causing // selection_ptr to suddendly be out of range. Ensure it doesn't overflow.