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, LIBRETRO_ASSETS_DIRECTORY, etc.
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, libretro_autoconfig_directory>
<libretro_video_filter_directory, libretro_video_shader_directory> :
New variables. Use the values of the LIBRETRO_DIRECTORY,
LIBRETRO_ASSETS_DIRECTORY,
LIBRETRO_AUTOCONFIG_DIRECTORY, LIBRETRO_VIDEO_FILTER_DIRECTORY
and LIBRETRO_VIDEO_SHADER_DIRECTORY environment variables
instead of their corresponding configured values, when set.
* docs/retroarch.6: Document the environment variables honored and
their behavior.
  • Loading branch information
Apteryks committed Oct 2, 2024
1 parent 97c87dc commit b03edd7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 10 deletions.
43 changes: 34 additions & 9 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -3573,6 +3573,11 @@ 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;
char* libretro_autoconfig_directory = NULL;
char* libretro_video_filter_directory = NULL;
char* libretro_video_shader_directory = NULL;
static bool first_load = true;
bool without_overrides = false;
unsigned msg_color = 0;
Expand Down Expand Up @@ -3848,19 +3853,27 @@ 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);
#endif

/* Post-settings load */

libretro_directory = getenv("LIBRETRO_DIRECTORY");
if (libretro_directory) {
configuration_set_string(settings,
settings->paths.directory_libretro, libretro_directory);
configuration_set_string(settings,
settings->paths.path_libretro_info, libretro_directory);
}

libretro_autoconfig_directory = getenv("LIBRETRO_AUTOCONFIG_DIRECTORY");
if (libretro_autoconfig_directory)
configuration_set_string(settings,
settings->paths.directory_autoconfig,
libretro_autoconfig_directory);

if ( (rarch_flags & RARCH_FLAGS_HAS_SET_USERNAME)
&& (override_username))
{
Expand Down Expand Up @@ -4032,15 +4045,27 @@ static bool config_load_file(global_t *global,
*settings->paths.path_menu_wallpaper = '\0';
if (string_is_equal(settings->paths.path_rgui_theme_preset, "default"))
*settings->paths.path_rgui_theme_preset = '\0';
if (string_is_equal(settings->paths.directory_video_shader, "default"))
libretro_video_shader_directory = getenv("LIBRETRO_VIDEO_SHADER_DIRECTORY");
if (libretro_video_shader_directory) { /* override configuration value */
configuration_set_string(settings, settings->paths.directory_video_shader,
libretro_video_shader_directory);
} else if (string_is_equal(settings->paths.directory_video_shader, "default"))
*settings->paths.directory_video_shader = '\0';
if (string_is_equal(settings->paths.directory_video_filter, "default"))
libretro_video_filter_directory = getenv("LIBRETRO_VIDEO_FILTER_DIRECTORY");
if (libretro_video_filter_directory) { /* override configuration value */
configuration_set_string(settings, settings->paths.directory_video_filter,
libretro_video_filter_directory);
} else if (string_is_equal(settings->paths.directory_video_filter, "default"))
*settings->paths.directory_video_filter = '\0';
if (string_is_equal(settings->paths.directory_audio_filter, "default"))
*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 configuration 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
35 changes: 34 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,36 @@ 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 honors the following environment variables:

.TP
\fBLIBRETRO_DIRECTORY\fR
Specify the directory where RetroArch looks for core and info files,
overriding the value of the "libretro_directory" configuration file
option.

.TP
\fBLIBRETRO_ASSETS_DIRECTORY\fR
Specify the directory where RetroArch looks for assets, overriding
the value of the "assets_directory" configuration file
option.

.TP
\fBLIBRETRO_AUTOCONFIG_DIRECTORY\fR
Specify the directory where RetroArch looks for controller
auto-configuration files, overriding the value of the
"joypad_autoconfig_dir" configuration file option.

.TP
\fBLIBRETRO_VIDEO_FILTER_DIRECTORY\fR
Specify the directory where RetroArch looks for video filters,
overriding the value of the "video_filter_dir" configuration file
option.

.TP
\fBLIBRETRO_VIDEO_SHADER_DIRECTORY\fR
Specify the directory where RetroArch looks for video shaders,
overriding the value of the "video_shader_dir" configuration file
option.

0 comments on commit b03edd7

Please sign in to comment.