2016-08-14 06:03:31 +05:30
|
|
|
#include "Env.h"
|
|
|
|
#include <FileSystem.h>
|
|
|
|
#include <minecraft/VersionFilterData.h>
|
|
|
|
#include "FMLLibrariesTask.h"
|
2017-07-24 12:31:37 +05:30
|
|
|
#include "minecraft/MinecraftInstance.h"
|
2020-06-27 15:32:31 +05:30
|
|
|
#include "minecraft/PackProfile.h"
|
2020-07-18 19:48:02 +05:30
|
|
|
#include "BuildConfig.h"
|
2016-08-14 06:03:31 +05:30
|
|
|
|
2017-07-24 12:31:37 +05:30
|
|
|
FMLLibrariesTask::FMLLibrariesTask(MinecraftInstance * inst)
|
2016-08-14 06:03:31 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
m_inst = inst;
|
2016-08-14 06:03:31 +05:30
|
|
|
}
|
|
|
|
void FMLLibrariesTask::executeTask()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
// Get the mod list
|
|
|
|
MinecraftInstance *inst = (MinecraftInstance *)m_inst;
|
2020-06-27 15:32:31 +05:30
|
|
|
auto components = inst->getPackProfile();
|
2018-07-15 18:21:05 +05:30
|
|
|
auto profile = components->getProfile();
|
2016-08-14 06:03:31 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
if (!profile->hasTrait("legacyFML"))
|
|
|
|
{
|
|
|
|
emitSucceeded();
|
|
|
|
return;
|
|
|
|
}
|
2016-08-14 06:03:31 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
QString version = components->getComponentVersion("net.minecraft");
|
|
|
|
auto &fmlLibsMapping = g_VersionFilterData.fmlLibsMapping;
|
|
|
|
if (!fmlLibsMapping.contains(version))
|
|
|
|
{
|
|
|
|
emitSucceeded();
|
|
|
|
return;
|
|
|
|
}
|
2016-08-14 06:03:31 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
auto &libList = fmlLibsMapping[version];
|
2016-08-14 06:03:31 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
// determine if we need some libs for FML or forge
|
|
|
|
setStatus(tr("Checking for FML libraries..."));
|
|
|
|
if(!components->getComponent("net.minecraftforge"))
|
|
|
|
{
|
|
|
|
emitSucceeded();
|
|
|
|
return;
|
|
|
|
}
|
2016-08-14 06:03:31 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
// now check the lib folder inside the instance for files.
|
|
|
|
for (auto &lib : libList)
|
|
|
|
{
|
|
|
|
QFileInfo libInfo(FS::PathCombine(inst->libDir(), lib.filename));
|
|
|
|
if (libInfo.exists())
|
|
|
|
continue;
|
|
|
|
fmlLibsToProcess.append(lib);
|
|
|
|
}
|
2016-08-14 06:03:31 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
// if everything is in place, there's nothing to do here...
|
|
|
|
if (fmlLibsToProcess.isEmpty())
|
|
|
|
{
|
|
|
|
emitSucceeded();
|
|
|
|
return;
|
|
|
|
}
|
2016-08-14 06:03:31 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
// download missing libs to our place
|
|
|
|
setStatus(tr("Dowloading FML libraries..."));
|
|
|
|
auto dljob = new NetJob("FML libraries");
|
|
|
|
auto metacache = ENV.metacache();
|
|
|
|
for (auto &lib : fmlLibsToProcess)
|
|
|
|
{
|
|
|
|
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
|
2020-07-18 19:48:02 +05:30
|
|
|
QString urlString = (lib.ours ? BuildConfig.FMLLIBS_OUR_BASE_URL : BuildConfig.FMLLIBS_FORGE_BASE_URL) + lib.filename;
|
2018-07-15 18:21:05 +05:30
|
|
|
dljob->addNetAction(Net::Download::makeCached(QUrl(urlString), entry));
|
|
|
|
}
|
2016-08-14 06:03:31 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
connect(dljob, &NetJob::succeeded, this, &FMLLibrariesTask::fmllibsFinished);
|
|
|
|
connect(dljob, &NetJob::failed, this, &FMLLibrariesTask::fmllibsFailed);
|
|
|
|
connect(dljob, &NetJob::progress, this, &FMLLibrariesTask::progress);
|
|
|
|
downloadJob.reset(dljob);
|
|
|
|
downloadJob->start();
|
2016-08-14 06:03:31 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool FMLLibrariesTask::canAbort() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return true;
|
2016-08-14 06:03:31 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void FMLLibrariesTask::fmllibsFinished()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
downloadJob.reset();
|
|
|
|
if (!fmlLibsToProcess.isEmpty())
|
|
|
|
{
|
|
|
|
setStatus(tr("Copying FML libraries into the instance..."));
|
|
|
|
MinecraftInstance *inst = (MinecraftInstance *)m_inst;
|
|
|
|
auto metacache = ENV.metacache();
|
|
|
|
int index = 0;
|
|
|
|
for (auto &lib : fmlLibsToProcess)
|
|
|
|
{
|
|
|
|
progress(index, fmlLibsToProcess.size());
|
|
|
|
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
|
|
|
|
auto path = FS::PathCombine(inst->libDir(), lib.filename);
|
|
|
|
if (!FS::ensureFilePathExists(path))
|
|
|
|
{
|
|
|
|
emitFailed(tr("Failed creating FML library folder inside the instance."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!QFile::copy(entry->getFullPath(), FS::PathCombine(inst->libDir(), lib.filename)))
|
|
|
|
{
|
|
|
|
emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.filename));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
progress(index, fmlLibsToProcess.size());
|
|
|
|
}
|
|
|
|
emitSucceeded();
|
2016-08-14 06:03:31 +05:30
|
|
|
}
|
|
|
|
void FMLLibrariesTask::fmllibsFailed(QString reason)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
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));
|
2016-08-14 06:03:31 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool FMLLibrariesTask::abort()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(downloadJob)
|
|
|
|
{
|
|
|
|
return downloadJob->abort();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << "Prematurely aborted FMLLibrariesTask";
|
|
|
|
}
|
|
|
|
return true;
|
2016-08-14 06:03:31 +05:30
|
|
|
}
|