2013-12-20 13:47:26 +00:00
|
|
|
#include "OneSixFTBInstance.h"
|
|
|
|
|
|
|
|
#include "OneSixVersion.h"
|
|
|
|
#include "OneSixLibrary.h"
|
|
|
|
#include "tasks/SequentialTask.h"
|
|
|
|
#include "ForgeInstaller.h"
|
|
|
|
#include "lists/ForgeVersionList.h"
|
2014-02-21 17:01:06 +00:00
|
|
|
#include "OneSixInstance_p.h"
|
2014-02-21 18:15:59 +00:00
|
|
|
#include "OneSixVersionBuilder.h"
|
2013-12-20 13:47:26 +00:00
|
|
|
#include "MultiMC.h"
|
2014-02-21 18:15:59 +00:00
|
|
|
#include "pathutils.h"
|
2013-12-20 13:47:26 +00:00
|
|
|
|
|
|
|
class OneSixFTBInstanceForge : public Task
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit OneSixFTBInstanceForge(const QString &version, OneSixFTBInstance *inst, QObject *parent = 0) :
|
|
|
|
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 04:15:26 +00:00
|
|
|
{
|
|
|
|
emitFailed(QString("Couldn't find forge version ") + version );
|
2013-12-20 13:47:26 +00:00
|
|
|
return;
|
2013-12-22 04:15:26 +00:00
|
|
|
}
|
2013-12-20 13:47:26 +00:00
|
|
|
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);});
|
|
|
|
connect(fjob, &NetJob::succeeded, this, &OneSixFTBInstanceForge::installForge);
|
|
|
|
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 18:20:07 +00:00
|
|
|
if (!instance->reloadVersion())
|
2013-12-20 13:47:26 +00:00
|
|
|
{
|
|
|
|
emitFailed(tr("Couldn't load the version config"));
|
|
|
|
return;
|
|
|
|
}
|
2013-12-22 03:31:30 +00:00
|
|
|
auto version = instance->getFullVersion();
|
2014-01-23 20:31:41 +00:00
|
|
|
if (!forge.add(instance))
|
2013-12-20 13:47:26 +00:00
|
|
|
{
|
|
|
|
emitFailed(tr("Couldn't install Forge"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
emitSucceeded();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
OneSixFTBInstance *instance;
|
|
|
|
QString version;
|
|
|
|
ForgeVersionPtr forgeVersion;
|
|
|
|
MetaEntryPtr entry;
|
|
|
|
NetJob *fjob;
|
|
|
|
};
|
|
|
|
|
|
|
|
OneSixFTBInstance::OneSixFTBInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) :
|
|
|
|
OneSixInstance(rootDir, settings, parent)
|
|
|
|
{
|
2014-02-21 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OneSixFTBInstance::init()
|
|
|
|
{
|
|
|
|
reloadVersion();
|
2013-12-20 13:47:26 +00:00
|
|
|
}
|
|
|
|
|
2014-02-21 18:15:59 +00:00
|
|
|
void OneSixFTBInstance::copy(const QDir &newDir)
|
|
|
|
{
|
|
|
|
QStringList libraryNames;
|
|
|
|
// create patch file
|
|
|
|
{
|
|
|
|
QLOG_DEBUG() << "Creating patch file for FTB instance...";
|
|
|
|
QFile f(minecraftRoot() + "/pack.json");
|
|
|
|
if (!f.open(QFile::ReadOnly))
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << "Couldn't open" << f.fileName() << ":" << f.errorString();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QJsonObject root = QJsonDocument::fromJson(f.readAll()).object();
|
|
|
|
QJsonArray libs = root.value("libraries").toArray();
|
|
|
|
QJsonArray outLibs;
|
|
|
|
for (auto lib : libs)
|
|
|
|
{
|
|
|
|
QJsonObject libObj = lib.toObject();
|
|
|
|
libObj.insert("MMC-hint", QString("local"));
|
|
|
|
libObj.insert("insert", QString("prepend"));
|
|
|
|
libraryNames.append(libObj.value("name").toString());
|
|
|
|
outLibs.append(libObj);
|
|
|
|
}
|
|
|
|
root.remove("libraries");
|
|
|
|
root.remove("id");
|
|
|
|
root.insert("+libraries", outLibs);
|
|
|
|
root.insert("order", 1);
|
|
|
|
root.insert("fileId", QString("org.multimc.ftb.pack.json"));
|
|
|
|
root.insert("name", name());
|
|
|
|
root.insert("mcVersion", intendedVersionId());
|
|
|
|
root.insert("version", intendedVersionId());
|
|
|
|
ensureFilePathExists(newDir.absoluteFilePath("patches/ftb.json"));
|
|
|
|
QFile out(newDir.absoluteFilePath("patches/ftb.json"));
|
|
|
|
if (!out.open(QFile::WriteOnly | QFile::Truncate))
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << "Couldn't open" << out.fileName() << ":" << out.errorString();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
out.write(QJsonDocument(root).toJson());
|
|
|
|
}
|
|
|
|
// copy libraries
|
|
|
|
{
|
|
|
|
QLOG_DEBUG() << "Copying FTB libraries";
|
|
|
|
for (auto library : libraryNames)
|
|
|
|
{
|
|
|
|
OneSixLibrary *lib = new OneSixLibrary(library);
|
|
|
|
lib->finalize();
|
|
|
|
const QString out = QDir::current().absoluteFilePath("libraries/" + lib->storagePath());
|
|
|
|
if (QFile::exists(out))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!ensureFilePathExists(out))
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << "Couldn't create folder structure for" << out;
|
|
|
|
}
|
|
|
|
if (!QFile::copy(librariesPath().absoluteFilePath(lib->storagePath()), out))
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << "Couldn't copy" << lib->rawName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-15 21:49:37 +00:00
|
|
|
QString OneSixFTBInstance::id() const
|
|
|
|
{
|
|
|
|
return "FTB/" + BaseInstance::id();
|
|
|
|
}
|
|
|
|
|
2014-02-20 16:06:32 +00:00
|
|
|
QDir OneSixFTBInstance::librariesPath() const
|
|
|
|
{
|
|
|
|
return QDir(MMC->settings()->get("FTBRoot").toString() + "/libraries");
|
|
|
|
}
|
|
|
|
QDir OneSixFTBInstance::versionsPath() const
|
|
|
|
{
|
|
|
|
return QDir(MMC->settings()->get("FTBRoot").toString() + "/versions");
|
|
|
|
}
|
|
|
|
|
2014-02-21 17:01:06 +00:00
|
|
|
QStringList OneSixFTBInstance::externalPatches() const
|
|
|
|
{
|
|
|
|
I_D(OneSixInstance);
|
|
|
|
return QStringList() << versionsPath().absoluteFilePath(intendedVersionId() + "/" + intendedVersionId() + ".json")
|
|
|
|
<< minecraftRoot() + "/pack.json";
|
|
|
|
}
|
|
|
|
|
2014-02-21 18:15:59 +00:00
|
|
|
bool OneSixFTBInstance::providesVersionFile() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-20 13:47:26 +00:00
|
|
|
QString OneSixFTBInstance::getStatusbarDescription()
|
|
|
|
{
|
|
|
|
return "OneSix FTB: " + intendedVersionId();
|
|
|
|
}
|
|
|
|
bool OneSixFTBInstance::menuActionEnabled(QString action_name) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-27 02:00:49 +00:00
|
|
|
std::shared_ptr<Task> OneSixFTBInstance::doUpdate()
|
2013-12-20 13:47:26 +00:00
|
|
|
{
|
2014-02-21 17:01:06 +00:00
|
|
|
return OneSixInstance::doUpdate();
|
2013-12-20 13:47:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "OneSixFTBInstance.moc"
|