diff --git a/pcsx2-qt/Settings/ControllerSettingsWindow.cpp b/pcsx2-qt/Settings/ControllerSettingsWindow.cpp index 6779d15fed..c335b1797a 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 2ee8996a20..e754dc5b5f 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 ee04e8c37b..4efe1a1e8b 100644 --- a/pcsx2-qt/Settings/ControllerSettingsWindow.ui +++ b/pcsx2-qt/Settings/ControllerSettingsWindow.ui @@ -113,6 +113,16 @@ + + + + Rename Profile + + + + + +