Skip to content

Commit

Permalink
Fall back to global system dir for contentless cores when 'System Fil…
Browse files Browse the repository at this point in the history
…es are in Content Directory' is enabled
  • Loading branch information
bslenul committed Jan 30, 2024
1 parent 25317c3 commit 9a1e5f9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
23 changes: 17 additions & 6 deletions menu/menu_displaylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ static int menu_displaylist_parse_core_info(
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;
bool core_does_not_need_content = flags & CONTENT_ST_FLAG_CORE_DOES_NOT_NEED_CONTENT;
char tmp_path[PATH_MAX_LENGTH];

firmware_info.path = core_info->path;
Expand All @@ -727,12 +728,22 @@ static int menu_displaylist_parse_core_info(
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;
/* If core can run contentless and content path is empty,
* fall back to global system dir path */
if (string_is_empty(tmp_path) && core_does_not_need_content)
firmware_info.directory.system = settings->paths.directory_system;
else
{
size_t len = strlen(tmp_path);

/* Removes trailing slash (unless root dir), doesn't really matter
* but it's more consistent with how the path is stored and
* displayed without 'System Files are in Content Directory' */
if ( string_count_occurrences_single_character(tmp_path, PATH_DEFAULT_SLASH_C()) > 1
&& 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;
Expand Down
28 changes: 20 additions & 8 deletions runloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1961,35 +1961,47 @@ bool runloop_environment_cb(unsigned cmd, void *data)

case RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY:
{
uint8_t flags = content_get_flags();
const char *dir_system = settings->paths.directory_system;
bool dir_system_is_empty = string_is_empty(dir_system);
bool systemfiles_in_content_dir = settings->bools.systemfiles_in_content_dir;
bool core_does_not_need_content = flags & CONTENT_ST_FLAG_CORE_DOES_NOT_NEED_CONTENT;

if ( string_is_empty(dir_system)
|| systemfiles_in_content_dir)
if (dir_system_is_empty || systemfiles_in_content_dir)
{
const char *fullpath = path_get(RARCH_PATH_CONTENT);
const char *fullpath = path_get(RARCH_PATH_CONTENT);
bool fullpath_is_empty = string_is_empty(fullpath);

if (!string_is_empty(fullpath))
if (!fullpath_is_empty)
{
size_t len;
char tmp_path[PATH_MAX_LENGTH];

if (string_is_empty(dir_system))
if (dir_system_is_empty)
RARCH_WARN("[Environ]: SYSTEM DIR is empty, assume CONTENT DIR %s\n",
fullpath);

strlcpy(tmp_path, fullpath, sizeof(tmp_path));
path_basedir(tmp_path);

/* Removes trailing slash */
/* Removes trailing slash (unless root dir) */
len = strlen(tmp_path);
if (tmp_path[len - 1] == PATH_DEFAULT_SLASH_C())
if ( string_count_occurrences_single_character(tmp_path, PATH_DEFAULT_SLASH_C()) > 1
&& 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);
/* If core can run contentless and content path is empty,
* fall back to global system dir path if set */
if ( !dir_system_is_empty
&& fullpath_is_empty
&& core_does_not_need_content)
*(const char**)data = dir_system;
else
*(const char**)data = dir_get_ptr(RARCH_DIR_SYSTEM);

RARCH_LOG("[Environ]: SYSTEM_DIRECTORY: \"%s\".\n",
*(const char**)data);
}
Expand Down

0 comments on commit 9a1e5f9

Please sign in to comment.