From 0fc719c4cfc7b1307322ff2636d59a14a24e29c8 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 3 Nov 2024 17:38:48 +1000 Subject: [PATCH] Cheats: Simplify code merging on import The save file already does replacement. --- src/core/cheats.cpp | 14 +------------- src/core/cheats.h | 3 --- src/duckstation-qt/gamecheatsettingswidget.cpp | 3 +-- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/core/cheats.cpp b/src/core/cheats.cpp index 1e4657285..e4172aaf4 100644 --- a/src/core/cheats.cpp +++ b/src/core/cheats.cpp @@ -581,7 +581,7 @@ std::string Cheats::FormatCodeForFile(const CodeInfo& code) fmt::format_to(appender, "OptionRange = {}:{}\n", code.option_range_start, code.option_range_end); } - fmt::format_to(appender, "{}\n", code.body); + fmt::format_to(appender, "{}\n\n", code.body, code.body.ends_with('\n') ? "\n" : ""); return std::string(buf.begin(), buf.end()); } @@ -700,18 +700,6 @@ bool Cheats::SaveCodesToFile(const char* path, const CodeInfoList& codes, Error* return true; } -void Cheats::MergeCheatList(CodeInfoList* dst, CodeInfoList src) -{ - for (CodeInfo& code : src) - { - CodeInfo* existing_code = FindCodeInInfoList(*dst, code.name); - if (existing_code) - *existing_code = std::move(code); - else - dst->push_back(std::move(code)); - } -} - std::string Cheats::GetChtFilename(const std::string_view serial, std::optional hash, bool cheats) { return Path::Combine(cheats ? EmuFolders::Cheats : EmuFolders::Patches, GetChtTemplate(serial, hash, false)); diff --git a/src/core/cheats.h b/src/core/cheats.h index f2c27da2f..7a83e6e98 100644 --- a/src/core/cheats.h +++ b/src/core/cheats.h @@ -116,9 +116,6 @@ extern bool UpdateCodeInFile(const char* path, const std::string_view name, cons /// Updates or adds multiple codes to the file, rewriting it. extern bool SaveCodesToFile(const char* path, const CodeInfoList& codes, Error* error); -/// Merges two cheat lists, with any duplicates in the new list taking precedence. -extern void MergeCheatList(CodeInfoList* dst, CodeInfoList src); - /// Returns the path to a new cheat/patch cht for the specified serial and hash. extern std::string GetChtFilename(const std::string_view serial, std::optional hash, bool cheats); diff --git a/src/duckstation-qt/gamecheatsettingswidget.cpp b/src/duckstation-qt/gamecheatsettingswidget.cpp index a5d9fdf44..0e8ed7010 100644 --- a/src/duckstation-qt/gamecheatsettingswidget.cpp +++ b/src/duckstation-qt/gamecheatsettingswidget.cpp @@ -488,8 +488,7 @@ void GameCheatSettingsWidget::importCodes(const std::string& file_contents) return; } - Cheats::MergeCheatList(&m_codes, std::move(new_codes)); - if (!Cheats::SaveCodesToFile(getPathForSavingCheats().c_str(), m_codes, &error)) + if (!Cheats::SaveCodesToFile(getPathForSavingCheats().c_str(), new_codes, &error)) { QMessageBox::critical(this, tr("Error"), tr("Failed to save file:\n%1").arg(QString::fromStdString(error.GetDescription())));