| 24 | namespace FEX::Config { |
| 25 | namespace JSON { |
| 26 | static void LoadJSonConfig(const fextl::string& Config, std::function<void(const char* Name, const char* ConfigSring)> Func) { |
| 27 | fextl::vector<char> Data; |
| 28 | if (!FEXCore::FileLoading::LoadFile(Data, Config)) { |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | FEX::JSON::JsonAllocator Pool {}; |
| 33 | const json_t* json = FEX::JSON::CreateJSON(Data, Pool); |
| 34 | |
| 35 | if (!json) { |
| 36 | ERROR_AND_DIE_FMT("Failed to parse JSON from file '{}' - invalid JSON format", Config); |
| 37 | } |
| 38 | |
| 39 | const json_t* ConfigList = json_getProperty(json, "Config"); |
| 40 | |
| 41 | if (!ConfigList) { |
| 42 | // This is a non-error if the configuration file exists but no Config section |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | for (const json_t* ConfigItem = json_getChild(ConfigList); ConfigItem != nullptr; ConfigItem = json_getSibling(ConfigItem)) { |
| 47 | const char* ConfigName = json_getName(ConfigItem); |
| 48 | const char* ConfigString = json_getValue(ConfigItem); |
| 49 | |
| 50 | if (!ConfigName) { |
| 51 | LogMan::Msg::EFmt("JSON file '{}': Couldn't get config name for an item", Config); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | if (!ConfigString) { |
| 56 | LogMan::Msg::EFmt("JSON file '{}': Couldn't get value for config item '{}'", Config, ConfigName); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | Func(ConfigName, ConfigString); |
| 61 | } |
| 62 | } |
| 63 | } // namespace JSON |
| 64 | |
| 65 | static constexpr std::pair<std::string_view, FEXCore::Config::ConfigOption> ConfigLookup[] { |
no test coverage detected