Merge remote-tracking branch 'upstream/develop' into no-ensure

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad
2025-11-10 18:56:32 +00:00
28 changed files with 139 additions and 112 deletions

View File

@@ -405,8 +405,8 @@ if(UNIX AND APPLE)
set(MACOSX_SPARKLE_UPDATE_PUBLIC_KEY "v55ZWWD6QlPoXGV6VLzOTZxZUggWeE51X8cRQyQh6vA=" CACHE STRING "Public key for Sparkle update feed")
set(MACOSX_SPARKLE_UPDATE_FEED_URL "https://prismlauncher.org/feed/appcast.xml" CACHE STRING "URL for Sparkle update feed")
set(MACOSX_SPARKLE_DOWNLOAD_URL "https://github.com/sparkle-project/Sparkle/releases/download/2.6.4/Sparkle-2.6.4.tar.xz" CACHE STRING "URL to Sparkle release archive")
set(MACOSX_SPARKLE_SHA256 "50612a06038abc931f16011d7903b8326a362c1074dabccb718404ce8e585f0b" CACHE STRING "SHA256 checksum for Sparkle release archive")
set(MACOSX_SPARKLE_DOWNLOAD_URL "https://github.com/sparkle-project/Sparkle/releases/download/2.8.0/Sparkle-2.8.0.tar.xz" CACHE STRING "URL to Sparkle release archive")
set(MACOSX_SPARKLE_SHA256 "fd5681ee92bf238aaac2d08214ceaf0cc8976e452d7f882d80bac1e61581f3b1" CACHE STRING "SHA256 checksum for Sparkle release archive")
set(MACOSX_SPARKLE_DIR "${CMAKE_BINARY_DIR}/frameworks/Sparkle")
if(NOT MACOSX_SPARKLE_UPDATE_PUBLIC_KEY STREQUAL "" AND NOT MACOSX_SPARKLE_UPDATE_FEED_URL STREQUAL "")

6
flake.lock generated
View File

@@ -18,11 +18,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1761907660,
"narHash": "sha256-kJ8lIZsiPOmbkJypG+B5sReDXSD1KGu2VEPNqhRa/ew=",
"lastModified": 1762363567,
"narHash": "sha256-YRqMDEtSMbitIMj+JLpheSz0pwEr0Rmy5mC7myl17xs=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2fb006b87f04c4d3bdf08cfdbc7fab9c13d94a15",
"rev": "ae814fd3904b621d8ab97418f1d0f2eb0d3716f4",
"type": "github"
},
"original": {

View File

@@ -35,34 +35,8 @@
#include "Application.h"
// #define BREAK_INFINITE_LOOP
// #define BREAK_EXCEPTION
// #define BREAK_RETURN
#ifdef BREAK_INFINITE_LOOP
#include <chrono>
#include <thread>
#endif
int main(int argc, char* argv[])
{
#ifdef BREAK_INFINITE_LOOP
while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(250));
}
#endif
#ifdef BREAK_EXCEPTION
throw 42;
#endif
#ifdef BREAK_RETURN
return 42;
#endif
#if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0)
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
// initialize Qt
Application app(argc, argv);

View File

@@ -22,10 +22,16 @@
#include "FileSystem.h"
static QImage improveSkin(const QImage& skin)
static QImage improveSkin(QImage skin)
{
// It seems some older skins may use this format, which can't be drawn onto
// https://github.com/PrismLauncher/PrismLauncher/issues/4032
// https://doc.qt.io/qt-6/qpainter.html#begin
if (skin.format() == QImage::Format_Indexed8) {
skin = skin.convertToFormat(QImage::Format_RGB32);
}
if (skin.size() == QSize(64, 32)) { // old format
QImage newSkin = QImage(QSize(64, 64), skin.format());
auto newSkin = QImage(QSize(64, 64), skin.format());
newSkin.fill(Qt::transparent);
QPainter p(&newSkin);
p.drawImage(QPoint(0, 0), skin.copy(QRect(0, 0, 64, 32))); // copy head
@@ -109,7 +115,7 @@ SkinModel::SkinModel(QDir skinDir, QJsonObject obj)
m_model = Model::SLIM;
}
m_path = skinDir.absoluteFilePath(name) + ".png";
m_texture = QImage(getSkin(m_path));
m_texture = getSkin(m_path);
m_preview = generatePreviews(m_texture, m_model == Model::SLIM);
}

