From 9d5f4059bfe3a9563df8094818562aa89b6c5fd5 Mon Sep 17 00:00:00 2001 From: DioEgizio <83089242+DioEgizio@users.noreply.github.com> Date: Mon, 15 Dec 2025 18:10:35 +0100 Subject: [PATCH] feat+fix: Rework modrinth fallback for blocked mods a bit Signed-off-by: DioEgizio <83089242+DioEgizio@users.noreply.github.com> --- launcher/Application.cpp | 1 + .../modplatform/flame/FileResolvingTask.cpp | 39 +++++++++---------- launcher/ui/pages/global/APIPage.cpp | 5 +++ launcher/ui/pages/global/APIPage.ui | 13 +++++-- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 21bb43d3a..622f688e6 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -886,6 +886,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) m_settings->set("FlameKeyOverride", flameKey); m_settings->reset("CFKeyOverride"); } + m_settings->registerSetting("FallbackMRBlockedMods", true); m_settings->registerSetting("ModrinthToken", ""); m_settings->registerSetting("UserAgentOverride", ""); diff --git a/launcher/modplatform/flame/FileResolvingTask.cpp b/launcher/modplatform/flame/FileResolvingTask.cpp index 3989d0427..9cd85aef7 100644 --- a/launcher/modplatform/flame/FileResolvingTask.cpp +++ b/launcher/modplatform/flame/FileResolvingTask.cpp @@ -29,6 +29,8 @@ #include "net/NetJob.h" #include "tasks/Task.h" +#include "Application.h" + static const FlameAPI flameAPI; static ModrinthAPI modrinthAPI; @@ -169,34 +171,30 @@ void Flame::FileResolvingTask::netJobFinished(QByteArray* response) getFlameProjects(); return; - } + } + if (APPLICATION->settings()->get("FallbackMRBlockedMods").toBool()){ + try { + auto entries = Json::requireObject(doc); + for (auto& out : m_manifest.files) { + auto url = QUrl(out.version.downloadUrl, QUrl::TolerantMode); + if (!url.isValid() && "sha1" == out.version.hash_type && !out.version.hash.isEmpty()) { + try { + auto entry = Json::requireObject(entries, out.version.hash); - try { - auto entries = Json::requireObject(doc); - for (auto& out : m_manifest.files) { - auto url = QUrl(out.version.downloadUrl, QUrl::TolerantMode); - if (!url.isValid() && "sha1" == out.version.hash_type && !out.version.hash.isEmpty()) { - try { - auto entry = Json::requireObject(entries, out.version.hash); + auto file = Modrinth::loadIndexedPackVersion(entry); - auto file = Modrinth::loadIndexedPackVersion(entry); - - // If there's more than one mod loader for this version, we can't know for sure - // which file is relative to each loader, so it's best to not use any one and - // let the user download it manually. - if (!file.loaders || hasSingleModLoaderSelected(file.loaders)) { out.version.downloadUrl = file.downloadUrl; qDebug() << "Found alternative on modrinth" << out.version.fileName; + } catch (Json::JsonException& e) { + qDebug() << e.cause(); + qDebug() << entries; } - } catch (Json::JsonException& e) { - qDebug() << e.cause(); - qDebug() << entries; } } + } catch (Json::JsonException& e) { + qDebug() << e.cause(); + qDebug() << doc; } - } catch (Json::JsonException& e) { - qDebug() << e.cause(); - qDebug() << doc; } getFlameProjects(); }); @@ -215,7 +213,6 @@ void Flame::FileResolvingTask::netJobFinished(QByteArray* response) step_progress->status = status; stepProgress(*step_progress); }); - m_task->start(); } diff --git a/launcher/ui/pages/global/APIPage.cpp b/launcher/ui/pages/global/APIPage.cpp index 0cfe0c3b0..c399df469 100644 --- a/launcher/ui/pages/global/APIPage.cpp +++ b/launcher/ui/pages/global/APIPage.cpp @@ -135,6 +135,10 @@ void APIPage::loadSettings() ui->pasteTypeComboBox->setCurrentIndex(pasteTypeIndex); + if (bool fallbackMRBlockedMods = s->get("FallbackMRBlockedMods").toBool()) { + ui->FallbackMRBlockedMods->setChecked(fallbackMRBlockedMods); + } + QString msaClientID = s->get("MSAClientIDOverride").toString(); ui->msaClientID->setText(msaClientID); QString metaURL = s->get("MetaURLOverride").toString(); @@ -188,6 +192,7 @@ void APIPage::applySettings() upgradeToHTTPS(resourceURL); upgradeToHTTPS(fmlLibsURL); + s->set("FallbackMRBlockedMods", ui->FallbackMRBlockedMods->checkState()); s->set("MetaURLOverride", metaURL.toString()); s->set("ResourceURLOverride", resourceURL.toString()); s->set("LegacyFMLLibsURLOverride", fmlLibsURL.toString()); diff --git a/launcher/ui/pages/global/APIPage.ui b/launcher/ui/pages/global/APIPage.ui index 5b46cd6d7..7d759d256 100644 --- a/launcher/ui/pages/global/APIPage.ui +++ b/launcher/ui/pages/global/APIPage.ui @@ -32,9 +32,9 @@ 0 - -216 - 816 - 832 + -262 + 820 + 908 @@ -379,6 +379,13 @@ + + + + Enable fallback to Modrinth for blocked mods + + +