diff options
Diffstat (limited to 'src/yuzu_tester/config.cpp')
| -rw-r--r-- | src/yuzu_tester/config.cpp | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/src/yuzu_tester/config.cpp b/src/yuzu_tester/config.cpp new file mode 100644 index 000000000..b96b7d279 --- /dev/null +++ b/src/yuzu_tester/config.cpp | |||
| @@ -0,0 +1,184 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <memory> | ||
| 6 | #include <sstream> | ||
| 7 | #include <SDL.h> | ||
| 8 | #include <inih/cpp/INIReader.h> | ||
| 9 | #include "common/file_util.h" | ||
| 10 | #include "common/logging/log.h" | ||
| 11 | #include "common/param_package.h" | ||
| 12 | #include "core/hle/service/acc/profile_manager.h" | ||
| 13 | #include "core/settings.h" | ||
| 14 | #include "input_common/main.h" | ||
| 15 | #include "yuzu_tester/config.h" | ||
| 16 | #include "yuzu_tester/default_ini.h" | ||
| 17 | |||
| 18 | Config::Config() { | ||
| 19 | // TODO: Don't hardcode the path; let the frontend decide where to put the config files. | ||
| 20 | sdl2_config_loc = | ||
| 21 | FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "sdl2-tester-config.ini"; | ||
| 22 | sdl2_config = std::make_unique<INIReader>(sdl2_config_loc); | ||
| 23 | |||
| 24 | Reload(); | ||
| 25 | } | ||
| 26 | |||
| 27 | Config::~Config() = default; | ||
| 28 | |||
| 29 | bool Config::LoadINI(const std::string& default_contents, bool retry) { | ||
| 30 | const char* location = this->sdl2_config_loc.c_str(); | ||
| 31 | if (sdl2_config->ParseError() < 0) { | ||
| 32 | if (retry) { | ||
| 33 | LOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", location); | ||
| 34 | FileUtil::CreateFullPath(location); | ||
| 35 | FileUtil::WriteStringToFile(true, default_contents, location); | ||
| 36 | sdl2_config = std::make_unique<INIReader>(location); // Reopen file | ||
| 37 | |||
| 38 | return LoadINI(default_contents, false); | ||
| 39 | } | ||
| 40 | LOG_ERROR(Config, "Failed."); | ||
| 41 | return false; | ||
| 42 | } | ||
| 43 | LOG_INFO(Config, "Successfully loaded {}", location); | ||
| 44 | return true; | ||
| 45 | } | ||
| 46 | |||
| 47 | void Config::ReadValues() { | ||
| 48 | // Controls | ||
| 49 | for (std::size_t p = 0; p < Settings::values.players.size(); ++p) { | ||
| 50 | for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { | ||
| 51 | Settings::values.players[p].buttons[i] = ""; | ||
| 52 | } | ||
| 53 | |||
| 54 | for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { | ||
| 55 | Settings::values.players[p].analogs[i] = ""; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | Settings::values.mouse_enabled = false; | ||
| 60 | for (int i = 0; i < Settings::NativeMouseButton::NumMouseButtons; ++i) { | ||
| 61 | Settings::values.mouse_buttons[i] = ""; | ||
| 62 | } | ||
| 63 | |||
| 64 | Settings::values.motion_device = ""; | ||
| 65 | |||
| 66 | Settings::values.keyboard_enabled = false; | ||
| 67 | |||
| 68 | Settings::values.debug_pad_enabled = false; | ||
| 69 | for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { | ||
| 70 | Settings::values.debug_pad_buttons[i] = ""; | ||
| 71 | } | ||
| 72 | |||
| 73 | for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { | ||
| 74 | Settings::values.debug_pad_analogs[i] = ""; | ||
| 75 | } | ||
| 76 | |||
| 77 | Settings::values.touchscreen.enabled = ""; | ||
| 78 | Settings::values.touchscreen.device = ""; | ||
| 79 | Settings::values.touchscreen.finger = 0; | ||
| 80 | Settings::values.touchscreen.rotation_angle = 0; | ||
| 81 | Settings::values.touchscreen.diameter_x = 15; | ||
| 82 | Settings::values.touchscreen.diameter_y = 15; | ||
| 83 | |||
| 84 | // Data Storage | ||
| 85 | Settings::values.use_virtual_sd = | ||
| 86 | sdl2_config->GetBoolean("Data Storage", "use_virtual_sd", true); | ||
| 87 | FileUtil::GetUserPath(FileUtil::UserPath::NANDDir, | ||
| 88 | sdl2_config->Get("Data Storage", "nand_directory", | ||
| 89 | FileUtil::GetUserPath(FileUtil::UserPath::NANDDir))); | ||
| 90 | FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir, | ||
| 91 | sdl2_config->Get("Data Storage", "sdmc_directory", | ||
| 92 | FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir))); | ||
| 93 | |||
| 94 | // System | ||
| 95 | Settings::values.use_docked_mode = sdl2_config->GetBoolean("System", "use_docked_mode", false); | ||
| 96 | const auto size = sdl2_config->GetInteger("System", "users_size", 0); | ||
| 97 | |||
| 98 | Settings::values.current_user = std::clamp<int>( | ||
| 99 | sdl2_config->GetInteger("System", "current_user", 0), 0, Service::Account::MAX_USERS - 1); | ||
| 100 | |||
| 101 | const auto rng_seed_enabled = sdl2_config->GetBoolean("System", "rng_seed_enabled", false); | ||
| 102 | if (rng_seed_enabled) { | ||
| 103 | Settings::values.rng_seed = sdl2_config->GetInteger("System", "rng_seed", 0); | ||
| 104 | } else { | ||
| 105 | Settings::values.rng_seed = std::nullopt; | ||
| 106 | } | ||
| 107 | |||
| 108 | const auto custom_rtc_enabled = sdl2_config->GetBoolean("System", "custom_rtc_enabled", false); | ||
| 109 | if (custom_rtc_enabled) { | ||
| 110 | Settings::values.custom_rtc = | ||
| 111 | std::chrono::seconds(sdl2_config->GetInteger("System", "custom_rtc", 0)); | ||
| 112 | } else { | ||
| 113 | Settings::values.custom_rtc = std::nullopt; | ||
| 114 | } | ||
| 115 | |||
| 116 | // Core | ||
| 117 | Settings::values.cpu_jit_enabled = sdl2_config->GetBoolean("Core", "cpu_jit_enabled", true); | ||
| 118 | Settings::values.use_multi_core = sdl2_config->GetBoolean("Core", "use_multi_core", false); | ||
| 119 | |||
| 120 | // Renderer | ||
| 121 | Settings::values.resolution_factor = | ||
| 122 | static_cast<float>(sdl2_config->GetReal("Renderer", "resolution_factor", 1.0)); | ||
| 123 | Settings::values.use_frame_limit = false; | ||
| 124 | Settings::values.frame_limit = 100; | ||
| 125 | Settings::values.use_disk_shader_cache = | ||
| 126 | sdl2_config->GetBoolean("Renderer", "use_disk_shader_cache", false); | ||
| 127 | Settings::values.use_accurate_gpu_emulation = | ||
| 128 | sdl2_config->GetBoolean("Renderer", "use_accurate_gpu_emulation", false); | ||
| 129 | Settings::values.use_asynchronous_gpu_emulation = | ||
| 130 | sdl2_config->GetBoolean("Renderer", "use_asynchronous_gpu_emulation", false); | ||
| 131 | |||
| 132 | Settings::values.bg_red = static_cast<float>(sdl2_config->GetReal("Renderer", "bg_red", 0.0)); | ||
| 133 | Settings::values.bg_green = | ||
| 134 | static_cast<float>(sdl2_config->GetReal("Renderer", "bg_green", 0.0)); | ||
| 135 | Settings::values.bg_blue = static_cast<float>(sdl2_config->GetReal("Renderer", "bg_blue", 0.0)); | ||
| 136 | |||
| 137 | // Audio | ||
| 138 | Settings::values.sink_id = "null"; | ||
| 139 | Settings::values.enable_audio_stretching = false; | ||
| 140 | Settings::values.audio_device_id = "auto"; | ||
| 141 | Settings::values.volume = 0; | ||
| 142 | |||
| 143 | Settings::values.language_index = sdl2_config->GetInteger("System", "language_index", 1); | ||
| 144 | |||
| 145 | // Miscellaneous | ||
| 146 | Settings::values.log_filter = sdl2_config->Get("Miscellaneous", "log_filter", "*:Trace"); | ||
| 147 | Settings::values.use_dev_keys = sdl2_config->GetBoolean("Miscellaneous", "use_dev_keys", false); | ||
| 148 | |||
| 149 | // Debugging | ||
| 150 | Settings::values.use_gdbstub = false; | ||
| 151 | Settings::values.program_args = ""; | ||
| 152 | Settings::values.dump_exefs = sdl2_config->GetBoolean("Debugging", "dump_exefs", false); | ||
| 153 | Settings::values.dump_nso = sdl2_config->GetBoolean("Debugging", "dump_nso", false); | ||
| 154 | |||
| 155 | const auto title_list = sdl2_config->Get("AddOns", "title_ids", ""); | ||
| 156 | std::stringstream ss(title_list); | ||
| 157 | std::string line; | ||
| 158 | while (std::getline(ss, line, '|')) { | ||
| 159 | const auto title_id = std::stoul(line, nullptr, 16); | ||
| 160 | const auto disabled_list = sdl2_config->Get("AddOns", "disabled_" + line, ""); | ||
| 161 | |||
| 162 | std::stringstream inner_ss(disabled_list); | ||
| 163 | std::string inner_line; | ||
| 164 | std::vector<std::string> out; | ||
| 165 | while (std::getline(inner_ss, inner_line, '|')) { | ||
| 166 | out.push_back(inner_line); | ||
| 167 | } | ||
| 168 | |||
| 169 | Settings::values.disabled_addons.insert_or_assign(title_id, out); | ||
| 170 | } | ||
| 171 | |||
| 172 | // Web Service | ||
| 173 | Settings::values.enable_telemetry = | ||
| 174 | sdl2_config->GetBoolean("WebService", "enable_telemetry", true); | ||
| 175 | Settings::values.web_api_url = | ||
| 176 | sdl2_config->Get("WebService", "web_api_url", "https://api.yuzu-emu.org"); | ||
| 177 | Settings::values.yuzu_username = sdl2_config->Get("WebService", "yuzu_username", ""); | ||
| 178 | Settings::values.yuzu_token = sdl2_config->Get("WebService", "yuzu_token", ""); | ||
| 179 | } | ||
| 180 | |||
| 181 | void Config::Reload() { | ||
| 182 | LoadINI(DefaultINI::sdl2_config_file); | ||
| 183 | ReadValues(); | ||
| 184 | } | ||