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"
|
2017-10-12 02:34:24 +05:30
|
|
|
#include "minecraft/ComponentList.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
|
|
|
{
|
|
|
|
m_inst = inst;
|
|
|
|
}
|
|
|
|
void FMLLibrariesTask::executeTask()
|
|
|
|
{
|
|
|
|
// Get the mod list
|
2017-07-24 12:31:37 +05:30
|
|
|
MinecraftInstance *inst = (MinecraftInstance *)m_inst;
|
2017-11-05 03:25:25 +05:30
|
|
|
auto components = inst->getComponentList();
|
|
|
|
auto profile = components->getProfile();
|
2016-08-14 06:03:31 +05:30
|
|
|
|
|
|
|
if (!profile->hasTrait("legacyFML"))
|
|
|
|
{
|
|
|
|
emitSucceeded();
|
2017-07-07 23:20:24 +05:30
|
|
|
return;
|
2016-08-14 06:03:31 +05:30
|
|
|
}
|
|
|
|
|
2017-11-11 06:08:31 +05:30
|
|
|
QString version = components->getComponentVersion("net.minecraft");
|
2016-08-14 06:03:31 +05:30
|
|
|
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-04 02:41:52 +05:30
|
|
|
setStatus(tr("Checking for FML libraries..."));
|
2017-11-11 06:08:31 +05:30
|
|
|
if(!components->getComponent("net.minecraftforge"))
|
2016-08-14 06:03:31 +05:30
|
|
|
{
|
|
|
|
emitSucceeded();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now check the lib folder inside the instance for files.
|
|
|
|
for (auto &lib : libList)
|
|
|
|
{
|
2017-07-24 12:31:37 +05:30
|
|
|
QFileInfo libInfo(FS::PathCombine(inst->libDir(), lib.filename));
|
2016-08-14 06:03:31 +05:30
|
|
|
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
|
2017-05-04 02:41:52 +05:30
|
|
|
setStatus(tr("Dowloading FML libraries..."));
|
2016-08-14 06:03:31 +05:30
|
|
|
auto dljob = new NetJob("FML libraries");
|
|
|
|
auto metacache = ENV.metacache();
|
|
|
|
for (auto &lib : fmlLibsToProcess)
|
|
|
|
{
|
|
|
|
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
|
|
|
|
QString urlString = lib.ours ? URLConstants::FMLLIBS_OUR_BASE_URL + lib.filename
|
|
|
|
: URLConstants::FMLLIBS_FORGE_BASE_URL + lib.filename;
|
|
|
|
dljob->addNetAction(Net::Download::makeCached(QUrl(urlString), entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FMLLibrariesTask::canAbort() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FMLLibrariesTask::fmllibsFinished()
|
|
|
|
{
|
|
|
|
downloadJob.reset();
|
|
|
|
if (!fmlLibsToProcess.isEmpty())
|
|
|
|
{
|
2017-05-04 02:41:52 +05:30
|
|
|
setStatus(tr("Copying FML libraries into the instance..."));
|
2017-07-24 12:31:37 +05:30
|
|
|
MinecraftInstance *inst = (MinecraftInstance *)m_inst;
|
2016-08-14 06:03:31 +05:30
|
|
|
auto metacache = ENV.metacache();
|
|
|
|
int index = 0;
|
|
|
|
for (auto &lib : fmlLibsToProcess)
|
|
|
|
{
|
|
|
|
progress(index, fmlLibsToProcess.size());
|
|
|
|
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
|
2017-07-24 12:31:37 +05:30
|
|
|
auto path = FS::PathCombine(inst->libDir(), lib.filename);
|
2016-08-14 06:03:31 +05:30
|
|
|
if (!FS::ensureFilePathExists(path))
|
|
|
|
{
|
|
|
|
emitFailed(tr("Failed creating FML library folder inside the instance."));
|
|
|
|
return;
|
|
|
|
}
|
2017-07-24 12:31:37 +05:30
|
|
|
if (!QFile::copy(entry->getFullPath(), FS::PathCombine(inst->libDir(), lib.filename)))
|
2016-08-14 06:03:31 +05:30
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|