| 18 | } |
| 19 | |
| 20 | std::optional<ModInfo> ModInfo::getInfo(const UString &path) |
| 21 | { |
| 22 | xml_document doc; |
| 23 | ModInfo info; |
| 24 | |
| 25 | auto filePath = path + "/modinfo.xml"; |
| 26 | auto parseResult = doc.load_file(filePath.c_str()); |
| 27 | if (!parseResult) |
| 28 | { |
| 29 | LogWarning("Failed to parse ModInfo at \"%s\": %s at offset %u", filePath, |
| 30 | parseResult.description(), parseResult.offset); |
| 31 | return {}; |
| 32 | } |
| 33 | auto infoNode = doc.child("openapoc_modinfo"); |
| 34 | if (!infoNode) |
| 35 | { |
| 36 | LogWarning("ModInfo at \"%s\" doesn't have an \"openapoc_modinfo\" root node", filePath); |
| 37 | return {}; |
| 38 | } |
| 39 | |
| 40 | info.setName(readNode("name", infoNode)); |
| 41 | info.setAuthor(readNode("author", infoNode)); |
| 42 | info.setVersion(readNode("version", infoNode)); |
| 43 | info.setDescription(readNode("description", infoNode)); |
| 44 | info.setLink(readNode("link", infoNode)); |
| 45 | info.setID(readNode("id", infoNode)); |
| 46 | info.setDataPath(readNode("datapath", infoNode)); |
| 47 | info.setStatePath(readNode("statepath", infoNode)); |
| 48 | info.setMinVersion(readNode("minversion", infoNode)); |
| 49 | info.setModLoadScript(readNode("modloadscript", infoNode)); |
| 50 | |
| 51 | auto requiresNode = infoNode.child("requires"); |
| 52 | if (requiresNode) |
| 53 | { |
| 54 | for (const auto node : requiresNode.children("entry")) |
| 55 | { |
| 56 | info.requirements().push_back(node.value()); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | auto conflictsNode = infoNode.child("conflicts"); |
| 61 | if (conflictsNode) |
| 62 | { |
| 63 | for (const auto node : conflictsNode.children("entry")) |
| 64 | { |
| 65 | info.conflicts().push_back(node.value()); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | auto languagesNode = infoNode.child("languages"); |
| 70 | if (languagesNode) |
| 71 | { |
| 72 | for (const auto node : languagesNode.children("entry")) |
| 73 | { |
| 74 | info.supported_languages.push_back(node.text().get()); |
| 75 | } |
| 76 | } |
| 77 | return info; |
nothing calls this directly
no test coverage detected