Merge pull request #1563 from Trial97/modrinth_pack

Pack import fixes and improvements
This commit is contained in:
Tayou 2023-10-13 16:38:37 +02:00 committed by GitHub
commit 7015b8f7b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 293 additions and 41 deletions

View File

@ -906,6 +906,9 @@ SET(LAUNCHER_SOURCES
ui/pages/modplatform/ImportPage.cpp ui/pages/modplatform/ImportPage.cpp
ui/pages/modplatform/ImportPage.h ui/pages/modplatform/ImportPage.h
ui/pages/modplatform/OptionalModDialog.cpp
ui/pages/modplatform/OptionalModDialog.h
ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp
ui/pages/modplatform/modrinth/ModrinthResourceModels.h ui/pages/modplatform/modrinth/ModrinthResourceModels.h
ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp
@ -1068,6 +1071,7 @@ qt_wrap_ui(LAUNCHER_UI
ui/pages/modplatform/legacy_ftb/Page.ui ui/pages/modplatform/legacy_ftb/Page.ui
ui/pages/modplatform/import_ftb/ImportFTBPage.ui ui/pages/modplatform/import_ftb/ImportFTBPage.ui
ui/pages/modplatform/ImportPage.ui ui/pages/modplatform/ImportPage.ui
ui/pages/modplatform/OptionalModDialog.ui
ui/pages/modplatform/modrinth/ModrinthPage.ui ui/pages/modplatform/modrinth/ModrinthPage.ui
ui/pages/modplatform/technic/TechnicPage.ui ui/pages/modplatform/technic/TechnicPage.ui
ui/widgets/InstanceCardWidget.ui ui/widgets/InstanceCardWidget.ui

View File

@ -43,5 +43,5 @@ void ATLauncher::loadIndexedPack(ATLauncher::IndexedPack& m, QJsonObject& obj)
m.system = Json::ensureBoolean(obj, QString("system"), false); m.system = Json::ensureBoolean(obj, QString("system"), false);
m.description = Json::ensureString(obj, "description", ""); m.description = Json::ensureString(obj, "description", "");
m.safeName = Json::requireString(obj, "name").replace(QRegularExpression("[^A-Za-z0-9]"), ""); m.safeName = Json::requireString(obj, "name").replace(QRegularExpression("[^A-Za-z0-9]"), "").toLower() + ".png";
} }

View File

