config.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <GLFW/glfw3.h>
  5. #include "citra/default_ini.h"
  6. #include "common/file_util.h"
  7. #include "common/logging/log.h"
  8. #include "core/settings.h"
  9. #include "core/core.h"
  10. #include "config.h"
  11. Config::Config() {
  12. // TODO: Don't hardcode the path; let the frontend decide where to put the config files.
  13. glfw_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "glfw-config.ini";
  14. glfw_config = new INIReader(glfw_config_loc);
  15. Reload();
  16. }
  17. bool Config::LoadINI(INIReader* config, const char* location, const std::string& default_contents, bool retry) {
  18. if (config->ParseError() < 0) {
  19. if (retry) {
  20. LOG_WARNING(Config, "Failed to load %s. Creating file from defaults...", location);
  21. FileUtil::CreateFullPath(location);
  22. FileUtil::WriteStringToFile(true, default_contents, location);
  23. *config = INIReader(location); // Reopen file
  24. return LoadINI(config, location, default_contents, false);
  25. }
  26. LOG_ERROR(Config, "Failed.");
  27. return false;
  28. }
  29. LOG_INFO(Config, "Successfully loaded %s", location);
  30. return true;
  31. }
  32. void Config::ReadValues() {
  33. // Controls
  34. Settings::values.pad_a_key = glfw_config->GetInteger("Controls", "pad_a", GLFW_KEY_A);
  35. Settings::values.pad_b_key = glfw_config->GetInteger("Controls", "pad_b", GLFW_KEY_S);
  36. Settings::values.pad_x_key = glfw_config->GetInteger("Controls", "pad_x", GLFW_KEY_Z);
  37. Settings::values.pad_y_key = glfw_config->GetInteger("Controls", "pad_y", GLFW_KEY_X);
  38. Settings::values.pad_l_key = glfw_config->GetInteger("Controls", "pad_l", GLFW_KEY_Q);
  39. Settings::values.pad_r_key = glfw_config->GetInteger("Controls", "pad_r", GLFW_KEY_W);
  40. Settings::values.pad_zl_key = glfw_config->GetInteger("Controls", "pad_zl", GLFW_KEY_1);
  41. Settings::values.pad_zr_key = glfw_config->GetInteger("Controls", "pad_zr", GLFW_KEY_2);
  42. Settings::values.pad_start_key = glfw_config->GetInteger("Controls", "pad_start", GLFW_KEY_M);
  43. Settings::values.pad_select_key = glfw_config->GetInteger("Controls", "pad_select", GLFW_KEY_N);
  44. Settings::values.pad_home_key = glfw_config->GetInteger("Controls", "pad_home", GLFW_KEY_B);
  45. Settings::values.pad_dup_key = glfw_config->GetInteger("Controls", "pad_dup", GLFW_KEY_T);
  46. Settings::values.pad_ddown_key = glfw_config->GetInteger("Controls", "pad_ddown", GLFW_KEY_G);
  47. Settings::values.pad_dleft_key = glfw_config->GetInteger("Controls", "pad_dleft", GLFW_KEY_F);
  48. Settings::values.pad_dright_key = glfw_config->GetInteger("Controls", "pad_dright", GLFW_KEY_H);
  49. Settings::values.pad_sup_key = glfw_config->GetInteger("Controls", "pad_sup", GLFW_KEY_UP);
  50. Settings::values.pad_sdown_key = glfw_config->GetInteger("Controls", "pad_sdown", GLFW_KEY_DOWN);
  51. Settings::values.pad_sleft_key = glfw_config->GetInteger("Controls", "pad_sleft", GLFW_KEY_LEFT);
  52. Settings::values.pad_sright_key = glfw_config->GetInteger("Controls", "pad_sright", GLFW_KEY_RIGHT);
  53. Settings::values.pad_cup_key = glfw_config->GetInteger("Controls", "pad_cup", GLFW_KEY_I);
  54. Settings::values.pad_cdown_key = glfw_config->GetInteger("Controls", "pad_cdown", GLFW_KEY_K);
  55. Settings::values.pad_cleft_key = glfw_config->GetInteger("Controls", "pad_cleft", GLFW_KEY_J);
  56. Settings::values.pad_cright_key = glfw_config->GetInteger("Controls", "pad_cright", GLFW_KEY_L);
  57. // Core
  58. Settings::values.gpu_refresh_rate = glfw_config->GetInteger("Core", "gpu_refresh_rate", 30);
  59. Settings::values.frame_skip = glfw_config->GetInteger("Core", "frame_skip", 0);
  60. // Renderer
  61. Settings::values.use_hw_renderer = glfw_config->GetBoolean("Renderer", "use_hw_renderer", false);
  62. Settings::values.bg_red = (float)glfw_config->GetReal("Renderer", "bg_red", 1.0);
  63. Settings::values.bg_green = (float)glfw_config->GetReal("Renderer", "bg_green", 1.0);
  64. Settings::values.bg_blue = (float)glfw_config->GetReal("Renderer", "bg_blue", 1.0);
  65. // Data Storage
  66. Settings::values.use_virtual_sd = glfw_config->GetBoolean("Data Storage", "use_virtual_sd", true);
  67. // System Region
  68. Settings::values.region_value = glfw_config->GetInteger("System Region", "region_value", 1);
  69. // Miscellaneous
  70. Settings::values.log_filter = glfw_config->Get("Miscellaneous", "log_filter", "*:Info");
  71. }
  72. void Config::Reload() {
  73. LoadINI(glfw_config, glfw_config_loc.c_str(), DefaultINI::glfw_config_file);
  74. ReadValues();
  75. }
  76. Config::~Config() {
  77. delete glfw_config;
  78. }