Refactor: Move Semver from slice3r to libslic3r

A static symbol Slic3r::SEMVER is introduced, which holds
the running slicer's Semver object.

This is mainly done to make testing updater behaviour
_much_ easier. Additionaly to cleanup some questionable code
(Semver was being parsed multiple times / in multiple places
in the frontend.)
This commit is contained in:
Vojtech Kral 2019-08-09 17:01:37 +02:00
parent b5dd13b987
commit 745182988d
13 changed files with 21 additions and 27 deletions

View file

@ -139,6 +139,7 @@ add_library(libslic3r STATIC
PrintConfig.hpp
PrintObject.cpp
PrintRegion.cpp
Semver.cpp
SLAPrint.cpp
SLAPrint.hpp
SLA/SLAAutoSupports.hpp

7
src/libslic3r/Semver.cpp Normal file
View file

@ -0,0 +1,7 @@
#include "libslic3r.h"
namespace Slic3r {
Semver SEMVER { SLIC3R_VERSION };
}

View file

@ -19,6 +19,7 @@
#include <cmath>
#include "Technologies.hpp"
#include "Semver.hpp"
typedef int32_t coord_t;
typedef double coordf_t;
@ -92,6 +93,8 @@ inline std::string debug_out_path(const char *name, ...)
namespace Slic3r {
extern Semver SEMVER;
template<typename T, typename Q>
inline T unscale(Q v) { return T(v) * T(SCALING_FACTOR); }

View file

@ -366,7 +366,7 @@ const Snapshot& SnapshotDB::take_snapshot(const AppConfig &app_config, Snapshot:
// Snapshot header.
snapshot.time_captured = Slic3r::Utils::get_current_time_utc();
snapshot.id = Slic3r::Utils::format_time_ISO8601Z(snapshot.time_captured);
snapshot.slic3r_version_captured = *Semver::parse(SLIC3R_VERSION); // XXX: have Semver Slic3r version
snapshot.slic3r_version_captured = Slic3r::SEMVER;
snapshot.comment = comment;
snapshot.reason = reason;
// Active presets at the time of the snapshot.

View file

@ -8,8 +8,8 @@
#include <boost/filesystem.hpp>
#include "libslic3r/Semver.hpp"
#include "Version.hpp"
#include "../Utils/Semver.hpp"
namespace Slic3r {

View file

@ -15,7 +15,6 @@ namespace Slic3r {
namespace GUI {
namespace Config {
static const Semver s_current_slic3r_semver(SLIC3R_VERSION);
// Optimized lexicographic compare of two pre-release versions, ignoring the numeric suffix.
static int compare_prerelease(const char *p1, const char *p2)
@ -64,7 +63,7 @@ bool Version::is_slic3r_supported(const Semver &slic3r_version) const
bool Version::is_current_slic3r_supported() const
{
return this->is_slic3r_supported(s_current_slic3r_semver);
return this->is_slic3r_supported(Slic3r::SEMVER);
}
#if 0

View file

@ -7,7 +7,7 @@
#include <boost/filesystem.hpp>
#include "libslic3r/FileParserError.hpp"
#include "../Utils/Semver.hpp"
#include "libslic3r/Semver.hpp"
namespace Slic3r {
namespace GUI {

View file

@ -6,7 +6,7 @@
#include <string>
#include "libslic3r/Config.hpp"
#include "slic3r/Utils/Semver.hpp"
#include "libslic3r/Semver.hpp"
namespace Slic3r {

View file

@ -8,8 +8,6 @@
#include <wx/font.h>
#include <wx/bitmap.h>
#include "slic3r/Utils/Semver.hpp"
class wxBoxSizer;
class wxCheckBox;
class wxStaticBitmap;

View file

@ -8,7 +8,7 @@
#include "libslic3r/libslic3r.h"
#include "libslic3r/PrintConfig.hpp"
#include "slic3r/Utils/Semver.hpp"
#include "libslic3r/Semver.hpp"
class wxBitmap;
class wxBitmapComboBox;

View file

@ -5,7 +5,7 @@
#include <unordered_map>
#include <vector>
#include "slic3r/Utils/Semver.hpp"
#include "libslic3r/Semver.hpp"
#include "MsgDialog.hpp"
class wxBoxSizer;

View file

@ -124,25 +124,12 @@ 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;
}
wxDEFINE_EVENT(EVT_SLIC3R_VERSION_ONLINE, wxCommandEvent);
struct PresetUpdater::priv
{
const Semver ver_slic3r;
std::vector<Index> index_db;
bool enabled_version_check;
@ -170,8 +157,7 @@ struct PresetUpdater::priv
};
PresetUpdater::priv::priv()
: ver_slic3r(get_slic3r_version())
, cache_path(fs::path(Slic3r::data_dir()) / "cache")
: 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)
@ -594,8 +580,8 @@ void PresetUpdater::slic3r_update_notify()
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 > p->ver_slic3r && (! ver_online_seen || *ver_online_seen < *ver_online)) {
GUI::MsgUpdateSlic3r notification(p->ver_slic3r, *ver_online);
if (*ver_online > Slic3r::SEMVER && (! ver_online_seen || *ver_online_seen < *ver_online)) {
GUI::MsgUpdateSlic3r notification(Slic3r::SEMVER, *ver_online);
notification.ShowModal();
if (notification.disable_version_check()) {
app_config->set("version_check", "0");