From ab34ef3ceb6b487845ab371c7796af2f23dfb3c2 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Thu, 5 Dec 2019 11:04:18 +0100 Subject: [PATCH] Fix of an application update situation, where the profiles were not updated correctly if the index installed in vendor directory was the same as the one provided with the applicaton installation. --- src/slic3r/Config/Version.cpp | 9 +++++++-- src/slic3r/Config/Version.hpp | 2 ++ src/slic3r/GUI/GUI_App.cpp | 2 +- src/slic3r/Utils/PresetUpdater.cpp | 26 +++++++++++++++++--------- src/slic3r/Utils/PresetUpdater.hpp | 4 +++- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/slic3r/Config/Version.cpp b/src/slic3r/Config/Version.cpp index da522dd5e..fcebf88d1 100644 --- a/src/slic3r/Config/Version.cpp +++ b/src/slic3r/Config/Version.cpp @@ -286,16 +286,21 @@ Index::const_iterator Index::find(const Semver &ver) const return (it == m_configs.end() || it->config_version == ver) ? it : m_configs.end(); } -Index::const_iterator Index::recommended() const +Index::const_iterator Index::recommended(const Semver &slic3r_version) const { const_iterator highest = this->end(); for (const_iterator it = this->begin(); it != this->end(); ++ it) - if (it->is_current_slic3r_supported() && + if (it->is_slic3r_supported(slic3r_version) && (highest == this->end() || highest->config_version < it->config_version)) highest = it; return highest; } +Index::const_iterator Index::recommended() const +{ + return this->recommended(Slic3r::SEMVER); +} + std::vector Index::load_db() { boost::filesystem::path cache_dir = boost::filesystem::path(Slic3r::data_dir()) / "cache"; diff --git a/src/slic3r/Config/Version.hpp b/src/slic3r/Config/Version.hpp index 19c565ffb..e5f1a2e21 100644 --- a/src/slic3r/Config/Version.hpp +++ b/src/slic3r/Config/Version.hpp @@ -71,6 +71,8 @@ public: // Returns configs().end() if such version does not exist in the index. This shall never happen // if the index is valid. const_iterator recommended() const; + // Recommended config for a provided slic3r version. Used when checking for slic3r update (slic3r_version is the old one read out from PrusaSlicer.ini) + const_iterator recommended(const Semver &slic3r_version) const; // Returns the filesystem path from which this index has originally been loaded const boost::filesystem::path& path() const { return m_path; } diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 401fb94d8..71448cb05 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -283,7 +283,7 @@ bool GUI_App::on_init_inner() PresetUpdater::UpdateResult updater_result; try { - updater_result = preset_updater->config_update(); + updater_result = preset_updater->config_update(app_config->orig_version()); if (updater_result == PresetUpdater::R_INCOMPAT_EXIT) { mainframe->Close(); } else if (updater_result == PresetUpdater::R_INCOMPAT_CONFIGURED) { diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index 3cebf2f89..d333e96ed 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -156,7 +156,7 @@ struct PresetUpdater::priv void sync_config(const VendorMap vendors); void check_install_indices() const; - Updates get_config_updates() const; + Updates get_config_updates(const Semver& old_slic3r_version) const; void perform_updates(Updates &&updates, bool snapshot = true) const; }; @@ -167,7 +167,9 @@ PresetUpdater::priv::priv() , cancel(false) { set_download_prefs(GUI::wxGetApp().app_config); + // Install indicies from resources. Only installs those that are either missing or older than in resources. check_install_indices(); + // Load indices from the cache directory. index_db = Index::load_db(); } @@ -273,6 +275,7 @@ void PresetUpdater::priv::sync_config(const VendorMap vendors) if (!enabled_config_update) { return; } // Donwload vendor preset bundles + // Over all indices from the cache directory: for (auto &index : index_db) { if (cancel) { return; } @@ -366,13 +369,16 @@ void PresetUpdater::priv::check_install_indices() const } } -// Generates a list of bundle updates that are to be performed -Updates PresetUpdater::priv::get_config_updates() const +// Generates a list of bundle updates that are to be performed. +// Version of slic3r that was running the last time and which was read out from PrusaSlicer.ini is provided +// as a parameter. +Updates PresetUpdater::priv::get_config_updates(const Semver &old_slic3r_version) const { Updates updates; BOOST_LOG_TRIVIAL(info) << "Checking for cached configuration updates..."; + // Over all indices from the cache directory: for (const auto idx : index_db) { auto bundle_path = vendor_path / (idx.vendor() + ".ini"); auto bundle_path_idx = vendor_path / idx.path().filename(); @@ -382,7 +388,7 @@ Updates PresetUpdater::priv::get_config_updates() const continue; } - // Perform a basic load and check the version + // Perform a basic load and check the version of the installed preset bundle. auto vp = VendorProfile::from_ini(bundle_path, false); // Getting a recommended version from the latest index, wich may have been downloaded @@ -414,7 +420,8 @@ Updates PresetUpdater::priv::get_config_updates() const BOOST_LOG_TRIVIAL(warning) << "Current Slic3r incompatible with installed bundle: " << bundle_path.string(); updates.incompats.emplace_back(std::move(bundle_path), *ver_current, vp.name); } else if (recommended->config_version > vp.config_version) { - // Config bundle update situation + // Config bundle update situation. The recommended config bundle version for this PrusaSlicer version from the index from the cache is newer + // than the version of the currently installed config bundle. // Load 'installed' idx, if any. // 'Installed' indices are kept alongside the bundle in the `vendor` subdir @@ -423,8 +430,9 @@ Updates PresetUpdater::priv::get_config_updates() const Index existing_idx; try { existing_idx.load(bundle_path_idx); - - const auto existing_recommended = existing_idx.recommended(); + // Find a recommended config bundle version for the slic3r version last executed. This makes sure that a config bundle update will not be missed + // when upgrading an application. On the other side, the user will be bugged every time he will switch between slic3r versions. + const auto existing_recommended = existing_idx.recommended(old_slic3r_version); if (existing_recommended != existing_idx.end() && recommended->config_version == existing_recommended->config_version) { // The user has already seen (and presumably rejected) this update BOOST_LOG_TRIVIAL(info) << boost::format("Downloaded index for `%1%` is the same as installed one, not offering an update.") % idx.vendor(); @@ -607,11 +615,11 @@ void PresetUpdater::slic3r_update_notify() } } -PresetUpdater::UpdateResult PresetUpdater::config_update() const +PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver &old_slic3r_version) const { if (! p->enabled_config_update) { return R_NOOP; } - auto updates = p->get_config_updates(); + auto updates = p->get_config_updates(old_slic3r_version); if (updates.incompats.size() > 0) { BOOST_LOG_TRIVIAL(info) << boost::format("%1% bundles incompatible. Asking for action...") % updates.incompats.size(); diff --git a/src/slic3r/Utils/PresetUpdater.hpp b/src/slic3r/Utils/PresetUpdater.hpp index 7c2aab7cc..3a0f19893 100644 --- a/src/slic3r/Utils/PresetUpdater.hpp +++ b/src/slic3r/Utils/PresetUpdater.hpp @@ -38,7 +38,9 @@ public: // If updating is enabled, check if updates are available in cache, if so, ask about installation. // A false return value implies Slic3r should exit due to incompatibility of configuration. - UpdateResult config_update() const; + // Providing old slic3r version upgrade profiles on upgrade of an application even in case + // that the config index installed from the Internet is equal to the index contained in the installation package. + UpdateResult config_update(const Semver &old_slic3r_version) const; // "Update" a list of bundles from resources (behaves like an online update). void install_bundles_rsrc(std::vector bundles, bool snapshot = true) const;