| 57 | } |
| 58 | |
| 59 | void ModUpdateDialog::checkCandidates() |
| 60 | { |
| 61 | // Ensure mods have valid metadata |
| 62 | auto went_well = ensureMetadata(); |
| 63 | if (!went_well) { |
| 64 | m_aborted = true; |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | // Report failed metadata generation |
| 69 | if (!m_failed_metadata.empty()) { |
| 70 | QString text; |
| 71 | for (const auto& failed : m_failed_metadata) { |
| 72 | const auto& mod = std::get<0>(failed); |
| 73 | const auto& reason = std::get<1>(failed); |
| 74 | text += tr("Mod name: %1<br>File name: %2<br>Reason: %3<br><br>").arg(mod->name(), mod->fileinfo().fileName(), reason); |
| 75 | } |
| 76 | |
| 77 | ScrollMessageBox message_dialog(m_parent, tr("Metadata generation failed"), |
| 78 | tr("Could not generate metadata for the following mods:<br>" |
| 79 | "Do you wish to proceed without those mods?"), |
| 80 | text); |
| 81 | message_dialog.setModal(true); |
| 82 | if (message_dialog.exec() == QDialog::Rejected) { |
| 83 | m_aborted = true; |
| 84 | QMetaObject::invokeMethod(this, "reject", Qt::QueuedConnection); |
| 85 | return; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | auto versions = mcVersions(m_instance); |
| 90 | auto loadersList = mcLoadersList(m_instance); |
| 91 | |
| 92 | SequentialTask check_task(tr("Checking for updates")); |
| 93 | |
| 94 | if (!m_modrinth_to_update.empty()) { |
| 95 | m_modrinth_check_task.reset(new ModrinthCheckUpdate(m_modrinth_to_update, versions, loadersList, m_mod_model)); |
| 96 | connect(m_modrinth_check_task.get(), &CheckUpdateTask::checkFailed, this, |
| 97 | [this](Mod* mod, QString reason, QUrl recover_url) { m_failed_check_update.append({ mod, reason, recover_url }); }); |
| 98 | check_task.addTask(m_modrinth_check_task); |
| 99 | } |
| 100 | |
| 101 | if (!m_flame_to_update.empty()) { |
| 102 | m_flame_check_task.reset(new FlameCheckUpdate(m_flame_to_update, versions, loadersList, m_mod_model)); |
| 103 | connect(m_flame_check_task.get(), &CheckUpdateTask::checkFailed, this, |
| 104 | [this](Mod* mod, QString reason, QUrl recover_url) { m_failed_check_update.append({ mod, reason, recover_url }); }); |
| 105 | check_task.addTask(m_flame_check_task); |
| 106 | } |
| 107 | |
| 108 | connect(&check_task, &Task::failed, this, |
| 109 | [&](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); }); |
| 110 | |
| 111 | connect(&check_task, &Task::succeeded, this, [&]() { |
| 112 | QStringList warnings = check_task.warnings(); |
| 113 | if (warnings.count()) { |
| 114 | CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->exec(); |
| 115 | } |
| 116 | }); |
no test coverage detected