mirror of
https://github.com/stenzek/duckstation.git
synced 2026-10-28 20:48:22 +01:00
Qt: Update gamesettings ini when cheats are renamed
This commit is contained in:
3 files changed
+44
-2
No files matched your search
@@ -655,7 +655,13 @@ void GameCheatSettingsWidget::editCode(const std::string_view code_name)
|
||||
new CheatCodeEditorDialog(this, getPathForSavingCheats(code->name), m_codes, *code, getGroupNames());
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
connect(dlg, &QDialog::accepted, this, [this] {
|
||||
connect(dlg, &QDialog::accepted, this, [this, dlg, old_name = code->name] {
|
||||
if (CheatCodeEditorDialog::renameCodeInSettings(m_dialog->getSettingsInterface(), Cheats::CHEATS_CONFIG_SECTION,
|
||||
old_name, dlg->getCode().name))
|
||||
{
|
||||
m_dialog->saveGameSettings();
|
||||
}
|
||||
|
||||
reloadList();
|
||||
QtHost::ReloadCheatFiles(m_dialog->getGameSerial(), false, true);
|
||||
});
|
||||
@@ -835,6 +841,29 @@ CheatCodeEditorDialog::CheatCodeEditorDialog(QWidget* parent, std::string save_p
|
||||
|
||||
CheatCodeEditorDialog::~CheatCodeEditorDialog() = default;
|
||||
|
||||
bool CheatCodeEditorDialog::renameCodeInSettings(SettingsInterface* si, const char* section,
|
||||
const std::string& old_name, const std::string& new_name)
|
||||
{
|
||||
if (old_name.empty() || old_name == new_name)
|
||||
return false;
|
||||
|
||||
bool changed = false;
|
||||
if (si->RemoveFromStringList(section, Cheats::PATCH_ENABLE_CONFIG_KEY, old_name.c_str()))
|
||||
{
|
||||
si->AddToStringList(section, Cheats::PATCH_ENABLE_CONFIG_KEY, new_name.c_str());
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (u32 value; si->FindUIntValue(section, old_name.c_str(), &value))
|
||||
{
|
||||
si->DeleteValue(section, old_name.c_str());
|
||||
si->SetUIntValue(section, new_name.c_str(), value);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
void CheatCodeEditorDialog::onGroupSelectedIndexChanged(int index)
|
||||
{
|
||||
if (index != (m_ui.group->count() - 1))
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace GameList {
|
||||
struct Entry;
|
||||
}
|
||||
|
||||
class SettingsInterface;
|
||||
class SettingsWindow;
|
||||
|
||||
class QStandardItem;
|
||||
@@ -96,6 +97,12 @@ public:
|
||||
Cheats::CodeInfo code, const QStringList& group_names);
|
||||
~CheatCodeEditorDialog() override;
|
||||
|
||||
const Cheats::CodeInfo& getCode() const { return m_code; }
|
||||
|
||||
/// Moves the enable state and option value of a renamed code. Returns true if the settings were changed.
|
||||
static bool renameCodeInSettings(SettingsInterface* si, const char* section, const std::string& old_name,
|
||||
const std::string& new_name);
|
||||
|
||||
private:
|
||||
void onGroupSelectedIndexChanged(int index);
|
||||
void saveClicked();
|
||||
|
||||
@@ -121,7 +121,13 @@ void GamePatchSettingsWidget::editPatch(const std::string& name)
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dlg->setWindowTitle(tr("Patch Editor"));
|
||||
|
||||
connect(dlg, &QDialog::accepted, this, [this] {
|
||||
connect(dlg, &QDialog::accepted, this, [this, dlg, old_name = name] {
|
||||
if (CheatCodeEditorDialog::renameCodeInSettings(m_dialog->getSettingsInterface(), Cheats::PATCHES_CONFIG_SECTION,
|
||||
old_name, dlg->getCode().name))
|
||||
{
|
||||
m_dialog->saveGameSettings();
|
||||
}
|
||||
|
||||
reloadList();
|
||||
QtHost::ReloadCheatFiles(m_dialog->getGameSerial(), false, true);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user