From 55e907385bb9d818d7b097631562e1c893feef2f Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 30 Jun 2020 21:35:15 +0200 Subject: [PATCH] patch_manager: warning for incompatible patches (#8535) * patch_manager: warning for incompatible patches This will open a warning dialog whenever the patch manager is opened and incompatible patches are detected. * Apply suggestions from code review Co-authored-by: Bird Egop Co-authored-by: Bird Egop --- Utilities/bin_patch.cpp | 7 +++++-- Utilities/bin_patch.h | 5 +++++ rpcs3/rpcs3qt/patch_manager_dialog.cpp | 25 +++++++++++++++++++++---- rpcs3/rpcs3qt/patch_manager_dialog.h | 2 +- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Utilities/bin_patch.cpp b/Utilities/bin_patch.cpp index 28cf9ff08a..e683883eb9 100644 --- a/Utilities/bin_patch.cpp +++ b/Utilities/bin_patch.cpp @@ -6,8 +6,6 @@ LOG_CHANNEL(patch_log); -static const std::string patch_engine_version = "1.2"; - namespace config_key { static const std::string enable_legacy_patches = "Enable Legacy Patches"; @@ -84,6 +82,11 @@ std::string patch_engine::get_patch_config_path() #endif } +std::string patch_engine::get_patches_path() +{ + return fs::get_config_dir() + "patches/"; +} + std::string patch_engine::get_imported_patch_path() { return fs::get_config_dir() + "patches/imported_patch.yml"; diff --git a/Utilities/bin_patch.h b/Utilities/bin_patch.h index c1bfcee76e..b59c197678 100644 --- a/Utilities/bin_patch.h +++ b/Utilities/bin_patch.h @@ -20,6 +20,8 @@ namespace patch_key static const std::string version = "Version"; } +static const std::string patch_engine_version = "1.2"; + enum class patch_type { invalid, @@ -90,6 +92,9 @@ public: // Returns the directory in which patch_config.yml is located static std::string get_patch_config_path(); + // Returns the directory in which patches are located + static std::string get_patches_path(); + // Returns the filepath for the imported_patch.yml static std::string get_imported_patch_path(); diff --git a/rpcs3/rpcs3qt/patch_manager_dialog.cpp b/rpcs3/rpcs3qt/patch_manager_dialog.cpp index d13db1ce19..17b848695e 100644 --- a/rpcs3/rpcs3qt/patch_manager_dialog.cpp +++ b/rpcs3/rpcs3qt/patch_manager_dialog.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "ui_patch_manager_dialog.h" #include "patch_manager_dialog.h" @@ -100,7 +101,7 @@ int patch_manager_dialog::exec() void patch_manager_dialog::refresh(bool restore_layout) { - load_patches(); + load_patches(restore_layout); populate_tree(); filter_patches(ui->patch_filter->text()); @@ -120,13 +121,13 @@ void patch_manager_dialog::refresh(bool restore_layout) } } -void patch_manager_dialog::load_patches() +void patch_manager_dialog::load_patches(bool show_error) { m_map.clear(); // NOTE: Make sure these paths are loaded in the same order as they are applied on boot - const std::string patches_path = fs::get_config_dir() + "patches/"; + const std::string patches_path = patch_engine::get_patches_path(); const QStringList filters = QStringList() << "*_patch.yml"; QStringList path_list; @@ -135,9 +136,25 @@ void patch_manager_dialog::load_patches() path_list << QDir(QString::fromStdString(patches_path)).entryList(filters); path_list.removeDuplicates(); // make sure to load patch.yml and imported_patch.yml only once + bool has_errors = false; + for (const auto& path : path_list) { - patch_engine::load(m_map, patches_path + path.toStdString()); + if (!patch_engine::load(m_map, patches_path + path.toStdString())) + { + has_errors = true; + } + } + + if (show_error && has_errors) + { + // Open a warning dialog after the patch manager was opened + QTimer::singleShot(100, [this, patches_path]() + { + QMessageBox::warning(this, tr("Incompatible patches detected"), + tr("Some of your patches are not compatible with the current version of RPCS3's Patch Manager.\n\nMake sure that all the patches located in \"%0\" contain the proper formatting that is required for the Patch Manager Version %1.") + .arg(QString::fromStdString(patches_path)).arg(QString::fromStdString(patch_engine_version))); + }); } } diff --git a/rpcs3/rpcs3qt/patch_manager_dialog.h b/rpcs3/rpcs3qt/patch_manager_dialog.h index 151c105fb3..d40ba5618e 100644 --- a/rpcs3/rpcs3qt/patch_manager_dialog.h +++ b/rpcs3/rpcs3qt/patch_manager_dialog.h @@ -50,7 +50,7 @@ private Q_SLOTS: private: void refresh(bool restore_layout = false); - void load_patches(); + void load_patches(bool show_error); void populate_tree(); void save_config(); void update_patch_info(const gui_patch_info& info);