config.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. namespace FS = Common::FS;
  17. Config::Config() {
  18. // TODO: Don't hardcode the path; let the frontend decide where to put the config files.
  19. sdl2_config_loc = FS::GetUserPath(FS::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. FS::CreateFullPath(location);
  30. FS::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.GetValue().size(); ++p) {
  43. for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) {
  44. Settings::values.players.GetValue()[p].buttons[i] = "";
  45. }
  46. for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) {
  47. Settings::values.players.GetValue()[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.vibration_enabled.SetValue(true);
  64. Settings::values.enable_accurate_vibrations.SetValue(false);
  65. Settings::values.motion_enabled.SetValue(true);
  66. Settings::values.touchscreen.enabled = "";
  67. Settings::values.touchscreen.device = "";
  68. Settings::values.touchscreen.finger = 0;
  69. Settings::values.touchscreen.rotation_angle = 0;
  70. Settings::values.touchscreen.diameter_x = 15;
  71. Settings::values.touchscreen.diameter_y = 15;
  72. Settings::values.use_docked_mode.SetValue(
  73. sdl2_config->GetBoolean("Controls", "use_docked_mode", false));
  74. // Data Storage
  75. Settings::values.use_virtual_sd =
  76. sdl2_config->GetBoolean("Data Storage", "use_virtual_sd", true);
  77. FS::GetUserPath(Common::FS::UserPath::NANDDir,
  78. sdl2_config->Get("Data Storage", "nand_directory",
  79. Common::FS::GetUserPath(Common::FS::UserPath::NANDDir)));
  80. FS::GetUserPath(Common::FS::UserPath::SDMCDir,
  81. sdl2_config->Get("Data Storage", "sdmc_directory",
  82. Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir)));
  83. // System
  84. Settings::values.current_user = std::clamp<int>(
  85. sdl2_config->GetInteger("System", "current_user", 0), 0, Service::Account::MAX_USERS - 1);
  86. const auto rng_seed_enabled = sdl2_config->GetBoolean("System", "rng_seed_enabled", false);
  87. if (rng_seed_enabled) {
  88. Settings::values.rng_seed.SetValue(sdl2_config->GetInteger("System", "rng_seed", 0));
  89. } else {
  90. Settings::values.rng_seed.SetValue(std::nullopt);
  91. }
  92. const auto custom_rtc_enabled = sdl2_config->GetBoolean("System", "custom_rtc_enabled", false);
  93. if (custom_rtc_enabled) {
  94. Settings::values.custom_rtc.SetValue(
  95. std::chrono::seconds(sdl2_config->GetInteger("System", "custom_rtc", 0)));
  96. } else {
  97. Settings::values.custom_rtc.SetValue(std::nullopt);
  98. }
  99. // Core
  100. Settings::values.use_multi_core.SetValue(
  101. sdl2_config->GetBoolean("Core", "use_multi_core", false));
  102. // Renderer
  103. Settings::values.aspect_ratio.SetValue(
  104. static_cast<int>(sdl2_config->GetInteger("Renderer", "aspect_ratio", 0)));
  105. Settings::values.max_anisotropy.SetValue(
  106. static_cast<int>(sdl2_config->GetInteger("Renderer", "max_anisotropy", 0)));
  107. Settings::values.use_frame_limit.SetValue(false);
  108. Settings::values.frame_limit.SetValue(100);
  109. Settings::values.use_disk_shader_cache.SetValue(
  110. sdl2_config->GetBoolean("Renderer", "use_disk_shader_cache", false));
  111. const int gpu_accuracy_level = sdl2_config->GetInteger("Renderer", "gpu_accuracy", 0);
  112. Settings::values.gpu_accuracy.SetValue(static_cast<Settings::GPUAccuracy>(gpu_accuracy_level));
  113. Settings::values.use_asynchronous_gpu_emulation.SetValue(
  114. sdl2_config->GetBoolean("Renderer", "use_asynchronous_gpu_emulation", false));
  115. Settings::values.use_fast_gpu_time.SetValue(
  116. sdl2_config->GetBoolean("Renderer", "use_fast_gpu_time", true));
  117. Settings::values.bg_red.SetValue(
  118. static_cast<float>(sdl2_config->GetReal("Renderer", "bg_red", 0.0)));
  119. Settings::values.bg_green.SetValue(
  120. static_cast<float>(sdl2_config->GetReal("Renderer", "bg_green", 0.0)));
  121. Settings::values.bg_blue.SetValue(
  122. static_cast<float>(sdl2_config->GetReal("Renderer", "bg_blue", 0.0)));
  123. // Audio
  124. Settings::values.sink_id = "null";
  125. Settings::values.enable_audio_stretching.SetValue(false);
  126. Settings::values.audio_device_id = "auto";
  127. Settings::values.volume.SetValue(0);
  128. Settings::values.language_index.SetValue(
  129. sdl2_config->GetInteger("System", "language_index", 1));
  130. // Miscellaneous
  131. Settings::values.log_filter = sdl2_config->Get("Miscellaneous", "log_filter", "*:Trace");
  132. Settings::values.use_dev_keys = sdl2_config->GetBoolean("Miscellaneous", "use_dev_keys", false);
  133. // Debugging
  134. Settings::values.program_args = "";
  135. Settings::values.dump_exefs = sdl2_config->GetBoolean("Debugging", "dump_exefs", false);
  136. Settings::values.dump_nso = sdl2_config->GetBoolean("Debugging", "dump_nso", false);
  137. const auto title_list = sdl2_config->Get("AddOns", "title_ids", "");
  138. std::stringstream ss(title_list);
  139. std::string line;
  140. while (std::getline(ss, line, '|')) {
  141. const auto title_id = std::stoul(line, nullptr, 16);
  142. const auto disabled_list = sdl2_config->Get("AddOns", "disabled_" + line, "");
  143. std::stringstream inner_ss(disabled_list);
  144. std::string inner_line;
  145. std::vector<std::string> out;
  146. while (std::getline(inner_ss, inner_line, '|')) {
  147. out.push_back(inner_line);
  148. }
  149. Settings::values.disabled_addons.insert_or_assign(title_id, out);
  150. }
  151. // Web Service
  152. Settings::values.enable_telemetry =
  153. sdl2_config->GetBoolean("WebService", "enable_telemetry", true);
  154. Settings::values.web_api_url =
  155. sdl2_config->Get("WebService", "web_api_url", "https://api.yuzu-emu.org");
  156. Settings::values.yuzu_username = sdl2_config->Get("WebService", "yuzu_username", "");
  157. Settings::values.yuzu_token = sdl2_config->Get("WebService", "yuzu_token", "");
  158. }
  159. void Config::Reload() {
  160. LoadINI(DefaultINI::sdl2_config_file);
  161. ReadValues();
  162. }