2013-12-20 13:47:26 +00:00
|
|
|
#include "OneSixFTBInstance.h"
|
2015-04-03 09:55:16 +00:00
|
|
|
#include "FTBProfileStrategy.h"
|
2013-12-20 13:47:26 +00:00
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "minecraft/MinecraftProfile.h"
|
2016-02-26 01:04:21 +00:00
|
|
|
#include "minecraft/GradleSpecifier.h"
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "tasks/SequentialTask.h"
|
|
|
|
#include <settings/INISettingsObject.h>
|
2015-10-04 23:47:27 +00:00
|
|
|
#include <FileSystem.h>
|
2013-12-20 13:47:26 +00:00
|
|
|
|
2016-02-27 18:58:40 +00:00
|
|
|
#include <QJsonArray>
|
|
|
|
|
2015-02-01 02:08:25 +00:00
|
|
|
OneSixFTBInstance::OneSixFTBInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) :
|
|
|
|
OneSixInstance(globalSettings, settings, rootDir)
|
2013-12-20 13:47:26 +00:00
|
|
|
{
|
2015-02-02 00:09:28 +00:00
|
|
|
m_globalSettings = globalSettings;
|
2014-02-21 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
2014-02-21 18:15:59 +00:00
|
|
|
void OneSixFTBInstance::copy(const QDir &newDir)
|
|
|
|
{
|
|
|
|
QStringList libraryNames;
|
|
|
|
// create patch file
|
|
|
|
{
|
2015-02-02 01:14:14 +00:00
|
|
|
qDebug()<< "Creating patch file for FTB instance...";
|
2014-02-21 18:15:59 +00:00
|
|
|
QFile f(minecraftRoot() + "/pack.json");
|
|
|
|
if (!f.open(QFile::ReadOnly))
|
|
|
|
{
|
2015-02-02 01:14:14 +00:00
|
|
|
qCritical() << "Couldn't open" << f.fileName() << ":" << f.errorString();
|
2014-02-21 18:15:59 +00:00
|
|
|
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");
|
2014-11-17 20:45:29 +00:00
|
|
|
|
|
|
|
// HACK HACK HACK HACK
|
|
|
|
// A workaround for a problem in MultiMC, triggered by a historical problem in FTB,
|
|
|
|
// triggered by Mojang getting their library versions wrong in 1.7.10
|
|
|
|
if(intendedVersionId() == "1.7.10")
|
|
|
|
{
|
|
|
|
auto insert = [&outLibs, &libraryNames](QString name)
|
|
|
|
{
|
|
|
|
QJsonObject libObj;
|
|
|
|
libObj.insert("insert", QString("replace"));
|
|
|
|
libObj.insert("name", name);
|
|
|
|
libraryNames.push_back(name);
|
|
|
|
outLibs.prepend(libObj);
|
|
|
|
};
|
|
|
|
insert("com.google.guava:guava:16.0");
|
|
|
|
insert("org.apache.commons:commons-lang3:3.2.1");
|
|
|
|
}
|
2014-02-21 18:15:59 +00:00
|
|
|
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());
|
2015-10-04 23:47:27 +00:00
|
|
|
FS::ensureFilePathExists(newDir.absoluteFilePath("patches/ftb.json"));
|
2014-02-21 18:15:59 +00:00
|
|
|
QFile out(newDir.absoluteFilePath("patches/ftb.json"));
|
|
|
|
if (!out.open(QFile::WriteOnly | QFile::Truncate))
|
|
|
|
{
|
2015-02-02 01:14:14 +00:00
|
|
|
qCritical() << "Couldn't open" << out.fileName() << ":" << out.errorString();
|
2014-02-21 18:15:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
out.write(QJsonDocument(root).toJson());
|
|
|
|
}
|
|
|
|
// copy libraries
|
|
|
|
{
|
2015-02-02 01:14:14 +00:00
|
|
|
qDebug() << "Copying FTB libraries";
|
2014-02-21 18:15:59 +00:00
|
|
|
for (auto library : libraryNames)
|
|
|
|
{
|
2016-02-26 01:04:21 +00:00
|
|
|
GradleSpecifier lib(library);
|
|
|
|
const QString out = QDir::current().absoluteFilePath("libraries/" + lib.toPath());
|
2014-02-21 18:15:59 +00:00
|
|
|
if (QFile::exists(out))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2015-10-04 23:47:27 +00:00
|
|
|
if (!FS::ensureFilePathExists(out))
|
2014-02-21 18:15:59 +00:00
|
|
|
{
|
2015-02-02 01:14:14 +00:00
|
|
|
qCritical() << "Couldn't create folder structure for" << out;
|
2014-02-21 18:15:59 +00:00
|
|
|
}
|
2016-02-26 01:04:21 +00:00
|
|
|
if (!QFile::copy(librariesPath().absoluteFilePath(lib.toPath()), out))
|
2014-02-21 18:15:59 +00:00
|
|
|
{
|
2016-02-26 01:04:21 +00:00
|
|
|
qCritical() << "Couldn't copy" << QString(lib);
|
2014-02-21 18:15:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-04 13:46:15 +00:00
|
|
|
// now set the target instance to be plain OneSix
|
|
|
|
INISettingsObject settings_obj(newDir.absoluteFilePath("instance.cfg"));
|
|
|
|
settings_obj.registerSetting("InstanceType", "Legacy");
|
|
|
|
QString inst_type = settings_obj.get("InstanceType").toString();
|
|
|
|
settings_obj.set("InstanceType", "OneSix");
|
2014-02-21 18:15:59 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2015-02-02 00:09:28 +00:00
|
|
|
return QDir(m_globalSettings->get("FTBRoot").toString() + "/libraries");
|
2014-02-20 16:06:32 +00:00
|
|
|
}
|
2014-05-08 17:05:07 +00:00
|
|
|
|
2014-02-20 16:06:32 +00:00
|
|
|
QDir OneSixFTBInstance::versionsPath() const
|
|
|
|
{
|
2015-02-02 00:09:28 +00:00
|
|
|
return QDir(m_globalSettings->get("FTBRoot").toString() + "/versions");
|
2014-02-20 16:06:32 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 09:55:16 +00:00
|
|
|
bool OneSixFTBInstance::providesVersionFile() const
|
2014-02-21 17:01:06 +00:00
|
|
|
{
|
2015-04-03 09:55:16 +00:00
|
|
|
return true;
|
2014-02-21 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 09:55:16 +00:00
|
|
|
void OneSixFTBInstance::createProfile()
|
2014-02-21 18:15:59 +00:00
|
|
|
{
|
2015-04-03 09:55:16 +00:00
|
|
|
m_version.reset(new MinecraftProfile(new FTBProfileStrategy(this)));
|
2014-02-21 18:15:59 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 23:06:45 +00:00
|
|
|
std::shared_ptr<Task> OneSixFTBInstance::createUpdateTask()
|
2013-12-20 13:47:26 +00:00
|
|
|
{
|
2015-09-21 23:06:45 +00:00
|
|
|
return OneSixInstance::createUpdateTask();
|
2013-12-20 13:47:26 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 23:06:45 +00:00
|
|
|
QString OneSixFTBInstance::typeName() const
|
2013-12-20 13:47:26 +00:00
|
|
|
{
|
2015-09-21 23:06:45 +00:00
|
|
|
return tr("OneSix FTB");
|
2013-12-20 13:47:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "OneSixFTBInstance.moc"
|