View File

@@ -67,7 +67,10 @@ Task::Ptr ResourceAPI::searchProjects(SearchArgs&& args, Callback<QList<ModPlatf
}
callbacks.on_fail(reason, network_error_code);
});
QObject::connect(netJob.get(), &NetJob::aborted, [callbacks] { callbacks.on_abort(); });
QObject::connect(netJob.get(), &NetJob::aborted, [callbacks] {
if (callbacks.on_abort != nullptr)
callbacks.on_abort();
});
return netJob;
}
@@ -80,7 +83,7 @@ Task::Ptr ResourceAPI::getProjectVersions(VersionSearchArgs&& args, Callback<QVe
auto versions_url = versions_url_optional.value();
auto netJob = makeShared<NetJob>(QString("%1::Versions").arg(args.pack.name), APPLICATION->network());
auto netJob = makeShared<NetJob>(QString("%1::Versions").arg(args.pack->name), APPLICATION->network());
auto response = std::make_shared<QByteArray>();
netJob->addNetAction(Net::ApiDownload::makeByteArray(versions_url, response));
@@ -104,7 +107,7 @@ Task::Ptr ResourceAPI::getProjectVersions(VersionSearchArgs&& args, Callback<QVe
auto file = loadIndexedPackVersion(obj, args.resourceType);
if (!file.addonId.isValid())
file.addonId = args.pack.addonId;
file.addonId = args.pack->addonId;
if (file.fileId.isValid() && !file.downloadUrl.isEmpty()) // Heuristic to check if the returned value is valid
unsortedVersions.append(file);
@@ -135,15 +138,18 @@ Task::Ptr ResourceAPI::getProjectVersions(VersionSearchArgs&& args, Callback<QVe
}
callbacks.on_fail(reason, network_error_code);
});
QObject::connect(netJob.get(), &NetJob::aborted, [callbacks] { callbacks.on_abort(); });
QObject::connect(netJob.get(), &NetJob::aborted, [callbacks] {
if (callbacks.on_abort != nullptr)
callbacks.on_abort();
});
return netJob;
}
Task::Ptr ResourceAPI::getProjectInfo(ProjectInfoArgs&& args, Callback<ModPlatform::IndexedPack>&& callbacks) const
Task::Ptr ResourceAPI::getProjectInfo(ProjectInfoArgs&& args, Callback<ModPlatform::IndexedPack::Ptr>&& callbacks) const
{
auto response = std::make_shared<QByteArray>();
auto job = getProject(args.pack.addonId.toString(), response);
auto job = getProject(args.pack->addonId.toString(), response);
QObject::connect(job.get(), &NetJob::succeeded, [this, response, callbacks, args] {
auto pack = args.pack;
@@ -159,8 +165,8 @@ Task::Ptr ResourceAPI::getProjectInfo(ProjectInfoArgs&& args, Callback<ModPlatfo
auto obj = Json::requireObject(doc);
if (obj.contains("data"))
obj = Json::requireObject(obj, "data");
loadIndexedPack(pack, obj);
loadExtraPackInfo(pack, obj);
loadIndexedPack(*pack, obj);
loadExtraPackInfo(*pack, obj);
} catch (const JSONValidationError& e) {
qDebug() << doc;
qWarning() << "Error while reading " << debugName() << " resource info: " << e.cause();
@@ -182,7 +188,10 @@ Task::Ptr ResourceAPI::getProjectInfo(ProjectInfoArgs&& args, Callback<ModPlatfo
}
callbacks.on_fail(reason, network_error_code);
});
QObject::connect(job.get(), &NetJob::aborted, [callbacks] { callbacks.on_abort(); });
QObject::connect(job.get(), &NetJob::aborted, [callbacks] {
if (callbacks.on_abort != nullptr)
callbacks.on_abort();
});
return job;
}

View File

@@ -88,7 +88,7 @@ class ResourceAPI {
};
struct VersionSearchArgs {
ModPlatform::IndexedPack pack;
ModPlatform::IndexedPack::Ptr pack;
std::optional<std::list<Version>> mcVersions;
std::optional<ModPlatform::ModLoaderTypes> loaders;
@@ -96,7 +96,7 @@ class ResourceAPI {
};
struct ProjectInfoArgs {
ModPlatform::IndexedPack pack;
ModPlatform::IndexedPack::Ptr pack;
};
struct DependencySearchArgs {
@@ -115,7 +115,7 @@ class ResourceAPI {
virtual Task::Ptr getProject(QString addonId, std::shared_ptr<QByteArray> response) const;
virtual Task::Ptr getProjects(QStringList addonIds, std::shared_ptr<QByteArray> response) const = 0;
virtual Task::Ptr getProjectInfo(ProjectInfoArgs&&, Callback<ModPlatform::IndexedPack>&&) const;
virtual Task::Ptr getProjectInfo(ProjectInfoArgs&&, Callback<ModPlatform::IndexedPack::Ptr>&&) const;
Task::Ptr getProjectVersions(VersionSearchArgs&& args, Callback<QVector<ModPlatform::IndexedVersion>>&& callbacks) const;
virtual Task::Ptr getDependencyVersion(DependencySearchArgs&&, Callback<ModPlatform::IndexedVersion>&&) const;

View File

@@ -126,7 +126,7 @@ class FlameAPI : public ResourceAPI {
std::optional<QString> getVersionsURL(VersionSearchArgs const& args) const override
{
auto addonId = args.pack.addonId.toString();
auto addonId = args.pack->addonId.toString();
QString url = QString(BuildConfig.FLAME_BASE_URL + "/mods/%1/files?pageSize=10000").arg(addonId);
if (args.mcVersions.has_value())
@@ -160,10 +160,7 @@ class FlameAPI : public ResourceAPI {
void loadExtraPackInfo(ModPlatform::IndexedPack& m, [[maybe_unused]] QJsonObject&) const override { FlameMod::loadBody(m); }
private:
std::optional<QString> getInfoURL(QString const& id) const override
{
return QString(BuildConfig.FLAME_BASE_URL + "/mods/%1").arg(id);
}
std::optional<QString> getInfoURL(QString const& id) const override { return QString(BuildConfig.FLAME_BASE_URL + "/mods/%1").arg(id); }
std::optional<QString> getDependencyURL(DependencySearchArgs const& args) const override
{
auto addonId = args.dependency.addonId.toString();

View File

@@ -46,7 +46,9 @@ void FlameCheckUpdate::executeTask()
connect(netJob, &Task::stepProgress, this, &FlameCheckUpdate::propagateStepProgress);
connect(netJob, &Task::details, this, &FlameCheckUpdate::setDetails);
for (auto* resource : m_resources) {
auto versionsUrlOptional = api.getVersionsURL({ { resource->metadata()->project_id.toString() }, m_gameVersions });
auto project = std::make_shared<ModPlatform::IndexedPack>();
project->addonId = resource->metadata()->project_id.toString();
auto versionsUrlOptional = api.getVersionsURL({ project, m_gameVersions });
if (!versionsUrlOptional.has_value())
continue;

View File

@@ -26,12 +26,15 @@ void FlameMod::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
}
auto authors = obj["authors"].toArray();
for (auto authorIter : authors) {
auto author = Json::requireObject(authorIter);
ModPlatform::ModpackAuthor packAuthor;
packAuthor.name = Json::requireString(author, "name");
packAuthor.url = Json::requireString(author, "url");
pack.authors.append(packAuthor);
if (!authors.isEmpty()) {
pack.authors.clear();
for (auto authorIter : authors) {
auto author = Json::requireObject(authorIter);
ModPlatform::ModpackAuthor packAuthor;
packAuthor.name = Json::requireString(author, "name");
packAuthor.url = Json::requireString(author, "url");
pack.authors.append(packAuthor);
}
}
pack.extraDataLoaded = false;

View File

@@ -45,7 +45,8 @@ class ModrinthAPI : public ResourceAPI {
{
QStringList l;
for (auto loader : { ModPlatform::NeoForge, ModPlatform::Forge, ModPlatform::Fabric, ModPlatform::Quilt, ModPlatform::LiteLoader,
ModPlatform::DataPack, ModPlatform::Babric, ModPlatform::BTA, ModPlatform::LegacyFabric, ModPlatform::Ornithe, ModPlatform::Rift }) {
ModPlatform::DataPack, ModPlatform::Babric, ModPlatform::BTA, ModPlatform::LegacyFabric, ModPlatform::Ornithe,
ModPlatform::Rift }) {
if (types & loader) {
l << getModLoaderAsString(loader);
}
@@ -188,7 +189,7 @@ class ModrinthAPI : public ResourceAPI {
get_arguments.append(QString("loaders=[\"%1\"]").arg(getModLoaderStrings(args.loaders.value()).join("\",\"")));
return QString("%1/project/%2/version%3%4")
.arg(BuildConfig.MODRINTH_PROD_URL, args.pack.addonId.toString(), get_arguments.isEmpty() ? "" : "?", get_arguments.join('&'));
.arg(BuildConfig.MODRINTH_PROD_URL, args.pack->addonId.toString(), get_arguments.isEmpty() ? "" : "?", get_arguments.join('&'));
};
QString getGameVersionsArray(std::list<Version> mcVersions) const
@@ -204,7 +205,8 @@ class ModrinthAPI : public ResourceAPI {
static inline auto validateModLoaders(ModPlatform::ModLoaderTypes loaders) -> bool
{
return loaders & (ModPlatform::NeoForge | ModPlatform::Forge | ModPlatform::Fabric | ModPlatform::Quilt | ModPlatform::LiteLoader |
ModPlatform::DataPack | ModPlatform::Babric | ModPlatform::BTA | ModPlatform::LegacyFabric | ModPlatform::Ornithe | ModPlatform::Rift);
ModPlatform::DataPack | ModPlatform::Babric | ModPlatform::BTA | ModPlatform::LegacyFabric |
ModPlatform::Ornithe | ModPlatform::Rift);
}
std::optional<QString> getDependencyURL(DependencySearchArgs const& args) const override

View File

@@ -249,7 +249,7 @@ bool ModrinthCreationTask::createInstance()
auto root_modpack_url = QUrl::fromLocalFile(root_modpack_path);
// TODO make this work with other sorts of resource
QHash<QString, Resource*> resources;
for (auto file : m_files) {
for (auto& file : m_files) {
auto fileName = file.path;
fileName = FS::RemoveInvalidPathChars(fileName);
auto file_path = FS::PathCombine(root_modpack_path, fileName);

View File

@@ -33,7 +33,7 @@ bool shouldDownloadOnSide(QString side)
return side == "required" || side == "optional";
}
// https://docs.modrinth.com/api-spec/#tag/projects/operation/getProject
// https://docs.modrinth.com/api/operations/getproject/
void Modrinth::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
{
pack.addonId = obj["project_id"].toString();
@@ -54,10 +54,12 @@ void Modrinth::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
pack.logoUrl = obj["icon_url"].toString("");
pack.logoName = QString("%1.%2").arg(obj["slug"].toString()), QFileInfo(QUrl(pack.logoUrl).fileName()).suffix();
ModPlatform::ModpackAuthor modAuthor;
modAuthor.name = obj["author"].toString(QObject::tr("No author(s)"));
modAuthor.url = api.getAuthorURL(modAuthor.name);
pack.authors.append(modAuthor);
if (obj.contains("author")) {
ModPlatform::ModpackAuthor modAuthor;
modAuthor.name = obj["author"].toString();
modAuthor.url = api.getAuthorURL(modAuthor.name);
pack.authors = { modAuthor };
}
auto client = shouldDownloadOnSide(obj["client_side"].toString());
auto server = shouldDownloadOnSide(obj["server_side"].toString());

View File

@@ -252,7 +252,6 @@
<file>scalable/discord.svg</file>
<!-- flat instance icons CC BY-SA 4.0, Santiago Cézar -->
<file alias="128x128/flame.png">scalable/instances/flame.svg</file>
<file>scalable/instances/chicken.svg</file>
<file>scalable/instances/creeper.svg</file>
<file>scalable/instances/enderpearl.svg</file>

View File

@@ -202,6 +202,13 @@ void SkinOpenGLWindow::resizeGL(int w, int h)
void SkinOpenGLWindow::paintGL()
{
// Adjust the viewport to account for fractional scaling
qreal dpr = devicePixelRatio();
if (dpr != 1.f) {
QSize scaledSize = size() * dpr;
glViewport(0, 0, scaledSize.width(), scaledSize.height());
}
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -235,6 +242,13 @@ void SkinOpenGLWindow::paintGL()
m_scene->draw(m_modelProgram);
m_modelProgram->release();
// Redraw the first frame; this is necessary because the pixel ratio for Wayland fractional scaling is not negotiated properly on the
// first frame
if (m_isFirstFrame) {
m_isFirstFrame = false;
update();
}
}
void SkinOpenGLWindow::updateScene(SkinModel* skin)

View File

@@ -74,6 +74,8 @@ class SkinOpenGLWindow : public QOpenGLWindow, protected QOpenGLFunctions {
float m_yaw = 90; // Horizontal rotation angle
float m_pitch = 0; // Vertical rotation angle
bool m_isFirstFrame = true;
opengl::BoxGeometry* m_background = nullptr;
QOpenGLTexture* m_backgroundTexture = nullptr;
QColor m_baseColor;

View File

@@ -6,12 +6,14 @@
#include <QDesktopServices>
#include <QUrl>
#include <QUrlQuery>
#include "modplatform/ModIndex.h"
#include "ui_ManagedPackPage.h"
#include <QFileDialog>
#include <QListView>
#include <QProxyStyle>
#include <QStyleFactory>
#include <memory>
#include "Application.h"
#include "BuildConfig.h"
@@ -284,7 +286,8 @@ void ModrinthManagedPackPage::parseManagedPack()
};
callbacks.on_fail = [this](QString reason, int) { setFailState(); };
callbacks.on_abort = [this]() { setFailState(); };
m_fetch_job = m_api.getProjectVersions({ m_pack, {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
m_fetch_job = m_api.getProjectVersions(
{ std::make_shared<ModPlatform::IndexedPack>(m_pack), {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
ui->changelogTextBrowser->setText(tr("Fetching changelogs..."));
@@ -455,7 +458,8 @@ void FlameManagedPackPage::parseManagedPack()
};
callbacks.on_fail = [this](QString reason, int) { setFailState(); };
callbacks.on_abort = [this]() { setFailState(); };
m_fetch_job = m_api.getProjectVersions({ m_pack, {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
m_fetch_job = m_api.getProjectVersions(
{ std::make_shared<ModPlatform::IndexedPack>(m_pack), {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
m_fetch_job->start();
}

View File

@@ -23,14 +23,14 @@ ResourceAPI::SearchArgs DataPackResourceModel::createSearchArguments()
ResourceAPI::VersionSearchArgs DataPackResourceModel::createVersionsArguments(const QModelIndex& entry)
{
auto& pack = m_packs[entry.row()];
return { *pack, {}, ModPlatform::ModLoaderType::DataPack };
auto pack = m_packs[entry.row()];
return { pack, {}, ModPlatform::ModLoaderType::DataPack };
}
ResourceAPI::ProjectInfoArgs DataPackResourceModel::createInfoArguments(const QModelIndex& entry)
{
auto& pack = m_packs[entry.row()];
return { *pack };
auto pack = m_packs[entry.row()];
return { pack };
}
void DataPackResourceModel::searchWithTerm(const QString& term, unsigned int sort)

View File

@@ -49,7 +49,7 @@ ResourceAPI::SearchArgs ModModel::createSearchArguments()
ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(const QModelIndex& entry)
{
auto& pack = *m_packs[entry.row()];
auto pack = m_packs[entry.row()];
auto profile = static_cast<MinecraftInstance const&>(m_base_instance).getPackProfile();
Q_ASSERT(profile);
@@ -67,7 +67,7 @@ ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(const QModelInd
ResourceAPI::ProjectInfoArgs ModModel::createInfoArguments(const QModelIndex& entry)
{
auto& pack = *m_packs[entry.row()];
auto pack = m_packs[entry.row()];
return { pack };
}

View File

@@ -141,7 +141,7 @@ void ResourceModel::search()
if (m_search_term.startsWith("#")) {
auto projectId = m_search_term.mid(1);
if (!projectId.isEmpty()) {
ResourceAPI::Callback<ModPlatform::IndexedPack> callbacks;
ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks;
callbacks.on_fail = [this](QString reason, int) {
if (!s_running_models.constFind(this).value())
@@ -159,7 +159,9 @@ void ResourceModel::search()
return;
searchRequestForOneSucceeded(pack);
};
if (auto job = m_api->getProjectInfo({ projectId }, std::move(callbacks)); job)
auto project = std::make_shared<ModPlatform::IndexedPack>();
project->addonId = projectId;
if (auto job = m_api->getProjectInfo({ project }, std::move(callbacks)); job)
runSearchJob(job);
return;
}
@@ -219,7 +221,7 @@ void ResourceModel::loadEntry(const QModelIndex& entry)
if (!pack->extraDataLoaded) {
auto args{ createInfoArguments(entry) };
ResourceAPI::Callback<ModPlatform::IndexedPack> callbacks{};
ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks{};
callbacks.on_succeed = [this, entry](auto& newpack) {
if (!s_running_models.constFind(this).value())
@@ -388,12 +390,12 @@ void ResourceModel::searchRequestSucceeded(QList<ModPlatform::IndexedPack::Ptr>&
endInsertRows();
}
void ResourceModel::searchRequestForOneSucceeded(ModPlatform::IndexedPack& pack)
void ResourceModel::searchRequestForOneSucceeded(ModPlatform::IndexedPack::Ptr pack)
{
m_search_state = SearchState::Finished;
beginInsertRows(QModelIndex(), m_packs.size(), m_packs.size() + 1);
m_packs.append(std::make_shared<ModPlatform::IndexedPack>(pack));
m_packs.append(pack);
endInsertRows();
}
@@ -448,18 +450,17 @@ void ResourceModel::versionRequestSucceeded(QVector<ModPlatform::IndexedVersion>
emit versionListUpdated(index);
}
void ResourceModel::infoRequestSucceeded(ModPlatform::IndexedPack& pack, const QModelIndex& index)
void ResourceModel::infoRequestSucceeded(ModPlatform::IndexedPack::Ptr pack, const QModelIndex& index)
{
auto current_pack = data(index, Qt::UserRole).value<ModPlatform::IndexedPack::Ptr>();
// Check if the index is still valid for this resource or not
if (pack.addonId != current_pack->addonId)
if (pack->addonId != current_pack->addonId)
return;
*current_pack = pack;
// Cache info :^)
QVariant new_pack;
new_pack.setValue(current_pack);
new_pack.setValue(pack);
if (!setData(index, new_pack, Qt::UserRole)) {
qWarning() << "Failed to cache resource info!";
return;

View File

@@ -138,13 +138,13 @@ class ResourceModel : public QAbstractListModel {
private:
/* Default search request callbacks */
void searchRequestSucceeded(QList<ModPlatform::IndexedPack::Ptr>&);
void searchRequestForOneSucceeded(ModPlatform::IndexedPack&);
void searchRequestForOneSucceeded(ModPlatform::IndexedPack::Ptr);
void searchRequestFailed(QString reason, int network_error_code);
void searchRequestAborted();
void versionRequestSucceeded(QVector<ModPlatform::IndexedVersion>&, QVariant, const QModelIndex&);
void infoRequestSucceeded(ModPlatform::IndexedPack&, const QModelIndex&);
void infoRequestSucceeded(ModPlatform::IndexedPack::Ptr, const QModelIndex&);
signals:
void versionListUpdated(const QModelIndex& index);

View File

@@ -25,14 +25,14 @@ ResourceAPI::SearchArgs ResourcePackResourceModel::createSearchArguments()
ResourceAPI::VersionSearchArgs ResourcePackResourceModel::createVersionsArguments(const QModelIndex& entry)
{
auto& pack = m_packs[entry.row()];
return { *pack, {}, {}, ModPlatform::ResourceType::ResourcePack };
auto pack = m_packs[entry.row()];
return { pack, {}, {}, ModPlatform::ResourceType::ResourcePack };
}
ResourceAPI::ProjectInfoArgs ResourcePackResourceModel::createInfoArguments(const QModelIndex& entry)
{
auto& pack = m_packs[entry.row()];
return { *pack };
auto pack = m_packs[entry.row()];
return { pack };
}
void ResourcePackResourceModel::searchWithTerm(const QString& term, unsigned int sort)

View File

@@ -22,14 +22,14 @@ ResourceAPI::SearchArgs ShaderPackResourceModel::createSearchArguments()
ResourceAPI::VersionSearchArgs ShaderPackResourceModel::createVersionsArguments(const QModelIndex& entry)
{
auto& pack = m_packs[entry.row()];
return { *pack, {}, {}, ModPlatform::ResourceType::ShaderPack };
auto pack = m_packs[entry.row()];
return { pack, {}, {}, ModPlatform::ResourceType::ShaderPack };
}
ResourceAPI::ProjectInfoArgs ShaderPackResourceModel::createInfoArguments(const QModelIndex& entry)
{
auto& pack = m_packs[entry.row()];
return { *pack };
auto pack = m_packs[entry.row()];
return { pack };
}
void ShaderPackResourceModel::searchWithTerm(const QString& term, unsigned int sort)

View File

@@ -11,6 +11,7 @@
#include <Version.h>
#include <QtMath>
#include <memory>
namespace Flame {
@@ -167,7 +168,7 @@ void ListModel::performPaginatedSearch()
if (m_currentSearchTerm.startsWith("#")) {
auto projectId = m_currentSearchTerm.mid(1);
if (!projectId.isEmpty()) {
ResourceAPI::Callback<ModPlatform::IndexedPack> callbacks;
ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks;
callbacks.on_fail = [this](QString reason, int) { searchRequestFailed(reason); };
callbacks.on_succeed = [this](auto& pack) { searchRequestForOneSucceeded(pack); };
@@ -175,7 +176,9 @@ void ListModel::performPaginatedSearch()
qCritical() << "Search task aborted by an unknown reason!";
searchRequestFailed("Aborted");
};
if (auto job = api.getProjectInfo({ { projectId } }, std::move(callbacks)); job) {
auto project = std::make_shared<ModPlatform::IndexedPack>();
project->addonId = projectId;
if (auto job = api.getProjectInfo({ project }, std::move(callbacks)); job) {
m_jobPtr = job;
m_jobPtr->start();
}
@@ -189,6 +192,10 @@ void ListModel::performPaginatedSearch()
callbacks.on_succeed = [this](auto& doc) { searchRequestFinished(doc); };
callbacks.on_fail = [this](QString reason, int) { searchRequestFailed(reason); };
callbacks.on_abort = [this] {
qCritical() << "Search task aborted by an unknown reason!";
searchRequestFailed("Aborted");
};
auto netJob = api.searchProjects({ ModPlatform::ResourceType::Modpack, m_nextSearchOffset, m_currentSearchTerm, sort, m_filter->loaders,
m_filter->versions, ModPlatform::Side::NoSide, m_filter->categoryIds, m_filter->openSource },
@@ -241,12 +248,12 @@ void Flame::ListModel::searchRequestFinished(QList<ModPlatform::IndexedPack::Ptr
endInsertRows();
}
void Flame::ListModel::searchRequestForOneSucceeded(ModPlatform::IndexedPack& pack)
void Flame::ListModel::searchRequestForOneSucceeded(ModPlatform::IndexedPack::Ptr pack)
{
m_jobPtr.reset();
beginInsertRows(QModelIndex(), m_modpacks.size(), m_modpacks.size() + 1);
m_modpacks.append(std::make_shared<ModPlatform::IndexedPack>(pack));
m_modpacks.append(pack);
endInsertRows();
}

View File

@@ -50,7 +50,7 @@ class ListModel : public QAbstractListModel {
void searchRequestFinished(QList<ModPlatform::IndexedPack::Ptr>&);
void searchRequestFailed(QString reason);
void searchRequestForOneSucceeded(ModPlatform::IndexedPack&);
void searchRequestForOneSucceeded(ModPlatform::IndexedPack::Ptr);
private:
void requestLogo(QString file, QString url);

View File

@@ -203,7 +203,7 @@ void FlamePage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelInde
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec();
};
auto netJob = api.getProjectVersions({ *m_current, {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
auto netJob = api.getProjectVersions({ m_current, {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
m_job = netJob;
netJob->start();

View File

@@ -47,6 +47,7 @@
#include "net/ApiDownload.h"
#include <QMessageBox>
#include <memory>
namespace Modrinth {
@@ -137,7 +138,7 @@ void ModpackListModel::performPaginatedSearch()
if (m_currentSearchTerm.startsWith("#")) {
auto projectId = m_currentSearchTerm.mid(1);
if (!projectId.isEmpty()) {
ResourceAPI::Callback<ModPlatform::IndexedPack> callbacks;
ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks;
callbacks.on_fail = [this](QString reason, int) { searchRequestFailed(reason); };
callbacks.on_succeed = [this](auto& pack) { searchRequestForOneSucceeded(pack); };
@@ -145,7 +146,9 @@ void ModpackListModel::performPaginatedSearch()
qCritical() << "Search task aborted by an unknown reason!";
searchRequestFailed("Aborted");
};
if (auto job = api.getProjectInfo({ projectId }, std::move(callbacks)); job) {
auto project = std::make_shared<ModPlatform::IndexedPack>();
project->addonId = projectId;
if (auto job = api.getProjectInfo({ project }, std::move(callbacks)); job) {
m_jobPtr = job;
m_jobPtr->start();
}
@@ -159,6 +162,10 @@ void ModpackListModel::performPaginatedSearch()
callbacks.on_succeed = [this](auto& doc) { searchRequestFinished(doc); };
callbacks.on_fail = [this](QString reason, int) { searchRequestFailed(reason); };
callbacks.on_abort = [this] {
qCritical() << "Search task aborted by an unknown reason!";
searchRequestFailed("Aborted");
};
auto netJob = api.searchProjects({ ModPlatform::ResourceType::Modpack, m_nextSearchOffset, m_currentSearchTerm, sort, m_filter->loaders,
m_filter->versions, ModPlatform::Side::NoSide, m_filter->categoryIds, m_filter->openSource },
@@ -300,12 +307,12 @@ void ModpackListModel::searchRequestFinished(QList<ModPlatform::IndexedPack::Ptr
endInsertRows();
}
void ModpackListModel::searchRequestForOneSucceeded(ModPlatform::IndexedPack& pack)
void ModpackListModel::searchRequestForOneSucceeded(ModPlatform::IndexedPack::Ptr pack)
{
m_jobPtr.reset();
beginInsertRows(QModelIndex(), m_modpacks.size(), m_modpacks.size() + 1);
m_modpacks.append(std::make_shared<ModPlatform::IndexedPack>(pack));
m_modpacks.append(pack);
endInsertRows();
}

View File

@@ -86,7 +86,7 @@ class ModpackListModel : public QAbstractListModel {
public slots:
void searchRequestFinished(QList<ModPlatform::IndexedPack::Ptr>& doc_all);
void searchRequestFailed(QString reason);
void searchRequestForOneSucceeded(ModPlatform::IndexedPack&);
void searchRequestForOneSucceeded(ModPlatform::IndexedPack::Ptr);
protected slots:

View File

@@ -146,7 +146,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelI
if (!m_current->extraDataLoaded) {
qDebug() << "Loading modrinth modpack information";
ResourceAPI::Callback<ModPlatform::IndexedPack> callbacks;
ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks;
auto id = m_current->addonId;
callbacks.on_fail = [this](QString reason, int) {
@@ -157,10 +157,8 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelI
return; // wrong request?
}
*m_current = pack;
QVariant current_updated;
current_updated.setValue(m_current);
current_updated.setValue(pack);
if (!m_model->setData(curr, current_updated, Qt::UserRole))
qWarning() << "Failed to cache extra info for the current pack!";
@@ -168,7 +166,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelI
suggestCurrent();
updateUI();
};
if (auto netJob = m_api.getProjectInfo({ { m_current->addonId } }, std::move(callbacks)); netJob) {
if (auto netJob = m_api.getProjectInfo({ m_current }, std::move(callbacks)); netJob) {
m_job = netJob;
m_job->start();
}
@@ -220,7 +218,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelI
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec();
};
auto netJob = m_api.getProjectVersions({ *m_current, {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
auto netJob = m_api.getProjectVersions({ m_current, {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
m_job2 = netJob;
m_job2->start();