| 11 | } |
| 12 | |
| 13 | void LibrariesTask::executeTask() |
| 14 | { |
| 15 | setStatus(tr("Downloading required library files...")); |
| 16 | qDebug() << m_inst->name() << ": downloading libraries"; |
| 17 | MinecraftInstance* inst = (MinecraftInstance*)m_inst; |
| 18 | |
| 19 | // Build a list of URLs that will need to be downloaded. |
| 20 | auto components = inst->getPackProfile(); |
| 21 | auto profile = components->getProfile(); |
| 22 | |
| 23 | NetJob::Ptr job{ new NetJob(tr("Libraries for instance %1").arg(inst->name()), APPLICATION->network()) }; |
| 24 | downloadJob.reset(job); |
| 25 | |
| 26 | auto metacache = APPLICATION->metacache(); |
| 27 | |
| 28 | auto processArtifactPool = [&](const QList<LibraryPtr>& pool, QStringList& errors, const QString& localPath) { |
| 29 | for (auto lib : pool) { |
| 30 | if (!lib) { |
| 31 | emitFailed(tr("Null jar is specified in the metadata, aborting.")); |
| 32 | return false; |
| 33 | } |
| 34 | auto dls = lib->getDownloads(inst->runtimeContext(), metacache.get(), errors, localPath); |
| 35 | for (auto dl : dls) { |
| 36 | downloadJob->addNetAction(dl); |
| 37 | } |
| 38 | } |
| 39 | return true; |
| 40 | }; |
| 41 | |
| 42 | QStringList failedLocalLibraries; |
| 43 | QList<LibraryPtr> libArtifactPool; |
| 44 | libArtifactPool.append(profile->getLibraries()); |
| 45 | libArtifactPool.append(profile->getNativeLibraries()); |
| 46 | libArtifactPool.append(profile->getMavenFiles()); |
| 47 | for (auto agent : profile->getAgents()) { |
| 48 | libArtifactPool.append(agent->library()); |
| 49 | } |
| 50 | libArtifactPool.append(profile->getMainJar()); |
| 51 | processArtifactPool(libArtifactPool, failedLocalLibraries, inst->getLocalLibraryPath()); |
| 52 | |
| 53 | QStringList failedLocalJarMods; |
| 54 | processArtifactPool(profile->getJarMods(), failedLocalJarMods, inst->jarModsDir()); |
| 55 | |
| 56 | if (!failedLocalJarMods.empty() || !failedLocalLibraries.empty()) { |
| 57 | downloadJob.reset(); |
| 58 | QString failed_all = (failedLocalLibraries + failedLocalJarMods).join("\n"); |
| 59 | emitFailed(tr("Some artifacts marked as 'local' are missing their files:\n%1\n\nYou need to either add the files, or removed the " |
| 60 | "packages that require them.\nYou'll have to correct this problem manually.") |
| 61 | .arg(failed_all)); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | connect(downloadJob.get(), &NetJob::succeeded, this, &LibrariesTask::emitSucceeded); |
| 66 | connect(downloadJob.get(), &NetJob::failed, this, &LibrariesTask::jarlibFailed); |
| 67 | connect(downloadJob.get(), &NetJob::aborted, this, [this] { emitFailed(tr("Aborted")); }); |
| 68 | connect(downloadJob.get(), &NetJob::progress, this, &LibrariesTask::progress); |
| 69 | connect(downloadJob.get(), &NetJob::stepProgress, this, &LibrariesTask::propagateStepProgress); |
| 70 |
nothing calls this directly
no test coverage detected