From f46550bd7ce7347a4edef163390546a351f84d0d Mon Sep 17 00:00:00 2001 From: sonninnos <45124675+sonninnos@users.noreply.github.com> Date: Sun, 22 Jan 2023 14:03:10 +0200 Subject: [PATCH] Ignore system subdir replacement if subdir has subdirs (#14887) --- menu/cbs/menu_cbs_ok.c | 5 +++++ runloop.c | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 0e3d97b821..9f1baa8dc7 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -2270,6 +2270,11 @@ static int default_action_ok_load_content_with_core_from_menu(const char *_path, content_info.argv = NULL; content_info.args = NULL; content_info.environ_get = NULL; + + /* Clear playlist cache to avoid stale data when + * getting SYSTEM dir on launch via 'Load Content' */ + playlist_free_cached(); + if (!task_push_load_content_with_core( _path, &content_info, (enum rarch_core_type)_type, NULL, NULL)) diff --git a/runloop.c b/runloop.c index ecbcb59180..5b8ecf685e 100644 --- a/runloop.c +++ b/runloop.c @@ -86,6 +86,7 @@ #include #include #include +#include #ifdef EMSCRIPTEN #include @@ -1984,13 +1985,43 @@ bool runloop_environment_cb(unsigned cmd, void *data) if ( system_info && !string_is_empty(system_info->library_name)) { + bool entry_is_dir = false; + fill_pathname_join(dir_system_subdir, dir_system, system_info->library_name, sizeof(dir_system_subdir)); - RARCH_DBG("[Environ]: SYSTEM_DIRECTORY candidate: \"%s\".\n", - dir_system_subdir); + /* Inspect if the subdir has dirs under it, and ignore + * it if so. Because for example PPSSPP already uses a + * subdir named after 'library_name', so it would have + * to be 'system/PPSSPP/PPSSPP' otherwise. */ + if (path_is_valid(dir_system_subdir)) + { + struct RDIR *entry = retro_opendir(dir_system_subdir); + if (entry) + { + while (retro_readdir(entry)) + { + const char *entry_name = retro_dirent_get_name(entry); + if (strstr(entry_name, ".")) + continue; + + if (retro_dirent_is_dir(entry, NULL)) + { + entry_is_dir = true; + break; + } + } + retro_closedir(entry); + } + } + + if (entry_is_dir) + dir_system_subdir[0] = '\0'; + else + RARCH_DBG("[Environ]: SYSTEM_DIRECTORY candidate: \"%s\".\n", + dir_system_subdir); } #ifdef HAVE_MENU