2026-02-06 06:37:30 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
2025-09-15 17:21:18 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
2022-05-15 02:06:02 +02:00
|
|
|
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-11-28 14:02:29 -05:00
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <utility>
|
2018-12-04 13:34:46 -05:00
|
|
|
|
2026-02-06 14:05:44 +01:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
2018-12-04 13:34:46 -05:00
|
|
|
#include <QHeaderView>
|
2018-11-28 14:02:29 -05:00
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QTreeView>
|
2026-02-06 06:37:30 +01:00
|
|
|
#include <qstandardpaths.h>
|
2018-12-04 13:34:46 -05:00
|
|
|
|
2026-02-06 14:05:44 +01:00
|
|
|
#include "common/common_types.h"
|
2021-05-25 19:32:56 -04:00
|
|
|
#include "common/fs/fs.h"
|
|
|
|
|
#include "common/fs/path_util.h"
|
2026-02-06 06:37:30 +01:00
|
|
|
#include "configuration/addon/mod_select_dialog.h"
|
2020-07-09 22:42:09 -04:00
|
|
|
#include "core/core.h"
|
2018-11-28 14:02:29 -05:00
|
|
|
#include "core/file_sys/patch_manager.h"
|
|
|
|
|
#include "core/loader/loader.h"
|
2026-02-06 06:37:30 +01:00
|
|
|
#include "frontend_common/mod_manager.h"
|
|
|
|
|
#include "qt_common/abstract/frontend.h"
|
|
|
|
|
#include "qt_common/config/uisettings.h"
|
|
|
|
|
#include "qt_common/util/mod.h"
|
2020-07-09 22:42:09 -04:00
|
|
|
#include "ui_configure_per_game_addons.h"
|
2018-11-28 14:02:29 -05:00
|
|
|
#include "yuzu/configuration/configure_input.h"
|
2020-07-09 22:42:09 -04:00
|
|
|
#include "yuzu/configuration/configure_per_game_addons.h"
|
2018-11-28 14:02:29 -05:00
|
|
|
|
2021-09-02 21:40:55 -04:00
|
|
|
ConfigurePerGameAddons::ConfigurePerGameAddons(Core::System& system_, QWidget* parent)
|
2021-10-15 15:26:20 -04:00
|
|
|
: QWidget(parent), ui{std::make_unique<Ui::ConfigurePerGameAddons>()}, system{system_} {
|
2018-11-28 14:02:29 -05:00
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
|
|
layout = new QVBoxLayout;
|
|
|
|
|
tree_view = new QTreeView;
|
|
|
|
|
item_model = new QStandardItemModel(tree_view);
|
|
|
|
|
tree_view->setModel(item_model);
|
|
|
|
|
tree_view->setAlternatingRowColors(true);
|
|
|
|
|
tree_view->setSelectionMode(QHeaderView::SingleSelection);
|
|
|
|
|
tree_view->setSelectionBehavior(QHeaderView::SelectRows);
|
|
|
|
|
tree_view->setVerticalScrollMode(QHeaderView::ScrollPerPixel);
|
|
|
|
|
tree_view->setHorizontalScrollMode(QHeaderView::ScrollPerPixel);
|
|
|
|
|
tree_view->setSortingEnabled(true);
|
|
|
|
|
tree_view->setEditTriggers(QHeaderView::NoEditTriggers);
|
|
|
|
|
tree_view->setUniformRowHeights(true);
|
|
|
|
|
tree_view->setContextMenuPolicy(Qt::NoContextMenu);
|
|
|
|
|
|
|
|
|
|
item_model->insertColumns(0, 2);
|
2018-12-26 17:45:12 -05:00
|
|
|
item_model->setHeaderData(0, Qt::Horizontal, tr("Patch Name"));
|
|
|
|
|
item_model->setHeaderData(1, Qt::Horizontal, tr("Version"));
|
2018-11-28 14:02:29 -05:00
|
|
|
|
2022-04-02 13:39:35 +01:00
|
|
|
tree_view->header()->setStretchLastSection(false);
|
|
|
|
|
tree_view->header()->setSectionResizeMode(0, QHeaderView::ResizeMode::Stretch);
|
2022-04-02 17:19:25 +01:00
|
|
|
tree_view->header()->setMinimumSectionSize(150);
|
2022-04-02 13:39:35 +01:00
|
|
|
|
2018-11-28 14:02:29 -05:00
|
|
|
// We must register all custom types with the Qt Automoc system so that we are able to use it
|
2020-07-09 22:42:09 -04:00
|
|
|
// with signals/slots. In this case, QList falls under the umbrella of custom types.
|
2018-11-28 14:02:29 -05:00
|
|
|
qRegisterMetaType<QList<QStandardItem*>>("QList<QStandardItem*>");
|
|
|
|
|
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
layout->setSpacing(0);
|
|
|
|
|
layout->addWidget(tree_view);
|
|
|
|
|
|
|
|
|
|
ui->scrollArea->setLayout(layout);
|
|
|
|
|
|
2021-09-02 21:40:55 -04:00
|
|
|
ui->scrollArea->setEnabled(!system.IsPoweredOn());
|
2018-11-28 14:02:29 -05:00
|
|
|
|
2026-02-06 14:05:44 +01:00
|
|
|
connect(item_model, &QStandardItemModel::itemChanged, this,
|
|
|
|
|
&ConfigurePerGameAddons::OnItemChanged);
|
2018-11-28 14:02:29 -05:00
|
|
|
connect(item_model, &QStandardItemModel::itemChanged,
|
2018-12-04 13:34:46 -05:00
|
|
|
[] { UISettings::values.is_game_list_reload_pending.exchange(true); });
|
2026-02-06 06:37:30 +01:00
|
|
|
|
|
|
|
|
connect(ui->folder, &QAbstractButton::clicked, this, &ConfigurePerGameAddons::InstallModFolder);
|
|
|
|
|
connect(ui->zip, &QAbstractButton::clicked, this, &ConfigurePerGameAddons::InstallModZip);
|
2018-11-28 14:02:29 -05:00
|
|
|
}
|
|
|
|
|
|
2020-07-09 22:42:09 -04:00
|
|
|
ConfigurePerGameAddons::~ConfigurePerGameAddons() = default;
|
2018-12-04 13:34:46 -05:00
|
|
|
|
2026-02-06 14:05:44 +01:00
|
|
|
void ConfigurePerGameAddons::OnItemChanged(QStandardItem* item) {
|
|
|
|
|
if (update_items.size() > 1 && item->checkState() == Qt::Checked) {
|
|
|
|
|
auto it = std::find(update_items.begin(), update_items.end(), item);
|
|
|
|
|
if (it != update_items.end()) {
|
|
|
|
|
for (auto* update_item : update_items) {
|
|
|
|
|
if (update_item != item && update_item->checkState() == Qt::Checked) {
|
|
|
|
|
disconnect(item_model, &QStandardItemModel::itemChanged, this,
|
|
|
|
|
&ConfigurePerGameAddons::OnItemChanged);
|
|
|
|
|
update_item->setCheckState(Qt::Unchecked);
|
|
|
|
|
connect(item_model, &QStandardItemModel::itemChanged, this,
|
|
|
|
|
&ConfigurePerGameAddons::OnItemChanged);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 22:42:09 -04:00
|
|
|
void ConfigurePerGameAddons::ApplyConfiguration() {
|
2018-11-28 14:02:29 -05:00
|
|
|
std::vector<std::string> disabled_addons;
|
|
|
|
|
|
|
|
|
|
for (const auto& item : list_items) {
|
|
|
|
|
const auto disabled = item.front()->checkState() == Qt::Unchecked;
|
2026-02-06 14:05:44 +01:00
|
|
|
if (disabled) {
|
|
|
|
|
QVariant userData = item.front()->data(Qt::UserRole);
|
|
|
|
|
if (userData.isValid() && userData.canConvert<quint32>() && item.front()->text() == QStringLiteral("Update")) {
|
|
|
|
|
quint32 numeric_version = userData.toUInt();
|
|
|
|
|
disabled_addons.push_back(fmt::format("Update@{}", numeric_version));
|
|
|
|
|
} else {
|
|
|
|
|
disabled_addons.push_back(item.front()->text().toStdString());
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-28 14:02:29 -05:00
|
|
|
}
|
|
|
|
|
|
2019-04-23 09:09:02 -04:00
|
|
|
auto current = Settings::values.disabled_addons[title_id];
|
|
|
|
|
std::sort(disabled_addons.begin(), disabled_addons.end());
|
|
|
|
|
std::sort(current.begin(), current.end());
|
|
|
|
|
if (disabled_addons != current) {
|
2025-05-08 22:16:07 +00:00
|
|
|
Common::FS::RemoveFile(Common::FS::GetEdenPath(Common::FS::EdenPath::CacheDir) /
|
2021-06-19 03:43:16 -04:00
|
|
|
"game_list" / fmt::format("{:016X}.pv.txt", title_id));
|
2019-04-23 09:09:02 -04:00
|
|
|
}
|
|
|
|
|
|
2018-11-28 14:02:29 -05:00
|
|
|
Settings::values.disabled_addons[title_id] = disabled_addons;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-26 19:57:35 -04:00
|
|
|
void ConfigurePerGameAddons::LoadFromFile(FileSys::VirtualFile file_) {
|
|
|
|
|
file = std::move(file_);
|
2020-07-09 22:42:09 -04:00
|
|
|
LoadConfiguration();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConfigurePerGameAddons::SetTitleId(u64 id) {
|
|
|
|
|
this->title_id = id;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-06 06:37:30 +01:00
|
|
|
void ConfigurePerGameAddons::InstallMods(const QStringList& mods) {
|
|
|
|
|
QStringList failed;
|
|
|
|
|
for (const auto& mod : mods) {
|
|
|
|
|
if (FrontendCommon::InstallMod(mod.toStdString(), title_id, true) ==
|
|
|
|
|
FrontendCommon::Failed) {
|
|
|
|
|
failed << QFileInfo(mod).baseName();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (failed.empty()) {
|
|
|
|
|
QtCommon::Frontend::Information(tr("Mod Install Succeeded"),
|
|
|
|
|
tr("Successfully installed all mods."));
|
|
|
|
|
|
|
|
|
|
item_model->removeRows(0, item_model->rowCount());
|
|
|
|
|
list_items.clear();
|
|
|
|
|
LoadConfiguration();
|
|
|
|
|
|
|
|
|
|
UISettings::values.is_game_list_reload_pending.exchange(true);
|
|
|
|
|
} else {
|
|
|
|
|
QtCommon::Frontend::Critical(
|
|
|
|
|
tr("Mod Install Failed"),
|
|
|
|
|
tr("Failed to install the following mods:\n\t%1\nCheck the log for details.")
|
|
|
|
|
.arg(failed.join(QStringLiteral("\n\t"))));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConfigurePerGameAddons::InstallModPath(const QString& path) {
|
|
|
|
|
const auto mods = QtCommon::Mod::GetModFolders(path, {});
|
|
|
|
|
|
|
|
|
|
if (mods.size() > 1) {
|
|
|
|
|
ModSelectDialog* dialog = new ModSelectDialog(mods, this);
|
|
|
|
|
connect(dialog, &ModSelectDialog::modsSelected, this, &ConfigurePerGameAddons::InstallMods);
|
|
|
|
|
dialog->show();
|
|
|
|
|
} else {
|
|
|
|
|
InstallMods(mods);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConfigurePerGameAddons::InstallModFolder() {
|
|
|
|
|
const auto path = QtCommon::Frontend::GetExistingDirectory(
|
|
|
|
|
tr("Mod Folder"), QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InstallModPath(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConfigurePerGameAddons::InstallModZip() {
|
|
|
|
|
const auto path = QtCommon::Frontend::GetOpenFileName(
|
|
|
|
|
tr("Zipped Mod Location"),
|
|
|
|
|
QStandardPaths::writableLocation(QStandardPaths::DownloadLocation),
|
|
|
|
|
tr("Zipped Archives (*.zip)"));
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString extracted = QtCommon::Mod::ExtractMod(path);
|
|
|
|
|
if (!extracted.isEmpty())
|
|
|
|
|
InstallModPath(extracted);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 22:42:09 -04:00
|
|
|
void ConfigurePerGameAddons::changeEvent(QEvent* event) {
|
2019-06-05 18:39:46 -04:00
|
|
|
if (event->type() == QEvent::LanguageChange) {
|
|
|
|
|
RetranslateUI();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 22:42:09 -04:00
|
|
|
QWidget::changeEvent(event);
|
2019-06-05 18:39:46 -04:00
|
|
|
}
|
|
|
|
|
|
2020-07-09 22:42:09 -04:00
|
|
|
void ConfigurePerGameAddons::RetranslateUI() {
|
2019-06-05 18:39:46 -04:00
|
|
|
ui->retranslateUi(this);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 22:42:09 -04:00
|
|
|
void ConfigurePerGameAddons::LoadConfiguration() {
|
2019-05-19 12:47:30 -04:00
|
|
|
if (file == nullptr) {
|
2018-11-28 14:02:29 -05:00
|
|
|
return;
|
2019-05-19 12:47:30 -04:00
|
|
|
}
|
2018-11-28 14:02:29 -05:00
|
|
|
|
2020-11-18 07:53:10 -05:00
|
|
|
const FileSys::PatchManager pm{title_id, system.GetFileSystemController(),
|
|
|
|
|
system.GetContentProvider()};
|
|
|
|
|
const auto loader = Loader::GetLoader(system, file);
|
2018-11-28 14:02:29 -05:00
|
|
|
|
|
|
|
|
FileSys::VirtualFile update_raw;
|
|
|
|
|
loader->ReadUpdateRaw(update_raw);
|
|
|
|
|
|
|
|
|
|
const auto& disabled = Settings::values.disabled_addons[title_id];
|
|
|
|
|
|
2026-02-06 14:05:44 +01:00
|
|
|
update_items.clear();
|
|
|
|
|
list_items.clear();
|
|
|
|
|
item_model->removeRows(0, item_model->rowCount());
|
|
|
|
|
|
|
|
|
|
std::vector<FileSys::Patch> patches = pm.GetPatches(update_raw);
|
|
|
|
|
|
|
|
|
|
bool has_enabled_update = false;
|
|
|
|
|
|
|
|
|
|
for (const auto& patch : patches) {
|
2024-01-19 16:37:34 -05:00
|
|
|
const auto name = QString::fromStdString(patch.name);
|
2019-05-19 12:47:30 -04:00
|
|
|
|
|
|
|
|
auto* const first_item = new QStandardItem;
|
2018-11-28 14:02:29 -05:00
|
|
|
first_item->setText(name);
|
|
|
|
|
first_item->setCheckable(true);
|
|
|
|
|
|
2026-02-06 14:05:44 +01:00
|
|
|
const bool is_external_update = patch.type == FileSys::PatchType::Update &&
|
|
|
|
|
patch.source == FileSys::PatchSource::External &&
|
|
|
|
|
patch.numeric_version != 0;
|
|
|
|
|
|
|
|
|
|
if (is_external_update) {
|
|
|
|
|
first_item->setData(static_cast<quint32>(patch.numeric_version), Qt::UserRole);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool patch_disabled = false;
|
|
|
|
|
if (is_external_update) {
|
|
|
|
|
std::string disabled_key = fmt::format("Update@{}", patch.numeric_version);
|
|
|
|
|
patch_disabled = std::find(disabled.begin(), disabled.end(), disabled_key) != disabled.end();
|
|
|
|
|
} else {
|
|
|
|
|
patch_disabled = std::find(disabled.begin(), disabled.end(), name.toStdString()) != disabled.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool should_enable = !patch_disabled;
|
|
|
|
|
|
|
|
|
|
if (patch.type == FileSys::PatchType::Update) {
|
|
|
|
|
if (should_enable) {
|
|
|
|
|
if (has_enabled_update) {
|
|
|
|
|
should_enable = false;
|
|
|
|
|
} else {
|
|
|
|
|
has_enabled_update = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
update_items.push_back(first_item);
|
|
|
|
|
}
|
2018-11-28 14:02:29 -05:00
|
|
|
|
2026-02-06 14:05:44 +01:00
|
|
|
first_item->setCheckState(should_enable ? Qt::Checked : Qt::Unchecked);
|
2018-11-28 14:02:29 -05:00
|
|
|
|
|
|
|
|
list_items.push_back(QList<QStandardItem*>{
|
2024-01-19 16:37:34 -05:00
|
|
|
first_item, new QStandardItem{QString::fromStdString(patch.version)}});
|
2018-11-28 14:02:29 -05:00
|
|
|
item_model->appendRow(list_items.back());
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-02 13:39:35 +01:00
|
|
|
tree_view->resizeColumnToContents(1);
|
2018-11-28 14:02:29 -05:00
|
|
|
}
|