From e931bd8ab4338231e723ed627d161e80206f1688 Mon Sep 17 00:00:00 2001 From: "lane.wei" Date: Fri, 1 Mar 2024 10:08:52 +0800 Subject: [PATCH] FIX: updater: fix force upgrade logic JIRA: STUDIO-6393 Change-Id: I46c51e09e7390e5ab0de40215911aac9635ab476 (cherry picked from commit 673ba6ff4ebda039d71dcbfdaa28c1252f5b8821) --- src/slic3r/Utils/PresetUpdater.cpp | 40 +++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index d992312de..17b635ca8 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -220,6 +220,7 @@ struct PresetUpdater::priv std::string version; std::string description; std::string url; + bool force{false}; std::string cache_root; std::vector sub_caches; }; @@ -238,7 +239,7 @@ struct PresetUpdater::priv void sync_tooltip(std::string http_url, std::string language); void sync_plugins(std::string http_url, std::string plugin_version); void sync_printer_config(std::string http_url); - bool get_cached_plugins_version(std::string &cached_version); + bool get_cached_plugins_version(std::string &cached_version, bool& force); //BBS: refine preset update logic bool install_bundles_rsrc(std::vector bundles, bool snapshot) const; @@ -531,6 +532,7 @@ void PresetUpdater::priv::sync_resources(std::string http_url, std::mapsecond.version; j["description"] = resource_update->second.description; + j["force"] = resource_update->second.force; boost::nowide::ofstream c; c.open(changelog_file, std::ios::out | std::ios::trunc); @@ -878,8 +884,8 @@ void PresetUpdater::priv::sync_tooltip(std::string http_url, std::string languag } catch (...) {} std::map resources { - {"slicer/tooltip/common", { common_version, "", "", (cache_root / "common").string() }}, - {"slicer/tooltip/" + language, { language_version, "", "", (cache_root / language).string() }} + {"slicer/tooltip/common", { common_version, "", "", false, (cache_root / "common").string() }}, + {"slicer/tooltip/" + language, { language_version, "", "", false, (cache_root / language).string() }} }; sync_resources(http_url, resources); for (auto &r : resources) { @@ -895,7 +901,7 @@ void PresetUpdater::priv::sync_tooltip(std::string http_url, std::string languag } // return true means there are plugins files -bool PresetUpdater::priv::get_cached_plugins_version(std::string& cached_version) +bool PresetUpdater::priv::get_cached_plugins_version(std::string& cached_version, bool &force) { std::string data_dir_str = data_dir(); boost::filesystem::path data_dir_path(data_dir_str); @@ -929,6 +935,7 @@ bool PresetUpdater::priv::get_cached_plugins_version(std::string& cached_version ifs >> j; cached_version = j["version"]; + force = j["force"]; } catch(nlohmann::detail::parse_error &err) { BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": parse "< resources { - {"slicer/plugins/cloud", { using_version, "", "", cache_path.string(), {"plugins"}}} + {"slicer/plugins/cloud", { using_version, "", "", false, cache_path.string(), {"plugins"}}} }; sync_resources(http_url, resources, true, plugin_version, "network_plugins.json"); } @@ -1050,10 +1058,18 @@ void PresetUpdater::priv::sync_plugins(std::string http_url, std::string plugin_ BOOST_LOG_TRIVIAL(warning) << format("[BBL Updater] sync_plugins: %1%", e.what()); } - bool result = get_cached_plugins_version(cached_version); + bool result = get_cached_plugins_version(cached_version, force_upgrade); if (result) { - BOOST_LOG_TRIVIAL(info) << format("[BBL Updater] found new plugins: %1%, prompt to update", cached_version); - GUI::wxGetApp().plater()->get_notification_manager()->push_notification(GUI::NotificationType::BBLPluginUpdateAvailable); + BOOST_LOG_TRIVIAL(info) << format("[BBL Updater] found new plugins: %1%, prompt to update, force_upgrade %2%", cached_version, force_upgrade); + if (force_upgrade) { + auto app_config = GUI::wxGetApp().app_config; + if (!app_config) + GUI::wxGetApp().plater()->get_notification_manager()->push_notification(GUI::NotificationType::BBLPluginUpdateAvailable); + else + app_config->set("update_network_plugin", "true"); + } + else + GUI::wxGetApp().plater()->get_notification_manager()->push_notification(GUI::NotificationType::BBLPluginUpdateAvailable); } } @@ -1103,7 +1119,7 @@ void PresetUpdater::priv::sync_printer_config(std::string http_url) } try { - std::map resources{{"slicer/printer/bbl", {using_version, "", "", cache_folder.string()}}}; + std::map resources{{"slicer/printer/bbl", {using_version, "", "", false, cache_folder.string()}}}; sync_resources(http_url, resources, false, cached_version, "printer.json"); } catch (std::exception &e) { BOOST_LOG_TRIVIAL(warning) << format("[BBL Updater] sync_printer_config: %1%", e.what());