MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / ReadMCModInfo

Function ReadMCModInfo

launcher/minecraft/mod/tasks/LocalModParseTask.cpp:23–89  ·  view source on GitHub ↗

OLD format: https://github.com/MinecraftForge/FML/wiki/FML-mod-information-file/5bf6a2d05145ec79387acc0d45c958642fb049fc

Source from the content-addressed store, hash-verified

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

Callers 2

processAsZipMethod · 0.85
processAsFolderMethod · 0.85

Calls 7

fromJsonFunction · 0.85
isEmptyMethod · 0.80
appendMethod · 0.80
objectMethod · 0.80
atMethod · 0.45
toStringMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected