diff options
Diffstat (limited to 'src/yuzu_cmd/config.cpp')
| -rw-r--r-- | src/yuzu_cmd/config.cpp | 279 |
1 files changed, 0 insertions, 279 deletions
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp deleted file mode 100644 index 0d25ff400..000000000 --- a/src/yuzu_cmd/config.cpp +++ /dev/null | |||
| @@ -1,279 +0,0 @@ | |||
| 1 | // SPDX-FileCopyrightText: 2014 Citra Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include <memory> | ||
| 5 | #include <optional> | ||
| 6 | #include <sstream> | ||
| 7 | #include <INIReader.h> | ||
| 8 | #include <SDL.h> | ||
| 9 | #include "common/fs/file.h" | ||
| 10 | #include "common/fs/fs.h" | ||
| 11 | #include "common/fs/path_util.h" | ||
| 12 | #include "common/logging/log.h" | ||
| 13 | #include "common/settings.h" | ||
| 14 | #include "core/hle/service/acc/profile_manager.h" | ||
| 15 | #include "input_common/main.h" | ||
| 16 | #include "yuzu_cmd/config.h" | ||
| 17 | #include "yuzu_cmd/default_ini.h" | ||
| 18 | |||
| 19 | namespace FS = Common::FS; | ||
| 20 | |||
| 21 | const std::filesystem::path default_config_path = | ||
| 22 | FS::GetYuzuPath(FS::YuzuPath::ConfigDir) / "sdl2-config.ini"; | ||
| 23 | |||
| 24 | Config::Config(std::optional<std::filesystem::path> config_path) | ||
| 25 | : sdl2_config_loc{config_path.value_or(default_config_path)}, | ||
| 26 | sdl2_config{std::make_unique<INIReader>(FS::PathToUTF8String(sdl2_config_loc))} { | ||
| 27 | Reload(); | ||
| 28 | } | ||
| 29 | |||
| 30 | Config::~Config() = default; | ||
| 31 | |||
| 32 | bool Config::LoadINI(const std::string& default_contents, bool retry) { | ||
| 33 | const auto config_loc_str = FS::PathToUTF8String(sdl2_config_loc); | ||
| 34 | if (sdl2_config->ParseError() < 0) { | ||
| 35 | if (retry) { | ||
| 36 | LOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", | ||
| 37 | config_loc_str); | ||
| 38 | |||
| 39 | void(FS::CreateParentDir(sdl2_config_loc)); | ||
| 40 | void(FS::WriteStringToFile(sdl2_config_loc, FS::FileType::TextFile, default_contents)); | ||
| 41 | |||
| 42 | sdl2_config = std::make_unique<INIReader>(config_loc_str); | ||
| 43 | |||
| 44 | return LoadINI(default_contents, false); | ||
| 45 | } | ||
| 46 | LOG_ERROR(Config, "Failed."); | ||
| 47 | return false; | ||
| 48 | } | ||
| 49 | LOG_INFO(Config, "Successfully loaded {}", config_loc_str); | ||
| 50 | return true; | ||
| 51 | } | ||
| 52 | |||
| 53 | static const std::array<int, Settings::NativeButton::NumButtons> default_buttons = { | ||
| 54 | SDL_SCANCODE_A, SDL_SCANCODE_S, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_T, | ||
| 55 | SDL_SCANCODE_G, SDL_SCANCODE_F, SDL_SCANCODE_H, SDL_SCANCODE_Q, SDL_SCANCODE_W, | ||
| 56 | SDL_SCANCODE_M, SDL_SCANCODE_N, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_B, | ||
| 57 | }; | ||
| 58 | |||
| 59 | static const std::array<int, Settings::NativeMotion::NumMotions> default_motions = { | ||
| 60 | SDL_SCANCODE_7, | ||
| 61 | SDL_SCANCODE_8, | ||
| 62 | }; | ||
| 63 | |||
| 64 | static const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> default_analogs{{ | ||
| 65 | { | ||
| 66 | SDL_SCANCODE_UP, | ||
| 67 | SDL_SCANCODE_DOWN, | ||
| 68 | SDL_SCANCODE_LEFT, | ||
| 69 | SDL_SCANCODE_RIGHT, | ||
| 70 | SDL_SCANCODE_D, | ||
| 71 | }, | ||
| 72 | { | ||
| 73 | SDL_SCANCODE_I, | ||
| 74 | SDL_SCANCODE_K, | ||
| 75 | SDL_SCANCODE_J, | ||
| 76 | SDL_SCANCODE_L, | ||
| 77 | SDL_SCANCODE_D, | ||
| 78 | }, | ||
| 79 | }}; | ||
| 80 | |||
| 81 | template <> | ||
| 82 | void Config::ReadSetting(const std::string& group, Settings::Setting<std::string>& setting) { | ||
| 83 | std::string setting_value = sdl2_config->Get(group, setting.GetLabel(), setting.GetDefault()); | ||
| 84 | if (setting_value.empty()) { | ||
| 85 | setting_value = setting.GetDefault(); | ||
| 86 | } | ||
| 87 | setting = std::move(setting_value); | ||
| 88 | } | ||
| 89 | |||
| 90 | template <> | ||
| 91 | void Config::ReadSetting(const std::string& group, Settings::Setting<bool>& setting) { | ||
| 92 | setting = sdl2_config->GetBoolean(group, setting.GetLabel(), setting.GetDefault()); | ||
| 93 | } | ||
| 94 | |||
| 95 | template <typename Type, bool ranged> | ||
| 96 | void Config::ReadSetting(const std::string& group, Settings::Setting<Type, ranged>& setting) { | ||
| 97 | setting = static_cast<Type>(sdl2_config->GetInteger(group, setting.GetLabel(), | ||
| 98 | static_cast<long>(setting.GetDefault()))); | ||
| 99 | } | ||
| 100 | |||
| 101 | void Config::ReadCategory(Settings::Category category) { | ||
| 102 | for (const auto setting : Settings::values.linkage.by_category[category]) { | ||
| 103 | const char* category_name = [&]() { | ||
| 104 | if (category == Settings::Category::Controls) { | ||
| 105 | // For compatibility with older configs | ||
| 106 | return "ControlsGeneral"; | ||
| 107 | } else { | ||
| 108 | return Settings::TranslateCategory(category); | ||
| 109 | } | ||
| 110 | }(); | ||
| 111 | std::string setting_value = | ||
| 112 | sdl2_config->Get(category_name, setting->GetLabel(), setting->DefaultToString()); | ||
| 113 | setting->LoadString(setting_value); | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | void Config::ReadValues() { | ||
| 118 | // Controls | ||
| 119 | ReadCategory(Settings::Category::Controls); | ||
| 120 | |||
| 121 | for (std::size_t p = 0; p < Settings::values.players.GetValue().size(); ++p) { | ||
| 122 | auto& player = Settings::values.players.GetValue()[p]; | ||
| 123 | |||
| 124 | const auto group = fmt::format("ControlsP{}", p); | ||
| 125 | for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { | ||
| 126 | std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); | ||
| 127 | player.buttons[i] = | ||
| 128 | sdl2_config->Get(group, Settings::NativeButton::mapping[i], default_param); | ||
| 129 | if (player.buttons[i].empty()) { | ||
| 130 | player.buttons[i] = default_param; | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { | ||
| 135 | std::string default_param = InputCommon::GenerateAnalogParamFromKeys( | ||
| 136 | default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], | ||
| 137 | default_analogs[i][3], default_analogs[i][4], 0.5f); | ||
| 138 | player.analogs[i] = | ||
| 139 | sdl2_config->Get(group, Settings::NativeAnalog::mapping[i], default_param); | ||
| 140 | if (player.analogs[i].empty()) { | ||
| 141 | player.analogs[i] = default_param; | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | for (int i = 0; i < Settings::NativeMotion::NumMotions; ++i) { | ||
| 146 | const std::string default_param = | ||
| 147 | InputCommon::GenerateKeyboardParam(default_motions[i]); | ||
| 148 | auto& player_motions = player.motions[i]; | ||
| 149 | |||
| 150 | player_motions = | ||
| 151 | sdl2_config->Get(group, Settings::NativeMotion::mapping[i], default_param); | ||
| 152 | if (player_motions.empty()) { | ||
| 153 | player_motions = default_param; | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | player.connected = sdl2_config->GetBoolean(group, "connected", false); | ||
| 158 | } | ||
| 159 | |||
| 160 | for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { | ||
| 161 | std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); | ||
| 162 | Settings::values.debug_pad_buttons[i] = sdl2_config->Get( | ||
| 163 | "ControlsGeneral", std::string("debug_pad_") + Settings::NativeButton::mapping[i], | ||
| 164 | default_param); | ||
| 165 | if (Settings::values.debug_pad_buttons[i].empty()) | ||
| 166 | Settings::values.debug_pad_buttons[i] = default_param; | ||
| 167 | } | ||
| 168 | |||
| 169 | for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { | ||
| 170 | std::string default_param = InputCommon::GenerateAnalogParamFromKeys( | ||
| 171 | default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], | ||
| 172 | default_analogs[i][3], default_analogs[i][4], 0.5f); | ||
| 173 | Settings::values.debug_pad_analogs[i] = sdl2_config->Get( | ||
| 174 | "ControlsGeneral", std::string("debug_pad_") + Settings::NativeAnalog::mapping[i], | ||
| 175 | default_param); | ||
| 176 | if (Settings::values.debug_pad_analogs[i].empty()) | ||
| 177 | Settings::values.debug_pad_analogs[i] = default_param; | ||
| 178 | } | ||
| 179 | |||
| 180 | Settings::values.touchscreen.enabled = | ||
| 181 | sdl2_config->GetBoolean("ControlsGeneral", "touch_enabled", true); | ||
| 182 | Settings::values.touchscreen.rotation_angle = | ||
| 183 | sdl2_config->GetInteger("ControlsGeneral", "touch_angle", 0); | ||
| 184 | Settings::values.touchscreen.diameter_x = | ||
| 185 | sdl2_config->GetInteger("ControlsGeneral", "touch_diameter_x", 15); | ||
| 186 | Settings::values.touchscreen.diameter_y = | ||
| 187 | sdl2_config->GetInteger("ControlsGeneral", "touch_diameter_y", 15); | ||
| 188 | |||
| 189 | int num_touch_from_button_maps = | ||
| 190 | sdl2_config->GetInteger("ControlsGeneral", "touch_from_button_map", 0); | ||
| 191 | if (num_touch_from_button_maps > 0) { | ||
| 192 | for (int i = 0; i < num_touch_from_button_maps; ++i) { | ||
| 193 | Settings::TouchFromButtonMap map; | ||
| 194 | map.name = sdl2_config->Get("ControlsGeneral", | ||
| 195 | std::string("touch_from_button_maps_") + std::to_string(i) + | ||
| 196 | std::string("_name"), | ||
| 197 | "default"); | ||
| 198 | const int num_touch_maps = sdl2_config->GetInteger( | ||
| 199 | "ControlsGeneral", | ||
| 200 | std::string("touch_from_button_maps_") + std::to_string(i) + std::string("_count"), | ||
| 201 | 0); | ||
| 202 | map.buttons.reserve(num_touch_maps); | ||
| 203 | |||
| 204 | for (int j = 0; j < num_touch_maps; ++j) { | ||
| 205 | std::string touch_mapping = | ||
| 206 | sdl2_config->Get("ControlsGeneral", | ||
| 207 | std::string("touch_from_button_maps_") + std::to_string(i) + | ||
| 208 | std::string("_bind_") + std::to_string(j), | ||
| 209 | ""); | ||
| 210 | map.buttons.emplace_back(std::move(touch_mapping)); | ||
| 211 | } | ||
| 212 | |||
| 213 | Settings::values.touch_from_button_maps.emplace_back(std::move(map)); | ||
| 214 | } | ||
| 215 | } else { | ||
| 216 | Settings::values.touch_from_button_maps.emplace_back( | ||
| 217 | Settings::TouchFromButtonMap{"default", {}}); | ||
| 218 | num_touch_from_button_maps = 1; | ||
| 219 | } | ||
| 220 | Settings::values.touch_from_button_map_index = std::clamp( | ||
| 221 | Settings::values.touch_from_button_map_index.GetValue(), 0, num_touch_from_button_maps - 1); | ||
| 222 | |||
| 223 | ReadCategory(Settings::Category::Audio); | ||
| 224 | ReadCategory(Settings::Category::Core); | ||
| 225 | ReadCategory(Settings::Category::Cpu); | ||
| 226 | ReadCategory(Settings::Category::CpuDebug); | ||
| 227 | ReadCategory(Settings::Category::CpuUnsafe); | ||
| 228 | ReadCategory(Settings::Category::Renderer); | ||
| 229 | ReadCategory(Settings::Category::RendererAdvanced); | ||
| 230 | ReadCategory(Settings::Category::RendererDebug); | ||
| 231 | ReadCategory(Settings::Category::System); | ||
| 232 | ReadCategory(Settings::Category::SystemAudio); | ||
| 233 | ReadCategory(Settings::Category::DataStorage); | ||
| 234 | ReadCategory(Settings::Category::Debugging); | ||
| 235 | ReadCategory(Settings::Category::DebuggingGraphics); | ||
| 236 | ReadCategory(Settings::Category::Miscellaneous); | ||
| 237 | ReadCategory(Settings::Category::Network); | ||
| 238 | ReadCategory(Settings::Category::WebService); | ||
| 239 | |||
| 240 | // Data Storage | ||
| 241 | FS::SetYuzuPath(FS::YuzuPath::NANDDir, | ||
| 242 | sdl2_config->Get("Data Storage", "nand_directory", | ||
| 243 | FS::GetYuzuPathString(FS::YuzuPath::NANDDir))); | ||
| 244 | FS::SetYuzuPath(FS::YuzuPath::SDMCDir, | ||
| 245 | sdl2_config->Get("Data Storage", "sdmc_directory", | ||
| 246 | FS::GetYuzuPathString(FS::YuzuPath::SDMCDir))); | ||
| 247 | FS::SetYuzuPath(FS::YuzuPath::LoadDir, | ||
| 248 | sdl2_config->Get("Data Storage", "load_directory", | ||
| 249 | FS::GetYuzuPathString(FS::YuzuPath::LoadDir))); | ||
| 250 | FS::SetYuzuPath(FS::YuzuPath::DumpDir, | ||
| 251 | sdl2_config->Get("Data Storage", "dump_directory", | ||
| 252 | FS::GetYuzuPathString(FS::YuzuPath::DumpDir))); | ||
| 253 | |||
| 254 | // Debugging | ||
| 255 | Settings::values.record_frame_times = | ||
| 256 | sdl2_config->GetBoolean("Debugging", "record_frame_times", false); | ||
| 257 | |||
| 258 | const auto title_list = sdl2_config->Get("AddOns", "title_ids", ""); | ||
| 259 | std::stringstream ss(title_list); | ||
| 260 | std::string line; | ||
| 261 | while (std::getline(ss, line, '|')) { | ||
| 262 | const auto title_id = std::strtoul(line.c_str(), nullptr, 16); | ||
| 263 | const auto disabled_list = sdl2_config->Get("AddOns", "disabled_" + line, ""); | ||
| 264 | |||
| 265 | std::stringstream inner_ss(disabled_list); | ||
| 266 | std::string inner_line; | ||
| 267 | std::vector<std::string> out; | ||
| 268 | while (std::getline(inner_ss, inner_line, '|')) { | ||
| 269 | out.push_back(inner_line); | ||
| 270 | } | ||
| 271 | |||
| 272 | Settings::values.disabled_addons.insert_or_assign(title_id, out); | ||
| 273 | } | ||
| 274 | } | ||
| 275 | |||
| 276 | void Config::Reload() { | ||
| 277 | LoadINI(DefaultINI::sdl2_config_file); | ||
| 278 | ReadValues(); | ||
| 279 | } | ||