Merge branch 'Fix_Assert' of github.com:Trial97/PrismLauncher into develop
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
commit
1d167f8fda
@ -1,20 +1,20 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* PolyMC - Minecraft Launcher
|
||||||
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@ -104,6 +104,7 @@ struct IndexedPack {
|
|||||||
|
|
||||||
bool versionsLoaded = false;
|
bool versionsLoaded = false;
|
||||||
QVector<IndexedVersion> versions;
|
QVector<IndexedVersion> versions;
|
||||||
|
QVariant loadedFileId; // to check for already downloaded mods
|
||||||
|
|
||||||
// Don't load by default, since some modplatform don't have that info
|
// Don't load by default, since some modplatform don't have that info
|
||||||
bool extraDataLoaded = true;
|
bool extraDataLoaded = true;
|
||||||
@ -119,11 +120,12 @@ struct IndexedPack {
|
|||||||
}
|
}
|
||||||
[[nodiscard]] bool isAnyVersionSelected() const
|
[[nodiscard]] bool isAnyVersionSelected() const
|
||||||
{
|
{
|
||||||
|
if (loadedFileId.isValid())
|
||||||
|
return true;
|
||||||
if (!versionsLoaded)
|
if (!versionsLoaded)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return std::any_of(versions.constBegin(), versions.constEnd(),
|
return std::any_of(versions.constBegin(), versions.constEnd(), [](auto const& v) { return v.is_currently_selected; });
|
||||||
[](auto const& v) { return v.is_currently_selected; });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -196,25 +196,10 @@ void ResourceDownloadDialog::addResource(ModPlatform::IndexedPack& pack, ModPlat
|
|||||||
m_buttons.button(QDialogButtonBox::Ok)->setEnabled(!m_selected.isEmpty());
|
m_buttons.button(QDialogButtonBox::Ok)->setEnabled(!m_selected.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
static ModPlatform::IndexedVersion& getVersionWithID(ModPlatform::IndexedPack& pack, QVariant id)
|
|
||||||
{
|
|
||||||
Q_ASSERT(pack.versionsLoaded);
|
|
||||||
auto it = std::find_if(pack.versions.begin(), pack.versions.end(), [id](auto const& v) { return v.fileId == id; });
|
|
||||||
Q_ASSERT(it != pack.versions.end());
|
|
||||||
return *it;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ResourceDownloadDialog::removeResource(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& ver)
|
void ResourceDownloadDialog::removeResource(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& ver)
|
||||||
{
|
{
|
||||||
if (auto selected_task_it = m_selected.find(pack.name); selected_task_it != m_selected.end()) {
|
dynamic_cast<ResourcePage*>(m_container->getPage(Modrinth::id()))->removeResourceFromPage(pack.name);
|
||||||
auto selected_task = *selected_task_it;
|
dynamic_cast<ResourcePage*>(m_container->getPage(Flame::id()))->removeResourceFromPage(pack.name);
|
||||||
auto old_version_id = selected_task->getVersionID();
|
|
||||||
if (selected_task->getProvider() != pack.provider) // If the pack name matches but they are different providers search for the
|
|
||||||
// old one(in the actual pack) and deselect it.
|
|
||||||
getVersionWithID(selected_task->getPack(), old_version_id).is_currently_selected = false;
|
|
||||||
else if (ver.fileId != old_version_id) // If the new and old version IDs don't match, search for the old one and deselect it.
|
|
||||||
getVersionWithID(pack, old_version_id).is_currently_selected = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deselect the new version too, since all versions of that pack got removed.
|
// Deselect the new version too, since all versions of that pack got removed.
|
||||||
ver.is_currently_selected = false;
|
ver.is_currently_selected = false;
|
||||||
|
@ -6,12 +6,23 @@
|
|||||||
|
|
||||||
#include "minecraft/MinecraftInstance.h"
|
#include "minecraft/MinecraftInstance.h"
|
||||||
#include "minecraft/PackProfile.h"
|
#include "minecraft/PackProfile.h"
|
||||||
|
#include "minecraft/mod/ModFolderModel.h"
|
||||||
|
#include "modplatform/ModIndex.h"
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
namespace ResourceDownload {
|
namespace ResourceDownload {
|
||||||
|
|
||||||
ModModel::ModModel(BaseInstance const& base_inst, ResourceAPI* api) : ResourceModel(api), m_base_instance(base_inst) {}
|
ModModel::ModModel(BaseInstance const& base_inst, ResourceAPI* api) : ResourceModel(api), m_base_instance(base_inst)
|
||||||
|
{
|
||||||
|
auto folder = static_cast<MinecraftInstance const&>(m_base_instance).loaderModList();
|
||||||
|
for (auto mod : folder->allMods()) {
|
||||||
|
auto meta = mod->metadata();
|
||||||
|
ModPlatform::IndexedPack pack{ meta->project_id, meta->provider, meta->name, meta->slug };
|
||||||
|
pack.loadedFileId = meta->file_id;
|
||||||
|
addPack(pack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/******** Make data requests ********/
|
/******** Make data requests ********/
|
||||||
|
|
||||||
|
@ -55,8 +55,7 @@
|
|||||||
|
|
||||||
namespace ResourceDownload {
|
namespace ResourceDownload {
|
||||||
|
|
||||||
ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance& instance)
|
ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance)
|
||||||
: ResourcePage(dialog, instance)
|
|
||||||
{
|
{
|
||||||
connect(m_ui->searchButton, &QPushButton::clicked, this, &ModPage::triggerSearch);
|
connect(m_ui->searchButton, &QPushButton::clicked, this, &ModPage::triggerSearch);
|
||||||
connect(m_ui->resourceFilterButton, &QPushButton::clicked, this, &ModPage::filterMods);
|
connect(m_ui->resourceFilterButton, &QPushButton::clicked, this, &ModPage::filterMods);
|
||||||
@ -75,12 +74,10 @@ void ModPage::setFilterWidget(unique_qobject_ptr<ModFilterWidget>& widget)
|
|||||||
m_filter_widget->setInstance(&static_cast<MinecraftInstance&>(m_base_instance));
|
m_filter_widget->setInstance(&static_cast<MinecraftInstance&>(m_base_instance));
|
||||||
m_filter = m_filter_widget->getFilter();
|
m_filter = m_filter_widget->getFilter();
|
||||||
|
|
||||||
connect(m_filter_widget.get(), &ModFilterWidget::filterChanged, this, [&]{
|
connect(m_filter_widget.get(), &ModFilterWidget::filterChanged, this,
|
||||||
m_ui->searchButton->setStyleSheet("text-decoration: underline");
|
[&] { m_ui->searchButton->setStyleSheet("text-decoration: underline"); });
|
||||||
});
|
connect(m_filter_widget.get(), &ModFilterWidget::filterUnchanged, this,
|
||||||
connect(m_filter_widget.get(), &ModFilterWidget::filterUnchanged, this, [&]{
|
[&] { m_ui->searchButton->setStyleSheet("text-decoration: none"); });
|
||||||
m_ui->searchButton->setStyleSheet("text-decoration: none");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******** Callbacks to events in the UI (set up in the derived classes) ********/
|
/******** Callbacks to events in the UI (set up in the derived classes) ********/
|
||||||
@ -128,8 +125,8 @@ void ModPage::updateVersionList()
|
|||||||
for (int i = 0; i < current_pack.versions.size(); i++) {
|
for (int i = 0; i < current_pack.versions.size(); i++) {
|
||||||
auto version = current_pack.versions[i];
|
auto version = current_pack.versions[i];
|
||||||
bool valid = false;
|
bool valid = false;
|
||||||
for(auto& mcVer : m_filter->versions){
|
for (auto& mcVer : m_filter->versions) {
|
||||||
//NOTE: Flame doesn't care about loader, so passing it changes nothing.
|
// NOTE: Flame doesn't care about loader, so passing it changes nothing.
|
||||||
if (validateVersion(version, mcVer.toString(), packProfile->getModLoaders())) {
|
if (validateVersion(version, mcVer.toString(), packProfile->getModLoaders())) {
|
||||||
valid = true;
|
valid = true;
|
||||||
break;
|
break;
|
||||||
@ -151,6 +148,7 @@ void ModPage::updateVersionList()
|
|||||||
void ModPage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
|
void ModPage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
|
||||||
{
|
{
|
||||||
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
||||||
|
m_model->addPack(pack);
|
||||||
m_parent_dialog->addResource(pack, version, is_indexed);
|
m_parent_dialog->addResource(pack, version, is_indexed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,9 +6,11 @@
|
|||||||
|
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QList>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "BuildConfig.h"
|
#include "BuildConfig.h"
|
||||||
@ -335,6 +337,14 @@ void ResourceModel::searchRequestSucceeded(QJsonDocument& doc)
|
|||||||
ModPlatform::IndexedPack pack;
|
ModPlatform::IndexedPack pack;
|
||||||
try {
|
try {
|
||||||
loadIndexedPack(pack, packObj);
|
loadIndexedPack(pack, packObj);
|
||||||
|
if (auto sel =
|
||||||
|
std::find_if(m_selected.begin(), m_selected.end(),
|
||||||
|
[&pack](ModPlatform::IndexedPack& i) { return i.provider == pack.provider && i.addonId == pack.addonId; });
|
||||||
|
sel != m_selected.end()) {
|
||||||
|
pack.versionsLoaded = sel->versionsLoaded;
|
||||||
|
pack.versions = sel->versions;
|
||||||
|
pack.loadedFileId = sel->loadedFileId;
|
||||||
|
}
|
||||||
newList.append(pack);
|
newList.append(pack);
|
||||||
} catch (const JSONValidationError& e) {
|
} catch (const JSONValidationError& e) {
|
||||||
qWarning() << "Error while loading resource from " << debugName() << ": " << e.cause();
|
qWarning() << "Error while loading resource from " << debugName() << ": " << e.cause();
|
||||||
@ -398,6 +408,11 @@ void ResourceModel::versionRequestSucceeded(QJsonDocument& doc, ModPlatform::Ind
|
|||||||
try {
|
try {
|
||||||
auto arr = doc.isObject() ? Json::ensureArray(doc.object(), "data") : doc.array();
|
auto arr = doc.isObject() ? Json::ensureArray(doc.object(), "data") : doc.array();
|
||||||
loadIndexedPackVersions(current_pack, arr);
|
loadIndexedPackVersions(current_pack, arr);
|
||||||
|
if (current_pack.loadedFileId.isValid())
|
||||||
|
if (auto ver = std::find_if(current_pack.versions.begin(), current_pack.versions.end(),
|
||||||
|
[¤t_pack](ModPlatform::IndexedVersion v) { return v.fileId == current_pack.loadedFileId; });
|
||||||
|
ver != current_pack.versions.end())
|
||||||
|
ver->is_currently_selected = true;
|
||||||
} catch (const JSONValidationError& e) {
|
} catch (const JSONValidationError& e) {
|
||||||
qDebug() << doc;
|
qDebug() << doc;
|
||||||
qWarning() << "Error while reading " << debugName() << " resource version: " << e.cause();
|
qWarning() << "Error while reading " << debugName() << " resource version: " << e.cause();
|
||||||
@ -441,4 +456,51 @@ void ResourceModel::infoRequestSucceeded(QJsonDocument& doc, ModPlatform::Indexe
|
|||||||
emit projectInfoUpdated();
|
emit projectInfoUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourceModel::removePack(QString& rem)
|
||||||
|
{
|
||||||
|
auto pred = [&rem](ModPlatform::IndexedPack i) { return rem == i.name; };
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 1, 0)
|
||||||
|
m_selected.removeIf(pred);
|
||||||
|
#else
|
||||||
|
{ // well partial implementation of remove_if in case the QT Version is not high enough
|
||||||
|
const auto cbegin = m_selected.cbegin();
|
||||||
|
const auto cend = m_selected.cend();
|
||||||
|
const auto t_it = std::find_if(cbegin, cend, pred);
|
||||||
|
auto result = std::distance(cbegin, t_it);
|
||||||
|
if (result != m_selected.size()) {
|
||||||
|
// now detach:
|
||||||
|
const auto e = m_selected.end();
|
||||||
|
|
||||||
|
auto it = std::next(m_selected.begin(), result);
|
||||||
|
auto dest = it;
|
||||||
|
|
||||||
|
// Loop Invariants:
|
||||||
|
// - it != e
|
||||||
|
// - [next(it), e[ still to be checked
|
||||||
|
// - [c.begin(), dest[ are result
|
||||||
|
while (++it != e) {
|
||||||
|
if (!pred(*it)) {
|
||||||
|
*dest = std::move(*it);
|
||||||
|
++dest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result = std::distance(dest, e);
|
||||||
|
m_selected.erase(dest, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// m_selected.removeAt(qsizetype i)
|
||||||
|
auto pack = std::find_if(m_packs.begin(), m_packs.end(), [&rem](ModPlatform::IndexedPack i) { return rem == i.name; });
|
||||||
|
if (pack == m_packs.end()) { // ignore it if is not in the current search
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!pack->versionsLoaded) {
|
||||||
|
pack->loadedFileId = {};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (auto& ver : pack->versions)
|
||||||
|
ver.is_currently_selected = false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ResourceDownload
|
} // namespace ResourceDownload
|
||||||
|
@ -80,6 +80,9 @@ class ResourceModel : public QAbstractListModel {
|
|||||||
/** Gets the icon at the URL for the given index. If it's not fetched yet, fetch it and update when fisinhed. */
|
/** Gets the icon at the URL for the given index. If it's not fetched yet, fetch it and update when fisinhed. */
|
||||||
std::optional<QIcon> getIcon(QModelIndex&, const QUrl&);
|
std::optional<QIcon> getIcon(QModelIndex&, const QUrl&);
|
||||||
|
|
||||||
|
void addPack(ModPlatform::IndexedPack& add) { m_selected.append(add); }
|
||||||
|
void removePack(QString& rem);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** Resets the model's data. */
|
/** Resets the model's data. */
|
||||||
void clearData();
|
void clearData();
|
||||||
@ -124,6 +127,7 @@ class ResourceModel : public QAbstractListModel {
|
|||||||
QSet<QUrl> m_failed_icon_actions;
|
QSet<QUrl> m_failed_icon_actions;
|
||||||
|
|
||||||
QList<ModPlatform::IndexedPack> m_packs;
|
QList<ModPlatform::IndexedPack> m_packs;
|
||||||
|
QList<ModPlatform::IndexedPack> m_selected;
|
||||||
|
|
||||||
// HACK: We need this to prevent callbacks from calling the model after it has already been deleted.
|
// HACK: We need this to prevent callbacks from calling the model after it has already been deleted.
|
||||||
// This leaks a tiny bit of memory per time the user has opened a resource dialog. How to make this better?
|
// This leaks a tiny bit of memory per time the user has opened a resource dialog. How to make this better?
|
||||||
|
@ -308,6 +308,7 @@ void ResourcePage::onVersionSelectionChanged(QString data)
|
|||||||
|
|
||||||
void ResourcePage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
|
void ResourcePage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
|
||||||
{
|
{
|
||||||
|
m_model->addPack(pack);
|
||||||
m_parent_dialog->addResource(pack, version);
|
m_parent_dialog->addResource(pack, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,6 +317,11 @@ void ResourcePage::removeResourceFromDialog(ModPlatform::IndexedPack& pack, ModP
|
|||||||
m_parent_dialog->removeResource(pack, version);
|
m_parent_dialog->removeResource(pack, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourcePage::removeResourceFromPage(QString& name)
|
||||||
|
{
|
||||||
|
m_model->removePack(name);
|
||||||
|
}
|
||||||
|
|
||||||
void ResourcePage::onResourceSelected()
|
void ResourcePage::onResourceSelected()
|
||||||
{
|
{
|
||||||
if (m_selected_version_index < 0)
|
if (m_selected_version_index < 0)
|
||||||
|
@ -74,6 +74,7 @@ class ResourcePage : public QWidget, public BasePage {
|
|||||||
|
|
||||||
virtual void addResourceToDialog(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&);
|
virtual void addResourceToDialog(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&);
|
||||||
virtual void removeResourceFromDialog(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&);
|
virtual void removeResourceFromDialog(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&);
|
||||||
|
virtual void removeResourceFromPage(QString& name);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void triggerSearch() {}
|
virtual void triggerSearch() {}
|
||||||
|
@ -13,8 +13,7 @@
|
|||||||
|
|
||||||
namespace ResourceDownload {
|
namespace ResourceDownload {
|
||||||
|
|
||||||
ShaderPackResourcePage::ShaderPackResourcePage(ShaderPackDownloadDialog* dialog, BaseInstance& instance)
|
ShaderPackResourcePage::ShaderPackResourcePage(ShaderPackDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance)
|
||||||
: ResourcePage(dialog, instance)
|
|
||||||
{
|
{
|
||||||
connect(m_ui->searchButton, &QPushButton::clicked, this, &ShaderPackResourcePage::triggerSearch);
|
connect(m_ui->searchButton, &QPushButton::clicked, this, &ShaderPackResourcePage::triggerSearch);
|
||||||
connect(m_ui->packView, &QListView::doubleClicked, this, &ShaderPackResourcePage::onResourceSelected);
|
connect(m_ui->packView, &QListView::doubleClicked, this, &ShaderPackResourcePage::onResourceSelected);
|
||||||
@ -38,7 +37,8 @@ QMap<QString, QString> ShaderPackResourcePage::urlHandlers() const
|
|||||||
{
|
{
|
||||||
QMap<QString, QString> map;
|
QMap<QString, QString> map;
|
||||||
map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?modrinth\\.com\\/shaders\\/([^\\/]+)\\/?"), "modrinth");
|
map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?modrinth\\.com\\/shaders\\/([^\\/]+)\\/?"), "modrinth");
|
||||||
map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?curseforge\\.com\\/minecraft\\/customization\\/([^\\/]+)\\/?"), "curseforge");
|
map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?curseforge\\.com\\/minecraft\\/customization\\/([^\\/]+)\\/?"),
|
||||||
|
"curseforge");
|
||||||
map.insert(QRegularExpression::anchoredPattern("minecraft\\.curseforge\\.com\\/projects\\/([^\\/]+)\\/?"), "curseforge");
|
map.insert(QRegularExpression::anchoredPattern("minecraft\\.curseforge\\.com\\/projects\\/([^\\/]+)\\/?"), "curseforge");
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ void ShaderPackResourcePage::addResourceToDialog(ModPlatform::IndexedPack& pack,
|
|||||||
{
|
{
|
||||||
if (version.loaders.contains(QStringLiteral("canvas")))
|
if (version.loaders.contains(QStringLiteral("canvas")))
|
||||||
version.custom_target_folder = QStringLiteral("resourcepacks");
|
version.custom_target_folder = QStringLiteral("resourcepacks");
|
||||||
|
m_model->addPack(pack);
|
||||||
m_parent_dialog->addResource(pack, version);
|
m_parent_dialog->addResource(pack, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user