2016-08-14 01:33:31 +01:00
|
|
|
#include "LibrariesTask.h"
|
2021-11-21 22:21:12 +00:00
|
|
|
|
2017-07-24 08:01:37 +01:00
|
|
|
#include "minecraft/MinecraftInstance.h"
|
2020-06-27 11:02:31 +01:00
|
|
|
#include "minecraft/PackProfile.h"
|
2016-08-14 01:33:31 +01:00
|
|
|
|
2021-11-21 22:21:12 +00:00
|
|
|
#include "Application.h"
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
LibrariesTask::LibrariesTask(MinecraftInstance* inst)
|
2016-08-14 01:33:31 +01:00
|
|
|
{
|
|
|
|
m_inst = inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibrariesTask::executeTask()
|
|
|
|
{
|
2022-12-12 00:11:32 +00:00
|
|
|
setStatus(tr("Downloading required library files..."));
|
2016-08-14 01:33:31 +01:00
|
|
|
qDebug() << m_inst->name() << ": downloading libraries";
|
2023-08-02 17:35:35 +01:00
|
|
|
MinecraftInstance* inst = (MinecraftInstance*)m_inst;
|
2016-08-14 01:33:31 +01:00
|
|
|
|
|
|
|
// Build a list of URLs that will need to be downloaded.
|
2020-06-27 11:02:31 +01:00
|
|
|
auto components = inst->getPackProfile();
|
2017-11-04 21:55:25 +00:00
|
|
|
auto profile = components->getProfile();
|
2016-08-14 01:33:31 +01:00
|
|
|
|
2023-01-24 19:52:09 +00:00
|
|
|
NetJob::Ptr job{ new NetJob(tr("Libraries for instance %1").arg(inst->name()), APPLICATION->network()) };
|
2017-04-13 08:28:25 +01:00
|
|
|
downloadJob.reset(job);
|
2016-08-14 01:33:31 +01:00
|
|
|
|
2021-11-21 22:21:12 +00:00
|
|
|
auto metacache = APPLICATION->metacache();
|
2018-11-26 02:06:58 +00:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
auto processArtifactPool = [&](const QList<LibraryPtr>& pool, QStringList& errors, const QString& localPath) {
|
|
|
|
for (auto lib : pool) {
|
|
|
|
if (!lib) {
|
2018-11-26 08:57:51 +00:00
|
|
|
emitFailed(tr("Null jar is specified in the metadata, aborting."));
|
|
|
|
return false;
|
|
|
|
}
|
2022-07-11 08:01:07 +01:00
|
|
|
auto dls = lib->getDownloads(inst->runtimeContext(), metacache.get(), errors, localPath);
|
2023-08-02 17:35:35 +01:00
|
|
|
for (auto dl : dls) {
|
2018-11-26 08:57:51 +00:00
|
|
|
downloadJob->addNetAction(dl);
|
|
|
|
}
|
2017-04-13 08:28:25 +01:00
|
|
|
}
|
2018-11-26 08:57:51 +00:00
|
|
|
return true;
|
|
|
|
};
|
2017-04-06 22:31:23 +01:00
|
|
|
|
2018-11-26 08:57:51 +00:00
|
|
|
QStringList failedLocalLibraries;
|
|
|
|
QList<LibraryPtr> libArtifactPool;
|
|
|
|
libArtifactPool.append(profile->getLibraries());
|
|
|
|
libArtifactPool.append(profile->getNativeLibraries());
|
2020-03-27 01:23:15 +00:00
|
|
|
libArtifactPool.append(profile->getMavenFiles());
|
2023-08-02 17:35:35 +01:00
|
|
|
for (auto agent : profile->getAgents()) {
|
2022-04-06 07:22:24 +01:00
|
|
|
libArtifactPool.append(agent->library());
|
|
|
|
}
|
2018-11-26 08:57:51 +00:00
|
|
|
libArtifactPool.append(profile->getMainJar());
|
|
|
|
processArtifactPool(libArtifactPool, failedLocalLibraries, inst->getLocalLibraryPath());
|
|
|
|
|
|
|
|
QStringList failedLocalJarMods;
|
2018-12-05 23:33:49 +00:00
|
|
|
processArtifactPool(profile->getJarMods(), failedLocalJarMods, inst->jarModsDir());
|
2018-11-26 08:57:51 +00:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!failedLocalJarMods.empty() || !failedLocalLibraries.empty()) {
|
2016-08-14 01:33:31 +01:00
|
|
|
downloadJob.reset();
|
2018-11-26 08:57:51 +00:00
|
|
|
QString failed_all = (failedLocalLibraries + failedLocalJarMods).join("\n");
|
2023-08-02 17:35:35 +01:00
|
|
|
emitFailed(tr("Some artifacts marked as 'local' are missing their files:\n%1\n\nYou need to either add the files, or removed the "
|
|
|
|
"packages that require them.\nYou'll have to correct this problem manually.")
|
|
|
|
.arg(failed_all));
|
2016-08-14 01:33:31 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-11-26 08:57:51 +00:00
|
|
|
|
2016-08-14 01:33:31 +01:00
|
|
|
connect(downloadJob.get(), &NetJob::succeeded, this, &LibrariesTask::emitSucceeded);
|
|
|
|
connect(downloadJob.get(), &NetJob::failed, this, &LibrariesTask::jarlibFailed);
|
2023-08-02 17:35:35 +01:00
|
|
|
connect(downloadJob.get(), &NetJob::aborted, this, [this] { emitFailed(tr("Aborted")); });
|
2016-08-14 01:33:31 +01:00
|
|
|
connect(downloadJob.get(), &NetJob::progress, this, &LibrariesTask::progress);
|
2023-07-26 21:20:30 +01:00
|
|
|
connect(downloadJob.get(), &NetJob::stepProgress, this, &LibrariesTask::propagateStepProgress);
|
2023-03-31 07:50:29 +01:00
|
|
|
|
2021-12-31 04:27:59 +00:00
|
|
|
downloadJob->start();
|
2016-08-14 01:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LibrariesTask::canAbort() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibrariesTask::jarlibFailed(QString reason)
|
|
|
|
{
|
|
|
|
emitFailed(tr("Game update failed: it was impossible to fetch the required libraries.\nReason:\n%1").arg(reason));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LibrariesTask::abort()
|
|
|
|
{
|
2023-08-02 17:35:35 +01:00
|
|
|
if (downloadJob) {
|
2016-08-14 01:33:31 +01:00
|
|
|
return downloadJob->abort();
|
2023-08-02 17:35:35 +01:00
|
|
|
} else {
|
2016-08-14 01:33:31 +01:00
|
|
|
qWarning() << "Prematurely aborted LibrariesTask";
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|