MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / downloadMods

Method downloadMods

launcher/modplatform/atlauncher/ATLPackInstallTask.cpp:724–854  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

722}
723
724void PackInstallTask::downloadMods()
725{
726 qDebug() << "PackInstallTask::installMods: " << QThread::currentThreadId();
727
728 QVector<ATLauncher::VersionMod> optionalMods;
729 for (const auto& mod : m_version.mods) {
730 if (mod.optional) {
731 optionalMods.push_back(mod);
732 }
733 }
734
735 // Select optional mods, if pack contains any
736 QVector<QString> selectedMods;
737 if (!optionalMods.isEmpty()) {
738 setStatus(tr("Selecting optional mods..."));
739 selectedMods = m_support->chooseOptionalMods(m_version, optionalMods);
740 }
741
742 setStatus(tr("Downloading mods..."));
743
744 jarmods.clear();
745 jobPtr = new NetJob(tr("Mod download"), APPLICATION->network());
746 for(const auto& mod : m_version.mods) {
747 // skip non-client mods
748 if(!mod.client) continue;
749
750 // skip optional mods that were not selected
751 if(mod.optional && !selectedMods.contains(mod.name)) continue;
752
753 QString url;
754 switch(mod.download) {
755 case DownloadType::Server:
756 url = BuildConfig.ATL_DOWNLOAD_SERVER_URL + mod.url;
757 break;
758 case DownloadType::Browser:
759 emitFailed(tr("Unsupported download type: %1").arg(mod.download_raw));
760 return;
761 case DownloadType::Direct:
762 url = mod.url;
763 break;
764 case DownloadType::Unknown:
765 emitFailed(tr("Unknown download type: %1").arg(mod.download_raw));
766 return;
767 }
768
769 QFileInfo fileName(mod.file);
770 auto cacheName = fileName.completeBaseName() + "-" + mod.md5 + "." + fileName.suffix();
771
772 if (mod.type == ModType::Extract || mod.type == ModType::TexturePackExtract || mod.type == ModType::ResourcePackExtract) {
773 auto entry = APPLICATION->metacache()->resolveEntry("ATLauncherPacks", cacheName);
774 entry->setStale(true);
775 modsToExtract.insert(entry->getFullPath(), mod);
776
777 auto dl = Net::Download::makeCached(url, entry);
778 if (!mod.md5.isEmpty()) {
779 auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
780 dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
781 }

Callers

nothing calls this directly

Calls 15

PathCombineFunction · 0.85
getComponentVersionFunction · 0.85
isEmptyMethod · 0.80
chooseOptionalModsMethod · 0.80
networkMethod · 0.80
resolveEntryMethod · 0.80
metacacheMethod · 0.80
insertMethod · 0.80
getFullPathMethod · 0.80
addNetActionMethod · 0.80
clearMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected