From 16e3b786fc04ffd8d510bfb2a60157648825954f Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sun, 6 Nov 2022 10:08:54 +0000 Subject: [PATCH] Implement Scrumplex's suggestions Signed-off-by: TheKodeToad --- launcher/ui/dialogs/ModDownloadDialog.cpp | 4 +- launcher/ui/dialogs/ModDownloadDialog.h | 2 +- launcher/ui/pages/modplatform/ModPage.cpp | 46 ++++++++----------- .../pages/modplatform/flame/FlameModPage.cpp | 5 +- .../ui/pages/modplatform/flame/FlameModPage.h | 2 +- 5 files changed, 27 insertions(+), 32 deletions(-) diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index 0a0e61e36..24d23ba98 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 TheKodeToad * @@ -199,4 +199,4 @@ bool ModDownloadDialog::selectPage(QString pageId) ModPage* ModDownloadDialog::getSelectedPage() { return m_selectedPage; -} \ No newline at end of file +} diff --git a/launcher/ui/dialogs/ModDownloadDialog.h b/launcher/ui/dialogs/ModDownloadDialog.h index 29bdcf82d..fcf6f4fc2 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.h +++ b/launcher/ui/dialogs/ModDownloadDialog.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 TheKodeToad * diff --git a/launcher/ui/pages/modplatform/ModPage.cpp b/launcher/ui/pages/modplatform/ModPage.cpp index ec6f488fb..2f5f95bfc 100644 --- a/launcher/ui/pages/modplatform/ModPage.cpp +++ b/launcher/ui/pages/modplatform/ModPage.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 TheKodeToad * @@ -43,6 +43,7 @@ #include #include +#include #include "minecraft/MinecraftInstance.h" #include "minecraft/PackProfile.h" @@ -254,32 +255,25 @@ void ModPage::openUrl(const QUrl& url) } // detect mod URLs and search instead - int prefixLength = 0; + static const QRegularExpression modrinth(QRegularExpression::anchoredPattern("(?:www\\.)?modrinth\\.com\\/mod\\/([^\\/]+)\\/?")), + curseForge(QRegularExpression::anchoredPattern("(?:www\\.)?curseforge\\.com\\/minecraft\\/mc-mods\\/([^\\/]+)\\/?")), + curseForgeOld(QRegularExpression::anchoredPattern("minecraft\\.curseforge\\.com\\/projects\\/([^\\/]+)\\/?")); + + const QString address = url.host() + url.path(); + QRegularExpressionMatch match; const char* page; - if ((url.host() == "modrinth.com" || url.host() == "www.modrinth.com") && url.path().startsWith("/mod/")) { - prefixLength = 5; + if ((match = modrinth.match(address)).hasMatch()) page = "modrinth"; - } else if (APPLICATION->capabilities() & Application::SupportsFlame && - (url.host() == "curseforge.com" || url.host().endsWith(".curseforge.com"))) { - if (url.path().toLower().startsWith("/minecraft/mc-mods/")) - prefixLength = 19; - else if (url.path().toLower().startsWith("/projects/")) - prefixLength = 10; + else if (APPLICATION->capabilities() & Application::SupportsFlame && + ((match = curseForge.match(address)).hasMatch() || (match = curseForgeOld.match(address)).hasMatch())) page = "curseforge"; - } - if (prefixLength != 0) { - QString slug = url.path().mid(prefixLength); + if (match.hasMatch()) { + const QString slug = match.captured(1); - // remove trailing slash(es) - while (slug.endsWith('/')) - slug.remove(slug.length() - 1, 1); - - // ensure that the path doesn't contain any further slashes, - // and the user isn't opening the same mod; they probably - // intended to view in their web browser - if (!slug.isEmpty() && !slug.contains('/') && slug != current.slug) { + // ensure the user isn't opening the same mod + if (slug != current.slug) { dialog->selectPage(page); ModPage* newPage = dialog->getSelectedPage(); @@ -290,8 +284,8 @@ void ModPage::openUrl(const QUrl& url) auto jump = [url, slug, model, view] { for (int row = 0; row < model->rowCount({}); row++) { - QModelIndex index = model->index(row); - auto pack = model->data(index, Qt::UserRole).value(); + const QModelIndex index = model->index(row); + const auto pack = model->data(index, Qt::UserRole).value(); if (pack.slug == slug) { view->setCurrentIndex(index); @@ -306,10 +300,10 @@ void ModPage::openUrl(const QUrl& url) searchEdit->setText(slug); newPage->triggerSearch(); - if (!model->activeJob()) - jump(); - else + if (model->activeJob()) connect(model->activeJob(), &Task::finished, jump); + else + jump(); return; } diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp index faf12cea1..bad78c97d 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 TheKodeToad * @@ -84,6 +84,7 @@ void FlameModPage::openUrl(const QUrl& url) { if (url.scheme().isEmpty()) { QString query = url.query(QUrl::FullyDecoded); + if (query.startsWith("remoteUrl=")) { // attempt to resolve url from warning page query.remove(0, 10); @@ -93,4 +94,4 @@ void FlameModPage::openUrl(const QUrl& url) } ModPage::openUrl(url); -} \ No newline at end of file +} diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.h b/launcher/ui/pages/modplatform/flame/FlameModPage.h index da4fcdffb..58479ab94 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.h +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 TheKodeToad *