From b030791384a312d8368941fb7bc01c65e1fd6dea Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Wed, 11 Apr 2018 17:07:27 +0200 Subject: [PATCH] Semver fixes, misc fixes --- resources/profiles/BarBaz.ini | 2 +- resources/profiles/Foobar.ini | 2 +- xs/src/semver/semver.c | 18 ++++++++++++++++++ xs/src/semver/semver.h | 3 +++ xs/src/slic3r/GUI/AboutDialog.cpp | 2 +- xs/src/slic3r/GUI/GUI.cpp | 8 ++++---- xs/src/slic3r/Utils/Semver.hpp | 30 +++++------------------------- xs/src/slic3r/Utils/Time.cpp | 3 ++- 8 files changed, 35 insertions(+), 33 deletions(-) diff --git a/resources/profiles/BarBaz.ini b/resources/profiles/BarBaz.ini index 83bb15684..7c8cd3a6b 100644 --- a/resources/profiles/BarBaz.ini +++ b/resources/profiles/BarBaz.ini @@ -5,7 +5,7 @@ name = Bar Baz # Configuration version of this file. Config file will only be installed, if the config_version differs. # This means, the server may force the Slic3r configuration to be downgraded. -config_version = 0.1 +config_version = 0.1.0 # Where to get the updates from? config_update_url = https://example.com diff --git a/resources/profiles/Foobar.ini b/resources/profiles/Foobar.ini index 21681398a..571aa8bb8 100644 --- a/resources/profiles/Foobar.ini +++ b/resources/profiles/Foobar.ini @@ -5,7 +5,7 @@ name = Foo Bar # Configuration version of this file. Config file will only be installed, if the config_version differs. # This means, the server may force the Slic3r configuration to be downgraded. -config_version = 0.1 +config_version = 0.1.0 # Where to get the updates from? config_update_url = https://example.com diff --git a/xs/src/semver/semver.c b/xs/src/semver/semver.c index 599217f89..3e4a30e3a 100644 --- a/xs/src/semver/semver.c +++ b/xs/src/semver/semver.c @@ -615,3 +615,21 @@ semver_numeric (semver_t *x) { return num; } + +static char *semver_strdup(const char *src) { + if (src == NULL) return NULL; + size_t len = strlen(src) + 1; + char *res = malloc(len); + return res != NULL ? (char *) memcpy(res, src, len) : NULL; +} + +semver_t +semver_copy(const semver_t *ver) { + semver_t res = *ver; + if (ver->metadata != NULL) { + res.metadata = strdup(ver->metadata); + } + if (ver->prerelease != NULL) { + res.prerelease = strdup(ver->prerelease); + } +} \ No newline at end of file diff --git a/xs/src/semver/semver.h b/xs/src/semver/semver.h index 1b48670ca..7251f51e3 100644 --- a/xs/src/semver/semver.h +++ b/xs/src/semver/semver.h @@ -98,6 +98,9 @@ semver_is_valid (const char *s); int semver_clean (char *s); +semver_t +semver_copy(const semver_t *ver); + #ifdef __cplusplus } #endif diff --git a/xs/src/slic3r/GUI/AboutDialog.cpp b/xs/src/slic3r/GUI/AboutDialog.cpp index 49cfff2bd..664bbd1bb 100644 --- a/xs/src/slic3r/GUI/AboutDialog.cpp +++ b/xs/src/slic3r/GUI/AboutDialog.cpp @@ -56,7 +56,7 @@ AboutDialog::AboutDialog() // version { - std::string version_string = _(L("Version ")) + std::string(SLIC3R_VERSION); + auto version_string = _(L("Version ")) + std::string(SLIC3R_VERSION); wxStaticText* version = new wxStaticText(this, wxID_ANY, version_string.c_str(), wxDefaultPosition, wxDefaultSize); wxFont version_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); #ifdef __WXMSW__ diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index cef56b892..d70b47840 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -352,11 +352,11 @@ void add_config_menu(wxMenuBar *menu, int event_preferences_changed, int event_l // A different naming convention is used for the Wizard on Windows vs. OSX & GTK. #if WIN32 - std::string config_wizard_menu = _(L("Configuration Wizard")); - std::string config_wizard_tooltip = _(L("Run configuration wizard")); + auto config_wizard_menu = _(L("Configuration Wizard")); + auto config_wizard_tooltip = _(L("Run configuration wizard")); #else - std::string config_wizard_menu = _(L("Configuration Assistant")); - std::string config_wizard_tooltip = _(L("Run configuration Assistant")); + auto config_wizard_menu = _(L("Configuration Assistant")); + auto config_wizard_tooltip = _(L("Run configuration Assistant")); #endif // Cmd+, is standard on OS X - what about other operating systems? local_menu->Append(config_id_base + ConfigMenuWizard, config_wizard_menu + "\u2026", config_wizard_tooltip); diff --git a/xs/src/slic3r/Utils/Semver.hpp b/xs/src/slic3r/Utils/Semver.hpp index 2ac2ba700..a1f4a92e8 100644 --- a/xs/src/slic3r/Utils/Semver.hpp +++ b/xs/src/slic3r/Utils/Semver.hpp @@ -43,11 +43,7 @@ public: } } - static const Semver zero() - { - static semver_t ver = { 0, 0, 0, nullptr, nullptr }; - return Semver(ver); - } + static const Semver zero() { return Semver(semver_zero()); } static const Semver inf() { @@ -61,37 +57,21 @@ public: return Semver(ver); } - Semver(Semver &&other) : ver(other.ver) - { - other.ver.major = other.ver.minor = other.ver.patch = 0; - other.ver.metadata = other.ver.prerelease = nullptr; - } - - Semver(const Semver &other) : ver(other.ver) - { - if (other.ver.metadata != nullptr) - ver.metadata = strdup(other.ver.metadata); - if (other.ver.prerelease != nullptr) - ver.prerelease = strdup(other.ver.prerelease); - } + 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.major = other.ver.minor = other.ver.patch = 0; - other.ver.metadata = other.ver.prerelease = nullptr; + other.ver = semver_zero(); return *this; } Semver &operator=(const Semver &other) { ::semver_free(&ver); - ver = other.ver; - if (other.ver.metadata != nullptr) - ver.metadata = strdup(other.ver.metadata); - if (other.ver.prerelease != nullptr) - ver.prerelease = strdup(other.ver.prerelease); + ver = ::semver_copy(&other.ver); return *this; } diff --git a/xs/src/slic3r/Utils/Time.cpp b/xs/src/slic3r/Utils/Time.cpp index a2b2328af..f38c4b407 100644 --- a/xs/src/slic3r/Utils/Time.cpp +++ b/xs/src/slic3r/Utils/Time.cpp @@ -71,7 +71,8 @@ time_t get_current_time_utc() tm.tm_isdst = -1; return mktime(&tm); #else - return gmtime(); + const time_t current_local = time(nullptr); + return mktime(gmtime(¤t_local)); #endif }