https://fabricmc.net/wiki/documentation:fabric_mod_json
| 222 | |
| 223 | // https://fabricmc.net/wiki/documentation:fabric_mod_json |
| 224 | std::shared_ptr<ModDetails> ReadFabricModInfo(QByteArray contents) |
| 225 | { |
| 226 | QJsonParseError jsonError; |
| 227 | QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError); |
| 228 | auto object = jsonDoc.object(); |
| 229 | auto schemaVersion = object.contains("schemaVersion") ? object.value("schemaVersion").toInt(0) : 0; |
| 230 | |
| 231 | std::shared_ptr<ModDetails> details = std::make_shared<ModDetails>(); |
| 232 | |
| 233 | details->mod_id = object.value("id").toString(); |
| 234 | details->version = object.value("version").toString(); |
| 235 | |
| 236 | details->name = object.contains("name") ? object.value("name").toString() : details->mod_id; |
| 237 | details->description = object.value("description").toString(); |
| 238 | |
| 239 | if (schemaVersion >= 1) |
| 240 | { |
| 241 | QJsonArray authors = object.value("authors").toArray(); |
| 242 | for (auto author: authors) |
| 243 | { |
| 244 | if(author.isObject()) { |
| 245 | details->authors.append(author.toObject().value("name").toString()); |
| 246 | } |
| 247 | else { |
| 248 | details->authors.append(author.toString()); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | if (object.contains("contact")) |
| 253 | { |
| 254 | QJsonObject contact = object.value("contact").toObject(); |
| 255 | |
| 256 | if (contact.contains("homepage")) |
| 257 | { |
| 258 | details->homeurl = contact.value("homepage").toString(); |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | return details; |
| 263 | } |
| 264 | |
| 265 | // https://github.com/QuiltMC/rfcs/blob/master/specification/0002-quilt.mod.json.md |
| 266 | std::shared_ptr<ModDetails> ReadQuiltModInfo(QByteArray contents) |