PresetUpdater: Don't fail as hard if version not found in index #1821
GUI_App: Add OnExceptionInMainLoop handler
This commit is contained in:
parent
eb643a1f52
commit
d8c7966bec
3 changed files with 51 additions and 15 deletions
|
@ -3,8 +3,10 @@
|
|||
#include "GUI_ObjectManipulation.hpp"
|
||||
#include "I18N.hpp"
|
||||
|
||||
#include <exception>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#include <wx/stdpaths.h>
|
||||
#include <wx/imagpng.h>
|
||||
|
@ -181,7 +183,6 @@ bool GUI_App::OnInit()
|
|||
mainframe->Close();
|
||||
} catch (const std::exception &ex) {
|
||||
show_error(nullptr, ex.what());
|
||||
mainframe->Close();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -681,6 +682,23 @@ void GUI_App::load_current_presets()
|
|||
}
|
||||
}
|
||||
|
||||
bool GUI_App::OnExceptionInMainLoop()
|
||||
{
|
||||
try {
|
||||
throw;
|
||||
} catch (const std::exception &ex) {
|
||||
const std::string error = (boost::format("Uncaught exception: %1%") % ex.what()).str();
|
||||
BOOST_LOG_TRIVIAL(error) << error;
|
||||
show_error(nullptr, from_u8(error));
|
||||
} catch (...) {
|
||||
const char *error = "Uncaught exception: Unknown error";
|
||||
BOOST_LOG_TRIVIAL(error) << error;
|
||||
show_error(nullptr, from_u8(error));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
// wxWidgets override to get an event on open files.
|
||||
void GUI_App::MacOpenFiles(const wxArrayString &fileNames)
|
||||
|
|
|
@ -137,6 +137,8 @@ public:
|
|||
bool checked_tab(Tab* tab);
|
||||
void load_current_presets();
|
||||
|
||||
virtual bool OnExceptionInMainLoop();
|
||||
|
||||
#ifdef __APPLE__
|
||||
// wxWidgets override to get an event on open files.
|
||||
void MacOpenFiles(const wxArrayString &fileNames) override;
|
||||
|
|
|
@ -90,9 +90,23 @@ struct Updates
|
|||
std::vector<Update> updates;
|
||||
};
|
||||
|
||||
static Semver get_slic3r_version()
|
||||
{
|
||||
auto res = Semver::parse(SLIC3R_VERSION);
|
||||
|
||||
if (! res) {
|
||||
const char *error = "Could not parse Slic3r version string: " SLIC3R_VERSION;
|
||||
BOOST_LOG_TRIVIAL(error) << error;
|
||||
throw std::runtime_error(error);
|
||||
}
|
||||
|
||||
return *res;
|
||||
}
|
||||
|
||||
|
||||
struct PresetUpdater::priv
|
||||
{
|
||||
const Semver ver_slic3r;
|
||||
std::vector<Index> index_db;
|
||||
|
||||
bool enabled_version_check;
|
||||
|
@ -122,12 +136,13 @@ struct PresetUpdater::priv
|
|||
static void copy_file(const fs::path &from, const fs::path &to);
|
||||
};
|
||||
|
||||
PresetUpdater::priv::priv() :
|
||||
had_config_update(false),
|
||||
cache_path(fs::path(Slic3r::data_dir()) / "cache"),
|
||||
rsrc_path(fs::path(resources_dir()) / "profiles"),
|
||||
vendor_path(fs::path(Slic3r::data_dir()) / "vendor"),
|
||||
cancel(false)
|
||||
PresetUpdater::priv::priv()
|
||||
: ver_slic3r(get_slic3r_version())
|
||||
, had_config_update(false)
|
||||
, cache_path(fs::path(Slic3r::data_dir()) / "cache")
|
||||
, rsrc_path(fs::path(resources_dir()) / "profiles")
|
||||
, vendor_path(fs::path(Slic3r::data_dir()) / "vendor")
|
||||
, cancel(false)
|
||||
{
|
||||
set_download_prefs(GUI::wxGetApp().app_config);
|
||||
check_install_indices();
|
||||
|
@ -209,6 +224,9 @@ void PresetUpdater::priv::sync_version() const
|
|||
.on_complete([&](std::string body, unsigned /* http_status */) {
|
||||
boost::trim(body);
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("Got Slic3rPE online version: `%1%`. Sending to GUI thread...") % body;
|
||||
|
||||
// FIXME: race condition
|
||||
|
||||
// wxCommandEvent* evt = new wxCommandEvent(version_online_event);
|
||||
// evt->SetString(body);
|
||||
// GUI::get_app()->QueueEvent(evt);
|
||||
|
@ -260,7 +278,7 @@ void PresetUpdater::priv::sync_config(const std::set<VendorProfile> vendors)
|
|||
continue;
|
||||
}
|
||||
if (new_index.version() < index.version()) {
|
||||
BOOST_LOG_TRIVIAL(error) << boost::format("The downloaded index %1% for vendor %2% is older than the active one. Ignoring the downloaded index.") % idx_path_temp % vendor.name;
|
||||
BOOST_LOG_TRIVIAL(warning) << boost::format("The downloaded index %1% for vendor %2% is older than the active one. Ignoring the downloaded index.") % idx_path_temp % vendor.name;
|
||||
continue;
|
||||
}
|
||||
Slic3r::rename_file(idx_path_temp, idx_path);
|
||||
|
@ -275,6 +293,7 @@ void PresetUpdater::priv::sync_config(const std::set<VendorProfile> vendors)
|
|||
BOOST_LOG_TRIVIAL(error) << boost::format("No recommended version for vendor: %1%, invalid index?") % vendor.name;
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto recommended = recommended_it->config_version;
|
||||
|
||||
BOOST_LOG_TRIVIAL(debug) << boost::format("Got index for vendor: %1%: current version: %2%, recommended version: %3%")
|
||||
|
@ -341,7 +360,8 @@ Updates PresetUpdater::priv::get_config_updates() const
|
|||
if (ver_current == idx.end()) {
|
||||
auto message = (boost::format("Preset bundle `%1%` version not found in index: %2%") % idx.vendor() % vp.config_version.to_string()).str();
|
||||
BOOST_LOG_TRIVIAL(error) << message;
|
||||
throw std::runtime_error(message);
|
||||
GUI::show_error(nullptr, GUI::from_u8(message));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Getting a recommended version from the latest index, wich may have been downloaded
|
||||
|
@ -528,18 +548,14 @@ void PresetUpdater::slic3r_update_notify()
|
|||
}
|
||||
|
||||
auto* app_config = GUI::wxGetApp().app_config;
|
||||
const auto ver_slic3r = Semver::parse(SLIC3R_VERSION);
|
||||
const auto ver_online_str = app_config->get("version_online");
|
||||
const auto ver_online = Semver::parse(ver_online_str);
|
||||
const auto ver_online_seen = Semver::parse(app_config->get("version_online_seen"));
|
||||
if (! ver_slic3r) {
|
||||
throw std::runtime_error("Could not parse Slic3r version string: " SLIC3R_VERSION);
|
||||
}
|
||||
|
||||
if (ver_online) {
|
||||
// Only display the notification if the version available online is newer AND if we haven't seen it before
|
||||
if (*ver_online > *ver_slic3r && (! ver_online_seen || *ver_online_seen < *ver_online)) {
|
||||
GUI::MsgUpdateSlic3r notification(*ver_slic3r, *ver_online);
|
||||
if (*ver_online > p->ver_slic3r && (! ver_online_seen || *ver_online_seen < *ver_online)) {
|
||||
GUI::MsgUpdateSlic3r notification(p->ver_slic3r, *ver_online);
|
||||
notification.ShowModal();
|
||||
if (notification.disable_version_check()) {
|
||||
app_config->set("version_check", "0");
|
||||
|
|
Loading…
Add table
Reference in a new issue