From 1f74d46d3951a2b58e3a8ee2469348221c53220e Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Tue, 26 May 2020 23:23:44 -0700 Subject: [PATCH 1/5] AnalogController: Use proper upper bound when validating axis_code --- src/core/analog_controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/analog_controller.cpp b/src/core/analog_controller.cpp index 33a9d1568..808f7906f 100644 --- a/src/core/analog_controller.cpp +++ b/src/core/analog_controller.cpp @@ -67,7 +67,7 @@ std::optional AnalogController::GetButtonCodeByName(std::string_view button void AnalogController::SetAxisState(s32 axis_code, float value) { - if (axis_code < 0 || axis_code >= static_cast(Button::Count)) + if (axis_code < 0 || axis_code >= static_cast(Axis::Count)) return; // -1..1 -> 0..255 From ca873cf24387e4cbb1c4b02b326d56622c8816a3 Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Wed, 27 May 2020 00:31:00 -0700 Subject: [PATCH 2/5] InputProfiles: Update DualShock 4 input profile Profile also works for DualShock 3 on Linux. --- data/inputprofiles/DualShock 4.ini | 44 ++++++++++++++++-------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/data/inputprofiles/DualShock 4.ini b/data/inputprofiles/DualShock 4.ini index f21057e1e..fdfc31194 100644 --- a/data/inputprofiles/DualShock 4.ini +++ b/data/inputprofiles/DualShock 4.ini @@ -1,22 +1,24 @@ [Controller1] -Type=AnalogController -ButtonUp=Controller0/Button11 -ButtonDown=Controller0/Button12 -ButtonLeft=Controller0/Button13 -ButtonRight=Controller0/Button14 -ButtonSelect=Controller0/Button4 -ButtonStart=Controller0/Button6 -ButtonTriangle=Controller0/Button3 -ButtonCross=Controller0/Button0 -ButtonCircle=Controller0/Button1 -ButtonSquare=Controller0/Button2 -ButtonL1=Controller0/Button9 -ButtonL2=Controller0/+Axis4 -ButtonR1=Controller0/Button10 -ButtonR2=Controller0/+Axis5 -ButtonL3=Controller0/Button7 -ButtonR3=Controller0/Button8 -AxisLeftX=Controller0/Axis0 -AxisLeftY=Controller0/Axis1 -AxisRightX=Controller0/Axis2 -AxisRightY=Controller0/Axis3 +Type = AnalogController +ButtonUp = Controller0/Button11 +ButtonDown = Controller0/Button12 +ButtonLeft = Controller0/Button13 +ButtonRight = Controller0/Button14 +ButtonSelect = Controller0/Button4 +ButtonStart = Controller0/Button6 +ButtonTriangle = Controller0/Button3 +ButtonCross = Controller0/Button0 +ButtonCircle = Controller0/Button1 +ButtonSquare = Controller0/Button2 +ButtonL1 = Controller0/Button9 +ButtonL2 = Controller0/+Axis4 +ButtonR1 = Controller0/Button10 +ButtonR2 = Controller0/+Axis5 +ButtonL3 = Controller0/Button7 +ButtonR3 = Controller0/Button8 +ButtonAnalog = Controller0/Button5 +AxisLeftX = Controller0/Axis0 +AxisLeftY = Controller0/Axis1 +AxisRightX = Controller0/Axis2 +AxisRightY = Controller0/Axis3 +Rumble = Controller0 From b5311e5896a5e83dcae12b8dc7490ed26b0dd877 Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Wed, 27 May 2020 15:57:44 -0700 Subject: [PATCH 3/5] InputProfiles: Add PlayStation Classic Controller input profile --- .../PlayStation Classic Controller.ini | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 data/inputprofiles/PlayStation Classic Controller.ini diff --git a/data/inputprofiles/PlayStation Classic Controller.ini b/data/inputprofiles/PlayStation Classic Controller.ini new file mode 100644 index 000000000..7c7728f30 --- /dev/null +++ b/data/inputprofiles/PlayStation Classic Controller.ini @@ -0,0 +1,16 @@ +[Controller1] +Type = DigitalController +ButtonUp = Controller0/-Axis1 +ButtonDown = Controller0/+Axis1 +ButtonLeft = Controller0/-Axis0 +ButtonRight = Controller0/+Axis0 +ButtonSelect = Controller0/Button4 +ButtonStart = Controller0/Button6 +ButtonTriangle = Controller0/Button3 +ButtonCross = Controller0/Button0 +ButtonCircle = Controller0/Button1 +ButtonSquare = Controller0/Button2 +ButtonL1 = Controller0/Button9 +ButtonL2 = Controller0/+Axis4 +ButtonR1 = Controller0/Button10 +ButtonR2 = Controller0/+Axis5 From f8fea1b21595808d04109c0ecb66e3e5b954d2d0 Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Wed, 27 May 2020 16:36:41 -0700 Subject: [PATCH 4/5] INISettingsInterface: Return bool on saving settings --- src/frontend-common/ini_settings_interface.cpp | 10 +++++++--- src/frontend-common/ini_settings_interface.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/frontend-common/ini_settings_interface.cpp b/src/frontend-common/ini_settings_interface.cpp index 24f7a14bf..5c1daebea 100644 --- a/src/frontend-common/ini_settings_interface.cpp +++ b/src/frontend-common/ini_settings_interface.cpp @@ -16,13 +16,17 @@ INISettingsInterface::~INISettingsInterface() Save(); } -void INISettingsInterface::Save() +bool INISettingsInterface::Save() { SI_Error err = m_ini.SaveFile(m_filename.c_str(), false); if (err != SI_OK) + { Log_WarningPrintf("Failed to save settings to '%s'.", m_filename.c_str()); - else - m_dirty = false; + return false; + } + + m_dirty = false; + return true; } void INISettingsInterface::Clear() diff --git a/src/frontend-common/ini_settings_interface.h b/src/frontend-common/ini_settings_interface.h index 88dac946f..592c99d75 100644 --- a/src/frontend-common/ini_settings_interface.h +++ b/src/frontend-common/ini_settings_interface.h @@ -9,7 +9,7 @@ public: INISettingsInterface(std::string filename); ~INISettingsInterface(); - void Save(); + bool Save(); void Clear() override; From e1e3cf4f5a0c338d76c6667be007ea77936a63ae Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Wed, 27 May 2020 17:27:17 -0700 Subject: [PATCH 5/5] CommonHostInterface: Simplify input profile saving --- src/frontend-common/common_host_interface.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 246128198..97849586b 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -1068,15 +1068,12 @@ void CommonHostInterface::ApplyInputProfile(const char* profile_path, SettingsIn bool CommonHostInterface::SaveInputProfile(const char* profile_path, SettingsInterface& si) { if (FileSystem::FileExists(profile_path)) - { - if (!FileSystem::DeleteFile(profile_path)) - { - Log_ErrorPrintf("Failed to delete existing input profile '%s' when saving", profile_path); - return false; - } - } + Log_WarningPrintf("Existing input profile at '%s' will be overwritten", profile_path); + else + Log_WarningPrintf("Input profile at '%s' does not exist, new input profile will be created", profile_path); INISettingsInterface profile(profile_path); + profile.Clear(); for (u32 controller_index = 1; controller_index <= NUM_CONTROLLER_AND_CARD_PORTS; controller_index++) { @@ -1109,7 +1106,13 @@ bool CommonHostInterface::SaveInputProfile(const char* profile_path, SettingsInt profile.SetStringValue(section_name, "Rumble", rumble_value.c_str()); } - profile.Save(); + if(!profile.Save()) + { + Log_ErrorPrintf("Failed to save input profile to '%s'", profile_path); + return false; + } + + Log_SuccessPrintf("Input profile saved to '%s'", profile_path); return true; }