2020-12-28 16:15:37 +01:00
|
|
|
// Copyright 2020 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <algorithm>
|
2021-06-03 08:01:41 +02:00
|
|
|
#include <filesystem>
|
2020-12-28 16:15:37 +01:00
|
|
|
#include <memory>
|
2021-06-02 03:16:38 +02:00
|
|
|
#include <string>
|
2020-12-28 16:15:37 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2021-06-03 08:01:41 +02:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2021-05-21 09:31:35 +02:00
|
|
|
#include <QAbstractButton>
|
2020-12-28 16:15:37 +01:00
|
|
|
#include <QCheckBox>
|
2021-05-21 09:31:35 +02:00
|
|
|
#include <QDialogButtonBox>
|
2020-12-28 16:15:37 +01:00
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QMenu>
|
2021-05-21 09:31:35 +02:00
|
|
|
#include <QPushButton>
|
2020-12-28 16:15:37 +01:00
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QString>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QTreeView>
|
|
|
|
|
2021-06-03 08:01:41 +02:00
|
|
|
#include "common/fs/fs_util.h"
|
2021-06-02 03:16:38 +02:00
|
|
|
#include "common/fs/path_util.h"
|
2020-12-28 16:15:37 +01:00
|
|
|
#include "core/core.h"
|
|
|
|
#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"
|
|
|
|
#include "ui_configure_per_game.h"
|
|
|
|
#include "yuzu/configuration/config.h"
|
2021-10-09 02:29:53 +02:00
|
|
|
#include "yuzu/configuration/configure_audio.h"
|
|
|
|
#include "yuzu/configuration/configure_cpu.h"
|
|
|
|
#include "yuzu/configuration/configure_general.h"
|
|
|
|
#include "yuzu/configuration/configure_graphics.h"
|
|
|
|
#include "yuzu/configuration/configure_graphics_advanced.h"
|
2020-12-28 16:15:37 +01:00
|
|
|
#include "yuzu/configuration/configure_input.h"
|
|
|
|
#include "yuzu/configuration/configure_per_game.h"
|
2021-10-09 02:29:53 +02:00
|
|
|
#include "yuzu/configuration/configure_per_game_addons.h"
|
|
|
|
#include "yuzu/configuration/configure_system.h"
|
2020-12-28 16:15:37 +01:00
|
|
|
#include "yuzu/uisettings.h"
|
|
|
|
#include "yuzu/util/util.h"
|
|
|
|
|
2021-10-09 02:29:53 +02:00
|
|
|
ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id, const std::string& file_name,
|
|
|
|
Core::System& system_)
|
|
|
|
: QDialog(parent), ui(std::make_unique<Ui::ConfigurePerGame>()),
|
|
|
|
title_id(title_id), system{system_}, addons_tab{std::make_unique<ConfigurePerGameAddons>(
|
|
|
|
system_, this)},
|
|
|
|
audio_tab{std::make_unique<ConfigureAudio>(system_, this)},
|
|
|
|
cpu_tab{std::make_unique<ConfigureCpu>(system_, this)},
|
|
|
|
general_tab{std::make_unique<ConfigureGeneral>(system_, this)},
|
|
|
|
graphics_tab{std::make_unique<ConfigureGraphics>(system_, this)},
|
|
|
|
graphics_advanced_tab{std::make_unique<ConfigureGraphicsAdvanced>(system_, this)},
|
|
|
|
system_tab{std::make_unique<ConfigureSystem>(system_, this)} {
|
2021-06-03 08:01:41 +02:00
|
|
|
const auto file_path = std::filesystem::path(Common::FS::ToU8String(file_name));
|
|
|
|
const auto config_file_name = title_id == 0 ? Common::FS::PathToUTF8String(file_path.filename())
|
|
|
|
: fmt::format("{:016X}", title_id);
|
2021-10-09 02:29:53 +02:00
|
|
|
game_config =
|
|
|
|
std::make_unique<Config>(system, config_file_name, Config::ConfigType::PerGameConfig);
|
2020-12-28 16:15:37 +01:00
|
|
|
|
|
|
|
ui->setupUi(this);
|
2021-10-09 02:29:53 +02:00
|
|
|
|
|
|
|
ui->tabWidget->addTab(addons_tab.get(), tr("Add-Ons"));
|
|
|
|
ui->tabWidget->addTab(general_tab.get(), tr("General"));
|
|
|
|
ui->tabWidget->addTab(system_tab.get(), tr("System"));
|
|
|
|
ui->tabWidget->addTab(cpu_tab.get(), tr("CPU"));
|
|
|
|
ui->tabWidget->addTab(graphics_tab.get(), tr("Graphics"));
|
|
|
|
ui->tabWidget->addTab(graphics_advanced_tab.get(), tr("GraphicsAdvanced"));
|
|
|
|
ui->tabWidget->addTab(audio_tab.get(), tr("Audio"));
|
|
|
|
|
2020-12-28 16:15:37 +01:00
|
|
|
setFocusPolicy(Qt::ClickFocus);
|
|
|
|
setWindowTitle(tr("Properties"));
|
2021-06-23 14:35:57 +02:00
|
|
|
// remove Help question mark button from the title bar
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2020-12-28 16:15:37 +01:00
|
|
|
|
2021-10-09 02:29:53 +02:00
|
|
|
addons_tab->SetTitleId(title_id);
|
2020-12-28 16:15:37 +01:00
|
|
|
|
|
|
|
scene = new QGraphicsScene;
|
|
|
|
ui->icon_view->setScene(scene);
|
|
|
|
|
2021-10-09 02:29:53 +02:00
|
|
|
if (system.IsPoweredOn()) {
|
2021-05-21 09:31:35 +02:00
|
|
|
QPushButton* apply_button = ui->buttonBox->addButton(QDialogButtonBox::Apply);
|
|
|
|
connect(apply_button, &QAbstractButton::clicked, this,
|
|
|
|
&ConfigurePerGame::HandleApplyButtonClicked);
|
|
|
|
}
|
|
|
|
|
2020-12-28 16:15:37 +01:00
|
|
|
LoadConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigurePerGame::~ConfigurePerGame() = default;
|
|
|
|
|
|
|
|
void ConfigurePerGame::ApplyConfiguration() {
|
2021-10-09 02:29:53 +02:00
|
|
|
addons_tab->ApplyConfiguration();
|
|
|
|
general_tab->ApplyConfiguration();
|
|
|
|
cpu_tab->ApplyConfiguration();
|
|
|
|
system_tab->ApplyConfiguration();
|
|
|
|
graphics_tab->ApplyConfiguration();
|
|
|
|
graphics_advanced_tab->ApplyConfiguration();
|
|
|
|
audio_tab->ApplyConfiguration();
|
|
|
|
|
|
|
|
system.ApplySettings();
|
2020-12-28 16:15:37 +01:00
|
|
|
Settings::LogSettings();
|
|
|
|
|
|
|
|
game_config->Save();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigurePerGame::changeEvent(QEvent* event) {
|
|
|
|
if (event->type() == QEvent::LanguageChange) {
|
|
|
|
RetranslateUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialog::changeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigurePerGame::RetranslateUI() {
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|
|
|
|
|
2021-05-21 09:31:35 +02:00
|
|
|
void ConfigurePerGame::HandleApplyButtonClicked() {
|
|
|
|
UISettings::values.configuration_applied = true;
|
|
|
|
ApplyConfiguration();
|
|
|
|
}
|
|
|
|
|
2020-12-28 16:15:37 +01:00
|
|
|
void ConfigurePerGame::LoadFromFile(FileSys::VirtualFile file) {
|
|
|
|
this->file = std::move(file);
|
|
|
|
LoadConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigurePerGame::LoadConfiguration() {
|
|
|
|
if (file == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-09 02:29:53 +02:00
|
|
|
addons_tab->LoadFromFile(file);
|
2020-12-28 16:15:37 +01:00
|
|
|
|
|
|
|
ui->display_title_id->setText(
|
|
|
|
QStringLiteral("%1").arg(title_id, 16, 16, QLatin1Char{'0'}).toUpper());
|
|
|
|
|
|
|
|
const FileSys::PatchManager pm{title_id, system.GetFileSystemController(),
|
|
|
|
system.GetContentProvider()};
|
|
|
|
const auto control = pm.GetControlMetadata();
|
|
|
|
const auto loader = Loader::GetLoader(system, file);
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
FileSys::NACP nacp;
|
|
|
|
if (loader->ReadControlData(nacp) == Loader::ResultStatus::Success)
|
|
|
|
ui->display_developer->setText(QString::fromStdString(nacp.GetDeveloperName()));
|
|
|
|
|
|
|
|
ui->display_version->setText(QStringLiteral("1.0.0"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (control.second != nullptr) {
|
|
|
|
scene->clear();
|
|
|
|
|
|
|
|
QPixmap map;
|
|
|
|
const auto bytes = control.second->ReadAllBytes();
|
|
|
|
map.loadFromData(bytes.data(), static_cast<u32>(bytes.size()));
|
|
|
|
|
|
|
|
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;
|
|
|
|
map.loadFromData(bytes.data(), static_cast<u32>(bytes.size()));
|
|
|
|
|
|
|
|
scene->addPixmap(map.scaled(ui->icon_view->width(), ui->icon_view->height(),
|
|
|
|
Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->display_filename->setText(QString::fromStdString(file->GetName()));
|
|
|
|
|
|
|
|
ui->display_format->setText(
|
|
|
|
QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType())));
|
|
|
|
|
|
|
|
const auto valueText = ReadableByteSize(file->GetSize());
|
|
|
|
ui->display_size->setText(valueText);
|
2021-10-09 02:29:53 +02:00
|
|
|
|
|
|
|
general_tab->SetConfiguration();
|
|
|
|
cpu_tab->SetConfiguration();
|
|
|
|
system_tab->SetConfiguration();
|
|
|
|
graphics_tab->SetConfiguration();
|
|
|
|
graphics_advanced_tab->SetConfiguration();
|
|
|
|
audio_tab->SetConfiguration();
|
2020-12-28 16:15:37 +01:00
|
|
|
}
|