From 411745c0b07b07c77c31d5b09e80fbd6dcb6c3ef Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 2 Jan 2015 13:58:51 -0300 Subject: [PATCH] Removed redundancy in frontend configs by creating a core config file --- src/citra/CMakeLists.txt | 1 - src/citra/citra.cpp | 4 +- src/citra/config.cpp | 40 +++++++++++++------- src/citra/config.h | 4 ++ src/citra/default_ini.h | 41 -------------------- src/citra_qt/CMakeLists.txt | 2 +- src/citra_qt/config.cpp | 32 ++-------------- src/citra_qt/config.h | 4 ++ src/citra_qt/main.cpp | 4 +- src/core/CMakeLists.txt | 2 + src/core/config.cpp | 74 +++++++++++++++++++++++++++++++++++++ src/core/config.h | 28 ++++++++++++++ 12 files changed, 149 insertions(+), 87 deletions(-) delete mode 100644 src/citra/default_ini.h create mode 100644 src/core/config.cpp create mode 100644 src/core/config.h diff --git a/src/citra/CMakeLists.txt b/src/citra/CMakeLists.txt index bbb3374f2..bb51a7d03 100644 --- a/src/citra/CMakeLists.txt +++ b/src/citra/CMakeLists.txt @@ -7,7 +7,6 @@ set(SRCS set(HEADERS emu_window/emu_window_glfw.h config.h - default_ini.h resource.h ) diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp index 69f0b35b3..561b813b9 100644 --- a/src/citra/citra.cpp +++ b/src/citra/citra.cpp @@ -12,6 +12,7 @@ #include "core/settings.h" #include "core/system.h" +#include "core/config.h" #include "core/core.h" #include "core/loader/loader.h" @@ -33,7 +34,8 @@ int __cdecl main(int argc, char **argv) { return -1; } - Config config; + Citra::Config frontend_config; + Core::Config core_config; log_filter.ParseFilterString(Settings::values.log_filter); std::string boot_filename = argv[1]; diff --git a/src/citra/config.cpp b/src/citra/config.cpp index 2bf0dff35..482fa0f52 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -4,12 +4,33 @@ #include -#include "citra/default_ini.h" +#include "citra/config.h" #include "common/file_util.h" #include "core/settings.h" #include "core/core.h" -#include "config.h" +namespace Citra { + +static const char* default_config_file = R"( +[Controls] +pad_start = +pad_select = +pad_home = +pad_dup = +pad_ddown = +pad_dleft = +pad_dright = +pad_a = +pad_b = +pad_x = +pad_y = +pad_r = +pad_l = +pad_sup = +pad_sdown = +pad_sleft = +pad_sright = +)"; Config::Config() { // TODO: Don't hardcode the path; let the frontend decide where to put the config files. @@ -55,24 +76,15 @@ void Config::ReadValues() { Settings::values.pad_sdown_key = glfw_config->GetInteger("Controls", "pad_sdown", GLFW_KEY_DOWN); Settings::values.pad_sleft_key = glfw_config->GetInteger("Controls", "pad_sleft", GLFW_KEY_LEFT); Settings::values.pad_sright_key = glfw_config->GetInteger("Controls", "pad_sright", GLFW_KEY_RIGHT); - - // Core - Settings::values.cpu_core = glfw_config->GetInteger("Core", "cpu_core", Core::CPU_Interpreter); - Settings::values.gpu_refresh_rate = glfw_config->GetInteger("Core", "gpu_refresh_rate", 30); - Settings::values.frame_skip = glfw_config->GetInteger("Core", "frame_skip", 0); - - // Data Storage - Settings::values.use_virtual_sd = glfw_config->GetBoolean("Data Storage", "use_virtual_sd", true); - - // Miscellaneous - Settings::values.log_filter = glfw_config->Get("Miscellaneous", "log_filter", "*:Info"); } void Config::Reload() { - LoadINI(glfw_config, glfw_config_loc.c_str(), DefaultINI::glfw_config_file); + LoadINI(glfw_config, glfw_config_loc.c_str(), default_config_file); ReadValues(); } Config::~Config() { delete glfw_config; } + +} diff --git a/src/citra/config.h b/src/citra/config.h index 0eb176c7d..4119009d1 100644 --- a/src/citra/config.h +++ b/src/citra/config.h @@ -10,6 +10,8 @@ #include "common/common_types.h" +namespace Citra { + class Config { INIReader* glfw_config; std::string glfw_config_loc; @@ -22,3 +24,5 @@ public: void Reload(); }; + +} diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h deleted file mode 100644 index ebe2e9767..000000000 --- a/src/citra/default_ini.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2014 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -namespace DefaultINI { - -const char* glfw_config_file = R"( -[Controls] -pad_start = -pad_select = -pad_home = -pad_dup = -pad_ddown = -pad_dleft = -pad_dright = -pad_a = -pad_b = -pad_x = -pad_y = -pad_r = -pad_l = -pad_sup = -pad_sdown = -pad_sleft = -pad_sright = - -[Core] -cpu_core = ## 0: Interpreter (default), 1: OldInterpreter (may work better, soon to be deprecated) -gpu_refresh_rate = ## 30 (default) -frame_skip = ## 0: No frameskip (default), 1 : 2x frameskip, 2 : 4x frameskip, etc. - -[Data Storage] -use_virtual_sd = - -[Miscellaneous] -log_filter = *:Info ## Examples: *:Debug Kernel.SVC:Trace Service.*:Critical -)"; - -} diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt index a0ba252b3..b1157954a 100644 --- a/src/citra_qt/CMakeLists.txt +++ b/src/citra_qt/CMakeLists.txt @@ -59,7 +59,7 @@ endif() add_executable(citra-qt ${SRCS} ${HEADERS} ${UI_HDRS}) target_link_libraries(citra-qt core common video_core qhexedit) -target_link_libraries(citra-qt ${OPENGL_gl_LIBRARY} ${CITRA_QT_LIBS}) +target_link_libraries(citra-qt inih ${OPENGL_gl_LIBRARY} ${CITRA_QT_LIBS}) if (UNIX) target_link_libraries(citra-qt -pthread) diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index 1596c08d7..615bbd4b4 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp @@ -11,6 +11,8 @@ #include "config.h" +namespace Citra_Qt { + Config::Config() { // TODO: Don't hardcode the path; let the frontend decide where to put the config files. @@ -41,20 +43,6 @@ void Config::ReadValues() { Settings::values.pad_sleft_key = qt_config->value("pad_sleft", Qt::Key_Left).toInt(); Settings::values.pad_sright_key = qt_config->value("pad_sright", Qt::Key_Right).toInt(); qt_config->endGroup(); - - qt_config->beginGroup("Core"); - Settings::values.cpu_core = qt_config->value("cpu_core", Core::CPU_Interpreter).toInt(); - Settings::values.gpu_refresh_rate = qt_config->value("gpu_refresh_rate", 30).toInt(); - Settings::values.frame_skip = qt_config->value("frame_skip", 0).toInt(); - qt_config->endGroup(); - - qt_config->beginGroup("Data Storage"); - Settings::values.use_virtual_sd = qt_config->value("use_virtual_sd", true).toBool(); - qt_config->endGroup(); - - qt_config->beginGroup("Miscellaneous"); - Settings::values.log_filter = qt_config->value("log_filter", "*:Info").toString().toStdString(); - qt_config->endGroup(); } void Config::SaveValues() { @@ -77,20 +65,6 @@ void Config::SaveValues() { qt_config->setValue("pad_sleft", Settings::values.pad_sleft_key); qt_config->setValue("pad_sright", Settings::values.pad_sright_key); qt_config->endGroup(); - - qt_config->beginGroup("Core"); - qt_config->setValue("cpu_core", Settings::values.cpu_core); - qt_config->setValue("gpu_refresh_rate", Settings::values.gpu_refresh_rate); - qt_config->setValue("frame_skip", Settings::values.frame_skip); - qt_config->endGroup(); - - qt_config->beginGroup("Data Storage"); - qt_config->setValue("use_virtual_sd", Settings::values.use_virtual_sd); - qt_config->endGroup(); - - qt_config->beginGroup("Miscellaneous"); - qt_config->setValue("log_filter", QString::fromStdString(Settings::values.log_filter)); - qt_config->endGroup(); } void Config::Reload() { @@ -106,3 +80,5 @@ Config::~Config() { delete qt_config; } + +} diff --git a/src/citra_qt/config.h b/src/citra_qt/config.h index 4485cae73..d92b62aa8 100644 --- a/src/citra_qt/config.h +++ b/src/citra_qt/config.h @@ -8,6 +8,8 @@ #include "common/common_types.h" +namespace Citra_Qt { + class Config { QSettings* qt_config; std::string qt_config_loc; @@ -21,3 +23,5 @@ public: void Reload(); void Save(); }; + +} diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index c6671bef1..fd0209522 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -37,6 +37,7 @@ #include "core/settings.h" #include "core/system.h" +#include "core/config.h" #include "core/core.h" #include "core/loader/loader.h" #include "core/arm/disassembler/load_symbol_map.h" @@ -48,7 +49,8 @@ GMainWindow::GMainWindow() { Pica::g_debug_context = Pica::DebugContext::Construct(); - Config config; + Citra_Qt::Config frontend_config; + Core::Config core_config; ui.setupUi(this); statusBar()->hide(); diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index b67226d8d..e1892063e 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -76,6 +76,7 @@ set(SRCS loader/loader.cpp loader/ncch.cpp loader/3dsx.cpp + config.cpp core.cpp core_timing.cpp mem_map.cpp @@ -170,6 +171,7 @@ set(HEADERS loader/loader.h loader/ncch.h loader/3dsx.h + config.h core.h core_timing.h mem_map.h diff --git a/src/core/config.cpp b/src/core/config.cpp new file mode 100644 index 000000000..556da0d4f --- /dev/null +++ b/src/core/config.cpp @@ -0,0 +1,74 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include + +#include "common/file_util.h" +#include "core/settings.h" +#include "core/config.h" +#include "core/core.h" + +namespace Core { + +static const char* default_config_file = R"( +[Core] +cpu_core = ;; 0: Interpreter (default), 1: OldInterpreter (may work better, soon to be deprecated) +gpu_refresh_rate = ;; 30 (default) +frame_skip = ;; 0: No frameskip (default), 1 : 2x frameskip, 2 : 4x frameskip, etc. + +[Data Storage] +use_virtual_sd = + +[Miscellaneous] +log_filter = *:Info ;; Examples: *:Debug Kernel.SVC:Trace Service.*:Critical +)"; + +Config::Config() { + // TODO: Don't hardcode the path; let the frontend decide where to put the config files. + core_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "core-config.ini"; + core_config = new INIReader(core_config_loc); + + Reload(); +} + +bool Config::LoadINI(INIReader* config, const char* location, const std::string& default_contents, bool retry) { + if (config->ParseError() < 0) { + if (retry) { + LOG_WARNING(Config, "Failed to load %s. Creating file from defaults...", location); + FileUtil::CreateFullPath(location); + FileUtil::WriteStringToFile(true, default_contents, location); + *config = INIReader(location); // Reopen file + + return LoadINI(config, location, default_contents, false); + } + LOG_ERROR(Config, "Failed."); + return false; + } + LOG_INFO(Config, "Successfully loaded %s", location); + return true; +} + +void Config::ReadValues() { + // Core + Settings::values.cpu_core = core_config->GetInteger("Core", "cpu_core", Core::CPU_Interpreter); + Settings::values.gpu_refresh_rate = core_config->GetInteger("Core", "gpu_refresh_rate", 30); + Settings::values.frame_skip = core_config->GetInteger("Core", "frame_skip", 0); + + // Data Storage + Settings::values.use_virtual_sd = core_config->GetBoolean("Data Storage", "use_virtual_sd", true); + + // Miscellaneous + Settings::values.log_filter = core_config->Get("Miscellaneous", "log_filter", "*:Info"); +} + +void Config::Reload() { + LoadINI(core_config, core_config_loc.c_str(), default_config_file); + ReadValues(); +} + +Config::~Config() { + delete core_config; +} + +} diff --git a/src/core/config.h b/src/core/config.h new file mode 100644 index 000000000..81f69c2b8 --- /dev/null +++ b/src/core/config.h @@ -0,0 +1,28 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include + +#include + +#include "common/common_types.h" + +namespace Core { + +class Config { + INIReader* core_config; + std::string core_config_loc; + + bool LoadINI(INIReader* config, const char* location, const std::string& default_contents="", bool retry=true); + void ReadValues(); +public: + Config(); + ~Config(); + + void Reload(); +}; + +}