MCPcopy Create free account
hub / github.com/PrismLauncher/PrismLauncher / updateMods

Method updateMods

launcher/ui/pages/instance/ModFolderPage.cpp:219–301  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217}
218
219void ModFolderPage::updateMods(bool includeDeps)
220{
221 if (m_instance->typeName() != "Minecraft")
222 return; // this is a null instance or a legacy instance
223
224 auto profile = static_cast<MinecraftInstance*>(m_instance)->getPackProfile();
225 if (!profile->getModLoaders().has_value()) {
226 if (handleNoModLoader()) {
227 return;
228 }
229 }
230 if (APPLICATION->settings()->get("ModMetadataDisabled").toBool()) {
231 QMessageBox::critical(this, tr("Error"), tr("Mod updates are unavailable when metadata is disabled!"));
232 return;
233 }
234 if (m_instance != nullptr && m_instance->isRunning()) {
235 auto response =
236 CustomMessageBox::selectable(this, tr("Confirm Update"),
237 tr("Updating mods while the game is running may cause mod duplication and game crashes.\n"
238 "The old files may not be deleted as they are in use.\n"
239 "Are you sure you want to do this?"),
240 QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
241 ->exec();
242
243 if (response != QMessageBox::Yes)
244 return;
245 }
246 auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
247
248 auto mods_list = m_model->selectedResources(selection);
249 bool use_all = mods_list.empty();
250 if (use_all)
251 mods_list = m_model->allResources();
252
253 ResourceUpdateDialog update_dialog(this, m_instance, m_model, mods_list, includeDeps, profile->getModLoadersList());
254 update_dialog.checkCandidates();
255
256 if (update_dialog.aborted()) {
257 CustomMessageBox::selectable(this, tr("Aborted"), tr("The mod updater was aborted!"), QMessageBox::Warning)->show();
258 return;
259 }
260 if (update_dialog.noUpdates()) {
261 QString message{ tr("'%1' is up-to-date! :)").arg(mods_list.front()->name()) };
262 if (mods_list.size() > 1) {
263 if (use_all) {
264 message = tr("All mods are up-to-date! :)");
265 } else {
266 message = tr("All selected mods are up-to-date! :)");
267 }
268 }
269 CustomMessageBox::selectable(this, tr("Update checker"), message)->exec();
270 return;
271 }
272
273 if (update_dialog.exec()) {
274 auto tasks = new ConcurrentTask("Download Mods", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
275 connect(tasks, &Task::failed, [this, tasks](QString reason) {
276 CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();

Callers

nothing calls this directly

Calls 15

selectableFunction · 0.85
getPackProfileMethod · 0.80
getModLoadersMethod · 0.80
selectedResourcesMethod · 0.80
allResourcesMethod · 0.80
getModLoadersListMethod · 0.80
checkCandidatesMethod · 0.80
abortedMethod · 0.80
showMethod · 0.80
noUpdatesMethod · 0.80
addTaskMethod · 0.80
setSkipButtonMethod · 0.80

Tested by

no test coverage detected