2016-08-14 01:33:31 +01:00
|
|
|
#include "Env.h"
|
|
|
|
#include "LibrariesTask.h"
|
2017-07-24 08:01:37 +01:00
|
|
|
#include "minecraft/MinecraftInstance.h"
|
2017-10-11 22:04:24 +01:00
|
|
|
#include "minecraft/ComponentList.h"
|
2016-08-14 01:33:31 +01:00
|
|
|
|
2017-07-24 08:01:37 +01:00
|
|
|
LibrariesTask::LibrariesTask(MinecraftInstance * inst)
|
2016-08-14 01:33:31 +01:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
m_inst = inst;
|
2016-08-14 01:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibrariesTask::executeTask()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
setStatus(tr("Getting the library files from Mojang..."));
|
|
|
|
qDebug() << m_inst->name() << ": downloading libraries";
|
|
|
|
MinecraftInstance *inst = (MinecraftInstance *)m_inst;
|
2016-08-14 01:33:31 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
// Build a list of URLs that will need to be downloaded.
|
|
|
|
auto components = inst->getComponentList();
|
|
|
|
auto profile = components->getProfile();
|
2016-08-14 01:33:31 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
auto job = new NetJob(tr("Libraries for instance %1").arg(inst->name()));
|
|
|
|
downloadJob.reset(job);
|
2016-08-14 01:33:31 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
auto metacache = ENV.metacache();
|
2018-11-26 02:06:58 +00:00
|
|
|
QStringList failedLocalFiles;
|
|
|
|
|
|
|
|
QList<LibraryPtr> artifactPool;
|
|
|
|
artifactPool.append(profile->getLibraries());
|
|
|
|
artifactPool.append(profile->getNativeLibraries());
|
|
|
|
artifactPool.append(profile->getJarMods());
|
|
|
|
artifactPool.append(profile->getMainJar());
|
|
|
|
for (auto lib : artifactPool)
|
2018-07-15 13:51:05 +01:00
|
|
|
{
|
|
|
|
if(!lib)
|
|
|
|
{
|
|
|
|
emitFailed(tr("Null jar is specified in the metadata, aborting."));
|
|
|
|
return;
|
|
|
|
}
|
2018-11-26 02:06:58 +00:00
|
|
|
auto dls = lib->getDownloads(currentSystem, metacache.get(), failedLocalFiles, inst->getLocalLibraryPath());
|
2018-07-15 13:51:05 +01:00
|
|
|
for(auto dl : dls)
|
|
|
|
{
|
|
|
|
downloadJob->addNetAction(dl);
|
|
|
|
}
|
2018-11-26 02:06:58 +00:00
|
|
|
}
|
2017-04-06 22:31:23 +01:00
|
|
|
|
2018-11-26 02:06:58 +00:00
|
|
|
if (!failedLocalFiles.empty())
|
2018-07-15 13:51:05 +01:00
|
|
|
{
|
|
|
|
downloadJob.reset();
|
2018-11-26 02:06:58 +00:00
|
|
|
QString failed_all = failedLocalFiles.join("\n");
|
|
|
|
emitFailed(tr("Some libraries marked as 'local' are missing their jar files:\n%1\n\nYou'll have to correct this problem manually.").arg(failed_all));
|
2018-07-15 13:51:05 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
connect(downloadJob.get(), &NetJob::succeeded, this, &LibrariesTask::emitSucceeded);
|
|
|
|
connect(downloadJob.get(), &NetJob::failed, this, &LibrariesTask::jarlibFailed);
|
|
|
|
connect(downloadJob.get(), &NetJob::progress, this, &LibrariesTask::progress);
|
|
|
|
downloadJob->start();
|
2016-08-14 01:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LibrariesTask::canAbort() const
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
return true;
|
2016-08-14 01:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibrariesTask::jarlibFailed(QString reason)
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
emitFailed(tr("Game update failed: it was impossible to fetch the required libraries.\nReason:\n%1").arg(reason));
|
2016-08-14 01:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LibrariesTask::abort()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
if(downloadJob)
|
|
|
|
{
|
|
|
|
return downloadJob->abort();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << "Prematurely aborted LibrariesTask";
|
|
|
|
}
|
|
|
|
return true;
|
2016-08-14 01:33:31 +01:00
|
|
|
}
|