From 08828a2d9e7112a3f04affc20c1a49f36636457e Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Sat, 28 Sep 2024 00:23:36 +0900 Subject: [PATCH] configuration: Have environment variables override configuration. 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) : 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. --- configuration.c | 14 ++++++++++++-- docs/retroarch.6 | 14 +++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/configuration.c b/configuration.c index 5808a3f21c55..5d1913ebf31a 100644 --- a/configuration.c +++ b/configuration.c @@ -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; @@ -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 @@ -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")) diff --git a/docs/retroarch.6 b/docs/retroarch.6 index 7478040e176a..fa36cb8bd6e1 100644 --- a/docs/retroarch.6 +++ b/docs/retroarch.6 @@ -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 @@ -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.