From 2bcf70af3f4b80870d93b17c367c9822a6ba4f41 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 4 Feb 2024 15:29:36 +0100 Subject: [PATCH 1/3] InputCommon: Refactor away InputConfig::LoadConfig's switch case By having getters for this information, other code that needs access to the same information can call the getters instead of duplicating the information. --- Source/Core/Core/FreeLookManager.cpp | 7 +-- Source/Core/Core/HW/GBAPad.cpp | 6 +-- Source/Core/Core/HW/GCKeyboard.cpp | 6 +-- Source/Core/Core/HW/GCPad.cpp | 6 +-- Source/Core/Core/HW/Wiimote.cpp | 5 +- Source/Core/Core/HotkeyManager.cpp | 4 +- Source/Core/InputCommon/InputConfig.cpp | 64 +++++++++++++++---------- Source/Core/InputCommon/InputConfig.h | 16 ++++--- 8 files changed, 68 insertions(+), 46 deletions(-) diff --git a/Source/Core/Core/FreeLookManager.cpp b/Source/Core/Core/FreeLookManager.cpp index 4c5596588d..fd996bdab9 100644 --- a/Source/Core/Core/FreeLookManager.cpp +++ b/Source/Core/Core/FreeLookManager.cpp @@ -312,7 +312,8 @@ void FreeLookController::UpdateInput(CameraControllerInput* camera_controller) namespace FreeLook { -static InputConfig s_config("FreeLookController", _trans("FreeLook"), "FreeLookController"); +static InputConfig s_config("FreeLookController", _trans("FreeLook"), "FreeLookController", + InputConfig::InputClass::GC); InputConfig* GetInputConfig() { return &s_config; @@ -336,12 +337,12 @@ void Initialize() FreeLook::GetConfig().Refresh(); - s_config.LoadConfig(InputConfig::InputClass::GC); + s_config.LoadConfig(); } void LoadInputConfig() { - s_config.LoadConfig(InputConfig::InputClass::GC); + s_config.LoadConfig(); } bool IsInitialized() diff --git a/Source/Core/Core/HW/GBAPad.cpp b/Source/Core/Core/HW/GBAPad.cpp index 7f25b56fd1..04d68c4260 100644 --- a/Source/Core/Core/HW/GBAPad.cpp +++ b/Source/Core/Core/HW/GBAPad.cpp @@ -10,7 +10,7 @@ namespace Pad { -static InputConfig s_config("GBA", _trans("Pad"), "GBA"); +static InputConfig s_config("GBA", _trans("Pad"), "GBA", InputConfig::InputClass::GBA); InputConfig* GetGBAConfig() { return &s_config; @@ -34,12 +34,12 @@ void InitializeGBA() s_config.RegisterHotplugCallback(); // Load the saved controller config - s_config.LoadConfig(InputConfig::InputClass::GBA); + s_config.LoadConfig(); } void LoadGBAConfig() { - s_config.LoadConfig(InputConfig::InputClass::GBA); + s_config.LoadConfig(); } bool IsGBAInitialized() diff --git a/Source/Core/Core/HW/GCKeyboard.cpp b/Source/Core/Core/HW/GCKeyboard.cpp index f99193f4d4..897d2d6850 100644 --- a/Source/Core/Core/HW/GCKeyboard.cpp +++ b/Source/Core/Core/HW/GCKeyboard.cpp @@ -17,7 +17,7 @@ namespace Keyboard { -static InputConfig s_config("GCKeyNew", _trans("Keyboard"), "GCKey"); +static InputConfig s_config("GCKeyNew", _trans("Keyboard"), "GCKey", InputConfig::InputClass::GC); InputConfig* GetConfig() { return &s_config; @@ -41,12 +41,12 @@ void Initialize() s_config.RegisterHotplugCallback(); // Load the saved controller config - s_config.LoadConfig(InputConfig::InputClass::GC); + s_config.LoadConfig(); } void LoadConfig() { - s_config.LoadConfig(InputConfig::InputClass::GC); + s_config.LoadConfig(); } ControllerEmu::ControlGroup* GetGroup(int port, KeyboardGroup group) diff --git a/Source/Core/Core/HW/GCPad.cpp b/Source/Core/Core/HW/GCPad.cpp index faf50f3c02..cddb085be8 100644 --- a/Source/Core/Core/HW/GCPad.cpp +++ b/Source/Core/Core/HW/GCPad.cpp @@ -14,7 +14,7 @@ namespace Pad { -static InputConfig s_config("GCPadNew", _trans("Pad"), "GCPad"); +static InputConfig s_config("GCPadNew", _trans("Pad"), "GCPad", InputConfig::InputClass::GC); InputConfig* GetConfig() { return &s_config; @@ -38,12 +38,12 @@ void Initialize() s_config.RegisterHotplugCallback(); // Load the saved controller config - s_config.LoadConfig(InputConfig::InputClass::GC); + s_config.LoadConfig(); } void LoadConfig() { - s_config.LoadConfig(InputConfig::InputClass::GC); + s_config.LoadConfig(); } bool IsInitialized() diff --git a/Source/Core/Core/HW/Wiimote.cpp b/Source/Core/Core/HW/Wiimote.cpp index 86f9c6a56c..0638ab788b 100644 --- a/Source/Core/Core/HW/Wiimote.cpp +++ b/Source/Core/Core/HW/Wiimote.cpp @@ -97,7 +97,8 @@ HIDWiimote* GetHIDWiimoteSource(unsigned int index) namespace Wiimote { -static InputConfig s_config(WIIMOTE_INI_NAME, _trans("Wii Remote"), "Wiimote"); +static InputConfig s_config(WIIMOTE_INI_NAME, _trans("Wii Remote"), "Wiimote", + InputConfig::InputClass::Wii); InputConfig* GetConfig() { @@ -206,7 +207,7 @@ void ResetAllWiimotes() void LoadConfig() { - s_config.LoadConfig(InputConfig::InputClass::Wii); + s_config.LoadConfig(); s_last_connect_request_counter.fill(0); } diff --git a/Source/Core/Core/HotkeyManager.cpp b/Source/Core/Core/HotkeyManager.cpp index 668c500390..45e1c4dd9a 100644 --- a/Source/Core/Core/HotkeyManager.cpp +++ b/Source/Core/Core/HotkeyManager.cpp @@ -207,7 +207,7 @@ static std::array s_hotkey_down; static HotkeyStatus s_hotkey; static bool s_enabled; -static InputConfig s_config("Hotkeys", _trans("Hotkeys"), "Hotkeys"); +static InputConfig s_config("Hotkeys", _trans("Hotkeys"), "Hotkeys", InputConfig::InputClass::GC); InputConfig* GetConfig() { @@ -304,7 +304,7 @@ void Initialize() void LoadConfig() { - s_config.LoadConfig(InputConfig::InputClass::GC); + s_config.LoadConfig(); LoadLegacyConfig(s_config.GetController(0)); } diff --git a/Source/Core/InputCommon/InputConfig.cpp b/Source/Core/InputCommon/InputConfig.cpp index f372fa3c1f..0acd67c392 100644 --- a/Source/Core/InputCommon/InputConfig.cpp +++ b/Source/Core/InputCommon/InputConfig.cpp @@ -20,57 +20,40 @@ #include "InputCommon/InputProfile.h" InputConfig::InputConfig(const std::string& ini_name, const std::string& gui_name, - const std::string& profile_name) - : m_ini_name(ini_name), m_gui_name(gui_name), m_profile_name(profile_name) + const std::string& profile_name, InputClass input_class) + : m_ini_name(ini_name), m_gui_name(gui_name), m_profile_name(profile_name), + m_input_class(input_class) { } InputConfig::~InputConfig() = default; -bool InputConfig::LoadConfig(InputClass type) +bool InputConfig::LoadConfig() { Common::IniFile inifile; bool useProfile[MAX_BBMOTES] = {false, false, false, false, false}; static constexpr std::array num = {"1", "2", "3", "4", "BB"}; std::string profile[MAX_BBMOTES]; - std::string path; m_dynamic_input_tex_config_manager.Load(); if (SConfig::GetInstance().GetGameID() != "00000000") { - std::string type_str; - switch (type) - { - case InputClass::GBA: - type_str = "GBA"; - path = "Profiles/GBA/"; - break; - case InputClass::Wii: - type_str = "Wiimote"; - path = "Profiles/Wiimote/"; - break; - case InputClass::GC: - default: - type_str = "Pad"; - path = "Profiles/GCPad/"; - break; - } + const std::string profile_directory = GetProfileDirectoryPath(); Common::IniFile game_ini = SConfig::GetInstance().LoadGameIni(); auto* control_section = game_ini.GetOrCreateSection("Controls"); for (int i = 0; i < 4; i++) { - const auto profile_name = fmt::format("{}Profile{}", type_str, num[i]); + const auto profile_name = fmt::format("{}Profile{}", GetProfileKey(), num[i]); if (control_section->Exists(profile_name)) { std::string profile_setting; if (control_section->Get(profile_name, &profile_setting)) { - auto profiles = InputProfile::GetProfilesFromSetting( - profile_setting, File::GetUserPath(D_CONFIG_IDX) + path); + auto profiles = InputProfile::GetProfilesFromSetting(profile_setting, profile_directory); if (profiles.empty()) { @@ -176,6 +159,39 @@ bool InputConfig::ControllersNeedToBeCreated() const return m_controllers.empty(); } +std::string InputConfig::GetProfileKey() const +{ + switch (m_input_class) + { + case InputClass::GBA: + return "GBA"; + case InputClass::Wii: + return "Wiimote"; + case InputClass::GC: + default: + return "Pad"; + } +} + +std::string InputConfig::GetProfileDirectoryName() const +{ + switch (m_input_class) + { + case InputClass::GBA: + return "GBA"; + case InputClass::Wii: + return "Wiimote"; + case InputClass::GC: + default: + return "GCPad"; + } +} + +std::string InputConfig::GetProfileDirectoryPath() const +{ + return fmt::format("{}Profiles/{}/", File::GetUserPath(D_CONFIG_IDX), GetProfileDirectoryName()); +} + int InputConfig::GetControllerCount() const { return static_cast(m_controllers.size()); diff --git a/Source/Core/InputCommon/InputConfig.h b/Source/Core/InputCommon/InputConfig.h index a0d0203df6..85be1ad505 100644 --- a/Source/Core/InputCommon/InputConfig.h +++ b/Source/Core/InputCommon/InputConfig.h @@ -24,11 +24,6 @@ class EmulatedController; class InputConfig { public: - InputConfig(const std::string& ini_name, const std::string& gui_name, - const std::string& profile_name); - - ~InputConfig(); - enum class InputClass { GC, @@ -36,7 +31,12 @@ public: GBA, }; - bool LoadConfig(InputClass type); + InputConfig(const std::string& ini_name, const std::string& gui_name, + const std::string& profile_name, InputClass input_class); + + ~InputConfig(); + + bool LoadConfig(); void SaveConfig(); template @@ -52,6 +52,9 @@ public: std::string GetGUIName() const { return m_gui_name; } std::string GetProfileName() const { return m_profile_name; } + std::string GetProfileKey() const; + std::string GetProfileDirectoryName() const; + std::string GetProfileDirectoryPath() const; int GetControllerCount() const; // These should be used after creating all controllers and before clearing them, respectively. @@ -66,5 +69,6 @@ private: const std::string m_ini_name; const std::string m_gui_name; const std::string m_profile_name; + const InputClass m_input_class; InputCommon::DynamicInputTextureManager m_dynamic_input_tex_config_manager; }; From 6cf55ab1ee13e62b272642ae4f1fadcc792b5e28 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 4 Feb 2024 16:31:15 +0100 Subject: [PATCH 2/3] InputCommon: Unify GetProfileName and GetProfileDirectoryName After reading the previous commit, you might think "hold on, what's the difference between GetProfileName and GetProfileDirectoryName"? These two are being used for the exact same thing - figuring out where profiles are stored - yet they return different values for certain controllers like GC keyboards! As far as I can tell, the existing code has been broken for GC keyboards since they were introduced a decade ago. The GUI (and more recently, also InputCycler) would write and read profiles in one location, and our code for loading profiles specified in a game INI file would read profiles in another location. This commit gets rid of the set of values used by the game INI code in favor of the other set. This does breaking existing setups where a GCKey profile has been configured in a game INI, but I think the number of working such setups is vanishingly small. The alternative would make existing GCKey profiles go missing from the profile dropdown in the GUI, which I think would be more disruptive. The alternative would also force new GCKey profiles into the same directory as GCPad profiles. This commit also fixes a regression from d6c0f8e749. The Android GUI was using GetProfileName to figure out what key to use in the game INI, which made it use incorrect game INI entries for GameCube controller profiles but not Wii Remote profiles. Now the Android GUI uses GetProfileKey for this, fixing the problem. --- .../model/controlleremu/EmulatedController.kt | 6 ++++- .../input/ui/ProfileDialogPresenter.kt | 6 ++--- .../settings/ui/SettingsFragmentPresenter.kt | 2 +- .../Android/jni/Input/EmulatedController.cpp | 20 ++++++++++++-- .../Config/Mapping/MappingWindow.cpp | 13 ++++----- Source/Core/InputCommon/InputConfig.cpp | 27 +++++++------------ Source/Core/InputCommon/InputConfig.h | 10 +++---- Source/Core/InputCommon/InputProfile.cpp | 8 +++--- 8 files changed, 50 insertions(+), 42 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.kt index e84dd201a5..4b2c6ec92c 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.kt @@ -30,7 +30,11 @@ class EmulatedController private constructor(private val pointer: Long) { external fun saveProfile(path: String) - external fun getProfileName(): String + external fun getProfileKey(): String + + external fun getUserProfileDirectoryPath(): String + + external fun getSysProfileDirectoryPath(): String companion object { @JvmStatic diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileDialogPresenter.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileDialogPresenter.kt index 2896c815fe..5c0a50a8b8 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileDialogPresenter.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileDialogPresenter.kt @@ -101,11 +101,11 @@ class ProfileDialogPresenter { } private fun getProfileDirectoryPath(stock: Boolean): String { - val profileDirectoryName = menuTag.correspondingEmulatedController.getProfileName() + val controller = menuTag.correspondingEmulatedController return if (stock) { - "${DirectoryInitialization.getSysDirectory()}/Profiles/$profileDirectoryName/" + controller.getSysProfileDirectoryPath() } else { - "${DirectoryInitialization.getUserDirectory()}/Config/Profiles/$profileDirectoryName/" + controller.getUserProfileDirectoryPath() } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt index 1051f445ae..44e2b2b915 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt @@ -2237,7 +2237,7 @@ class SettingsFragmentPresenter( controllerNumber: Int ) { val profiles = ProfileDialogPresenter(menuTag).getProfileNames(false) - val profileKey = controller.getProfileName() + "Profile" + (controllerNumber + 1) + val profileKey = controller.getProfileKey() + "Profile" + (controllerNumber + 1) sl.add( StringSingleChoiceSetting( context, diff --git a/Source/Android/jni/Input/EmulatedController.cpp b/Source/Android/jni/Input/EmulatedController.cpp index c1dfd7ce5d..8a76240dfd 100644 --- a/Source/Android/jni/Input/EmulatedController.cpp +++ b/Source/Android/jni/Input/EmulatedController.cpp @@ -126,10 +126,26 @@ Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedContro } JNIEXPORT jstring JNICALL -Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getProfileName( +Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getProfileKey( JNIEnv* env, jobject obj) { - return ToJString(env, EmulatedControllerFromJava(env, obj)->GetConfig()->GetProfileName()); + return ToJString(env, EmulatedControllerFromJava(env, obj)->GetConfig()->GetProfileKey()); +} + +JNIEXPORT jstring JNICALL +Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getUserProfileDirectoryPath( + JNIEnv* env, jobject obj) +{ + return ToJString( + env, EmulatedControllerFromJava(env, obj)->GetConfig()->GetUserProfileDirectoryPath()); +} + +JNIEXPORT jstring JNICALL +Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getSysProfileDirectoryPath( + JNIEnv* env, jobject obj) +{ + return ToJString(env, + EmulatedControllerFromJava(env, obj)->GetConfig()->GetSysProfileDirectoryPath()); } JNIEXPORT jobject JNICALL diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingWindow.cpp b/Source/Core/DolphinQt/Config/Mapping/MappingWindow.cpp index 8413db981d..6c815e4a15 100644 --- a/Source/Core/DolphinQt/Config/Mapping/MappingWindow.cpp +++ b/Source/Core/DolphinQt/Config/Mapping/MappingWindow.cpp @@ -319,9 +319,8 @@ void MappingWindow::OnSaveProfilePressed() if (profile_name.isEmpty()) return; - const std::string profile_path = File::GetUserPath(D_CONFIG_IDX) + PROFILES_DIR + - m_config->GetProfileName() + "/" + profile_name.toStdString() + - ".ini"; + const std::string profile_path = + m_config->GetUserProfileDirectoryPath() + profile_name.toStdString() + ".ini"; File::CreateFullPath(profile_path); @@ -487,8 +486,7 @@ void MappingWindow::PopulateProfileSelection() { m_profiles_combo->clear(); - const std::string profiles_path = - File::GetUserPath(D_CONFIG_IDX) + PROFILES_DIR + m_config->GetProfileName(); + const std::string profiles_path = m_config->GetUserProfileDirectoryPath(); for (const auto& filename : Common::DoFileSearch({profiles_path}, {".ini"})) { std::string basename; @@ -499,9 +497,8 @@ void MappingWindow::PopulateProfileSelection() m_profiles_combo->insertSeparator(m_profiles_combo->count()); - const std::string builtin_profiles_path = - File::GetSysDirectory() + PROFILES_DIR + m_config->GetProfileName(); - for (const auto& filename : Common::DoFileSearch({builtin_profiles_path}, {".ini"})) + for (const auto& filename : + Common::DoFileSearch({m_config->GetSysProfileDirectoryPath()}, {".ini"})) { std::string basename; SplitPath(filename, nullptr, &basename, nullptr); diff --git a/Source/Core/InputCommon/InputConfig.cpp b/Source/Core/InputCommon/InputConfig.cpp index 0acd67c392..651e2821c2 100644 --- a/Source/Core/InputCommon/InputConfig.cpp +++ b/Source/Core/InputCommon/InputConfig.cpp @@ -20,8 +20,8 @@ #include "InputCommon/InputProfile.h" InputConfig::InputConfig(const std::string& ini_name, const std::string& gui_name, - const std::string& profile_name, InputClass input_class) - : m_ini_name(ini_name), m_gui_name(gui_name), m_profile_name(profile_name), + const std::string& profile_directory_name, InputClass input_class) + : m_ini_name(ini_name), m_gui_name(gui_name), m_profile_directory_name(profile_directory_name), m_input_class(input_class) { } @@ -39,7 +39,7 @@ bool InputConfig::LoadConfig() if (SConfig::GetInstance().GetGameID() != "00000000") { - const std::string profile_directory = GetProfileDirectoryPath(); + const std::string profile_directory = GetUserProfileDirectoryPath(); Common::IniFile game_ini = SConfig::GetInstance().LoadGameIni(); auto* control_section = game_ini.GetOrCreateSection("Controls"); @@ -173,25 +173,16 @@ std::string InputConfig::GetProfileKey() const } } -std::string InputConfig::GetProfileDirectoryName() const -{ - switch (m_input_class) - { - case InputClass::GBA: - return "GBA"; - case InputClass::Wii: - return "Wiimote"; - case InputClass::GC: - default: - return "GCPad"; - } -} - -std::string InputConfig::GetProfileDirectoryPath() const +std::string InputConfig::GetUserProfileDirectoryPath() const { return fmt::format("{}Profiles/{}/", File::GetUserPath(D_CONFIG_IDX), GetProfileDirectoryName()); } +std::string InputConfig::GetSysProfileDirectoryPath() const +{ + return fmt::format("{}Profiles/{}/", File::GetSysDirectory(), GetProfileDirectoryName()); +} + int InputConfig::GetControllerCount() const { return static_cast(m_controllers.size()); diff --git a/Source/Core/InputCommon/InputConfig.h b/Source/Core/InputCommon/InputConfig.h index 85be1ad505..ff8c4be65d 100644 --- a/Source/Core/InputCommon/InputConfig.h +++ b/Source/Core/InputCommon/InputConfig.h @@ -32,7 +32,7 @@ public: }; InputConfig(const std::string& ini_name, const std::string& gui_name, - const std::string& profile_name, InputClass input_class); + const std::string& profile_directory_name, InputClass input_class); ~InputConfig(); @@ -51,10 +51,10 @@ public: bool IsControllerControlledByGamepadDevice(int index) const; std::string GetGUIName() const { return m_gui_name; } - std::string GetProfileName() const { return m_profile_name; } std::string GetProfileKey() const; - std::string GetProfileDirectoryName() const; - std::string GetProfileDirectoryPath() const; + std::string GetProfileDirectoryName() const { return m_profile_directory_name; } + std::string GetUserProfileDirectoryPath() const; + std::string GetSysProfileDirectoryPath() const; int GetControllerCount() const; // These should be used after creating all controllers and before clearing them, respectively. @@ -68,7 +68,7 @@ private: std::vector> m_controllers; const std::string m_ini_name; const std::string m_gui_name; - const std::string m_profile_name; + const std::string m_profile_directory_name; const InputClass m_input_class; InputCommon::DynamicInputTextureManager m_dynamic_input_tex_config_manager; }; diff --git a/Source/Core/InputCommon/InputProfile.cpp b/Source/Core/InputCommon/InputProfile.cpp index 81d04cf75a..0d439c48e1 100644 --- a/Source/Core/InputCommon/InputProfile.cpp +++ b/Source/Core/InputCommon/InputProfile.cpp @@ -55,8 +55,8 @@ std::vector GetProfilesFromSetting(const std::string& setting, cons std::vector ProfileCycler::GetProfilesForDevice(InputConfig* device_configuration) { - const std::string device_profile_root_location(File::GetUserPath(D_CONFIG_IDX) + "Profiles/" + - device_configuration->GetProfileName()); + const std::string device_profile_root_location( + device_configuration->GetUserProfileDirectoryPath()); return Common::DoFileSearch({device_profile_root_location}, {".ini"}, true); } @@ -101,8 +101,8 @@ ProfileCycler::GetMatchingProfilesFromSetting(const std::string& setting, const std::vector& profiles, InputConfig* device_configuration) { - const std::string device_profile_root_location(File::GetUserPath(D_CONFIG_IDX) + "Profiles/" + - device_configuration->GetProfileName() + "/"); + const std::string device_profile_root_location( + device_configuration->GetUserProfileDirectoryPath()); const auto& profiles_from_setting = GetProfilesFromSetting(setting, device_profile_root_location); if (profiles_from_setting.empty()) From 1315b54ffaa2833ddda7e543945c88ed5396efd6 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 4 Feb 2024 17:36:15 +0100 Subject: [PATCH 3/3] InputCommon: Use distinct values for profile key Because the last commit made us use separate folders for GCPad and GCKey profiles, we should also use separate game INI keys for them. Otherwise setting e.g. PadProfile1 in a game INI will make both GCPad and GCKey try to load it, typically with one of them succeeding and the other one showing a panic alert due to the profile not existing in its folder. Better do this breaking change for GCKeys in the same PR as the other breaking change rather than later. --- Source/Core/Core/FreeLookManager.cpp | 2 +- Source/Core/Core/HW/GBAPad.cpp | 2 +- Source/Core/Core/HW/GCKeyboard.cpp | 2 +- Source/Core/Core/HW/GCPad.cpp | 2 +- Source/Core/Core/HW/Wiimote.cpp | 3 +-- Source/Core/Core/HotkeyManager.cpp | 2 +- Source/Core/InputCommon/InputConfig.cpp | 18 ++---------------- Source/Core/InputCommon/InputConfig.h | 13 +++---------- 8 files changed, 11 insertions(+), 33 deletions(-) diff --git a/Source/Core/Core/FreeLookManager.cpp b/Source/Core/Core/FreeLookManager.cpp index fd996bdab9..d69c3cec13 100644 --- a/Source/Core/Core/FreeLookManager.cpp +++ b/Source/Core/Core/FreeLookManager.cpp @@ -313,7 +313,7 @@ void FreeLookController::UpdateInput(CameraControllerInput* camera_controller) namespace FreeLook { static InputConfig s_config("FreeLookController", _trans("FreeLook"), "FreeLookController", - InputConfig::InputClass::GC); + "FreeLookController"); InputConfig* GetInputConfig() { return &s_config; diff --git a/Source/Core/Core/HW/GBAPad.cpp b/Source/Core/Core/HW/GBAPad.cpp index 04d68c4260..77585a27f0 100644 --- a/Source/Core/Core/HW/GBAPad.cpp +++ b/Source/Core/Core/HW/GBAPad.cpp @@ -10,7 +10,7 @@ namespace Pad { -static InputConfig s_config("GBA", _trans("Pad"), "GBA", InputConfig::InputClass::GBA); +static InputConfig s_config("GBA", _trans("Pad"), "GBA", "GBA"); InputConfig* GetGBAConfig() { return &s_config; diff --git a/Source/Core/Core/HW/GCKeyboard.cpp b/Source/Core/Core/HW/GCKeyboard.cpp index 897d2d6850..4af090de70 100644 --- a/Source/Core/Core/HW/GCKeyboard.cpp +++ b/Source/Core/Core/HW/GCKeyboard.cpp @@ -17,7 +17,7 @@ namespace Keyboard { -static InputConfig s_config("GCKeyNew", _trans("Keyboard"), "GCKey", InputConfig::InputClass::GC); +static InputConfig s_config("GCKeyNew", _trans("Keyboard"), "GCKey", "GCKey"); InputConfig* GetConfig() { return &s_config; diff --git a/Source/Core/Core/HW/GCPad.cpp b/Source/Core/Core/HW/GCPad.cpp index cddb085be8..5450eea0c4 100644 --- a/Source/Core/Core/HW/GCPad.cpp +++ b/Source/Core/Core/HW/GCPad.cpp @@ -14,7 +14,7 @@ namespace Pad { -static InputConfig s_config("GCPadNew", _trans("Pad"), "GCPad", InputConfig::InputClass::GC); +static InputConfig s_config("GCPadNew", _trans("Pad"), "GCPad", "Pad"); InputConfig* GetConfig() { return &s_config; diff --git a/Source/Core/Core/HW/Wiimote.cpp b/Source/Core/Core/HW/Wiimote.cpp index 0638ab788b..2fa2270635 100644 --- a/Source/Core/Core/HW/Wiimote.cpp +++ b/Source/Core/Core/HW/Wiimote.cpp @@ -97,8 +97,7 @@ HIDWiimote* GetHIDWiimoteSource(unsigned int index) namespace Wiimote { -static InputConfig s_config(WIIMOTE_INI_NAME, _trans("Wii Remote"), "Wiimote", - InputConfig::InputClass::Wii); +static InputConfig s_config(WIIMOTE_INI_NAME, _trans("Wii Remote"), "Wiimote", "Wiimote"); InputConfig* GetConfig() { diff --git a/Source/Core/Core/HotkeyManager.cpp b/Source/Core/Core/HotkeyManager.cpp index 45e1c4dd9a..83b0c31616 100644 --- a/Source/Core/Core/HotkeyManager.cpp +++ b/Source/Core/Core/HotkeyManager.cpp @@ -207,7 +207,7 @@ static std::array s_hotkey_down; static HotkeyStatus s_hotkey; static bool s_enabled; -static InputConfig s_config("Hotkeys", _trans("Hotkeys"), "Hotkeys", InputConfig::InputClass::GC); +static InputConfig s_config("Hotkeys", _trans("Hotkeys"), "Hotkeys", "Hotkeys"); InputConfig* GetConfig() { diff --git a/Source/Core/InputCommon/InputConfig.cpp b/Source/Core/InputCommon/InputConfig.cpp index 651e2821c2..ff3f68acd0 100644 --- a/Source/Core/InputCommon/InputConfig.cpp +++ b/Source/Core/InputCommon/InputConfig.cpp @@ -20,9 +20,9 @@ #include "InputCommon/InputProfile.h" InputConfig::InputConfig(const std::string& ini_name, const std::string& gui_name, - const std::string& profile_directory_name, InputClass input_class) + const std::string& profile_directory_name, const std::string& profile_key) : m_ini_name(ini_name), m_gui_name(gui_name), m_profile_directory_name(profile_directory_name), - m_input_class(input_class) + m_profile_key(profile_key) { } @@ -159,20 +159,6 @@ bool InputConfig::ControllersNeedToBeCreated() const return m_controllers.empty(); } -std::string InputConfig::GetProfileKey() const -{ - switch (m_input_class) - { - case InputClass::GBA: - return "GBA"; - case InputClass::Wii: - return "Wiimote"; - case InputClass::GC: - default: - return "Pad"; - } -} - std::string InputConfig::GetUserProfileDirectoryPath() const { return fmt::format("{}Profiles/{}/", File::GetUserPath(D_CONFIG_IDX), GetProfileDirectoryName()); diff --git a/Source/Core/InputCommon/InputConfig.h b/Source/Core/InputCommon/InputConfig.h index ff8c4be65d..09b9f6c182 100644 --- a/Source/Core/InputCommon/InputConfig.h +++ b/Source/Core/InputCommon/InputConfig.h @@ -24,15 +24,8 @@ class EmulatedController; class InputConfig { public: - enum class InputClass - { - GC, - Wii, - GBA, - }; - InputConfig(const std::string& ini_name, const std::string& gui_name, - const std::string& profile_directory_name, InputClass input_class); + const std::string& profile_directory_name, const std::string& profile_key); ~InputConfig(); @@ -51,7 +44,7 @@ public: bool IsControllerControlledByGamepadDevice(int index) const; std::string GetGUIName() const { return m_gui_name; } - std::string GetProfileKey() const; + std::string GetProfileKey() const { return m_profile_key; } std::string GetProfileDirectoryName() const { return m_profile_directory_name; } std::string GetUserProfileDirectoryPath() const; std::string GetSysProfileDirectoryPath() const; @@ -69,6 +62,6 @@ private: const std::string m_ini_name; const std::string m_gui_name; const std::string m_profile_directory_name; - const InputClass m_input_class; + const std::string m_profile_key; InputCommon::DynamicInputTextureManager m_dynamic_input_tex_config_manager; };