From 3572461d31ea8cfadd3659029847db298a40c359 Mon Sep 17 00:00:00 2001 From: Bobby Smith <33353403+bslenul@users.noreply.github.com> Date: Sun, 28 Jan 2024 18:57:34 +0100 Subject: [PATCH] Improvements to firmware checks when "System Files are in Content Directory" is enabled (#16170) --- intl/msg_hash_us.h | 8 +++++++ menu/menu_displaylist.c | 47 ++++++++++++++++++++++++++++++++++++++--- msg_hash.h | 2 ++ runloop.c | 9 +++++++- 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index e299152890..e7237165ca 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -527,6 +527,14 @@ MSG_HASH( MENU_ENUM_LABEL_VALUE_CORE_INFO_FIRMWARE, "Firmware" ) +MSG_HASH( + MENU_ENUM_LABEL_VALUE_CORE_INFO_FIRMWARE_IN_CONTENT_DIRECTORY, + "- Note: 'System Files are in Content Directory' is currently enabled." + ) +MSG_HASH( + MENU_ENUM_LABEL_VALUE_CORE_INFO_FIRMWARE_PATH, + "- Looking in: '%s'" + ) MSG_HASH( MENU_ENUM_LABEL_VALUE_MISSING_REQUIRED, "Missing, Required:" diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index ae81c446da..9f4500e570 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -709,11 +709,33 @@ static int menu_displaylist_parse_core_info( if (core_info->firmware_count > 0) { core_info_ctx_firmware_t firmware_info; - bool update_missing_firmware = false; - bool set_missing_firmware = false; + uint8_t flags = content_get_flags(); + bool update_missing_firmware = false; + bool set_missing_firmware = false; + bool systemfiles_in_content_dir = settings->bools.systemfiles_in_content_dir; + bool content_is_inited = flags & CONTENT_ST_FLAG_IS_INITED; + char tmp_path[PATH_MAX_LENGTH]; firmware_info.path = core_info->path; - firmware_info.directory.system = settings->paths.directory_system; + + /* If 'System Files are in Content Directory' is enabled and content is inited, + * adjust the path to check for firmware files */ + if (systemfiles_in_content_dir && content_is_inited) + { + size_t len; + + strlcpy(tmp_path, path_get(RARCH_PATH_CONTENT), sizeof(tmp_path)); + path_basedir(tmp_path); + + /* Removes trailing slash, doesn't really matter but it's more consistent with how + * the path is stored and displayed without 'System Files are in Content Directory' */ + len = strlen(tmp_path); + if (tmp_path[len - 1] == PATH_DEFAULT_SLASH_C()) + tmp_path[len - 1] = '\0'; + firmware_info.directory.system = tmp_path; + } + else + firmware_info.directory.system = settings->paths.directory_system; update_missing_firmware = core_info_list_update_missing_firmware(&firmware_info, &set_missing_firmware); @@ -740,6 +762,25 @@ static int menu_displaylist_parse_core_info( MENU_ENUM_LABEL_CORE_INFO_ENTRY, MENU_SETTINGS_CORE_INFO_NONE, 0, 0, NULL)) count++; + /* If 'System Files are in Content Directory' is enabled, let's add a note about it. */ + if (systemfiles_in_content_dir) + { + len = strlcpy(tmp, + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CORE_INFO_FIRMWARE_IN_CONTENT_DIRECTORY), + sizeof(tmp)); + if (menu_entries_append(list, tmp, "", + MENU_ENUM_LABEL_CORE_INFO_ENTRY, MENU_SETTINGS_CORE_INFO_NONE, 0, 0, NULL)) + count++; + } + + /* Show the path that was checked */ + len = snprintf(tmp, sizeof(tmp), + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CORE_INFO_FIRMWARE_PATH), + firmware_info.directory.system); + if (menu_entries_append(list, tmp, "", + MENU_ENUM_LABEL_CORE_INFO_ENTRY, MENU_SETTINGS_CORE_INFO_NONE, 0, 0, NULL)) + count++; + len = strlcpy(tmp, "(!) ", sizeof(tmp)); /* FIXME: This looks hacky and probably diff --git a/msg_hash.h b/msg_hash.h index 76c3a185b0..b56852f322 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -3366,6 +3366,8 @@ enum msg_hash_enums MENU_ENUM_LABEL_VALUE_CORE_INFO_LICENSES, MENU_ENUM_LABEL_VALUE_CORE_INFO_SUPPORTED_EXTENSIONS, MENU_ENUM_LABEL_VALUE_CORE_INFO_FIRMWARE, + MENU_ENUM_LABEL_VALUE_CORE_INFO_FIRMWARE_IN_CONTENT_DIRECTORY, + MENU_ENUM_LABEL_VALUE_CORE_INFO_FIRMWARE_PATH, MENU_ENUM_LABEL_VALUE_CORE_INFO_REQUIRED_HW_API, MENU_ENUM_LABEL_VALUE_CORE_INFO_SAVESTATE_SUPPORT_LEVEL, diff --git a/runloop.c b/runloop.c index 5d781aca91..5b59d614fb 100644 --- a/runloop.c +++ b/runloop.c @@ -1971,6 +1971,7 @@ bool runloop_environment_cb(unsigned cmd, void *data) if (!string_is_empty(fullpath)) { + size_t len; char tmp_path[PATH_MAX_LENGTH]; if (string_is_empty(dir_system)) @@ -1979,12 +1980,18 @@ bool runloop_environment_cb(unsigned cmd, void *data) strlcpy(tmp_path, fullpath, sizeof(tmp_path)); path_basedir(tmp_path); + + /* Removes trailing slash */ + len = strlen(tmp_path); + if (tmp_path[len - 1] == PATH_DEFAULT_SLASH_C()) + tmp_path[len - 1] = '\0'; + dir_set(RARCH_DIR_SYSTEM, tmp_path); } *(const char**)data = dir_get_ptr(RARCH_DIR_SYSTEM); RARCH_LOG("[Environ]: SYSTEM_DIRECTORY: \"%s\".\n", - dir_system); + *(const char**)data); } else {