| 285 | } |
| 286 | |
| 287 | bool ModrinthCreationTask::parseManifest(const QString& index_path, std::vector<Modrinth::File>& files, bool set_managed_info, bool show_optional_dialog) |
| 288 | { |
| 289 | try { |
| 290 | auto doc = Json::requireDocument(index_path); |
| 291 | auto obj = Json::requireObject(doc, "modrinth.index.json"); |
| 292 | int formatVersion = Json::requireInteger(obj, "formatVersion", "modrinth.index.json"); |
| 293 | if (formatVersion == 1) { |
| 294 | auto game = Json::requireString(obj, "game", "modrinth.index.json"); |
| 295 | if (game != "minecraft") { |
| 296 | throw JSONValidationError("Unknown game: " + game); |
| 297 | } |
| 298 | |
| 299 | if (set_managed_info) { |
| 300 | m_managed_version_id = Json::ensureString(obj, "versionId", {}, "Managed ID"); |
| 301 | m_managed_name = Json::ensureString(obj, "name", {}, "Managed Name"); |
| 302 | } |
| 303 | |
| 304 | auto jsonFiles = Json::requireIsArrayOf<QJsonObject>(obj, "files", "modrinth.index.json"); |
| 305 | bool had_optional = false; |
| 306 | for (const auto& modInfo : jsonFiles) { |
| 307 | Modrinth::File file; |
| 308 | file.path = Json::requireString(modInfo, "path"); |
| 309 | |
| 310 | if (QDir::isAbsolutePath(file.path) || QDir::cleanPath(file.path).startsWith("..")) { |
| 311 | qDebug() << "Skipped file that tries to place itself in an absolute location or in a parent directory."; |
| 312 | continue; |
| 313 | } |
| 314 | |
| 315 | auto env = Json::ensureObject(modInfo, "env"); |
| 316 | // 'env' field is optional |
| 317 | if (!env.isEmpty()) { |
| 318 | QString support = Json::ensureString(env, "client", "unsupported"); |
| 319 | if (support == "unsupported") { |
| 320 | continue; |
| 321 | } else if (support == "optional") { |
| 322 | // TODO: Make a review dialog for choosing which ones the user wants! |
| 323 | if (!had_optional && show_optional_dialog) { |
| 324 | had_optional = true; |
| 325 | auto info = CustomMessageBox::selectable( |
| 326 | m_parent, tr("Optional mod detected!"), |
| 327 | tr("One or more mods from this modpack are optional. They will be downloaded, but disabled by default!"), |
| 328 | QMessageBox::Information); |
| 329 | info->exec(); |
| 330 | } |
| 331 | |
| 332 | if (file.path.endsWith(".jar")) |
| 333 | file.path += ".disabled"; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | QJsonObject hashes = Json::requireObject(modInfo, "hashes"); |
| 338 | QString hash; |
| 339 | QCryptographicHash::Algorithm hashAlgorithm; |
| 340 | hash = Json::ensureString(hashes, "sha1"); |
| 341 | hashAlgorithm = QCryptographicHash::Sha1; |
| 342 | if (hash.isEmpty()) { |
| 343 | hash = Json::ensureString(hashes, "sha512"); |
| 344 | hashAlgorithm = QCryptographicHash::Sha512; |
nothing calls this directly
no test coverage detected