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
// Refer to the license.txt file included.
#include <cstring>
#include "common/file_util.h"
#include "core/core.h"
#include "core/gdbstub/gdbstub.h"
@@ -65,6 +67,16 @@ Values global_values;
Values game_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() {
static constexpr std::array<const char*, 46> timezones{{
"auto", "default", "CET", "CST6CDT", "Cuba", "EET", "Egypt", "Eire",

View File

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

View File

@@ -13,12 +13,13 @@
#include "input_common/udp/client.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.
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);
qt_config =
std::make_unique<QSettings>(QString::fromStdString(qt_config_loc), QSettings::IniFormat);
global = is_global;
Reload();
}
@@ -807,18 +808,20 @@ void Config::ReadWebServiceValues() {
}
void Config::ReadValues() {
if (global) {
ReadDebuggingValues();
ReadDataStorageValues();
ReadWebServiceValues();
ReadDisabledAddOnValues();
ReadUIValues();
}
ReadControlValues();
ReadCoreValues();
ReadRendererValues();
ReadAudioValues();
ReadDataStorageValues();
ReadSystemValues();
ReadMiscellaneousValues();
ReadDebuggingValues();
ReadWebServiceValues();
ReadServiceValues();
ReadDisabledAddOnValues();
ReadUIValues();
}
void Config::SavePlayerValues() {
@@ -905,18 +908,20 @@ void Config::SaveTouchscreenValues() {
}
void Config::SaveValues() {
if (global) {
SaveDebuggingValues();
SaveDataStorageValues();
SaveWebServiceValues();
SaveDisabledAddOnValues();
SaveUIValues();
}
SaveControlValues();
SaveCoreValues();
SaveRendererValues();
SaveAudioValues();
SaveDataStorageValues();
SaveSystemValues();
SaveMiscellaneousValues();
SaveDebuggingValues();
SaveWebServiceValues();
SaveServiceValues();
SaveDisabledAddOnValues();
SaveUIValues();
}
void Config::SaveAudioValues() {

View File

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

View File

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

View File

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