2014-01-24 22:42:02 +05:30
|
|
|
#include "OneSixFTBInstance.h"
|
2013-12-20 19:17:26 +05:30
|
|
|
|
2014-01-24 22:42:02 +05:30
|
|
|
#include "OneSixVersion.h"
|
|
|
|
#include "OneSixLibrary.h"
|
2013-12-20 19:17:26 +05:30
|
|
|
#include "tasks/SequentialTask.h"
|
|
|
|
#include "ForgeInstaller.h"
|
|
|
|
#include "lists/ForgeVersionList.h"
|
|
|
|
#include "MultiMC.h"
|
|
|
|
|
2014-01-24 22:42:02 +05:30
|
|
|
class OneSixFTBInstanceForge : public Task
|
2013-12-20 19:17:26 +05:30
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-01-24 22:42:02 +05:30
|
|
|
explicit OneSixFTBInstanceForge(const QString &version, OneSixFTBInstance *inst, QObject *parent = 0) :
|
2013-12-20 19:17:26 +05:30
|
|
|
Task(parent), instance(inst), version("Forge " + version)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void executeTask()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < MMC->forgelist()->count(); ++i)
|
|
|
|
{
|
|
|
|
if (MMC->forgelist()->at(i)->name() == version)
|
|
|
|
{
|
|
|
|
forgeVersion = std::dynamic_pointer_cast<ForgeVersion>(MMC->forgelist()->at(i));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!forgeVersion)
|
2013-12-22 09:45:26 +05:30
|
|
|
{
|
|
|
|
emitFailed(QString("Couldn't find forge version ") + version );
|
2013-12-20 19:17:26 +05:30
|
|
|
return;
|
2013-12-22 09:45:26 +05:30
|
|
|
}
|
2013-12-20 19:17:26 +05:30
|
|
|
entry = MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename);
|
|
|
|
if (entry->stale)
|
|
|
|
{
|
|
|
|
setStatus(tr("Downloading Forge..."));
|
|
|
|
fjob = new NetJob("Forge download");
|
|
|
|
fjob->addNetAction(CacheDownload::make(forgeVersion->installer_url, entry));
|
|
|
|
connect(fjob, &NetJob::failed, [this](){emitFailed(m_failReason);});
|
2014-01-24 22:42:02 +05:30
|
|
|
connect(fjob, &NetJob::succeeded, this, &OneSixFTBInstanceForge::installForge);
|
2013-12-20 19:17:26 +05:30
|
|
|
connect(fjob, &NetJob::progress, [this](qint64 c, qint64 total){ setProgress(100 * c / total); });
|
|
|
|
fjob->start();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
installForge();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private
|
|
|
|
slots:
|
|
|
|
void installForge()
|
|
|
|
{
|
|
|
|
setStatus(tr("Installing Forge..."));
|
|
|
|
QString forgePath = entry->getFullPath();
|
|
|
|
ForgeInstaller forge(forgePath, forgeVersion->universal_url);
|
2014-01-27 23:50:07 +05:30
|
|
|
if (!instance->reloadVersion())
|
2013-12-20 19:17:26 +05:30
|
|
|
{
|
|
|
|
emitFailed(tr("Couldn't load the version config"));
|
|
|
|
return;
|
|
|
|
}
|
2013-12-22 09:01:30 +05:30
|
|
|
auto version = instance->getFullVersion();
|
2014-01-24 02:01:41 +05:30
|
|
|
if (!forge.add(instance))
|
2013-12-20 19:17:26 +05:30
|
|
|
{
|
|
|
|
emitFailed(tr("Couldn't install Forge"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
emitSucceeded();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-01-24 22:42:02 +05:30
|
|
|
OneSixFTBInstance *instance;
|
2013-12-20 19:17:26 +05:30
|
|
|
QString version;
|
|
|
|
ForgeVersionPtr forgeVersion;
|
|
|
|
MetaEntryPtr entry;
|
|
|
|
NetJob *fjob;
|
|
|
|
};
|
|
|
|
|
2014-01-24 22:42:02 +05:30
|
|
|
OneSixFTBInstance::OneSixFTBInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) :
|
|
|
|
OneSixInstance(rootDir, settings, parent)
|
2013-12-20 19:17:26 +05:30
|
|
|
{
|
|
|
|
QFile f(QDir(minecraftRoot()).absoluteFilePath("pack.json"));
|
|
|
|
if (f.open(QFile::ReadOnly))
|
|
|
|
{
|
|
|
|
QString data = QString::fromUtf8(f.readAll());
|
|
|
|
QRegularExpressionMatch match = QRegularExpression("net.minecraftforge:minecraftforge:[\\.\\d]*").match(data);
|
2014-01-24 22:42:02 +05:30
|
|
|
m_forge.reset(new OneSixLibrary(match.captured()));
|
2013-12-20 19:17:26 +05:30
|
|
|
m_forge->finalize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-24 22:42:02 +05:30
|
|
|
QString OneSixFTBInstance::id() const
|
2014-01-16 03:19:37 +05:30
|
|
|
{
|
|
|
|
return "FTB/" + BaseInstance::id();
|
|
|
|
}
|
|
|
|
|
2014-01-24 22:42:02 +05:30
|
|
|
QString OneSixFTBInstance::getStatusbarDescription()
|
2013-12-20 19:17:26 +05:30
|
|
|
{
|
2014-01-24 22:42:02 +05:30
|
|
|
return "OneSix FTB: " + intendedVersionId();
|
2013-12-20 19:17:26 +05:30
|
|
|
}
|
2014-01-24 22:42:02 +05:30
|
|
|
bool OneSixFTBInstance::menuActionEnabled(QString action_name) const
|
2013-12-20 19:17:26 +05:30
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-24 22:42:02 +05:30
|
|
|
std::shared_ptr<Task> OneSixFTBInstance::doUpdate(bool only_prepare)
|
2013-12-20 19:17:26 +05:30
|
|
|
{
|
|
|
|
std::shared_ptr<SequentialTask> task;
|
|
|
|
task.reset(new SequentialTask(this));
|
|
|
|
if (!MMC->forgelist()->isLoaded())
|
|
|
|
{
|
|
|
|
task->addTask(std::shared_ptr<Task>(MMC->forgelist()->getLoadTask()));
|
|
|
|
}
|
2014-01-24 22:42:02 +05:30
|
|
|
task->addTask(OneSixInstance::doUpdate(only_prepare));
|
|
|
|
task->addTask(std::shared_ptr<Task>(new OneSixFTBInstanceForge(m_forge->version(), this, this)));
|
2013-12-22 10:17:10 +05:30
|
|
|
//FIXME: yes. this may appear dumb. but the previous step can change the list, so we do it all again.
|
|
|
|
//TODO: Add a graph task. Construct graphs of tasks so we may capture the logic properly.
|
2014-01-24 22:42:02 +05:30
|
|
|
task->addTask(OneSixInstance::doUpdate(only_prepare));
|
2013-12-20 19:17:26 +05:30
|
|
|
return task;
|
|
|
|
}
|
|
|
|
|
2014-01-24 22:42:02 +05:30
|
|
|
#include "OneSixFTBInstance.moc"
|