diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index cc7f6ab171..e2ff58cebf 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -3354,8 +3354,9 @@ bool ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese if (install_bundles.size() > 0) { // Install bundles from resources or cache / vendor. // Don't create snapshot - we've already done that above if applicable. - - bool install_result = updater->install_bundles_rsrc_or_cache_vendor(std::move(install_bundles), false); + GUI_App& app = wxGetApp(); + const auto* archive_db = app.plater()->get_preset_archive_database(); + bool install_result = updater->install_bundles_rsrc_or_cache_vendor(std::move(install_bundles), archive_db->get_archive_repositories(), false); if (!install_result) return false; } else { @@ -3574,10 +3575,11 @@ void ConfigWizard::priv::set_config_updated_from_archive(bool is_updated) // This set with preset_updater used to be done in GUI_App::run_wizard before ConfigWizard::run() GUI_App& app = wxGetApp(); // Do blocking sync on every change of archive repos, so user is always offered recent profiles. - app.preset_updater->sync_blocking(app.preset_bundle, &app, app.plater()->get_preset_archive_database()->get_archive_repositories(), app.plater()->get_preset_archive_database()->get_selected_repositories_uuid()); + const ArchiveRepositoryVector &repos = app.plater()->get_preset_archive_database()->get_archive_repositories(); + app.preset_updater->sync_blocking(app.preset_bundle, &app, repos, app.plater()->get_preset_archive_database()->get_selected_repositories_uuid()); // Offer update installation. It used to be offered only when wizard run reason was RR_USER. app.preset_updater->update_index_db(); - app.preset_updater->config_update(app.app_config->orig_version(), PresetUpdater::UpdateParams::SHOW_TEXT_BOX); + app.preset_updater->config_update(app.app_config->orig_version(), PresetUpdater::UpdateParams::SHOW_TEXT_BOX, repos); // We have now probably changed data. We need to rebuild or database from which wizards constructs. // DK: Im not sure if we should do full load_vendors. or only load BundleMap::load(). diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 8f61b51999..65b6f8e616 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -3475,7 +3475,7 @@ bool GUI_App::check_updates(const bool verbose) PresetUpdater::UpdateResult updater_result; try { preset_updater->update_index_db(); - 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, plater()->get_preset_archive_database()->get_archive_repositories()); if (updater_result == PresetUpdater::R_INCOMPAT_EXIT) { mainframe->Close(); // Applicaiton is closing. diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 957a16fb22..94284ce2a8 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -781,7 +781,10 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) if (wxGetApp().is_editor()) { this->q->Bind(EVT_EJECT_DRIVE_NOTIFICAION_CLICKED, [this](EjectDriveNotificationClickedEvent&) { this->q->eject_drive(); }); this->q->Bind(EVT_EXPORT_GCODE_NOTIFICAION_CLICKED, [this](ExportGcodeNotificationClickedEvent&) { this->q->export_gcode(true); }); - this->q->Bind(EVT_PRESET_UPDATE_AVAILABLE_CLICKED, [](PresetUpdateAvailableClickedEvent&) { wxGetApp().get_preset_updater()->on_update_notification_confirm(); }); + this->q->Bind(EVT_PRESET_UPDATE_AVAILABLE_CLICKED, [](PresetUpdateAvailableClickedEvent&) { + GUI_App &app = wxGetApp(); + app.get_preset_updater()->on_update_notification_confirm(app.plater()->get_preset_archive_database()->get_archive_repositories()); + }); this->q->Bind(EVT_REMOVABLE_DRIVE_EJECTED, [this, q](RemovableDriveEjectEvent &evt) { if (evt.data.second) { q->show_action_buttons(); diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index a486b5c970..bdbd341ba1 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -184,21 +184,18 @@ struct PresetUpdater::priv priv(); void set_download_prefs(const AppConfig *app_config); - //bool get_file(const std::string &url, const fs::path &target_path) const; void prune_tmps() const; void clear_cache_vendor() const; void sync_config(const VendorMap& vendors, const GUI::ArchiveRepository& archive); void check_install_indices() const; Updates get_config_updates(const Semver& old_slic3r_version) const; - bool perform_updates(Updates &&updates, bool snapshot = true) const; + bool perform_updates(Updates &&updates, const ArchiveRepositoryVector& repositories, bool snapshot = true) const; void set_waiting_updates(Updates u); // checks existence and downloads resource to cache void get_missing_resource(const GUI::ArchiveRepository& archive, const std::string& vendor, const std::string& filename, const std::string& repository_id_from_ini) const; // checks existence and downloads resource to vendor or copy from cache to vendor void get_or_copy_missing_resource(const GUI::ArchiveRepository& archive, const std::string& vendor, const std::string& filename, const std::string& repository_id_from_ini) const; - // checks existence and copies resource to vendor from cache to vendor - void copy_missing_resource(const std::string& vendor, const std::string& filename, const std::string& url) const; void update_index_db(); }; @@ -229,41 +226,6 @@ void PresetUpdater::priv::set_download_prefs(const AppConfig *app_config) enabled_config_update = app_config->get_bool("preset_update") && !app_config->legacy_datadir(); } -// Downloads a file (http get operation). Cancels if the Updater is being destroyed. -//bool PresetUpdater::priv::get_file(const std::string &url, const fs::path &target_path) const -//{ -// bool res = false; -// fs::path tmp_path = target_path; -// tmp_path += format(".%1%%2%", get_current_pid(), TMP_EXTENSION); -// -// BOOST_LOG_TRIVIAL(info) << format("Get: `%1%`\n\t-> `%2%`\n\tvia tmp path `%3%`", -// url, -// target_path.string(), -// tmp_path.string()); -// -// Http::get(url) -// .on_progress([](Http::Progress, bool &cancel) { -// if (cancel) { cancel = true; } -// }) -// .on_error([&](std::string body, std::string error, unsigned http_status) { -// (void)body; -// BOOST_LOG_TRIVIAL(error) << format("Error getting: `%1%`: HTTP %2%, %3%", -// url, -// http_status, -// error); -// }) -// .on_complete([&](std::string body, unsigned /* http_status */) { -// fs::fstream file(tmp_path, std::ios::out | std::ios::binary | std::ios::trunc); -// file.write(body.c_str(), body.size()); -// file.close(); -// fs::rename(tmp_path, target_path); -// res = true; -// }) -// .perform_sync(); -// -// return res; -//} - // Remove leftover paritally downloaded files, if any. void PresetUpdater::priv::prune_tmps() const { @@ -359,35 +321,6 @@ void PresetUpdater::priv::get_or_copy_missing_resource(const GUI::ArchiveReposit BOOST_LOG_TRIVIAL(debug) << "Copiing: " << file_in_cache << " to " << file_in_vendor; copy_file_fix(file_in_cache, file_in_vendor); } -// gets resource to vendor// -void PresetUpdater::priv::copy_missing_resource(const std::string& vendor, const std::string& filename, const std::string& url) const -{ - if (filename.empty() || vendor.empty()) - return; - - const fs::path file_in_vendor(vendor_path / (vendor + "/" + filename)); - const fs::path file_in_rsrc(rsrc_path / (vendor + "/" + filename)); - const fs::path file_in_cache(cache_path / (vendor + "/" + filename)); - - if (fs::exists(file_in_vendor)) { // Already in vendor. No need to do anything. - BOOST_LOG_TRIVIAL(info) << "Resource " << vendor << " / " << filename << " found in vendor folder. No need to download."; - return; - } - if (fs::exists(file_in_rsrc)) { // In resources dir since installation. No need to do anything. - BOOST_LOG_TRIVIAL(info) << "Resource " << vendor << " / " << filename << " found in resources folder. No need to download."; - return; - } - if (!fs::exists(file_in_cache)) { // No file to copy. Bad! - BOOST_LOG_TRIVIAL(error) << "Resource " << vendor << " / " << filename << " not found!"; - return; - } - - if (!fs::exists(file_in_vendor.parent_path())) // create vendor_name dir in vendor - fs::create_directory(file_in_vendor.parent_path()); - - BOOST_LOG_TRIVIAL(debug) << "Copiing: " << file_in_cache << " to " << file_in_vendor; - copy_file_fix(file_in_cache, file_in_vendor); -} // Download vendor indices. Also download new bundles if an index indicates there's a new one available. // Both are saved in cache. @@ -788,14 +721,14 @@ void PresetUpdater::priv::sync_config(const VendorMap& vendors, const GUI::Archi } for (const auto& model : vp.models) { for (const std::string& res : { model.bed_texture, model.bed_model, model.thumbnail }) { - if (!model.thumbnail.empty()) { + if (!res.empty()) { try { get_or_copy_missing_resource(archive_repository, vp.id, res, vp.repo_id); } catch (const std::exception& e) { - BOOST_LOG_TRIVIAL(error) << "Failed to get " << model.thumbnail << " for " << vp.id << " " << model.id << ": " << e.what(); + BOOST_LOG_TRIVIAL(error) << "Failed to get " << res << " for " << vp.id << " " << model.id << ": " << e.what(); } } if (cancel) @@ -1029,7 +962,7 @@ Updates PresetUpdater::priv::get_config_updates(const Semver &old_slic3r_version return updates; } -bool PresetUpdater::priv::perform_updates(Updates &&updates, bool snapshot) const +bool PresetUpdater::priv::perform_updates(Updates &&updates, const ArchiveRepositoryVector& repositories, bool snapshot) const { if (updates.incompats.size() > 0) { if (snapshot) { @@ -1116,7 +1049,12 @@ bool PresetUpdater::priv::perform_updates(Updates &&updates, bool snapshot) cons continue; try { - copy_missing_resource(vp.id, resource, vp.config_update_url); + auto it = std::find_if(repositories.begin(), repositories.end(), [&vp](const auto& i){ return vp.repo_id == i->get_manifest().id; }); + if (it != repositories.end()) + get_or_copy_missing_resource(*(*it), vp.id, resource, vp.repo_id); + else { + BOOST_LOG_TRIVIAL(error) << "Failed to prepare " << resource << " for " << vp.id << " " << model.id << ": Missing record for repository with repo_id " << vp.repo_id; + } } catch (const std::exception& e) { @@ -1159,7 +1097,7 @@ void PresetUpdater::sync(const PresetBundle *preset_bundle, wxEvtHandler* evt_ha { p->set_download_prefs(GUI::wxGetApp().app_config); if (!p->enabled_config_update) { return; } - + p->thread = std::thread([this, &vendors = preset_bundle->vendors, &repositories, &selected_repo_uuids, evt_handler]() { this->p->clear_cache_vendor(); this->p->prune_tmps(); @@ -1247,7 +1185,7 @@ static bool reload_configs_update_gui() return true; } -PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3r_version, UpdateParams params) const +PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3r_version, UpdateParams params, const ArchiveRepositoryVector& repositories) const { if (! p->enabled_config_update) { return R_NOOP; } @@ -1281,7 +1219,7 @@ PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3 // This effectively removes the incompatible bundles: // (snapshot is taken beforehand) - if (! p->perform_updates(std::move(updates)) || + if (! p->perform_updates(std::move(updates), repositories) || ! GUI::wxGetApp().run_wizard(GUI::ConfigWizard::RR_DATA_INCOMPAT)) return R_INCOMPAT_EXIT; @@ -1323,7 +1261,7 @@ PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3 const auto res = dlg.ShowModal(); if (res == wxID_OK) { BOOST_LOG_TRIVIAL(info) << "User wants to update..."; - if (! p->perform_updates(std::move(updates)) || + if (! p->perform_updates(std::move(updates), repositories) || ! reload_configs_update_gui()) return R_INCOMPAT_EXIT; return R_UPDATE_INSTALLED; @@ -1366,7 +1304,7 @@ PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3 const auto res = dlg.ShowModal(); if (res == wxID_OK) { BOOST_LOG_TRIVIAL(debug) << "User agreed to perform the update"; - if (! p->perform_updates(std::move(updates)) || + if (! p->perform_updates(std::move(updates), repositories) || ! reload_configs_update_gui()) return R_ALL_CANCELED; return R_UPDATE_INSTALLED; @@ -1387,7 +1325,7 @@ PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3 return R_NOOP; } -bool PresetUpdater::install_bundles_rsrc_or_cache_vendor(std::vector bundles, bool snapshot) const +bool PresetUpdater::install_bundles_rsrc_or_cache_vendor(std::vector bundles, const ArchiveRepositoryVector& repositories, bool snapshot) const { Updates updates; @@ -1490,10 +1428,10 @@ bool PresetUpdater::install_bundles_rsrc_or_cache_vendor(std::vectorperform_updates(std::move(updates), snapshot); + return p->perform_updates(std::move(updates), repositories, snapshot); } -void PresetUpdater::on_update_notification_confirm() +void PresetUpdater::on_update_notification_confirm(const ArchiveRepositoryVector& repositories) { if (!p->has_waiting_updates) return; @@ -1516,7 +1454,7 @@ void PresetUpdater::on_update_notification_confirm() const auto res = dlg.ShowModal(); if (res == wxID_OK) { BOOST_LOG_TRIVIAL(debug) << "User agreed to perform the update"; - if (p->perform_updates(std::move(p->waiting_updates)) && + if (p->perform_updates(std::move(p->waiting_updates), repositories) && reload_configs_update_gui()) { p->has_waiting_updates = false; } diff --git a/src/slic3r/Utils/PresetUpdater.hpp b/src/slic3r/Utils/PresetUpdater.hpp index 59520ae34d..c1d8c43f48 100644 --- a/src/slic3r/Utils/PresetUpdater.hpp +++ b/src/slic3r/Utils/PresetUpdater.hpp @@ -62,14 +62,14 @@ public: // A false return value implies Slic3r should exit due to incompatibility of configuration. // 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, UpdateParams params) const; + UpdateResult config_update(const Semver &old_slic3r_version, UpdateParams params, const ArchiveRepositoryVector& repositories) const; void update_index_db(); // "Update" a list of bundles from resources or cache/vendor (behaves like an online update). - bool install_bundles_rsrc_or_cache_vendor(std::vector bundles, bool snapshot = true) const; + bool install_bundles_rsrc_or_cache_vendor(std::vector bundles, const ArchiveRepositoryVector& repositories, bool snapshot = true) const; - void on_update_notification_confirm(); + void on_update_notification_confirm(const ArchiveRepositoryVector& repositories); bool version_check_enabled() const;