diff options
Diffstat (limited to 'src/slic3r/Utils')
-rw-r--r-- | src/slic3r/Utils/FixModelByWin10.cpp | 3 | ||||
-rw-r--r-- | src/slic3r/Utils/HexFile.cpp | 1 | ||||
-rw-r--r-- | src/slic3r/Utils/HexFile.hpp | 1 | ||||
-rw-r--r-- | src/slic3r/Utils/OctoPrint.cpp | 46 | ||||
-rw-r--r-- | src/slic3r/Utils/OctoPrint.hpp | 25 | ||||
-rw-r--r-- | src/slic3r/Utils/PresetUpdater.cpp | 136 | ||||
-rw-r--r-- | src/slic3r/Utils/PresetUpdater.hpp | 14 | ||||
-rw-r--r-- | src/slic3r/Utils/PrintHost.cpp | 1 |
8 files changed, 158 insertions, 69 deletions
diff --git a/src/slic3r/Utils/FixModelByWin10.cpp b/src/slic3r/Utils/FixModelByWin10.cpp index bcab6daaf..9df656701 100644 --- a/src/slic3r/Utils/FixModelByWin10.cpp +++ b/src/slic3r/Utils/FixModelByWin10.cpp @@ -377,7 +377,8 @@ void fix_model_by_win10_sdk_gui(ModelObject &model_object, int volume_idx) // PresetBundle bundle; on_progress(L("Loading repaired model"), 80); DynamicPrintConfig config; - bool loaded = Slic3r::load_3mf(path_dst.string().c_str(), &config, &model, false); + ConfigSubstitutionContext config_substitutions{ ForwardCompatibilitySubstitutionRule::EnableSilent }; + bool loaded = Slic3r::load_3mf(path_dst.string().c_str(), config, config_substitutions, &model, false); boost::filesystem::remove(path_dst); if (! loaded) throw Slic3r::RuntimeError(L("Import of the repaired 3mf file failed")); diff --git a/src/slic3r/Utils/HexFile.cpp b/src/slic3r/Utils/HexFile.cpp index 26596f629..a13fcab02 100644 --- a/src/slic3r/Utils/HexFile.cpp +++ b/src/slic3r/Utils/HexFile.cpp @@ -19,6 +19,7 @@ static HexFile::DeviceKind parse_device_kind(const std::string &str) else if (str == "mk3") { return HexFile::DEV_MK3; } else if (str == "mm-control") { return HexFile::DEV_MM_CONTROL; } else if (str == "cw1") { return HexFile::DEV_CW1; } + else if (str == "cw1s") { return HexFile::DEV_CW1S; } else { return HexFile::DEV_GENERIC; } } diff --git a/src/slic3r/Utils/HexFile.hpp b/src/slic3r/Utils/HexFile.hpp index 742ae00e6..b32d110ed 100644 --- a/src/slic3r/Utils/HexFile.hpp +++ b/src/slic3r/Utils/HexFile.hpp @@ -17,6 +17,7 @@ struct HexFile DEV_MK3, DEV_MM_CONTROL, DEV_CW1, + DEV_CW1S, }; boost::filesystem::path path; diff --git a/src/slic3r/Utils/OctoPrint.cpp b/src/slic3r/Utils/OctoPrint.cpp index bb864c98d..f0d9982e4 100644 --- a/src/slic3r/Utils/OctoPrint.cpp +++ b/src/slic3r/Utils/OctoPrint.cpp @@ -178,7 +178,7 @@ const char* SL1Host::get_name() const { return "SL1Host"; } wxString SL1Host::get_test_ok_msg () const { - return wxString::Format(_L("Connection to %s works correctly."), "Prusa SL1"); + return wxString::Format(_L("Connection to %s works correctly."), "Prusa SL1 / SL1S"); } wxString SL1Host::get_test_failed_msg (wxString &msg) const @@ -209,4 +209,48 @@ void SL1Host::set_auth(Http &http) const } } +// PrusaLink +PrusaLink::PrusaLink(DynamicPrintConfig* config) : + OctoPrint(config), + authorization_type(dynamic_cast<const ConfigOptionEnum<AuthorizationType>*>(config->option("printhost_authorization_type"))->value), + username(config->opt_string("printhost_user")), + password(config->opt_string("printhost_password")) +{ +} + +const char* PrusaLink::get_name() const { return "PrusaLink"; } + +wxString PrusaLink::get_test_ok_msg() const +{ + return _(L("Connection to PrusaLink works correctly.")); +} + +wxString PrusaLink::get_test_failed_msg(wxString& msg) const +{ + return GUI::from_u8((boost::format("%s: %s") + % _utf8(L("Could not connect to PrusaLink")) + % std::string(msg.ToUTF8())).str()); +} + +bool PrusaLink::validate_version_text(const boost::optional<std::string>& version_text) const +{ + return version_text ? (boost::starts_with(*version_text, "PrusaLink") || boost::starts_with(*version_text, "OctoPrint")) : false; +} + +void PrusaLink::set_auth(Http& http) const +{ + switch (authorization_type) { + case atKeyPassword: + http.header("X-Api-Key", get_apikey()); + break; + case atUserPassword: + http.auth_digest(username, password); + break; + } + + if (!get_cafile().empty()) { + http.ca_file(get_cafile()); + } +} + } diff --git a/src/slic3r/Utils/OctoPrint.hpp b/src/slic3r/Utils/OctoPrint.hpp index c91dc5834..7c17f3793 100644 --- a/src/slic3r/Utils/OctoPrint.hpp +++ b/src/slic3r/Utils/OctoPrint.hpp @@ -70,6 +70,31 @@ private: std::string password; }; +class PrusaLink : public OctoPrint +{ +public: + PrusaLink(DynamicPrintConfig* config); + ~PrusaLink() override = default; + + const char* get_name() const override; + + wxString get_test_ok_msg() const override; + wxString get_test_failed_msg(wxString& msg) const override; + bool can_start_print() const override { return true; } + +protected: + bool validate_version_text(const boost::optional<std::string>& version_text) const override; + +private: + void set_auth(Http& http) const override; + + // Host authorization type. + AuthorizationType authorization_type; + // username and password for HTTP Digest Authentization (RFC RFC2617) + std::string username; + std::string password; +}; + } #endif diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index 37c32da16..076504243 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -56,15 +56,18 @@ static const char *TMP_EXTENSION = ".download"; void copy_file_fix(const fs::path &source, const fs::path &target) { - static const auto perms = fs::owner_read | fs::owner_write | fs::group_read | fs::others_read; // aka 644 - BOOST_LOG_TRIVIAL(debug) << format("PresetUpdater: Copying %1% -> %2%", source, target); - - // Make sure the file has correct permission both before and after we copy over it - if (fs::exists(target)) { - fs::permissions(target, perms); + std::string error_message; + CopyFileResult cfr = copy_file(source.string(), target.string(), error_message, false); + if (cfr != CopyFileResult::SUCCESS) { + BOOST_LOG_TRIVIAL(error) << "Copying failed(" << cfr << "): " << error_message; + throw Slic3r::CriticalException(GUI::format( + _L("Copying of file %1% to %2% failed: %3%"), + source, target, error_message)); } - fs::copy_file(source, target, fs::copy_option::overwrite_if_exists); + // Permissions should be copied from the source file by copy_file(). We are not sure about the source + // permissions, let's rewrite them with 644. + static constexpr const auto perms = fs::owner_read | fs::owner_write | fs::group_read | fs::others_read; fs::permissions(target, perms); } @@ -168,7 +171,7 @@ struct PresetUpdater::priv void check_install_indices() const; Updates get_config_updates(const Semver& old_slic3r_version) const; - void perform_updates(Updates &&updates, bool snapshot = true) const; + bool perform_updates(Updates &&updates, bool snapshot = true) const; void set_waiting_updates(Updates u); }; @@ -512,7 +515,7 @@ Updates PresetUpdater::priv::get_config_updates(const Semver &old_slic3r_version } if (recommended->config_version < vp.config_version) { - BOOST_LOG_TRIVIAL(warning) << format("Recommended config version for the currently running " SLIC3R_APP_NAME " is older than the currently installed config for vendor %1%. This should not happen.", idx.vendor()); + BOOST_LOG_TRIVIAL(warning) << format("Recommended config version for the currently running %1% is older than the currently installed config for vendor %2%. This should not happen.", SLIC3R_APP_NAME, idx.vendor()); continue; } @@ -583,7 +586,7 @@ Updates PresetUpdater::priv::get_config_updates(const Semver &old_slic3r_version found = true; } else { BOOST_LOG_TRIVIAL(warning) << format("The recommended config version for vendor `%1%` in resources does not match the recommended\n" - " config version for this version of " SLIC3R_APP_NAME ". Corrupted installation?", idx.vendor()); + " config version for this version of `%2%`. Corrupted installation?", idx.vendor(), SLIC3R_APP_NAME); } } } @@ -636,12 +639,14 @@ Updates PresetUpdater::priv::get_config_updates(const Semver &old_slic3r_version return updates; } -void PresetUpdater::priv::perform_updates(Updates &&updates, bool snapshot) const +bool PresetUpdater::priv::perform_updates(Updates &&updates, bool snapshot) const { if (updates.incompats.size() > 0) { if (snapshot) { BOOST_LOG_TRIVIAL(info) << "Taking a snapshot..."; - SnapshotDB::singleton().take_snapshot(*GUI::wxGetApp().app_config, Snapshot::SNAPSHOT_DOWNGRADE); + if (! GUI::Config::take_config_snapshot_cancel_on_error(*GUI::wxGetApp().app_config, Snapshot::SNAPSHOT_DOWNGRADE, "", + _u8L("Continue and install configuration updates?"))) + return false; } BOOST_LOG_TRIVIAL(info) << format("Deleting %1% incompatible bundles", updates.incompats.size()); @@ -656,7 +661,9 @@ void PresetUpdater::priv::perform_updates(Updates &&updates, bool snapshot) cons if (snapshot) { BOOST_LOG_TRIVIAL(info) << "Taking a snapshot..."; - SnapshotDB::singleton().take_snapshot(*GUI::wxGetApp().app_config, Snapshot::SNAPSHOT_UPGRADE); + if (! GUI::Config::take_config_snapshot_cancel_on_error(*GUI::wxGetApp().app_config, Snapshot::SNAPSHOT_UPGRADE, "", + _u8L("Continue and install configuration updates?"))) + return false; } BOOST_LOG_TRIVIAL(info) << format("Performing %1% updates", updates.updates.size()); @@ -667,7 +674,8 @@ void PresetUpdater::priv::perform_updates(Updates &&updates, bool snapshot) cons update.install(); PresetBundle bundle; - bundle.load_configbundle(update.source.string(), PresetBundle::LOAD_CFGBNDLE_SYSTEM); + // Throw when parsing invalid configuration. Only valid configuration is supposed to be provided over the air. + bundle.load_configbundle(update.source.string(), PresetBundle::LoadConfigBundleAttribute::LoadSystem, ForwardCompatibilitySubstitutionRule::Disable); BOOST_LOG_TRIVIAL(info) << format("Deleting %1% conflicting presets", bundle.prints.size() + bundle.filaments.size() + bundle.printers.size()); @@ -699,6 +707,8 @@ void PresetUpdater::priv::perform_updates(Updates &&updates, bool snapshot) cons for (const auto &name : bundle.obsolete_presets.printers) { obsolete_remover("printer", name); } } } + + return true; } void PresetUpdater::priv::set_waiting_updates(Updates u) @@ -765,7 +775,20 @@ void PresetUpdater::slic3r_update_notify() } } -PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3r_version, bool no_notification) const +static void reload_configs_update_gui() +{ + // Reload global configuration + auto* app_config = GUI::wxGetApp().app_config; + // System profiles should not trigger any substitutions, user profiles may trigger substitutions, but these substitutions + // were already presented to the user on application start up. Just do substitutions now and keep quiet about it. + // However throw on substitutions in system profiles, those shall never happen with system profiles installed over the air. + GUI::wxGetApp().preset_bundle->load_presets(*app_config, ForwardCompatibilitySubstitutionRule::EnableSilentDisableSystem); + GUI::wxGetApp().load_current_presets(); + GUI::wxGetApp().plater()->set_bed_shape(); + GUI::wxGetApp().update_wizard_from_config(); +} + +PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3r_version, UpdateParams params) const { if (! p->enabled_config_update) { return R_NOOP; } @@ -799,11 +822,9 @@ PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3 // This effectively removes the incompatible bundles: // (snapshot is taken beforehand) - p->perform_updates(std::move(updates)); - - if (!GUI::wxGetApp().run_wizard(GUI::ConfigWizard::RR_DATA_INCOMPAT)) { + if (! p->perform_updates(std::move(updates)) || + ! GUI::wxGetApp().run_wizard(GUI::ConfigWizard::RR_DATA_INCOMPAT)) return R_INCOMPAT_EXIT; - } return R_INCOMPAT_CONFIGURED; } @@ -822,7 +843,7 @@ PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3 } //forced update - if(incompatible_version) + if (incompatible_version) { BOOST_LOG_TRIVIAL(info) << format("Update of %1% bundles available. At least one requires higher version of Slicer.", updates.updates.size()); @@ -837,14 +858,9 @@ 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..."; - - p->perform_updates(std::move(updates)); - - // Reload global configuration - auto* app_config = GUI::wxGetApp().app_config; - GUI::wxGetApp().preset_bundle->load_presets(*app_config); - GUI::wxGetApp().load_current_presets(); - GUI::wxGetApp().plater()->set_bed_shape(); + if (! p->perform_updates(std::move(updates))) + return R_INCOMPAT_EXIT; + reload_configs_update_gui(); return R_UPDATE_INSTALLED; } else { @@ -854,35 +870,35 @@ PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3 } // regular update - if (no_notification) { + if (params == UpdateParams::SHOW_NOTIFICATION) { + p->set_waiting_updates(updates); + GUI::wxGetApp().plater()->get_notification_manager()->push_notification(GUI::NotificationType::PresetUpdateAvailable); + } + else { BOOST_LOG_TRIVIAL(info) << format("Update of %1% bundles available. Asking for confirmation ...", p->waiting_updates.updates.size()); - std::vector<GUI::MsgUpdateConfig::Update> updates_msg; + std::vector<GUI::MsgUpdateConfig::Update> updates_msg; for (const auto& update : updates.updates) { - std::string changelog_url = update.version.config_version.prerelease() == nullptr ? update.changelog_url : std::string(); - updates_msg.emplace_back(update.vendor, update.version.config_version, update.version.comment, std::move(changelog_url)); - } + std::string changelog_url = update.version.config_version.prerelease() == nullptr ? update.changelog_url : std::string(); + updates_msg.emplace_back(update.vendor, update.version.config_version, update.version.comment, std::move(changelog_url)); + } - GUI::MsgUpdateConfig dlg(updates_msg); + GUI::MsgUpdateConfig dlg(updates_msg, params == UpdateParams::FORCED_BEFORE_WIZARD); - const auto res = dlg.ShowModal(); - if (res == wxID_OK) { - BOOST_LOG_TRIVIAL(debug) << "User agreed to perform the update"; - p->perform_updates(std::move(updates)); - - // Reload global configuration - auto* app_config = GUI::wxGetApp().app_config; - GUI::wxGetApp().preset_bundle->load_presets(*app_config); - GUI::wxGetApp().load_current_presets(); - return R_UPDATE_INSTALLED; + 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))) + return R_ALL_CANCELED; + reload_configs_update_gui(); + return R_UPDATE_INSTALLED; } else { - BOOST_LOG_TRIVIAL(info) << "User refused the update"; - return R_UPDATE_REJECT; - } - } else { - p->set_waiting_updates(updates); - GUI::wxGetApp().plater()->get_notification_manager()->push_notification(GUI::NotificationType::PresetUpdateAvailable); + BOOST_LOG_TRIVIAL(info) << "User refused the update"; + if (params == UpdateParams::FORCED_BEFORE_WIZARD && res == wxID_CANCEL) + return R_ALL_CANCELED; + return R_UPDATE_REJECT; + } } // MsgUpdateConfig will show after the notificaation is clicked @@ -893,7 +909,7 @@ PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3 return R_NOOP; } -void PresetUpdater::install_bundles_rsrc(std::vector<std::string> bundles, bool snapshot) const +bool PresetUpdater::install_bundles_rsrc(std::vector<std::string> bundles, bool snapshot) const { Updates updates; @@ -905,7 +921,7 @@ void PresetUpdater::install_bundles_rsrc(std::vector<std::string> bundles, bool updates.updates.emplace_back(std::move(path_in_rsrc), std::move(path_in_vendors), Version(), "", ""); } - p->perform_updates(std::move(updates), snapshot); + return p->perform_updates(std::move(updates), snapshot); } void PresetUpdater::on_update_notification_confirm() @@ -925,20 +941,14 @@ 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"; - p->perform_updates(std::move(p->waiting_updates)); - - // Reload global configuration - auto* app_config = GUI::wxGetApp().app_config; - GUI::wxGetApp().preset_bundle->load_presets(*app_config); - GUI::wxGetApp().load_current_presets(); - p->has_waiting_updates = false; - //return R_UPDATE_INSTALLED; + if (p->perform_updates(std::move(p->waiting_updates))) { + reload_configs_update_gui(); + p->has_waiting_updates = false; + } } else { BOOST_LOG_TRIVIAL(info) << "User refused the update"; - //return R_UPDATE_REJECT; - } - + } } } diff --git a/src/slic3r/Utils/PresetUpdater.hpp b/src/slic3r/Utils/PresetUpdater.hpp index 0ca363c61..d7eeb5604 100644 --- a/src/slic3r/Utils/PresetUpdater.hpp +++ b/src/slic3r/Utils/PresetUpdater.hpp @@ -35,18 +35,24 @@ public: R_INCOMPAT_CONFIGURED, R_UPDATE_INSTALLED, R_UPDATE_REJECT, - R_UPDATE_NOTIFICATION + R_UPDATE_NOTIFICATION, + R_ALL_CANCELED + }; + + enum class UpdateParams { + SHOW_TEXT_BOX, // force modal textbox + SHOW_NOTIFICATION, // only shows notification + FORCED_BEFORE_WIZARD // indicates that check of updated is forced before ConfigWizard opening }; // 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. // 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. - // no_notification = force modal textbox, otherwise some cases only shows notification - UpdateResult config_update(const Semver &old_slic3r_version, bool no_notification) const; + UpdateResult config_update(const Semver &old_slic3r_version, UpdateParams params) const; // "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; + bool install_bundles_rsrc(std::vector<std::string> bundles, bool snapshot = true) const; void on_update_notification_confirm(); private: diff --git a/src/slic3r/Utils/PrintHost.cpp b/src/slic3r/Utils/PrintHost.cpp index 455494277..52ec8bbfe 100644 --- a/src/slic3r/Utils/PrintHost.cpp +++ b/src/slic3r/Utils/PrintHost.cpp @@ -60,6 +60,7 @@ PrintHost* PrintHost::get_print_host(DynamicPrintConfig *config) const auto host_type = opt != nullptr ? opt->value : htOctoPrint; switch (host_type) { + case htPrusaLink: return new PrusaLink(config); case htOctoPrint: return new OctoPrint(config); case htDuet: return new Duet(config); case htFlashAir: return new FlashAir(config); |