mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-23 08:41:11 -06:00
Initial implementation of configuration snapshotting.
This commit is contained in:
parent
2b8da333ef
commit
670061ac33
11 changed files with 787 additions and 31 deletions
|
@ -28,6 +28,24 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
static const Semver zero()
|
||||
{
|
||||
static semver_t ver = { 0, 0, 0, nullptr, nullptr };
|
||||
return Semver(ver);
|
||||
}
|
||||
|
||||
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) { *this = std::move(other); }
|
||||
Semver(const Semver &other) { *this = other; }
|
||||
|
||||
|
@ -36,13 +54,16 @@ public:
|
|||
ver = other.ver;
|
||||
other.ver.major = other.ver.minor = other.ver.patch = 0;
|
||||
other.ver.metadata = other.ver.prerelease = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Semver &operator=(const Semver &other)
|
||||
{
|
||||
::semver_free(&ver);
|
||||
ver = other.ver;
|
||||
if (other.ver.metadata != nullptr) { std::strcpy(ver.metadata, other.ver.metadata); }
|
||||
if (other.ver.prerelease != nullptr) { std::strcpy(ver.prerelease, other.ver.prerelease); }
|
||||
return *this;
|
||||
}
|
||||
|
||||
~Semver() { ::semver_free(&ver); }
|
||||
|
@ -55,8 +76,10 @@ public:
|
|||
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); }
|
||||
bool operator^(const Semver &b) const { return ::semver_satisfies_caret(ver, b.ver); }
|
||||
bool in_range(const Semver &low, const Semver &high) const { return low <= *this && *this <= high; }
|
||||
|
||||
// Conversion
|
||||
std::string to_string() const {
|
||||
|
@ -79,6 +102,7 @@ public:
|
|||
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; }
|
||||
|
||||
private:
|
||||
semver_t ver;
|
||||
|
||||
|
|
63
xs/src/slic3r/Utils/Time.cpp
Normal file
63
xs/src/slic3r/Utils/Time.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
#include "Time.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
namespace Utils {
|
||||
|
||||
time_t parse_time_ISO8601Z(const std::string &sdate)
|
||||
{
|
||||
int y, M, d, h, m;
|
||||
float s;
|
||||
if (sscanf(sdate.c_str(), "%d-%d-%dT%d:%d:%fZ", &y, &M, &d, &h, &m, &s) != 6)
|
||||
return (time_t)-1;
|
||||
struct tm tms;
|
||||
tms.tm_year = y - 1900; // Year since 1900
|
||||
tms.tm_mon = M - 1; // 0-11
|
||||
tms.tm_mday = d; // 1-31
|
||||
tms.tm_hour = h; // 0-23
|
||||
tms.tm_min = m; // 0-59
|
||||
tms.tm_sec = (int)s; // 0-61 (0-60 in C++11)
|
||||
return mktime(&tms);
|
||||
}
|
||||
|
||||
std::string format_time_ISO8601Z(time_t time)
|
||||
{
|
||||
struct tm tms;
|
||||
#ifdef WIN32
|
||||
gmtime_s(time, &tms);
|
||||
#else
|
||||
gmtime_r(&tms, time);
|
||||
#endif
|
||||
char buf[128];
|
||||
sprintf(buf, "%d-%d-%dT%d:%d:%fZ",
|
||||
tms.tm_year + 1900
|
||||
tms.tm_mon + 1
|
||||
tms.tm_mday
|
||||
tms.tm_hour
|
||||
tms.tm_min
|
||||
tms.tm_sec);
|
||||
return buf;
|
||||
}
|
||||
|
||||
time_t get_current_time_utc()
|
||||
{
|
||||
#ifdef WIN32
|
||||
SYSTEMTIME st;
|
||||
::GetSystemTime(&st);
|
||||
std::tm tm;
|
||||
tm.tm_sec = st.wSecond;
|
||||
tm.tm_min = st.wMinute;
|
||||
tm.tm_hour = st.wHour;
|
||||
tm.tm_mday = st.wDay;
|
||||
tm.tm_mon = st.wMonth - 1;
|
||||
tm.tm_year = st.wYear - 1900;
|
||||
tm.tm_isdst = -1;
|
||||
return mktime(&tm);
|
||||
#else
|
||||
return gmtime();
|
||||
#endif
|
||||
}
|
||||
|
||||
}; // namespace Utils
|
||||
}; // namespace Slic3r
|
||||
|
||||
#endif /* slic3r_Utils_Time_hpp_ */
|
22
xs/src/slic3r/Utils/Time.hpp
Normal file
22
xs/src/slic3r/Utils/Time.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef slic3r_Utils_Time_hpp_
|
||||
#define slic3r_Utils_Time_hpp_
|
||||
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
|
||||
namespace Slic3r {
|
||||
namespace Utils {
|
||||
|
||||
// Utilities to convert an UTC time_t to/from an ISO8601 time format,
|
||||
// useful for putting timestamps into file and directory names.
|
||||
// Returns (time_t)-1 on error.
|
||||
extern time_t parse_time_ISO8601Z(const std::string &s);
|
||||
extern std::string format_time_ISO8601Z(time_t time);
|
||||
|
||||
// There is no gmtime() on windows.
|
||||
time_t get_current_time_utc();
|
||||
|
||||
}; // namespace Utils
|
||||
}; // namespace Slic3r
|
||||
|
||||
#endif /* slic3r_Utils_Time_hpp_ */
|
Loading…
Add table
Add a link
Reference in a new issue