Skip to content

Commit

Permalink
Merge pull request #3556 from Sonicadvance1/move_app_config
Browse files Browse the repository at this point in the history
FEXCore: Fixes priority of FEX_APP_CONFIG
  • Loading branch information
Sonicadvance1 authored Apr 5, 2024
2 parents c43af8e + 904646e commit 7786c23
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
3 changes: 2 additions & 1 deletion FEXCore/Source/Interface/Config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,15 @@ namespace DefaultValues {
static fextl::map<FEXCore::Config::LayerType, fextl::unique_ptr<FEXCore::Config::Layer>> ConfigLayers;
static FEXCore::Config::Layer *Meta{};

constexpr std::array<FEXCore::Config::LayerType, 9> LoadOrder = {
constexpr std::array<FEXCore::Config::LayerType, 10> LoadOrder = {
FEXCore::Config::LayerType::LAYER_GLOBAL_MAIN,
FEXCore::Config::LayerType::LAYER_MAIN,
FEXCore::Config::LayerType::LAYER_GLOBAL_STEAM_APP,
FEXCore::Config::LayerType::LAYER_GLOBAL_APP,
FEXCore::Config::LayerType::LAYER_LOCAL_STEAM_APP,
FEXCore::Config::LayerType::LAYER_LOCAL_APP,
FEXCore::Config::LayerType::LAYER_ARGUMENTS,
FEXCore::Config::LayerType::LAYER_USER_OVERRIDE,
FEXCore::Config::LayerType::LAYER_ENVIRONMENT,
FEXCore::Config::LayerType::LAYER_TOP
};
Expand Down
1 change: 1 addition & 0 deletions FEXCore/include/FEXCore/Config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace Handler {
LAYER_GLOBAL_APP,
LAYER_LOCAL_STEAM_APP,
LAYER_LOCAL_APP,
LAYER_USER_OVERRIDE,
LAYER_ENVIRONMENT,
LAYER_TOP,
};
Expand Down
33 changes: 18 additions & 15 deletions Source/Common/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ namespace JSON {
public:
explicit MainLoader(FEXCore::Config::LayerType Type);
explicit MainLoader(fextl::string ConfigFile);
explicit MainLoader(FEXCore::Config::LayerType Type, const char* ConfigFile);

void Load() override;

private:
Expand Down Expand Up @@ -188,6 +190,12 @@ namespace JSON {
, Config{std::move(ConfigFile)} {
}


MainLoader::MainLoader(FEXCore::Config::LayerType Type, const char* ConfigFile)
: OptionMapper(Type)
, Config{ConfigFile} {
}

void MainLoader::Load() {
JSON::LoadJSonConfig(Config, [this](const char *Name, const char *ConfigString) {
MapNameToOption(Name, ConfigString);
Expand Down Expand Up @@ -276,6 +284,10 @@ namespace JSON {
}
}

fextl::unique_ptr<FEXCore::Config::Layer> CreateUserOverrideLayer(const char* AppConfig) {
return fextl::make_unique<MainLoader>(FEXCore::Config::LayerType::LAYER_USER_OVERRIDE, AppConfig);
}

fextl::unique_ptr<FEXCore::Config::Layer> CreateAppLayer(const fextl::string& Filename, FEXCore::Config::LayerType Type) {
return fextl::make_unique<AppLoader>(Filename, Type);
}
Expand Down Expand Up @@ -371,6 +383,11 @@ namespace JSON {
FEXCore::Config::AddLayer(fextl::make_unique<FEX::ArgLoader::ArgLoader>(argc, argv));
}

const char *AppConfig = getenv("FEX_APP_CONFIG");
if (AppConfig && FHU::Filesystem::Exists(AppConfig)) {
FEXCore::Config::AddLayer(CreateUserOverrideLayer(AppConfig));
}

FEXCore::Config::AddLayer(CreateEnvironmentLayer(envp));
FEXCore::Config::Load();

Expand Down Expand Up @@ -529,21 +546,7 @@ namespace JSON {
}

fextl::string GetConfigFileLocation(bool Global) {
fextl::string ConfigFile{};
if (Global) {
ConfigFile = GetConfigDirectory(true) + "Config.json";
}
else {
const char *AppConfig = getenv("FEX_APP_CONFIG");
if (AppConfig) {
// App config environment variable overwrites only the config file
ConfigFile = AppConfig;
}
else {
ConfigFile = GetConfigDirectory(false) + "Config.json";
}
}
return ConfigFile;
return GetConfigDirectory(Global) + "Config.json";
}

void InitializeConfigs() {
Expand Down
1 change: 1 addition & 0 deletions Source/Common/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ namespace FEX::Config {
* @return unique_ptr for that layer
*/
fextl::unique_ptr<FEXCore::Config::Layer> CreateMainLayer(fextl::string const *File = nullptr);
fextl::unique_ptr<FEXCore::Config::Layer> CreateUserOverrideLayer(const char* AppConfig);

/**
* @brief Create an application configuration loader
Expand Down
6 changes: 6 additions & 0 deletions Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ FileManager::FileManager(FEXCore::Context::Context *ctx)
// - AppConfig Global
// - Steam AppConfig Local
// - AppConfig Local
// - AppConfig override
// This doesn't support the classic thunks interface.

auto AppName = AppConfigName();
Expand All @@ -245,6 +246,11 @@ FileManager::FileManager(FEXCore::Context::Context *ctx)
ConfigPaths.emplace_back(FEXCore::Config::GetApplicationConfig(AppName, false));
}

const char *AppConfig = getenv("FEX_APP_CONFIG");
if (AppConfig) {
ConfigPaths.emplace_back(AppConfig);
}

if (!LDPath().empty()) {
RootFSFD = open(LDPath().c_str(), O_DIRECTORY | O_PATH | O_CLOEXEC);
if (RootFSFD == -1) {
Expand Down

0 comments on commit 7786c23

Please sign in to comment.