summaryrefslogtreecommitdiff
path: root/src/frontend_common/config.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend_common/config.cpp')
-rw-r--r--src/frontend_common/config.cpp78
1 files changed, 58 insertions, 20 deletions
diff --git a/src/frontend_common/config.cpp b/src/frontend_common/config.cpp
index 51576b4ee..905f35118 100644
--- a/src/frontend_common/config.cpp
+++ b/src/frontend_common/config.cpp
@@ -5,13 +5,14 @@
5#include <array> 5#include <array>
6#include "common/fs/fs.h" 6#include "common/fs/fs.h"
7#include "common/fs/path_util.h" 7#include "common/fs/path_util.h"
8#include "common/logging/log.h"
8#include "common/settings.h" 9#include "common/settings.h"
9#include "common/settings_common.h" 10#include "common/settings_common.h"
10#include "common/settings_enums.h" 11#include "common/settings_enums.h"
11#include "config.h" 12#include "config.h"
12#include "core/core.h" 13#include "core/core.h"
13#include "core/hle/service/acc/profile_manager.h" 14#include "core/hle/service/acc/profile_manager.h"
14#include "core/hle/service/hid/controllers/npad.h" 15#include "hid_core/resources/npad/npad.h"
15#include "network/network.h" 16#include "network/network.h"
16 17
17#include <boost/algorithm/string/replace.hpp> 18#include <boost/algorithm/string/replace.hpp>
@@ -58,6 +59,19 @@ void Config::Initialize(const std::optional<std::string> config_path) {
58} 59}
59 60
60void Config::WriteToIni() const { 61void Config::WriteToIni() const {
62 std::string config_type;
63 switch (type) {
64 case ConfigType::GlobalConfig:
65 config_type = "Global";
66 break;
67 case ConfigType::PerGameConfig:
68 config_type = "Game Specific";
69 break;
70 case ConfigType::InputProfile:
71 config_type = "Input Profile";
72 break;
73 }
74 LOG_INFO(Config, "Writing {} configuration to: {}", config_type, config_loc);
61 FILE* fp = nullptr; 75 FILE* fp = nullptr;
62#ifdef _WIN32 76#ifdef _WIN32
63 fp = _wfopen(Common::UTF8ToUTF16W(config_loc).data(), L"wb"); 77 fp = _wfopen(Common::UTF8ToUTF16W(config_loc).data(), L"wb");
@@ -117,10 +131,10 @@ void Config::ReadPlayerValues(const std::size_t player_index) {
117 player_prefix.append("player_").append(ToString(player_index)).append("_"); 131 player_prefix.append("player_").append(ToString(player_index)).append("_");
118 } 132 }
119 133
134 const auto profile_name = ReadStringSetting(std::string(player_prefix).append("profile_name"));
135
120 auto& player = Settings::values.players.GetValue()[player_index]; 136 auto& player = Settings::values.players.GetValue()[player_index];
121 if (IsCustomConfig()) { 137 if (IsCustomConfig()) {
122 const auto profile_name =
123 ReadStringSetting(std::string(player_prefix).append("profile_name"));
124 if (profile_name.empty()) { 138 if (profile_name.empty()) {
125 // Use the global input config 139 // Use the global input config
126 player = Settings::values.players.GetValue(true)[player_index]; 140 player = Settings::values.players.GetValue(true)[player_index];
@@ -139,6 +153,10 @@ void Config::ReadPlayerValues(const std::size_t player_index) {
139 player.controller_type = controller; 153 player.controller_type = controller;
140 } 154 }
141 } else { 155 } else {
156 if (global) {
157 auto& player_global = Settings::values.players.GetValue(true)[player_index];
158 player_global.profile_name = profile_name;
159 }
142 std::string connected_key = player_prefix; 160 std::string connected_key = player_prefix;
143 player.connected = ReadBooleanSetting(connected_key.append("connected"), 161 player.connected = ReadBooleanSetting(connected_key.append("connected"),
144 std::make_optional(player_index == 0)); 162 std::make_optional(player_index == 0));
@@ -280,6 +298,16 @@ void Config::ReadDebuggingValues() {
280 EndGroup(); 298 EndGroup();
281} 299}
282 300
301#ifdef __unix__
302void Config::ReadLinuxValues() {
303 BeginGroup(Settings::TranslateCategory(Settings::Category::Linux));
304
305 ReadCategory(Settings::Category::Linux);
306
307 EndGroup();
308}
309#endif
310
283void Config::ReadServiceValues() { 311void Config::ReadServiceValues() {
284 BeginGroup(Settings::TranslateCategory(Settings::Category::Services)); 312 BeginGroup(Settings::TranslateCategory(Settings::Category::Services));
285 313
@@ -386,6 +414,9 @@ void Config::ReadValues() {
386 ReadControlValues(); 414 ReadControlValues();
387 ReadCoreValues(); 415 ReadCoreValues();
388 ReadCpuValues(); 416 ReadCpuValues();
417#ifdef __unix__
418 ReadLinuxValues();
419#endif
389 ReadRendererValues(); 420 ReadRendererValues();
390 ReadAudioValues(); 421 ReadAudioValues();
391 ReadSystemValues(); 422 ReadSystemValues();
@@ -412,6 +443,11 @@ void Config::SavePlayerValues(const std::size_t player_index) {
412 std::make_optional(static_cast<u8>(Settings::ControllerType::ProController))); 443 std::make_optional(static_cast<u8>(Settings::ControllerType::ProController)));
413 444
414 if (!player_prefix.empty() || !Settings::IsConfiguringGlobal()) { 445 if (!player_prefix.empty() || !Settings::IsConfiguringGlobal()) {
446 if (global) {
447 const auto& player_global = Settings::values.players.GetValue(true)[player_index];
448 WriteStringSetting(std::string(player_prefix).append("profile_name"),
449 player_global.profile_name, std::make_optional(std::string("")));
450 }
415 WriteBooleanSetting(std::string(player_prefix).append("connected"), player.connected, 451 WriteBooleanSetting(std::string(player_prefix).append("connected"), player.connected,
416 std::make_optional(player_index == 0)); 452 std::make_optional(player_index == 0));
417 WriteIntegerSetting(std::string(player_prefix).append("vibration_enabled"), 453 WriteIntegerSetting(std::string(player_prefix).append("vibration_enabled"),
@@ -468,16 +504,22 @@ void Config::SaveMotionTouchValues() {
468 504
469void Config::SaveValues() { 505void Config::SaveValues() {
470 if (global) { 506 if (global) {
507 LOG_DEBUG(Config, "Saving global generic configuration values");
471 SaveDataStorageValues(); 508 SaveDataStorageValues();
472 SaveDebuggingValues(); 509 SaveDebuggingValues();
473 SaveDisabledAddOnValues(); 510 SaveDisabledAddOnValues();
474 SaveNetworkValues(); 511 SaveNetworkValues();
475 SaveWebServiceValues(); 512 SaveWebServiceValues();
476 SaveMiscellaneousValues(); 513 SaveMiscellaneousValues();
514 } else {
515 LOG_DEBUG(Config, "Saving only generic configuration values");
477 } 516 }
478 SaveControlValues(); 517 SaveControlValues();
479 SaveCoreValues(); 518 SaveCoreValues();
480 SaveCpuValues(); 519 SaveCpuValues();
520#ifdef __unix__
521 SaveLinuxValues();
522#endif
481 SaveRendererValues(); 523 SaveRendererValues();
482 SaveAudioValues(); 524 SaveAudioValues();
483 SaveSystemValues(); 525 SaveSystemValues();
@@ -552,6 +594,16 @@ void Config::SaveDebuggingValues() {
552 EndGroup(); 594 EndGroup();
553} 595}
554 596
597#ifdef __unix__
598void Config::SaveLinuxValues() {
599 BeginGroup(Settings::TranslateCategory(Settings::Category::Linux));
600
601 WriteCategory(Settings::Category::Linux);
602
603 EndGroup();
604}
605#endif
606
555void Config::SaveNetworkValues() { 607void Config::SaveNetworkValues() {
556 BeginGroup(Settings::TranslateCategory(Settings::Category::Services)); 608 BeginGroup(Settings::TranslateCategory(Settings::Category::Services));
557 609
@@ -762,17 +814,6 @@ void Config::WriteBooleanSetting(const std::string& key, const bool& value,
762 WritePreparedSetting(key, AdjustOutputString(ToString(value)), string_default, use_global); 814 WritePreparedSetting(key, AdjustOutputString(ToString(value)), string_default, use_global);
763} 815}
764 816
765template <typename T>
766std::enable_if_t<std::is_integral_v<T>> Config::WriteIntegerSetting(
767 const std::string& key, const T& value, const std::optional<T>& default_value,
768 const std::optional<bool>& use_global) {
769 std::optional<std::string> string_default = std::nullopt;
770 if (default_value.has_value()) {
771 string_default = std::make_optional(ToString(default_value.value()));
772 }
773 WritePreparedSetting(key, AdjustOutputString(ToString(value)), string_default, use_global);
774}
775
776void Config::WriteDoubleSetting(const std::string& key, const double& value, 817void Config::WriteDoubleSetting(const std::string& key, const double& value,
777 const std::optional<double>& default_value, 818 const std::optional<double>& default_value,
778 const std::optional<bool>& use_global) { 819 const std::optional<bool>& use_global) {
@@ -825,10 +866,6 @@ void Config::Reload() {
825 SaveValues(); 866 SaveValues();
826} 867}
827 868
828void Config::Save() {
829 SaveValues();
830}
831
832void Config::ClearControlPlayerValues() const { 869void Config::ClearControlPlayerValues() const {
833 // If key is an empty string, all keys in the current group() are removed. 870 // If key is an empty string, all keys in the current group() are removed.
834 const char* section = Settings::TranslateCategory(Settings::Category::Controls); 871 const char* section = Settings::TranslateCategory(Settings::Category::Controls);
@@ -894,9 +931,10 @@ void Config::WriteSettingGeneric(const Settings::BasicSetting* const setting) {
894 WriteBooleanSetting(std::string(key).append("\\use_global"), setting->UsingGlobal()); 931 WriteBooleanSetting(std::string(key).append("\\use_global"), setting->UsingGlobal());
895 } 932 }
896 if (global || !setting->UsingGlobal()) { 933 if (global || !setting->UsingGlobal()) {
934 auto value = global ? setting->ToStringGlobal() : setting->ToString();
897 WriteBooleanSetting(std::string(key).append("\\default"), 935 WriteBooleanSetting(std::string(key).append("\\default"),
898 setting->ToString() == setting->DefaultToString()); 936 value == setting->DefaultToString());
899 WriteStringSetting(key, setting->ToString()); 937 WriteStringSetting(key, value);
900 } 938 }
901 } else if (global) { 939 } else if (global) {
902 WriteBooleanSetting(std::string(key).append("\\default"), 940 WriteBooleanSetting(std::string(key).append("\\default"),