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.
This commit is contained in:
bubnikv 2019-12-05 11:04:18 +01:00
parent 26eaa8af1e
commit ab34ef3ceb
5 changed files with 30 additions and 13 deletions

View File

@ -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(); 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(); const_iterator highest = this->end();
for (const_iterator it = this->begin(); it != this->end(); ++ it) 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 == this->end() || highest->config_version < it->config_version))
highest = it; highest = it;
return highest; return highest;
} }
Index::const_iterator Index::recommended() const
{
return this->recommended(Slic3r::SEMVER);
}
std::vector<Index> Index::load_db() std::vector<Index> Index::load_db()
{ {
boost::filesystem::path cache_dir = boost::filesystem::path(Slic3r::data_dir()) / "cache"; boost::filesystem::path cache_dir = boost::filesystem::path(Slic3r::data_dir()) / "cache";

View File

@ -71,6 +71,8 @@ public:
// Returns configs().end() if such version does not exist in the index. This shall never happen // Returns configs().end() if such version does not exist in the index. This shall never happen
// if the index is valid. // if the index is valid.
const_iterator recommended() const; 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 // Returns the filesystem path from which this index has originally been loaded
const boost::filesystem::path& path() const { return m_path; } const boost::filesystem::path& path() const { return m_path; }

View File

@ -283,7 +283,7 @@ bool GUI_App::on_init_inner()
PresetUpdater::UpdateResult updater_result; PresetUpdater::UpdateResult updater_result;
try { try {
updater_result = preset_updater->config_update(); updater_result = preset_updater->config_update(app_config->orig_version());
if (updater_result == PresetUpdater::R_INCOMPAT_EXIT) { if (updater_result == PresetUpdater::R_INCOMPAT_EXIT) {
mainframe->Close(); mainframe->Close();
} else if (updater_result == PresetUpdater::R_INCOMPAT_CONFIGURED) { } else if (updater_result == PresetUpdater::R_INCOMPAT_CONFIGURED) {

View File

@ -156,7 +156,7 @@ struct PresetUpdater::priv
void sync_config(const VendorMap vendors); void sync_config(const VendorMap vendors);
void check_install_indices() const; 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; void perform_updates(Updates &&updates, bool snapshot = true) const;
}; };
@ -167,7 +167,9 @@ PresetUpdater::priv::priv()
, cancel(false) , cancel(false)
{ {
set_download_prefs(GUI::wxGetApp().app_config); 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(); check_install_indices();
// Load indices from the cache directory.
index_db = Index::load_db(); index_db = Index::load_db();
} }
@ -273,6 +275,7 @@ void PresetUpdater::priv::sync_config(const VendorMap vendors)
if (!enabled_config_update) { return; } if (!enabled_config_update) { return; }
// Donwload vendor preset bundles // Donwload vendor preset bundles
// Over all indices from the cache directory:
for (auto &index : index_db) { for (auto &index : index_db) {
if (cancel) { return; } 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 // Generates a list of bundle updates that are to be performed.
Updates PresetUpdater::priv::get_config_updates() const // 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; Updates updates;
BOOST_LOG_TRIVIAL(info) << "Checking for cached configuration updates..."; BOOST_LOG_TRIVIAL(info) << "Checking for cached configuration updates...";
// Over all indices from the cache directory:
for (const auto idx : index_db) { for (const auto idx : index_db) {
auto bundle_path = vendor_path / (idx.vendor() + ".ini"); auto bundle_path = vendor_path / (idx.vendor() + ".ini");
auto bundle_path_idx = vendor_path / idx.path().filename(); auto bundle_path_idx = vendor_path / idx.path().filename();
@ -382,7 +388,7 @@ Updates PresetUpdater::priv::get_config_updates() const
continue; 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); auto vp = VendorProfile::from_ini(bundle_path, false);
// Getting a recommended version from the latest index, wich may have been downloaded // 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(); 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); updates.incompats.emplace_back(std::move(bundle_path), *ver_current, vp.name);
} else if (recommended->config_version > vp.config_version) { } 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. // Load 'installed' idx, if any.
// 'Installed' indices are kept alongside the bundle in the `vendor` subdir // '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; Index existing_idx;
try { try {
existing_idx.load(bundle_path_idx); existing_idx.load(bundle_path_idx);
// Find a recommended config bundle version for the slic3r version last executed. This makes sure that a config bundle update will not be missed
const auto existing_recommended = existing_idx.recommended(); // 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) { if (existing_recommended != existing_idx.end() && recommended->config_version == existing_recommended->config_version) {
// The user has already seen (and presumably rejected) this update // 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(); 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; } 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) { if (updates.incompats.size() > 0) {
BOOST_LOG_TRIVIAL(info) << boost::format("%1% bundles incompatible. Asking for action...") % updates.incompats.size(); BOOST_LOG_TRIVIAL(info) << boost::format("%1% bundles incompatible. Asking for action...") % updates.incompats.size();

View File

@ -38,7 +38,9 @@ public:
// If updating is enabled, check if updates are available in cache, if so, ask about installation. // 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. // 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). // "Update" a list of bundles from resources (behaves like an online update).
void install_bundles_rsrc(std::vector<std::string> bundles, bool snapshot = true) const; void install_bundles_rsrc(std::vector<std::string> bundles, bool snapshot = true) const;