77#include < FEXCore/fextl/fmt.h>
88#include < FEXCore/fextl/map.h>
99#include < FEXCore/fextl/string.h>
10+ #include < FEXCore/fextl/vector.h>
1011#include < FEXCore/Utils/Allocator.h>
1112#include < FEXCore/Utils/FileLoading.h>
13+ #include < FEXCore/Utils/WildcardMatcher.h>
1214#include < FEXHeaderUtils/Filesystem.h>
1315#include < FEXHeaderUtils/SymlinkChecks.h>
14-
1516#include < cstring>
1617#include < fmt/format.h>
1718#include < functional>
2829
2930namespace FEX ::Config {
3031namespace JSON {
31- static void LoadJSonConfig (const fextl::string& Config, std::function<void (const char * Name, const char * ConfigSring )> Func) {
32+ static void LoadJSonConfig (const fextl::string& Config, std::function<void (const char * Name, const char * ConfigString )> Func) {
3233 fextl::vector<char > Data;
3334 if (!FEXCore::FileLoading::LoadFile (Data, Config)) {
3435 return ;
@@ -48,21 +49,49 @@ namespace JSON {
4849 return ;
4950 }
5051
51- for (const json_t * ConfigItem = json_getChild (ConfigList); ConfigItem != nullptr ; ConfigItem = json_getSibling (ConfigItem)) {
52- const char * ConfigName = json_getName (ConfigItem);
53- const char * ConfigString = json_getValue (ConfigItem);
52+ fextl::vector<const json_t *> ConfigBlocks;
53+ ConfigBlocks.push_back (ConfigList);
5454
55- if (!ConfigName) {
56- LogMan::Msg::EFmt (" JSON file '{}': Couldn't get config name for an item" , Config);
57- return ;
58- }
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+ }
5965
60- if (!ConfigString) {
61- LogMan::Msg::EFmt (" JSON file '{}': Couldn't get value for config item '{}'" , Config, ConfigName);
62- return ;
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 ;
75+ }
6376 }
77+ }
78+
79+ for (auto ConfigBlock : ConfigBlocks) {
80+ for (const json_t * ConfigItem = json_getChild (ConfigBlock); ConfigItem != nullptr ; ConfigItem = json_getSibling (ConfigItem)) {
81+ const char * ConfigName = json_getName (ConfigItem);
82+ const char * ConfigString = json_getValue (ConfigItem);
83+
84+ if (!ConfigName) {
85+ LogMan::Msg::EFmt (" JSON file '{}': Couldn't get config name for an item" , Config);
86+ return ;
87+ }
6488
65- Func (ConfigName, ConfigString);
89+ if (!ConfigString) {
90+ LogMan::Msg::EFmt (" JSON file '{}': Couldn't get value for config item '{}'" , Config, ConfigName);
91+ return ;
92+ }
93+ Func (ConfigName, ConfigString);
94+ }
6695 }
6796 }
6897} // namespace JSON
0 commit comments