| 239 | } |
| 240 | |
| 241 | void ModFolderPage::updateMods(bool includeDeps) |
| 242 | { |
| 243 | if (m_instance->typeName() != "Minecraft") |
| 244 | return; // this is a null instance or a legacy instance |
| 245 | |
| 246 | auto profile = static_cast<MinecraftInstance*>(m_instance)->getPackProfile(); |
| 247 | if (!profile->getModLoaders().has_value()) { |
| 248 | QMessageBox::critical(this, tr("Error"), tr("Please install a mod loader first!")); |
| 249 | return; |
| 250 | } |
| 251 | if (APPLICATION->settings()->get("ModMetadataDisabled").toBool()) { |
| 252 | QMessageBox::critical(this, tr("Error"), tr("Mod updates are unavailable when metadata is disabled!")); |
| 253 | return; |
| 254 | } |
| 255 | if (m_instance != nullptr && m_instance->isRunning()) { |
| 256 | auto response = |
| 257 | CustomMessageBox::selectable(this, tr("Confirm Update"), |
| 258 | tr("Updating mods while the game is running may cause mod duplication and game crashes.\n" |
| 259 | "The old files may not be deleted as they are in use.\n" |
| 260 | "Are you sure you want to do this?"), |
| 261 | QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) |
| 262 | ->exec(); |
| 263 | |
| 264 | if (response != QMessageBox::Yes) |
| 265 | return; |
| 266 | } |
| 267 | auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes(); |
| 268 | |
| 269 | auto mods_list = m_model->selectedMods(selection); |
| 270 | bool use_all = mods_list.empty(); |
| 271 | if (use_all) |
| 272 | mods_list = m_model->allMods(); |
| 273 | |
| 274 | ModUpdateDialog update_dialog(this, m_instance, m_model, mods_list, includeDeps); |
| 275 | update_dialog.checkCandidates(); |
| 276 | |
| 277 | if (update_dialog.aborted()) { |
| 278 | CustomMessageBox::selectable(this, tr("Aborted"), tr("The mod updater was aborted!"), QMessageBox::Warning)->show(); |
| 279 | return; |
| 280 | } |
| 281 | if (update_dialog.noUpdates()) { |
| 282 | QString message{ tr("'%1' is up-to-date! :)").arg(mods_list.front()->name()) }; |
| 283 | if (mods_list.size() > 1) { |
| 284 | if (use_all) { |
| 285 | message = tr("All mods are up-to-date! :)"); |
| 286 | } else { |
| 287 | message = tr("All selected mods are up-to-date! :)"); |
| 288 | } |
| 289 | } |
| 290 | CustomMessageBox::selectable(this, tr("Update checker"), message)->exec(); |
| 291 | return; |
| 292 | } |
| 293 | |
| 294 | if (update_dialog.exec()) { |
| 295 | auto tasks = new ConcurrentTask("Download Mods", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt()); |
| 296 | connect(tasks, &Task::failed, [this, tasks](QString reason) { |
| 297 | CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); |
| 298 | tasks->deleteLater(); |
nothing calls this directly
no test coverage detected