diff options
Diffstat (limited to 'src/yuzu_cmd/config.cpp')
| -rw-r--r-- | src/yuzu_cmd/config.cpp | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp new file mode 100644 index 000000000..94d1a9f1c --- /dev/null +++ b/src/yuzu_cmd/config.cpp | |||
| @@ -0,0 +1,160 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <memory> | ||
| 6 | #include <SDL.h> | ||
| 7 | #include <inih/cpp/INIReader.h> | ||
| 8 | #include "citra/config.h" | ||
| 9 | #include "citra/default_ini.h" | ||
| 10 | #include "common/file_util.h" | ||
| 11 | #include "common/logging/log.h" | ||
| 12 | #include "common/param_package.h" | ||
| 13 | #include "core/settings.h" | ||
| 14 | #include "input_common/main.h" | ||
| 15 | |||
| 16 | Config::Config() { | ||
| 17 | // TODO: Don't hardcode the path; let the frontend decide where to put the config files. | ||
| 18 | sdl2_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "sdl2-config.ini"; | ||
| 19 | sdl2_config = std::make_unique<INIReader>(sdl2_config_loc); | ||
| 20 | |||
| 21 | Reload(); | ||
| 22 | } | ||
| 23 | |||
| 24 | Config::~Config() = default; | ||
| 25 | |||
| 26 | bool Config::LoadINI(const std::string& default_contents, bool retry) { | ||
| 27 | const char* location = this->sdl2_config_loc.c_str(); | ||
| 28 | if (sdl2_config->ParseError() < 0) { | ||
| 29 | if (retry) { | ||
| 30 | LOG_WARNING(Config, "Failed to load %s. Creating file from defaults...", location); | ||
| 31 | FileUtil::CreateFullPath(location); | ||
| 32 | FileUtil::WriteStringToFile(true, default_contents, location); | ||
| 33 | sdl2_config = std::make_unique<INIReader>(location); // Reopen file | ||
| 34 | |||
| 35 | return LoadINI(default_contents, false); | ||
| 36 | } | ||
| 37 | LOG_ERROR(Config, "Failed."); | ||
| 38 | return false; | ||
| 39 | } | ||
| 40 | LOG_INFO(Config, "Successfully loaded %s", location); | ||
| 41 | return true; | ||
| 42 | } | ||
| 43 | |||
| 44 | static const std::array<int, Settings::NativeButton::NumButtons> default_buttons = { | ||
| 45 | SDL_SCANCODE_A, SDL_SCANCODE_S, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_T, | ||
| 46 | SDL_SCANCODE_G, SDL_SCANCODE_F, SDL_SCANCODE_H, SDL_SCANCODE_Q, SDL_SCANCODE_W, | ||
| 47 | SDL_SCANCODE_M, SDL_SCANCODE_N, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_B, | ||
| 48 | }; | ||
| 49 | |||
| 50 | static const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> default_analogs{{ | ||
| 51 | { | ||
| 52 | SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_D, | ||
| 53 | }, | ||
| 54 | { | ||
| 55 | SDL_SCANCODE_I, SDL_SCANCODE_K, SDL_SCANCODE_J, SDL_SCANCODE_L, SDL_SCANCODE_D, | ||
| 56 | }, | ||
| 57 | }}; | ||
| 58 | |||
| 59 | void Config::ReadValues() { | ||
| 60 | // Controls | ||
| 61 | for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { | ||
| 62 | std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); | ||
| 63 | Settings::values.buttons[i] = | ||
| 64 | sdl2_config->Get("Controls", Settings::NativeButton::mapping[i], default_param); | ||
| 65 | if (Settings::values.buttons[i].empty()) | ||
| 66 | Settings::values.buttons[i] = default_param; | ||
| 67 | } | ||
| 68 | |||
| 69 | for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { | ||
| 70 | std::string default_param = InputCommon::GenerateAnalogParamFromKeys( | ||
| 71 | default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], | ||
| 72 | default_analogs[i][3], default_analogs[i][4], 0.5f); | ||
| 73 | Settings::values.analogs[i] = | ||
| 74 | sdl2_config->Get("Controls", Settings::NativeAnalog::mapping[i], default_param); | ||
| 75 | if (Settings::values.analogs[i].empty()) | ||
| 76 | Settings::values.analogs[i] = default_param; | ||
| 77 | } | ||
| 78 | |||
| 79 | Settings::values.motion_device = sdl2_config->Get( | ||
| 80 | "Controls", "motion_device", "engine:motion_emu,update_period:100,sensitivity:0.01"); | ||
| 81 | Settings::values.touch_device = | ||
| 82 | sdl2_config->Get("Controls", "touch_device", "engine:emu_window"); | ||
| 83 | |||
| 84 | // Core | ||
| 85 | Settings::values.cpu_core = | ||
| 86 | static_cast<Settings::CpuCore>(sdl2_config->GetInteger("Core", "cpu_core", 0)); | ||
| 87 | |||
| 88 | // Renderer | ||
| 89 | Settings::values.use_hw_renderer = sdl2_config->GetBoolean("Renderer", "use_hw_renderer", true); | ||
| 90 | Settings::values.use_shader_jit = sdl2_config->GetBoolean("Renderer", "use_shader_jit", true); | ||
| 91 | Settings::values.resolution_factor = | ||
| 92 | (float)sdl2_config->GetReal("Renderer", "resolution_factor", 1.0); | ||
| 93 | Settings::values.use_vsync = sdl2_config->GetBoolean("Renderer", "use_vsync", false); | ||
| 94 | Settings::values.toggle_framelimit = | ||
| 95 | sdl2_config->GetBoolean("Renderer", "toggle_framelimit", true); | ||
| 96 | |||
| 97 | Settings::values.bg_red = (float)sdl2_config->GetReal("Renderer", "bg_red", 0.0); | ||
| 98 | Settings::values.bg_green = (float)sdl2_config->GetReal("Renderer", "bg_green", 0.0); | ||
| 99 | Settings::values.bg_blue = (float)sdl2_config->GetReal("Renderer", "bg_blue", 0.0); | ||
| 100 | |||
| 101 | // Layout | ||
| 102 | Settings::values.layout_option = | ||
| 103 | static_cast<Settings::LayoutOption>(sdl2_config->GetInteger("Layout", "layout_option", 0)); | ||
| 104 | Settings::values.swap_screen = sdl2_config->GetBoolean("Layout", "swap_screen", false); | ||
| 105 | Settings::values.custom_layout = sdl2_config->GetBoolean("Layout", "custom_layout", false); | ||
| 106 | Settings::values.custom_top_left = | ||
| 107 | static_cast<u16>(sdl2_config->GetInteger("Layout", "custom_top_left", 0)); | ||
| 108 | Settings::values.custom_top_top = | ||
| 109 | static_cast<u16>(sdl2_config->GetInteger("Layout", "custom_top_top", 0)); | ||
| 110 | Settings::values.custom_top_right = | ||
| 111 | static_cast<u16>(sdl2_config->GetInteger("Layout", "custom_top_right", 400)); | ||
| 112 | Settings::values.custom_top_bottom = | ||
| 113 | static_cast<u16>(sdl2_config->GetInteger("Layout", "custom_top_bottom", 240)); | ||
| 114 | Settings::values.custom_bottom_left = | ||
| 115 | static_cast<u16>(sdl2_config->GetInteger("Layout", "custom_bottom_left", 40)); | ||
| 116 | Settings::values.custom_bottom_top = | ||
| 117 | static_cast<u16>(sdl2_config->GetInteger("Layout", "custom_bottom_top", 240)); | ||
| 118 | Settings::values.custom_bottom_right = | ||
| 119 | static_cast<u16>(sdl2_config->GetInteger("Layout", "custom_bottom_right", 360)); | ||
| 120 | Settings::values.custom_bottom_bottom = | ||
| 121 | static_cast<u16>(sdl2_config->GetInteger("Layout", "custom_bottom_bottom", 480)); | ||
| 122 | |||
| 123 | // Audio | ||
| 124 | Settings::values.sink_id = sdl2_config->Get("Audio", "output_engine", "auto"); | ||
| 125 | Settings::values.enable_audio_stretching = | ||
| 126 | sdl2_config->GetBoolean("Audio", "enable_audio_stretching", true); | ||
| 127 | Settings::values.audio_device_id = sdl2_config->Get("Audio", "output_device", "auto"); | ||
| 128 | |||
| 129 | // Data Storage | ||
| 130 | Settings::values.use_virtual_sd = | ||
| 131 | sdl2_config->GetBoolean("Data Storage", "use_virtual_sd", true); | ||
| 132 | |||
| 133 | // System | ||
| 134 | Settings::values.is_new_3ds = sdl2_config->GetBoolean("System", "is_new_3ds", false); | ||
| 135 | Settings::values.region_value = | ||
| 136 | sdl2_config->GetInteger("System", "region_value", Settings::REGION_VALUE_AUTO_SELECT); | ||
| 137 | |||
| 138 | // Miscellaneous | ||
| 139 | Settings::values.log_filter = sdl2_config->Get("Miscellaneous", "log_filter", "*:Info"); | ||
| 140 | |||
| 141 | // Debugging | ||
| 142 | Settings::values.use_gdbstub = sdl2_config->GetBoolean("Debugging", "use_gdbstub", false); | ||
| 143 | Settings::values.gdbstub_port = | ||
| 144 | static_cast<u16>(sdl2_config->GetInteger("Debugging", "gdbstub_port", 24689)); | ||
| 145 | |||
| 146 | // Web Service | ||
| 147 | Settings::values.enable_telemetry = | ||
| 148 | sdl2_config->GetBoolean("WebService", "enable_telemetry", true); | ||
| 149 | Settings::values.telemetry_endpoint_url = sdl2_config->Get( | ||
| 150 | "WebService", "telemetry_endpoint_url", "https://services.citra-emu.org/api/telemetry"); | ||
| 151 | Settings::values.verify_endpoint_url = sdl2_config->Get( | ||
| 152 | "WebService", "verify_endpoint_url", "https://services.citra-emu.org/api/profile"); | ||
| 153 | Settings::values.citra_username = sdl2_config->Get("WebService", "citra_username", ""); | ||
| 154 | Settings::values.citra_token = sdl2_config->Get("WebService", "citra_token", ""); | ||
| 155 | } | ||
| 156 | |||
| 157 | void Config::Reload() { | ||
| 158 | LoadINI(DefaultINI::sdl2_config_file); | ||
| 159 | ReadValues(); | ||
| 160 | } | ||