Skip to content

Commit

Permalink
Honor the LIBRETRO_DATABASE_DIRECTORY environment variable. (#17431)
Browse files Browse the repository at this point in the history
* Partially revert a change made in 69ceb95.

The change caused the 'libretro_directory' config option to always
revert to the default value, which was not intended behavior.

Reported-by: Michael Cook

* platform: Honor the LIBRETRO_DATABASE_DIRECTORY environment variable.

This is a follow-up to commit 69ceb95.

* frontend/drivers/platform_unix.c
(libretro_database_directory): New variable.
(frontend_unix_get_env): Set DEFAULT_DIR_DATABASE to the value of
the LIBRETRO_DATABASE_DIRECTORY environment variable, if available.
* frontend/drivers/platform_win32.c: Likewise.
* configuration.c (config_load_file)
<libretro_database_directory>: New variable. Use the values of
the LIBRETRO_DATABASE_DIRECTORY environment variables instead of their
corresponding configured values, when set.
* docs/retroarch.6: Document.
* retroarch.c (retroarch_print_help): List supported environment
variables, and cross-reference the man page.
  • Loading branch information
Apteryks authored Jan 19, 2025
1 parent 5db9b7f commit 274cd41
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
17 changes: 15 additions & 2 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -3571,6 +3571,7 @@ static bool config_load_file(global_t *global,
char* libretro_directory = NULL;
char* libretro_assets_directory = NULL;
char* libretro_autoconfig_directory = NULL;
char* libretro_database_directory = NULL;
char* libretro_system_directory = NULL;
char* libretro_video_filter_directory = NULL;
char* libretro_video_shader_directory = NULL;
Expand Down Expand Up @@ -3855,6 +3856,12 @@ static bool config_load_file(global_t *global,
strlcpy(path_settings[i].ptr, tmp_str, PATH_MAX_LENGTH);
}

#if !IOS
if (config_get_path(conf, "libretro_directory", tmp_str, sizeof(tmp_str)))
configuration_set_string(settings,
settings->paths.directory_libretro, tmp_str);
#endif

#ifdef RARCH_CONSOLE
if (conf)
video_driver_load_settings(global, conf);
Expand All @@ -3871,13 +3878,19 @@ static bool config_load_file(global_t *global,
}

libretro_autoconfig_directory = getenv("LIBRETRO_AUTOCONFIG_DIRECTORY");
if (libretro_autoconfig_directory)
if (libretro_autoconfig_directory) /* override configuration value */
configuration_set_string(settings,
settings->paths.directory_autoconfig,
libretro_autoconfig_directory);

libretro_database_directory = getenv("LIBRETRO_DATABASE_DIRECTORY");
if (libretro_database_directory) /* override configuration value */
configuration_set_string(settings,
settings->paths.path_content_database,
libretro_database_directory);

libretro_system_directory = getenv("LIBRETRO_SYSTEM_DIRECTORY");
if (libretro_system_directory)
if (libretro_system_directory) /* override configuration value */
configuration_set_string(settings,
settings->paths.directory_system,
libretro_system_directory);
Expand Down
8 changes: 7 additions & 1 deletion docs/retroarch.6
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.\" retroarch.6:

.TH "RETROARCH" "6" "January 16, 2025" "RETROARCH" "System Manager's Manual: retroarch"
.TH "RETROARCH" "6" "January 18, 2025" "RETROARCH" "System Manager's Manual: retroarch"

.SH NAME

Expand Down Expand Up @@ -261,6 +261,12 @@ Specify the directory where RetroArch looks for controller
auto-configuration files, overriding the value of the
"joypad_autoconfig_dir" configuration file option.

.TP
\fBLIBRETRO_DATABASE_DIRECTORY\fR
Specify the directory where RetroArch looks for database files,
overriding the value of the "content_database_path" configuration file
option.

.TP
\fBLIBRETRO_SYSTEM_DIRECTORY\fR
Specify the directory where RetroArch looks for system files,
Expand Down
10 changes: 8 additions & 2 deletions frontend/drivers/platform_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,7 @@ static void frontend_unix_get_env(int *argc,
const char* libretro_directory = getenv("LIBRETRO_DIRECTORY");
const char* libretro_assets_directory = getenv("LIBRETRO_ASSETS_DIRECTORY");
const char* libretro_autoconfig_directory = getenv("LIBRETRO_AUTOCONFIG_DIRECTORY");
const char* libretro_database_directory = getenv("LIBRETRO_DATABASE_DIRECTORY");
const char* libretro_system_directory = getenv("LIBRETRO_SYSTEM_DIRECTORY");
const char* libretro_video_filter_directory = getenv("LIBRETRO_VIDEO_FILTER_DIRECTORY");
const char* libretro_video_shader_directory = getenv("LIBRETRO_VIDEO_SHADER_DIRECTORY");
Expand Down Expand Up @@ -1889,8 +1890,13 @@ static void frontend_unix_get_env(int *argc,
"records_config", sizeof(g_defaults.dirs[DEFAULT_DIR_RECORD_CONFIG]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_RECORD_OUTPUT], base_path,
"records", sizeof(g_defaults.dirs[DEFAULT_DIR_RECORD_OUTPUT]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_DATABASE], base_path,
"database/rdb", sizeof(g_defaults.dirs[DEFAULT_DIR_DATABASE]));
if (!string_is_empty(libretro_database_directory))
strlcpy(g_defaults.dirs[DEFAULT_DIR_DATABASE],
libretro_database_directory,
sizeof(g_defaults.dirs[DEFAULT_DIR_DATABASE]));
else
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_DATABASE], base_path,
"database/rdb", sizeof(g_defaults.dirs[DEFAULT_DIR_DATABASE]));
if (!string_is_empty(libretro_video_shader_directory))
strlcpy(g_defaults.dirs[DEFAULT_DIR_SHADER],
libretro_video_shader_directory,
Expand Down
10 changes: 8 additions & 2 deletions frontend/drivers/platform_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ static void frontend_win32_env_get(int *argc, char *argv[],
const char *libretro_directory = getenv("LIBRETRO_DIRECTORY");
const char *libretro_assets_directory = getenv("LIBRETRO_ASSETS_DIRECTORY");
const char* libretro_autoconfig_directory = getenv("LIBRETRO_AUTOCONFIG_DIRECTORY");
const char* libretro_database_directory = getenv("LIBRETRO_DATABASE_DIRECTORY");
const char* libretro_system_directory = getenv("LIBRETRO_SYSTEM_DIRECTORY");
const char* libretro_video_filter_directory = getenv("LIBRETRO_VIDEO_FILTER_DIRECTORY");
const char* libretro_video_shader_directory = getenv("LIBRETRO_VIDEO_SHADER_DIRECTORY");
Expand Down Expand Up @@ -595,8 +596,13 @@ static void frontend_win32_env_get(int *argc, char *argv[],
":\\filters\\video", sizeof(g_defaults.dirs[DEFAULT_DIR_VIDEO_FILTER]));
fill_pathname_expand_special(g_defaults.dirs[DEFAULT_DIR_CHEATS],
":\\cheats", sizeof(g_defaults.dirs[DEFAULT_DIR_CHEATS]));
fill_pathname_expand_special(g_defaults.dirs[DEFAULT_DIR_DATABASE],
":\\database\\rdb", sizeof(g_defaults.dirs[DEFAULT_DIR_DATABASE]));
if (!string_is_empty(libretro_database_directory))
strlcpy(g_defaults.dirs[DEFAULT_DIR_DATABASE],
libretro_database_directory,
sizeof(g_defaults.dirs[DEFAULT_DIR_DATABASE]));
else
fill_pathname_expand_special(g_defaults.dirs[DEFAULT_DIR_DATABASE],
":\\database\\rdb", sizeof(g_defaults.dirs[DEFAULT_DIR_DATABASE]));
fill_pathname_expand_special(g_defaults.dirs[DEFAULT_DIR_PLAYLIST],
":\\playlists", sizeof(g_defaults.dirs[DEFAULT_DIR_PLAYLIST]));
fill_pathname_expand_special(g_defaults.dirs[DEFAULT_DIR_RECORD_CONFIG],
Expand Down
20 changes: 20 additions & 0 deletions retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -6519,7 +6519,27 @@ static void retroarch_print_help(const char *arg0)
"Path for the save state files (*.state). (DEPRECATED, use --appendconfig and savestate_directory)\n"
, sizeof(buf) - _len);

/* Flush buffer here to avoid the error "error: string length ‘752’
* is greater than the length ‘509’ ISO C90 compilers are required
* to support" */
fputs(buf, stdout);

#if defined(__linux__) || defined(__GNU__) || (defined(BSD) && !defined(__MACH__))
buf[0] = '\0';
_len = 0;
_len += strlcpy(buf + _len,
"\nThe following environment variables are supported:\n\n"
" LIBRETRO_ASSETS_DIRECTORY\n"
" LIBRETRO_AUTOCONFIG_DIRECTORY\n"
" LIBRETRO_DATABASE_DIRECTORY\n"
" LIBRETRO_DIRECTORY\n"
" LIBRETRO_SYSTEM_DIRECTORY\n"
" LIBRETRO_VIDEO_FILTER_DIRECTORY\n"
" LIBRETRO_VIDEO_SHADER_DIRECTORY\n\n"
"Refer to `man 6 retroarch' for a description of what they do.\n"
, sizeof(buf) - _len);
fputs(buf, stdout);
#endif
}

#ifdef HAVE_DYNAMIC
Expand Down

0 comments on commit 274cd41

Please sign in to comment.