Merge pull request #939 from flowln/mod_downloader_improve
Some more UI / UX improvements to the mod downloader!
This commit is contained in:
@ -73,7 +73,7 @@ class ModAPI {
|
||||
};
|
||||
|
||||
virtual void searchMods(CallerType* caller, SearchArgs&& args) const = 0;
|
||||
virtual void getModInfo(CallerType* caller, ModPlatform::IndexedPack& pack) = 0;
|
||||
virtual void getModInfo(ModPlatform::IndexedPack& pack, std::function<void(QJsonDocument&, ModPlatform::IndexedPack&)> callback) = 0;
|
||||
|
||||
virtual auto getProject(QString addonId, QByteArray* response) const -> NetJob* = 0;
|
||||
virtual auto getProjects(QStringList addonIds, QByteArray* response) const -> NetJob* = 0;
|
||||
@ -85,7 +85,7 @@ class ModAPI {
|
||||
ModLoaderTypes loaders;
|
||||
};
|
||||
|
||||
virtual void getVersions(CallerType* caller, VersionSearchArgs&& args) const = 0;
|
||||
virtual void getVersions(VersionSearchArgs&& args, std::function<void(QJsonDocument&, QString)> callback) const = 0;
|
||||
|
||||
static auto getModLoaderString(ModLoaderType type) -> const QString {
|
||||
switch (type) {
|
||||
|
@ -75,6 +75,8 @@ struct ExtraPackData {
|
||||
QString sourceUrl;
|
||||
QString wikiUrl;
|
||||
QString discordUrl;
|
||||
|
||||
QString body;
|
||||
};
|
||||
|
||||
struct IndexedPack {
|
||||
|
@ -67,6 +67,43 @@ auto FlameAPI::getModFileChangelog(int modId, int fileId) -> QString
|
||||
return changelog;
|
||||
}
|
||||
|
||||
auto FlameAPI::getModDescription(int modId) -> QString
|
||||
{
|
||||
QEventLoop lock;
|
||||
QString description;
|
||||
|
||||
auto* netJob = new NetJob(QString("Flame::ModDescription"), APPLICATION->network());
|
||||
auto* response = new QByteArray();
|
||||
netJob->addNetAction(Net::Download::makeByteArray(
|
||||
QString("https://api.curseforge.com/v1/mods/%1/description")
|
||||
.arg(QString::number(modId)), response));
|
||||
|
||||
QObject::connect(netJob, &NetJob::succeeded, [netJob, response, &description] {
|
||||
QJsonParseError parse_error{};
|
||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||
if (parse_error.error != QJsonParseError::NoError) {
|
||||
qWarning() << "Error while parsing JSON response from Flame::ModDescription at " << parse_error.offset
|
||||
<< " reason: " << parse_error.errorString();
|
||||
qWarning() << *response;
|
||||
|
||||
netJob->failed(parse_error.errorString());
|
||||
return;
|
||||
}
|
||||
|
||||
description = Json::ensureString(doc.object(), "data");
|
||||
});
|
||||
|
||||
QObject::connect(netJob, &NetJob::finished, [response, &lock] {
|
||||
delete response;
|
||||
lock.quit();
|
||||
});
|
||||
|
||||
netJob->start();
|
||||
lock.exec();
|
||||
|
||||
return description;
|
||||
}
|
||||
|
||||
auto FlameAPI::getLatestVersion(VersionSearchArgs&& args) -> ModPlatform::IndexedVersion
|
||||
{
|
||||
QEventLoop loop;
|
||||
|
@ -7,6 +7,7 @@ class FlameAPI : public NetworkModAPI {
|
||||
public:
|
||||
auto matchFingerprints(const QList<uint>& fingerprints, QByteArray* response) -> NetJob::Ptr;
|
||||
auto getModFileChangelog(int modId, int fileId) -> QString;
|
||||
auto getModDescription(int modId) -> QString;
|
||||
|
||||
auto getLatestVersion(VersionSearchArgs&& args) -> ModPlatform::IndexedVersion;
|
||||
|
||||
|
@ -4,10 +4,9 @@
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "modplatform/flame/FlameAPI.h"
|
||||
#include "net/NetJob.h"
|
||||
|
||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
||||
static FlameAPI api;
|
||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
||||
|
||||
void FlameMod::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
|
||||
{
|
||||
@ -31,10 +30,11 @@ void FlameMod::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
|
||||
pack.authors.append(packAuthor);
|
||||
}
|
||||
|
||||
loadExtraPackData(pack, obj);
|
||||
pack.extraDataLoaded = false;
|
||||
loadURLs(pack, obj);
|
||||
}
|
||||
|
||||
void FlameMod::loadExtraPackData(ModPlatform::IndexedPack& pack, QJsonObject& obj)
|
||||
void FlameMod::loadURLs(ModPlatform::IndexedPack& pack, QJsonObject& obj)
|
||||
{
|
||||
auto links_obj = Json::ensureObject(obj, "links");
|
||||
|
||||
@ -50,7 +50,16 @@ void FlameMod::loadExtraPackData(ModPlatform::IndexedPack& pack, QJsonObject& ob
|
||||
if(pack.extraData.wikiUrl.endsWith('/'))
|
||||
pack.extraData.wikiUrl.chop(1);
|
||||
|
||||
pack.extraDataLoaded = true;
|
||||
if (!pack.extraData.body.isEmpty())
|
||||
pack.extraDataLoaded = true;
|
||||
}
|
||||
|
||||
void FlameMod::loadBody(ModPlatform::IndexedPack& pack, QJsonObject& obj)
|
||||
{
|
||||
pack.extraData.body = api.getModDescription(pack.addonId.toInt());
|
||||
|
||||
if (!pack.extraData.issuesUrl.isEmpty() || !pack.extraData.sourceUrl.isEmpty() || !pack.extraData.wikiUrl.isEmpty())
|
||||
pack.extraDataLoaded = true;
|
||||
}
|
||||
|
||||
static QString enumToString(int hash_algorithm)
|
||||
|
@ -12,7 +12,8 @@
|
||||
namespace FlameMod {
|
||||
|
||||
void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj);
|
||||
void loadExtraPackData(ModPlatform::IndexedPack& m, QJsonObject& obj);
|
||||
void loadURLs(ModPlatform::IndexedPack& m, QJsonObject& obj);
|
||||
void loadBody(ModPlatform::IndexedPack& m, QJsonObject& obj);
|
||||
void loadIndexedPackVersions(ModPlatform::IndexedPack& pack,
|
||||
QJsonArray& arr,
|
||||
const shared_qobject_ptr<QNetworkAccessManager>& network,
|
||||
|
@ -31,48 +31,48 @@ void NetworkModAPI::searchMods(CallerType* caller, SearchArgs&& args) const
|
||||
netJob->start();
|
||||
}
|
||||
|
||||
void NetworkModAPI::getModInfo(CallerType* caller, ModPlatform::IndexedPack& pack)
|
||||
void NetworkModAPI::getModInfo(ModPlatform::IndexedPack& pack, std::function<void(QJsonDocument&, ModPlatform::IndexedPack&)> callback)
|
||||
{
|
||||
auto response = new QByteArray();
|
||||
auto job = getProject(pack.addonId.toString(), response);
|
||||
|
||||
QObject::connect(job, &NetJob::succeeded, caller, [caller, &pack, response] {
|
||||
QObject::connect(job, &NetJob::succeeded, [callback, &pack, response] {
|
||||
QJsonParseError parse_error{};
|
||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||
if (parse_error.error != QJsonParseError::NoError) {
|
||||
qWarning() << "Error while parsing JSON response from " << caller->debugName() << " at " << parse_error.offset
|
||||
qWarning() << "Error while parsing JSON response for mod info at " << parse_error.offset
|
||||
<< " reason: " << parse_error.errorString();
|
||||
qWarning() << *response;
|
||||
return;
|
||||
}
|
||||
|
||||
caller->infoRequestFinished(doc, pack);
|
||||
callback(doc, pack);
|
||||
});
|
||||
|
||||
job->start();
|
||||
}
|
||||
|
||||
void NetworkModAPI::getVersions(CallerType* caller, VersionSearchArgs&& args) const
|
||||
void NetworkModAPI::getVersions(VersionSearchArgs&& args, std::function<void(QJsonDocument&, QString)> callback) const
|
||||
{
|
||||
auto netJob = new NetJob(QString("%1::ModVersions(%2)").arg(caller->debugName()).arg(args.addonId), APPLICATION->network());
|
||||
auto netJob = new NetJob(QString("ModVersions(%2)").arg(args.addonId), APPLICATION->network());
|
||||
auto response = new QByteArray();
|
||||
|
||||
netJob->addNetAction(Net::Download::makeByteArray(getVersionsURL(args), response));
|
||||
|
||||
QObject::connect(netJob, &NetJob::succeeded, caller, [response, caller, args] {
|
||||
QObject::connect(netJob, &NetJob::succeeded, [response, callback, args] {
|
||||
QJsonParseError parse_error{};
|
||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||
if (parse_error.error != QJsonParseError::NoError) {
|
||||
qWarning() << "Error while parsing JSON response from " << caller->debugName() << " at " << parse_error.offset
|
||||
qWarning() << "Error while parsing JSON response for getting versions at " << parse_error.offset
|
||||
<< " reason: " << parse_error.errorString();
|
||||
qWarning() << *response;
|
||||
return;
|
||||
}
|
||||
|
||||
caller->versionRequestSucceeded(doc, args.addonId);
|
||||
callback(doc, args.addonId);
|
||||
});
|
||||
|
||||
QObject::connect(netJob, &NetJob::finished, caller, [response, netJob] {
|
||||
QObject::connect(netJob, &NetJob::finished, [response, netJob] {
|
||||
netJob->deleteLater();
|
||||
delete response;
|
||||
});
|
||||
|
@ -5,8 +5,8 @@
|
||||
class NetworkModAPI : public ModAPI {
|
||||
public:
|
||||
void searchMods(CallerType* caller, SearchArgs&& args) const override;
|
||||
void getModInfo(CallerType* caller, ModPlatform::IndexedPack& pack) override;
|
||||
void getVersions(CallerType* caller, VersionSearchArgs&& args) const override;
|
||||
void getModInfo(ModPlatform::IndexedPack& pack, std::function<void(QJsonDocument&, ModPlatform::IndexedPack&)> callback) override;
|
||||
void getVersions(VersionSearchArgs&& args, std::function<void(QJsonDocument&, QString)> callback) const override;
|
||||
|
||||
auto getProject(QString addonId, QByteArray* response) const -> NetJob* override;
|
||||
|
||||
|
@ -87,6 +87,8 @@ void Modrinth::loadExtraPackData(ModPlatform::IndexedPack& pack, QJsonObject& ob
|
||||
pack.extraData.donate.append(donate);
|
||||
}
|
||||
|
||||
pack.extraData.body = Json::ensureString(obj, "body");
|
||||
|
||||
pack.extraDataLoaded = true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user