OLD format: https://github.com/MinecraftForge/FML/wiki/FML-mod-information-file/5bf6a2d05145ec79387acc0d45c958642fb049fc
| 19 | // OLD format: |
| 20 | // https://github.com/MinecraftForge/FML/wiki/FML-mod-information-file/5bf6a2d05145ec79387acc0d45c958642fb049fc |
| 21 | std::shared_ptr<ModDetails> ReadMCModInfo(QByteArray contents) |
| 22 | { |
| 23 | auto getInfoFromArray = [&](QJsonArray arr)->std::shared_ptr<ModDetails> |
| 24 | { |
| 25 | if (!arr.at(0).isObject()) { |
| 26 | return nullptr; |
| 27 | } |
| 28 | std::shared_ptr<ModDetails> details = std::make_shared<ModDetails>(); |
| 29 | auto firstObj = arr.at(0).toObject(); |
| 30 | details->mod_id = firstObj.value("modid").toString(); |
| 31 | auto name = firstObj.value("name").toString(); |
| 32 | // NOTE: ignore stupid example mods copies where the author didn't even bother to change the name |
| 33 | if(name != "Example Mod") { |
| 34 | details->name = name; |
| 35 | } |
| 36 | details->version = firstObj.value("version").toString(); |
| 37 | details->updateurl = firstObj.value("updateUrl").toString(); |
| 38 | auto homeurl = firstObj.value("url").toString().trimmed(); |
| 39 | if(!homeurl.isEmpty()) |
| 40 | { |
| 41 | // fix up url. |
| 42 | if (!homeurl.startsWith("http://") && !homeurl.startsWith("https://") && !homeurl.startsWith("ftp://")) |
| 43 | { |
| 44 | homeurl.prepend("http://"); |
| 45 | } |
| 46 | } |
| 47 | details->homeurl = homeurl; |
| 48 | details->description = firstObj.value("description").toString(); |
| 49 | QJsonArray authors = firstObj.value("authorList").toArray(); |
| 50 | if (authors.size() == 0) { |
| 51 | // FIXME: what is the format of this? is there any? |
| 52 | authors = firstObj.value("authors").toArray(); |
| 53 | } |
| 54 | |
| 55 | for (auto author: authors) |
| 56 | { |
| 57 | details->authors.append(author.toString()); |
| 58 | } |
| 59 | details->credits = firstObj.value("credits").toString(); |
| 60 | return details; |
| 61 | }; |
| 62 | QJsonParseError jsonError; |
| 63 | QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError); |
| 64 | // this is the very old format that had just the array |
| 65 | if (jsonDoc.isArray()) |
| 66 | { |
| 67 | return getInfoFromArray(jsonDoc.array()); |
| 68 | } |
| 69 | else if (jsonDoc.isObject()) |
| 70 | { |
| 71 | auto val = jsonDoc.object().value("modinfoversion"); |
| 72 | if(val.isUndefined()) { |
| 73 | val = jsonDoc.object().value("modListVersion"); |
| 74 | } |
| 75 | int version = val.toDouble(); |
| 76 | if (version != 2) |
| 77 | { |
| 78 | qCritical() << "BAD stuff happened to mod json:"; |