PrismLauncher/launcher/modplatform/modrinth/ModrinthUrl.cpp
unnameduser5000 92315147d6 Add support for modrinth://modpack links
Assisted-by: OpenAI gpt-5
Signed-off-by: unnameduser5000 <daiwentao167@gmail.com>
2026-05-10 22:25:31 +08:00

45 lines
1.3 KiB
C++

// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ModrinthUrl.h"
namespace Modrinth {
auto parseModpackLink(const QUrl& url) -> std::optional<ParsedModpackLink>
{
if (url.scheme().compare("modrinth", Qt::CaseInsensitive) != 0) {
return std::nullopt;
}
if (url.host().compare("modpack", Qt::CaseInsensitive) != 0) {
return std::nullopt;
}
const auto segments = QUrl::fromPercentEncoding(url.path().toUtf8()).split('/', Qt::SkipEmptyParts);
if (segments.size() != 1) {
return std::nullopt;
}
const auto slug = segments.constFirst().trimmed();
if (slug.isEmpty()) {
return std::nullopt;
}
return ParsedModpackLink{ slug };
}
} // namespace Modrinth