Snapshots: Disable activation of incompatible snapshots
This commit is contained in:
parent
df3e84d580
commit
bbc3c890ea
@ -117,11 +117,11 @@ void Snapshot::load_ini(const std::string &path)
|
|||||||
if (! semver)
|
if (! semver)
|
||||||
throw_on_parse_error("invalid " + kvp.first + " format for " + section.first);
|
throw_on_parse_error("invalid " + kvp.first + " format for " + section.first);
|
||||||
if (kvp.first == "version")
|
if (kvp.first == "version")
|
||||||
vc.version = *semver;
|
vc.version.config_version = *semver;
|
||||||
else if (kvp.first == "min_slic3r_version")
|
else if (kvp.first == "min_slic3r_version")
|
||||||
vc.min_slic3r_version = *semver;
|
vc.version.min_slic3r_version = *semver;
|
||||||
else
|
else
|
||||||
vc.max_slic3r_version = *semver;
|
vc.version.max_slic3r_version = *semver;
|
||||||
} else if (boost::starts_with(kvp.first, key_prefix_model) && kvp.first.size() > key_prefix_model.size()) {
|
} else if (boost::starts_with(kvp.first, key_prefix_model) && kvp.first.size() > key_prefix_model.size()) {
|
||||||
// Parse the printer variants installed for the current model.
|
// Parse the printer variants installed for the current model.
|
||||||
auto &set_variants = vc.models_variants_installed[kvp.first.substr(key_prefix_model.size())];
|
auto &set_variants = vc.models_variants_installed[kvp.first.substr(key_prefix_model.size())];
|
||||||
@ -181,9 +181,9 @@ void Snapshot::save_ini(const std::string &path)
|
|||||||
// Export the vendor configs.
|
// Export the vendor configs.
|
||||||
for (const VendorConfig &vc : this->vendor_configs) {
|
for (const VendorConfig &vc : this->vendor_configs) {
|
||||||
c << std::endl << "[Vendor:" << vc.name << "]" << std::endl;
|
c << std::endl << "[Vendor:" << vc.name << "]" << std::endl;
|
||||||
c << "version = " << vc.version.to_string() << std::endl;
|
c << "version = " << vc.version.config_version.to_string() << std::endl;
|
||||||
c << "min_slic3r_version = " << vc.min_slic3r_version.to_string() << std::endl;
|
c << "min_slic3r_version = " << vc.version.min_slic3r_version.to_string() << std::endl;
|
||||||
c << "max_slic3r_version = " << vc.max_slic3r_version.to_string() << std::endl;
|
c << "max_slic3r_version = " << vc.version.max_slic3r_version.to_string() << std::endl;
|
||||||
// Export installed printer models and their variants.
|
// Export installed printer models and their variants.
|
||||||
for (const auto &model : vc.models_variants_installed) {
|
for (const auto &model : vc.models_variants_installed) {
|
||||||
if (model.second.size() == 0)
|
if (model.second.size() == 0)
|
||||||
@ -326,10 +326,10 @@ void SnapshotDB::update_slic3r_versions(std::vector<Index> &index_db)
|
|||||||
for (Snapshot::VendorConfig &vendor_config : snapshot.vendor_configs) {
|
for (Snapshot::VendorConfig &vendor_config : snapshot.vendor_configs) {
|
||||||
auto it = std::find_if(index_db.begin(), index_db.end(), [&vendor_config](const Index &idx) { return idx.vendor() == vendor_config.name; });
|
auto it = std::find_if(index_db.begin(), index_db.end(), [&vendor_config](const Index &idx) { return idx.vendor() == vendor_config.name; });
|
||||||
if (it != index_db.end()) {
|
if (it != index_db.end()) {
|
||||||
Index::const_iterator it_version = it->find(vendor_config.version);
|
Index::const_iterator it_version = it->find(vendor_config.version.config_version);
|
||||||
if (it_version != it->end()) {
|
if (it_version != it->end()) {
|
||||||
vendor_config.min_slic3r_version = it_version->min_slic3r_version;
|
vendor_config.version.min_slic3r_version = it_version->min_slic3r_version;
|
||||||
vendor_config.max_slic3r_version = it_version->max_slic3r_version;
|
vendor_config.version.max_slic3r_version = it_version->max_slic3r_version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -395,16 +395,16 @@ const Snapshot& SnapshotDB::take_snapshot(const AppConfig &app_config, Snapshot:
|
|||||||
bundle.load_configbundle((data_dir / "vendor" / (cfg.name + ".ini")).string(), PresetBundle::LOAD_CFGBUNDLE_VENDOR_ONLY);
|
bundle.load_configbundle((data_dir / "vendor" / (cfg.name + ".ini")).string(), PresetBundle::LOAD_CFGBUNDLE_VENDOR_ONLY);
|
||||||
for (const VendorProfile &vp : bundle.vendors)
|
for (const VendorProfile &vp : bundle.vendors)
|
||||||
if (vp.id == cfg.name)
|
if (vp.id == cfg.name)
|
||||||
cfg.version = vp.config_version;
|
cfg.version.config_version = vp.config_version;
|
||||||
// Fill-in the min/max slic3r version from the config index, if possible.
|
// Fill-in the min/max slic3r version from the config index, if possible.
|
||||||
try {
|
try {
|
||||||
// Load the config index for the vendor.
|
// Load the config index for the vendor.
|
||||||
Index index;
|
Index index;
|
||||||
index.load(data_dir / "vendor" / (cfg.name + ".idx"));
|
index.load(data_dir / "vendor" / (cfg.name + ".idx"));
|
||||||
auto it = index.find(cfg.version);
|
auto it = index.find(cfg.version.config_version);
|
||||||
if (it != index.end()) {
|
if (it != index.end()) {
|
||||||
cfg.min_slic3r_version = it->min_slic3r_version;
|
cfg.version.min_slic3r_version = it->min_slic3r_version;
|
||||||
cfg.max_slic3r_version = it->max_slic3r_version;
|
cfg.version.max_slic3r_version = it->max_slic3r_version;
|
||||||
}
|
}
|
||||||
} catch (const std::runtime_error &err) {
|
} catch (const std::runtime_error &err) {
|
||||||
}
|
}
|
||||||
@ -476,7 +476,7 @@ SnapshotDB::const_iterator SnapshotDB::snapshot_with_vendor_preset(const std::st
|
|||||||
auto it_vendor_config = std::lower_bound(snapshot.vendor_configs.begin(), snapshot.vendor_configs.end(),
|
auto it_vendor_config = std::lower_bound(snapshot.vendor_configs.begin(), snapshot.vendor_configs.end(),
|
||||||
key, [](const Snapshot::VendorConfig &cfg1, const Snapshot::VendorConfig &cfg2) { return cfg1.name < cfg2.name; });
|
key, [](const Snapshot::VendorConfig &cfg1, const Snapshot::VendorConfig &cfg2) { return cfg1.name < cfg2.name; });
|
||||||
if (it_vendor_config != snapshot.vendor_configs.end() && it_vendor_config->name == vendor_name &&
|
if (it_vendor_config != snapshot.vendor_configs.end() && it_vendor_config->name == vendor_name &&
|
||||||
config_version == it_vendor_config->version) {
|
config_version == it_vendor_config->version.config_version) {
|
||||||
// Vendor config found with the correct version.
|
// Vendor config found with the correct version.
|
||||||
// Save it, but continue searching, as we want the newest snapshot.
|
// Save it, but continue searching, as we want the newest snapshot.
|
||||||
it_found = it;
|
it_found = it;
|
||||||
|
@ -18,7 +18,6 @@ class AppConfig;
|
|||||||
namespace GUI {
|
namespace GUI {
|
||||||
namespace Config {
|
namespace Config {
|
||||||
|
|
||||||
class Version;
|
|
||||||
class Index;
|
class Index;
|
||||||
|
|
||||||
// A snapshot contains:
|
// A snapshot contains:
|
||||||
@ -76,12 +75,8 @@ public:
|
|||||||
struct VendorConfig {
|
struct VendorConfig {
|
||||||
// Name of the vendor contained in this snapshot.
|
// Name of the vendor contained in this snapshot.
|
||||||
std::string name;
|
std::string name;
|
||||||
// Version of the vendor config contained in this snapshot.
|
// Version of the vendor config contained in this snapshot, along with compatibility data.
|
||||||
Semver version = Semver::invalid();
|
Version version;
|
||||||
// Minimum Slic3r version compatible with this vendor configuration.
|
|
||||||
Semver min_slic3r_version = Semver::zero();
|
|
||||||
// Maximum Slic3r version compatible with this vendor configuration, or empty.
|
|
||||||
Semver max_slic3r_version = Semver::inf();
|
|
||||||
// Which printer models of this vendor were installed, and which variants of the models?
|
// Which printer models of this vendor were installed, and which variants of the models?
|
||||||
std::map<std::string, std::set<std::string>> models_variants_installed;
|
std::map<std::string, std::set<std::string>> models_variants_installed;
|
||||||
};
|
};
|
||||||
|
@ -13,7 +13,7 @@ namespace Slic3r {
|
|||||||
namespace GUI {
|
namespace GUI {
|
||||||
namespace Config {
|
namespace Config {
|
||||||
|
|
||||||
static boost::optional<Semver> s_current_slic3r_semver = Semver::parse(SLIC3R_VERSION);
|
static const Semver s_current_slic3r_semver(SLIC3R_VERSION);
|
||||||
|
|
||||||
// Optimized lexicographic compare of two pre-release versions, ignoring the numeric suffix.
|
// Optimized lexicographic compare of two pre-release versions, ignoring the numeric suffix.
|
||||||
static int compare_prerelease(const char *p1, const char *p2)
|
static int compare_prerelease(const char *p1, const char *p2)
|
||||||
@ -62,7 +62,7 @@ bool Version::is_slic3r_supported(const Semver &slic3r_version) const
|
|||||||
|
|
||||||
bool Version::is_current_slic3r_supported() const
|
bool Version::is_current_slic3r_supported() const
|
||||||
{
|
{
|
||||||
return this->is_slic3r_supported(*s_current_slic3r_semver);
|
return this->is_slic3r_supported(s_current_slic3r_semver);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -39,18 +39,16 @@ static std::string generate_html_row(const Config::Snapshot &snapshot, bool row_
|
|||||||
text += " (" + snapshot.comment + ")";
|
text += " (" + snapshot.comment + ")";
|
||||||
text += "</b></font><br>";
|
text += "</b></font><br>";
|
||||||
// End of row header.
|
// End of row header.
|
||||||
// text += _(L("ID:")) + " " + snapshot.id + "<br>";
|
|
||||||
// text += _(L("time captured:")) + " " + Utils::format_local_date_time(snapshot.time_captured) + "<br>";
|
|
||||||
text += _(L("slic3r version")) + ": " + snapshot.slic3r_version_captured.to_string() + "<br>";
|
text += _(L("slic3r version")) + ": " + snapshot.slic3r_version_captured.to_string() + "<br>";
|
||||||
// text += "reason: " + snapshot.reason + "<br>";
|
|
||||||
text += _(L("print")) + ": " + snapshot.print + "<br>";
|
text += _(L("print")) + ": " + snapshot.print + "<br>";
|
||||||
text += _(L("filaments")) + ": " + snapshot.filaments.front() + "<br>";
|
text += _(L("filaments")) + ": " + snapshot.filaments.front() + "<br>";
|
||||||
text += _(L("printer")) + ": " + snapshot.printer + "<br>";
|
text += _(L("printer")) + ": " + snapshot.printer + "<br>";
|
||||||
|
|
||||||
|
bool compatible = true;
|
||||||
for (const Config::Snapshot::VendorConfig &vc : snapshot.vendor_configs) {
|
for (const Config::Snapshot::VendorConfig &vc : snapshot.vendor_configs) {
|
||||||
text += _(L("vendor")) + ": " + vc.name + ", ver: " + vc.version.to_string() + ", min slic3r ver: " + vc.min_slic3r_version.to_string();
|
text += _(L("vendor")) + ": " + vc.name + ", ver: " + vc.version.config_version.to_string() + ", min slic3r ver: " + vc.version.min_slic3r_version.to_string();
|
||||||
if (vc.max_slic3r_version != Semver::inf())
|
if (vc.version.max_slic3r_version != Semver::inf())
|
||||||
text += ", max slic3r ver: " + vc.max_slic3r_version.to_string();
|
text += ", max slic3r ver: " + vc.version.max_slic3r_version.to_string();
|
||||||
text += "<br>";
|
text += "<br>";
|
||||||
for (const std::pair<std::string, std::set<std::string>> &model : vc.models_variants_installed) {
|
for (const std::pair<std::string, std::set<std::string>> &model : vc.models_variants_installed) {
|
||||||
text += _(L("model")) + ": " + model.first + ", " + _(L("variants")) + ": ";
|
text += _(L("model")) + ": " + model.first + ", " + _(L("variants")) + ": ";
|
||||||
@ -61,9 +59,13 @@ static std::string generate_html_row(const Config::Snapshot &snapshot, bool row_
|
|||||||
}
|
}
|
||||||
text += "<br>";
|
text += "<br>";
|
||||||
}
|
}
|
||||||
|
if (! vc.version.is_current_slic3r_supported()) { compatible = false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! snapshot_active)
|
if (! compatible) {
|
||||||
|
text += "<p align=\"right\">" + _(L("Incompatible with this Slic3r")) + "</p>";
|
||||||
|
}
|
||||||
|
else if (! snapshot_active)
|
||||||
text += "<p align=\"right\"><a href=\"" + snapshot.id + "\">" + _(L("Activate")) + "</a></p>";
|
text += "<p align=\"right\"><a href=\"" + snapshot.id + "\">" + _(L("Activate")) + "</a></p>";
|
||||||
text += "</td>";
|
text += "</td>";
|
||||||
text += "</tr>";
|
text += "</tr>";
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
#include <stdexcept>
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
|
|
||||||
@ -33,6 +34,16 @@ public:
|
|||||||
set_prerelease(prerelease);
|
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)
|
static boost::optional<Semver> parse(const std::string &str)
|
||||||
{
|
{
|
||||||
semver_t ver = semver_zero();
|
semver_t ver = semver_zero();
|
||||||
|
Loading…
Reference in New Issue
Block a user