configuration: swap to per-game config memory for properties dialog

Does not set memory going in-game. Swaps to game values when opening the
properties dialog, then swaps back when closing it. Uses a `memcpy` to swap.
Also implements saving config files, limited to certain groups of configurations
so as to not risk setting unsafe configurations.
This commit is contained in:
lat9nq
2020-06-17 15:22:56 -04:00
parent d96eb90144
commit 1dedbbdaaa
6 changed files with 40 additions and 18 deletions

View File

@@ -2,6 +2,8 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <cstring>
#include "common/file_util.h" #include "common/file_util.h"
#include "core/core.h" #include "core/core.h"
#include "core/gdbstub/gdbstub.h" #include "core/gdbstub/gdbstub.h"
@@ -65,6 +67,16 @@ Values global_values;
Values game_values; Values game_values;
Values *values = &global_values; Values *values = &global_values;
void SwapValues(bool global) {
if (global) {
values = &global_values;
}
else {
std::memcpy(&game_values, &global_values, sizeof(global_values));
values = &game_values;
}
}
std::string GetTimeZoneString() { std::string GetTimeZoneString() {
static constexpr std::array<const char*, 46> timezones{{ static constexpr std::array<const char*, 46> timezones{{
"auto", "default", "CET", "CST6CDT", "Cuba", "EET", "Egypt", "Eire", "auto", "default", "CET", "CST6CDT", "Cuba", "EET", "Egypt", "Eire",

View File

@@ -499,6 +499,7 @@ extern Values game_values;
extern Values *values; extern Values *values;
float Volume(); float Volume();
void SwapValues(bool global);
bool IsGPULevelExtreme(); bool IsGPULevelExtreme();
bool IsGPULevelHigh(); bool IsGPULevelHigh();

View File

@@ -13,12 +13,13 @@
#include "input_common/udp/client.h" #include "input_common/udp/client.h"
#include "yuzu/configuration/config.h" #include "yuzu/configuration/config.h"
Config::Config() { Config::Config(const std::string& config_file, bool is_global) {
// TODO: Don't hardcode the path; let the frontend decide where to put the config files. // TODO: Don't hardcode the path; let the frontend decide where to put the config files.
qt_config_loc = FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "qt-config.ini"; qt_config_loc = FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + config_file;
FileUtil::CreateFullPath(qt_config_loc); FileUtil::CreateFullPath(qt_config_loc);
qt_config = qt_config =
std::make_unique<QSettings>(QString::fromStdString(qt_config_loc), QSettings::IniFormat); std::make_unique<QSettings>(QString::fromStdString(qt_config_loc), QSettings::IniFormat);
global = is_global;
Reload(); Reload();
} }
@@ -807,18 +808,20 @@ void Config::ReadWebServiceValues() {
} }
void Config::ReadValues() { void Config::ReadValues() {
if (global) {
ReadDebuggingValues();
ReadDataStorageValues();
ReadWebServiceValues();
ReadDisabledAddOnValues();
ReadUIValues();
}
ReadControlValues(); ReadControlValues();
ReadCoreValues(); ReadCoreValues();
ReadRendererValues(); ReadRendererValues();
ReadAudioValues(); ReadAudioValues();
ReadDataStorageValues();
ReadSystemValues(); ReadSystemValues();
ReadMiscellaneousValues(); ReadMiscellaneousValues();
ReadDebuggingValues();
ReadWebServiceValues();
ReadServiceValues(); ReadServiceValues();
ReadDisabledAddOnValues();
ReadUIValues();
} }
void Config::SavePlayerValues() { void Config::SavePlayerValues() {
@@ -905,18 +908,20 @@ void Config::SaveTouchscreenValues() {
} }
void Config::SaveValues() { void Config::SaveValues() {
if (global) {
SaveDebuggingValues();
SaveDataStorageValues();
SaveWebServiceValues();
SaveDisabledAddOnValues();
SaveUIValues();
}
SaveControlValues(); SaveControlValues();
SaveCoreValues(); SaveCoreValues();
SaveRendererValues(); SaveRendererValues();
SaveAudioValues(); SaveAudioValues();
SaveDataStorageValues();
SaveSystemValues(); SaveSystemValues();
SaveMiscellaneousValues(); SaveMiscellaneousValues();
SaveDebuggingValues();
SaveWebServiceValues();
SaveServiceValues(); SaveServiceValues();
SaveDisabledAddOnValues();
SaveUIValues();
} }
void Config::SaveAudioValues() { void Config::SaveAudioValues() {

View File

@@ -15,7 +15,7 @@ class QSettings;
class Config { class Config {
public: public:
Config(); Config(const std::string& config_loc = "qt-config.ini", bool is_global = true);
~Config(); ~Config();
void Reload(); void Reload();
@@ -87,4 +87,6 @@ private:
std::unique_ptr<QSettings> qt_config; std::unique_ptr<QSettings> qt_config;
std::string qt_config_loc; std::string qt_config_loc;
bool global;
}; };

View File

@@ -34,6 +34,9 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id)
setFocusPolicy(Qt::ClickFocus); setFocusPolicy(Qt::ClickFocus);
setWindowTitle(tr("Properties")); setWindowTitle(tr("Properties"));
Settings::SwapValues(true);
game_config = std::make_unique<Config>(fmt::format("{:016X}", title_id) + ".ini", false);
ui->addonsTab->SetTitleId(title_id); ui->addonsTab->SetTitleId(title_id);
scene = new QGraphicsScene; scene = new QGraphicsScene;
@@ -44,7 +47,8 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id)
LoadConfiguration(); LoadConfiguration();
} }
ConfigurePerGame::~ConfigurePerGame() = default; ConfigurePerGame::~ConfigurePerGame() {
}
void ConfigurePerGame::ApplyConfiguration() { void ConfigurePerGame::ApplyConfiguration() {
ui->addonsTab->ApplyConfiguration(); ui->addonsTab->ApplyConfiguration();

View File

@@ -10,6 +10,7 @@
#include <QDialog> #include <QDialog>
#include <QList> #include <QList>
#include "yuzu/configuration/config.h"
#include "core/file_sys/vfs_types.h" #include "core/file_sys/vfs_types.h"
class QGraphicsScene; class QGraphicsScene;
@@ -46,10 +47,7 @@ private:
FileSys::VirtualFile file; FileSys::VirtualFile file;
u64 title_id; u64 title_id;
//QVBoxLayout* layout;
//QTreeView* tree_view;
//QStandardItemModel* item_model;
QGraphicsScene* scene; QGraphicsScene* scene;
//std::vector<QList<QStandardItem*>> list_items; std::unique_ptr<Config> game_config;
}; };