2017-01-08 03:58:05 +00:00
|
|
|
/* Copyright 2013-2017 MultiMC Contributors
|
2013-11-04 01:53:05 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-09-22 03:21:36 +01:00
|
|
|
#include "ForgeInstaller.h"
|
2016-02-27 18:58:40 +00:00
|
|
|
#include "ForgeVersionList.h"
|
|
|
|
|
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 "net/HttpMetaCache.h"
|
|
|
|
#include "tasks/Task.h"
|
2016-02-27 18:58:40 +00:00
|
|
|
#include "minecraft/onesix/OneSixInstance.h"
|
2016-02-27 21:02:56 +00:00
|
|
|
#include <minecraft/onesix/OneSixVersionFormat.h>
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "minecraft/VersionFilterData.h"
|
2016-03-13 18:45:34 +00:00
|
|
|
#include "minecraft/MinecraftVersion.h"
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "Env.h"
|
2015-05-28 18:38:29 +01:00
|
|
|
#include "Exception.h"
|
2015-10-05 00:47:27 +01:00
|
|
|
#include <FileSystem.h>
|
2014-04-23 01:27:40 +01:00
|
|
|
|
2013-09-22 03:21:36 +01:00
|
|
|
#include <quazip.h>
|
|
|
|
#include <quazipfile.h>
|
|
|
|
#include <QStringList>
|
2014-01-27 18:20:07 +00:00
|
|
|
#include <QRegularExpression>
|
|
|
|
#include <QRegularExpressionMatch>
|
2015-01-31 15:59:03 +00:00
|
|
|
|
2014-01-22 06:33:32 +00:00
|
|
|
#include <QJsonDocument>
|
2014-01-23 20:31:41 +00:00
|
|
|
#include <QJsonArray>
|
2014-01-22 06:33:32 +00:00
|
|
|
#include <QSaveFile>
|
|
|
|
#include <QCryptographicHash>
|
|
|
|
|
2014-04-23 01:27:40 +01:00
|
|
|
ForgeInstaller::ForgeInstaller() : BaseInstaller()
|
2014-03-14 19:48:57 +00:00
|
|
|
{
|
|
|
|
}
|
2014-12-27 21:45:49 +00:00
|
|
|
|
2014-03-14 19:48:57 +00:00
|
|
|
void ForgeInstaller::prepare(const QString &filename, const QString &universalUrl)
|
2013-09-22 03:21:36 +01:00
|
|
|
{
|
2016-03-13 18:45:34 +00:00
|
|
|
VersionFilePtr newVersion;
|
2014-03-14 19:48:57 +00:00
|
|
|
m_universal_url = universalUrl;
|
2013-09-22 03:21:36 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2016-03-13 18:45:34 +00:00
|
|
|
try
|
2013-09-22 03:21:36 +01:00
|
|
|
{
|
2016-03-13 18:45:34 +00:00
|
|
|
newVersion = OneSixVersionFormat::versionFileFromJson(QJsonDocument(versionInfoVal.toObject()), QString(), false);
|
|
|
|
}
|
|
|
|
catch(Exception &err)
|
|
|
|
{
|
2016-03-18 14:02:54 +00:00
|
|
|
qWarning() << "Forge: Fatal error while parsing version file:" << err.what();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(auto problem: newVersion->getProblems())
|
|
|
|
{
|
|
|
|
qWarning() << "Forge: Problem found: " << problem.getDescription();
|
|
|
|
}
|
|
|
|
if(newVersion->getProblemSeverity() == ProblemSeverity::PROBLEM_ERROR)
|
|
|
|
{
|
|
|
|
qWarning() << "Forge: Errors found while parsing version file";
|
2016-03-13 18:45:34 +00:00
|
|
|
return;
|
2013-09-22 03:21:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QJsonObject installObj = installVal.toObject();
|
|
|
|
QString libraryName = installObj.value("path").toString();
|
|
|
|
internalPath = installObj.value("filePath").toString();
|
2016-04-03 21:17:06 +01:00
|
|
|
m_forgeVersionString = installObj.value("version").toString().remove("Forge", Qt::CaseInsensitive).trimmed();
|
2013-09-22 03:21:36 +01:00
|
|
|
|
|
|
|
// where do we put the library? decode the mojang path
|
2016-02-26 01:04:21 +00:00
|
|
|
GradleSpecifier lib(libraryName);
|
2013-09-22 13:00:37 +01:00
|
|
|
|
2016-02-26 01:04:21 +00:00
|
|
|
auto cacheentry = ENV.metacache()->resolveEntry("libraries", lib.toPath());
|
|
|
|
finalPath = "libraries/" + lib.toPath();
|
2015-10-05 00:47:27 +01:00
|
|
|
if (!FS::ensureFilePathExists(finalPath))
|
2013-09-22 03:21:36 +01:00
|
|
|
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);
|
|
|
|
|
2016-03-26 15:56:57 +00:00
|
|
|
cacheentry->setStale(false);
|
|
|
|
cacheentry->setMD5Sum(md5sum.result().toHex().constData());
|
2015-01-31 15:59:03 +00:00
|
|
|
ENV.metacache()->updateEntry(cacheentry);
|
2013-09-22 03:21:36 +01:00
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
|
2014-04-23 01:27:40 +01:00
|
|
|
m_forge_json = newVersion;
|
2013-09-22 03:21:36 +01:00
|
|
|
}
|
2014-12-27 21:45:49 +00:00
|
|
|
|
2014-01-24 17:12:02 +00:00
|
|
|
bool ForgeInstaller::add(OneSixInstance *to)
|
2013-09-22 03:21:36 +01:00
|
|
|
{
|
2014-01-23 20:31:41 +00:00
|
|
|
if (!BaseInstaller::add(to))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-23 01:27:40 +01:00
|
|
|
if (!m_forge_json)
|
2013-09-22 03:21:36 +01:00
|
|
|
{
|
2016-03-13 18:45:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-07-07 07:40:03 +01:00
|
|
|
|
2016-03-13 18:45:34 +00:00
|
|
|
// A blacklist
|
|
|
|
QSet<QString> blacklist{"authlib", "realms"};
|
|
|
|
QList<QString> xzlist{"org.scala-lang", "com.typesafe"};
|
2014-07-07 07:40:03 +01:00
|
|
|
|
2016-03-13 18:45:34 +00:00
|
|
|
// get the minecraft version from the instance
|
|
|
|
VersionFilePtr minecraft;
|
|
|
|
auto minecraftPatch = to->getMinecraftProfile()->versionPatch("net.minecraft");
|
|
|
|
if(minecraftPatch)
|
|
|
|
{
|
|
|
|
minecraft = std::dynamic_pointer_cast<VersionFile>(minecraftPatch);
|
|
|
|
if(!minecraft)
|
|
|
|
{
|
|
|
|
auto mcWrap = std::dynamic_pointer_cast<MinecraftVersion>(minecraftPatch);
|
|
|
|
if(mcWrap)
|
2014-07-19 22:16:02 +01:00
|
|
|
{
|
2016-03-13 18:45:34 +00:00
|
|
|
minecraft = mcWrap->getVersionFile();
|
2013-09-22 03:21:36 +01:00
|
|
|
}
|
2016-03-13 18:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// for each library in the version we are adding (except for the blacklisted)
|
|
|
|
QMutableListIterator<LibraryPtr> iter(m_forge_json->libraries);
|
|
|
|
while (iter.hasNext())
|
|
|
|
{
|
|
|
|
auto library = iter.next();
|
|
|
|
QString libName = library->artifactId();
|
|
|
|
QString libVersion = library->version();
|
|
|
|
QString rawName = library->rawName();
|
2014-07-07 07:40:03 +01:00
|
|
|
|
2016-03-13 18:45:34 +00:00
|
|
|
// ignore lwjgl libraries.
|
|
|
|
if (g_VersionFilterData.lwjglWhitelist.contains(library->artifactPrefix()))
|
|
|
|
{
|
|
|
|
iter.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// ignore other blacklisted (realms, authlib)
|
|
|
|
if (blacklist.contains(libName))
|
|
|
|
{
|
|
|
|
iter.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// if minecraft version was found, ignore everything that is already in the minecraft version
|
|
|
|
if(minecraft)
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
for (auto & lib: minecraft->libraries)
|
2013-09-30 01:34:46 +01:00
|
|
|
{
|
2016-03-13 18:45:34 +00:00
|
|
|
if(library->artifactPrefix() == lib->artifactPrefix() && library->version() == lib->version())
|
2014-07-07 07:40:03 +01:00
|
|
|
{
|
2016-03-13 18:45:34 +00:00
|
|
|
found = true;
|
2014-07-07 07:40:03 +01:00
|
|
|
break;
|
|
|
|
}
|
2013-09-30 01:34:46 +01:00
|
|
|
}
|
2016-03-13 18:45:34 +00:00
|
|
|
if (found)
|
|
|
|
continue;
|
|
|
|
}
|
2013-09-22 03:21:36 +01:00
|
|
|
|
2016-03-13 18:45:34 +00:00
|
|
|
// if this is the actual forge lib, set an absolute url for the download
|
|
|
|
if (m_forge_version->type == ForgeVersion::Gradle)
|
|
|
|
{
|
|
|
|
if (libName == "forge")
|
2013-09-22 03:21:36 +01:00
|
|
|
{
|
2016-03-13 18:45:34 +00:00
|
|
|
library->setClassifier("universal");
|
2013-09-22 03:21:36 +01:00
|
|
|
}
|
2016-03-13 18:45:34 +00:00
|
|
|
else if (libName == "minecraftforge")
|
2014-01-27 18:20:07 +00:00
|
|
|
{
|
2016-03-13 18:45:34 +00:00
|
|
|
QString forgeCoord("net.minecraftforge:forge:%1:universal");
|
|
|
|
// using insane form of the MC version...
|
|
|
|
QString longVersion = m_forge_version->mcver + "-" + m_forge_version->jobbuildver;
|
|
|
|
GradleSpecifier spec(forgeCoord.arg(longVersion));
|
|
|
|
library->setRawName(spec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (libName.contains("minecraftforge"))
|
|
|
|
{
|
|
|
|
library->setAbsoluteUrl(m_universal_url);
|
2014-01-27 18:20:07 +00:00
|
|
|
}
|
2013-09-22 03:21:36 +01:00
|
|
|
}
|
2016-03-13 18:45:34 +00:00
|
|
|
|
|
|
|
// mark bad libraries based on the xzlist above
|
|
|
|
for (auto entry : xzlist)
|
2014-01-27 18:20:07 +00:00
|
|
|
{
|
2016-03-13 18:45:34 +00:00
|
|
|
qDebug() << "Testing " << rawName << " : " << entry;
|
|
|
|
if (rawName.startsWith(entry))
|
2014-01-27 18:20:07 +00:00
|
|
|
{
|
2016-03-13 18:45:34 +00:00
|
|
|
library->setHint("forge-pack-xz");
|
|
|
|
break;
|
2014-01-27 18:20:07 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-13 18:45:34 +00:00
|
|
|
}
|
|
|
|
QString &args = m_forge_json->minecraftArguments;
|
|
|
|
QStringList tweakers;
|
|
|
|
{
|
|
|
|
QRegularExpression expression("--tweakClass ([a-zA-Z0-9\\.]*)");
|
|
|
|
QRegularExpressionMatch match = expression.match(args);
|
|
|
|
while (match.hasMatch())
|
2014-01-27 18:20:07 +00:00
|
|
|
{
|
2016-03-13 18:45:34 +00:00
|
|
|
tweakers.append(match.captured(1));
|
|
|
|
args.remove(match.capturedStart(), match.capturedLength());
|
|
|
|
match = expression.match(args);
|
2014-01-27 18:20:07 +00:00
|
|
|
}
|
2016-03-13 18:45:34 +00:00
|
|
|
if(tweakers.size())
|
2014-01-27 18:20:07 +00:00
|
|
|
{
|
2016-03-13 18:45:34 +00:00
|
|
|
args.operator=(args.trimmed());
|
|
|
|
m_forge_json->addTweakers = tweakers;
|
2014-01-27 18:20:07 +00:00
|
|
|
}
|
2014-01-23 20:31:41 +00:00
|
|
|
}
|
2016-03-13 18:45:34 +00:00
|
|
|
if(minecraft && args == minecraft->minecraftArguments)
|
|
|
|
{
|
|
|
|
args.clear();
|
|
|
|
}
|
2014-01-23 20:31:41 +00:00
|
|
|
|
2016-03-13 18:45:34 +00:00
|
|
|
m_forge_json->name = "Forge";
|
|
|
|
m_forge_json->fileId = id();
|
|
|
|
m_forge_json->version = m_forgeVersionString;
|
2016-03-26 15:56:57 +00:00
|
|
|
m_forge_json->dependsOnMinecraftVersion = to->intendedVersionId();
|
2016-03-13 18:45:34 +00:00
|
|
|
m_forge_json->order = 5;
|
2014-02-01 13:52:21 +00:00
|
|
|
|
2016-04-03 21:17:06 +01:00
|
|
|
// reset some things we do not want to be passed along.
|
|
|
|
m_forge_json->m_releaseTime = QDateTime();
|
|
|
|
m_forge_json->m_updateTime = QDateTime();
|
|
|
|
m_forge_json->minimumLauncherVersion = -1;
|
|
|
|
m_forge_json->type.clear();
|
|
|
|
m_forge_json->minecraftArguments.clear();
|
|
|
|
m_forge_json->minecraftVersion.clear();
|
|
|
|
|
2016-03-13 18:45:34 +00:00
|
|
|
QSaveFile file(filename(to->instanceRoot()));
|
2014-01-23 20:31:41 +00:00
|
|
|
if (!file.open(QFile::WriteOnly))
|
|
|
|
{
|
2015-02-02 01:14:14 +00:00
|
|
|
qCritical() << "Error opening" << file.fileName()
|
2014-01-27 18:20:07 +00:00
|
|
|
<< "for reading:" << file.errorString();
|
2014-01-23 20:31:41 +00:00
|
|
|
return false;
|
2013-09-22 03:21:36 +01:00
|
|
|
}
|
2016-03-19 02:06:32 +00:00
|
|
|
file.write(OneSixVersionFormat::versionFileToJson(m_forge_json, true).toJson());
|
2016-03-13 18:45:34 +00:00
|
|
|
file.commit();
|
2014-01-23 20:31:41 +00:00
|
|
|
|
2014-01-22 06:33:32 +00:00
|
|
|
return true;
|
2013-09-22 03:21:36 +01:00
|
|
|
}
|
2014-03-14 19:48:57 +00:00
|
|
|
|
2014-04-23 01:27:40 +01:00
|
|
|
bool ForgeInstaller::addLegacy(OneSixInstance *to)
|
|
|
|
{
|
|
|
|
if (!BaseInstaller::add(to))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-31 15:59:03 +00:00
|
|
|
auto entry = ENV.metacache()->resolveEntry("minecraftforge", m_forge_version->filename());
|
2015-10-05 00:47:27 +01:00
|
|
|
finalPath = FS::PathCombine(to->jarModsDir(), m_forge_version->filename());
|
|
|
|
if (!FS::ensureFilePathExists(finalPath))
|
2014-05-04 23:10:59 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-27 21:45:49 +00:00
|
|
|
if (!QFile::copy(entry->getFullPath(), finalPath))
|
2014-05-04 23:10:59 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-23 01:27:40 +01:00
|
|
|
QJsonObject obj;
|
|
|
|
obj.insert("order", 5);
|
|
|
|
{
|
|
|
|
QJsonArray jarmodsPlus;
|
|
|
|
{
|
|
|
|
QJsonObject libObj;
|
|
|
|
libObj.insert("name", m_forge_version->universal_filename);
|
|
|
|
jarmodsPlus.append(libObj);
|
|
|
|
}
|
|
|
|
obj.insert("+jarMods", jarmodsPlus);
|
|
|
|
}
|
|
|
|
|
|
|
|
obj.insert("name", QString("Forge"));
|
|
|
|
obj.insert("fileId", id());
|
|
|
|
obj.insert("version", m_forge_version->jobbuildver);
|
|
|
|
obj.insert("mcVersion", to->intendedVersionId());
|
2014-05-04 23:10:59 +01:00
|
|
|
if (g_VersionFilterData.fmlLibsMapping.contains(m_forge_version->mcver))
|
2014-04-23 01:27:40 +01:00
|
|
|
{
|
|
|
|
QJsonArray traitsPlus;
|
|
|
|
traitsPlus.append(QString("legacyFML"));
|
|
|
|
obj.insert("+traits", traitsPlus);
|
|
|
|
}
|
2015-01-27 21:31:07 +00:00
|
|
|
auto fullversion = to->getMinecraftProfile();
|
2014-05-04 23:10:59 +01:00
|
|
|
fullversion->remove("net.minecraftforge");
|
2014-12-27 21:45:49 +00:00
|
|
|
|
2014-04-23 01:27:40 +01:00
|
|
|
QFile file(filename(to->instanceRoot()));
|
|
|
|
if (!file.open(QFile::WriteOnly))
|
|
|
|
{
|
2015-02-02 01:14:14 +00:00
|
|
|
qCritical() << "Error opening" << file.fileName()
|
2014-04-23 01:27:40 +01:00
|
|
|
<< "for reading:" << file.errorString();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
file.write(QJsonDocument(obj).toJson());
|
|
|
|
file.close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-14 19:48:57 +00:00
|
|
|
class ForgeInstallTask : public Task
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-04-23 01:27:40 +01:00
|
|
|
ForgeInstallTask(ForgeInstaller *installer, OneSixInstance *instance,
|
|
|
|
BaseVersionPtr version, QObject *parent = 0)
|
2014-03-14 19:48:57 +00:00
|
|
|
: Task(parent), m_installer(installer), m_instance(instance), m_version(version)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void executeTask() override
|
|
|
|
{
|
2015-05-05 00:33:34 +01:00
|
|
|
setStatus(tr("Installing Forge..."));
|
2014-04-23 01:27:40 +01:00
|
|
|
ForgeVersionPtr forgeVersion = std::dynamic_pointer_cast<ForgeVersion>(m_version);
|
|
|
|
if (!forgeVersion)
|
2014-03-14 19:48:57 +00:00
|
|
|
{
|
2014-04-23 01:27:40 +01:00
|
|
|
emitFailed(tr("Unknown error occured"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
prepare(forgeVersion);
|
|
|
|
}
|
|
|
|
void prepare(ForgeVersionPtr forgeVersion)
|
|
|
|
{
|
2015-01-31 15:59:03 +00:00
|
|
|
auto entry = ENV.metacache()->resolveEntry("minecraftforge", forgeVersion->filename());
|
2014-04-23 01:27:40 +01:00
|
|
|
auto installFunction = [this, entry, forgeVersion]()
|
|
|
|
{
|
|
|
|
if (!install(entry, forgeVersion))
|
2014-03-14 19:48:57 +00:00
|
|
|
{
|
2015-05-05 00:33:34 +01:00
|
|
|
qCritical() << "Failure installing Forge";
|
|
|
|
emitFailed(tr("Failure to install Forge"));
|
2014-03-14 19:48:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-23 01:27:40 +01:00
|
|
|
reload();
|
2014-03-14 19:48:57 +00:00
|
|
|
}
|
2014-04-23 01:27:40 +01:00
|
|
|
};
|
2014-05-04 23:10:59 +01:00
|
|
|
|
2014-12-27 21:45:49 +00:00
|
|
|
/*
|
|
|
|
* HACK IF the local non-stale file is too small, mark is as stale
|
|
|
|
*
|
|
|
|
* This fixes some problems with bad files acquired because of unhandled HTTP redirects
|
|
|
|
* in old versions of MultiMC.
|
|
|
|
*/
|
2016-03-26 15:56:57 +00:00
|
|
|
if (!entry->isStale())
|
2014-12-27 21:45:49 +00:00
|
|
|
{
|
|
|
|
QFileInfo localFile(entry->getFullPath());
|
|
|
|
if (localFile.size() <= 0x4000)
|
|
|
|
{
|
2016-03-26 15:56:57 +00:00
|
|
|
entry->setStale(true);
|
2014-12-27 21:45:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-26 15:56:57 +00:00
|
|
|
if (entry->isStale())
|
2014-04-23 01:27:40 +01:00
|
|
|
{
|
|
|
|
NetJob *fjob = new NetJob("Forge download");
|
2016-05-28 18:54:17 +01:00
|
|
|
fjob->addNetAction(Net::Download::makeCached(forgeVersion->url(), entry));
|
2015-07-26 16:55:29 +01:00
|
|
|
connect(fjob, &NetJob::progress, this, &Task::setProgress);
|
|
|
|
connect(fjob, &NetJob::status, this, &Task::setStatus);
|
2015-04-26 22:04:50 +01:00
|
|
|
connect(fjob, &NetJob::failed, [this](QString reason)
|
2015-05-05 00:33:34 +01:00
|
|
|
{ emitFailed(tr("Failure to download Forge:\n%1").arg(reason)); });
|
2014-04-23 01:27:40 +01:00
|
|
|
connect(fjob, &NetJob::succeeded, installFunction);
|
|
|
|
fjob->start();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
installFunction();
|
2014-03-14 19:48:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bool install(const std::shared_ptr<MetaEntry> &entry, const ForgeVersionPtr &forgeVersion)
|
|
|
|
{
|
2014-04-23 01:27:40 +01:00
|
|
|
if (forgeVersion->usesInstaller())
|
|
|
|
{
|
|
|
|
QString forgePath = entry->getFullPath();
|
|
|
|
m_installer->prepare(forgePath, forgeVersion->universal_url);
|
|
|
|
return m_installer->add(m_instance);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return m_installer->addLegacy(m_instance);
|
2014-03-14 19:48:57 +00:00
|
|
|
}
|
|
|
|
void reload()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-01-27 21:31:07 +00:00
|
|
|
m_instance->reloadProfile();
|
2014-03-14 19:48:57 +00:00
|
|
|
emitSucceeded();
|
|
|
|
}
|
2015-05-28 18:38:29 +01:00
|
|
|
catch (Exception &e)
|
2014-03-14 19:48:57 +00:00
|
|
|
{
|
|
|
|
emitFailed(e.cause());
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
emitFailed(tr("Failed to load the version description file for reasons unknown."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ForgeInstaller *m_installer;
|
|
|
|
OneSixInstance *m_instance;
|
|
|
|
BaseVersionPtr m_version;
|
|
|
|
};
|
|
|
|
|
2015-04-26 22:04:50 +01:00
|
|
|
Task *ForgeInstaller::createInstallTask(OneSixInstance *instance,
|
2014-04-23 01:27:40 +01:00
|
|
|
BaseVersionPtr version, QObject *parent)
|
2014-03-14 19:48:57 +00:00
|
|
|
{
|
2014-04-23 01:27:40 +01:00
|
|
|
if (!version)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
m_forge_version = std::dynamic_pointer_cast<ForgeVersion>(version);
|
2014-03-14 19:48:57 +00:00
|
|
|
return new ForgeInstallTask(this, instance, version, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "ForgeInstaller.moc"
|