Fix crash when selecting same mod from different providers (#1029)
This commit is contained in:
parent
0ece0b5b27
commit
1840505a0f
@ -1,21 +1,21 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2022-2023 flowln <flowlnlnln@gmail.com>
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2022-2023 flowln <flowlnlnln@gmail.com>
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
*
|
||||
* 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 "ResourceDownloadTask.h"
|
||||
|
||||
@ -24,14 +24,15 @@
|
||||
#include "minecraft/mod/ModFolderModel.h"
|
||||
#include "minecraft/mod/ResourceFolderModel.h"
|
||||
|
||||
ResourceDownloadTask::ResourceDownloadTask(ModPlatform::IndexedPack pack,
|
||||
ResourceDownloadTask::ResourceDownloadTask(ModPlatform::IndexedPack::Ptr pack,
|
||||
ModPlatform::IndexedVersion version,
|
||||
const std::shared_ptr<ResourceFolderModel> packs,
|
||||
bool is_indexed)
|
||||
: m_pack(std::move(pack)), m_pack_version(std::move(version)), m_pack_model(packs)
|
||||
bool is_indexed,
|
||||
QString custom_target_folder)
|
||||
: m_pack(std::move(pack)), m_pack_version(std::move(version)), m_pack_model(packs), m_custom_target_folder(custom_target_folder)
|
||||
{
|
||||
if (auto model = dynamic_cast<ModFolderModel*>(m_pack_model.get()); model && is_indexed) {
|
||||
m_update_task.reset(new LocalModUpdateTask(model->indexDir(), m_pack, m_pack_version));
|
||||
m_update_task.reset(new LocalModUpdateTask(model->indexDir(), *m_pack, m_pack_version));
|
||||
connect(m_update_task.get(), &LocalModUpdateTask::hasOldMod, this, &ResourceDownloadTask::hasOldResource);
|
||||
|
||||
addTask(m_update_task);
|
||||
@ -40,13 +41,13 @@ ResourceDownloadTask::ResourceDownloadTask(ModPlatform::IndexedPack pack,
|
||||
m_filesNetJob.reset(new NetJob(tr("Resource download"), APPLICATION->network()));
|
||||
m_filesNetJob->setStatus(tr("Downloading resource:\n%1").arg(m_pack_version.downloadUrl));
|
||||
|
||||
QDir dir { m_pack_model->dir() };
|
||||
QDir dir{ m_pack_model->dir() };
|
||||
{
|
||||
// FIXME: Make this more generic. May require adding additional info to IndexedVersion,
|
||||
// or adquiring a reference to the base instance.
|
||||
if (!m_pack_version.custom_target_folder.isEmpty()) {
|
||||
if (!m_custom_target_folder.isEmpty()) {
|
||||
dir.cdUp();
|
||||
dir.cd(m_pack_version.custom_target_folder);
|
||||
dir.cd(m_custom_target_folder);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,44 +1,51 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2022-2023 flowln <flowlnlnln@gmail.com>
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2022-2023 flowln <flowlnlnln@gmail.com>
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
*
|
||||
* 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 "net/NetJob.h"
|
||||
#include "tasks/SequentialTask.h"
|
||||
|
||||
#include "modplatform/ModIndex.h"
|
||||
#include "minecraft/mod/tasks/LocalModUpdateTask.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
|
||||
class ResourceFolderModel;
|
||||
|
||||
class ResourceDownloadTask : public SequentialTask {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ResourceDownloadTask(ModPlatform::IndexedPack pack, ModPlatform::IndexedVersion version, const std::shared_ptr<ResourceFolderModel> packs, bool is_indexed = true);
|
||||
public:
|
||||
explicit ResourceDownloadTask(ModPlatform::IndexedPack::Ptr pack,
|
||||
ModPlatform::IndexedVersion version,
|
||||
const std::shared_ptr<ResourceFolderModel> packs,
|
||||
bool is_indexed = true,
|
||||
QString custom_target_folder = {});
|
||||
const QString& getFilename() const { return m_pack_version.fileName; }
|
||||
const QString& getCustomPath() const { return m_pack_version.custom_target_folder; }
|
||||
const QString& getCustomPath() const { return m_custom_target_folder; }
|
||||
const QVariant& getVersionID() const { return m_pack_version.fileId; }
|
||||
const QString& getName() const { return m_pack->name; }
|
||||
ModPlatform::IndexedPack::Ptr getPack() { return m_pack; }
|
||||
|
||||
private:
|
||||
ModPlatform::IndexedPack m_pack;
|
||||
private:
|
||||
ModPlatform::IndexedPack::Ptr m_pack;
|
||||
ModPlatform::IndexedVersion m_pack_version;
|
||||
const std::shared_ptr<ResourceFolderModel> m_pack_model;
|
||||
QString m_custom_target_folder;
|
||||
|
||||
NetJob::Ptr m_filesNetJob;
|
||||
LocalModUpdateTask::Ptr m_update_task;
|
||||
@ -47,11 +54,8 @@ private:
|
||||
void downloadFailed(QString reason);
|
||||
void downloadSucceeded();
|
||||
|
||||
std::tuple<QString, QString> to_delete {"", ""};
|
||||
std::tuple<QString, QString> to_delete{ "", "" };
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void hasOldResource(QString name, QString filename);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
@ -1,20 +1,20 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Copyright (c) 2022 flowln <flowlnlnln@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/>.
|
||||
*/
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Copyright (c) 2022 flowln <flowlnlnln@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
|
||||
|
||||
@ -69,7 +69,6 @@ struct IndexedVersion {
|
||||
|
||||
// For internal use, not provided by APIs
|
||||
bool is_currently_selected = false;
|
||||
QString custom_target_folder;
|
||||
};
|
||||
|
||||
struct ExtraPackData {
|
||||
@ -116,12 +115,12 @@ struct IndexedPack {
|
||||
if (!versionsLoaded)
|
||||
return false;
|
||||
|
||||
return std::any_of(versions.constBegin(), versions.constEnd(),
|
||||
[](auto const& v) { return v.is_currently_selected; });
|
||||
return std::any_of(versions.constBegin(), versions.constEnd(), [](auto const& v) { return v.is_currently_selected; });
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ModPlatform
|
||||
|
||||
Q_DECLARE_METATYPE(ModPlatform::IndexedPack)
|
||||
Q_DECLARE_METATYPE(ModPlatform::IndexedPack::Ptr)
|
||||
Q_DECLARE_METATYPE(ModPlatform::ResourceProvider)
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "FlameModIndex.h"
|
||||
|
||||
#include <MurmurHash2.h>
|
||||
#include <memory>
|
||||
|
||||
#include "FileSystem.h"
|
||||
#include "Json.h"
|
||||
@ -129,8 +130,7 @@ void FlameCheckUpdate::executeTask()
|
||||
setStatus(tr("Getting API response from CurseForge for '%1'...").arg(mod->name()));
|
||||
setProgress(i++, m_mods.size());
|
||||
|
||||
ModPlatform::IndexedPack pack{ mod->metadata()->project_id.toString() };
|
||||
auto latest_ver = api.getLatestVersion({ pack, m_game_versions, m_loaders });
|
||||
auto latest_ver = api.getLatestVersion({ { mod->metadata()->project_id.toString() }, m_game_versions, m_loaders });
|
||||
|
||||
// Check if we were aborted while getting the latest version
|
||||
if (m_was_aborted) {
|
||||
@ -156,15 +156,15 @@ void FlameCheckUpdate::executeTask()
|
||||
|
||||
if (!latest_ver.hash.isEmpty() && (mod->metadata()->hash != latest_ver.hash || mod->status() == ModStatus::NotInstalled)) {
|
||||
// Fake pack with the necessary info to pass to the download task :)
|
||||
ModPlatform::IndexedPack pack;
|
||||
pack.name = mod->name();
|
||||
pack.slug = mod->metadata()->slug;
|
||||
pack.addonId = mod->metadata()->project_id;
|
||||
pack.websiteUrl = mod->homeurl();
|
||||
auto pack = std::make_shared<ModPlatform::IndexedPack>();
|
||||
pack->name = mod->name();
|
||||
pack->slug = mod->metadata()->slug;
|
||||
pack->addonId = mod->metadata()->project_id;
|
||||
pack->websiteUrl = mod->homeurl();
|
||||
for (auto& author : mod->authors())
|
||||
pack.authors.append({ author });
|
||||
pack.description = mod->description();
|
||||
pack.provider = ModPlatform::ResourceProvider::FLAME;
|
||||
pack->authors.append({ author });
|
||||
pack->description = mod->description();
|
||||
pack->provider = ModPlatform::ResourceProvider::FLAME;
|
||||
|
||||
auto old_version = mod->version();
|
||||
if (old_version.isEmpty() && mod->status() != ModStatus::NotInstalled) {
|
||||
@ -173,7 +173,7 @@ void FlameCheckUpdate::executeTask()
|
||||
}
|
||||
|
||||
auto download_task = makeShared<ResourceDownloadTask>(pack, latest_ver, m_mods_folder);
|
||||
m_updatable.emplace_back(pack.name, mod->metadata()->hash, old_version, latest_ver.version,
|
||||
m_updatable.emplace_back(pack->name, mod->metadata()->hash, old_version, latest_ver.version,
|
||||
api.getModFileChangelog(latest_ver.addonId.toInt(), latest_ver.fileId.toInt()),
|
||||
ModPlatform::ResourceProvider::FLAME, download_task);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ void ModrinthCheckUpdate::executeTask()
|
||||
if (mod->metadata()->hash_format != best_hash_type) {
|
||||
auto hash_task = Hashing::createModrinthHasher(mod->fileinfo().absoluteFilePath());
|
||||
connect(hash_task.get(), &Task::succeeded, [&] {
|
||||
QString hash (hash_task->getResult());
|
||||
QString hash(hash_task->getResult());
|
||||
hashes.append(hash);
|
||||
mappings.insert(hash, mod);
|
||||
});
|
||||
@ -67,7 +67,7 @@ void ModrinthCheckUpdate::executeTask()
|
||||
}
|
||||
|
||||
QEventLoop loop;
|
||||
connect(&hashing_task, &Task::finished, [&loop]{ loop.quit(); });
|
||||
connect(&hashing_task, &Task::finished, [&loop] { loop.quit(); });
|
||||
hashing_task.start();
|
||||
loop.exec();
|
||||
|
||||
@ -112,7 +112,8 @@ void ModrinthCheckUpdate::executeTask()
|
||||
// so we may want to filter it
|
||||
QString loader_filter;
|
||||
if (m_loaders.has_value()) {
|
||||
static auto flags = { ResourceAPI::ModLoaderType::Forge, ResourceAPI::ModLoaderType::Fabric, ResourceAPI::ModLoaderType::Quilt };
|
||||
static auto flags = { ResourceAPI::ModLoaderType::Forge, ResourceAPI::ModLoaderType::Fabric,
|
||||
ResourceAPI::ModLoaderType::Quilt };
|
||||
for (auto flag : flags) {
|
||||
if (m_loaders.value().testFlag(flag)) {
|
||||
loader_filter = api.getModLoaderString(flag);
|
||||
@ -122,7 +123,8 @@ void ModrinthCheckUpdate::executeTask()
|
||||
}
|
||||
|
||||
// Currently, we rely on a couple heuristics to determine whether an update is actually available or not:
|
||||
// - The file needs to be preferred: It is either the primary file, or the one found via (explicit) usage of the loader_filter
|
||||
// - The file needs to be preferred: It is either the primary file, or the one found via (explicit) usage of the
|
||||
// loader_filter
|
||||
// - The version reported by the JAR is different from the version reported by the indexed version (it's usually the case)
|
||||
// Such is the pain of having arbitrary files for a given version .-.
|
||||
|
||||
@ -149,19 +151,19 @@ void ModrinthCheckUpdate::executeTask()
|
||||
continue;
|
||||
|
||||
// Fake pack with the necessary info to pass to the download task :)
|
||||
ModPlatform::IndexedPack pack;
|
||||
pack.name = mod->name();
|
||||
pack.slug = mod->metadata()->slug;
|
||||
pack.addonId = mod->metadata()->project_id;
|
||||
pack.websiteUrl = mod->homeurl();
|
||||
auto pack = std::make_shared<ModPlatform::IndexedPack>();
|
||||
pack->name = mod->name();
|
||||
pack->slug = mod->metadata()->slug;
|
||||
pack->addonId = mod->metadata()->project_id;
|
||||
pack->websiteUrl = mod->homeurl();
|
||||
for (auto& author : mod->authors())
|
||||
pack.authors.append({ author });
|
||||
pack.description = mod->description();
|
||||
pack.provider = ModPlatform::ResourceProvider::MODRINTH;
|
||||
pack->authors.append({ author });
|
||||
pack->description = mod->description();
|
||||
pack->provider = ModPlatform::ResourceProvider::MODRINTH;
|
||||
|
||||
auto download_task = makeShared<ResourceDownloadTask>(pack, project_ver, m_mods_folder);
|
||||
|
||||
m_updatable.emplace_back(pack.name, hash, mod->version(), project_ver.version_number, project_ver.changelog,
|
||||
m_updatable.emplace_back(pack->name, hash, mod->version(), project_ver.version_number, project_ver.changelog,
|
||||
ModPlatform::ResourceProvider::MODRINTH, download_task);
|
||||
}
|
||||
}
|
||||
|
@ -20,14 +20,15 @@
|
||||
#include "ResourceDownloadDialog.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Application.h"
|
||||
#include "ResourceDownloadTask.h"
|
||||
|
||||
#include "minecraft/mod/ModFolderModel.h"
|
||||
#include "minecraft/mod/ResourcePackFolderModel.h"
|
||||
#include "minecraft/mod/TexturePackFolderModel.h"
|
||||
#include "minecraft/mod/ShaderPackFolderModel.h"
|
||||
#include "minecraft/mod/TexturePackFolderModel.h"
|
||||
|
||||
#include "ui/dialogs/ReviewMessageBox.h"
|
||||
|
||||
@ -41,7 +42,10 @@
|
||||
namespace ResourceDownload {
|
||||
|
||||
ResourceDownloadDialog::ResourceDownloadDialog(QWidget* parent, const std::shared_ptr<ResourceFolderModel> base_model)
|
||||
: QDialog(parent), m_base_model(base_model), m_buttons(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel), m_vertical_layout(this)
|
||||
: QDialog(parent)
|
||||
, m_base_model(base_model)
|
||||
, m_buttons(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel)
|
||||
, m_vertical_layout(this)
|
||||
{
|
||||
setObjectName(QStringLiteral("ResourceDownloadDialog"));
|
||||
|
||||
@ -102,7 +106,8 @@ void ResourceDownloadDialog::initializeContainer()
|
||||
void ResourceDownloadDialog::connectButtons()
|
||||
{
|
||||
auto OkButton = m_buttons.button(QDialogButtonBox::Ok);
|
||||
OkButton->setToolTip(tr("Opens a new popup to review your selected %1 and confirm your selection. Shortcut: Ctrl+Return").arg(resourcesString()));
|
||||
OkButton->setToolTip(
|
||||
tr("Opens a new popup to review your selected %1 and confirm your selection. Shortcut: Ctrl+Return").arg(resourcesString()));
|
||||
connect(OkButton, &QPushButton::clicked, this, &ResourceDownloadDialog::confirm);
|
||||
|
||||
auto CancelButton = m_buttons.button(QDialogButtonBox::Cancel);
|
||||
@ -114,21 +119,24 @@ void ResourceDownloadDialog::connectButtons()
|
||||
|
||||
void ResourceDownloadDialog::confirm()
|
||||
{
|
||||
auto keys = m_selected.keys();
|
||||
keys.sort(Qt::CaseInsensitive);
|
||||
auto selected = getTasks();
|
||||
std::sort(selected.begin(), selected.end(), [](const DownloadTaskPtr& a, const DownloadTaskPtr& b) {
|
||||
return QString::compare(a->getName(), b->getName(), Qt::CaseInsensitive) < 0;
|
||||
});
|
||||
|
||||
auto confirm_dialog = ReviewMessageBox::create(this, tr("Confirm %1 to download").arg(resourcesString()));
|
||||
confirm_dialog->retranslateUi(resourcesString());
|
||||
|
||||
for (auto& task : keys) {
|
||||
auto selected = m_selected.constFind(task).value();
|
||||
confirm_dialog->appendResource({ task, selected->getFilename(), selected->getCustomPath() });
|
||||
for (auto& task : selected) {
|
||||
confirm_dialog->appendResource({ task->getName(), task->getFilename(), task->getCustomPath() });
|
||||
}
|
||||
|
||||
if (confirm_dialog->exec()) {
|
||||
auto deselected = confirm_dialog->deselectedResources();
|
||||
for (auto name : deselected) {
|
||||
m_selected.remove(name);
|
||||
for (auto page : m_container->getPages()) {
|
||||
auto res = static_cast<ResourcePage*>(page);
|
||||
for (auto name : deselected)
|
||||
res->removeResourceFromPage(name);
|
||||
}
|
||||
|
||||
this->accept();
|
||||
@ -145,46 +153,39 @@ ResourcePage* ResourceDownloadDialog::getSelectedPage()
|
||||
return m_selectedPage;
|
||||
}
|
||||
|
||||
void ResourceDownloadDialog::addResource(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& ver, bool is_indexed)
|
||||
void ResourceDownloadDialog::addResource(ModPlatform::IndexedPack::Ptr pack, ModPlatform::IndexedVersion& ver)
|
||||
{
|
||||
removeResource(pack, ver);
|
||||
|
||||
ver.is_currently_selected = true;
|
||||
m_selected.insert(pack.name, makeShared<ResourceDownloadTask>(pack, ver, getBaseModel(), is_indexed));
|
||||
|
||||
m_buttons.button(QDialogButtonBox::Ok)->setEnabled(!m_selected.isEmpty());
|
||||
removeResource(pack->name);
|
||||
m_selectedPage->addResourceToPage(pack, ver, getBaseModel());
|
||||
setButtonStatus();
|
||||
}
|
||||
|
||||
static ModPlatform::IndexedVersion& getVersionWithID(ModPlatform::IndexedPack& pack, QVariant id)
|
||||
void ResourceDownloadDialog::removeResource(const QString& pack_name)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (auto selected_task_it = m_selected.find(pack.name); selected_task_it != m_selected.end()) {
|
||||
auto selected_task = *selected_task_it;
|
||||
auto old_version_id = selected_task->getVersionID();
|
||||
|
||||
// If the new and old version IDs don't match, search for the old one and deselect it.
|
||||
if (ver.fileId != old_version_id)
|
||||
getVersionWithID(pack, old_version_id).is_currently_selected = false;
|
||||
for (auto page : m_container->getPages()) {
|
||||
static_cast<ResourcePage*>(page)->removeResourceFromPage(pack_name);
|
||||
}
|
||||
setButtonStatus();
|
||||
}
|
||||
|
||||
// Deselect the new version too, since all versions of that pack got removed.
|
||||
ver.is_currently_selected = false;
|
||||
|
||||
m_selected.remove(pack.name);
|
||||
|
||||
m_buttons.button(QDialogButtonBox::Ok)->setEnabled(!m_selected.isEmpty());
|
||||
void ResourceDownloadDialog::setButtonStatus()
|
||||
{
|
||||
auto selected = false;
|
||||
for (auto page : m_container->getPages()) {
|
||||
auto res = static_cast<ResourcePage*>(page);
|
||||
selected = selected || res->hasSelectedPacks();
|
||||
}
|
||||
m_buttons.button(QDialogButtonBox::Ok)->setEnabled(selected);
|
||||
}
|
||||
|
||||
const QList<ResourceDownloadDialog::DownloadTaskPtr> ResourceDownloadDialog::getTasks()
|
||||
{
|
||||
return m_selected.values();
|
||||
QList<DownloadTaskPtr> selected;
|
||||
for (auto page : m_container->getPages()) {
|
||||
auto res = static_cast<ResourcePage*>(page);
|
||||
selected.append(res->selectedPacks());
|
||||
}
|
||||
return selected;
|
||||
}
|
||||
|
||||
void ResourceDownloadDialog::selectedPageChanged(BasePage* previous, BasePage* selected)
|
||||
@ -205,8 +206,6 @@ void ResourceDownloadDialog::selectedPageChanged(BasePage* previous, BasePage* s
|
||||
m_selectedPage->setSearchTerm(prev_page->getSearchTerm());
|
||||
}
|
||||
|
||||
|
||||
|
||||
ModDownloadDialog::ModDownloadDialog(QWidget* parent, const std::shared_ptr<ModFolderModel>& mods, BaseInstance* instance)
|
||||
: ResourceDownloadDialog(parent, mods), m_instance(instance)
|
||||
{
|
||||
@ -232,7 +231,6 @@ QList<BasePage*> ModDownloadDialog::getPages()
|
||||
return pages;
|
||||
}
|
||||
|
||||
|
||||
ResourcePackDownloadDialog::ResourcePackDownloadDialog(QWidget* parent,
|
||||
const std::shared_ptr<ResourcePackFolderModel>& resource_packs,
|
||||
BaseInstance* instance)
|
||||
@ -258,7 +256,6 @@ QList<BasePage*> ResourcePackDownloadDialog::getPages()
|
||||
return pages;
|
||||
}
|
||||
|
||||
|
||||
TexturePackDownloadDialog::TexturePackDownloadDialog(QWidget* parent,
|
||||
const std::shared_ptr<TexturePackFolderModel>& resource_packs,
|
||||
BaseInstance* instance)
|
||||
@ -284,7 +281,6 @@ QList<BasePage*> TexturePackDownloadDialog::getPages()
|
||||
return pages;
|
||||
}
|
||||
|
||||
|
||||
ShaderPackDownloadDialog::ShaderPackDownloadDialog(QWidget* parent,
|
||||
const std::shared_ptr<ShaderPackFolderModel>& shaders,
|
||||
BaseInstance* instance)
|
||||
|
@ -62,8 +62,8 @@ class ResourceDownloadDialog : public QDialog, public BasePageProvider {
|
||||
bool selectPage(QString pageId);
|
||||
ResourcePage* getSelectedPage();
|
||||
|
||||
void addResource(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&, bool is_indexed = false);
|
||||
void removeResource(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&);
|
||||
void addResource(ModPlatform::IndexedPack::Ptr, ModPlatform::IndexedVersion&);
|
||||
void removeResource(const QString&);
|
||||
|
||||
const QList<DownloadTaskPtr> getTasks();
|
||||
[[nodiscard]] const std::shared_ptr<ResourceFolderModel> getBaseModel() const { return m_base_model; }
|
||||
@ -79,6 +79,7 @@ class ResourceDownloadDialog : public QDialog, public BasePageProvider {
|
||||
|
||||
protected:
|
||||
[[nodiscard]] virtual QString geometrySaveKey() const { return ""; }
|
||||
void setButtonStatus();
|
||||
|
||||
protected:
|
||||
const std::shared_ptr<ResourceFolderModel> m_base_model;
|
||||
@ -88,12 +89,8 @@ class ResourceDownloadDialog : public QDialog, public BasePageProvider {
|
||||
|
||||
QDialogButtonBox m_buttons;
|
||||
QVBoxLayout m_vertical_layout;
|
||||
|
||||
QHash<QString, DownloadTaskPtr> m_selected;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class ModDownloadDialog final : public ResourceDownloadDialog {
|
||||
Q_OBJECT
|
||||
|
||||
@ -153,9 +150,7 @@ class ShaderPackDownloadDialog final : public ResourceDownloadDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ShaderPackDownloadDialog(QWidget* parent,
|
||||
const std::shared_ptr<ShaderPackFolderModel>& shader_packs,
|
||||
BaseInstance* instance);
|
||||
explicit ShaderPackDownloadDialog(QWidget* parent, const std::shared_ptr<ShaderPackFolderModel>& shader_packs, BaseInstance* instance);
|
||||
~ShaderPackDownloadDialog() override = default;
|
||||
|
||||
//: String that gets appended to the shader pack download dialog title ("Download " + resourcesString())
|
||||
|
@ -55,8 +55,7 @@
|
||||
|
||||
namespace ResourceDownload {
|
||||
|
||||
ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance& instance)
|
||||
: ResourcePage(dialog, instance)
|
||||
ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance)
|
||||
{
|
||||
connect(m_ui->searchButton, &QPushButton::clicked, this, &ModPage::triggerSearch);
|
||||
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 = m_filter_widget->getFilter();
|
||||
|
||||
connect(m_filter_widget.get(), &ModFilterWidget::filterChanged, this, [&]{
|
||||
m_ui->searchButton->setStyleSheet("text-decoration: underline");
|
||||
});
|
||||
connect(m_filter_widget.get(), &ModFilterWidget::filterUnchanged, this, [&]{
|
||||
m_ui->searchButton->setStyleSheet("text-decoration: none");
|
||||
});
|
||||
connect(m_filter_widget.get(), &ModFilterWidget::filterChanged, this,
|
||||
[&] { m_ui->searchButton->setStyleSheet("text-decoration: underline"); });
|
||||
connect(m_filter_widget.get(), &ModFilterWidget::filterUnchanged, this,
|
||||
[&] { m_ui->searchButton->setStyleSheet("text-decoration: none"); });
|
||||
}
|
||||
|
||||
/******** Callbacks to events in the UI (set up in the derived classes) ********/
|
||||
@ -125,11 +122,11 @@ void ModPage::updateVersionList()
|
||||
QString mcVersion = packProfile->getComponentVersion("net.minecraft");
|
||||
|
||||
auto current_pack = getCurrentPack();
|
||||
for (int i = 0; i < current_pack.versions.size(); i++) {
|
||||
auto version = current_pack.versions[i];
|
||||
for (int i = 0; i < current_pack->versions.size(); i++) {
|
||||
auto version = current_pack->versions[i];
|
||||
bool valid = false;
|
||||
for(auto& mcVer : m_filter->versions){
|
||||
//NOTE: Flame doesn't care about loader, so passing it changes nothing.
|
||||
for (auto& mcVer : m_filter->versions) {
|
||||
// NOTE: Flame doesn't care about loader, so passing it changes nothing.
|
||||
if (validateVersion(version, mcVer.toString(), packProfile->getModLoaders())) {
|
||||
valid = true;
|
||||
break;
|
||||
@ -148,10 +145,12 @@ void ModPage::updateVersionList()
|
||||
updateSelectionButton();
|
||||
}
|
||||
|
||||
void ModPage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
|
||||
void ModPage::addResourceToPage(ModPlatform::IndexedPack::Ptr pack,
|
||||
ModPlatform::IndexedVersion& version,
|
||||
const std::shared_ptr<ResourceFolderModel> base_model)
|
||||
{
|
||||
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
||||
m_parent_dialog->addResource(pack, version, is_indexed);
|
||||
m_model->addPack(pack, version, base_model, is_indexed);
|
||||
}
|
||||
|
||||
} // namespace ResourceDownload
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
#include "modplatform/ModIndex.h"
|
||||
|
||||
#include "ui/pages/modplatform/ResourcePage.h"
|
||||
#include "ui/pages/modplatform/ModModel.h"
|
||||
#include "ui/pages/modplatform/ResourcePage.h"
|
||||
#include "ui/widgets/ModFilterWidget.h"
|
||||
|
||||
namespace Ui {
|
||||
@ -25,13 +25,14 @@ class ModPage : public ResourcePage {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
static T* create(ModDownloadDialog* dialog, BaseInstance& instance)
|
||||
{
|
||||
auto page = new T(dialog, instance);
|
||||
auto model = static_cast<ModModel*>(page->getModel());
|
||||
|
||||
auto filter_widget = ModFilterWidget::create(static_cast<MinecraftInstance&>(instance).getPackProfile()->getComponentVersion("net.minecraft"), page);
|
||||
auto filter_widget =
|
||||
ModFilterWidget::create(static_cast<MinecraftInstance&>(instance).getPackProfile()->getComponentVersion("net.minecraft"), page);
|
||||
page->setFilterWidget(filter_widget);
|
||||
model->setFilter(page->getFilter());
|
||||
|
||||
@ -48,9 +49,13 @@ class ModPage : public ResourcePage {
|
||||
|
||||
[[nodiscard]] QMap<QString, QString> urlHandlers() const override;
|
||||
|
||||
void addResourceToDialog(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&) override;
|
||||
void addResourceToPage(ModPlatform::IndexedPack::Ptr,
|
||||
ModPlatform::IndexedVersion&,
|
||||
const std::shared_ptr<ResourceFolderModel>) override;
|
||||
|
||||
virtual auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, std::optional<ResourceAPI::ModLoaderTypes> loaders = {}) const -> bool = 0;
|
||||
virtual auto validateVersion(ModPlatform::IndexedVersion& ver,
|
||||
QString mineVer,
|
||||
std::optional<ResourceAPI::ModLoaderTypes> loaders = {}) const -> bool = 0;
|
||||
|
||||
[[nodiscard]] bool supportsFiltering() const override { return true; };
|
||||
auto getFilter() const -> const std::shared_ptr<ModFilterWidget::Filter> { return m_filter; }
|
||||
|
@ -6,9 +6,11 @@
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QIcon>
|
||||
#include <QList>
|
||||
#include <QMessageBox>
|
||||
#include <QPixmapCache>
|
||||
#include <QUrl>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
#include "Application.h"
|
||||
@ -65,7 +67,7 @@ auto ResourceModel::data(const QModelIndex& index, int role) const -> QVariant
|
||||
return QSize(0, 58);
|
||||
case Qt::UserRole: {
|
||||
QVariant v;
|
||||
v.setValue(*pack);
|
||||
v.setValue(pack);
|
||||
return v;
|
||||
}
|
||||
// Custom data
|
||||
@ -103,7 +105,7 @@ bool ResourceModel::setData(const QModelIndex& index, const QVariant& value, int
|
||||
if (pos >= m_packs.size() || pos < 0 || !index.isValid())
|
||||
return false;
|
||||
|
||||
m_packs[pos] = std::make_shared<ModPlatform::IndexedPack>(value.value<ModPlatform::IndexedPack>());
|
||||
m_packs[pos] = value.value<ModPlatform::IndexedPack::Ptr>();
|
||||
emit dataChanged(index, index);
|
||||
|
||||
return true;
|
||||
@ -336,6 +338,14 @@ void ResourceModel::searchRequestSucceeded(QJsonDocument& doc)
|
||||
ModPlatform::IndexedPack::Ptr pack = std::make_shared<ModPlatform::IndexedPack>();
|
||||
try {
|
||||
loadIndexedPack(*pack, packObj);
|
||||
if (auto sel = std::find_if(m_selected.begin(), m_selected.end(),
|
||||
[&pack](const DownloadTaskPtr i) {
|
||||
const auto ipack = i->getPack();
|
||||
return ipack->provider == pack->provider && ipack->addonId == pack->addonId;
|
||||
});
|
||||
sel != m_selected.end()) {
|
||||
newList.append(sel->get()->getPack());
|
||||
} else
|
||||
newList.append(pack);
|
||||
} catch (const JSONValidationError& e) {
|
||||
qWarning() << "Error while loading resource from " << debugName() << ": " << e.cause();
|
||||
@ -390,15 +400,15 @@ void ResourceModel::searchRequestAborted()
|
||||
|
||||
void ResourceModel::versionRequestSucceeded(QJsonDocument& doc, ModPlatform::IndexedPack& pack, const QModelIndex& index)
|
||||
{
|
||||
auto current_pack = data(index, Qt::UserRole).value<ModPlatform::IndexedPack>();
|
||||
auto current_pack = data(index, Qt::UserRole).value<ModPlatform::IndexedPack::Ptr>();
|
||||
|
||||
// Check if the index is still valid for this resource or not
|
||||
if (pack.addonId != current_pack.addonId)
|
||||
if (pack.addonId != current_pack->addonId)
|
||||
return;
|
||||
|
||||
try {
|
||||
auto arr = doc.isObject() ? Json::ensureArray(doc.object(), "data") : doc.array();
|
||||
loadIndexedPackVersions(current_pack, arr);
|
||||
loadIndexedPackVersions(*current_pack, arr);
|
||||
} catch (const JSONValidationError& e) {
|
||||
qDebug() << doc;
|
||||
qWarning() << "Error while reading " << debugName() << " resource version: " << e.cause();
|
||||
@ -417,15 +427,15 @@ void ResourceModel::versionRequestSucceeded(QJsonDocument& doc, ModPlatform::Ind
|
||||
|
||||
void ResourceModel::infoRequestSucceeded(QJsonDocument& doc, ModPlatform::IndexedPack& pack, const QModelIndex& index)
|
||||
{
|
||||
auto current_pack = data(index, Qt::UserRole).value<ModPlatform::IndexedPack>();
|
||||
auto current_pack = data(index, Qt::UserRole).value<ModPlatform::IndexedPack::Ptr>();
|
||||
|
||||
// Check if the index is still valid for this resource or not
|
||||
if (pack.addonId != current_pack.addonId)
|
||||
if (pack.addonId != current_pack->addonId)
|
||||
return;
|
||||
|
||||
try {
|
||||
auto obj = Json::requireObject(doc);
|
||||
loadExtraPackInfo(current_pack, obj);
|
||||
loadExtraPackInfo(*current_pack, obj);
|
||||
} catch (const JSONValidationError& e) {
|
||||
qDebug() << doc;
|
||||
qWarning() << "Error while reading " << debugName() << " resource info: " << e.cause();
|
||||
@ -442,4 +452,39 @@ void ResourceModel::infoRequestSucceeded(QJsonDocument& doc, ModPlatform::Indexe
|
||||
emit projectInfoUpdated();
|
||||
}
|
||||
|
||||
void ResourceModel::addPack(ModPlatform::IndexedPack::Ptr pack,
|
||||
ModPlatform::IndexedVersion& version,
|
||||
const std::shared_ptr<ResourceFolderModel> packs,
|
||||
bool is_indexed,
|
||||
QString custom_target_folder)
|
||||
{
|
||||
version.is_currently_selected = true;
|
||||
m_selected.append(makeShared<ResourceDownloadTask>(pack, version, packs, is_indexed, custom_target_folder));
|
||||
}
|
||||
|
||||
void ResourceModel::removePack(const QString& rem)
|
||||
{
|
||||
auto pred = [&rem](const DownloadTaskPtr i) { return rem == i->getName(); };
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 1, 0)
|
||||
m_selected.removeIf(pred);
|
||||
#else
|
||||
{
|
||||
for (auto it = m_selected.begin(); it != m_selected.end();)
|
||||
if (pred(*it))
|
||||
it = m_selected.erase(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
#endif
|
||||
auto pack = std::find_if(m_packs.begin(), m_packs.end(), [&rem](const ModPlatform::IndexedPack::Ptr i) { return rem == i->name; });
|
||||
if (pack == m_packs.end()) { // ignore it if is not in the current search
|
||||
return;
|
||||
}
|
||||
if (!pack->get()->versionsLoaded) {
|
||||
return;
|
||||
}
|
||||
for (auto& ver : pack->get()->versions)
|
||||
ver.is_currently_selected = false;
|
||||
}
|
||||
|
||||
} // namespace ResourceDownload
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
|
||||
#include "ResourceDownloadTask.h"
|
||||
#include "modplatform/ResourceAPI.h"
|
||||
|
||||
#include "tasks/ConcurrentTask.h"
|
||||
@ -29,6 +30,8 @@ class ResourceModel : public QAbstractListModel {
|
||||
Q_PROPERTY(QString search_term MEMBER m_search_term WRITE setSearchTerm)
|
||||
|
||||
public:
|
||||
using DownloadTaskPtr = shared_qobject_ptr<ResourceDownloadTask>;
|
||||
|
||||
ResourceModel(ResourceAPI* api);
|
||||
~ResourceModel() override;
|
||||
|
||||
@ -80,6 +83,14 @@ 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. */
|
||||
std::optional<QIcon> getIcon(QModelIndex&, const QUrl&);
|
||||
|
||||
void addPack(ModPlatform::IndexedPack::Ptr pack,
|
||||
ModPlatform::IndexedVersion& version,
|
||||
const std::shared_ptr<ResourceFolderModel> packs,
|
||||
bool is_indexed = false,
|
||||
QString custom_target_folder = {});
|
||||
void removePack(const QString& rem);
|
||||
QList<DownloadTaskPtr> selectedPacks() { return m_selected; }
|
||||
|
||||
protected:
|
||||
/** Resets the model's data. */
|
||||
void clearData();
|
||||
@ -124,6 +135,7 @@ class ResourceModel : public QAbstractListModel {
|
||||
QSet<QUrl> m_failed_icon_actions;
|
||||
|
||||
QList<ModPlatform::IndexedPack::Ptr> m_packs;
|
||||
QList<DownloadTaskPtr> m_selected;
|
||||
|
||||
// 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?
|
||||
|
@ -37,6 +37,7 @@
|
||||
*/
|
||||
|
||||
#include "ResourcePage.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
#include "ui_ResourcePage.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
@ -158,16 +159,16 @@ void ResourcePage::addSortings()
|
||||
m_ui->sortByBox->addItem(sorting.readable_name, QVariant(sorting.index));
|
||||
}
|
||||
|
||||
bool ResourcePage::setCurrentPack(ModPlatform::IndexedPack pack)
|
||||
bool ResourcePage::setCurrentPack(ModPlatform::IndexedPack::Ptr pack)
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(pack);
|
||||
return m_model->setData(m_ui->packView->currentIndex(), v, Qt::UserRole);
|
||||
}
|
||||
|
||||
ModPlatform::IndexedPack ResourcePage::getCurrentPack() const
|
||||
ModPlatform::IndexedPack::Ptr ResourcePage::getCurrentPack() const
|
||||
{
|
||||
return m_model->data(m_ui->packView->currentIndex(), Qt::UserRole).value<ModPlatform::IndexedPack>();
|
||||
return m_model->data(m_ui->packView->currentIndex(), Qt::UserRole).value<ModPlatform::IndexedPack::Ptr>();
|
||||
}
|
||||
|
||||
void ResourcePage::updateUi()
|
||||
@ -175,14 +176,14 @@ void ResourcePage::updateUi()
|
||||
auto current_pack = getCurrentPack();
|
||||
|
||||
QString text = "";
|
||||
QString name = current_pack.name;
|
||||
QString name = current_pack->name;
|
||||
|
||||
if (current_pack.websiteUrl.isEmpty())
|
||||
if (current_pack->websiteUrl.isEmpty())
|
||||
text = name;
|
||||
else
|
||||
text = "<a href=\"" + current_pack.websiteUrl + "\">" + name + "</a>";
|
||||
text = "<a href=\"" + current_pack->websiteUrl + "\">" + name + "</a>";
|
||||
|
||||
if (!current_pack.authors.empty()) {
|
||||
if (!current_pack->authors.empty()) {
|
||||
auto authorToStr = [](ModPlatform::ModpackAuthor& author) -> QString {
|
||||
if (author.url.isEmpty()) {
|
||||
return author.name;
|
||||
@ -190,44 +191,44 @@ void ResourcePage::updateUi()
|
||||
return QString("<a href=\"%1\">%2</a>").arg(author.url, author.name);
|
||||
};
|
||||
QStringList authorStrs;
|
||||
for (auto& author : current_pack.authors) {
|
||||
for (auto& author : current_pack->authors) {
|
||||
authorStrs.push_back(authorToStr(author));
|
||||
}
|
||||
text += "<br>" + tr(" by ") + authorStrs.join(", ");
|
||||
}
|
||||
|
||||
if (current_pack.extraDataLoaded) {
|
||||
if (!current_pack.extraData.donate.isEmpty()) {
|
||||
if (current_pack->extraDataLoaded) {
|
||||
if (!current_pack->extraData.donate.isEmpty()) {
|
||||
text += "<br><br>" + tr("Donate information: ");
|
||||
auto donateToStr = [](ModPlatform::DonationData& donate) -> QString {
|
||||
return QString("<a href=\"%1\">%2</a>").arg(donate.url, donate.platform);
|
||||
};
|
||||
QStringList donates;
|
||||
for (auto& donate : current_pack.extraData.donate) {
|
||||
for (auto& donate : current_pack->extraData.donate) {
|
||||
donates.append(donateToStr(donate));
|
||||
}
|
||||
text += donates.join(", ");
|
||||
}
|
||||
|
||||
if (!current_pack.extraData.issuesUrl.isEmpty() || !current_pack.extraData.sourceUrl.isEmpty() ||
|
||||
!current_pack.extraData.wikiUrl.isEmpty() || !current_pack.extraData.discordUrl.isEmpty()) {
|
||||
if (!current_pack->extraData.issuesUrl.isEmpty() || !current_pack->extraData.sourceUrl.isEmpty() ||
|
||||
!current_pack->extraData.wikiUrl.isEmpty() || !current_pack->extraData.discordUrl.isEmpty()) {
|
||||
text += "<br><br>" + tr("External links:") + "<br>";
|
||||
}
|
||||
|
||||
if (!current_pack.extraData.issuesUrl.isEmpty())
|
||||
text += "- " + tr("Issues: <a href=%1>%1</a>").arg(current_pack.extraData.issuesUrl) + "<br>";
|
||||
if (!current_pack.extraData.wikiUrl.isEmpty())
|
||||
text += "- " + tr("Wiki: <a href=%1>%1</a>").arg(current_pack.extraData.wikiUrl) + "<br>";
|
||||
if (!current_pack.extraData.sourceUrl.isEmpty())
|
||||
text += "- " + tr("Source code: <a href=%1>%1</a>").arg(current_pack.extraData.sourceUrl) + "<br>";
|
||||
if (!current_pack.extraData.discordUrl.isEmpty())
|
||||
text += "- " + tr("Discord: <a href=%1>%1</a>").arg(current_pack.extraData.discordUrl) + "<br>";
|
||||
if (!current_pack->extraData.issuesUrl.isEmpty())
|
||||
text += "- " + tr("Issues: <a href=%1>%1</a>").arg(current_pack->extraData.issuesUrl) + "<br>";
|
||||
if (!current_pack->extraData.wikiUrl.isEmpty())
|
||||
text += "- " + tr("Wiki: <a href=%1>%1</a>").arg(current_pack->extraData.wikiUrl) + "<br>";
|
||||
if (!current_pack->extraData.sourceUrl.isEmpty())
|
||||
text += "- " + tr("Source code: <a href=%1>%1</a>").arg(current_pack->extraData.sourceUrl) + "<br>";
|
||||
if (!current_pack->extraData.discordUrl.isEmpty())
|
||||
text += "- " + tr("Discord: <a href=%1>%1</a>").arg(current_pack->extraData.discordUrl) + "<br>";
|
||||
}
|
||||
|
||||
text += "<hr>";
|
||||
|
||||
m_ui->packDescription->setHtml(
|
||||
text + (current_pack.extraData.body.isEmpty() ? current_pack.description : markdownToHTML(current_pack.extraData.body)));
|
||||
text + (current_pack->extraData.body.isEmpty() ? current_pack->description : markdownToHTML(current_pack->extraData.body)));
|
||||
m_ui->packDescription->flush();
|
||||
}
|
||||
|
||||
@ -239,7 +240,7 @@ void ResourcePage::updateSelectionButton()
|
||||
}
|
||||
|
||||
m_ui->resourceSelectionButton->setEnabled(true);
|
||||
if (!getCurrentPack().isVersionSelected(m_selected_version_index)) {
|
||||
if (!getCurrentPack()->isVersionSelected(m_selected_version_index)) {
|
||||
m_ui->resourceSelectionButton->setText(tr("Select %1 for download").arg(resourceString()));
|
||||
} else {
|
||||
m_ui->resourceSelectionButton->setText(tr("Deselect %1 for download").arg(resourceString()));
|
||||
@ -254,12 +255,12 @@ void ResourcePage::updateVersionList()
|
||||
m_ui->versionSelectionBox->clear();
|
||||
m_ui->versionSelectionBox->blockSignals(false);
|
||||
|
||||
for (int i = 0; i < current_pack.versions.size(); i++) {
|
||||
auto& version = current_pack.versions[i];
|
||||
for (int i = 0; i < current_pack->versions.size(); i++) {
|
||||
auto& version = current_pack->versions[i];
|
||||
if (optedOut(version))
|
||||
continue;
|
||||
|
||||
m_ui->versionSelectionBox->addItem(current_pack.versions[i].version, QVariant(i));
|
||||
m_ui->versionSelectionBox->addItem(current_pack->versions[i].version, QVariant(i));
|
||||
}
|
||||
|
||||
if (m_ui->versionSelectionBox->count() == 0) {
|
||||
@ -279,7 +280,7 @@ void ResourcePage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
|
||||
auto current_pack = getCurrentPack();
|
||||
|
||||
bool request_load = false;
|
||||
if (!current_pack.versionsLoaded) {
|
||||
if (!current_pack->versionsLoaded) {
|
||||
m_ui->resourceSelectionButton->setText(tr("Loading versions..."));
|
||||
m_ui->resourceSelectionButton->setEnabled(false);
|
||||
|
||||
@ -288,7 +289,7 @@ void ResourcePage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
|
||||
updateVersionList();
|
||||
}
|
||||
|
||||
if (!current_pack.extraDataLoaded)
|
||||
if (!current_pack->extraDataLoaded)
|
||||
request_load = true;
|
||||
|
||||
if (request_load)
|
||||
@ -308,14 +309,26 @@ void ResourcePage::onVersionSelectionChanged(QString data)
|
||||
updateSelectionButton();
|
||||
}
|
||||
|
||||
void ResourcePage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
|
||||
void ResourcePage::addResourceToDialog(ModPlatform::IndexedPack::Ptr pack, ModPlatform::IndexedVersion& version)
|
||||
{
|
||||
m_parent_dialog->addResource(pack, version);
|
||||
}
|
||||
|
||||
void ResourcePage::removeResourceFromDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
|
||||
void ResourcePage::removeResourceFromDialog(const QString& pack_name)
|
||||
{
|
||||
m_parent_dialog->removeResource(pack, version);
|
||||
m_parent_dialog->removeResource(pack_name);
|
||||
}
|
||||
|
||||
void ResourcePage::addResourceToPage(ModPlatform::IndexedPack::Ptr pack,
|
||||
ModPlatform::IndexedVersion& ver,
|
||||
const std::shared_ptr<ResourceFolderModel> base_model)
|
||||
{
|
||||
m_model->addPack(pack, ver, base_model);
|
||||
}
|
||||
|
||||
void ResourcePage::removeResourceFromPage(const QString& name)
|
||||
{
|
||||
m_model->removePack(name);
|
||||
}
|
||||
|
||||
void ResourcePage::onResourceSelected()
|
||||
@ -324,12 +337,12 @@ void ResourcePage::onResourceSelected()
|
||||
return;
|
||||
|
||||
auto current_pack = getCurrentPack();
|
||||
if (!current_pack.versionsLoaded)
|
||||
if (!current_pack->versionsLoaded)
|
||||
return;
|
||||
|
||||
auto& version = current_pack.versions[m_selected_version_index];
|
||||
auto& version = current_pack->versions[m_selected_version_index];
|
||||
if (version.is_currently_selected)
|
||||
removeResourceFromDialog(current_pack, version);
|
||||
removeResourceFromDialog(current_pack->name);
|
||||
else
|
||||
addResourceToDialog(current_pack, version);
|
||||
|
||||
@ -340,7 +353,7 @@ void ResourcePage::onResourceSelected()
|
||||
updateSelectionButton();
|
||||
|
||||
/* Force redraw on the resource list when the selection changes */
|
||||
m_ui->packView->adjustSize();
|
||||
m_ui->packView->repaint();
|
||||
}
|
||||
|
||||
void ResourcePage::openUrl(const QUrl& url)
|
||||
@ -370,7 +383,7 @@ void ResourcePage::openUrl(const QUrl& url)
|
||||
const QString slug = match.captured(1);
|
||||
|
||||
// ensure the user isn't opening the same mod
|
||||
if (slug != getCurrentPack().slug) {
|
||||
if (slug != getCurrentPack()->slug) {
|
||||
m_parent_dialog->selectPage(page);
|
||||
|
||||
auto newPage = m_parent_dialog->getSelectedPage();
|
||||
|
@ -7,10 +7,12 @@
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
#include "ResourceDownloadTask.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
#include "modplatform/ResourceAPI.h"
|
||||
|
||||
#include "ui/pages/BasePage.h"
|
||||
#include "ui/pages/modplatform/ResourceModel.h"
|
||||
#include "ui/widgets/ProgressWidget.h"
|
||||
|
||||
namespace Ui {
|
||||
@ -27,6 +29,7 @@ class ResourceModel;
|
||||
class ResourcePage : public QWidget, public BasePage {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using DownloadTaskPtr = shared_qobject_ptr<ResourceDownloadTask>;
|
||||
~ResourcePage() override;
|
||||
|
||||
/* Affects what the user sees */
|
||||
@ -57,8 +60,8 @@ class ResourcePage : public QWidget, public BasePage {
|
||||
/** Programatically set the term in the search bar. */
|
||||
void setSearchTerm(QString);
|
||||
|
||||
[[nodiscard]] bool setCurrentPack(ModPlatform::IndexedPack);
|
||||
[[nodiscard]] auto getCurrentPack() const -> ModPlatform::IndexedPack;
|
||||
[[nodiscard]] bool setCurrentPack(ModPlatform::IndexedPack::Ptr);
|
||||
[[nodiscard]] auto getCurrentPack() const -> ModPlatform::IndexedPack::Ptr;
|
||||
[[nodiscard]] auto getDialog() const -> const ResourceDownloadDialog* { return m_parent_dialog; }
|
||||
[[nodiscard]] auto getModel() const -> ResourceModel* { return m_model; }
|
||||
|
||||
@ -72,8 +75,13 @@ class ResourcePage : public QWidget, public BasePage {
|
||||
virtual void updateSelectionButton();
|
||||
virtual void updateVersionList();
|
||||
|
||||
virtual void addResourceToDialog(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&);
|
||||
virtual void removeResourceFromDialog(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&);
|
||||
void addResourceToDialog(ModPlatform::IndexedPack::Ptr, ModPlatform::IndexedVersion&);
|
||||
void removeResourceFromDialog(const QString& pack_name);
|
||||
virtual void removeResourceFromPage(const QString& name);
|
||||
virtual void addResourceToPage(ModPlatform::IndexedPack::Ptr, ModPlatform::IndexedVersion&, const std::shared_ptr<ResourceFolderModel>);
|
||||
|
||||
QList<DownloadTaskPtr> selectedPacks() { return m_model->selectedPacks(); }
|
||||
bool hasSelectedPacks() { return !(m_model->selectedPacks().isEmpty()); }
|
||||
|
||||
protected slots:
|
||||
virtual void triggerSearch() {}
|
||||
|
@ -13,8 +13,7 @@
|
||||
|
||||
namespace ResourceDownload {
|
||||
|
||||
ShaderPackResourcePage::ShaderPackResourcePage(ShaderPackDownloadDialog* dialog, BaseInstance& instance)
|
||||
: ResourcePage(dialog, instance)
|
||||
ShaderPackResourcePage::ShaderPackResourcePage(ShaderPackDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance)
|
||||
{
|
||||
connect(m_ui->searchButton, &QPushButton::clicked, this, &ShaderPackResourcePage::triggerSearch);
|
||||
connect(m_ui->packView, &QListView::doubleClicked, this, &ShaderPackResourcePage::onResourceSelected);
|
||||
@ -38,17 +37,20 @@ QMap<QString, QString> ShaderPackResourcePage::urlHandlers() const
|
||||
{
|
||||
QMap<QString, QString> map;
|
||||
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");
|
||||
return map;
|
||||
}
|
||||
|
||||
void ShaderPackResourcePage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
|
||||
void ShaderPackResourcePage::addResourceToPage(ModPlatform::IndexedPack::Ptr pack,
|
||||
ModPlatform::IndexedVersion& version,
|
||||
const std::shared_ptr<ResourceFolderModel> base_model)
|
||||
{
|
||||
QString custom_target_folder;
|
||||
if (version.loaders.contains(QStringLiteral("canvas")))
|
||||
version.custom_target_folder = QStringLiteral("resourcepacks");
|
||||
|
||||
m_parent_dialog->addResource(pack, version);
|
||||
custom_target_folder = QStringLiteral("resourcepacks");
|
||||
m_model->addPack(pack, version, base_model, false, custom_target_folder);
|
||||
}
|
||||
|
||||
} // namespace ResourceDownload
|
||||
|
@ -38,7 +38,9 @@ class ShaderPackResourcePage : public ResourcePage {
|
||||
|
||||
[[nodiscard]] bool supportsFiltering() const override { return false; };
|
||||
|
||||
void addResourceToDialog(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&) override;
|
||||
void addResourceToPage(ModPlatform::IndexedPack::Ptr,
|
||||
ModPlatform::IndexedVersion&,
|
||||
const std::shared_ptr<ResourceFolderModel>) override;
|
||||
|
||||
[[nodiscard]] QMap<QString, QString> urlHandlers() const override;
|
||||
|
||||
|
@ -137,6 +137,11 @@ BasePage* PageContainer::getPage(QString pageId)
|
||||
return m_model->findPageEntryById(pageId);
|
||||
}
|
||||
|
||||
const QList<BasePage*> PageContainer::getPages() const
|
||||
{
|
||||
return m_model->pages();
|
||||
}
|
||||
|
||||
void PageContainer::refreshContainer()
|
||||
{
|
||||
m_proxyModel->invalidate();
|
||||
|
@ -80,6 +80,7 @@ public:
|
||||
|
||||
virtual bool selectPage(QString pageId) override;
|
||||
BasePage* getPage(QString pageId) override;
|
||||
const QList<BasePage*> getPages() const;
|
||||
|
||||
void refreshContainer() override;
|
||||
virtual void setParentContainer(BasePageContainer * container)
|
||||
|
Loading…
Reference in New Issue
Block a user