@ -62,6 +62,7 @@
#include "minecraft/World.h" #include "minecraft/World.h"
#include "minecraft/mod/tasks/LocalResourceParse.h" #include "minecraft/mod/tasks/LocalResourceParse.h"
#include "net/ApiDownload.h" #include "net/ApiDownload.h"
#include "ui/pages/modplatform/OptionalModDialog.h"
static const FlameAPI api; static const FlameAPI api;
@ -509,13 +510,33 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
void FlameCreationTask::setupDownloadJob(QEventLoop& loop) void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
{ {
m_files_job.reset(new NetJob(tr("Mod Download Flame"), APPLICATION->network())); m_files_job.reset(new NetJob(tr("Mod Download Flame"), APPLICATION->network()));
for (const auto& result : m_mod_id_resolver->getResults().files) { auto results = m_mod_id_resolver->getResults().files;
QString filename = result.fileName;
QStringList optionalFiles;
for (auto& result : results) {
if (!result.required) { if (!result.required) {
filename += ".disabled"; optionalFiles << FS::PathCombine(result.targetFolder, result.fileName);
}
} }
auto relpath = FS::PathCombine("minecraft", result.targetFolder, filename); QStringList selectedOptionalMods;
if (!optionalFiles.empty()) {
OptionalModDialog optionalModDialog(m_parent, optionalFiles);
if (optionalModDialog.exec() == QDialog::Rejected) {
emitAborted();
loop.quit();
return;
}
selectedOptionalMods = optionalModDialog.getResult();
}
for (const auto& result : results) {
auto relpath = FS::PathCombine(result.targetFolder, result.fileName);
if (!result.required && !selectedOptionalMods.contains(relpath)) {
relpath += ".disabled";
}
relpath = FS::PathCombine("minecraft", relpath);
auto path = FS::PathCombine(m_stagingPath, relpath); auto path = FS::PathCombine(m_stagingPath, relpath);
switch (result.type) { switch (result.type) {

View File

@ -1,4 +1,6 @@
#include "FlamePackIndex.h" #include "FlamePackIndex.h"
#include <QFileInfo>
#include <QUrl>
#include "Json.h" #include "Json.h"
@ -9,8 +11,8 @@ void Flame::loadIndexedPack(Flame::IndexedPack& pack, QJsonObject& obj)
pack.description = Json::ensureString(obj, "summary", ""); pack.description = Json::ensureString(obj, "summary", "");
auto logo = Json::requireObject(obj, "logo"); auto logo = Json::requireObject(obj, "logo");
pack.logoName = Json::requireString(logo, "title");
pack.logoUrl = Json::requireString(logo, "thumbnailUrl"); pack.logoUrl = Json::requireString(logo, "thumbnailUrl");
pack.logoName = Json::requireString(obj, "slug") + "." + QFileInfo(QUrl(pack.logoUrl).fileName()).suffix();
auto authors = Json::requireArray(obj, "authors"); auto authors = Json::requireArray(obj, "authors");
for (auto authorIter : authors) { for (auto authorIter : authors) {

View File

@ -48,7 +48,7 @@ struct File {
int projectId = 0; int projectId = 0;
int fileId = 0; int fileId = 0;
// NOTE: the opposite to 'optional'. This is at the time of writing unused. // NOTE: the opposite to 'optional'
bool required = true; bool required = true;
QString hash; QString hash;
// NOTE: only set on blocked files ! Empty otherwise. // NOTE: only set on blocked files ! Empty otherwise.

View File

@ -9,6 +9,7 @@
#include "modplatform/helpers/OverrideUtils.h" #include "modplatform/helpers/OverrideUtils.h"
#include "modplatform/modrinth/ModrinthPackManifest.h"
#include "net/ChecksumValidator.h" #include "net/ChecksumValidator.h"
#include "net/ApiDownload.h" #include "net/ApiDownload.h"
@ -16,8 +17,10 @@
#include "settings/INISettingsObject.h" #include "settings/INISettingsObject.h"
#include "ui/dialogs/CustomMessageBox.h" #include "ui/dialogs/CustomMessageBox.h"
#include "ui/pages/modplatform/OptionalModDialog.h"
#include <QAbstractButton> #include <QAbstractButton>
#include <vector>
bool ModrinthCreationTask::abort() bool ModrinthCreationTask::abort()
{ {
@ -319,10 +322,10 @@ bool ModrinthCreationTask::parseManifest(const QString& index_path,
} }
auto jsonFiles = Json::requireIsArrayOf<QJsonObject>(obj, "files", "modrinth.index.json"); auto jsonFiles = Json::requireIsArrayOf<QJsonObject>(obj, "files", "modrinth.index.json");
bool had_optional = false; std::vector<Modrinth::File> optionalFiles;
for (const auto& modInfo : jsonFiles) { for (const auto& modInfo : jsonFiles) {
Modrinth::File file; Modrinth::File file;
file.path = Json::requireString(modInfo, "path"); file.path = Json::requireString(modInfo, "path").replace("\\", "/");
auto env = Json::ensureObject(modInfo, "env"); auto env = Json::ensureObject(modInfo, "env");
// 'env' field is optional // 'env' field is optional
@ -331,18 +334,7 @@ bool ModrinthCreationTask::parseManifest(const QString& index_path,
if (support == "unsupported") { if (support == "unsupported") {
continue; continue;
} else if (support == "optional") { } else if (support == "optional") {
// TODO: Make a review dialog for choosing which ones the user wants! file.required = false;
if (!had_optional && show_optional_dialog) {
had_optional = true;
auto info = CustomMessageBox::selectable(
m_parent, tr("Optional mod detected!"),
tr("One or more mods from this modpack are optional. They will be downloaded, but disabled by default!"),
QMessageBox::Information);
info->exec();
}
if (file.path.endsWith(".jar"))
file.path += ".disabled";
} }
} }
@ -385,9 +377,29 @@ bool ModrinthCreationTask::parseManifest(const QString& index_path,
} }
} }
files.push_back(file); (file.required ? files : optionalFiles).push_back(file);
} }
if (!optionalFiles.empty()) {
QStringList oFiles;
for (auto file : optionalFiles)
oFiles.push_back(file.path);
OptionalModDialog optionalModDialog(m_parent, oFiles);
if (optionalModDialog.exec() == QDialog::Rejected) {
emitAborted();
return false;
}
auto selectedMods = optionalModDialog.getResult();
for (auto file : optionalFiles) {
if (selectedMods.contains(file.path)) {
file.required = true;
} else {
file.path += ".disabled";
}
files.push_back(file);
}
}
if (set_internal_data) { if (set_internal_data) {
auto dependencies = Json::requireObject(obj, "dependencies", "modrinth.index.json"); auto dependencies = Json::requireObject(obj, "dependencies", "modrinth.index.json");
for (auto it = dependencies.begin(), end = dependencies.end(); it != end; ++it) { for (auto it = dependencies.begin(), end = dependencies.end(); it != end; ++it) {

View File

@ -35,6 +35,7 @@
*/ */
#include "ModrinthPackManifest.h" #include "ModrinthPackManifest.h"
#include <QFileInfo>
#include "Json.h" #include "Json.h"
#include "modplatform/modrinth/ModrinthAPI.h" #include "modplatform/modrinth/ModrinthAPI.h"
@ -56,8 +57,8 @@ void loadIndexedPack(Modpack& pack, QJsonObject& obj)
pack.description = Json::ensureString(obj, "description"); pack.description = Json::ensureString(obj, "description");
auto temp_author_name = Json::ensureString(obj, "author"); auto temp_author_name = Json::ensureString(obj, "author");
pack.author = std::make_tuple(temp_author_name, api.getAuthorURL(temp_author_name)); pack.author = std::make_tuple(temp_author_name, api.getAuthorURL(temp_author_name));
pack.iconName = QString("modrinth_%1").arg(Json::ensureString(obj, "slug"));
pack.iconUrl = Json::ensureString(obj, "icon_url"); pack.iconUrl = Json::ensureString(obj, "icon_url");
pack.iconName = QString("modrinth_%1.%2").arg(Json::ensureString(obj, "slug"), QFileInfo(pack.iconUrl.fileName()).suffix());
} }
void loadIndexedInfo(Modpack& pack, QJsonObject& obj) void loadIndexedInfo(Modpack& pack, QJsonObject& obj)

View File

@ -57,6 +57,7 @@ struct File {
QCryptographicHash::Algorithm hashAlgorithm; QCryptographicHash::Algorithm hashAlgorithm;
QByteArray hash; QByteArray hash;
QQueue<QUrl> downloads; QQueue<QUrl> downloads;
bool required = true;
}; };
struct DonationData { struct DonationData {

View File

@ -237,8 +237,7 @@ void NewInstanceDialog::setSuggestedIcon(const QString& key)
InstanceTask* NewInstanceDialog::extractTask() InstanceTask* NewInstanceDialog::extractTask()
{ {
InstanceTask* extracted = creationTask.get(); InstanceTask* extracted = creationTask.release();
creationTask.release();
InstanceName inst_name(ui->instNameTextBox->placeholderText().trimmed(), importVersion); InstanceName inst_name(ui->instNameTextBox->placeholderText().trimmed(), importVersion);
inst_name.setName(ui->instNameTextBox->text().trimmed()); inst_name.setName(ui->instNameTextBox->text().trimmed());

View File

@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
*
* 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 "OptionalModDialog.h"
#include "ui_OptionalModDialog.h"
OptionalModDialog::OptionalModDialog(QWidget* parent, const QStringList& mods) : QDialog(parent), ui(new Ui::OptionalModDialog)
{
ui->setupUi(this);
for (const QString& mod : mods) {
auto item = new QListWidgetItem(mod, ui->list);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(Qt::Unchecked);
item->setData(Qt::UserRole, mod);
}
connect(ui->selectAllButton, &QPushButton::clicked, ui->list, [this] {
for (int i = 0; i < ui->list->count(); i++)
ui->list->item(i)->setCheckState(Qt::Checked);
});
connect(ui->clearAllButton, &QPushButton::clicked, ui->list, [this] {
for (int i = 0; i < ui->list->count(); i++)
ui->list->item(i)->setCheckState(Qt::Unchecked);
});
connect(ui->list, &QListWidget::itemActivated, [](QListWidgetItem* item) {
if (item->checkState() == Qt::Checked)
item->setCheckState(Qt::Unchecked);
else
item->setCheckState(Qt::Checked);
});
}
OptionalModDialog::~OptionalModDialog()
{
delete ui;
}
QStringList OptionalModDialog::getResult()
{
QStringList result;
result.reserve(ui->list->count());
for (int i = 0; i < ui->list->count(); i++) {
auto item = ui->list->item(i);
if (item->checkState() == Qt::Checked)
result.append(item->data(Qt::UserRole).toString());
}
return result;
}

View File

@ -0,0 +1,39 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
*
* 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/>.
*/
#pragma once
#include <QAbstractListModel>
#include <QDialog>
namespace Ui {
class OptionalModDialog;
}
class OptionalModDialog : public QDialog {
Q_OBJECT
public:
OptionalModDialog(QWidget* parent, const QStringList& mods);
~OptionalModDialog() override;
QStringList getResult();
private:
Ui::OptionalModDialog* ui;
};

View File

@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OptionalModDialog</class>
<widget class="QDialog" name="OptionalModDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>550</width>
<height>310</height>
</rect>
</property>
<property name="windowTitle">
<string>Select Optional Mods</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="list">
<property name="defaultDropAction">
<enum>Qt::IgnoreAction</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="selectAllButton">
<property name="text">
<string>Select All</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearAllButton">
<property name="text">
<string>Deselect All</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Unchecked mods will be disabled.</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>OptionalModDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>274</x>
<y>284</y>
</hint>
<hint type="destinationlabel">
<x>274</x>
<y>154</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>OptionalModDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>274</x>
<y>284</y>
</hint>
<hint type="destinationlabel">
<x>274</x>
<y>154</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -63,7 +63,7 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
} }
auto icon = APPLICATION->getThemedIcon("atlauncher-placeholder"); auto icon = APPLICATION->getThemedIcon("atlauncher-placeholder");
auto url = QString(BuildConfig.ATL_DOWNLOAD_SERVER_URL + "launcher/images/%1.png").arg(pack.safeName.toLower()); auto url = QString(BuildConfig.ATL_DOWNLOAD_SERVER_URL + "launcher/images/%1").arg(pack.safeName);
((ListModel*)this)->requestLogo(pack.safeName, url); ((ListModel*)this)->requestLogo(pack.safeName, url);
return icon; return icon;

View File

@ -38,7 +38,7 @@
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QDialog> #include <QDialog>
#include "modplatform/atlauncher/ATLPackIndex.h" #include "modplatform/atlauncher/ATLPackManifest.h"
#include "net/NetJob.h" #include "net/NetJob.h"
namespace Ui { namespace Ui {

View File

@ -114,8 +114,8 @@ void AtlPage::suggestCurrent()
auto uiSupport = new AtlUserInteractionSupportImpl(this); auto uiSupport = new AtlUserInteractionSupportImpl(this);
dialog->setSuggestedPack(selected.name, selectedVersion, new ATLauncher::PackInstallTask(uiSupport, selected.name, selectedVersion)); dialog->setSuggestedPack(selected.name, selectedVersion, new ATLauncher::PackInstallTask(uiSupport, selected.name, selectedVersion));
auto editedLogoName = selected.safeName; auto editedLogoName = "atl_" + selected.safeName;
auto url = QString(BuildConfig.ATL_DOWNLOAD_SERVER_URL + "launcher/images/%1.png").arg(selected.safeName.toLower()); auto url = QString(BuildConfig.ATL_DOWNLOAD_SERVER_URL + "launcher/images/%1").arg(selected.safeName);
listModel->getLogo(selected.safeName, url, listModel->getLogo(selected.safeName, url,
[this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); }); [this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); });
} }

View File

@ -228,8 +228,7 @@ void FlamePage::suggestCurrent()
extra_info.insert("pack_version_id", QString::number(version.fileId)); extra_info.insert("pack_version_id", QString::number(version.fileId));
dialog->setSuggestedPack(current.name, new InstanceImportTask(version.downloadUrl, this, std::move(extra_info))); dialog->setSuggestedPack(current.name, new InstanceImportTask(version.downloadUrl, this, std::move(extra_info)));
QString editedLogoName; QString editedLogoName = "curseforge_" + current.logoName;
editedLogoName = "curseforge_" + current.logoName;
listModel->getLogo(current.logoName, current.logoUrl, listModel->getLogo(current.logoName, current.logoUrl,
[this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); }); [this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); });
} }

View File

@ -90,7 +90,7 @@ void ImportFTBPage::suggestCurrent()
} }
dialog->setSuggestedPack(selected.name, new PackInstallTask(selected)); dialog->setSuggestedPack(selected.name, new PackInstallTask(selected));
QString editedLogoName = QString("ftb_%1").arg(selected.id); QString editedLogoName = QString("ftb_%1_%2,jpg").arg(selected.name, selected.id);
dialog->setSuggestedIconFromFile(FS::PathCombine(selected.path, "folder.jpg"), editedLogoName); dialog->setSuggestedIconFromFile(FS::PathCombine(selected.path, "folder.jpg"), editedLogoName);
} }

