config.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "core/settings.h"
  8. #include "core/core.h"
  9. #include "config.h"
  10. Config::Config() {
  11. // TODO: Don't hardcode the path; let the frontend decide where to put the config files.
  12. glfw_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "glfw-config.ini";
  13. glfw_config = new INIReader(glfw_config_loc);
  14. Reload();
  15. }
  16. bool Config::LoadINI(INIReader* config, const char* location, const std::string& default_contents, bool retry) {
  17. if (config->ParseError() < 0) {
  18. if (retry) {
  19. LOG_WARNING(Config, "Failed to load %s. Creating file from defaults...", location);
  20. FileUtil::CreateFullPath(location);
  21. FileUtil::WriteStringToFile(true, default_contents, location);
  22. *config = INIReader(location); // Reopen file
  23. return LoadINI(config, location, default_contents, false);
  24. }
  25. LOG_ERROR(Config, "Failed.");
  26. return false;
  27. }
  28. LOG_INFO(Config, "Successfully loaded %s", location);
  29. return true;
  30. }
  31. void Config::ReadValues() {
  32. // Controls
  33. Settings::values.pad_a_key = glfw_config->GetInteger("Controls", "pad_a", GLFW_KEY_A);
  34. Settings::values.pad_b_key = glfw_config->GetInteger("Controls", "pad_b", GLFW_KEY_S);
  35. Settings::values.pad_x_key = glfw_config->GetInteger("Controls", "pad_x", GLFW_KEY_Z);
  36. Settings::values.pad_y_key = glfw_config->GetInteger("Controls", "pad_y", GLFW_KEY_X);
  37. Settings::values.pad_l_key = glfw_config->GetInteger("Controls", "pad_l", GLFW_KEY_Q);
  38. Settings::values.pad_r_key = glfw_config->GetInteger("Controls", "pad_r", GLFW_KEY_W);
  39. Settings::values.pad_start_key = glfw_config->GetInteger("Controls", "pad_start", GLFW_KEY_M);
  40. Settings::values.pad_select_key = glfw_config->GetInteger("Controls", "pad_select", GLFW_KEY_N);
  41. Settings::values.pad_home_key = glfw_config->GetInteger("Controls", "pad_home", GLFW_KEY_B);
  42. Settings::values.pad_dup_key = glfw_config->GetInteger("Controls", "pad_dup", GLFW_KEY_T);
  43. Settings::values.pad_ddown_key = glfw_config->GetInteger("Controls", "pad_ddown", GLFW_KEY_G);
  44. Settings::values.pad_dleft_key = glfw_config->GetInteger("Controls", "pad_dleft", GLFW_KEY_F);
  45. Settings::values.pad_dright_key = glfw_config->GetInteger("Controls", "pad_dright", GLFW_KEY_H);
  46. Settings::values.pad_sup_key = glfw_config->GetInteger("Controls", "pad_sup", GLFW_KEY_UP);
  47. Settings::values.pad_sdown_key = glfw_config->GetInteger("Controls", "pad_sdown", GLFW_KEY_DOWN);
  48. Settings::values.pad_sleft_key = glfw_config->GetInteger("Controls", "pad_sleft", GLFW_KEY_LEFT);
  49. Settings::values.pad_sright_key = glfw_config->GetInteger("Controls", "pad_sright", GLFW_KEY_RIGHT);
  50. // Core
  51. Settings::values.cpu_core = glfw_config->GetInteger("Core", "cpu_core", Core::CPU_Interpreter);
  52. Settings::values.gpu_refresh_rate = glfw_config->GetInteger("Core", "gpu_refresh_rate", 30);
  53. Settings::values.frame_skip = glfw_config->GetInteger("Core", "frame_skip", 0);
  54. // Data Storage
  55. Settings::values.use_virtual_sd = glfw_config->GetBoolean("Data Storage", "use_virtual_sd", true);
  56. // Miscellaneous
  57. Settings::values.log_filter = glfw_config->Get("Miscellaneous", "log_filter", "*:Info");
  58. }
  59. void Config::Reload() {
  60. LoadINI(glfw_config, glfw_config_loc.c_str(), DefaultINI::glfw_config_file);
  61. ReadValues();
  62. }
  63. Config::~Config() {
  64. delete glfw_config;
  65. }