From 5ba9d59307ff590bc71926d3c5e3ebddab9f9835 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Wed, 15 Dec 2021 14:27:25 +0100 Subject: If taking configuration snapshot before importing newer configuration fails, offer to stop importing configuration. --- src/slic3r/Config/Snapshot.cpp | 6 ++++-- src/slic3r/Config/Snapshot.hpp | 2 +- src/slic3r/GUI/GUI_App.cpp | 20 ++++++++++---------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/slic3r/Config/Snapshot.cpp b/src/slic3r/Config/Snapshot.cpp index 77a74bffe..1e44dac7b 100644 --- a/src/slic3r/Config/Snapshot.cpp +++ b/src/slic3r/Config/Snapshot.cpp @@ -586,10 +586,12 @@ const Snapshot* take_config_snapshot_report_error(const AppConfig &app_config, S } } -bool take_config_snapshot_cancel_on_error(const AppConfig &app_config, Snapshot::Reason reason, const std::string &comment, const std::string &message) +bool take_config_snapshot_cancel_on_error(const AppConfig &app_config, Snapshot::Reason reason, const std::string &comment, const std::string &message, Snapshot const **psnapshot) { try { - SnapshotDB::singleton().take_snapshot(app_config, reason, comment); + const Snapshot *snapshot = &SnapshotDB::singleton().take_snapshot(app_config, reason, comment); + if (*psnapshot) + *psnapshot = snapshot; return true; } catch (std::exception &err) { RichMessageDialog dlg(static_cast(wxGetApp().mainframe), diff --git a/src/slic3r/Config/Snapshot.hpp b/src/slic3r/Config/Snapshot.hpp index f45300633..5793aa548 100644 --- a/src/slic3r/Config/Snapshot.hpp +++ b/src/slic3r/Config/Snapshot.hpp @@ -132,7 +132,7 @@ const Snapshot* take_config_snapshot_report_error(const AppConfig &app_config, S // Take snapshot on SnapshotDB::singleton(). If taking snapshot fails, report "message", and present a "Continue" or "Abort" buttons to respond. // Return true on success and on "Continue" to continue with the process (for example installation of presets). -bool take_config_snapshot_cancel_on_error(const AppConfig &app_config, Snapshot::Reason reason, const std::string &comment, const std::string &message); +bool take_config_snapshot_cancel_on_error(const AppConfig &app_config, Snapshot::Reason reason, const std::string &comment, const std::string &message, Snapshot const **psnapshot = nullptr); } // namespace Config } // namespace GUI diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 13f76443c..c947cecb9 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -977,17 +977,17 @@ std::string GUI_App::check_older_app_config(Semver current_version, bool backup) if (msg.ShowModal() == wxID_YES) { std::string snapshot_id; if (backup) { - // configuration snapshot - std::string comment; - if (const Config::Snapshot* snapshot = Config::take_config_snapshot_report_error( - *app_config, - Config::Snapshot::SNAPSHOT_USER, - comment); - snapshot != nullptr) - // Is thos correct? Save snapshot id for later, when new app config is loaded. + const Config::Snapshot* snapshot{ nullptr }; + if (! GUI::Config::take_config_snapshot_cancel_on_error(*app_config, Config::Snapshot::SNAPSHOT_USER, "", + _u8L("Continue and import newer configuration?")), &snapshot) + return {}; + if (snapshot) { + // Save snapshot ID before loading the alternate AppConfig, as loading the alternate AppConfig may fail. snapshot_id = snapshot->id; - else - BOOST_LOG_TRIVIAL(error) << "Failed to take congiguration snapshot: "; + assert(! snapshot_id.empty()); + app_config->set("on_snapshot", snapshot_id); + } else + BOOST_LOG_TRIVIAL(error) << "Failed to take congiguration snapshot"; } // load app config from older file -- cgit v1.2.3