diff options
Diffstat (limited to 'src/citra/config.cpp')
| -rw-r--r-- | src/citra/config.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/citra/config.cpp b/src/citra/config.cpp new file mode 100644 index 000000000..1d5e9c717 --- /dev/null +++ b/src/citra/config.cpp | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <GLFW/glfw3.h> | ||
| 6 | |||
| 7 | #include "citra/default_ini.h" | ||
| 8 | #include "common/file_util.h" | ||
| 9 | #include "core/settings.h" | ||
| 10 | |||
| 11 | #include "config.h" | ||
| 12 | |||
| 13 | Config::Config() { | ||
| 14 | // TODO: Don't hardcode the path; let the frontend decide where to put the config files. | ||
| 15 | glfw_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "glfw-config.ini"; | ||
| 16 | glfw_config = new INIReader(glfw_config_loc); | ||
| 17 | |||
| 18 | Reload(); | ||
| 19 | } | ||
| 20 | |||
| 21 | bool Config::LoadINI(INIReader* config, const char* location, const std::string& default_contents, bool retry) { | ||
| 22 | if (config->ParseError() < 0) { | ||
| 23 | if (retry) { | ||
| 24 | ERROR_LOG(CONFIG, "Failed to load %s. Creating file from defaults...", location); | ||
| 25 | FileUtil::CreateFullPath(location); | ||
| 26 | FileUtil::WriteStringToFile(true, default_contents, location); | ||
| 27 | *config = INIReader(location); // Reopen file | ||
| 28 | |||
| 29 | return LoadINI(config, location, default_contents, false); | ||
| 30 | } | ||
| 31 | ERROR_LOG(CONFIG, "Failed."); | ||
| 32 | return false; | ||
| 33 | } | ||
| 34 | INFO_LOG(CONFIG, "Successfully loaded %s", location); | ||
| 35 | return true; | ||
| 36 | } | ||
| 37 | |||
| 38 | void Config::ReadControls() { | ||
| 39 | Settings::values.pad_a_key = glfw_config->GetInteger("Controls", "pad_a", GLFW_KEY_A); | ||
| 40 | Settings::values.pad_b_key = glfw_config->GetInteger("Controls", "pad_b", GLFW_KEY_S); | ||
| 41 | Settings::values.pad_x_key = glfw_config->GetInteger("Controls", "pad_x", GLFW_KEY_Z); | ||
| 42 | Settings::values.pad_y_key = glfw_config->GetInteger("Controls", "pad_y", GLFW_KEY_X); | ||
| 43 | Settings::values.pad_l_key = glfw_config->GetInteger("Controls", "pad_l", GLFW_KEY_Q); | ||
| 44 | Settings::values.pad_r_key = glfw_config->GetInteger("Controls", "pad_r", GLFW_KEY_W); | ||
| 45 | Settings::values.pad_start_key = glfw_config->GetInteger("Controls", "pad_start", GLFW_KEY_M); | ||
| 46 | Settings::values.pad_select_key = glfw_config->GetInteger("Controls", "pad_select", GLFW_KEY_N); | ||
| 47 | Settings::values.pad_home_key = glfw_config->GetInteger("Controls", "pad_home", GLFW_KEY_B); | ||
| 48 | Settings::values.pad_dup_key = glfw_config->GetInteger("Controls", "pad_dup", GLFW_KEY_T); | ||
| 49 | Settings::values.pad_ddown_key = glfw_config->GetInteger("Controls", "pad_ddown", GLFW_KEY_G); | ||
| 50 | Settings::values.pad_dleft_key = glfw_config->GetInteger("Controls", "pad_dleft", GLFW_KEY_F); | ||
| 51 | Settings::values.pad_dright_key = glfw_config->GetInteger("Controls", "pad_dright", GLFW_KEY_H); | ||
| 52 | Settings::values.pad_sup_key = glfw_config->GetInteger("Controls", "pad_sup", GLFW_KEY_UP); | ||
| 53 | Settings::values.pad_sdown_key = glfw_config->GetInteger("Controls", "pad_sdown", GLFW_KEY_DOWN); | ||
| 54 | Settings::values.pad_sleft_key = glfw_config->GetInteger("Controls", "pad_sleft", GLFW_KEY_LEFT); | ||
| 55 | Settings::values.pad_sright_key = glfw_config->GetInteger("Controls", "pad_sright", GLFW_KEY_RIGHT); | ||
| 56 | } | ||
| 57 | |||
| 58 | void Config::Reload() { | ||
| 59 | LoadINI(glfw_config, glfw_config_loc.c_str(), DefaultINI::glfw_config_file); | ||
| 60 | ReadControls(); | ||
| 61 | } | ||
| 62 | |||
| 63 | Config::~Config() { | ||
| 64 | delete glfw_config; | ||
| 65 | } | ||