config.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. // Data Storage
  70. Settings::values.use_virtual_sd =
  71. sdl2_config->GetBoolean("Data Storage", "use_virtual_sd", true);
  72. FileUtil::GetUserPath(FileUtil::UserPath::NANDDir,
  73. sdl2_config->Get("Data Storage", "nand_directory",
  74. FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)));
  75. FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir,
  76. sdl2_config->Get("Data Storage", "sdmc_directory",
  77. FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)));
  78. // System
  79. Settings::values.use_docked_mode = sdl2_config->GetBoolean("System", "use_docked_mode", false);
  80. Settings::values.current_user = std::clamp<int>(
  81. sdl2_config->GetInteger("System", "current_user", 0), 0, Service::Account::MAX_USERS - 1);
  82. const auto rng_seed_enabled = sdl2_config->GetBoolean("System", "rng_seed_enabled", false);
  83. if (rng_seed_enabled) {
  84. Settings::values.rng_seed = sdl2_config->GetInteger("System", "rng_seed", 0);
  85. } else {
  86. Settings::values.rng_seed = std::nullopt;
  87. }
  88. const auto custom_rtc_enabled = sdl2_config->GetBoolean("System", "custom_rtc_enabled", false);
  89. if (custom_rtc_enabled) {
  90. Settings::values.custom_rtc =
  91. std::chrono::seconds(sdl2_config->GetInteger("System", "custom_rtc", 0));
  92. } else {
  93. Settings::values.custom_rtc = std::nullopt;
  94. }
  95. // Core
  96. Settings::values.use_multi_core = sdl2_config->GetBoolean("Core", "use_multi_core", false);
  97. // Renderer
  98. Settings::values.resolution_factor =
  99. static_cast<float>(sdl2_config->GetReal("Renderer", "resolution_factor", 1.0));
  100. Settings::values.use_frame_limit = false;
  101. Settings::values.frame_limit = 100;
  102. Settings::values.use_disk_shader_cache =
  103. sdl2_config->GetBoolean("Renderer", "use_disk_shader_cache", false);
  104. Settings::values.use_accurate_gpu_emulation =
  105. sdl2_config->GetBoolean("Renderer", "use_accurate_gpu_emulation", false);
  106. Settings::values.use_asynchronous_gpu_emulation =
  107. sdl2_config->GetBoolean("Renderer", "use_asynchronous_gpu_emulation", false);
  108. Settings::values.bg_red = static_cast<float>(sdl2_config->GetReal("Renderer", "bg_red", 0.0));
  109. Settings::values.bg_green =
  110. static_cast<float>(sdl2_config->GetReal("Renderer", "bg_green", 0.0));
  111. Settings::values.bg_blue = static_cast<float>(sdl2_config->GetReal("Renderer", "bg_blue", 0.0));
  112. // Audio
  113. Settings::values.sink_id = "null";
  114. Settings::values.enable_audio_stretching = false;
  115. Settings::values.audio_device_id = "auto";
  116. Settings::values.volume = 0;
  117. Settings::values.language_index = sdl2_config->GetInteger("System", "language_index", 1);
  118. // Miscellaneous
  119. Settings::values.log_filter = sdl2_config->Get("Miscellaneous", "log_filter", "*:Trace");
  120. Settings::values.use_dev_keys = sdl2_config->GetBoolean("Miscellaneous", "use_dev_keys", false);
  121. // Debugging
  122. Settings::values.use_gdbstub = false;
  123. Settings::values.program_args = "";
  124. Settings::values.dump_exefs = sdl2_config->GetBoolean("Debugging", "dump_exefs", false);
  125. Settings::values.dump_nso = sdl2_config->GetBoolean("Debugging", "dump_nso", false);
  126. const auto title_list = sdl2_config->Get("AddOns", "title_ids", "");
  127. std::stringstream ss(title_list);
  128. std::string line;
  129. while (std::getline(ss, line, '|')) {
  130. const auto title_id = std::stoul(line, nullptr, 16);
  131. const auto disabled_list = sdl2_config->Get("AddOns", "disabled_" + line, "");
  132. std::stringstream inner_ss(disabled_list);
  133. std::string inner_line;
  134. std::vector<std::string> out;
  135. while (std::getline(inner_ss, inner_line, '|')) {
  136. out.push_back(inner_line);
  137. }
  138. Settings::values.disabled_addons.insert_or_assign(title_id, out);
  139. }
  140. // Web Service
  141. Settings::values.enable_telemetry =
  142. sdl2_config->GetBoolean("WebService", "enable_telemetry", true);
  143. Settings::values.web_api_url =
  144. sdl2_config->Get("WebService", "web_api_url", "https://api.yuzu-emu.org");
  145. Settings::values.yuzu_username = sdl2_config->Get("WebService", "yuzu_username", "");
  146. Settings::values.yuzu_token = sdl2_config->Get("WebService", "yuzu_token", "");
  147. }
  148. void Config::Reload() {
  149. LoadINI(DefaultINI::sdl2_config_file);
  150. ReadValues();
  151. }