From 574477866fe3e82a87214848d3d4b505535f2d3b Mon Sep 17 00:00:00 2001 From: Filoppi Date: Tue, 11 May 2021 16:30:29 +0300 Subject: InputCommon: fix serialization of control expression with line breaks The control expression editor allows line breaks, but the serialization was losing anything after the first line break (/r /n). Instead of opting to encode them and decode them on serialization (which I tried but was not safe, as it would lose /n written in the string by users), I opted to replace them with a space. --- .../Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp | 9 +++++++-- Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h | 9 ++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'Source/Core/InputCommon/ControllerEmu') diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp index 84c7238e48..2862445392 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp @@ -117,7 +117,10 @@ void ControlGroup::SaveConfig(IniFile::Section* sec, const std::string& defdev, for (auto& c : controls) { // control expression - sec->Set(group + c->name, c->control_ref->GetExpression(), ""); + std::string expression = c->control_ref->GetExpression(); + // We can't save line breaks in a single line config. Restoring them is too complicated. + ReplaceBreaksWithSpaces(expression); + sec->Set(group + c->name, expression, ""); // range sec->Set(group + c->name + "/Range", c->control_ref->range * 100.0, 100.0); @@ -135,7 +138,9 @@ void ControlGroup::SaveConfig(IniFile::Section* sec, const std::string& defdev, } else { - sec->Set(base + name, ext->GetSelectionSetting().GetInputReference().GetExpression(), "None"); + std::string expression = ext->GetSelectionSetting().GetInputReference().GetExpression(); + ReplaceBreaksWithSpaces(expression); + sec->Set(base + name, expression, "None"); } for (auto& ai : ext->GetAttachmentList()) diff --git a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h index 443f34d2ec..86bd2e39c3 100644 --- a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h +++ b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h @@ -113,9 +113,16 @@ public: void SaveToIni(IniFile::Section& section, const std::string& group_name) const override { if (IsSimpleValue()) + { section.Set(group_name + m_details.ini_name, GetValue(), m_default_value); + } else - section.Set(group_name + m_details.ini_name, m_value.m_input.GetExpression(), ""); + { + // We can't save line breaks in a single line config. Restoring them is too complicated. + std::string expression = m_value.m_input.GetExpression(); + ReplaceBreaksWithSpaces(expression); + section.Set(group_name + m_details.ini_name, expression, ""); + } } bool IsSimpleValue() const override { return m_value.IsSimpleValue(); } -- cgit v1.2.3