2016-08-14 01:33:31 +01:00
|
|
|
#include "FMLLibrariesTask.h"
|
2021-11-21 22:21:12 +00:00
|
|
|
|
|
|
|
#include "FileSystem.h"
|
|
|
|
#include "minecraft/VersionFilterData.h"
|
2017-07-24 08:01:37 +01:00
|
|
|
#include "minecraft/MinecraftInstance.h"
|
2020-06-27 11:02:31 +01:00
|
|
|
#include "minecraft/PackProfile.h"
|
2021-11-21 22:21:12 +00:00
|
|
|
|
2020-07-18 15:18:02 +01:00
|
|
|
#include "BuildConfig.h"
|
2021-11-21 22:21:12 +00:00
|
|
|
#include "Application.h"
|
2016-08-14 01:33:31 +01:00
|
|
|
|
2017-07-24 08:01:37 +01:00
|
|
|
FMLLibrariesTask::FMLLibrariesTask(MinecraftInstance * inst)
|
2016-08-14 01:33:31 +01:00
|
|
|
{
|
|
|
|
m_inst = inst;
|
|
|
|
}
|
|
|
|
void FMLLibrariesTask::executeTask()
|
|
|
|
{
|
|
|
|
// Get the mod list
|
2017-07-24 08:01:37 +01:00
|
|
|
MinecraftInstance *inst = (MinecraftInstance *)m_inst;
|
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
|
|
|
|
|
|
|
if (!profile->hasTrait("legacyFML"))
|
|
|
|
{
|
|
|
|
emitSucceeded();
|
2017-07-07 18:50:24 +01:00
|
|
|
return;
|
2016-08-14 01:33:31 +01:00
|
|
|
}
|
|
|
|
|
2017-11-11 00:38:31 +00:00
|
|
|
QString version = components->getComponentVersion("net.minecraft");
|
2016-08-14 01:33:31 +01:00
|
|
|
auto &fmlLibsMapping = g_VersionFilterData.fmlLibsMapping;
|
|
|
|
if (!fmlLibsMapping.contains(version))
|
|
|
|
{
|
|
|
|
emitSucceeded();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &libList = fmlLibsMapping[version];
|
|
|
|
|
|
|
|
// determine if we need some libs for FML or forge
|
2017-05-03 22:11:52 +01:00
|
|
|
setStatus(tr("Checking for FML libraries..."));
|
2017-11-11 00:38:31 +00:00
|
|
|
if(!components->getComponent("net.minecraftforge"))
|
2016-08-14 01:33:31 +01:00
|
|
|
{
|
|
|
|
emitSucceeded();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now check the lib folder inside the instance for files.
|
|
|
|
for (auto &lib : libList)
|
|
|
|
{
|
2017-07-24 08:01:37 +01:00
|
|
|
QFileInfo libInfo(FS::PathCombine(inst->libDir(), lib.filename));
|
2016-08-14 01:33:31 +01:00
|
|
|
if (libInfo.exists())
|
|
|
|
continue;
|
|
|
|
fmlLibsToProcess.append(lib);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if everything is in place, there's nothing to do here...
|
|
|
|
if (fmlLibsToProcess.isEmpty())
|
|
|
|
{
|
|
|
|
emitSucceeded();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// download missing libs to our place
|
2021-10-03 20:46:10 +01:00
|
|
|
setStatus(tr("Downloading FML libraries..."));
|
2023-01-24 19:52:09 +00:00
|
|
|
NetJob::Ptr dljob{ new NetJob("FML libraries", APPLICATION->network()) };
|
2021-11-21 22:21:12 +00:00
|
|
|
auto metacache = APPLICATION->metacache();
|
2022-08-21 17:18:04 +01:00
|
|
|
Net::Download::Options options = Net::Download::Option::MakeEternal;
|
2016-08-14 01:33:31 +01:00
|
|
|
for (auto &lib : fmlLibsToProcess)
|
|
|
|
{
|
|
|
|
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
|
2021-04-29 01:32:21 +01:00
|
|
|
QString urlString = BuildConfig.FMLLIBS_BASE_URL + lib.filename;
|
2022-08-21 17:18:04 +01:00
|
|
|
dljob->addNetAction(Net::Download::makeCached(QUrl(urlString), entry, options));
|
2016-08-14 01:33:31 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:52:09 +00:00
|
|
|
connect(dljob.get(), &NetJob::succeeded, this, &FMLLibrariesTask::fmllibsFinished);
|
|
|
|
connect(dljob.get(), &NetJob::failed, this, &FMLLibrariesTask::fmllibsFailed);
|
|
|
|
connect(dljob.get(), &NetJob::aborted, this, [this]{ emitFailed(tr("Aborted")); });
|
|
|
|
connect(dljob.get(), &NetJob::progress, this, &FMLLibrariesTask::progress);
|
2023-03-31 07:50:29 +01:00
|
|
|
connect(dljob.get(), &NetJob::stepProgress, this, &FMLLibrariesTask::propogateStepProgress);
|
2016-08-14 01:33:31 +01:00
|
|
|
downloadJob.reset(dljob);
|
2021-12-31 04:27:59 +00:00
|
|
|
downloadJob->start();
|
2016-08-14 01:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FMLLibrariesTask::canAbort() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FMLLibrariesTask::fmllibsFinished()
|
|
|
|
{
|
|
|
|
downloadJob.reset();
|
|
|
|
if (!fmlLibsToProcess.isEmpty())
|
|
|
|
{
|
2017-05-03 22:11:52 +01:00
|
|
|
setStatus(tr("Copying FML libraries into the instance..."));
|
2017-07-24 08:01:37 +01:00
|
|
|
MinecraftInstance *inst = (MinecraftInstance *)m_inst;
|
2021-11-21 22:21:12 +00:00
|
|
|
auto metacache = APPLICATION->metacache();
|
2016-08-14 01:33:31 +01:00
|
|
|
int index = 0;
|
|
|
|
for (auto &lib : fmlLibsToProcess)
|
|
|
|
{
|
|
|
|
progress(index, fmlLibsToProcess.size());
|
|
|
|
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
|
2017-07-24 08:01:37 +01:00
|
|
|
auto path = FS::PathCombine(inst->libDir(), lib.filename);
|
2016-08-14 01:33:31 +01:00
|
|
|
if (!FS::ensureFilePathExists(path))
|
|
|
|
{
|
|
|
|
emitFailed(tr("Failed creating FML library folder inside the instance."));
|
|
|
|
return;
|
|
|
|
}
|
2017-07-24 08:01:37 +01:00
|
|
|
if (!QFile::copy(entry->getFullPath(), FS::PathCombine(inst->libDir(), lib.filename)))
|
2016-08-14 01:33:31 +01:00
|
|
|
{
|
|
|
|
emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.filename));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
progress(index, fmlLibsToProcess.size());
|
|
|
|
}
|
|
|
|
emitSucceeded();
|
|
|
|
}
|
|
|
|
void FMLLibrariesTask::fmllibsFailed(QString reason)
|
|
|
|
{
|
|
|
|
QStringList failed = downloadJob->getFailedFiles();
|
|
|
|
QString failed_all = failed.join("\n");
|
|
|
|
emitFailed(tr("Failed to download the following files:\n%1\n\nReason:%2\nPlease try again.").arg(failed_all, reason));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FMLLibrariesTask::abort()
|
|
|
|
{
|
|
|
|
if(downloadJob)
|
|
|
|
{
|
|
|
|
return downloadJob->abort();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << "Prematurely aborted FMLLibrariesTask";
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|