pollymc/logic/ftb/OneSixFTBInstance.cpp

143 lines
4.0 KiB
C++
Raw Normal View History

#include "OneSixFTBInstance.h"
#include "FTBProfileStrategy.h"
2015-02-09 06:21:14 +05:30
#include "minecraft/MinecraftProfile.h"
#include "minecraft/OneSixLibrary.h"
#include "tasks/SequentialTask.h"
#include "forge/ForgeInstaller.h"
#include "forge/ForgeVersionList.h"
#include <settings/INISettingsObject.h>
2014-02-21 23:45:59 +05:30
#include "pathutils.h"
2015-02-01 07:38:25 +05:30
OneSixFTBInstance::OneSixFTBInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) :
OneSixInstance(globalSettings, settings, rootDir)
{
m_globalSettings = globalSettings;
}
2014-02-21 23:45:59 +05:30
void OneSixFTBInstance::copy(const QDir &newDir)
{
QStringList libraryNames;
// create patch file
{
qDebug()<< "Creating patch file for FTB instance...";
2014-02-21 23:45:59 +05:30
QFile f(minecraftRoot() + "/pack.json");
if (!f.open(QFile::ReadOnly))
{
qCritical() << "Couldn't open" << f.fileName() << ":" << f.errorString();
2014-02-21 23:45:59 +05:30
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");
// 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 23:45:59 +05:30
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))
{
qCritical() << "Couldn't open" << out.fileName() << ":" << out.errorString();
2014-02-21 23:45:59 +05:30
return;
}
out.write(QJsonDocument(root).toJson());
}
// copy libraries
{
qDebug() << "Copying FTB libraries";
2014-02-21 23:45:59 +05:30
for (auto library : libraryNames)
{
OneSixLibrary *lib = new OneSixLibrary(library);
const QString out = QDir::current().absoluteFilePath("libraries/" + lib->storagePath());
if (QFile::exists(out))
{
continue;
}
if (!ensureFilePathExists(out))
{
qCritical() << "Couldn't create folder structure for" << out;
2014-02-21 23:45:59 +05:30
}
if (!QFile::copy(librariesPath().absoluteFilePath(lib->storagePath()), out))
{
qCritical() << "Couldn't copy" << lib->rawName();
2014-02-21 23:45:59 +05:30
}
}
}
// 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 23:45:59 +05:30
}
QString OneSixFTBInstance::id() const
{
return "FTB/" + BaseInstance::id();
}
QDir OneSixFTBInstance::librariesPath() const
{
return QDir(m_globalSettings->get("FTBRoot").toString() + "/libraries");
}
QDir OneSixFTBInstance::versionsPath() const
{
return QDir(m_globalSettings->get("FTBRoot").toString() + "/versions");
}
bool OneSixFTBInstance::providesVersionFile() const
{
return true;
}
void OneSixFTBInstance::createProfile()
2014-02-21 23:45:59 +05:30
{
m_version.reset(new MinecraftProfile(new FTBProfileStrategy(this)));
2014-02-21 23:45:59 +05:30
}
QString OneSixFTBInstance::getStatusbarDescription()
{
2014-09-06 21:46:56 +05:30
if (flags() & VersionBrokenFlag)
{
return "OneSix FTB: " + intendedVersionId() + " (broken)";
}
return "OneSix FTB: " + intendedVersionId();
}
std::shared_ptr<Task> OneSixFTBInstance::doUpdate()
{
return OneSixInstance::doUpdate();
}
#include "OneSixFTBInstance.moc"