Start of mod downloading
This commit is contained in:
51
launcher/modplatform/modrinth/ModrinthPackIndex.cpp
Normal file
51
launcher/modplatform/modrinth/ModrinthPackIndex.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include <QObject>
|
||||
#include "ModrinthPackIndex.h"
|
||||
|
||||
#include "Json.h"
|
||||
#include "net/NetJob.h"
|
||||
|
||||
void Modrinth::loadIndexedPack(Modrinth::IndexedPack & pack, QJsonObject & obj)
|
||||
{
|
||||
pack.addonId = Json::requireString(obj, "mod_id");
|
||||
pack.name = Json::requireString(obj, "title");
|
||||
pack.websiteUrl = Json::ensureString(obj, "page_url", "");
|
||||
pack.description = Json::ensureString(obj, "description", "");
|
||||
|
||||
pack.logoUrl = Json::requireString(obj, "icon_url");
|
||||
pack.logoName = "logoName";
|
||||
|
||||
Modrinth::ModpackAuthor packAuthor;
|
||||
packAuthor.name = Json::requireString(obj, "author");
|
||||
packAuthor.url = Json::requireString(obj, "author_url");
|
||||
pack.authors.append(packAuthor); //TODO delete this ? only one author ever exists
|
||||
}
|
||||
|
||||
void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray & arr, const shared_qobject_ptr<QNetworkAccessManager>& network)
|
||||
{
|
||||
QVector<Modrinth::IndexedVersion> unsortedVersions;
|
||||
for(auto versionIter: arr) {
|
||||
auto obj = versionIter.toObject();
|
||||
Modrinth::IndexedVersion file;
|
||||
file.addonId = Json::requireString(obj,"mod_id") ;
|
||||
file.fileId = Json::requireString(obj, "id");
|
||||
file.date = Json::requireString(obj, "date_published");
|
||||
auto versionArray = Json::requireArray(obj, "game_versions");
|
||||
if (versionArray.empty()) {
|
||||
continue;
|
||||
}
|
||||
// pick the latest version supported
|
||||
file.mcVersion = versionArray[0].toString();
|
||||
file.version = Json::requireString(obj, "name");
|
||||
//TODO show all the files ?
|
||||
file.downloadUrl = Json::requireString(Json::requireArray(obj, "files")[0].toObject(),"url");
|
||||
unsortedVersions.append(file);
|
||||
}
|
||||
auto orderSortPredicate = [](const IndexedVersion & a, const IndexedVersion & b) -> bool
|
||||
{
|
||||
//dates are in RFC 3339 format
|
||||
return a.date > b.date;
|
||||
};
|
||||
std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
|
||||
pack.versions = unsortedVersions;
|
||||
pack.versionsLoaded = true;
|
||||
}
|
46
launcher/modplatform/modrinth/ModrinthPackIndex.h
Normal file
46
launcher/modplatform/modrinth/ModrinthPackIndex.h
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <QList>
|
||||
#include <QMetaType>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QObjectPtr.h>
|
||||
#include "net/NetJob.h"
|
||||
|
||||
namespace Modrinth {
|
||||
|
||||
struct ModpackAuthor {
|
||||
QString name;
|
||||
QString url;
|
||||
};
|
||||
|
||||
struct IndexedVersion {
|
||||
QString addonId;
|
||||
QString fileId;
|
||||
QString version;
|
||||
QString mcVersion;
|
||||
QString downloadUrl;
|
||||
QString date;
|
||||
};
|
||||
|
||||
struct IndexedPack
|
||||
{
|
||||
QString addonId;
|
||||
QString name;
|
||||
QString description;
|
||||
QList<ModpackAuthor> authors;
|
||||
QString logoName;
|
||||
QString logoUrl;
|
||||
QString websiteUrl;
|
||||
|
||||
bool versionsLoaded = false;
|
||||
QVector<IndexedVersion> versions;
|
||||
};
|
||||
|
||||
void loadIndexedPack(IndexedPack & m, QJsonObject & obj);
|
||||
void loadIndexedPackVersions(IndexedPack & m, QJsonArray & arr, const shared_qobject_ptr<QNetworkAccessManager>& network);
|
||||
void versionJobFinished();
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(Modrinth::IndexedPack)
|
Reference in New Issue
Block a user