1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

patch manager: add checkbox for "enable legacy"

This commit is contained in:
Megamouse 2020-06-11 15:12:44 +02:00
parent 768bb8d31f
commit 4a03f06175
6 changed files with 46 additions and 10 deletions

View File

@ -4,6 +4,8 @@
LOG_CHANNEL(patch_log);
static const std::string yml_key_enable_legacy_patches = "Enable Legacy Patches";
template <>
void fmt_class_string<YAML::NodeType::value>::format(std::string& out, u64 arg)
{
@ -87,7 +89,8 @@ void patch_engine::load(patch_map& patches_map, const std::string& path)
}
// Load patch config to determine which patches are enabled
patch_config_map patch_config = load_config();
bool enable_legacy_patches;
patch_config_map patch_config = load_config(enable_legacy_patches);
static const std::string target_version = "1.0";
std::string version;
@ -122,7 +125,7 @@ void patch_engine::load(patch_map& patches_map, const std::string& path)
{
struct patch_info info{};
info.hash = main_key;
info.enabled = true;
info.enabled = enable_legacy_patches;
info.is_legacy = true;
read_patch_node(info, pair.second, root);
@ -463,7 +466,7 @@ std::size_t patch_engine::apply_patch(const std::string& name, u8* dst, u32 file
return applied_total;
}
void patch_engine::save_config(const patch_map& patches_map)
void patch_engine::save_config(const patch_map& patches_map, bool enable_legacy_patches)
{
const std::string path = get_patch_config_path();
patch_log.notice("Saving patch config file %s", path);
@ -478,6 +481,10 @@ void patch_engine::save_config(const patch_map& patches_map)
YAML::Emitter out;
out << YAML::BeginMap;
// Save "Enable Legacy Patches"
out << yml_key_enable_legacy_patches << enable_legacy_patches;
// Save 'enabled' state per hash and description
patch_config_map config_map;
for (const auto& [hash, title_info] : patches_map)
@ -511,8 +518,10 @@ void patch_engine::save_config(const patch_map& patches_map)
file.write(out.c_str(), out.size());
}
patch_engine::patch_config_map patch_engine::load_config()
patch_engine::patch_config_map patch_engine::load_config(bool& enable_legacy_patches)
{
enable_legacy_patches = true; // Default to true
patch_config_map config_map;
const std::string path = get_patch_config_path();
@ -528,6 +537,13 @@ patch_engine::patch_config_map patch_engine::load_config()
return config_map;
}
// Try to load "Enable Legacy Patches" (default to true)
if (auto enable_legacy_node = root[yml_key_enable_legacy_patches])
{
enable_legacy_patches = enable_legacy_node.as<bool>(true);
root.remove(yml_key_enable_legacy_patches); // Remove the node in order to skip it in the next part
}
for (auto pair : root)
{
auto& hash = pair.first.Scalar();

View File

@ -94,10 +94,10 @@ public:
static void add_patch_data(YAML::Node node, patch_info& info, u32 modifier, const YAML::Node& root);
// Save to patch_config.yml
static void save_config(const patch_map& patches_map);
static void save_config(const patch_map& patches_map, bool enable_legacy_patches);
// Load patch_config.yml
static patch_config_map load_config();
static patch_config_map load_config(bool& enable_legacy_patches);
// Load from file and append to member patches map
void append_global_patches();

View File

@ -262,7 +262,7 @@ void emu_settings::EnhanceCheckBox(QCheckBox* checkbox, emu_settings_type type)
m_broken_types.insert(type);
}
connect(checkbox, &QCheckBox::stateChanged, [=, this](int val)
connect(checkbox, &QCheckBox::stateChanged, [type, this](int val)
{
const std::string str = val != 0 ? "true" : "false";
SetSetting(type, str);
@ -303,7 +303,7 @@ void emu_settings::EnhanceSlider(QSlider* slider, emu_settings_type type)
slider->setRange(min, max);
slider->setValue(val);
connect(slider, &QSlider::valueChanged, [=, this](int value)
connect(slider, &QSlider::valueChanged, [type, this](int value)
{
SetSetting(type, sstr(value));
});
@ -404,7 +404,7 @@ void emu_settings::EnhanceLineEdit(QLineEdit* edit, emu_settings_type type)
const std::string set_text = GetSetting(type);
edit->setText(qstr(set_text));
connect(edit, &QLineEdit::textChanged, [=, this](const QString &text)
connect(edit, &QLineEdit::textChanged, [type, this](const QString &text)
{
SetSetting(type, sstr(text));
});

View File

@ -5,6 +5,7 @@
#include <QDir>
#include <QMenu>
#include <QAction>
#include <QCheckBox>
#include "ui_patch_manager_dialog.h"
#include "patch_manager_dialog.h"
@ -39,6 +40,10 @@ patch_manager_dialog::patch_manager_dialog(QWidget* parent)
ui->setupUi(this);
setModal(true);
// Load config for special settings
patch_engine::load_config(m_legacy_patches_enabled);
ui->cb_enable_legacy_patches->setChecked(m_legacy_patches_enabled);
load_patches();
populate_tree();
@ -50,6 +55,7 @@ patch_manager_dialog::patch_manager_dialog(QWidget* parent)
connect(ui->patch_tree, &QTreeWidget::customContextMenuRequested, this, &patch_manager_dialog::on_custom_context_menu_requested);
connect(ui->pb_expand_all, &QAbstractButton::clicked, ui->patch_tree, &QTreeWidget::expandAll);
connect(ui->pb_collapse_all, &QAbstractButton::clicked, ui->patch_tree, &QTreeWidget::collapseAll);
connect(ui->cb_enable_legacy_patches, &QCheckBox::stateChanged, this, &patch_manager_dialog::on_legacy_patches_enabled);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QWidget::close);
connect(ui->buttonBox, &QDialogButtonBox::clicked, [this](QAbstractButton* button)
{
@ -195,7 +201,7 @@ void patch_manager_dialog::populate_tree()
void patch_manager_dialog::save()
{
patch_engine::save_config(m_map);
patch_engine::save_config(m_map, m_legacy_patches_enabled);
}
void patch_manager_dialog::filter_patches(const QString& term)
@ -342,3 +348,8 @@ void patch_manager_dialog::on_custom_context_menu_requested(const QPoint &pos)
menu->exec(ui->patch_tree->viewport()->mapToGlobal(pos));
}
void patch_manager_dialog::on_legacy_patches_enabled(int state)
{
m_legacy_patches_enabled = state == Qt::CheckState::Checked;
}

View File

@ -23,6 +23,7 @@ private Q_SLOTS:
void on_item_selected(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void on_item_changed(QTreeWidgetItem *item, int column);
void on_custom_context_menu_requested(const QPoint& pos);
void on_legacy_patches_enabled(int state);
private:
void load_patches();
@ -32,6 +33,7 @@ private:
void update_patch_info(const patch_engine::patch_info& info);
patch_engine::patch_map m_map;
bool m_legacy_patches_enabled = false;
Ui::patch_manager_dialog *ui;
};

View File

@ -36,6 +36,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_enable_legacy_patches">
<property name="text">
<string>Enable Legacy Patches</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_collapse_all">
<property name="text">