Skip to content

Commit

Permalink
configuration: Have environment variables override configuration.
Browse files Browse the repository at this point in the history
Because the configuration file is systematically written when
RetroArch terminates, persisting any previous default/configured
value, setting the LIBRETRO_DIRECTORY and LIBRETRO_ASSETS_DIRECTORY
environment variables would not have an effect unless the
retroarch.cfg configuration file was cleared.

This seems to go against the common expectation that environment
variables are set by users to *override* the default behavior or
configuration of an application.

* configuration.c (config_load_file) <libretro_directory>
<libretro_assets_directory>: New variables. Use the values of the
LIBRETRO_DIRECTORY and LIBRETRO_ASSETS_DIRECTORY environment variable
instead of their corresponding configurated values, when set.
* docs/retroarch.6: Document the environment varibales honored and
their behavior.
  • Loading branch information
Apteryks committed Sep 27, 2024
1 parent b5ac44e commit 08828a2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
14 changes: 12 additions & 2 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -3573,6 +3573,8 @@ static bool config_load_file(global_t *global,
{
unsigned i;
char tmp_str[PATH_MAX_LENGTH];
char* libretro_directory = NULL;
char* libretro_assets_directory = NULL;
static bool first_load = true;
bool without_overrides = false;
unsigned msg_color = 0;
Expand Down Expand Up @@ -3849,7 +3851,11 @@ static bool config_load_file(global_t *global,
}

#if !IOS
if (config_get_path(conf, "libretro_directory", tmp_str, sizeof(tmp_str)))
libretro_directory = getenv("LIBRETRO_DIRECTORY");
if (libretro_directory) { /* override the configured value */
configuration_set_string(settings,
settings->paths.directory_libretro, libretro_directory);
} else if (config_get_path(conf, "libretro_directory", tmp_str, sizeof(tmp_str)))
configuration_set_string(settings,
settings->paths.directory_libretro, tmp_str);
#endif
Expand Down Expand Up @@ -4040,7 +4046,11 @@ static bool config_load_file(global_t *global,
*settings->paths.directory_audio_filter = '\0';
if (string_is_equal(settings->paths.directory_core_assets, "default"))
*settings->paths.directory_core_assets = '\0';
if (string_is_equal(settings->paths.directory_assets, "default"))
libretro_assets_directory = getenv("LIBRETRO_ASSETS_DIRECTORY");
if (libretro_assets_directory) { /* override the configure value */
configuration_set_string(settings,
settings->paths.directory_assets, libretro_assets_directory);
} else if (string_is_equal(settings->paths.directory_assets, "default"))
*settings->paths.directory_assets = '\0';
#ifdef _3DS
if (string_is_equal(settings->paths.directory_bottom_assets, "default"))
Expand Down
14 changes: 13 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" "November 1, 2011" "RETROARCH" "System Manager's Manual: retroarch"
.TH "RETROARCH" "6" "September 28, 2024" "RETROARCH" "System Manager's Manual: retroarch"

.SH NAME

Expand Down Expand Up @@ -239,3 +239,15 @@ Disables all kinds of content patching.
.TP
\fB-D, --detach\fR
Detach from the current console. This is currently only relevant for Microsoft Windows.

.SH ENVIRONMENT
\fBretroarch\fR supports the following environment variables:
.TP
\fBLIBRETRO_DIRECTORY\fR
Specify the directory where RetroArch looks for its core files. It
overrides the value of the "libretro_directory" configuration file option.
.TP
\fBLIBRETRO_ASSETS_DIRECTORY\fR
Specify the directory where RetroArch looks to find its assets. It
overrides the value of the "assets_directory" configuration file
option.

0 comments on commit 08828a2

Please sign in to comment.