| 74 | } |
| 75 | |
| 76 | static std::string parseAddonInfo(AddonInfo& addoninfo, const picojson::value &json, const std::string &fileName, const std::string &exename) { |
| 77 | const std::string& json_error = picojson::get_last_error(); |
| 78 | if (!json_error.empty()) { |
| 79 | return "Loading " + fileName + " failed. " + json_error; |
| 80 | } |
| 81 | if (!json.is<picojson::object>()) |
| 82 | return "Loading " + fileName + " failed. JSON is not an object."; |
| 83 | |
| 84 | // TODO: remove/complete default value handling for missing fields |
| 85 | const picojson::object& obj = json.get<picojson::object>(); |
| 86 | { |
| 87 | const auto it = obj.find("args"); |
| 88 | if (it != obj.cend()) { |
| 89 | const auto& val = it->second; |
| 90 | if (!val.is<picojson::array>()) |
| 91 | return "Loading " + fileName + " failed. 'args' must be an array."; |
| 92 | for (const picojson::value &v : val.get<picojson::array>()) { |
| 93 | if (!v.is<std::string>()) |
| 94 | return "Loading " + fileName + " failed. 'args' entry is not a string."; |
| 95 | addoninfo.args += " " + v.get<std::string>(); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | { |
| 101 | const auto it = obj.find("ctu"); |
| 102 | if (it != obj.cend()) { |
| 103 | const auto& val = it->second; |
| 104 | // ctu is specified in the config file |
| 105 | if (!val.is<bool>()) |
| 106 | return "Loading " + fileName + " failed. 'ctu' must be a boolean."; |
| 107 | addoninfo.ctu = val.get<bool>(); |
| 108 | } |
| 109 | else { |
| 110 | addoninfo.ctu = false; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | { |
| 115 | const auto it = obj.find("python"); |
| 116 | if (it != obj.cend()) { |
| 117 | const auto& val = it->second; |
| 118 | // Python was defined in the config file |
| 119 | if (!val.is<std::string>()) { |
| 120 | return "Loading " + fileName +" failed. 'python' must be a string."; |
| 121 | } |
| 122 | addoninfo.python = val.get<std::string>(); |
| 123 | } |
| 124 | else { |
| 125 | addoninfo.python = ""; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | { |
| 130 | const auto it = obj.find("checkers"); |
| 131 | if (it != obj.cend()) { |
| 132 | const auto& val = it->second; |
| 133 | if (!val.is<picojson::array>()) |
no test coverage detected