config.cpp 7.5 KB

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