Qt: Add Clear and Reset buttons to cheat manager

This commit is contained in:
Connor McLaughlin
2021-02-12 00:20:04 +10:00
parent e75f1c1b6d
commit de688615ff
6 changed files with 119 additions and 17 deletions

View File

@ -2722,6 +2722,40 @@ bool CommonHostInterface::SaveCheatList(const char* filename)
return true;
}
bool CommonHostInterface::DeleteCheatList()
{
if (!System::IsValid())
return false;
const std::string filename(GetCheatFileName());
if (!filename.empty())
{
if (!FileSystem::DeleteFile(filename.c_str()))
return false;
AddFormattedOSDMessage(5.0f, TranslateString("OSDMessage", "Deleted cheat list '%s'."), filename.c_str());
}
System::SetCheatList(nullptr);
return true;
}
void CommonHostInterface::ClearCheatList(bool save_to_file)
{
if (!System::IsValid())
return;
CheatList* cl = System::GetCheatList();
if (!cl)
return;
while (cl->GetCodeCount() > 0)
cl->RemoveCode(cl->GetCodeCount() - 1);
if (save_to_file)
SaveCheatList();
}
void CommonHostInterface::SetCheatCodeState(u32 index, bool enabled, bool save_to_file)
{
if (!System::IsValid() || !System::HasCheatList())

View File

@ -220,6 +220,12 @@ public:
/// Saves the current cheat list to the specified file.
bool SaveCheatList(const char* filename);
/// Deletes the cheat list, if present.
bool DeleteCheatList();
/// Removes all cheats from the cheat list.
void ClearCheatList(bool save_to_file);
/// Enables/disabled the specified cheat code.
void SetCheatCodeState(u32 index, bool enabled, bool save_to_file);