MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / updateMods

Method updateMods

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

Source from the content-addressed store, hash-verified

239}
240
241void 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();

Callers

nothing calls this directly

Calls 15

selectableFunction · 0.85
getPackProfileMethod · 0.80
getModLoadersMethod · 0.80
selectedModsMethod · 0.80
allModsMethod · 0.80
checkCandidatesMethod · 0.80
abortedMethod · 0.80
showMethod · 0.80
noUpdatesMethod · 0.80
addTaskMethod · 0.80
setSkipButtonMethod · 0.80
execWithTaskMethod · 0.80

Tested by

no test coverage detected