patch manager: Add patch removal to context menu

Also avoid saving empty patch maps
This commit is contained in:
Megamouse 2020-06-19 19:47:51 +02:00
parent c4fe418f66
commit cd4ed11700
3 changed files with 73 additions and 5 deletions

View file

@ -71,6 +71,11 @@ std::string patch_engine::get_patch_config_path()
#endif
}
std::string patch_engine::get_imported_patch_path()
{
return fs::get_config_dir() + "patches/imported_patch.yml";
}
static void append_log_message(std::stringstream* log_messages, const std::string& message)
{
if (log_messages)
@ -461,7 +466,7 @@ void patch_engine::append_global_patches()
load(m_map, fs::get_config_dir() + "patches/patch.yml");
// Imported patch.yml
load(m_map, fs::get_config_dir() + "patches/imported_patch.yml");
load(m_map, get_imported_patch_path());
}
void patch_engine::append_title_patches(const std::string& title_id)
@ -729,6 +734,11 @@ bool patch_engine::save_patches(const patch_map& patches, const std::string& pat
for (const auto& [hash, container] : patches)
{
if (container.patch_info_map.empty())
{
continue;
}
out << YAML::Newline << YAML::Newline;
out << hash << YAML::BeginMap;
out << "Patches" << YAML::BeginMap;
@ -793,6 +803,27 @@ bool patch_engine::import_patches(const patch_engine::patch_map& patches, const
return false;
}
bool patch_engine::remove_patch(const patch_info& info)
{
patch_engine::patch_map patches;
if (load(patches, info.source_path))
{
if (patches.find(info.hash) != patches.end())
{
auto& container = patches[info.hash];
if (container.patch_info_map.find(info.description) != container.patch_info_map.end())
{
container.patch_info_map.erase(info.description);
return save_patches(patches, info.source_path);
}
}
}
return false;
}
patch_engine::patch_config_map patch_engine::load_config(bool& enable_legacy_patches)
{
enable_legacy_patches = true; // Default to true