@ -1,53 +1,49 @@
|
||||
#include "FMLLibrariesTask.h"
|
||||
|
||||
#include "FileSystem.h"
|
||||
#include "minecraft/VersionFilterData.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "minecraft/VersionFilterData.h"
|
||||
|
||||
#include "BuildConfig.h"
|
||||
#include "Application.h"
|
||||
#include "BuildConfig.h"
|
||||
|
||||
#include "net/ApiDownload.h"
|
||||
|
||||
FMLLibrariesTask::FMLLibrariesTask(MinecraftInstance * inst)
|
||||
FMLLibrariesTask::FMLLibrariesTask(MinecraftInstance* inst)
|
||||
{
|
||||
m_inst = inst;
|
||||
}
|
||||
void FMLLibrariesTask::executeTask()
|
||||
{
|
||||
// Get the mod list
|
||||
MinecraftInstance *inst = (MinecraftInstance *)m_inst;
|
||||
MinecraftInstance* inst = (MinecraftInstance*)m_inst;
|
||||
auto components = inst->getPackProfile();
|
||||
auto profile = components->getProfile();
|
||||
|
||||
if (!profile->hasTrait("legacyFML"))
|
||||
{
|
||||
if (!profile->hasTrait("legacyFML")) {
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
|
||||
QString version = components->getComponentVersion("net.minecraft");
|
||||
auto &fmlLibsMapping = g_VersionFilterData.fmlLibsMapping;
|
||||
if (!fmlLibsMapping.contains(version))
|
||||
{
|
||||
auto& fmlLibsMapping = g_VersionFilterData.fmlLibsMapping;
|
||||
if (!fmlLibsMapping.contains(version)) {
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
|
||||
auto &libList = fmlLibsMapping[version];
|
||||
auto& libList = fmlLibsMapping[version];
|
||||
|
||||
// determine if we need some libs for FML or forge
|
||||
setStatus(tr("Checking for FML libraries..."));
|
||||
if(!components->getComponent("net.minecraftforge"))
|
||||
{
|
||||
if (!components->getComponent("net.minecraftforge")) {
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
|
||||
// now check the lib folder inside the instance for files.
|
||||
for (auto &lib : libList)
|
||||
{
|
||||
for (auto& lib : libList) {
|
||||
QFileInfo libInfo(FS::PathCombine(inst->libDir(), lib.filename));
|
||||
if (libInfo.exists())
|
||||
continue;
|
||||
@ -55,8 +51,7 @@ void FMLLibrariesTask::executeTask()
|
||||
}
|
||||
|
||||
// if everything is in place, there's nothing to do here...
|
||||
if (fmlLibsToProcess.isEmpty())
|
||||
{
|
||||
if (fmlLibsToProcess.isEmpty()) {
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
@ -66,8 +61,7 @@ void FMLLibrariesTask::executeTask()
|
||||
NetJob::Ptr dljob{ new NetJob("FML libraries", APPLICATION->network()) };
|
||||
auto metacache = APPLICATION->metacache();
|
||||
Net::Download::Options options = Net::Download::Option::MakeEternal;
|
||||
for (auto &lib : fmlLibsToProcess)
|
||||
{
|
||||
for (auto& lib : fmlLibsToProcess) {
|
||||
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
|
||||
QString urlString = BuildConfig.FMLLIBS_BASE_URL + lib.filename;
|
||||
dljob->addNetAction(Net::ApiDownload::makeCached(QUrl(urlString), entry, options));
|
||||
@ -75,7 +69,7 @@ void FMLLibrariesTask::executeTask()
|
||||
|
||||
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::aborted, this, [this] { emitFailed(tr("Aborted")); });
|
||||
connect(dljob.get(), &NetJob::progress, this, &FMLLibrariesTask::progress);
|
||||
connect(dljob.get(), &NetJob::stepProgress, this, &FMLLibrariesTask::propagateStepProgress);
|
||||
downloadJob.reset(dljob);
|
||||
@ -90,24 +84,20 @@ bool FMLLibrariesTask::canAbort() const
|
||||
void FMLLibrariesTask::fmllibsFinished()
|
||||
{
|
||||
downloadJob.reset();
|
||||
if (!fmlLibsToProcess.isEmpty())
|
||||
{
|
||||
if (!fmlLibsToProcess.isEmpty()) {
|
||||
setStatus(tr("Copying FML libraries into the instance..."));
|
||||
MinecraftInstance *inst = (MinecraftInstance *)m_inst;
|
||||
MinecraftInstance* inst = (MinecraftInstance*)m_inst;
|
||||
auto metacache = APPLICATION->metacache();
|
||||
int index = 0;
|
||||
for (auto &lib : fmlLibsToProcess)
|
||||
{
|
||||
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))
|
||||
{
|
||||
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)))
|
||||
{
|
||||
if (!QFile::copy(entry->getFullPath(), FS::PathCombine(inst->libDir(), lib.filename))) {
|
||||
emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.filename));
|
||||
return;
|
||||
}
|
||||
@ -126,12 +116,9 @@ void FMLLibrariesTask::fmllibsFailed(QString reason)
|
||||
|
||||
bool FMLLibrariesTask::abort()
|
||||
{
|
||||
if(downloadJob)
|
||||
{
|
||||
if (downloadJob) {
|
||||
return downloadJob->abort();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
qWarning() << "Prematurely aborted FMLLibrariesTask";
|
||||
}
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user