Implement Scrumplex's suggestions
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
cb796dbdfb
commit
16e3b786fc
@ -1,6 +1,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
@ -199,4 +199,4 @@ bool ModDownloadDialog::selectPage(QString pageId)
|
|||||||
ModPage* ModDownloadDialog::getSelectedPage()
|
ModPage* ModDownloadDialog::getSelectedPage()
|
||||||
{
|
{
|
||||||
return m_selectedPage;
|
return m_selectedPage;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
@ -43,6 +43,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <HoeDown.h>
|
#include <HoeDown.h>
|
||||||
|
#include <qregularexpression.h>
|
||||||
|
|
||||||
#include "minecraft/MinecraftInstance.h"
|
#include "minecraft/MinecraftInstance.h"
|
||||||
#include "minecraft/PackProfile.h"
|
#include "minecraft/PackProfile.h"
|
||||||
@ -254,32 +255,25 @@ void ModPage::openUrl(const QUrl& url)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// detect mod URLs and search instead
|
// 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;
|
const char* page;
|
||||||
|
|
||||||
if ((url.host() == "modrinth.com" || url.host() == "www.modrinth.com") && url.path().startsWith("/mod/")) {
|
if ((match = modrinth.match(address)).hasMatch())
|
||||||
prefixLength = 5;
|
|
||||||
page = "modrinth";
|
page = "modrinth";
|
||||||
} else if (APPLICATION->capabilities() & Application::SupportsFlame &&
|
else if (APPLICATION->capabilities() & Application::SupportsFlame &&
|
||||||
(url.host() == "curseforge.com" || url.host().endsWith(".curseforge.com"))) {
|
((match = curseForge.match(address)).hasMatch() || (match = curseForgeOld.match(address)).hasMatch()))
|
||||||
if (url.path().toLower().startsWith("/minecraft/mc-mods/"))
|
|
||||||
prefixLength = 19;
|
|
||||||
else if (url.path().toLower().startsWith("/projects/"))
|
|
||||||
prefixLength = 10;
|
|
||||||
page = "curseforge";
|
page = "curseforge";
|
||||||
}
|
|
||||||
|
|
||||||
if (prefixLength != 0) {
|
if (match.hasMatch()) {
|
||||||
QString slug = url.path().mid(prefixLength);
|
const QString slug = match.captured(1);
|
||||||
|
|
||||||
// remove trailing slash(es)
|
// ensure the user isn't opening the same mod
|
||||||
while (slug.endsWith('/'))
|
if (slug != current.slug) {
|
||||||
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) {
|
|
||||||
dialog->selectPage(page);
|
dialog->selectPage(page);
|
||||||
|
|
||||||
ModPage* newPage = dialog->getSelectedPage();
|
ModPage* newPage = dialog->getSelectedPage();
|
||||||
@ -290,8 +284,8 @@ void ModPage::openUrl(const QUrl& url)
|
|||||||
|
|
||||||
auto jump = [url, slug, model, view] {
|
auto jump = [url, slug, model, view] {
|
||||||
for (int row = 0; row < model->rowCount({}); row++) {
|
for (int row = 0; row < model->rowCount({}); row++) {
|
||||||
QModelIndex index = model->index(row);
|
const QModelIndex index = model->index(row);
|
||||||
auto pack = model->data(index, Qt::UserRole).value<ModPlatform::IndexedPack>();
|
const auto pack = model->data(index, Qt::UserRole).value<ModPlatform::IndexedPack>();
|
||||||
|
|
||||||
if (pack.slug == slug) {
|
if (pack.slug == slug) {
|
||||||
view->setCurrentIndex(index);
|
view->setCurrentIndex(index);
|
||||||
@ -306,10 +300,10 @@ void ModPage::openUrl(const QUrl& url)
|
|||||||
searchEdit->setText(slug);
|
searchEdit->setText(slug);
|
||||||
newPage->triggerSearch();
|
newPage->triggerSearch();
|
||||||
|
|
||||||
if (!model->activeJob())
|
if (model->activeJob())
|
||||||
jump();
|
|
||||||
else
|
|
||||||
connect(model->activeJob(), &Task::finished, jump);
|
connect(model->activeJob(), &Task::finished, jump);
|
||||||
|
else
|
||||||
|
jump();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
@ -84,6 +84,7 @@ void FlameModPage::openUrl(const QUrl& url)
|
|||||||
{
|
{
|
||||||
if (url.scheme().isEmpty()) {
|
if (url.scheme().isEmpty()) {
|
||||||
QString query = url.query(QUrl::FullyDecoded);
|
QString query = url.query(QUrl::FullyDecoded);
|
||||||
|
|
||||||
if (query.startsWith("remoteUrl=")) {
|
if (query.startsWith("remoteUrl=")) {
|
||||||
// attempt to resolve url from warning page
|
// attempt to resolve url from warning page
|
||||||
query.remove(0, 10);
|
query.remove(0, 10);
|
||||||
@ -93,4 +94,4 @@ void FlameModPage::openUrl(const QUrl& url)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ModPage::openUrl(url);
|
ModPage::openUrl(url);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user