diff --git a/common/SettingsInterface.h b/common/SettingsInterface.h index 8ac443bc17..79747b2a52 100644 --- a/common/SettingsInterface.h +++ b/common/SettingsInterface.h @@ -42,11 +42,12 @@ public: virtual void SetBoolValue(const char* section, const char* key, bool value) = 0; virtual void SetStringValue(const char* section, const char* key, const char* value) = 0; - virtual std::vector GetStringList(const char* section, const char* key) = 0; + virtual std::vector GetStringList(const char* section, const char* key) const = 0; virtual void SetStringList(const char* section, const char* key, const std::vector& items) = 0; virtual bool RemoveFromStringList(const char* section, const char* key, const char* item) = 0; virtual bool AddToStringList(const char* section, const char* key, const char* item) = 0; + virtual bool ContainsValue(const char* section, const char* key) const = 0; virtual void DeleteValue(const char* section, const char* key) = 0; virtual void ClearSection(const char* section) = 0; @@ -153,4 +154,67 @@ public: { value.has_value() ? SetStringValue(section, key, value.value()) : DeleteValue(section, key); } + + __fi void CopyBoolValue(const SettingsInterface& si, const char* section, const char* key) + { + bool value; + if (si.GetBoolValue(section, key, &value)) + SetBoolValue(section, key, value); + else + DeleteValue(section, key); + } + + __fi void CopyIntValue(const SettingsInterface& si, const char* section, const char* key) + { + int value; + if (si.GetIntValue(section, key, &value)) + SetIntValue(section, key, value); + else + DeleteValue(section, key); + } + + __fi void CopyUIntValue(const SettingsInterface& si, const char* section, const char* key) + { + uint value; + if (si.GetUIntValue(section, key, &value)) + SetUIntValue(section, key, value); + else + DeleteValue(section, key); + } + + __fi void CopyFloatValue(const SettingsInterface& si, const char* section, const char* key) + { + float value; + if (si.GetFloatValue(section, key, &value)) + SetFloatValue(section, key, value); + else + DeleteValue(section, key); + } + + __fi void CopyDoubleValue(const SettingsInterface& si, const char* section, const char* key) + { + double value; + if (si.GetDoubleValue(section, key, &value)) + SetDoubleValue(section, key, value); + else + DeleteValue(section, key); + } + + __fi void CopyStringValue(const SettingsInterface& si, const char* section, const char* key) + { + std::string value; + if (si.GetStringValue(section, key, &value)) + SetStringValue(section, key, value.c_str()); + else + DeleteValue(section, key); + } + + __fi void CopyStringListValue(const SettingsInterface& si, const char* section, const char* key) + { + std::vector value(si.GetStringList(section, key)); + if (!value.empty()) + SetStringList(section, key, value); + else + DeleteValue(section, key); + } }; diff --git a/pcsx2/Frontend/INISettingsInterface.cpp b/pcsx2/Frontend/INISettingsInterface.cpp index 048807f65c..7a23c817ad 100644 --- a/pcsx2/Frontend/INISettingsInterface.cpp +++ b/pcsx2/Frontend/INISettingsInterface.cpp @@ -185,6 +185,11 @@ void INISettingsInterface::SetStringValue(const char* section, const char* key, m_ini.SetValue(section, key, value, nullptr, true); } +bool INISettingsInterface::ContainsValue(const char* section, const char* key) const +{ + return (m_ini.GetValue(section, key, nullptr) != nullptr); +} + void INISettingsInterface::DeleteValue(const char* section, const char* key) { m_dirty = true; diff --git a/pcsx2/Frontend/INISettingsInterface.h b/pcsx2/Frontend/INISettingsInterface.h index 5c6dd4e710..e258ed23e8 100644 --- a/pcsx2/Frontend/INISettingsInterface.h +++ b/pcsx2/Frontend/INISettingsInterface.h @@ -48,6 +48,7 @@ public: void SetDoubleValue(const char* section, const char* key, double value) override; void SetBoolValue(const char* section, const char* key, bool value) override; void SetStringValue(const char* section, const char* key, const char* value) override; + bool ContainsValue(const char* section, const char* key) const override; void DeleteValue(const char* section, const char* key) override; void ClearSection(const char* section) override; diff --git a/pcsx2/Frontend/LayeredSettingsInterface.cpp b/pcsx2/Frontend/LayeredSettingsInterface.cpp index d1e9ad9ae8..453e76c546 100644 --- a/pcsx2/Frontend/LayeredSettingsInterface.cpp +++ b/pcsx2/Frontend/LayeredSettingsInterface.cpp @@ -147,6 +147,19 @@ void LayeredSettingsInterface::SetStringValue(const char* section, const char* k pxFailRel("Attempt to call SetStringValue() on layered settings interface"); } +bool LayeredSettingsInterface::ContainsValue(const char* section, const char* key) const +{ + for (u32 layer = FIRST_LAYER; layer <= LAST_LAYER; layer++) + { + if (SettingsInterface* sif = m_layers[layer]; sif != nullptr) + { + if (sif->ContainsValue(key, section)) + return true; + } + } + return false; +} + void LayeredSettingsInterface::DeleteValue(const char* section, const char* key) { pxFailRel("Attempt to call DeleteValue() on layered settings interface"); @@ -157,7 +170,7 @@ void LayeredSettingsInterface::ClearSection(const char* section) pxFailRel("Attempt to call ClearSection() on layered settings interface"); } -std::vector LayeredSettingsInterface::GetStringList(const char* section, const char* key) +std::vector LayeredSettingsInterface::GetStringList(const char* section, const char* key) const { std::vector ret; diff --git a/pcsx2/Frontend/LayeredSettingsInterface.h b/pcsx2/Frontend/LayeredSettingsInterface.h index f23ebc59d3..a18aab455d 100644 --- a/pcsx2/Frontend/LayeredSettingsInterface.h +++ b/pcsx2/Frontend/LayeredSettingsInterface.h @@ -52,10 +52,11 @@ public: void SetDoubleValue(const char* section, const char* key, double value) override; void SetBoolValue(const char* section, const char* key, bool value) override; void SetStringValue(const char* section, const char* key, const char* value) override; + bool ContainsValue(const char* section, const char* key) const override; void DeleteValue(const char* section, const char* key) override; void ClearSection(const char* section) override; - std::vector GetStringList(const char* section, const char* key) override; + std::vector GetStringList(const char* section, const char* key) const override; void SetStringList(const char* section, const char* key, const std::vector& items) override; bool RemoveFromStringList(const char* section, const char* key, const char* item) override; bool AddToStringList(const char* section, const char* key, const char* item) override; diff --git a/pcsx2/HostSettings.cpp b/pcsx2/HostSettings.cpp index 77ec09ecf0..2e0273775e 100644 --- a/pcsx2/HostSettings.cpp +++ b/pcsx2/HostSettings.cpp @@ -32,6 +32,12 @@ SettingsInterface* Host::GetSettingsInterface() return &s_layered_settings_interface; } +SettingsInterface* Host::GetSettingsInterfaceForBindings() +{ + SettingsInterface* input_layer = s_layered_settings_interface.GetLayer(LayeredSettingsInterface::LAYER_INPUT); + return input_layer ? input_layer : &s_layered_settings_interface; +} + std::string Host::GetBaseStringSettingValue(const char* section, const char* key, const char* default_value /*= ""*/) { std::unique_lock lock(s_settings_mutex); @@ -169,6 +175,16 @@ SettingsInterface* Host::Internal::GetBaseSettingsLayer() return s_layered_settings_interface.GetLayer(LayeredSettingsInterface::LAYER_BASE); } +SettingsInterface* Host::Internal::GetGameSettingsLayer() +{ + return s_layered_settings_interface.GetLayer(LayeredSettingsInterface::LAYER_GAME); +} + +SettingsInterface* Host::Internal::GetInputSettingsLayer() +{ + return s_layered_settings_interface.GetLayer(LayeredSettingsInterface::LAYER_INPUT); +} + void Host::Internal::SetBaseSettingsLayer(SettingsInterface* sif) { pxAssertRel(s_layered_settings_interface.GetLayer(LayeredSettingsInterface::LAYER_BASE) == nullptr, "Base layer has not been set"); diff --git a/pcsx2/HostSettings.h b/pcsx2/HostSettings.h index 26967a2e65..e99c0c0bd5 100644 --- a/pcsx2/HostSettings.h +++ b/pcsx2/HostSettings.h @@ -56,11 +56,21 @@ namespace Host std::unique_lock GetSettingsLock(); SettingsInterface* GetSettingsInterface(); + /// Returns the settings interface that controller bindings should be loaded from. + /// If an input profile is being used, this will be the input layer, otherwise the layered interface. + SettingsInterface* GetSettingsInterfaceForBindings(); + namespace Internal { /// Retrieves the base settings layer. Must call with lock held. SettingsInterface* GetBaseSettingsLayer(); + /// Retrieves the game settings layer, if present. Must call with lock held. + SettingsInterface* GetGameSettingsLayer(); + + /// Retrieves the input settings layer, if present. Must call with lock held. + SettingsInterface* GetInputSettingsLayer(); + /// Sets the base settings layer. Should be called by the host at initialization time. void SetBaseSettingsLayer(SettingsInterface* sif); diff --git a/pcsx2/gui/wxSettingsInterface.cpp b/pcsx2/gui/wxSettingsInterface.cpp index ac74a2278a..c2c238e164 100644 --- a/pcsx2/gui/wxSettingsInterface.cpp +++ b/pcsx2/gui/wxSettingsInterface.cpp @@ -141,7 +141,7 @@ void wxSettingsInterface::SetStringValue(const char* section, const char* key, c m_config->Write(key, wxString::FromUTF8(value)); } -std::vector wxSettingsInterface::GetStringList(const char* section, const char* key) +std::vector wxSettingsInterface::GetStringList(const char* section, const char* key) const { pxFailRel("Not implemented"); return {}; @@ -163,6 +163,12 @@ bool wxSettingsInterface::AddToStringList(const char* section, const char* key, return false; } +bool wxSettingsInterface::ContainsValue(const char* section, const char* key) const +{ + CheckPath(section); + return m_config->Exists(key); +} + void wxSettingsInterface::DeleteValue(const char* section, const char* key) { CheckPath(section); diff --git a/pcsx2/gui/wxSettingsInterface.h b/pcsx2/gui/wxSettingsInterface.h index 416501eec1..258dcc45d0 100644 --- a/pcsx2/gui/wxSettingsInterface.h +++ b/pcsx2/gui/wxSettingsInterface.h @@ -44,11 +44,12 @@ public: void SetStringValue(const char* section, const char* key, const char* value) override; - std::vector GetStringList(const char* section, const char* key) override; + std::vector GetStringList(const char* section, const char* key) const override; void SetStringList(const char* section, const char* key, const std::vector& items) override; bool RemoveFromStringList(const char* section, const char* key, const char* item) override; bool AddToStringList(const char* section, const char* key, const char* item) override; + bool ContainsValue(const char* section, const char* key) const override; void DeleteValue(const char* section, const char* key) override; void ClearSection(const char* section) override;