From 542530c260e1fa65d28658ca07179890ec4093e8 Mon Sep 17 00:00:00 2001 From: Rain Date: Sat, 21 Dec 2024 15:29:47 -0500 Subject: [PATCH 1/3] Added rename input profile function --- .../Settings/ControllerSettingsWindow.cpp | 44 +++++++++++++++++++ pcsx2-qt/Settings/ControllerSettingsWindow.h | 1 + pcsx2-qt/Settings/ControllerSettingsWindow.ui | 10 +++++ 3 files changed, 55 insertions(+) diff --git a/pcsx2-qt/Settings/ControllerSettingsWindow.cpp b/pcsx2-qt/Settings/ControllerSettingsWindow.cpp index 6779d15fed742..c335b1797ac76 100644 --- a/pcsx2-qt/Settings/ControllerSettingsWindow.cpp +++ b/pcsx2-qt/Settings/ControllerSettingsWindow.cpp @@ -38,6 +38,7 @@ ControllerSettingsWindow::ControllerSettingsWindow() connect(m_ui.buttonBox, &QDialogButtonBox::rejected, this, &ControllerSettingsWindow::close); connect(m_ui.newProfile, &QPushButton::clicked, this, &ControllerSettingsWindow::onNewProfileClicked); connect(m_ui.applyProfile, &QPushButton::clicked, this, &ControllerSettingsWindow::onApplyProfileClicked); + connect(m_ui.renameProfile, &QPushButton::clicked, this, &ControllerSettingsWindow::onRenameProfileClicked); connect(m_ui.deleteProfile, &QPushButton::clicked, this, &ControllerSettingsWindow::onDeleteProfileClicked); connect(m_ui.mappingSettings, &QPushButton::clicked, this, &ControllerSettingsWindow::onMappingSettingsClicked); connect(m_ui.restoreDefaults, &QPushButton::clicked, this, &ControllerSettingsWindow::onRestoreDefaultsClicked); @@ -176,6 +177,48 @@ void ControllerSettingsWindow::onApplyProfileClicked() switchProfile({}); } +void ControllerSettingsWindow::onRenameProfileClicked() +{ + const QString profile_name(QInputDialog::getText(this, tr("Rename Input Profile"), + tr("Enter the new name for the input profile:").arg(m_profile_name))); + + if (profile_name.isEmpty()) + return; + + std::string old_profile_name(m_profile_name.toStdString()); + std::string old_profile_path(VMManager::GetInputProfilePath(m_profile_name.toStdString())); + std::string profile_path(VMManager::GetInputProfilePath(profile_name.toStdString())); + if (FileSystem::FileExists(profile_path.c_str())) + { + QMessageBox::critical(this, tr("Error"), tr("A profile with the name '%1' already exists.").arg(profile_name)); + return; + } + + if (!FileSystem::RenamePath(old_profile_path.c_str(), profile_path.c_str())) + { + QMessageBox::critical(this, tr("Error"), tr("Failed to rename '%1'.").arg(QString::fromStdString(old_profile_path))); + return; + } + + std::string game_settings_dir(EmuFolders::GameSettings); + for (const auto& game_settings : std::filesystem::recursive_directory_iterator(game_settings_dir)) + { + std::string game_settings_path(game_settings.path().string()); + std::unique_ptr update_sif(std::make_unique(std::move(game_settings_path))); + + update_sif->Load(); + + if (!old_profile_name.compare(update_sif->GetStringValue("EmuCore", "InputProfileName"))) + { + update_sif->SetStringValue("EmuCore", "InputProfileName", profile_name.toUtf8()); + } + } + + + refreshProfileList(); + switchProfile({profile_name}); +} + void ControllerSettingsWindow::onDeleteProfileClicked() { if (QMessageBox::question(this, tr("Delete Input Profile"), @@ -451,6 +494,7 @@ void ControllerSettingsWindow::createWidgets() } m_ui.applyProfile->setEnabled(isEditingProfile()); + m_ui.renameProfile->setEnabled(isEditingProfile()); m_ui.deleteProfile->setEnabled(isEditingProfile()); m_ui.restoreDefaults->setEnabled(isEditingGlobalSettings()); } diff --git a/pcsx2-qt/Settings/ControllerSettingsWindow.h b/pcsx2-qt/Settings/ControllerSettingsWindow.h index 2ee8996a20ec6..e754dc5b5faab 100644 --- a/pcsx2-qt/Settings/ControllerSettingsWindow.h +++ b/pcsx2-qt/Settings/ControllerSettingsWindow.h @@ -76,6 +76,7 @@ private Q_SLOTS: void onCurrentProfileChanged(int index); void onNewProfileClicked(); void onApplyProfileClicked(); + void onRenameProfileClicked(); void onDeleteProfileClicked(); void onMappingSettingsClicked(); void onRestoreDefaultsClicked(); diff --git a/pcsx2-qt/Settings/ControllerSettingsWindow.ui b/pcsx2-qt/Settings/ControllerSettingsWindow.ui index ee04e8c37b21a..4efe1a1e8bdad 100644 --- a/pcsx2-qt/Settings/ControllerSettingsWindow.ui +++ b/pcsx2-qt/Settings/ControllerSettingsWindow.ui @@ -113,6 +113,16 @@ + + + + Rename Profile + + + + + + From fca3d2938943199888cc24e289b73300f521b553 Mon Sep 17 00:00:00 2001 From: Rain Date: Tue, 24 Dec 2024 11:54:30 -0500 Subject: [PATCH 2/3] replaced recursive_directory_iterator w/ FindFiles() --- pcsx2-qt/Settings/ControllerSettingsWindow.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pcsx2-qt/Settings/ControllerSettingsWindow.cpp b/pcsx2-qt/Settings/ControllerSettingsWindow.cpp index c335b1797ac76..5e95c88fc7e4e 100644 --- a/pcsx2-qt/Settings/ControllerSettingsWindow.cpp +++ b/pcsx2-qt/Settings/ControllerSettingsWindow.cpp @@ -200,10 +200,11 @@ void ControllerSettingsWindow::onRenameProfileClicked() return; } - std::string game_settings_dir(EmuFolders::GameSettings); - for (const auto& game_settings : std::filesystem::recursive_directory_iterator(game_settings_dir)) + FileSystem::FindResultsArray files; + FileSystem::FindFiles(EmuFolders::GameSettings.c_str(), "*", FILESYSTEM_FIND_FILES, &files); + for (const auto& game_settings : files) { - std::string game_settings_path(game_settings.path().string()); + std::string game_settings_path(game_settings.FileName.c_str()); std::unique_ptr update_sif(std::make_unique(std::move(game_settings_path))); update_sif->Load(); @@ -212,8 +213,7 @@ void ControllerSettingsWindow::onRenameProfileClicked() { update_sif->SetStringValue("EmuCore", "InputProfileName", profile_name.toUtf8()); } - } - + } refreshProfileList(); switchProfile({profile_name}); From 408924119c0bbdb5b8a010b0f83f252b907f13b7 Mon Sep 17 00:00:00 2001 From: rtavarez98 <63325601+rtavarez98@users.noreply.github.com> Date: Fri, 27 Dec 2024 17:38:27 -0500 Subject: [PATCH 3/3] changed indentation from tab to space --- pcsx2-qt/Settings/ControllerSettingsWindow.ui | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pcsx2-qt/Settings/ControllerSettingsWindow.ui b/pcsx2-qt/Settings/ControllerSettingsWindow.ui index 4efe1a1e8bdad..dde6ff488ac76 100644 --- a/pcsx2-qt/Settings/ControllerSettingsWindow.ui +++ b/pcsx2-qt/Settings/ControllerSettingsWindow.ui @@ -113,16 +113,16 @@ - - - - Rename Profile - - - - - - + + + + Rename Profile + + + + + +