From 75994cc7659747f88e4e3a1e7d4c1f3283c27a0f Mon Sep 17 00:00:00 2001 From: "lane.wei" Date: Wed, 7 Aug 2024 15:49:45 +0800 Subject: [PATCH] ENH: updater: refine the logic of upgrading to presets 1. use seperate directory in ota 2. remove previous folder before updating 3. use new change file format 4. support force upgrading jira: no-jira Change-Id: I193a1a452ee62d2e808c6956aa3b0da060f2ae58 --- src/slic3r/GUI/GUI_App.cpp | 118 +++---- src/slic3r/GUI/GUI_App.hpp | 9 +- src/slic3r/GUI/MainFrame.cpp | 6 +- src/slic3r/Utils/PresetUpdater.cpp | 514 +++++++++++++++++------------ 4 files changed, 366 insertions(+), 281 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 24bcfb6dd..1cdc51cee 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1286,9 +1286,9 @@ void GUI_App::post_init() // This is ugly but I honestly found no better way to do it. // Neither wxShowEvent nor wxWindowCreateEvent work reliably. if (this->preset_updater) { // G-Code Viewer does not initialize preset_updater. - BOOST_LOG_TRIVIAL(info) << "before check_updates"; - this->check_updates(false); - BOOST_LOG_TRIVIAL(info) << "after check_updates"; + //BOOST_LOG_TRIVIAL(info) << "before check_updates"; + //this->check_updates(false); + //BOOST_LOG_TRIVIAL(info) << "after check_updates"; CallAfter([this] { bool cw_showed = this->config_wizard_startup(); @@ -2969,82 +2969,62 @@ void GUI_App::copy_network_if_available() { if (app_config->get("update_network_plugin") != "true") return; - std::string network_library, player_library, live555_library, network_library_dst, player_library_dst, live555_library_dst; std::string data_dir_str = data_dir(); - boost::filesystem::path data_dir_path(data_dir_str); + fs::path data_dir_path(data_dir_str); auto plugin_folder = data_dir_path / "plugins"; - auto cache_folder = data_dir_path / "ota"; - std::string changelog_file = cache_folder.string() + "/network_plugins.json"; + auto cache_folder = data_dir_path / "ota" / "plugins"; + //std::string changelog_file = cache_folder.string() + "/network_plugins.json"; #if defined(_MSC_VER) || defined(_WIN32) - network_library = cache_folder.string() + "/bambu_networking.dll"; - player_library = cache_folder.string() + "/BambuSource.dll"; - live555_library = cache_folder.string() + "/live555.dll"; - network_library_dst = plugin_folder.string() + "/bambu_networking.dll"; - player_library_dst = plugin_folder.string() + "/BambuSource.dll"; - live555_library_dst = plugin_folder.string() + "/live555.dll"; + const char* library_ext = ".dll"; #elif defined(__WXMAC__) - network_library = cache_folder.string() + "/libbambu_networking.dylib"; - player_library = cache_folder.string() + "/libBambuSource.dylib"; - live555_library = cache_folder.string() + "/liblive555.dylib"; - network_library_dst = plugin_folder.string() + "/libbambu_networking.dylib"; - player_library_dst = plugin_folder.string() + "/libBambuSource.dylib"; - live555_library_dst = plugin_folder.string() + "/liblive555.dylib"; + const char* library_ext = ".dylib"; #else - network_library = cache_folder.string() + "/libbambu_networking.so"; - player_library = cache_folder.string() + "/libBambuSource.so"; - live555_library = cache_folder.string() + "/liblive555.so"; - network_library_dst = plugin_folder.string() + "/libbambu_networking.so"; - player_library_dst = plugin_folder.string() + "/libBambuSource.so"; - live555_library_dst = plugin_folder.string() + "/liblive555.so"; + const char* library_ext = ".so"; #endif - BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< ": checking network_library " << network_library << ", player_library " << player_library; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": checking network_library from ota directory"; if (!boost::filesystem::exists(plugin_folder)) { - BOOST_LOG_TRIVIAL(info)<< __FUNCTION__ << ": create directory "<set("update_network_plugin", "false"); + return; } - if (boost::filesystem::exists(player_library)) { - CopyFileResult cfr = copy_file(player_library, player_library_dst, error_message, false); - if (cfr != CopyFileResult::SUCCESS) { - BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": Copying failed(" << cfr << "): " << error_message; - return; - } + try { + std::string error_message; + for (auto& dir_entry : boost::filesystem::directory_iterator(cache_folder)) + { + const auto& path = dir_entry.path(); + std::string file_path = path.string(); - static constexpr const auto perms = fs::owner_read | fs::owner_write | fs::group_read | fs::others_read; - fs::permissions(player_library_dst, perms); - fs::remove(player_library); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< ": Copying player library from" << player_library << " to " << player_library_dst<<" successfully."; + if (boost::algorithm::iends_with(file_path, library_ext)) { + std::string file_name = path.filename().string(); + std::string dest_path = (plugin_folder / file_name).string(); + CopyFileResult cfr = copy_file(file_path, dest_path, error_message, false); + if (cfr != CopyFileResult::SUCCESS) { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": Copying failed(" << cfr << "): " << error_message; + return; + } + + static constexpr const auto perms = fs::owner_read | fs::owner_write | fs::group_read | fs::others_read; + fs::permissions(dest_path, perms); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": Copying network library from" << file_path << " to " << dest_path << " successfully."; + } + } + if (boost::filesystem::exists(cache_folder)) + fs::remove_all(cache_folder); + } + catch (...) { + BOOST_LOG_TRIVIAL(error) << "Failed to copy plugins from ota"; } - if (boost::filesystem::exists(live555_library)) { - CopyFileResult cfr = copy_file(live555_library, live555_library_dst, error_message, false); - if (cfr != CopyFileResult::SUCCESS) { - BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": Copying failed(" << cfr << "): " << error_message; - return; - } - - static constexpr const auto perms = fs::owner_read | fs::owner_write | fs::group_read | fs::others_read; - fs::permissions(live555_library_dst, perms); - fs::remove(live555_library); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< ": Copying live555 library from" << live555_library << " to " << live555_library_dst<<" successfully."; - } - if (boost::filesystem::exists(changelog_file)) - fs::remove(changelog_file); app_config->set("update_network_plugin", "false"); + + return; } bool GUI_App::on_init_network(bool try_backup) @@ -6700,7 +6680,8 @@ void GUI_App::check_updates(const bool verbose) { PresetUpdater::UpdateResult updater_result; try { - updater_result = preset_updater->config_update(app_config->orig_version(), verbose ? PresetUpdater::UpdateParams::SHOW_TEXT_BOX : PresetUpdater::UpdateParams::SHOW_NOTIFICATION); + //updater_result = preset_updater->config_update(app_config->orig_version(), verbose ? PresetUpdater::UpdateParams::SHOW_TEXT_BOX : PresetUpdater::UpdateParams::SHOW_NOTIFICATION); + updater_result = preset_updater->config_update(app_config->orig_version(), PresetUpdater::UpdateParams::SHOW_TEXT_BOX); if (updater_result == PresetUpdater::R_INCOMPAT_EXIT) { mainframe->Close(); } @@ -6717,6 +6698,17 @@ void GUI_App::check_updates(const bool verbose) } } +void GUI_App::check_config_updates_from_updater() +{ + check_updates(false); +} + +void GUI_App::check_config_updates_from_menu() +{ + check_updates(true); +} + + bool GUI_App::open_browser_with_warning_dialog(const wxString& url, int flags/* = 0*/) { return wxLaunchDefaultBrowser(url, flags); diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 9b4394793..b17562066 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -237,9 +237,9 @@ private: bool m_opengl_initialized{ false }; #endif -//import model from mall +//import model from mall wxString m_download_file_url; - + //#ifdef _WIN32 wxColour m_color_label_modified; wxColour m_color_label_sys; @@ -380,7 +380,7 @@ public: bool get_side_menu_popup_status(); void set_side_menu_popup_status(bool status); void link_to_network_check(); - + const wxColour& get_label_clr_modified(){ return m_color_label_modified; } const wxColour& get_label_clr_sys() { return m_color_label_sys; } @@ -647,7 +647,8 @@ public: bool check_networking_version(); void cancel_networking_install(); void restart_networking(); - void check_config_updates_from_updater() { check_updates(false); } + void check_config_updates_from_updater(); + void check_config_updates_from_menu(); private: int updating_bambu_networking(); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index e817669cb..c9e667efd 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -2215,7 +2215,11 @@ static wxMenu* generate_help_menu() return true; }); - append_menu_item(helpMenu, wxID_ANY, _L("Open Network Test"), _L("Open Network Test"), [](wxCommandEvent&) { + append_menu_item(helpMenu, wxID_ANY, _L("Check for Presets Update"), _L("Check for Presets Update"), [](wxCommandEvent &) { + wxGetApp().check_config_updates_from_menu(); + }); + + append_menu_item(helpMenu, wxID_ANY, _L("Open Network Test"), _L("Open Network Test"), [](wxCommandEvent&) { NetworkTestDialog dlg(wxGetApp().mainframe); dlg.ShowModal(); }); diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index 1f41c853b..268c2685a 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -51,7 +51,8 @@ namespace Slic3r { static const char *INDEX_FILENAME = "index.idx"; static const char *TMP_EXTENSION = ".data"; - +static const char *PRESET_SUBPATH = "presets"; +static const char *PLUGINS_SUBPATH = "plugins"; void copy_file_fix(const fs::path &source, const fs::path &target) { @@ -80,13 +81,13 @@ void copy_directory_fix(const fs::path &source, const fs::path &target) if (fs::exists(target)) fs::remove_all(target); fs::create_directories(target); - for (auto &dir_entry : boost::filesystem::directory_iterator(source)) + for (auto &dir_entry : fs::directory_iterator(source)) { std::string source_file = dir_entry.path().string(); std::string name = dir_entry.path().filename().string(); std::string target_file = target.string() + "/" + name; - if (boost::filesystem::is_directory(dir_entry)) { + if (fs::is_directory(dir_entry)) { const auto target_path = target / name; copy_directory_fix(dir_entry, target_path); } @@ -220,6 +221,7 @@ struct PresetUpdater::priv std::string version; std::string description; std::string url; + std::string vendor; bool force{false}; std::string cache_root; std::vector sub_caches; @@ -234,8 +236,14 @@ struct PresetUpdater::priv void prune_tmps() const; void sync_version() const; void parse_version_string(const std::string& body) const; - void sync_resources(std::string http_url, std::map &resources, bool check_patch = false, std::string current_version="", std::string changelog_file=""); - void sync_config(std::string http_url, const VendorMap vendors); + bool sync_resources(std::string http_url, std::map &resources, bool check_patch = false, std::string current_version="", std::string changelog_file=""); + + void remove_config_files(std::string vendor, std::string sub_path) const; + //compare_count means how many sub-versions in AA.BB.CC.DD need to be checked + bool get_valid_ota_version(Semver& app_version, Semver& current_version, Semver& cached_version, int compare_count) const; + void parse_ota_files(std::string ota_json, std::string& version, bool& force_upgrade, std::string& description) const; + + bool sync_config(std::string http_url, const VendorMap vendors); 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); @@ -380,7 +388,7 @@ bool PresetUpdater::priv::extract_file(const fs::path &source_path, const fs::pa // Remove leftover paritally downloaded files, if any. void PresetUpdater::priv::prune_tmps() const { - for (auto &dir_entry : boost::filesystem::directory_iterator(cache_path)) + for (auto &dir_entry : fs::directory_iterator(cache_path)) if (is_plain_file(dir_entry) && dir_entry.path().extension() == TMP_EXTENSION) { BOOST_LOG_TRIVIAL(debug) << "[BBL Updater]remove old cached files: " << dir_entry.path().string(); fs::remove(dir_entry.path()); @@ -489,8 +497,9 @@ void PresetUpdater::priv::parse_version_string(const std::string& body) const //BBS: refine the Preset Updater logic // Download vendor indices. Also download new bundles if an index indicates there's a new one available. // Both are saved in cache. -void PresetUpdater::priv::sync_resources(std::string http_url, std::map &resources, bool check_patch, std::string current_version_str, std::string changelog_file) +bool PresetUpdater::priv::sync_resources(std::string http_url, std::map &resources, bool check_patch, std::string current_version_str, std::string changelog_file) { + bool has_new_update = false; std::map resource_list; BOOST_LOG_TRIVIAL(info) << boost::format("[BBL Updater]: sync_resources get preferred setting version for app version %1%, url: %2%, current_version_str %3%, check_patch %4%")%SLIC3R_APP_NAME%http_url%current_version_str%check_patch; @@ -498,7 +507,7 @@ void PresetUpdater::priv::sync_resources(std::string http_url, std::map current_version.min()) + || ((cached_version.min() == current_version.min()) && (cached_patch_cc > curent_patch_cc)) + || ((cached_version.min() == current_version.min()) && (cached_patch_cc == curent_patch_cc) && (cached_patch_dd > curent_patch_dd) ))) + valid = true; + } + else if (compare_count == 2) { + if ((cached_version.maj() == app_version.maj()) && (cached_version.min() == app_version.min()) + && ((cached_patch_cc > curent_patch_cc) + || ((cached_patch_cc == curent_patch_cc) && (cached_patch_dd > curent_patch_dd) ))) + valid = true; + } + else if (compare_count == 3) { + if ((cached_version.maj() == app_version.maj()) && (cached_version.min() == app_version.min()) && (cached_patch_cc == app_patch_cc) + && (cached_patch_dd > curent_patch_dd)) + valid = true; + } + return valid; +} + + +void PresetUpdater::priv::parse_ota_files(std::string ota_json, std::string& version, bool& force_upgrade, std::string& description) const +{ + version.clear(); + if (fs::exists(ota_json)) { + try { + boost::nowide::ifstream ifs(ota_json); + json j; + ifs >> j; + + if (j.contains("version")) + version = j["version"]; + if (j.contains("force")) + force_upgrade = j["force"]; + if (j.contains("description")) + description = j["description"]; + + BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(": ota_json %1%, version %2%, force %3%, description %4%")%ota_json %version %force_upgrade %description; + } + catch(nlohmann::detail::parse_error &err) { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": parse "<> vendor_list; - std::map vendor_descriptions; + bool has_new_config = false; + //std::map> vendor_list; + //std::map vendor_descriptions; BOOST_LOG_TRIVIAL(info) << boost::format("[BBL Updater]: sync_config Syncing configuration enter"); - if (!enabled_config_update) { return; } + if (!enabled_config_update) { return has_new_config; } BOOST_LOG_TRIVIAL(info) << boost::format("[BBL Updater]: sync_config get preferred setting version for app version %1%, http_url: %2%")%SLIC3R_VERSION%http_url; + auto cache_folder = cache_path / PRESET_SUBPATH; + std::string curr_app_version = SLIC3R_VERSION; + std::string using_app_version = curr_app_version.substr(0, 6) + "00.00"; + + for (auto vendor_it :vendors) { + const VendorProfile& vendor_profile = vendor_it.second; + std::string vendor_name = vendor_profile.id, vendor = vendor_profile.id; + boost::to_lower(vendor_name); + if (vendor != PresetBundle::BBL_BUNDLE) + continue; + + std::string vendor_ota_json = cache_folder.string() + "/"+vendor+".changelog"; + std::string vendor_resource_json = vendor_path.string() + "/"+vendor+".json"; + Semver current_preset_semver = get_version_from_json(vendor_resource_json); + std::string cached_version, description; + bool force = false, remove_previous = true, valid_version = false; + + //check previous cached config files, and delete unused + parse_ota_files(vendor_ota_json, cached_version, force, description); + if (!cached_version.empty()) { + Semver app_semver = curr_app_version; + Semver cached_semver = cached_version; + + valid_version = get_valid_ota_version(app_semver, current_preset_semver, cached_semver, 2); + + if (valid_version) { + remove_previous = false; + current_preset_semver = cached_semver; + has_new_config = true; + } + } + + //remove previous config files + if (remove_previous) + remove_config_files(vendor, PRESET_SUBPATH); + + //check online versions + try { + std::map resources + { + {"slicer/settings/"+vendor_name, { using_app_version, "", "", vendor, false, cache_folder.string()}} + }; + has_new_config |= sync_resources(http_url, resources, false, current_preset_semver.to_string(), vendor+".changelog"); + } + catch (std::exception& e) { + BOOST_LOG_TRIVIAL(warning) << format("[BBL Updater] sync_plugins: %1%", e.what()); + } + } +#if 0 std::string app_version = SLIC3R_VERSION; std::string query_version = app_version.substr(0, 6) + "00.00"; std::string query_params = "?"; @@ -721,6 +879,7 @@ void PresetUpdater::priv::sync_config(std::string http_url, const VendorMap vend std::string type; std::string vendor; std::string description; + bool force_upgrade = false; for (auto sub_iter = iter.value().begin(); sub_iter != iter.value().end(); sub_iter++) { if (boost::iequals(sub_iter.key(),"type")) { type = sub_iter.value(); @@ -735,6 +894,10 @@ void PresetUpdater::priv::sync_config(std::string http_url, const VendorMap vend else if (boost::iequals(sub_iter.key(),"url")) { url = sub_iter.value(); } + else if (boost::iequals(sub_iter.key(), "force_update")) { + force_upgrade = sub_iter.value(); + } + } BOOST_LOG_TRIVIAL(info) << "[BBL Updater]: get type "<< type <<", version "< resources { - {"slicer/tooltip/common", { common_version, "", "", false, (cache_root / "common").string() }}, - {"slicer/tooltip/" + language, { language_version, "", "", false, (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) { @@ -903,9 +1068,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 &force) { - std::string data_dir_str = data_dir(); - boost::filesystem::path data_dir_path(data_dir_str); - auto cache_folder = data_dir_path / "ota"; + auto cache_folder = cache_path / "plugins"; std::string network_library, player_library, live555_library; bool has_plugins = false; @@ -924,28 +1087,14 @@ bool PresetUpdater::priv::get_cached_plugins_version(std::string& cached_version #endif std::string changelog_file = cache_folder.string() + "/network_plugins.json"; - if (boost::filesystem::exists(network_library) - && boost::filesystem::exists(player_library) - && boost::filesystem::exists(live555_library) - && boost::filesystem::exists(changelog_file)) + if (fs::exists(network_library) + && fs::exists(player_library) + && fs::exists(live555_library) + && fs::exists(changelog_file)) { has_plugins = true; - try { - boost::nowide::ifstream ifs(changelog_file); - json j; - ifs >> j; - - if (j.contains("version")) - cached_version = j["version"]; - if (j.contains("force")) - force = j["force"]; - - BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< ": cached_version = "< resources { - {"slicer/plugins/cloud", { using_version, "", "", false, cache_path.string(), {"plugins"}}} + {"slicer/plugins/cloud", { using_version, "", "", "", false, cache_plugin_folder.string()}} }; sync_resources(http_url, resources, true, plugin_version, "network_plugins.json"); } @@ -1086,7 +1177,7 @@ void PresetUpdater::priv::sync_printer_config(std::string http_url) std::string cached_version; std::string data_dir_str = data_dir(); - boost::filesystem::path data_dir_path(data_dir_str); + fs::path data_dir_path(data_dir_str); auto config_folder = data_dir_path / "printers"; auto cache_folder = data_dir_path / "ota" / "printers"; @@ -1104,28 +1195,32 @@ void PresetUpdater::priv::sync_printer_config(std::string http_url) } catch (...) {} if (!cached_version.empty()) { bool need_delete_cache = false; - Semver current_semver = curr_version; - Semver cached_semver = cached_version; + Semver current_semver = curr_version; + Semver cached_semver = cached_version; if ((cached_semver.maj() != current_semver.maj()) || (cached_semver.min() != current_semver.min())) { need_delete_cache = true; BOOST_LOG_TRIVIAL(info) << boost::format("cached printer config version %1% not match with current %2%") % cached_version % curr_version; - } else if (cached_semver.patch() <= current_semver.patch()) { + } + else if (cached_semver.patch() <= current_semver.patch()) { need_delete_cache = true; BOOST_LOG_TRIVIAL(info) << boost::format("cached printer config version %1% not newer than current %2%") % cached_version % curr_version; - } else { + } + else { using_version = cached_version; } if (need_delete_cache) { boost::system::error_code ec; - boost::filesystem::remove_all(cache_folder, ec); - cached_version = curr_version; + fs::remove_all(cache_folder, ec); + cached_version = curr_version; } } + else + cached_version = curr_version; try { - std::map resources{{"slicer/printer/bbl", {using_version, "", "", false, 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()); @@ -1185,7 +1280,7 @@ void PresetUpdater::priv::check_installed_vendor_profiles() const //BBS: refine the init check logic std::vector bundles; - for (auto &dir_entry : boost::filesystem::directory_iterator(rsrc_path)) { + for (auto &dir_entry : fs::directory_iterator(rsrc_path)) { const auto &path = dir_entry.path(); std::string file_path = path.string(); if (is_json_file(file_path)) { @@ -1231,8 +1326,8 @@ void PresetUpdater::priv::check_installed_vendor_profiles() const Updates PresetUpdater::priv::get_printer_config_updates(bool update) const { std::string data_dir_str = data_dir(); - boost::filesystem::path data_dir_path(data_dir_str); - boost::filesystem::path resc_dir_path(resources_dir()); + fs::path data_dir_path(data_dir_str); + fs::path resc_dir_path(resources_dir()); auto config_folder = data_dir_path / "printers"; auto resc_folder = (update ? cache_path : resc_dir_path) / "printers"; std::string curr_version; @@ -1285,67 +1380,57 @@ Updates PresetUpdater::priv::get_printer_config_updates(bool update) const //BBS: refine the Preset Updater logic Updates PresetUpdater::priv::get_config_updates(const Semver &old_slic3r_version) const { - Updates updates; + Updates updates; + auto cache_folder = cache_path / PRESET_SUBPATH; - BOOST_LOG_TRIVIAL(info) << "[BBL Updater]:Checking for cached configuration updates..."; + BOOST_LOG_TRIVIAL(info) << "[BBL Updater]:Checking for cached configuration updates..."; - for (auto &dir_entry : boost::filesystem::directory_iterator(cache_path)) { - const auto &path = dir_entry.path(); - std::string file_path = path.string(); - if (is_json_file(file_path)) { - const auto path_in_vendor = vendor_path / path.filename(); - std::string vendor_name = path.filename().string(); - // Remove the .json suffix. - vendor_name.erase(vendor_name.size() - 5); - auto print_in_cache = (cache_path / vendor_name / PRESET_PRINT_NAME); - auto filament_in_cache = (cache_path / vendor_name / PRESET_FILAMENT_NAME); - auto machine_in_cache = (cache_path / vendor_name / PRESET_PRINTER_NAME); + //remove previous old datas + remove_config_files("BBL", std::string()); - if (( fs::exists(path_in_vendor)) - &&( fs::exists(print_in_cache)) - &&( fs::exists(filament_in_cache)) - &&( fs::exists(machine_in_cache))) { - Semver vendor_ver = get_version_from_json(path_in_vendor.string()); + if (fs::exists(cache_folder)) { + for (auto& dir_entry : fs::directory_iterator(cache_folder)) { + const auto& path = dir_entry.path(); + std::string file_path = path.string(); + if (is_json_file(file_path)) { + const auto path_in_vendor = vendor_path / path.filename(); + std::string vendor_name = path.filename().string(), cached_version, description; + // Remove the .json suffix. + vendor_name.erase(vendor_name.size() - 5); + auto print_in_cache = (cache_folder / vendor_name / PRESET_PRINT_NAME); + auto filament_in_cache = (cache_folder / vendor_name / PRESET_FILAMENT_NAME); + auto machine_in_cache = (cache_folder / vendor_name / PRESET_PRINTER_NAME); - std::map key_values; - std::vector keys(3); - Semver cache_ver; - keys[0] = BBL_JSON_KEY_VERSION; - keys[1] = BBL_JSON_KEY_DESCRIPTION; - keys[2] = BBL_JSON_KEY_FORCE_UPDATE; - get_values_from_json(file_path, keys, key_values); - std::string description = key_values[BBL_JSON_KEY_DESCRIPTION]; - bool force_update = false; - if (key_values.find(BBL_JSON_KEY_FORCE_UPDATE) != key_values.end()) - force_update = (key_values[BBL_JSON_KEY_FORCE_UPDATE] == "1")?true:false; - auto config_version = Semver::parse(key_values[BBL_JSON_KEY_VERSION]); - if (config_version) - cache_ver = *config_version; + std::string changelog_file = (cache_folder / (vendor_name + ".changelog")).string(); + bool force_update; - std::string changelog; - std::string changelog_file = (cache_path / (vendor_name + ".changelog")).string(); - boost::nowide::ifstream ifs(changelog_file); - if (ifs) { - std::ostringstream oss; - oss<< ifs.rdbuf(); - changelog = oss.str(); - //ifs>>changelog; - ifs.close(); - } + if ((fs::exists(path_in_vendor)) + && (fs::exists(print_in_cache)) + && (fs::exists(filament_in_cache)) + && (fs::exists(machine_in_cache))) { - bool version_match = ((vendor_ver.maj() == cache_ver.maj()) && (vendor_ver.min() == cache_ver.min())); - if (version_match && (vendor_ver < cache_ver)) { - Semver app_ver = *Semver::parse(SLIC3R_VERSION); - if (cache_ver.maj() == app_ver.maj()){ - BOOST_LOG_TRIVIAL(info) << "[BBL Updater]:need to update settings from "<set_download_prefs(GUI::wxGetApp().app_config); - if (!p->enabled_version_check && !p->enabled_config_update) { return; } + //p->set_download_prefs(GUI::wxGetApp().app_config); + if (!p->enabled_version_check && !p->enabled_config_update) { return; } - // Copy the whole vendors data for use in the background thread - // Unfortunatelly as of C++11, it needs to be copied again - // into the closure (but perhaps the compiler can elide this). + // Copy the whole vendors data for use in the background thread + // Unfortunatelly as of C++11, it needs to be copied again + // into the closure (but perhaps the compiler can elide this). VendorMap vendors = preset_bundle ? preset_bundle->vendors : VendorMap{}; - p->thread = std::thread([this, vendors, http_url, language, plugin_version]() { - this->p->prune_tmps(); - if (p->cancel) - return; - this->p->sync_version(); - if (p->cancel) - return; + p->thread = std::thread([this, vendors, http_url, language, plugin_version]() { + this->p->prune_tmps(); + if (p->cancel) + return; + //not used + //this->p->sync_version(); + //if (p->cancel) + // return; if (!vendors.empty()) { - this->p->sync_config(http_url, std::move(vendors)); - if (p->cancel) - return; - GUI::wxGetApp().CallAfter([] { - GUI::wxGetApp().check_config_updates_from_updater(); - }); + bool has_new_config = this->p->sync_config(http_url, std::move(vendors)); + if (p->cancel) + return; + if (has_new_config) { + GUI::wxGetApp().CallAfter([] { + GUI::wxGetApp().check_config_updates_from_updater(); + }); + } } - if (p->cancel) - return; + if (p->cancel) + return; this->p->sync_plugins(http_url, plugin_version); this->p->sync_printer_config(http_url); - //if (p->cancel) - // return; - //remove the tooltip currently - //this->p->sync_tooltip(http_url, language); - }); + //if (p->cancel) + // return; + //remove the tooltip currently + //this->p->sync_tooltip(http_url, language); + }); } void PresetUpdater::slic3r_update_notify()