View File

@ -179,15 +179,11 @@ void Page::suggestCurrent()
} }
dialog->setSuggestedPack(selected.name, selectedVersion, new PackInstallTask(APPLICATION->network(), selected, selectedVersion)); dialog->setSuggestedPack(selected.name, selectedVersion, new PackInstallTask(APPLICATION->network(), selected, selectedVersion));
QString editedLogoName; QString editedLogoName = selected.logo;
if (selected.logo.toLower().startsWith("ftb")) { if (!selected.logo.toLower().startsWith("ftb")) {
editedLogoName = selected.logo; editedLogoName = "ftb_" + editedLogoName;
} else {
editedLogoName = "ftb_" + selected.logo;
} }
editedLogoName = editedLogoName.left(editedLogoName.lastIndexOf(".png"));
if (selected.type == PackType::Public) { if (selected.type == PackType::Public) {
publicListModel->getLogo(selected.logo, publicListModel->getLogo(selected.logo,
[this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); }); [this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); });

View File

@ -41,7 +41,9 @@
#include "net/ApiDownload.h" #include "net/ApiDownload.h"
#include "ui/widgets/ProjectItem.h" #include "ui/widgets/ProjectItem.h"
#include <QFileInfo>
#include <QIcon> #include <QIcon>
#include <QUrl>
Technic::ListModel::ListModel(QObject* parent) : QAbstractListModel(parent) {} Technic::ListModel::ListModel(QObject* parent) : QAbstractListModel(parent) {}
@ -193,7 +195,7 @@ void Technic::ListModel::searchRequestFinished()
pack.logoName = "null"; pack.logoName = "null";
} else { } else {
pack.logoUrl = rawURL; pack.logoUrl = rawURL;
pack.logoName = rawURL.section(QLatin1Char('/'), -1); pack.logoName = pack.slug + "." + QFileInfo(QUrl(rawURL).fileName()).suffix();
} }
pack.broken = false; pack.broken = false;
newList.append(pack); newList.append(pack);
@ -215,7 +217,7 @@ void Technic::ListModel::searchRequestFinished()
auto iconUrl = Json::requireString(iconObj, "url"); auto iconUrl = Json::requireString(iconObj, "url");
pack.logoUrl = iconUrl; pack.logoUrl = iconUrl;
pack.logoName = iconUrl.section(QLatin1Char('/'), -1); pack.logoName = pack.slug + "." + QFileInfo(QUrl(iconUrl).fileName()).suffix();
} else { } else {
pack.logoUrl = "null"; pack.logoUrl = "null";
pack.logoName = "null"; pack.logoName = "null";