2015-02-03 03:55:30 +05:30
|
|
|
/* Copyright 2013-2015 MultiMC Contributors
|
2014-02-20 03:04:17 +05:30
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LiteLoaderVersionList.h"
|
2016-02-28 23:31:54 +05:30
|
|
|
#include <minecraft/onesix/OneSixVersionFormat.h>
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "Env.h"
|
|
|
|
#include "net/URLConstants.h"
|
2015-05-28 23:08:29 +05:30
|
|
|
#include "Exception.h"
|
2014-02-20 03:04:17 +05:30
|
|
|
|
|
|
|
#include <QtXml>
|
|
|
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonValue>
|
|
|
|
#include <QJsonParseError>
|
|
|
|
|
|
|
|
#include <QtAlgorithms>
|
|
|
|
|
|
|
|
#include <QtNetwork>
|
|
|
|
|
|
|
|
LiteLoaderVersionList::LiteLoaderVersionList(QObject *parent) : BaseVersionList(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Task *LiteLoaderVersionList::getLoadTask()
|
|
|
|
{
|
|
|
|
return new LLListLoadTask(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LiteLoaderVersionList::isLoaded()
|
|
|
|
{
|
|
|
|
return m_loaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
const BaseVersionPtr LiteLoaderVersionList::at(int i) const
|
|
|
|
{
|
|
|
|
return m_vlist.at(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
int LiteLoaderVersionList::count() const
|
|
|
|
{
|
|
|
|
return m_vlist.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second)
|
|
|
|
{
|
|
|
|
auto left = std::dynamic_pointer_cast<LiteLoaderVersion>(first);
|
|
|
|
auto right = std::dynamic_pointer_cast<LiteLoaderVersion>(second);
|
|
|
|
return left->timestamp > right->timestamp;
|
|
|
|
}
|
|
|
|
|
2016-06-14 01:30:09 +05:30
|
|
|
VersionFilePtr LiteLoaderVersion::getVersionFile()
|
|
|
|
{
|
|
|
|
auto f = std::make_shared<VersionFile>();
|
|
|
|
f->mainClass = "net.minecraft.launchwrapper.Launch";
|
|
|
|
f->addTweakers += tweakClass;
|
|
|
|
f->order = 10;
|
|
|
|
f->libraries = libraries;
|
|
|
|
f->name = "LiteLoader";
|
|
|
|
f->fileId = "com.mumfrey.liteloader";
|
|
|
|
f->version = version;
|
|
|
|
f->minecraftVersion = mcVersion;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2015-09-26 07:34:09 +05:30
|
|
|
void LiteLoaderVersionList::sortVersions()
|
2014-02-20 03:04:17 +05:30
|
|
|
{
|
|
|
|
beginResetModel();
|
2014-07-11 05:21:07 +05:30
|
|
|
std::sort(m_vlist.begin(), m_vlist.end(), cmpVersions);
|
2014-02-20 03:04:17 +05:30
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
2015-04-28 12:31:37 +05:30
|
|
|
QVariant LiteLoaderVersionList::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if (index.row() > count())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
auto version = std::dynamic_pointer_cast<LiteLoaderVersion>(m_vlist[index.row()]);
|
|
|
|
switch (role)
|
|
|
|
{
|
|
|
|
case VersionPointerRole:
|
|
|
|
return qVariantFromValue(m_vlist[index.row()]);
|
|
|
|
|
|
|
|
case VersionRole:
|
|
|
|
return version->name();
|
|
|
|
|
|
|
|
case VersionIdRole:
|
|
|
|
return version->descriptor();
|
|
|
|
|
|
|
|
case ParentGameVersionRole:
|
|
|
|
return version->mcVersion;
|
|
|
|
|
2016-06-14 05:38:56 +05:30
|
|
|
case LatestRole:
|
2015-04-28 12:31:37 +05:30
|
|
|
return version->isLatest;
|
|
|
|
|
2016-06-14 05:38:56 +05:30
|
|
|
case RecommendedRole:
|
|
|
|
return version->isRecommended;
|
|
|
|
|
|
|
|
case TypeRole:
|
|
|
|
return version->isSnapshot ? tr("Snapshot") : tr("Release");
|
|
|
|
|
2015-04-28 12:31:37 +05:30
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-14 05:38:56 +05:30
|
|
|
BaseVersionList::RoleList LiteLoaderVersionList::providesRoles() const
|
2015-04-28 12:31:37 +05:30
|
|
|
{
|
2016-06-14 05:38:56 +05:30
|
|
|
return {VersionPointerRole, VersionRole, VersionIdRole, ParentGameVersionRole, RecommendedRole, LatestRole, TypeRole};
|
2015-04-28 12:31:37 +05:30
|
|
|
}
|
|
|
|
|
2014-02-20 03:04:17 +05:30
|
|
|
BaseVersionPtr LiteLoaderVersionList::getLatestStable() const
|
|
|
|
{
|
|
|
|
for (int i = 0; i < m_vlist.length(); i++)
|
|
|
|
{
|
|
|
|
auto ver = std::dynamic_pointer_cast<LiteLoaderVersion>(m_vlist.at(i));
|
2016-06-14 05:38:56 +05:30
|
|
|
if (ver->isRecommended)
|
2014-02-20 03:04:17 +05:30
|
|
|
{
|
|
|
|
return m_vlist.at(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return BaseVersionPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LiteLoaderVersionList::updateListData(QList<BaseVersionPtr> versions)
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
m_vlist = versions;
|
|
|
|
m_loaded = true;
|
2014-07-11 05:21:07 +05:30
|
|
|
std::sort(m_vlist.begin(), m_vlist.end(), cmpVersions);
|
2014-02-20 03:04:17 +05:30
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
LLListLoadTask::LLListLoadTask(LiteLoaderVersionList *vlist)
|
|
|
|
{
|
|
|
|
m_list = vlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
LLListLoadTask::~LLListLoadTask()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLListLoadTask::executeTask()
|
|
|
|
{
|
|
|
|
setStatus(tr("Loading LiteLoader version list..."));
|
2014-03-02 06:38:01 +05:30
|
|
|
auto job = new NetJob("Version index");
|
|
|
|
// we do not care if the version is stale or not.
|
2015-01-31 21:29:03 +05:30
|
|
|
auto liteloaderEntry = ENV.metacache()->resolveEntry("liteloader", "versions.json");
|
2014-03-02 06:38:01 +05:30
|
|
|
|
|
|
|
// verify by poking the server.
|
2016-03-26 21:26:57 +05:30
|
|
|
liteloaderEntry->setStale(true);
|
2014-03-02 06:38:01 +05:30
|
|
|
|
2016-05-28 23:24:17 +05:30
|
|
|
job->addNetAction(listDownload = Net::Download::makeCached(QUrl(URLConstants::LITELOADER_URL), liteloaderEntry));
|
2014-03-02 06:38:01 +05:30
|
|
|
|
|
|
|
connect(listDownload.get(), SIGNAL(failed(int)), SLOT(listFailed()));
|
|
|
|
|
|
|
|
listJob.reset(job);
|
|
|
|
connect(listJob.get(), SIGNAL(succeeded()), SLOT(listDownloaded()));
|
|
|
|
connect(listJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64)));
|
|
|
|
listJob->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLListLoadTask::listFailed()
|
|
|
|
{
|
|
|
|
emitFailed("Failed to load LiteLoader version list.");
|
|
|
|
return;
|
2014-02-20 03:04:17 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LLListLoadTask::listDownloaded()
|
|
|
|
{
|
2014-03-02 06:38:01 +05:30
|
|
|
QByteArray data;
|
2014-02-20 03:04:17 +05:30
|
|
|
{
|
2016-05-28 23:24:17 +05:30
|
|
|
auto filename = listDownload->getTargetFilepath();
|
2014-03-02 06:38:01 +05:30
|
|
|
QFile listFile(filename);
|
|
|
|
if (!listFile.open(QIODevice::ReadOnly))
|
|
|
|
{
|
|
|
|
emitFailed("Failed to open the LiteLoader version list.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data = listFile.readAll();
|
|
|
|
listFile.close();
|
2016-05-28 23:24:17 +05:30
|
|
|
listDownload.reset();
|
2014-02-20 03:04:17 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
QJsonParseError jsonError;
|
2014-03-02 06:38:01 +05:30
|
|
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);
|
2014-02-20 03:04:17 +05:30
|
|
|
|
|
|
|
if (jsonError.error != QJsonParseError::NoError)
|
|
|
|
{
|
|
|
|
emitFailed("Error parsing version list JSON:" + jsonError.errorString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!jsonDoc.isObject())
|
|
|
|
{
|
|
|
|
emitFailed("Error parsing version list JSON: jsonDoc is not an object");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QJsonObject root = jsonDoc.object();
|
|
|
|
|
|
|
|
// Now, get the array of versions.
|
|
|
|
if (!root.value("versions").isObject())
|
|
|
|
{
|
|
|
|
emitFailed("Error parsing version list JSON: missing 'versions' object");
|
|
|
|
return;
|
|
|
|
}
|
2014-03-02 06:38:01 +05:30
|
|
|
|
|
|
|
auto meta = root.value("meta").toObject();
|
|
|
|
QString description = meta.value("description").toString(tr("This is a lightweight loader for mods that don't change game mechanics."));
|
|
|
|
QString defaultUrl = meta.value("url").toString("http://dl.liteloader.com");
|
|
|
|
QString authors = meta.value("authors").toString("Mumfrey");
|
|
|
|
auto versions = root.value("versions").toObject();
|
2014-02-20 03:04:17 +05:30
|
|
|
|
|
|
|
QList<BaseVersionPtr> tempList;
|
|
|
|
for (auto vIt = versions.begin(); vIt != versions.end(); ++vIt)
|
|
|
|
{
|
|
|
|
const QString mcVersion = vIt.key();
|
2016-06-14 01:30:09 +05:30
|
|
|
const QJsonObject versionObject = vIt.value().toObject();
|
|
|
|
|
2016-06-14 05:38:56 +05:30
|
|
|
auto processArtefacts = [&](QJsonObject artefacts, bool notSnapshots, std::shared_ptr<LiteLoaderVersion> &latest)
|
2014-02-20 03:04:17 +05:30
|
|
|
{
|
2016-06-14 05:38:56 +05:30
|
|
|
QString latestVersion;
|
2016-06-14 01:30:09 +05:30
|
|
|
QList<BaseVersionPtr> perMcVersionList;
|
|
|
|
for (auto aIt = artefacts.begin(); aIt != artefacts.end(); ++aIt)
|
|
|
|
{
|
|
|
|
const QString identifier = aIt.key();
|
|
|
|
const QJsonObject artefact = aIt.value().toObject();
|
|
|
|
if (identifier == "latest")
|
|
|
|
{
|
2016-06-14 05:38:56 +05:30
|
|
|
latestVersion = artefact.value("version").toString();
|
2016-06-14 01:30:09 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
LiteLoaderVersionPtr version(new LiteLoaderVersion());
|
|
|
|
version->version = artefact.value("version").toString();
|
|
|
|
version->mcVersion = mcVersion;
|
|
|
|
version->md5 = artefact.value("md5").toString();
|
2016-06-14 05:38:56 +05:30
|
|
|
version->timestamp = artefact.value("timestamp").toString().toLong();
|
2016-06-14 01:30:09 +05:30
|
|
|
version->tweakClass = artefact.value("tweakClass").toString();
|
|
|
|
version->authors = authors;
|
|
|
|
version->description = description;
|
|
|
|
version->defaultUrl = defaultUrl;
|
2016-06-14 05:38:56 +05:30
|
|
|
version->isSnapshot = !notSnapshots;
|
2016-06-14 01:30:09 +05:30
|
|
|
const QJsonArray libs = artefact.value("libraries").toArray();
|
|
|
|
for (auto lIt = libs.begin(); lIt != libs.end(); ++lIt)
|
|
|
|
{
|
|
|
|
auto libobject = (*lIt).toObject();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
auto lib = OneSixVersionFormat::libraryFromJson(libobject, "versions.json");
|
|
|
|
// hack to make liteloader 1.7.10_00 work
|
|
|
|
if(lib->rawName() == GradleSpecifier("org.ow2.asm:asm-all:5.0.3"))
|
|
|
|
{
|
|
|
|
lib->setRepositoryURL("http://repo.maven.apache.org/maven2/");
|
|
|
|
}
|
|
|
|
version->libraries.append(lib);
|
|
|
|
}
|
|
|
|
catch (Exception &e)
|
|
|
|
{
|
|
|
|
qCritical() << "Couldn't read JSON object:";
|
|
|
|
continue; // FIXME: ignores bad libraries and continues loading
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto liteloaderLib = std::make_shared<Library>("com.mumfrey:liteloader:" + version->version);
|
|
|
|
liteloaderLib->setRepositoryURL("http://dl.liteloader.com/versions/");
|
|
|
|
if(!notSnapshots)
|
|
|
|
{
|
|
|
|
liteloaderLib->setHint("always-stale");
|
|
|
|
}
|
|
|
|
version->libraries.append(liteloaderLib);
|
|
|
|
perMcVersionList.append(version);
|
|
|
|
}
|
|
|
|
if(notSnapshots)
|
2014-02-20 03:04:17 +05:30
|
|
|
{
|
2016-06-14 01:30:09 +05:30
|
|
|
for (auto version : perMcVersionList)
|
|
|
|
{
|
|
|
|
auto v = std::dynamic_pointer_cast<LiteLoaderVersion>(version);
|
2016-06-14 05:38:56 +05:30
|
|
|
if(v->version == latestVersion)
|
|
|
|
{
|
|
|
|
latest = v;
|
|
|
|
}
|
2016-06-14 01:30:09 +05:30
|
|
|
}
|
2014-02-20 03:04:17 +05:30
|
|
|
}
|
2016-06-14 01:30:09 +05:30
|
|
|
tempList.append(perMcVersionList);
|
|
|
|
};
|
|
|
|
|
2016-06-14 05:38:56 +05:30
|
|
|
std::shared_ptr<LiteLoaderVersion> latestSnapshot;
|
|
|
|
std::shared_ptr<LiteLoaderVersion> latestRelease;
|
2016-06-14 01:30:09 +05:30
|
|
|
// are there actually released versions for this mc version?
|
|
|
|
if(versionObject.contains("artefacts"))
|
|
|
|
{
|
|
|
|
const QJsonObject artefacts = versionObject.value("artefacts").toObject().value("com.mumfrey:liteloader").toObject();
|
2016-06-14 05:38:56 +05:30
|
|
|
processArtefacts(artefacts, true, latestRelease);
|
2016-06-14 01:30:09 +05:30
|
|
|
}
|
|
|
|
if(versionObject.contains("snapshots"))
|
|
|
|
{
|
|
|
|
QJsonObject artefacts = versionObject.value("snapshots").toObject().value("com.mumfrey:liteloader").toObject();
|
2016-06-14 05:38:56 +05:30
|
|
|
processArtefacts(artefacts, false, latestSnapshot);
|
|
|
|
}
|
|
|
|
if(latestSnapshot)
|
|
|
|
{
|
|
|
|
latestSnapshot->isLatest = true;
|
|
|
|
}
|
|
|
|
else if(latestRelease)
|
|
|
|
{
|
|
|
|
latestRelease->isLatest = true;
|
|
|
|
}
|
|
|
|
if(latestRelease)
|
|
|
|
{
|
|
|
|
latestRelease->isRecommended = true;
|
2014-02-20 03:04:17 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
m_list->updateListData(tempList);
|
|
|
|
|
|
|
|
emitSucceeded();
|
|
|
|
}
|