Cheats: Simplify code merging on import

The save file already does replacement.
This commit is contained in:
Stenzek 2024-11-03 17:38:48 +10:00
parent a8bc364a2b
commit 0fc719c4cf
No known key found for this signature in database
3 changed files with 2 additions and 18 deletions

View File

@ -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<GameHash> hash, bool cheats)
{
return Path::Combine(cheats ? EmuFolders::Cheats : EmuFolders::Patches, GetChtTemplate(serial, hash, false));

View File

@ -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<GameHash> hash, bool cheats);

View File

@ -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())));