2013-09-22 03:21:36 +01:00
|
|
|
#include "ForgeInstaller.h"
|
|
|
|
#include "OneSixVersion.h"
|
|
|
|
#include "OneSixLibrary.h"
|
2013-09-22 13:00:37 +01:00
|
|
|
#include "net/HttpMetaCache.h"
|
2013-09-22 03:21:36 +01:00
|
|
|
#include <quazip.h>
|
|
|
|
#include <quazipfile.h>
|
|
|
|
#include <pathutils.h>
|
|
|
|
#include <QStringList>
|
2013-09-22 13:00:37 +01:00
|
|
|
#include "MultiMC.h"
|
2013-09-22 03:21:36 +01:00
|
|
|
|
|
|
|
ForgeInstaller::ForgeInstaller(QString filename, QString universal_url)
|
|
|
|
{
|
2013-10-06 00:13:40 +01:00
|
|
|
std::shared_ptr<OneSixVersion> newVersion;
|
2013-09-22 03:21:36 +01:00
|
|
|
m_universal_url = universal_url;
|
|
|
|
|
|
|
|
QuaZip zip(filename);
|
|
|
|
if (!zip.open(QuaZip::mdUnzip))
|
|
|
|
return;
|
|
|
|
|
|
|
|
QuaZipFile file(&zip);
|
|
|
|
|
|
|
|
// read the install profile
|
|
|
|
if (!zip.setCurrentFile("install_profile.json"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
QJsonParseError jsonError;
|
|
|
|
if (!file.open(QIODevice::ReadOnly))
|
|
|
|
return;
|
|
|
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(file.readAll(), &jsonError);
|
|
|
|
file.close();
|
|
|
|
if (jsonError.error != QJsonParseError::NoError)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!jsonDoc.isObject())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QJsonObject root = jsonDoc.object();
|
|
|
|
|
|
|
|
auto installVal = root.value("install");
|
|
|
|
auto versionInfoVal = root.value("versionInfo");
|
|
|
|
if (!installVal.isObject() || !versionInfoVal.isObject())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// read the forge version info
|
|
|
|
{
|
|
|
|
newVersion = OneSixVersion::fromJson(versionInfoVal.toObject());
|
|
|
|
if (!newVersion)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonObject installObj = installVal.toObject();
|
|
|
|
QString libraryName = installObj.value("path").toString();
|
|
|
|
internalPath = installObj.value("filePath").toString();
|
|
|
|
|
|
|
|
// where do we put the library? decode the mojang path
|
|
|
|
OneSixLibrary lib(libraryName);
|
|
|
|
lib.finalize();
|
2013-09-22 13:00:37 +01:00
|
|
|
|
|
|
|
auto cacheentry = MMC->metacache()->resolveEntry("libraries", lib.storagePath());
|
2013-09-22 03:21:36 +01:00
|
|
|
finalPath = "libraries/" + lib.storagePath();
|
|
|
|
if (!ensureFilePathExists(finalPath))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!zip.setCurrentFile(internalPath))
|
|
|
|
return;
|
|
|
|
if (!file.open(QIODevice::ReadOnly))
|
|
|
|
return;
|
|
|
|
{
|
|
|
|
QByteArray data = file.readAll();
|
|
|
|
// extract file
|
|
|
|
QSaveFile extraction(finalPath);
|
|
|
|
if (!extraction.open(QIODevice::WriteOnly))
|
|
|
|
return;
|
|
|
|
if (extraction.write(data) != data.size())
|
|
|
|
return;
|
|
|
|
if (!extraction.commit())
|
|
|
|
return;
|
2013-09-22 13:00:37 +01:00
|
|
|
QCryptographicHash md5sum(QCryptographicHash::Md5);
|
|
|
|
md5sum.addData(data);
|
|
|
|
|
|
|
|
cacheentry->stale = false;
|
|
|
|
cacheentry->md5sum = md5sum.result().toHex().constData();
|
|
|
|
MMC->metacache()->updateEntry(cacheentry);
|
2013-09-22 03:21:36 +01:00
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
m_forge_version = newVersion;
|
|
|
|
realVersionId = m_forge_version->id = installObj.value("minecraft").toString();
|
|
|
|
}
|
|
|
|
|
2013-10-06 00:13:40 +01:00
|
|
|
bool ForgeInstaller::apply(std::shared_ptr<OneSixVersion> to)
|
2013-09-22 03:21:36 +01:00
|
|
|
{
|
|
|
|
if (!m_forge_version)
|
|
|
|
return false;
|
|
|
|
to->externalUpdateStart();
|
|
|
|
int sliding_insert_window = 0;
|
|
|
|
{
|
|
|
|
// for each library in the version we are adding (except for the blacklisted)
|
|
|
|
QSet<QString> blacklist{"lwjgl", "lwjgl_util", "lwjgl-platform"};
|
|
|
|
for (auto lib : m_forge_version->libraries)
|
|
|
|
{
|
|
|
|
QString libName = lib->name();
|
2013-09-30 01:34:46 +01:00
|
|
|
// WARNING: This could actually break.
|
2013-09-22 03:21:36 +01:00
|
|
|
// if this is the actual forge lib, set an absolute url for the download
|
2013-09-22 13:00:37 +01:00
|
|
|
if (libName.contains("minecraftforge"))
|
2013-09-22 03:21:36 +01:00
|
|
|
{
|
|
|
|
lib->setAbsoluteUrl(m_universal_url);
|
|
|
|
}
|
2013-09-30 01:34:46 +01:00
|
|
|
else if (libName.contains("scala"))
|
|
|
|
{
|
|
|
|
lib->setHint("forge-pack-xz");
|
|
|
|
}
|
2013-09-22 03:21:36 +01:00
|
|
|
if (blacklist.contains(libName))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// find an entry that matches this one
|
|
|
|
bool found = false;
|
|
|
|
for (auto tolib : to->libraries)
|
|
|
|
{
|
|
|
|
if (tolib->name() != libName)
|
|
|
|
continue;
|
|
|
|
found = true;
|
|
|
|
// replace lib
|
|
|
|
tolib = lib;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
// add lib
|
|
|
|
to->libraries.insert(sliding_insert_window, lib);
|
|
|
|
sliding_insert_window++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
to->mainClass = m_forge_version->mainClass;
|
|
|
|
to->minecraftArguments = m_forge_version->minecraftArguments;
|
|
|
|
to->processArguments = m_forge_version->processArguments;
|
|
|
|
}
|
|
|
|
to->externalUpdateFinish();
|
|
|
|
return to->toOriginalFile();
|
|
|
|
}
|