pineapple/src/yuzu/configuration/config.cpp

1576 lines
68 KiB
C++
Raw Normal View History

2022-07-27 20:06:50 +02:00
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2020-12-28 16:15:37 +01:00
#include <array>
#include <QKeySequence>
#include <QSettings>
2021-05-08 09:49:31 +02:00
#include "common/fs/fs.h"
#include "common/fs/path_util.h"
2020-12-28 16:15:37 +01:00
#include "core/core.h"
#include "core/hle/service/acc/profile_manager.h"
#include "core/hle/service/hid/controllers/npad.h"
#include "input_common/main.h"
2022-07-26 03:25:01 +02:00
#include "network/network.h"
2020-12-28 16:15:37 +01:00
#include "yuzu/configuration/config.h"
namespace FS = Common::FS;
2022-09-05 05:41:15 +02:00
Config::Config(const std::string& config_name, ConfigType config_type) : type(config_type) {
2020-12-28 16:15:37 +01:00
global = config_type == ConfigType::GlobalConfig;
Initialize(config_name);
}
Config::~Config() {
if (global) {
Save();
}
}
const std::array<int, Settings::NativeButton::NumButtons> Config::default_buttons = {
2021-04-26 10:37:40 +02:00
Qt::Key_C, Qt::Key_X, Qt::Key_V, Qt::Key_Z, Qt::Key_F,
Qt::Key_G, Qt::Key_Q, Qt::Key_E, Qt::Key_R, Qt::Key_T,
Qt::Key_M, Qt::Key_N, Qt::Key_Left, Qt::Key_Up, Qt::Key_Right,
Qt::Key_Down, Qt::Key_Q, Qt::Key_E, 0, 0,
2020-12-28 16:15:37 +01:00
};
const std::array<int, Settings::NativeMotion::NumMotions> Config::default_motions = {
Qt::Key_7,
Qt::Key_8,
};
const std::array<std::array<int, 4>, Settings::NativeAnalog::NumAnalogs> Config::default_analogs{{
{
2021-04-26 10:37:40 +02:00
Qt::Key_W,
Qt::Key_S,
Qt::Key_A,
Qt::Key_D,
2020-12-28 16:15:37 +01:00
},
{
Qt::Key_I,
Qt::Key_K,
Qt::Key_J,
Qt::Key_L,
},
}};
const std::array<int, 2> Config::default_stick_mod = {
2021-04-26 10:37:40 +02:00
Qt::Key_Shift,
0,
2020-12-28 16:15:37 +01:00
};
2022-04-16 16:44:44 +02:00
const std::array<int, 2> Config::default_ringcon_analogs{{
Qt::Key_A,
Qt::Key_D,
}};
2020-12-28 16:15:37 +01:00
// This shouldn't have anything except static initializers (no functions). So
// QKeySequence(...).toString() is NOT ALLOWED HERE.
// This must be in alphabetical order according to action name as it must have the same order as
// UISetting::values.shortcuts, which is alphabetically ordered.
// clang-format off
2022-02-10 19:04:38 +01:00
const std::array<UISettings::Shortcut, 22> Config::default_hotkeys{{
2022-06-11 07:46:45 +02:00
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Audio Mute/Unmute")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("Ctrl+M"), QStringLiteral("Home+Dpad_Right"), Qt::WindowShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Audio Volume Down")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("-"), QStringLiteral("Home+Dpad_Down"), Qt::ApplicationShortcut}},
2022-08-13 04:14:43 +02:00
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Audio Volume Up")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("="), QStringLiteral("Home+Dpad_Up"), Qt::ApplicationShortcut}},
2022-06-11 07:46:45 +02:00
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Capture Screenshot")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("Ctrl+P"), QStringLiteral("Screenshot"), Qt::WidgetWithChildrenShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Change Adapting Filter")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("F8"), QStringLiteral("Home+L"), Qt::ApplicationShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Change Docked Mode")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("F10"), QStringLiteral("Home+X"), Qt::ApplicationShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Change GPU Accuracy")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("F9"), QStringLiteral("Home+R"), Qt::ApplicationShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Continue/Pause Emulation")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("F4"), QStringLiteral("Home+Plus"), Qt::WindowShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Exit Fullscreen")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("Esc"), QStringLiteral(""), Qt::WindowShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Exit yuzu")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("Ctrl+Q"), QStringLiteral("Home+Minus"), Qt::WindowShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Fullscreen")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("F11"), QStringLiteral("Home+B"), Qt::WindowShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Load File")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("Ctrl+O"), QStringLiteral(""), Qt::WidgetWithChildrenShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Load/Remove Amiibo")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("F2"), QStringLiteral("Home+A"), Qt::WidgetWithChildrenShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Restart Emulation")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("F6"), QStringLiteral(""), Qt::WindowShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Stop Emulation")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("F5"), QStringLiteral(""), Qt::WindowShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "TAS Record")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("Ctrl+F7"), QStringLiteral(""), Qt::ApplicationShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "TAS Reset")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("Ctrl+F6"), QStringLiteral(""), Qt::ApplicationShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "TAS Start/Stop")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("Ctrl+F5"), QStringLiteral(""), Qt::ApplicationShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Toggle Filter Bar")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("Ctrl+F"), QStringLiteral(""), Qt::WindowShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Toggle Framerate Limit")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("Ctrl+U"), QStringLiteral("Home+Y"), Qt::ApplicationShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Toggle Mouse Panning")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("Ctrl+F9"), QStringLiteral(""), Qt::ApplicationShortcut}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Toggle Status Bar")), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")), {QStringLiteral("Ctrl+S"), QStringLiteral(""), Qt::WindowShortcut}},
2020-12-28 16:15:37 +01:00
}};
// clang-format on
2021-06-03 08:01:41 +02:00
void Config::Initialize(const std::string& config_name) {
2021-05-08 09:49:31 +02:00
const auto fs_config_loc = FS::GetYuzuPath(FS::YuzuPath::ConfigDir);
2021-05-18 20:58:12 +02:00
const auto config_file = fmt::format("{}.ini", config_name);
2021-05-08 09:49:31 +02:00
2020-12-28 16:15:37 +01:00
switch (type) {
case ConfigType::GlobalConfig:
2021-05-18 20:58:12 +02:00
qt_config_loc = FS::PathToUTF8String(fs_config_loc / config_file);
2021-05-08 09:49:31 +02:00
void(FS::CreateParentDir(qt_config_loc));
2020-12-28 16:15:37 +01:00
qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc),
QSettings::IniFormat);
Reload();
break;
case ConfigType::PerGameConfig:
2021-06-03 08:01:41 +02:00
qt_config_loc =
FS::PathToUTF8String(fs_config_loc / "custom" / FS::ToU8String(config_file));
2021-05-08 09:49:31 +02:00
void(FS::CreateParentDir(qt_config_loc));
2020-12-28 16:15:37 +01:00
qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc),
QSettings::IniFormat);
Reload();
break;
case ConfigType::InputProfile:
2021-05-18 20:58:12 +02:00
qt_config_loc = FS::PathToUTF8String(fs_config_loc / "input" / config_file);
2021-05-08 09:49:31 +02:00
void(FS::CreateParentDir(qt_config_loc));
2020-12-28 16:15:37 +01:00
qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc),
QSettings::IniFormat);
break;
}
}
2021-07-03 11:00:06 +02:00
/* {Read,Write}BasicSetting and WriteGlobalSetting templates must be defined here before their
* usages later in this file. This allows explicit definition of some types that don't work
* nicely with the general version.
*/
// Explicit std::string definition: Qt can't implicitly convert a std::string to a QVariant, nor
// can it implicitly convert a QVariant back to a {std::,Q}string
template <>
2022-07-05 04:21:48 +02:00
void Config::ReadBasicSetting(Settings::Setting<std::string>& setting) {
2021-07-03 11:00:06 +02:00
const QString name = QString::fromStdString(setting.GetLabel());
2021-07-08 22:42:51 +02:00
const auto default_value = QString::fromStdString(setting.GetDefault());
2021-07-03 11:00:06 +02:00
if (qt_config->value(name + QStringLiteral("/default"), false).toBool()) {
2021-07-08 22:42:51 +02:00
setting.SetValue(default_value.toStdString());
2021-07-03 11:00:06 +02:00
} else {
2021-07-08 22:42:51 +02:00
setting.SetValue(qt_config->value(name, default_value).toString().toStdString());
2021-07-03 11:00:06 +02:00
}
}
2021-07-08 22:42:51 +02:00
2022-07-17 09:10:25 +02:00
template <typename Type, bool ranged>
void Config::ReadBasicSetting(Settings::Setting<Type, ranged>& setting) {
2021-07-03 11:00:06 +02:00
const QString name = QString::fromStdString(setting.GetLabel());
2021-07-08 22:42:51 +02:00
const Type default_value = setting.GetDefault();
2021-07-03 11:00:06 +02:00
if (qt_config->value(name + QStringLiteral("/default"), false).toBool()) {
2021-07-08 22:42:51 +02:00
setting.SetValue(default_value);
2021-07-03 11:00:06 +02:00
} else {
setting.SetValue(
2021-07-08 22:42:51 +02:00
static_cast<QVariant>(qt_config->value(name, default_value)).value<Type>());
2021-07-03 11:00:06 +02:00
}
}
// Explicit std::string definition: Qt can't implicitly convert a std::string to a QVariant
template <>
2022-07-05 04:21:48 +02:00
void Config::WriteBasicSetting(const Settings::Setting<std::string>& setting) {
2021-07-03 11:00:06 +02:00
const QString name = QString::fromStdString(setting.GetLabel());
2021-07-08 22:42:51 +02:00
const std::string& value = setting.GetValue();
qt_config->setValue(name + QStringLiteral("/default"), value == setting.GetDefault());
qt_config->setValue(name, QString::fromStdString(value));
2021-07-03 11:00:06 +02:00
}
2021-07-08 22:42:51 +02:00
2022-07-17 09:10:25 +02:00
template <typename Type, bool ranged>
void Config::WriteBasicSetting(const Settings::Setting<Type, ranged>& setting) {
2021-07-03 11:00:06 +02:00
const QString name = QString::fromStdString(setting.GetLabel());
2021-07-08 22:42:51 +02:00
const Type value = setting.GetValue();
qt_config->setValue(name + QStringLiteral("/default"), value == setting.GetDefault());
qt_config->setValue(name, value);
2021-07-03 11:00:06 +02:00
}
2022-07-17 09:10:25 +02:00
template <typename Type, bool ranged>
void Config::WriteGlobalSetting(const Settings::SwitchableSetting<Type, ranged>& setting) {
2021-07-08 22:42:51 +02:00
const QString name = QString::fromStdString(setting.GetLabel());
const Type& value = setting.GetValue(global);
2021-07-03 11:00:06 +02:00
if (!global) {
qt_config->setValue(name + QStringLiteral("/use_global"), setting.UsingGlobal());
}
if (global || !setting.UsingGlobal()) {
2021-07-08 22:42:51 +02:00
qt_config->setValue(name + QStringLiteral("/default"), value == setting.GetDefault());
qt_config->setValue(name, value);
2021-07-03 11:00:06 +02:00
}
}
2020-12-28 16:15:37 +01:00
void Config::ReadPlayerValue(std::size_t player_index) {
const QString player_prefix = [this, player_index] {
if (type == ConfigType::InputProfile) {
return QString{};
} else {
return QStringLiteral("player_%1_").arg(player_index);
}
}();
auto& player = Settings::values.players.GetValue()[player_index];
if (player_prefix.isEmpty()) {
const auto controller = static_cast<Settings::ControllerType>(
qt_config
->value(QStringLiteral("%1type").arg(player_prefix),
static_cast<u8>(Settings::ControllerType::ProController))
.toUInt());
if (controller == Settings::ControllerType::LeftJoycon ||
controller == Settings::ControllerType::RightJoycon) {
player.controller_type = controller;
}
} else {
player.connected =
ReadSetting(QStringLiteral("%1connected").arg(player_prefix), player_index == 0)
.toBool();
player.controller_type = static_cast<Settings::ControllerType>(
qt_config
->value(QStringLiteral("%1type").arg(player_prefix),
static_cast<u8>(Settings::ControllerType::ProController))
.toUInt());
player.vibration_enabled =
qt_config->value(QStringLiteral("%1vibration_enabled").arg(player_prefix), true)
.toBool();
player.vibration_strength =
qt_config->value(QStringLiteral("%1vibration_strength").arg(player_prefix), 100)
.toInt();
player.body_color_left = qt_config
->value(QStringLiteral("%1body_color_left").arg(player_prefix),
Settings::JOYCON_BODY_NEON_BLUE)
.toUInt();
player.body_color_right =
qt_config
->value(QStringLiteral("%1body_color_right").arg(player_prefix),
Settings::JOYCON_BODY_NEON_RED)
.toUInt();
player.button_color_left =
qt_config
->value(QStringLiteral("%1button_color_left").arg(player_prefix),
Settings::JOYCON_BUTTONS_NEON_BLUE)
.toUInt();
player.button_color_right =
qt_config
->value(QStringLiteral("%1button_color_right").arg(player_prefix),
Settings::JOYCON_BUTTONS_NEON_RED)
.toUInt();
}
for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) {
const std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]);
auto& player_buttons = player.buttons[i];
player_buttons = qt_config
->value(QStringLiteral("%1").arg(player_prefix) +
QString::fromUtf8(Settings::NativeButton::mapping[i]),
QString::fromStdString(default_param))
.toString()
.toStdString();
if (player_buttons.empty()) {
player_buttons = default_param;
}
}
for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) {
const std::string default_param = InputCommon::GenerateAnalogParamFromKeys(
default_analogs[i][0], default_analogs[i][1], default_analogs[i][2],
default_analogs[i][3], default_stick_mod[i], 0.5f);
auto& player_analogs = player.analogs[i];
player_analogs = qt_config
->value(QStringLiteral("%1").arg(player_prefix) +
QString::fromUtf8(Settings::NativeAnalog::mapping[i]),
QString::fromStdString(default_param))
.toString()
.toStdString();
if (player_analogs.empty()) {
player_analogs = default_param;
}
}
for (int i = 0; i < Settings::NativeMotion::NumMotions; ++i) {
const std::string default_param = InputCommon::GenerateKeyboardParam(default_motions[i]);
auto& player_motions = player.motions[i];
player_motions = qt_config
->value(QStringLiteral("%1").arg(player_prefix) +
QString::fromUtf8(Settings::NativeMotion::mapping[i]),
QString::fromStdString(default_param))
.toString()
.toStdString();
if (player_motions.empty()) {
player_motions = default_param;
}
}
}
void Config::ReadDebugValues() {
2021-07-03 11:00:06 +02:00
ReadBasicSetting(Settings::values.debug_pad_enabled);
2020-12-28 16:15:37 +01:00
for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) {
const std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]);
auto& debug_pad_buttons = Settings::values.debug_pad_buttons[i];
debug_pad_buttons = qt_config
->value(QStringLiteral("debug_pad_") +
QString::fromUtf8(Settings::NativeButton::mapping[i]),
QString::fromStdString(default_param))
.toString()
.toStdString();
if (debug_pad_buttons.empty()) {
debug_pad_buttons = default_param;
}
}
for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) {
const std::string default_param = InputCommon::GenerateAnalogParamFromKeys(
default_analogs[i][0], default_analogs[i][1], default_analogs[i][2],
default_analogs[i][3], default_stick_mod[i], 0.5f);
auto& debug_pad_analogs = Settings::values.debug_pad_analogs[i];
debug_pad_analogs = qt_config
->value(QStringLiteral("debug_pad_") +
QString::fromUtf8(Settings::NativeAnalog::mapping[i]),
QString::fromStdString(default_param))
.toString()
.toStdString();
if (debug_pad_analogs.empty()) {
debug_pad_analogs = default_param;
}
}
}
void Config::ReadKeyboardValues() {
2021-07-03 11:00:06 +02:00
ReadBasicSetting(Settings::values.keyboard_enabled);
2020-12-28 16:15:37 +01:00
}
void Config::ReadMouseValues() {
2021-07-03 11:00:06 +02:00
ReadBasicSetting(Settings::values.mouse_enabled);
2020-12-28 16:15:37 +01:00
}
void Config::ReadTouchscreenValues() {
Settings::values.touchscreen.enabled =
ReadSetting(QStringLiteral("touchscreen_enabled"), true).toBool();
Settings::values.touchscreen.rotation_angle =
ReadSetting(QStringLiteral("touchscreen_angle"), 0).toUInt();
Settings::values.touchscreen.diameter_x =
ReadSetting(QStringLiteral("touchscreen_diameter_x"), 15).toUInt();
Settings::values.touchscreen.diameter_y =
ReadSetting(QStringLiteral("touchscreen_diameter_y"), 15).toUInt();
}
2022-04-16 16:44:44 +02:00
void Config::ReadHidbusValues() {
Settings::values.enable_ring_controller =
ReadSetting(QStringLiteral("enable_ring_controller"), true).toBool();
const std::string default_param = InputCommon::GenerateAnalogParamFromKeys(
0, 0, default_ringcon_analogs[0], default_ringcon_analogs[1], 0, 0.05f);
auto& ringcon_analogs = Settings::values.ringcon_analogs;
ringcon_analogs =
qt_config->value(QStringLiteral("ring_controller"), QString::fromStdString(default_param))
.toString()
.toStdString();
if (ringcon_analogs.empty()) {
ringcon_analogs = default_param;
}
}
2022-07-25 19:06:59 +02:00
void Config::ReadIrCameraValues() {
ReadBasicSetting(Settings::values.enable_ir_sensor);
ReadBasicSetting(Settings::values.ir_sensor_device);
}
2020-12-28 16:15:37 +01:00
void Config::ReadAudioValues() {
qt_config->beginGroup(QStringLiteral("Audio"));
if (global) {
2021-07-03 11:00:06 +02:00
ReadBasicSetting(Settings::values.sink_id);
2022-07-07 09:40:51 +02:00
ReadBasicSetting(Settings::values.audio_output_device_id);
ReadBasicSetting(Settings::values.audio_input_device_id);
2020-12-28 16:15:37 +01:00
}
2021-07-03 11:00:06 +02:00
ReadGlobalSetting(Settings::values.volume);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::ReadControlValues() {
qt_config->beginGroup(QStringLiteral("Controls"));
for (std::size_t p = 0; p < Settings::values.players.GetValue().size(); ++p) {
ReadPlayerValue(p);
}
ReadDebugValues();
ReadKeyboardValues();
ReadMouseValues();
ReadTouchscreenValues();
ReadMotionTouchValues();
2022-04-16 16:44:44 +02:00
ReadHidbusValues();
2022-07-25 19:06:59 +02:00
ReadIrCameraValues();
2020-12-28 16:15:37 +01:00
2021-09-29 00:14:39 +02:00
#ifdef _WIN32
2021-09-08 07:37:31 +02:00
ReadBasicSetting(Settings::values.enable_raw_input);
2021-09-29 00:14:39 +02:00
#else
Settings::values.enable_raw_input = false;
#endif
2021-07-03 11:00:06 +02:00
ReadBasicSetting(Settings::values.emulate_analog_keyboard);
2021-02-28 05:08:39 +01:00
Settings::values.mouse_panning = false;
2021-07-03 11:00:06 +02:00
ReadBasicSetting(Settings::values.mouse_panning_sensitivity);
2020-12-28 16:15:37 +01:00
2021-07-26 03:00:19 +02:00
ReadBasicSetting(Settings::values.tas_enable);
ReadBasicSetting(Settings::values.tas_loop);
ReadBasicSetting(Settings::values.pause_tas_on_load);
2021-07-03 11:00:06 +02:00
ReadGlobalSetting(Settings::values.use_docked_mode);
2021-05-25 22:52:37 +02:00
// Disable docked mode if handheld is selected
const auto controller_type = Settings::values.players.GetValue()[0].controller_type;
if (controller_type == Settings::ControllerType::Handheld) {
Settings::values.use_docked_mode.SetValue(false);
}
2021-07-03 11:00:06 +02:00
ReadGlobalSetting(Settings::values.vibration_enabled);
ReadGlobalSetting(Settings::values.enable_accurate_vibrations);
ReadGlobalSetting(Settings::values.motion_enabled);
2020-12-28 16:15:37 +01:00
2022-01-27 03:52:17 +01:00
ReadBasicSetting(Settings::values.controller_navigation);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::ReadMotionTouchValues() {
int num_touch_from_button_maps =
qt_config->beginReadArray(QStringLiteral("touch_from_button_maps"));
if (num_touch_from_button_maps > 0) {
const auto append_touch_from_button_map = [this] {
Settings::TouchFromButtonMap map;
map.name = ReadSetting(QStringLiteral("name"), QStringLiteral("default"))
.toString()
.toStdString();
const int num_touch_maps = qt_config->beginReadArray(QStringLiteral("entries"));
map.buttons.reserve(num_touch_maps);
for (int i = 0; i < num_touch_maps; i++) {
qt_config->setArrayIndex(i);
std::string touch_mapping =
ReadSetting(QStringLiteral("bind")).toString().toStdString();
map.buttons.emplace_back(std::move(touch_mapping));
}
qt_config->endArray(); // entries
Settings::values.touch_from_button_maps.emplace_back(std::move(map));
};
for (int i = 0; i < num_touch_from_button_maps; ++i) {
qt_config->setArrayIndex(i);
append_touch_from_button_map();
}
} else {
Settings::values.touch_from_button_maps.emplace_back(
Settings::TouchFromButtonMap{"default", {}});
num_touch_from_button_maps = 1;
}
qt_config->endArray();
2021-07-03 11:00:06 +02:00
ReadBasicSetting(Settings::values.touch_device);
ReadBasicSetting(Settings::values.touch_from_button_map_index);
Settings::values.touch_from_button_map_index = std::clamp(
Settings::values.touch_from_button_map_index.GetValue(), 0, num_touch_from_button_maps - 1);
ReadBasicSetting(Settings::values.udp_input_servers);
2021-11-27 00:35:19 +01:00
ReadBasicSetting(Settings::values.enable_udp_controller);
2020-12-28 16:15:37 +01:00
}
void Config::ReadCoreValues() {
qt_config->beginGroup(QStringLiteral("Core"));
2021-07-03 11:00:06 +02:00
ReadGlobalSetting(Settings::values.use_multi_core);
2022-02-22 00:50:44 +01:00
ReadGlobalSetting(Settings::values.use_extended_memory_layout);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::ReadDataStorageValues() {
qt_config->beginGroup(QStringLiteral("Data Storage"));
2021-07-03 11:00:06 +02:00
ReadBasicSetting(Settings::values.use_virtual_sd);
2021-05-08 09:49:31 +02:00
FS::SetYuzuPath(
FS::YuzuPath::NANDDir,
qt_config
->value(QStringLiteral("nand_directory"),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::NANDDir)))
.toString()
.toStdString());
FS::SetYuzuPath(
FS::YuzuPath::SDMCDir,
qt_config
->value(QStringLiteral("sdmc_directory"),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::SDMCDir)))
.toString()
.toStdString());
FS::SetYuzuPath(
FS::YuzuPath::LoadDir,
qt_config
->value(QStringLiteral("load_directory"),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::LoadDir)))
.toString()
.toStdString());
FS::SetYuzuPath(
FS::YuzuPath::DumpDir,
qt_config
->value(QStringLiteral("dump_directory"),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir)))
.toString()
.toStdString());
2021-07-26 03:00:19 +02:00
FS::SetYuzuPath(FS::YuzuPath::TASDir,
qt_config
->value(QStringLiteral("tas_directory"),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::TASDir)))
.toString()
.toStdString());
2021-07-03 11:00:06 +02:00
ReadBasicSetting(Settings::values.gamecard_inserted);
ReadBasicSetting(Settings::values.gamecard_current_game);
ReadBasicSetting(Settings::values.gamecard_path);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::ReadDebuggingValues() {
qt_config->beginGroup(QStringLiteral("Debugging"));
// Intentionally not using the QT default setting as this is intended to be changed in the ini
Settings::values.record_frame_times =
qt_config->value(QStringLiteral("record_frame_times"), false).toBool();
2022-06-01 20:08:41 +02:00
ReadBasicSetting(Settings::values.use_gdbstub);
ReadBasicSetting(Settings::values.gdbstub_port);
2021-07-03 11:00:06 +02:00
ReadBasicSetting(Settings::values.program_args);
ReadBasicSetting(Settings::values.dump_exefs);
ReadBasicSetting(Settings::values.dump_nso);
ReadBasicSetting(Settings::values.enable_fs_access_log);
ReadBasicSetting(Settings::values.reporting_services);
ReadBasicSetting(Settings::values.quest_flag);
ReadBasicSetting(Settings::values.disable_macro_jit);
ReadBasicSetting(Settings::values.extended_logging);
ReadBasicSetting(Settings::values.use_debug_asserts);
ReadBasicSetting(Settings::values.use_auto_stub);
2021-11-28 11:31:20 +01:00
ReadBasicSetting(Settings::values.enable_all_controllers);
2022-09-05 05:41:15 +02:00
ReadBasicSetting(Settings::values.create_crash_dumps);
2022-09-19 23:35:35 +02:00
ReadBasicSetting(Settings::values.perform_vulkan_check);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::ReadServiceValues() {
qt_config->beginGroup(QStringLiteral("Services"));
2021-08-13 07:06:50 +02:00
ReadBasicSetting(Settings::values.network_interface);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::ReadDisabledAddOnValues() {
const auto size = qt_config->beginReadArray(QStringLiteral("DisabledAddOns"));
for (int i = 0; i < size; ++i) {
qt_config->setArrayIndex(i);
const auto title_id = ReadSetting(QStringLiteral("title_id"), 0).toULongLong();
std::vector<std::string> out;
const auto d_size = qt_config->beginReadArray(QStringLiteral("disabled"));
for (int j = 0; j < d_size; ++j) {
qt_config->setArrayIndex(j);
out.push_back(ReadSetting(QStringLiteral("d"), QString{}).toString().toStdString());
}
qt_config->endArray();
Settings::values.disabled_addons.insert_or_assign(title_id, out);
}
qt_config->endArray();
}
void Config::ReadMiscellaneousValues() {
qt_config->beginGroup(QStringLiteral("Miscellaneous"));
2021-07-03 11:00:06 +02:00
ReadBasicSetting(Settings::values.log_filter);
ReadBasicSetting(Settings::values.use_dev_keys);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::ReadPathValues() {
qt_config->beginGroup(QStringLiteral("Paths"));
UISettings::values.roms_path = ReadSetting(QStringLiteral("romsPath")).toString();
UISettings::values.symbols_path = ReadSetting(QStringLiteral("symbolsPath")).toString();
UISettings::values.game_dir_deprecated =
ReadSetting(QStringLiteral("gameListRootDir"), QStringLiteral(".")).toString();
UISettings::values.game_dir_deprecated_deepscan =
ReadSetting(QStringLiteral("gameListDeepScan"), false).toBool();
const int gamedirs_size = qt_config->beginReadArray(QStringLiteral("gamedirs"));
for (int i = 0; i < gamedirs_size; ++i) {
qt_config->setArrayIndex(i);
UISettings::GameDir game_dir;
game_dir.path = ReadSetting(QStringLiteral("path")).toString();
game_dir.deep_scan = ReadSetting(QStringLiteral("deep_scan"), false).toBool();
game_dir.expanded = ReadSetting(QStringLiteral("expanded"), true).toBool();
UISettings::values.game_dirs.append(game_dir);
}
qt_config->endArray();
// create NAND and SD card directories if empty, these are not removable through the UI,
// also carries over old game list settings if present
if (UISettings::values.game_dirs.isEmpty()) {
UISettings::GameDir game_dir;
game_dir.path = QStringLiteral("SDMC");
game_dir.expanded = true;
UISettings::values.game_dirs.append(game_dir);
game_dir.path = QStringLiteral("UserNAND");
UISettings::values.game_dirs.append(game_dir);
game_dir.path = QStringLiteral("SysNAND");
UISettings::values.game_dirs.append(game_dir);
if (UISettings::values.game_dir_deprecated != QStringLiteral(".")) {
game_dir.path = UISettings::values.game_dir_deprecated;
game_dir.deep_scan = UISettings::values.game_dir_deprecated_deepscan;
UISettings::values.game_dirs.append(game_dir);
}
}
UISettings::values.recent_files = ReadSetting(QStringLiteral("recentFiles")).toStringList();
UISettings::values.language = ReadSetting(QStringLiteral("language"), QString{}).toString();
qt_config->endGroup();
}
void Config::ReadCpuValues() {
qt_config->beginGroup(QStringLiteral("Cpu"));
2021-07-09 03:27:40 +02:00
ReadBasicSetting(Settings::values.cpu_accuracy_first_time);
if (Settings::values.cpu_accuracy_first_time) {
Settings::values.cpu_accuracy.SetValue(Settings::values.cpu_accuracy.GetDefault());
Settings::values.cpu_accuracy_first_time.SetValue(false);
} else {
ReadGlobalSetting(Settings::values.cpu_accuracy);
}
2021-05-17 02:21:13 +02:00
2021-07-03 11:00:06 +02:00
ReadGlobalSetting(Settings::values.cpuopt_unsafe_unfuse_fma);
ReadGlobalSetting(Settings::values.cpuopt_unsafe_reduce_fp_error);
ReadGlobalSetting(Settings::values.cpuopt_unsafe_ignore_standard_fpcr);
ReadGlobalSetting(Settings::values.cpuopt_unsafe_inaccurate_nan);
ReadGlobalSetting(Settings::values.cpuopt_unsafe_fastmem_check);
2022-02-27 23:27:57 +01:00
ReadGlobalSetting(Settings::values.cpuopt_unsafe_ignore_global_monitor);
2020-12-28 16:15:37 +01:00
2021-05-17 02:21:13 +02:00
if (global) {
2021-07-09 03:27:40 +02:00
ReadBasicSetting(Settings::values.cpu_debug_mode);
2021-07-03 11:00:06 +02:00
ReadBasicSetting(Settings::values.cpuopt_page_tables);
ReadBasicSetting(Settings::values.cpuopt_block_linking);
ReadBasicSetting(Settings::values.cpuopt_return_stack_buffer);
ReadBasicSetting(Settings::values.cpuopt_fast_dispatcher);
ReadBasicSetting(Settings::values.cpuopt_context_elimination);
ReadBasicSetting(Settings::values.cpuopt_const_prop);
ReadBasicSetting(Settings::values.cpuopt_misc_ir);
ReadBasicSetting(Settings::values.cpuopt_reduce_misalign_checks);
ReadBasicSetting(Settings::values.cpuopt_fastmem);
2022-02-27 23:27:57 +01:00
ReadBasicSetting(Settings::values.cpuopt_fastmem_exclusives);
ReadBasicSetting(Settings::values.cpuopt_recompile_exclusives);
2020-12-28 16:15:37 +01:00
}
qt_config->endGroup();
}
void Config::ReadRendererValues() {
qt_config->beginGroup(QStringLiteral("Renderer"));
2021-07-03 11:00:06 +02:00
ReadGlobalSetting(Settings::values.renderer_backend);
ReadGlobalSetting(Settings::values.vulkan_device);
ReadGlobalSetting(Settings::values.fullscreen_mode);
ReadGlobalSetting(Settings::values.aspect_ratio);
2021-10-24 06:39:01 +02:00
ReadGlobalSetting(Settings::values.resolution_setup);
ReadGlobalSetting(Settings::values.scaling_filter);
ReadGlobalSetting(Settings::values.anti_aliasing);
2021-07-03 11:00:06 +02:00
ReadGlobalSetting(Settings::values.max_anisotropy);
2021-07-27 05:04:12 +02:00
ReadGlobalSetting(Settings::values.use_speed_limit);
ReadGlobalSetting(Settings::values.speed_limit);
2021-07-03 11:00:06 +02:00
ReadGlobalSetting(Settings::values.use_disk_shader_cache);
ReadGlobalSetting(Settings::values.gpu_accuracy);
ReadGlobalSetting(Settings::values.use_asynchronous_gpu_emulation);
2021-08-12 01:07:27 +02:00
ReadGlobalSetting(Settings::values.nvdec_emulation);
2021-07-03 11:00:06 +02:00
ReadGlobalSetting(Settings::values.accelerate_astc);
ReadGlobalSetting(Settings::values.use_vsync);
2021-07-09 23:54:15 +02:00
ReadGlobalSetting(Settings::values.shader_backend);
2021-07-03 11:00:06 +02:00
ReadGlobalSetting(Settings::values.use_asynchronous_shaders);
ReadGlobalSetting(Settings::values.use_fast_gpu_time);
2022-08-27 04:27:11 +02:00
ReadGlobalSetting(Settings::values.use_pessimistic_flushes);
2021-07-03 11:00:06 +02:00
ReadGlobalSetting(Settings::values.bg_red);
ReadGlobalSetting(Settings::values.bg_green);
ReadGlobalSetting(Settings::values.bg_blue);
2020-12-28 16:15:37 +01:00
2021-07-09 17:56:08 +02:00
if (global) {
ReadBasicSetting(Settings::values.renderer_debug);
2021-07-30 21:16:07 +02:00
ReadBasicSetting(Settings::values.renderer_shader_feedback);
2021-07-09 23:54:15 +02:00
ReadBasicSetting(Settings::values.enable_nsight_aftermath);
ReadBasicSetting(Settings::values.disable_shader_loop_safety_checks);
2021-07-09 17:56:08 +02:00
}
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::ReadScreenshotValues() {
qt_config->beginGroup(QStringLiteral("Screenshots"));
UISettings::values.enable_screenshot_save_as =
ReadSetting(QStringLiteral("enable_screenshot_save_as"), true).toBool();
2021-05-08 09:49:31 +02:00
FS::SetYuzuPath(
FS::YuzuPath::ScreenshotsDir,
2020-12-28 16:15:37 +01:00
qt_config
->value(QStringLiteral("screenshot_path"),
2021-05-08 09:49:31 +02:00
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::ScreenshotsDir)))
2020-12-28 16:15:37 +01:00
.toString()
.toStdString());
qt_config->endGroup();
}
void Config::ReadShortcutValues() {
qt_config->beginGroup(QStringLiteral("Shortcuts"));
for (const auto& [name, group, shortcut] : default_hotkeys) {
qt_config->beginGroup(group);
qt_config->beginGroup(name);
// No longer using ReadSetting for shortcut.second as it innacurately returns a value of 1
// for WidgetWithChildrenShortcut which is a value of 3. Needed to fix shortcuts the open
// a file dialog in windowed mode
UISettings::values.shortcuts.push_back(
{name,
group,
2021-12-29 21:59:21 +01:00
{ReadSetting(QStringLiteral("KeySeq"), shortcut.keyseq).toString(),
ReadSetting(QStringLiteral("Controller_KeySeq"), shortcut.controller_keyseq)
.toString(),
shortcut.context}});
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
qt_config->endGroup();
}
qt_config->endGroup();
}
void Config::ReadSystemValues() {
qt_config->beginGroup(QStringLiteral("System"));
2021-07-03 11:00:06 +02:00
ReadGlobalSetting(Settings::values.language_index);
2020-12-28 16:15:37 +01:00
2021-07-03 11:00:06 +02:00
ReadGlobalSetting(Settings::values.region_index);
2020-12-28 16:15:37 +01:00
2021-07-03 11:00:06 +02:00
ReadGlobalSetting(Settings::values.time_zone_index);
2020-12-28 16:15:37 +01:00
bool rng_seed_enabled;
ReadSettingGlobal(rng_seed_enabled, QStringLiteral("rng_seed_enabled"), false);
bool rng_seed_global =
global || qt_config->value(QStringLiteral("rng_seed/use_global"), true).toBool();
Settings::values.rng_seed.SetGlobal(rng_seed_global);
if (global || !rng_seed_global) {
if (rng_seed_enabled) {
2021-04-30 07:43:04 +02:00
Settings::values.rng_seed.SetValue(ReadSetting(QStringLiteral("rng_seed"), 0).toUInt());
2020-12-28 16:15:37 +01:00
} else {
Settings::values.rng_seed.SetValue(std::nullopt);
}
}
2021-05-17 02:21:13 +02:00
if (global) {
2021-08-03 07:02:43 +02:00
ReadBasicSetting(Settings::values.current_user);
Settings::values.current_user = std::clamp<int>(Settings::values.current_user.GetValue(), 0,
Service::Account::MAX_USERS - 1);
2021-05-17 02:21:13 +02:00
const auto custom_rtc_enabled =
ReadSetting(QStringLiteral("custom_rtc_enabled"), false).toBool();
2020-12-28 16:15:37 +01:00
if (custom_rtc_enabled) {
2021-10-17 08:30:38 +02:00
Settings::values.custom_rtc = ReadSetting(QStringLiteral("custom_rtc"), 0).toLongLong();
2020-12-28 16:15:37 +01:00
} else {
2021-05-17 02:21:13 +02:00
Settings::values.custom_rtc = std::nullopt;
2020-12-28 16:15:37 +01:00
}
}
2021-07-03 11:00:06 +02:00
ReadGlobalSetting(Settings::values.sound_index);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::ReadUIValues() {
qt_config->beginGroup(QStringLiteral("UI"));
UISettings::values.theme =
2022-01-17 11:19:28 +01:00
ReadSetting(
QStringLiteral("theme"),
2022-01-21 22:04:04 +01:00
QString::fromUtf8(UISettings::themes[static_cast<size_t>(default_theme)].second))
2020-12-28 16:15:37 +01:00
.toString();
2021-07-03 11:00:06 +02:00
ReadBasicSetting(UISettings::values.enable_discord_presence);
ReadBasicSetting(UISettings::values.select_user_on_boot);
2020-12-28 16:15:37 +01:00
ReadUIGamelistValues();
ReadUILayoutValues();
ReadPathValues();
ReadScreenshotValues();
ReadShortcutValues();
2022-07-26 03:25:01 +02:00
ReadMultiplayerValues();
2020-12-28 16:15:37 +01:00
2021-07-03 11:00:06 +02:00
ReadBasicSetting(UISettings::values.single_window_mode);
ReadBasicSetting(UISettings::values.fullscreen);
ReadBasicSetting(UISettings::values.display_titlebar);
ReadBasicSetting(UISettings::values.show_filter_bar);
ReadBasicSetting(UISettings::values.show_status_bar);
ReadBasicSetting(UISettings::values.confirm_before_closing);
ReadBasicSetting(UISettings::values.first_start);
ReadBasicSetting(UISettings::values.callout_flags);
ReadBasicSetting(UISettings::values.show_console);
ReadBasicSetting(UISettings::values.pause_when_in_background);
2022-02-10 19:04:38 +01:00
ReadBasicSetting(UISettings::values.mute_when_in_background);
2021-07-03 11:00:06 +02:00
ReadBasicSetting(UISettings::values.hide_mouse);
2022-03-24 10:07:14 +01:00
ReadBasicSetting(UISettings::values.disable_web_applet);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::ReadUIGamelistValues() {
qt_config->beginGroup(QStringLiteral("UIGameList"));
2021-07-03 11:00:06 +02:00
ReadBasicSetting(UISettings::values.show_add_ons);
2022-10-21 00:06:22 +02:00
ReadBasicSetting(UISettings::values.show_compat);
2021-08-01 14:23:27 +02:00
ReadBasicSetting(UISettings::values.game_icon_size);
ReadBasicSetting(UISettings::values.folder_icon_size);
2021-07-03 11:00:06 +02:00
ReadBasicSetting(UISettings::values.row_1_text_id);
ReadBasicSetting(UISettings::values.row_2_text_id);
ReadBasicSetting(UISettings::values.cache_game_list);
2021-12-18 02:10:41 +01:00
ReadBasicSetting(UISettings::values.favorites_expanded);
2021-04-15 00:16:40 +02:00
const int favorites_size = qt_config->beginReadArray(QStringLiteral("favorites"));
for (int i = 0; i < favorites_size; i++) {
qt_config->setArrayIndex(i);
UISettings::values.favorited_ids.append(
ReadSetting(QStringLiteral("program_id")).toULongLong());
}
qt_config->endArray();
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::ReadUILayoutValues() {
qt_config->beginGroup(QStringLiteral("UILayout"));
UISettings::values.geometry = ReadSetting(QStringLiteral("geometry")).toByteArray();
UISettings::values.state = ReadSetting(QStringLiteral("state")).toByteArray();
UISettings::values.renderwindow_geometry =
ReadSetting(QStringLiteral("geometryRenderWindow")).toByteArray();
UISettings::values.gamelist_header_state =
ReadSetting(QStringLiteral("gameListHeaderState")).toByteArray();
UISettings::values.microprofile_geometry =
ReadSetting(QStringLiteral("microProfileDialogGeometry")).toByteArray();
2021-07-03 11:00:06 +02:00
ReadBasicSetting(UISettings::values.microprofile_visible);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::ReadWebServiceValues() {
qt_config->beginGroup(QStringLiteral("WebService"));
2021-07-03 11:00:06 +02:00
ReadBasicSetting(Settings::values.enable_telemetry);
ReadBasicSetting(Settings::values.web_api_url);
ReadBasicSetting(Settings::values.yuzu_username);
ReadBasicSetting(Settings::values.yuzu_token);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
2022-07-26 03:25:01 +02:00
void Config::ReadMultiplayerValues() {
qt_config->beginGroup(QStringLiteral("Multiplayer"));
ReadBasicSetting(UISettings::values.multiplayer_nickname);
ReadBasicSetting(UISettings::values.multiplayer_ip);
ReadBasicSetting(UISettings::values.multiplayer_port);
ReadBasicSetting(UISettings::values.multiplayer_room_nickname);
ReadBasicSetting(UISettings::values.multiplayer_room_name);
ReadBasicSetting(UISettings::values.multiplayer_room_port);
ReadBasicSetting(UISettings::values.multiplayer_host_type);
ReadBasicSetting(UISettings::values.multiplayer_port);
ReadBasicSetting(UISettings::values.multiplayer_max_player);
ReadBasicSetting(UISettings::values.multiplayer_game_id);
ReadBasicSetting(UISettings::values.multiplayer_room_description);
// Read ban list back
int size = qt_config->beginReadArray(QStringLiteral("username_ban_list"));
UISettings::values.multiplayer_ban_list.first.resize(size);
for (int i = 0; i < size; ++i) {
qt_config->setArrayIndex(i);
UISettings::values.multiplayer_ban_list.first[i] =
ReadSetting(QStringLiteral("username")).toString().toStdString();
}
qt_config->endArray();
size = qt_config->beginReadArray(QStringLiteral("ip_ban_list"));
UISettings::values.multiplayer_ban_list.second.resize(size);
for (int i = 0; i < size; ++i) {
qt_config->setArrayIndex(i);
UISettings::values.multiplayer_ban_list.second[i] =
ReadSetting(QStringLiteral("ip")).toString().toStdString();
}
qt_config->endArray();
qt_config->endGroup();
}
2020-12-28 16:15:37 +01:00
void Config::ReadValues() {
if (global) {
ReadControlValues();
ReadDataStorageValues();
ReadDebuggingValues();
ReadDisabledAddOnValues();
ReadServiceValues();
ReadUIValues();
ReadWebServiceValues();
ReadMiscellaneousValues();
}
ReadCoreValues();
ReadCpuValues();
ReadRendererValues();
ReadAudioValues();
ReadSystemValues();
2022-07-26 03:25:01 +02:00
ReadMultiplayerValues();
2020-12-28 16:15:37 +01:00
}
void Config::SavePlayerValue(std::size_t player_index) {
const QString player_prefix = [this, player_index] {
if (type == ConfigType::InputProfile) {
return QString{};
} else {
return QStringLiteral("player_%1_").arg(player_index);
}
}();
const auto& player = Settings::values.players.GetValue()[player_index];
WriteSetting(QStringLiteral("%1type").arg(player_prefix),
static_cast<u8>(player.controller_type),
static_cast<u8>(Settings::ControllerType::ProController));
if (!player_prefix.isEmpty()) {
2021-01-20 07:48:03 +01:00
WriteSetting(QStringLiteral("%1connected").arg(player_prefix), player.connected,
player_index == 0);
2020-12-28 16:15:37 +01:00
WriteSetting(QStringLiteral("%1vibration_enabled").arg(player_prefix),
player.vibration_enabled, true);
WriteSetting(QStringLiteral("%1vibration_strength").arg(player_prefix),
player.vibration_strength, 100);
WriteSetting(QStringLiteral("%1body_color_left").arg(player_prefix), player.body_color_left,
Settings::JOYCON_BODY_NEON_BLUE);
WriteSetting(QStringLiteral("%1body_color_right").arg(player_prefix),
player.body_color_right, Settings::JOYCON_BODY_NEON_RED);
WriteSetting(QStringLiteral("%1button_color_left").arg(player_prefix),
player.button_color_left, Settings::JOYCON_BUTTONS_NEON_BLUE);
WriteSetting(QStringLiteral("%1button_color_right").arg(player_prefix),
player.button_color_right, Settings::JOYCON_BUTTONS_NEON_RED);
}
for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) {
const std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]);
WriteSetting(QStringLiteral("%1").arg(player_prefix) +
QString::fromStdString(Settings::NativeButton::mapping[i]),
QString::fromStdString(player.buttons[i]),
QString::fromStdString(default_param));
}
for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) {
const std::string default_param = InputCommon::GenerateAnalogParamFromKeys(
default_analogs[i][0], default_analogs[i][1], default_analogs[i][2],
default_analogs[i][3], default_stick_mod[i], 0.5f);
WriteSetting(QStringLiteral("%1").arg(player_prefix) +
QString::fromStdString(Settings::NativeAnalog::mapping[i]),
QString::fromStdString(player.analogs[i]),
QString::fromStdString(default_param));
}
for (int i = 0; i < Settings::NativeMotion::NumMotions; ++i) {
const std::string default_param = InputCommon::GenerateKeyboardParam(default_motions[i]);
WriteSetting(QStringLiteral("%1").arg(player_prefix) +
QString::fromStdString(Settings::NativeMotion::mapping[i]),
QString::fromStdString(player.motions[i]),
QString::fromStdString(default_param));
}
}
void Config::SaveDebugValues() {
2021-07-03 11:00:06 +02:00
WriteBasicSetting(Settings::values.debug_pad_enabled);
2020-12-28 16:15:37 +01:00
for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) {
const std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]);
WriteSetting(QStringLiteral("debug_pad_") +
QString::fromStdString(Settings::NativeButton::mapping[i]),
QString::fromStdString(Settings::values.debug_pad_buttons[i]),
QString::fromStdString(default_param));
}
for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) {
const std::string default_param = InputCommon::GenerateAnalogParamFromKeys(
default_analogs[i][0], default_analogs[i][1], default_analogs[i][2],
default_analogs[i][3], default_stick_mod[i], 0.5f);
WriteSetting(QStringLiteral("debug_pad_") +
QString::fromStdString(Settings::NativeAnalog::mapping[i]),
QString::fromStdString(Settings::values.debug_pad_analogs[i]),
QString::fromStdString(default_param));
}
}
void Config::SaveMouseValues() {
2021-07-03 11:00:06 +02:00
WriteBasicSetting(Settings::values.mouse_enabled);
2020-12-28 16:15:37 +01:00
}
void Config::SaveTouchscreenValues() {
const auto& touchscreen = Settings::values.touchscreen;
WriteSetting(QStringLiteral("touchscreen_enabled"), touchscreen.enabled, true);
WriteSetting(QStringLiteral("touchscreen_angle"), touchscreen.rotation_angle, 0);
WriteSetting(QStringLiteral("touchscreen_diameter_x"), touchscreen.diameter_x, 15);
WriteSetting(QStringLiteral("touchscreen_diameter_y"), touchscreen.diameter_y, 15);
}
void Config::SaveMotionTouchValues() {
2021-07-03 11:00:06 +02:00
WriteBasicSetting(Settings::values.touch_device);
WriteBasicSetting(Settings::values.touch_from_button_map_index);
WriteBasicSetting(Settings::values.udp_input_servers);
2021-11-27 00:35:19 +01:00
WriteBasicSetting(Settings::values.enable_udp_controller);
2020-12-28 16:15:37 +01:00
qt_config->beginWriteArray(QStringLiteral("touch_from_button_maps"));
for (std::size_t p = 0; p < Settings::values.touch_from_button_maps.size(); ++p) {
qt_config->setArrayIndex(static_cast<int>(p));
WriteSetting(QStringLiteral("name"),
QString::fromStdString(Settings::values.touch_from_button_maps[p].name),
QStringLiteral("default"));
qt_config->beginWriteArray(QStringLiteral("entries"));
for (std::size_t q = 0; q < Settings::values.touch_from_button_maps[p].buttons.size();
++q) {
qt_config->setArrayIndex(static_cast<int>(q));
WriteSetting(
QStringLiteral("bind"),
QString::fromStdString(Settings::values.touch_from_button_maps[p].buttons[q]));
}
qt_config->endArray();
}
qt_config->endArray();
}
2022-04-16 16:44:44 +02:00
void Config::SaveHidbusValues() {
WriteBasicSetting(Settings::values.enable_ring_controller);
const std::string default_param = InputCommon::GenerateAnalogParamFromKeys(
0, 0, default_ringcon_analogs[0], default_ringcon_analogs[1], 0, 0.05f);
WriteSetting(QStringLiteral("ring_controller"),
QString::fromStdString(Settings::values.ringcon_analogs),
QString::fromStdString(default_param));
}
2022-07-25 19:06:59 +02:00
void Config::SaveIrCameraValues() {
WriteBasicSetting(Settings::values.enable_ir_sensor);
WriteBasicSetting(Settings::values.ir_sensor_device);
}
2020-12-28 16:15:37 +01:00
void Config::SaveValues() {
if (global) {
SaveControlValues();
SaveDataStorageValues();
SaveDebuggingValues();
SaveDisabledAddOnValues();
2021-08-13 07:06:50 +02:00
SaveNetworkValues();
2020-12-28 16:15:37 +01:00
SaveUIValues();
SaveWebServiceValues();
SaveMiscellaneousValues();
}
SaveCoreValues();
SaveCpuValues();
SaveRendererValues();
SaveAudioValues();
SaveSystemValues();
2022-07-26 03:25:01 +02:00
SaveMultiplayerValues();
2020-12-28 16:15:37 +01:00
}
void Config::SaveAudioValues() {
qt_config->beginGroup(QStringLiteral("Audio"));
if (global) {
2021-07-03 11:00:06 +02:00
WriteBasicSetting(Settings::values.sink_id);
2022-07-07 09:40:51 +02:00
WriteBasicSetting(Settings::values.audio_output_device_id);
WriteBasicSetting(Settings::values.audio_input_device_id);
2020-12-28 16:15:37 +01:00
}
2021-07-03 11:00:06 +02:00
WriteGlobalSetting(Settings::values.volume);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::SaveControlValues() {
qt_config->beginGroup(QStringLiteral("Controls"));
for (std::size_t p = 0; p < Settings::values.players.GetValue().size(); ++p) {
SavePlayerValue(p);
}
SaveDebugValues();
SaveMouseValues();
SaveTouchscreenValues();
SaveMotionTouchValues();
2022-04-16 16:44:44 +02:00
SaveHidbusValues();
2022-07-25 19:06:59 +02:00
SaveIrCameraValues();
2020-12-28 16:15:37 +01:00
2021-07-03 11:00:06 +02:00
WriteGlobalSetting(Settings::values.use_docked_mode);
WriteGlobalSetting(Settings::values.vibration_enabled);
WriteGlobalSetting(Settings::values.enable_accurate_vibrations);
WriteGlobalSetting(Settings::values.motion_enabled);
2021-09-08 07:37:31 +02:00
WriteBasicSetting(Settings::values.enable_raw_input);
2021-07-03 11:00:06 +02:00
WriteBasicSetting(Settings::values.keyboard_enabled);
WriteBasicSetting(Settings::values.emulate_analog_keyboard);
WriteBasicSetting(Settings::values.mouse_panning_sensitivity);
2022-01-27 03:52:17 +01:00
WriteBasicSetting(Settings::values.controller_navigation);
2021-07-03 11:00:06 +02:00
2021-07-26 03:00:19 +02:00
WriteBasicSetting(Settings::values.tas_enable);
WriteBasicSetting(Settings::values.tas_loop);
WriteBasicSetting(Settings::values.pause_tas_on_load);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::SaveCoreValues() {
qt_config->beginGroup(QStringLiteral("Core"));
2021-07-03 11:00:06 +02:00
WriteGlobalSetting(Settings::values.use_multi_core);
2022-02-22 00:50:44 +01:00
WriteGlobalSetting(Settings::values.use_extended_memory_layout);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::SaveDataStorageValues() {
qt_config->beginGroup(QStringLiteral("Data Storage"));
2021-07-03 11:00:06 +02:00
WriteBasicSetting(Settings::values.use_virtual_sd);
2020-12-28 16:15:37 +01:00
WriteSetting(QStringLiteral("nand_directory"),
2021-05-08 09:49:31 +02:00
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::NANDDir)),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::NANDDir)));
2020-12-28 16:15:37 +01:00
WriteSetting(QStringLiteral("sdmc_directory"),
2021-05-08 09:49:31 +02:00
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::SDMCDir)),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::SDMCDir)));
2020-12-28 16:15:37 +01:00
WriteSetting(QStringLiteral("load_directory"),
2021-05-08 09:49:31 +02:00
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::LoadDir)),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::LoadDir)));
2020-12-28 16:15:37 +01:00
WriteSetting(QStringLiteral("dump_directory"),
2021-05-08 09:49:31 +02:00
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir)),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir)));
2021-07-26 03:00:19 +02:00
WriteSetting(QStringLiteral("tas_directory"),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::TASDir)),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::TASDir)));
2021-07-03 11:00:06 +02:00
WriteBasicSetting(Settings::values.gamecard_inserted);
WriteBasicSetting(Settings::values.gamecard_current_game);
WriteBasicSetting(Settings::values.gamecard_path);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::SaveDebuggingValues() {
qt_config->beginGroup(QStringLiteral("Debugging"));
// Intentionally not using the QT default setting as this is intended to be changed in the ini
qt_config->setValue(QStringLiteral("record_frame_times"), Settings::values.record_frame_times);
2022-06-01 20:08:41 +02:00
WriteBasicSetting(Settings::values.use_gdbstub);
WriteBasicSetting(Settings::values.gdbstub_port);
2021-07-03 11:00:06 +02:00
WriteBasicSetting(Settings::values.program_args);
WriteBasicSetting(Settings::values.dump_exefs);
WriteBasicSetting(Settings::values.dump_nso);
WriteBasicSetting(Settings::values.enable_fs_access_log);
WriteBasicSetting(Settings::values.quest_flag);
WriteBasicSetting(Settings::values.use_debug_asserts);
WriteBasicSetting(Settings::values.disable_macro_jit);
2021-11-28 11:31:20 +01:00
WriteBasicSetting(Settings::values.enable_all_controllers);
2022-09-05 05:41:15 +02:00
WriteBasicSetting(Settings::values.create_crash_dumps);
2022-09-19 23:35:35 +02:00
WriteBasicSetting(Settings::values.perform_vulkan_check);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
2021-08-13 07:06:50 +02:00
void Config::SaveNetworkValues() {
2020-12-28 16:15:37 +01:00
qt_config->beginGroup(QStringLiteral("Services"));
2021-07-03 11:00:06 +02:00
2021-08-13 07:06:50 +02:00
WriteBasicSetting(Settings::values.network_interface);
2021-07-03 11:00:06 +02:00
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::SaveDisabledAddOnValues() {
qt_config->beginWriteArray(QStringLiteral("DisabledAddOns"));
int i = 0;
for (const auto& elem : Settings::values.disabled_addons) {
qt_config->setArrayIndex(i);
WriteSetting(QStringLiteral("title_id"), QVariant::fromValue<u64>(elem.first), 0);
qt_config->beginWriteArray(QStringLiteral("disabled"));
for (std::size_t j = 0; j < elem.second.size(); ++j) {
qt_config->setArrayIndex(static_cast<int>(j));
WriteSetting(QStringLiteral("d"), QString::fromStdString(elem.second[j]), QString{});
}
qt_config->endArray();
++i;
}
qt_config->endArray();
}
void Config::SaveMiscellaneousValues() {
qt_config->beginGroup(QStringLiteral("Miscellaneous"));
2021-07-03 11:00:06 +02:00
WriteBasicSetting(Settings::values.log_filter);
WriteBasicSetting(Settings::values.use_dev_keys);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::SavePathValues() {
qt_config->beginGroup(QStringLiteral("Paths"));
WriteSetting(QStringLiteral("romsPath"), UISettings::values.roms_path);
WriteSetting(QStringLiteral("symbolsPath"), UISettings::values.symbols_path);
qt_config->beginWriteArray(QStringLiteral("gamedirs"));
for (int i = 0; i < UISettings::values.game_dirs.size(); ++i) {
qt_config->setArrayIndex(i);
const auto& game_dir = UISettings::values.game_dirs[i];
WriteSetting(QStringLiteral("path"), game_dir.path);
WriteSetting(QStringLiteral("deep_scan"), game_dir.deep_scan, false);
WriteSetting(QStringLiteral("expanded"), game_dir.expanded, true);
}
qt_config->endArray();
WriteSetting(QStringLiteral("recentFiles"), UISettings::values.recent_files);
WriteSetting(QStringLiteral("language"), UISettings::values.language, QString{});
qt_config->endGroup();
}
void Config::SaveCpuValues() {
qt_config->beginGroup(QStringLiteral("Cpu"));
2021-07-09 03:27:40 +02:00
WriteBasicSetting(Settings::values.cpu_accuracy_first_time);
2021-07-03 11:00:06 +02:00
WriteSetting(QStringLiteral("cpu_accuracy"),
static_cast<u32>(Settings::values.cpu_accuracy.GetValue(global)),
static_cast<u32>(Settings::values.cpu_accuracy.GetDefault()),
Settings::values.cpu_accuracy.UsingGlobal());
WriteGlobalSetting(Settings::values.cpuopt_unsafe_unfuse_fma);
WriteGlobalSetting(Settings::values.cpuopt_unsafe_reduce_fp_error);
WriteGlobalSetting(Settings::values.cpuopt_unsafe_ignore_standard_fpcr);
WriteGlobalSetting(Settings::values.cpuopt_unsafe_inaccurate_nan);
WriteGlobalSetting(Settings::values.cpuopt_unsafe_fastmem_check);
2022-02-27 23:27:57 +01:00
WriteGlobalSetting(Settings::values.cpuopt_unsafe_ignore_global_monitor);
2021-05-17 02:21:13 +02:00
if (global) {
2021-07-09 03:27:40 +02:00
WriteBasicSetting(Settings::values.cpu_debug_mode);
2021-07-03 11:00:06 +02:00
WriteBasicSetting(Settings::values.cpuopt_page_tables);
WriteBasicSetting(Settings::values.cpuopt_block_linking);
WriteBasicSetting(Settings::values.cpuopt_return_stack_buffer);
WriteBasicSetting(Settings::values.cpuopt_fast_dispatcher);
WriteBasicSetting(Settings::values.cpuopt_context_elimination);
WriteBasicSetting(Settings::values.cpuopt_const_prop);
WriteBasicSetting(Settings::values.cpuopt_misc_ir);
WriteBasicSetting(Settings::values.cpuopt_reduce_misalign_checks);
WriteBasicSetting(Settings::values.cpuopt_fastmem);
2022-03-13 10:13:48 +01:00
WriteBasicSetting(Settings::values.cpuopt_fastmem_exclusives);
WriteBasicSetting(Settings::values.cpuopt_recompile_exclusives);
2020-12-28 16:15:37 +01:00
}
qt_config->endGroup();
}
void Config::SaveRendererValues() {
qt_config->beginGroup(QStringLiteral("Renderer"));
2021-07-03 11:00:06 +02:00
WriteSetting(QString::fromStdString(Settings::values.renderer_backend.GetLabel()),
static_cast<u32>(Settings::values.renderer_backend.GetValue(global)),
static_cast<u32>(Settings::values.renderer_backend.GetDefault()),
Settings::values.renderer_backend.UsingGlobal());
WriteGlobalSetting(Settings::values.vulkan_device);
2021-07-28 21:57:36 +02:00
WriteSetting(QString::fromStdString(Settings::values.fullscreen_mode.GetLabel()),
static_cast<u32>(Settings::values.fullscreen_mode.GetValue(global)),
static_cast<u32>(Settings::values.fullscreen_mode.GetDefault()),
Settings::values.fullscreen_mode.UsingGlobal());
2021-07-03 11:00:06 +02:00
WriteGlobalSetting(Settings::values.aspect_ratio);
2021-10-24 06:39:01 +02:00
WriteSetting(QString::fromStdString(Settings::values.resolution_setup.GetLabel()),
static_cast<u32>(Settings::values.resolution_setup.GetValue(global)),
static_cast<u32>(Settings::values.resolution_setup.GetDefault()),
Settings::values.resolution_setup.UsingGlobal());
WriteSetting(QString::fromStdString(Settings::values.scaling_filter.GetLabel()),
static_cast<u32>(Settings::values.scaling_filter.GetValue(global)),
static_cast<u32>(Settings::values.scaling_filter.GetDefault()),
Settings::values.scaling_filter.UsingGlobal());
WriteSetting(QString::fromStdString(Settings::values.anti_aliasing.GetLabel()),
static_cast<u32>(Settings::values.anti_aliasing.GetValue(global)),
static_cast<u32>(Settings::values.anti_aliasing.GetDefault()),
Settings::values.anti_aliasing.UsingGlobal());
2021-07-03 11:00:06 +02:00
WriteGlobalSetting(Settings::values.max_anisotropy);
2021-07-27 05:04:12 +02:00
WriteGlobalSetting(Settings::values.use_speed_limit);
WriteGlobalSetting(Settings::values.speed_limit);
2021-07-03 11:00:06 +02:00
WriteGlobalSetting(Settings::values.use_disk_shader_cache);
WriteSetting(QString::fromStdString(Settings::values.gpu_accuracy.GetLabel()),
static_cast<u32>(Settings::values.gpu_accuracy.GetValue(global)),
static_cast<u32>(Settings::values.gpu_accuracy.GetDefault()),
Settings::values.gpu_accuracy.UsingGlobal());
WriteGlobalSetting(Settings::values.use_asynchronous_gpu_emulation);
2021-08-12 01:07:27 +02:00
WriteSetting(QString::fromStdString(Settings::values.nvdec_emulation.GetLabel()),
static_cast<u32>(Settings::values.nvdec_emulation.GetValue(global)),
static_cast<u32>(Settings::values.nvdec_emulation.GetDefault()),
Settings::values.nvdec_emulation.UsingGlobal());
2021-07-03 11:00:06 +02:00
WriteGlobalSetting(Settings::values.accelerate_astc);
WriteGlobalSetting(Settings::values.use_vsync);
2021-07-09 23:54:15 +02:00
WriteSetting(QString::fromStdString(Settings::values.shader_backend.GetLabel()),
static_cast<u32>(Settings::values.shader_backend.GetValue(global)),
static_cast<u32>(Settings::values.shader_backend.GetDefault()),
Settings::values.shader_backend.UsingGlobal());
2021-07-03 11:00:06 +02:00
WriteGlobalSetting(Settings::values.use_asynchronous_shaders);
WriteGlobalSetting(Settings::values.use_fast_gpu_time);
2022-08-27 04:27:11 +02:00
WriteGlobalSetting(Settings::values.use_pessimistic_flushes);
2021-07-03 11:00:06 +02:00
WriteGlobalSetting(Settings::values.bg_red);
WriteGlobalSetting(Settings::values.bg_green);
WriteGlobalSetting(Settings::values.bg_blue);
2020-12-28 16:15:37 +01:00
2021-07-09 17:56:08 +02:00
if (global) {
WriteBasicSetting(Settings::values.renderer_debug);
2021-07-30 21:16:07 +02:00
WriteBasicSetting(Settings::values.renderer_shader_feedback);
2021-07-09 23:54:15 +02:00
WriteBasicSetting(Settings::values.enable_nsight_aftermath);
WriteBasicSetting(Settings::values.disable_shader_loop_safety_checks);
2021-07-09 17:56:08 +02:00
}
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::SaveScreenshotValues() {
qt_config->beginGroup(QStringLiteral("Screenshots"));
2021-07-03 11:00:06 +02:00
WriteBasicSetting(UISettings::values.enable_screenshot_save_as);
2020-12-28 16:15:37 +01:00
WriteSetting(QStringLiteral("screenshot_path"),
2021-05-08 09:49:31 +02:00
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::ScreenshotsDir)));
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::SaveShortcutValues() {
qt_config->beginGroup(QStringLiteral("Shortcuts"));
// Lengths of UISettings::values.shortcuts & default_hotkeys are same.
// However, their ordering must also be the same.
for (std::size_t i = 0; i < default_hotkeys.size(); i++) {
const auto& [name, group, shortcut] = UISettings::values.shortcuts[i];
const auto& default_hotkey = default_hotkeys[i].shortcut;
qt_config->beginGroup(group);
qt_config->beginGroup(name);
2021-12-29 21:59:21 +01:00
WriteSetting(QStringLiteral("KeySeq"), shortcut.keyseq, default_hotkey.keyseq);
WriteSetting(QStringLiteral("Controller_KeySeq"), shortcut.controller_keyseq,
default_hotkey.controller_keyseq);
WriteSetting(QStringLiteral("Context"), shortcut.context, default_hotkey.context);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
qt_config->endGroup();
}
qt_config->endGroup();
}
void Config::SaveSystemValues() {
qt_config->beginGroup(QStringLiteral("System"));
2021-07-03 11:00:06 +02:00
WriteGlobalSetting(Settings::values.language_index);
WriteGlobalSetting(Settings::values.region_index);
WriteGlobalSetting(Settings::values.time_zone_index);
2020-12-28 16:15:37 +01:00
2021-07-03 11:00:06 +02:00
WriteSetting(QStringLiteral("rng_seed_enabled"),
Settings::values.rng_seed.GetValue(global).has_value(), false,
Settings::values.rng_seed.UsingGlobal());
WriteSetting(QStringLiteral("rng_seed"), Settings::values.rng_seed.GetValue(global).value_or(0),
0, Settings::values.rng_seed.UsingGlobal());
2020-12-28 16:15:37 +01:00
2021-05-17 02:21:13 +02:00
if (global) {
2021-08-03 07:02:43 +02:00
WriteBasicSetting(Settings::values.current_user);
2021-05-17 02:21:13 +02:00
WriteSetting(QStringLiteral("custom_rtc_enabled"), Settings::values.custom_rtc.has_value(),
false);
WriteSetting(QStringLiteral("custom_rtc"),
2021-10-17 08:30:38 +02:00
QVariant::fromValue<long long>(Settings::values.custom_rtc.value_or(0)), 0);
2021-05-17 02:21:13 +02:00
}
2020-12-28 16:15:37 +01:00
2021-07-03 11:00:06 +02:00
WriteGlobalSetting(Settings::values.sound_index);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::SaveUIValues() {
qt_config->beginGroup(QStringLiteral("UI"));
2022-01-21 22:04:04 +01:00
WriteSetting(QStringLiteral("theme"), UISettings::values.theme,
QString::fromUtf8(UISettings::themes[static_cast<size_t>(default_theme)].second));
2021-07-03 11:00:06 +02:00
WriteBasicSetting(UISettings::values.enable_discord_presence);
WriteBasicSetting(UISettings::values.select_user_on_boot);
2020-12-28 16:15:37 +01:00
SaveUIGamelistValues();
SaveUILayoutValues();
SavePathValues();
SaveScreenshotValues();
SaveShortcutValues();
2022-07-26 03:25:01 +02:00
SaveMultiplayerValues();
2020-12-28 16:15:37 +01:00
2021-07-03 11:00:06 +02:00
WriteBasicSetting(UISettings::values.single_window_mode);
WriteBasicSetting(UISettings::values.fullscreen);
WriteBasicSetting(UISettings::values.display_titlebar);
WriteBasicSetting(UISettings::values.show_filter_bar);
WriteBasicSetting(UISettings::values.show_status_bar);
WriteBasicSetting(UISettings::values.confirm_before_closing);
WriteBasicSetting(UISettings::values.first_start);
WriteBasicSetting(UISettings::values.callout_flags);
WriteBasicSetting(UISettings::values.show_console);
WriteBasicSetting(UISettings::values.pause_when_in_background);
2022-02-10 19:04:38 +01:00
WriteBasicSetting(UISettings::values.mute_when_in_background);
2021-07-03 11:00:06 +02:00
WriteBasicSetting(UISettings::values.hide_mouse);
2022-03-24 10:07:14 +01:00
WriteBasicSetting(UISettings::values.disable_web_applet);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::SaveUIGamelistValues() {
qt_config->beginGroup(QStringLiteral("UIGameList"));
2021-07-03 11:00:06 +02:00
WriteBasicSetting(UISettings::values.show_add_ons);
2022-10-21 00:06:22 +02:00
WriteBasicSetting(UISettings::values.show_compat);
2021-08-01 14:23:27 +02:00
WriteBasicSetting(UISettings::values.game_icon_size);
WriteBasicSetting(UISettings::values.folder_icon_size);
2021-07-03 11:00:06 +02:00
WriteBasicSetting(UISettings::values.row_1_text_id);
WriteBasicSetting(UISettings::values.row_2_text_id);
WriteBasicSetting(UISettings::values.cache_game_list);
2021-12-18 02:10:41 +01:00
WriteBasicSetting(UISettings::values.favorites_expanded);
2021-04-15 00:16:40 +02:00
qt_config->beginWriteArray(QStringLiteral("favorites"));
for (int i = 0; i < UISettings::values.favorited_ids.size(); i++) {
qt_config->setArrayIndex(i);
WriteSetting(QStringLiteral("program_id"),
QVariant::fromValue(UISettings::values.favorited_ids[i]));
}
qt_config->endArray();
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::SaveUILayoutValues() {
qt_config->beginGroup(QStringLiteral("UILayout"));
WriteSetting(QStringLiteral("geometry"), UISettings::values.geometry);
WriteSetting(QStringLiteral("state"), UISettings::values.state);
WriteSetting(QStringLiteral("geometryRenderWindow"), UISettings::values.renderwindow_geometry);
WriteSetting(QStringLiteral("gameListHeaderState"), UISettings::values.gamelist_header_state);
WriteSetting(QStringLiteral("microProfileDialogGeometry"),
UISettings::values.microprofile_geometry);
2021-07-03 11:00:06 +02:00
WriteBasicSetting(UISettings::values.microprofile_visible);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
void Config::SaveWebServiceValues() {
qt_config->beginGroup(QStringLiteral("WebService"));
2021-07-03 11:00:06 +02:00
WriteBasicSetting(Settings::values.enable_telemetry);
WriteBasicSetting(Settings::values.web_api_url);
WriteBasicSetting(Settings::values.yuzu_username);
WriteBasicSetting(Settings::values.yuzu_token);
2020-12-28 16:15:37 +01:00
qt_config->endGroup();
}
2022-07-26 03:25:01 +02:00
void Config::SaveMultiplayerValues() {
qt_config->beginGroup(QStringLiteral("Multiplayer"));
WriteBasicSetting(UISettings::values.multiplayer_nickname);
WriteBasicSetting(UISettings::values.multiplayer_ip);
WriteBasicSetting(UISettings::values.multiplayer_port);
WriteBasicSetting(UISettings::values.multiplayer_room_nickname);
WriteBasicSetting(UISettings::values.multiplayer_room_name);
WriteBasicSetting(UISettings::values.multiplayer_room_port);
WriteBasicSetting(UISettings::values.multiplayer_host_type);
WriteBasicSetting(UISettings::values.multiplayer_port);
WriteBasicSetting(UISettings::values.multiplayer_max_player);
WriteBasicSetting(UISettings::values.multiplayer_game_id);
WriteBasicSetting(UISettings::values.multiplayer_room_description);
// Write ban list
qt_config->beginWriteArray(QStringLiteral("username_ban_list"));
for (std::size_t i = 0; i < UISettings::values.multiplayer_ban_list.first.size(); ++i) {
qt_config->setArrayIndex(static_cast<int>(i));
WriteSetting(QStringLiteral("username"),
QString::fromStdString(UISettings::values.multiplayer_ban_list.first[i]));
}
qt_config->endArray();
qt_config->beginWriteArray(QStringLiteral("ip_ban_list"));
for (std::size_t i = 0; i < UISettings::values.multiplayer_ban_list.second.size(); ++i) {
qt_config->setArrayIndex(static_cast<int>(i));
WriteSetting(QStringLiteral("ip"),
QString::fromStdString(UISettings::values.multiplayer_ban_list.second[i]));
}
qt_config->endArray();
qt_config->endGroup();
}
2020-12-28 16:15:37 +01:00
QVariant Config::ReadSetting(const QString& name) const {
return qt_config->value(name);
}
QVariant Config::ReadSetting(const QString& name, const QVariant& default_value) const {
QVariant result;
if (qt_config->value(name + QStringLiteral("/default"), false).toBool()) {
result = default_value;
} else {
result = qt_config->value(name, default_value);
}
return result;
}
2022-07-17 09:10:25 +02:00
template <typename Type, bool ranged>
void Config::ReadGlobalSetting(Settings::SwitchableSetting<Type, ranged>& setting) {
2021-07-03 11:00:06 +02:00
QString name = QString::fromStdString(setting.GetLabel());
2020-12-28 16:15:37 +01:00
const bool use_global = qt_config->value(name + QStringLiteral("/use_global"), true).toBool();
setting.SetGlobal(use_global);
if (global || !use_global) {
2021-07-03 11:00:06 +02:00
setting.SetValue(static_cast<QVariant>(
ReadSetting(name, QVariant::fromValue<Type>(setting.GetDefault())))
.value<Type>());
2020-12-28 16:15:37 +01:00
}
}
template <typename Type>
void Config::ReadSettingGlobal(Type& setting, const QString& name,
const QVariant& default_value) const {
const bool use_global = qt_config->value(name + QStringLiteral("/use_global"), true).toBool();
if (global || !use_global) {
setting = ReadSetting(name, default_value).value<Type>();
}
}
void Config::WriteSetting(const QString& name, const QVariant& value) {
qt_config->setValue(name, value);
}
void Config::WriteSetting(const QString& name, const QVariant& value,
const QVariant& default_value) {
qt_config->setValue(name + QStringLiteral("/default"), value == default_value);
qt_config->setValue(name, value);
}
2021-07-03 11:00:06 +02:00
void Config::WriteSetting(const QString& name, const QVariant& value, const QVariant& default_value,
bool use_global) {
2020-12-28 16:15:37 +01:00
if (!global) {
qt_config->setValue(name + QStringLiteral("/use_global"), use_global);
}
if (global || !use_global) {
qt_config->setValue(name + QStringLiteral("/default"), value == default_value);
qt_config->setValue(name, value);
}
}
void Config::Reload() {
ReadValues();
// To apply default value changes
SaveValues();
}
void Config::Save() {
SaveValues();
}
void Config::ReadControlPlayerValue(std::size_t player_index) {
qt_config->beginGroup(QStringLiteral("Controls"));
ReadPlayerValue(player_index);
qt_config->endGroup();
}
void Config::SaveControlPlayerValue(std::size_t player_index) {
qt_config->beginGroup(QStringLiteral("Controls"));
SavePlayerValue(player_index);
qt_config->endGroup();
}
const std::string& Config::GetConfigFilePath() const {
return qt_config_loc;
}