2018-11-28 20:02:29 +01:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
2018-12-04 19:34:46 +01:00
|
|
|
|
|
|
|
#include <QHeaderView>
|
2018-11-28 20:02:29 +01:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QString>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QTreeView>
|
2018-12-04 19:34:46 +01:00
|
|
|
|
2019-04-23 15:09:02 +02:00
|
|
|
#include "common/common_paths.h"
|
|
|
|
#include "common/file_util.h"
|
2018-11-28 20:02:29 +01:00
|
|
|
#include "core/file_sys/control_metadata.h"
|
|
|
|
#include "core/file_sys/patch_manager.h"
|
|
|
|
#include "core/file_sys/xts_archive.h"
|
|
|
|
#include "core/loader/loader.h"
|
2018-12-04 19:34:46 +01:00
|
|
|
#include "ui_configure_per_general.h"
|
2018-11-28 20:02:29 +01:00
|
|
|
#include "yuzu/configuration/config.h"
|
|
|
|
#include "yuzu/configuration/configure_input.h"
|
|
|
|
#include "yuzu/configuration/configure_per_general.h"
|
2019-07-29 22:06:33 +02:00
|
|
|
#include "yuzu/uisettings.h"
|
2018-12-04 19:34:46 +01:00
|
|
|
#include "yuzu/util/util.h"
|
2018-11-28 20:02:29 +01:00
|
|
|
|
2018-12-04 19:34:46 +01:00
|
|
|
ConfigurePerGameGeneral::ConfigurePerGameGeneral(QWidget* parent, u64 title_id)
|
2018-11-28 20:02:29 +01:00
|
|
|
: QDialog(parent), ui(std::make_unique<Ui::ConfigurePerGameGeneral>()), title_id(title_id) {
|
|
|
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
setFocusPolicy(Qt::ClickFocus);
|
|
|
|
setWindowTitle(tr("Properties"));
|
|
|
|
|
|
|
|
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 23:45:12 +01:00
|
|
|
item_model->setHeaderData(0, Qt::Horizontal, tr("Patch Name"));
|
|
|
|
item_model->setHeaderData(1, Qt::Horizontal, tr("Version"));
|
2018-11-28 20:02:29 +01:00
|
|
|
|
|
|
|
// We must register all custom types with the Qt Automoc system so that we are able to use it
|
|
|
|
// with signals/slots. In this case, QList falls under the umbrells of custom types.
|
|
|
|
qRegisterMetaType<QList<QStandardItem*>>("QList<QStandardItem*>");
|
|
|
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
layout->setSpacing(0);
|
|
|
|
layout->addWidget(tree_view);
|
|
|
|
|
|
|
|
ui->scrollArea->setLayout(layout);
|
|
|
|
|
|
|
|
scene = new QGraphicsScene;
|
|
|
|
ui->icon_view->setScene(scene);
|
|
|
|
|
|
|
|
connect(item_model, &QStandardItemModel::itemChanged,
|
2018-12-04 19:34:46 +01:00
|
|
|
[] { UISettings::values.is_game_list_reload_pending.exchange(true); });
|
2018-11-28 20:02:29 +01:00
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
LoadConfiguration();
|
2018-11-28 20:02:29 +01:00
|
|
|
}
|
|
|
|
|
2018-12-04 19:34:46 +01:00
|
|
|
ConfigurePerGameGeneral::~ConfigurePerGameGeneral() = default;
|
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
void ConfigurePerGameGeneral::ApplyConfiguration() {
|
2018-11-28 20:02:29 +01:00
|
|
|
std::vector<std::string> disabled_addons;
|
|
|
|
|
|
|
|
for (const auto& item : list_items) {
|
|
|
|
const auto disabled = item.front()->checkState() == Qt::Unchecked;
|
|
|
|
if (disabled)
|
|
|
|
disabled_addons.push_back(item.front()->text().toStdString());
|
|
|
|
}
|
|
|
|
|
2019-04-23 15:09:02 +02: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) {
|
|
|
|
FileUtil::Delete(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP +
|
|
|
|
"game_list" + DIR_SEP + fmt::format("{:016X}.pv.txt", title_id));
|
|
|
|
}
|
|
|
|
|
2018-11-28 20:02:29 +01:00
|
|
|
Settings::values.disabled_addons[title_id] = disabled_addons;
|
|
|
|
}
|
|
|
|
|
2019-06-06 00:39:46 +02:00
|
|
|
void ConfigurePerGameGeneral::changeEvent(QEvent* event) {
|
|
|
|
if (event->type() == QEvent::LanguageChange) {
|
|
|
|
RetranslateUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialog::changeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigurePerGameGeneral::RetranslateUI() {
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
void ConfigurePerGameGeneral::LoadFromFile(FileSys::VirtualFile file) {
|
2018-11-28 20:02:29 +01:00
|
|
|
this->file = std::move(file);
|
2019-05-26 06:39:23 +02:00
|
|
|
LoadConfiguration();
|
2018-11-28 20:02:29 +01:00
|
|
|
}
|
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
void ConfigurePerGameGeneral::LoadConfiguration() {
|
2019-05-19 18:47:30 +02:00
|
|
|
if (file == nullptr) {
|
2018-11-28 20:02:29 +01:00
|
|
|
return;
|
2019-05-19 18:47:30 +02:00
|
|
|
}
|
2018-11-28 20:02:29 +01:00
|
|
|
|
2019-05-19 18:47:30 +02:00
|
|
|
ui->display_title_id->setText(QString::fromStdString(fmt::format("{:016X}", title_id)));
|
2018-11-28 20:02:29 +01:00
|
|
|
|
|
|
|
FileSys::PatchManager pm{title_id};
|
|
|
|
const auto control = pm.GetControlMetadata();
|
2019-05-19 18:47:30 +02:00
|
|
|
const auto loader = Loader::GetLoader(file);
|
2018-11-28 20:02:29 +01:00
|
|
|
|
|
|
|
if (control.first != nullptr) {
|
|
|
|
ui->display_version->setText(QString::fromStdString(control.first->GetVersionString()));
|
|
|
|
ui->display_name->setText(QString::fromStdString(control.first->GetApplicationName()));
|
|
|
|
ui->display_developer->setText(QString::fromStdString(control.first->GetDeveloperName()));
|
|
|
|
} else {
|
|
|
|
std::string title;
|
|
|
|
if (loader->ReadTitle(title) == Loader::ResultStatus::Success)
|
|
|
|
ui->display_name->setText(QString::fromStdString(title));
|
|
|
|
|
2018-12-11 04:17:45 +01:00
|
|
|
FileSys::NACP nacp;
|
|
|
|
if (loader->ReadControlData(nacp) == Loader::ResultStatus::Success)
|
|
|
|
ui->display_developer->setText(QString::fromStdString(nacp.GetDeveloperName()));
|
2018-11-28 20:02:29 +01:00
|
|
|
|
2018-12-04 19:34:46 +01:00
|
|
|
ui->display_version->setText(QStringLiteral("1.0.0"));
|
2018-11-28 20:02:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (control.second != nullptr) {
|
|
|
|
scene->clear();
|
|
|
|
|
|
|
|
QPixmap map;
|
|
|
|
const auto bytes = control.second->ReadAllBytes();
|
2019-01-01 01:13:40 +01:00
|
|
|
map.loadFromData(bytes.data(), static_cast<u32>(bytes.size()));
|
2018-11-28 20:02:29 +01:00
|
|
|
|
|
|
|
scene->addPixmap(map.scaled(ui->icon_view->width(), ui->icon_view->height(),
|
|
|
|
Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
|
|
|
} else {
|
|
|
|
std::vector<u8> bytes;
|
|
|
|
if (loader->ReadIcon(bytes) == Loader::ResultStatus::Success) {
|
|
|
|
scene->clear();
|
|
|
|
|
|
|
|
QPixmap map;
|
2019-01-01 01:13:40 +01:00
|
|
|
map.loadFromData(bytes.data(), static_cast<u32>(bytes.size()));
|
2018-11-28 20:02:29 +01:00
|
|
|
|
|
|
|
scene->addPixmap(map.scaled(ui->icon_view->width(), ui->icon_view->height(),
|
|
|
|
Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSys::VirtualFile update_raw;
|
|
|
|
loader->ReadUpdateRaw(update_raw);
|
|
|
|
|
|
|
|
const auto& disabled = Settings::values.disabled_addons[title_id];
|
|
|
|
|
|
|
|
for (const auto& patch : pm.GetPatchVersionNames(update_raw)) {
|
2019-05-19 18:47:30 +02:00
|
|
|
const auto name =
|
|
|
|
QString::fromStdString(patch.first).replace(QStringLiteral("[D] "), QString{});
|
|
|
|
|
|
|
|
auto* const first_item = new QStandardItem;
|
2018-11-28 20:02:29 +01:00
|
|
|
first_item->setText(name);
|
|
|
|
first_item->setCheckable(true);
|
|
|
|
|
|
|
|
const auto patch_disabled =
|
|
|
|
std::find(disabled.begin(), disabled.end(), name.toStdString()) != disabled.end();
|
|
|
|
|
|
|
|
first_item->setCheckState(patch_disabled ? Qt::Unchecked : Qt::Checked);
|
|
|
|
|
|
|
|
list_items.push_back(QList<QStandardItem*>{
|
|
|
|
first_item, new QStandardItem{QString::fromStdString(patch.second)}});
|
|
|
|
item_model->appendRow(list_items.back());
|
|
|
|
}
|
|
|
|
|
|
|
|
tree_view->setColumnWidth(0, 5 * tree_view->width() / 16);
|
|
|
|
|
|
|
|
ui->display_filename->setText(QString::fromStdString(file->GetName()));
|
|
|
|
|
|
|
|
ui->display_format->setText(
|
|
|
|
QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType())));
|
|
|
|
|
2018-12-04 19:34:46 +01:00
|
|
|
const auto valueText = ReadableByteSize(file->GetSize());
|
2018-11-28 20:02:29 +01:00
|
|
|
ui->display_size->setText(valueText);
|
|
|
|
}
|