2929
3030namespace FEX ::Config {
3131namespace JSON {
32- static void LoadJSonConfig (const fextl::string& Config, std::function<void (const char * Name, const char * ConfigString)> Func) {
32+ static void LoadJSonConfig (const fextl::string& Config, std::optional<fextl::string> AppName,
33+ std::function<void (const char * Name, const char * ConfigString)> Func) {
3334 fextl::vector<char > Data;
3435 if (!FEXCore::FileLoading::LoadFile (Data, Config)) {
3536 return ;
@@ -52,26 +53,17 @@ namespace JSON {
5253 fextl::vector<const json_t *> ConfigBlocks;
5354 ConfigBlocks.push_back (ConfigList);
5455
55- const json_t * OverrideList = json_getProperty (json, " AppOverrides" );
56- if (OverrideList) {
57- for (const json_t * Item = json_getChild (OverrideList); Item != nullptr ; Item = json_getSibling (Item)) {
58- const char * ItemName = json_getName (Item);
59- const json_t * OverrideNamedList = json_getProperty (OverrideList, ItemName);
60-
61- if (!ItemName) {
62- LogMan::Msg::EFmt (" JSON file '{}': Couldn't get config name for an item" , Config);
63- break ;
64- }
65-
66- if (!OverrideNamedList) {
67- LogMan::Msg::EFmt (" JSON file '{}': Couldn't get value for config item '{}'" , Config, ItemName);
68- break ;
69- }
70-
71- // Find the first match, then break
72- if (FEXCore::Utils::Wildcard::Matches (ItemName, Config)) {
73- ConfigBlocks.push_back (OverrideNamedList);
74- break ;
56+ if (AppName) {
57+ const json_t * OverrideList = json_getProperty (json, " AppOverrides" );
58+ if (OverrideList) {
59+ for (const json_t * Item = json_getChild (OverrideList); Item != nullptr ; Item = json_getSibling (Item)) {
60+ const char * AppPattern = json_getName (Item);
61+
62+ // Find the first match, then break
63+ if (FEXCore::Utils::Wildcard::Matches (AppPattern, *AppName)) {
64+ ConfigBlocks.push_back (Item);
65+ break ;
66+ }
7567 }
7668 }
7769 }
@@ -81,11 +73,6 @@ namespace JSON {
8173 const char * ConfigName = json_getName (ConfigItem);
8274 const char * ConfigString = json_getValue (ConfigItem);
8375
84- if (!ConfigName) {
85- LogMan::Msg::EFmt (" JSON file '{}': Couldn't get config name for an item" , Config);
86- return ;
87- }
88-
8976 if (!ConfigString) {
9077 LogMan::Msg::EFmt (" JSON file '{}': Couldn't get value for config item '{}'" , Config, ConfigName);
9178 return ;
@@ -196,22 +183,24 @@ class OptionMapper : public FEXCore::Config::Layer {
196183
197184class MainLoader final : public OptionMapper {
198185public:
199- explicit MainLoader (FEXCore::Config::LayerType Type);
200- explicit MainLoader (fextl::string ConfigFile);
186+ explicit MainLoader (FEXCore::Config::LayerType Type, std::optional<fextl::string> AppName = std:: nullopt );
187+ explicit MainLoader (fextl::string ConfigFile, std::optional<fextl::string> AppName = std:: nullopt );
201188 explicit MainLoader (FEXCore::Config::LayerType Type, std::string_view ConfigFile);
202189
203190 void Load () override ;
204191
205192private:
193+ std::optional<fextl::string> AppName;
206194 fextl::string Config;
207195};
208196
209197class AppLoader final : public OptionMapper {
210198public:
211- explicit AppLoader (const fextl::string& Filename , FEXCore::Config::LayerType Type);
199+ explicit AppLoader (const fextl::string& AppName , FEXCore::Config::LayerType Type);
212200 void Load ();
213201
214202private:
203+ const fextl::string AppName;
215204 fextl::string Config;
216205};
217206
@@ -250,12 +239,14 @@ void OptionMapper::MapNameToOption(const char* ConfigName, const char* ConfigStr
250239#include < FEXCore/Config/ConfigOptions.inl>
251240}
252241
253- MainLoader::MainLoader (FEXCore::Config::LayerType Type)
242+ MainLoader::MainLoader (FEXCore::Config::LayerType Type, std::optional<fextl::string> AppName )
254243 : OptionMapper(Type)
244+ , AppName {AppName}
255245 , Config {FEXCore::Config::GetConfigFileLocation (Type == FEXCore::Config::LayerType::LAYER_GLOBAL_MAIN)} {}
256246
257- MainLoader::MainLoader (fextl::string ConfigFile)
247+ MainLoader::MainLoader (fextl::string ConfigFile, std::optional<fextl::string> AppName )
258248 : OptionMapper(FEXCore::Config::LayerType::LAYER_MAIN)
249+ , AppName {AppName}
259250 , Config {std::move (ConfigFile)} {}
260251
261252
@@ -265,21 +256,22 @@ MainLoader::MainLoader(FEXCore::Config::LayerType Type, std::string_view ConfigF
265256
266257void MainLoader::Load () {
267258 SetCurrentConfigFile (Config);
268- JSON::LoadJSonConfig (Config, [this ](const char * Name, const char * ConfigString) { MapNameToOption (Name, ConfigString); });
259+ JSON::LoadJSonConfig (Config, AppName, [this ](const char * Name, const char * ConfigString) { MapNameToOption (Name, ConfigString); });
269260}
270261
271- AppLoader::AppLoader (const fextl::string& Filename, FEXCore::Config::LayerType Type)
272- : OptionMapper(Type) {
262+ AppLoader::AppLoader (const fextl::string& AppName, FEXCore::Config::LayerType Type)
263+ : OptionMapper(Type)
264+ , AppName {AppName} {
273265 const bool Global = Type == FEXCore::Config::LayerType::LAYER_GLOBAL_STEAM_APP || Type == FEXCore::Config::LayerType::LAYER_GLOBAL_APP;
274- Config = FEXCore::Config::GetApplicationConfig (Filename , Global);
266+ Config = FEXCore::Config::GetApplicationConfig (AppName , Global);
275267
276268 // Immediately load so we can reload the meta layer
277269 Load ();
278270}
279271
280272void AppLoader::Load () {
281273 SetCurrentConfigFile (Config);
282- JSON::LoadJSonConfig (Config, [this ](const char * Name, const char * ConfigString) { MapNameToOption (Name, ConfigString); });
274+ JSON::LoadJSonConfig (Config, AppName, [this ](const char * Name, const char * ConfigString) { MapNameToOption (Name, ConfigString); });
283275}
284276
285277EnvLoader::EnvLoader (char * const _envp[])
@@ -349,11 +341,11 @@ fextl::unique_ptr<FEXCore::Config::Layer> CreateGlobalMainLayer() {
349341 return fextl::make_unique<MainLoader>(FEXCore::Config::LayerType::LAYER_GLOBAL_MAIN);
350342}
351343
352- fextl::unique_ptr<FEXCore::Config::Layer> CreateMainLayer (const fextl::string* File) {
344+ fextl::unique_ptr<FEXCore::Config::Layer> CreateMainLayer (const fextl::string* File, std::optional<fextl::string> AppName ) {
353345 if (File) {
354- return fextl::make_unique<MainLoader>(*File);
346+ return fextl::make_unique<MainLoader>(*File, std::move (AppName) );
355347 } else {
356- return fextl::make_unique<MainLoader>(FEXCore::Config::LayerType::LAYER_MAIN);
348+ return fextl::make_unique<MainLoader>(FEXCore::Config::LayerType::LAYER_MAIN, std::move (AppName) );
357349 }
358350}
359351
@@ -490,7 +482,7 @@ void LoadConfig(fextl::string ProgramName, char** const envp, const PortableInfo
490482 if (!IsPortable) {
491483 FEXCore::Config::AddLayer (CreateGlobalMainLayer ());
492484 }
493- FEXCore::Config::AddLayer (CreateMainLayer ());
485+ FEXCore::Config::AddLayer (CreateMainLayer (nullptr , ProgramName. empty () ? std:: nullopt : std::optional {ProgramName} ));
494486
495487 if (!ProgramName.empty ()) {
496488 if (!IsPortable) {
0 commit comments