Gather and store liteloader metadata.

This commit is contained in:
Petr Mrázek 2014-03-02 02:08:01 +01:00
parent 053b938beb
commit 5a344a2933
4 changed files with 56 additions and 13 deletions

View File

@ -457,6 +457,7 @@ void MultiMC::initHttpMetaCache()
m_metacache->addBase("versions", QDir("versions").absolutePath()); m_metacache->addBase("versions", QDir("versions").absolutePath());
m_metacache->addBase("libraries", QDir("libraries").absolutePath()); m_metacache->addBase("libraries", QDir("libraries").absolutePath());
m_metacache->addBase("minecraftforge", QDir("mods/minecraftforge").absolutePath()); m_metacache->addBase("minecraftforge", QDir("mods/minecraftforge").absolutePath());
m_metacache->addBase("liteloader", QDir("mods/liteloader").absolutePath());
m_metacache->addBase("skins", QDir("accounts/skins").absolutePath()); m_metacache->addBase("skins", QDir("accounts/skins").absolutePath());
m_metacache->addBase("root", QDir(root()).absolutePath()); m_metacache->addBase("root", QDir(root()).absolutePath());
m_metacache->Load(); m_metacache->Load();

View File

@ -69,7 +69,7 @@ bool LiteLoaderInstaller::add(OneSixInstance *to)
obj.insert("+libraries", libraries); obj.insert("+libraries", libraries);
obj.insert("name", QString("LiteLoader")); obj.insert("name", QString("LiteLoader"));
obj.insert("fileId", id()); obj.insert("fileId", id());
obj.insert("version", to->intendedVersionId()); obj.insert("version", m_version->version);
obj.insert("mcVersion", to->intendedVersionId()); obj.insert("mcVersion", to->intendedVersionId());
QFile file(filename(to->instanceRoot())); QFile file(filename(to->instanceRoot()));

View File

@ -92,7 +92,6 @@ void LiteLoaderVersionList::updateListData(QList<BaseVersionPtr> versions)
LLListLoadTask::LLListLoadTask(LiteLoaderVersionList *vlist) LLListLoadTask::LLListLoadTask(LiteLoaderVersionList *vlist)
{ {
m_list = vlist; m_list = vlist;
vlistReply = nullptr;
} }
LLListLoadTask::~LLListLoadTask() LLListLoadTask::~LLListLoadTask()
@ -102,23 +101,49 @@ LLListLoadTask::~LLListLoadTask()
void LLListLoadTask::executeTask() void LLListLoadTask::executeTask()
{ {
setStatus(tr("Loading LiteLoader version list...")); setStatus(tr("Loading LiteLoader version list..."));
auto worker = MMC->qnam(); auto job = new NetJob("Version index");
vlistReply = worker->get(QNetworkRequest(QUrl(URLConstants::LITELOADER_URL))); // we do not care if the version is stale or not.
connect(vlistReply, SIGNAL(finished()), this, SLOT(listDownloaded())); auto liteloaderEntry = MMC->metacache()->resolveEntry("liteloader", "versions.json");
// verify by poking the server.
liteloaderEntry->stale = true;
job->addNetAction(listDownload = CacheDownload::make(QUrl(URLConstants::LITELOADER_URL),
liteloaderEntry));
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;
} }
void LLListLoadTask::listDownloaded() void LLListLoadTask::listDownloaded()
{ {
if (vlistReply->error() != QNetworkReply::NoError) QByteArray data;
{ {
vlistReply->deleteLater(); auto dlJob = listDownload;
emitFailed("Failed to load LiteLoader version list" + vlistReply->errorString()); auto filename = std::dynamic_pointer_cast<CacheDownload>(dlJob)->getTargetFilepath();
QFile listFile(filename);
if (!listFile.open(QIODevice::ReadOnly))
{
emitFailed("Failed to open the LiteLoader version list.");
return; return;
} }
data = listFile.readAll();
listFile.close();
dlJob.reset();
}
QJsonParseError jsonError; QJsonParseError jsonError;
QJsonDocument jsonDoc = QJsonDocument::fromJson(vlistReply->readAll(), &jsonError); QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);
vlistReply->deleteLater();
if (jsonError.error != QJsonParseError::NoError) if (jsonError.error != QJsonParseError::NoError)
{ {
@ -140,7 +165,12 @@ void LLListLoadTask::listDownloaded()
emitFailed("Error parsing version list JSON: missing 'versions' object"); emitFailed("Error parsing version list JSON: missing 'versions' object");
return; return;
} }
const QJsonObject versions = root.value("versions").toObject();
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();
QList<BaseVersionPtr> tempList; QList<BaseVersionPtr> tempList;
for (auto vIt = versions.begin(); vIt != versions.end(); ++vIt) for (auto vIt = versions.begin(); vIt != versions.end(); ++vIt)
@ -170,6 +200,9 @@ void LLListLoadTask::listDownloaded()
version->md5 = artefact.value("md5").toString(); version->md5 = artefact.value("md5").toString();
version->timestamp = artefact.value("timestamp").toDouble(); version->timestamp = artefact.value("timestamp").toDouble();
version->tweakClass = artefact.value("tweakClass").toString(); version->tweakClass = artefact.value("tweakClass").toString();
version->authors = authors;
version->description = description;
version->defaultUrl = defaultUrl;
const QJsonArray libs = artefact.value("libraries").toArray(); const QJsonArray libs = artefact.value("libraries").toArray();
for (auto lIt = libs.begin(); lIt != libs.end(); ++lIt) for (auto lIt = libs.begin(); lIt != libs.end(); ++lIt)
{ {

View File

@ -22,6 +22,7 @@
#include "BaseVersionList.h" #include "BaseVersionList.h"
#include "logic/tasks/Task.h" #include "logic/tasks/Task.h"
#include "logic/BaseVersion.h" #include "logic/BaseVersion.h"
#include <logic/net/NetJob.h>
class LLListLoadTask; class LLListLoadTask;
class QNetworkReply; class QNetworkReply;
@ -46,6 +47,7 @@ public:
return version; return version;
} }
// important info
QString version; QString version;
QString file; QString file;
QString mcVersion; QString mcVersion;
@ -54,6 +56,11 @@ public:
bool isLatest; bool isLatest;
QString tweakClass; QString tweakClass;
QStringList libraries; QStringList libraries;
// meta
QString defaultUrl;
QString description;
QString authors;
}; };
typedef std::shared_ptr<LiteLoaderVersion> LiteLoaderVersionPtr; typedef std::shared_ptr<LiteLoaderVersion> LiteLoaderVersionPtr;
@ -96,8 +103,10 @@ public:
protected protected
slots: slots:
void listDownloaded(); void listDownloaded();
void listFailed();
protected: protected:
QNetworkReply *vlistReply; NetJobPtr listJob;
CacheDownloadPtr listDownload;
LiteLoaderVersionList *m_list; LiteLoaderVersionList *m_list;
}; };