Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVojtech Kral <vojtech@kral.hk>2019-08-09 18:01:37 +0300
committerVojtech Kral <vojtech@kral.hk>2019-08-19 18:04:14 +0300
commit745182988d5edc06ef3d9c0ea1a2265a04d79a88 (patch)
treec24dabe4be88957374849bc6818188f90b77b909 /src/slic3r
parentb5dd13b9879eb1d149ed1c4f3f15fb10abd112a5 (diff)
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.)
Diffstat (limited to 'src/slic3r')
-rw-r--r--src/slic3r/Config/Snapshot.cpp2
-rw-r--r--src/slic3r/Config/Snapshot.hpp2
-rw-r--r--src/slic3r/Config/Version.cpp3
-rw-r--r--src/slic3r/Config/Version.hpp2
-rw-r--r--src/slic3r/GUI/AppConfig.hpp2
-rw-r--r--src/slic3r/GUI/MsgDialog.hpp2
-rw-r--r--src/slic3r/GUI/Preset.hpp2
-rw-r--r--src/slic3r/GUI/UpdateDialogs.hpp2
-rw-r--r--src/slic3r/Utils/PresetUpdater.cpp20
-rw-r--r--src/slic3r/Utils/Semver.hpp156
10 files changed, 10 insertions, 183 deletions
diff --git a/src/slic3r/Config/Snapshot.cpp b/src/slic3r/Config/Snapshot.cpp
index b208554b5..3757ec25b 100644
--- a/src/slic3r/Config/Snapshot.cpp
+++ b/src/slic3r/Config/Snapshot.cpp
@@ -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.
diff --git a/src/slic3r/Config/Snapshot.hpp b/src/slic3r/Config/Snapshot.hpp
index a916dfe92..9a7391691 100644
--- a/src/slic3r/Config/Snapshot.hpp
+++ b/src/slic3r/Config/Snapshot.hpp
@@ -8,8 +8,8 @@
#include <boost/filesystem.hpp>
+#include "libslic3r/Semver.hpp"
#include "Version.hpp"
-#include "../Utils/Semver.hpp"
namespace Slic3r {
diff --git a/src/slic3r/Config/Version.cpp b/src/slic3r/Config/Version.cpp
index 865884c6f..175abff69 100644
--- a/src/slic3r/Config/Version.cpp
+++ b/src/slic3r/Config/Version.cpp
@@ -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
diff --git a/src/slic3r/Config/Version.hpp b/src/slic3r/Config/Version.hpp
index 560bc29c2..19c565ffb 100644
--- a/src/slic3r/Config/Version.hpp
+++ b/src/slic3r/Config/Version.hpp
@@ -7,7 +7,7 @@
#include <boost/filesystem.hpp>
#include "libslic3r/FileParserError.hpp"
-#include "../Utils/Semver.hpp"
+#include "libslic3r/Semver.hpp"
namespace Slic3r {
namespace GUI {
diff --git a/src/slic3r/GUI/AppConfig.hpp b/src/slic3r/GUI/AppConfig.hpp
index 230a92294..8ad17b9db 100644
--- a/src/slic3r/GUI/AppConfig.hpp
+++ b/src/slic3r/GUI/AppConfig.hpp
@@ -6,7 +6,7 @@
#include <string>
#include "libslic3r/Config.hpp"
-#include "slic3r/Utils/Semver.hpp"
+#include "libslic3r/Semver.hpp"
namespace Slic3r {
diff --git a/src/slic3r/GUI/MsgDialog.hpp b/src/slic3r/GUI/MsgDialog.hpp
index ad4bbcc97..5a4929849 100644
--- a/src/slic3r/GUI/MsgDialog.hpp
+++ b/src/slic3r/GUI/MsgDialog.hpp
@@ -8,8 +8,6 @@
#include <wx/font.h>
#include <wx/bitmap.h>
-#include "slic3r/Utils/Semver.hpp"
-
class wxBoxSizer;
class wxCheckBox;
class wxStaticBitmap;
diff --git a/src/slic3r/GUI/Preset.hpp b/src/slic3r/GUI/Preset.hpp
index 8fd1652a8..e1efdc1ef 100644
--- a/src/slic3r/GUI/Preset.hpp
+++ b/src/slic3r/GUI/Preset.hpp
@@ -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;
diff --git a/src/slic3r/GUI/UpdateDialogs.hpp b/src/slic3r/GUI/UpdateDialogs.hpp
index 2a580e251..4b61b84c2 100644
--- a/src/slic3r/GUI/UpdateDialogs.hpp
+++ b/src/slic3r/GUI/UpdateDialogs.hpp
@@ -5,7 +5,7 @@
#include <unordered_map>
#include <vector>
-#include "slic3r/Utils/Semver.hpp"
+#include "libslic3r/Semver.hpp"
#include "MsgDialog.hpp"
class wxBoxSizer;
diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp
index 3f3139cad..589db36dc 100644
--- a/src/slic3r/Utils/PresetUpdater.cpp
+++ b/src/slic3r/Utils/PresetUpdater.cpp
@@ -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");
diff --git a/src/slic3r/Utils/Semver.hpp b/src/slic3r/Utils/Semver.hpp
deleted file mode 100644
index a755becaa..000000000
--- a/src/slic3r/Utils/Semver.hpp
+++ /dev/null
@@ -1,156 +0,0 @@
-#ifndef slic3r_Semver_hpp_
-#define slic3r_Semver_hpp_
-
-#include <string>
-#include <cstring>
-#include <ostream>
-#include <stdexcept>
-#include <boost/optional.hpp>
-#include <boost/format.hpp>
-
-#include "semver/semver.h"
-
-namespace Slic3r {
-
-
-class Semver
-{
-public:
- struct Major { const int i; Major(int i) : i(i) {} };
- struct Minor { const int i; Minor(int i) : i(i) {} };
- struct Patch { const int i; Patch(int i) : i(i) {} };
-
- Semver() : ver(semver_zero()) {}
-
- Semver(int major, int minor, int patch,
- boost::optional<const std::string&> metadata = boost::none,
- boost::optional<const std::string&> prerelease = boost::none)
- : ver(semver_zero())
- {
- ver.major = major;
- ver.minor = minor;
- ver.patch = patch;
- set_metadata(metadata);
- set_prerelease(prerelease);
- }
-
- Semver(const std::string &str) : ver(semver_zero())
- {
- auto parsed = parse(str);
- if (! parsed) {
- throw std::runtime_error(std::string("Could not parse version string: ") + str);
- }
- ver = parsed->ver;
- parsed->ver = semver_zero();
- }
-
- static boost::optional<Semver> parse(const std::string &str)
- {
- semver_t ver = semver_zero();
- if (::semver_parse(str.c_str(), &ver) == 0) {
- return Semver(ver);
- } else {
- return boost::none;
- }
- }
-
- static const Semver zero() { return Semver(semver_zero()); }
-
- static const Semver inf()
- {
- static semver_t ver = { std::numeric_limits<int>::max(), std::numeric_limits<int>::max(), std::numeric_limits<int>::max(), nullptr, nullptr };
- return Semver(ver);
- }
-
- static const Semver invalid()
- {
- static semver_t ver = { -1, 0, 0, nullptr, nullptr };
- return Semver(ver);
- }
-
- Semver(Semver &&other) : ver(other.ver) { other.ver = semver_zero(); }
- Semver(const Semver &other) : ver(::semver_copy(&other.ver)) {}
-
- Semver &operator=(Semver &&other)
- {
- ::semver_free(&ver);
- ver = other.ver;
- other.ver = semver_zero();
- return *this;
- }
-
- Semver &operator=(const Semver &other)
- {
- ::semver_free(&ver);
- ver = ::semver_copy(&other.ver);
- return *this;
- }
-
- ~Semver() { ::semver_free(&ver); }
-
- // const accessors
- int maj() const { return ver.major; }
- int min() const { return ver.minor; }
- int patch() const { return ver.patch; }
- const char* prerelease() const { return ver.prerelease; }
- const char* metadata() const { return ver.metadata; }
-
- // Setters
- void set_maj(int maj) { ver.major = maj; }
- void set_min(int min) { ver.minor = min; }
- void set_patch(int patch) { ver.patch = patch; }
- void set_metadata(boost::optional<const std::string&> meta) { ver.metadata = meta ? strdup(*meta) : nullptr; }
- void set_prerelease(boost::optional<const std::string&> pre) { ver.prerelease = pre ? strdup(*pre) : nullptr; }
-
- // Comparison
- bool operator<(const Semver &b) const { return ::semver_compare(ver, b.ver) == -1; }
- bool operator<=(const Semver &b) const { return ::semver_compare(ver, b.ver) <= 0; }
- bool operator==(const Semver &b) const { return ::semver_compare(ver, b.ver) == 0; }
- bool operator!=(const Semver &b) const { return ::semver_compare(ver, b.ver) != 0; }
- bool operator>=(const Semver &b) const { return ::semver_compare(ver, b.ver) >= 0; }
- bool operator>(const Semver &b) const { return ::semver_compare(ver, b.ver) == 1; }
- // We're using '&' instead of the '~' operator here as '~' is unary-only:
- // Satisfies patch if Major and minor are equal.
- bool operator&(const Semver &b) const { return ::semver_satisfies_patch(ver, b.ver) != 0; }
- bool operator^(const Semver &b) const { return ::semver_satisfies_caret(ver, b.ver) != 0; }
- bool in_range(const Semver &low, const Semver &high) const { return low <= *this && *this <= high; }
-
- // Conversion
- std::string to_string() const {
- auto res = (boost::format("%1%.%2%.%3%") % ver.major % ver.minor % ver.patch).str();
- if (ver.prerelease != nullptr) { res += '-'; res += ver.prerelease; }
- if (ver.metadata != nullptr) { res += '+'; res += ver.metadata; }
- return res;
- }
-
- // Arithmetics
- Semver& operator+=(const Major &b) { ver.major += b.i; return *this; }
- Semver& operator+=(const Minor &b) { ver.minor += b.i; return *this; }
- Semver& operator+=(const Patch &b) { ver.patch += b.i; return *this; }
- Semver& operator-=(const Major &b) { ver.major -= b.i; return *this; }
- Semver& operator-=(const Minor &b) { ver.minor -= b.i; return *this; }
- Semver& operator-=(const Patch &b) { ver.patch -= b.i; return *this; }
- Semver operator+(const Major &b) const { Semver res(*this); return res += b; }
- Semver operator+(const Minor &b) const { Semver res(*this); return res += b; }
- Semver operator+(const Patch &b) const { Semver res(*this); return res += b; }
- Semver operator-(const Major &b) const { Semver res(*this); return res -= b; }
- Semver operator-(const Minor &b) const { Semver res(*this); return res -= b; }
- Semver operator-(const Patch &b) const { Semver res(*this); return res -= b; }
-
- // Stream output
- friend std::ostream& operator<<(std::ostream& os, const Semver &self) {
- os << self.to_string();
- return os;
- }
-private:
- semver_t ver;
-
- Semver(semver_t ver) : ver(ver) {}
-
- static semver_t semver_zero() { return { 0, 0, 0, nullptr, nullptr }; }
- static char * strdup(const std::string &str) { return ::semver_strdup(const_cast<char*>(str.c_str())); }
-};
-
-
-}
-#endif