| 174 | } |
| 175 | |
| 176 | std::string AddonInfo::getAddonInfo(const std::string &fileName, const std::string &exename, bool debug) { |
| 177 | if (fileName[0] == '{') { |
| 178 | picojson::value json; |
| 179 | const std::string err = picojson::parse(json, fileName); |
| 180 | (void)err; // TODO: report |
| 181 | return parseAddonInfo(*this, json, fileName, exename); |
| 182 | } |
| 183 | if (fileName.find('.') == std::string::npos) |
| 184 | return getAddonInfo(fileName + ".py", exename, debug); |
| 185 | |
| 186 | if (endsWith(fileName, ".py")) { |
| 187 | scriptFile = Path::fromNativeSeparators(getFullPath(fileName, exename, debug)); |
| 188 | if (scriptFile.empty()) |
| 189 | return "Did not find addon " + fileName; |
| 190 | |
| 191 | std::string::size_type pos1 = scriptFile.rfind('/'); |
| 192 | if (pos1 == std::string::npos) |
| 193 | pos1 = 0; |
| 194 | else |
| 195 | pos1++; |
| 196 | std::string::size_type pos2 = scriptFile.rfind('.'); |
| 197 | if (pos2 < pos1) |
| 198 | pos2 = std::string::npos; |
| 199 | name = scriptFile.substr(pos1, pos2 - pos1); |
| 200 | |
| 201 | runScript = getFullPath("runaddon.py", exename); |
| 202 | |
| 203 | return ""; |
| 204 | } |
| 205 | |
| 206 | if (!endsWith(fileName, ".json")) |
| 207 | return "Failed to open addon " + fileName; |
| 208 | |
| 209 | std::ifstream fin(fileName); |
| 210 | if (!fin.is_open()) |
| 211 | return "Failed to open " + fileName; |
| 212 | if (name.empty()) { |
| 213 | name = Path::fromNativeSeparators(fileName); |
| 214 | if (name.find('/') != std::string::npos) |
| 215 | name = name.substr(name.rfind('/') + 1); |
| 216 | } |
| 217 | picojson::value json; |
| 218 | fin >> json; |
| 219 | return parseAddonInfo(*this, json, fileName, exename); |
| 220 | } |
no test coverage detected