MCPcopy Create free account
hub / github.com/FEX-Emu/FEX / LoadJSonConfig

Function LoadJSonConfig

Source/Common/Config.cpp:26–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24namespace FEX::Config {
25namespace 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
65static constexpr std::pair<std::string_view, FEXCore::Config::ConfigOption> ConfigLookup[] {

Callers 1

LoadMethod · 0.85

Calls 8

LoadFileFunction · 0.85
CreateJSONFunction · 0.85
json_getPropertyFunction · 0.85
json_getChildFunction · 0.85
json_getSiblingFunction · 0.85
json_getNameFunction · 0.85
json_getValueFunction · 0.85
EFmtFunction · 0.85

Tested by

no test coverage detected