Merged with Vojtech's branch
This commit is contained in:
commit
c5af8bfe78
@ -101,11 +101,14 @@ sub OnInit {
|
||||
$self->{app_config}->set('version', $Slic3r::VERSION);
|
||||
$self->{app_config}->save;
|
||||
|
||||
Slic3r::PresetUpdater::init_vendors();
|
||||
|
||||
# my $version_check = $self->{app_config}->get('version_check');
|
||||
$self->{preset_updater} = Slic3r::PresetUpdater->new($VERSION_ONLINE_EVENT, $self->{app_config});
|
||||
my $slic3r_update = $self->{app_config}->slic3r_update_avail;
|
||||
eval { $self->{preset_updater}->config_update($self->{app_config}) };
|
||||
if ($@) {
|
||||
warn $@ . "\n";
|
||||
fatal_error(undef, $@);
|
||||
}
|
||||
# my $slic3r_update = $self->{app_config}->slic3r_update_avail;
|
||||
|
||||
Slic3r::GUI::set_app_config($self->{app_config});
|
||||
Slic3r::GUI::load_language();
|
||||
@ -123,6 +126,7 @@ sub OnInit {
|
||||
Slic3r::GUI::set_preset_bundle($self->{preset_bundle});
|
||||
|
||||
# application frame
|
||||
print STDERR "Creating main frame...\n";
|
||||
Wx::Image::FindHandlerType(wxBITMAP_TYPE_PNG) || Wx::Image::AddHandler(Wx::PNGHandler->new);
|
||||
$self->{mainframe} = my $frame = Slic3r::GUI::MainFrame->new(
|
||||
# If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden.
|
||||
@ -145,20 +149,22 @@ sub OnInit {
|
||||
# before the UI was up and running.
|
||||
$self->CallAfter(sub {
|
||||
# XXX: recreate_GUI ???
|
||||
if ($slic3r_update) {
|
||||
# TODO
|
||||
}
|
||||
# if ($slic3r_update) {
|
||||
# # TODO
|
||||
# }
|
||||
# XXX: ?
|
||||
if ($run_wizard) {
|
||||
# Run the config wizard, don't offer the "reset user profile" checkbox.
|
||||
Slic3r::GUI::config_wizard(1);
|
||||
}
|
||||
|
||||
# $self->{preset_updater}->download($self->{preset_bundle});
|
||||
# TODO: call periodically?
|
||||
$self->{preset_updater}->sync($self->{app_config}, $self->{preset_bundle});
|
||||
});
|
||||
|
||||
# The following event is emited by the C++ menu implementation of application language change.
|
||||
EVT_COMMAND($self, -1, $LANGUAGE_CHANGE_EVENT, sub{
|
||||
print STDERR "LANGUAGE_CHANGE_EVENT\n";
|
||||
$self->recreate_GUI;
|
||||
});
|
||||
|
||||
@ -179,6 +185,7 @@ sub OnInit {
|
||||
}
|
||||
|
||||
sub recreate_GUI{
|
||||
print STDERR "recreate_GUI\n";
|
||||
my ($self) = @_;
|
||||
my $topwindow = $self->GetTopWindow();
|
||||
$self->{mainframe} = my $frame = Slic3r::GUI::MainFrame->new(
|
||||
|
@ -8,8 +8,7 @@ name = Prusa Research
|
||||
config_version = 0.1.0
|
||||
# Where to get the updates from?
|
||||
# TODO: proper URL
|
||||
# config_update_url = https://raw.githubusercontent.com/prusa3d/Slic3r-settings/master/live/PrusaResearch.ini
|
||||
config_update_url = https://gist.githubusercontent.com/vojtechkral/4d8fd4a3b8699a01ec892c264178461c/raw/e9187c3e15ceaf1a90f29b7c43cf3ccc746140f0/PrusaResearch.ini
|
||||
config_update_url = https://raw.githubusercontent.com/vojtechkral/slic3r-settings-tmp/master/PrusaResearch
|
||||
|
||||
# The printer models will be shown by the Configuration Wizard in this order,
|
||||
# also the first model installed & the first nozzle installed will be activated after install.
|
||||
|
@ -119,7 +119,7 @@ static std::string g_data_dir;
|
||||
|
||||
void set_data_dir(const std::string &dir)
|
||||
{
|
||||
g_data_dir = dir + "-alpha"; // FIXME: Resolve backcompat problems
|
||||
g_data_dir = dir;
|
||||
}
|
||||
|
||||
const std::string& data_dir()
|
||||
|
@ -637,4 +637,4 @@ semver_copy(const semver_t *ver) {
|
||||
res.prerelease = strdup(ver->prerelease);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ Semver Index::version() const
|
||||
return ver;
|
||||
}
|
||||
|
||||
Index::const_iterator Index::find(const Semver &ver)
|
||||
Index::const_iterator Index::find(const Semver &ver) const
|
||||
{
|
||||
Version key;
|
||||
key.config_version = ver;
|
||||
@ -282,22 +282,21 @@ Index::const_iterator Index::find(const Semver &ver)
|
||||
Index::const_iterator Index::recommended() const
|
||||
{
|
||||
int idx = -1;
|
||||
const_iterator highest = m_configs.end();
|
||||
const_iterator highest = this->end();
|
||||
for (const_iterator it = this->begin(); it != this->end(); ++ it)
|
||||
if (it->is_current_slic3r_supported() &&
|
||||
(highest == this->end() || highest->max_slic3r_version < it->max_slic3r_version))
|
||||
(highest == this->end() || highest->config_version < it->config_version))
|
||||
highest = it;
|
||||
return highest;
|
||||
}
|
||||
|
||||
std::vector<Index> Index::load_db()
|
||||
{
|
||||
boost::filesystem::path data_dir = boost::filesystem::path(Slic3r::data_dir());
|
||||
boost::filesystem::path vendor_dir = data_dir / "vendor";
|
||||
boost::filesystem::path cache_dir = boost::filesystem::path(Slic3r::data_dir()) / "cache";
|
||||
|
||||
std::vector<Index> index_db;
|
||||
std::string errors_cummulative;
|
||||
for (auto &dir_entry : boost::filesystem::directory_iterator(vendor_dir))
|
||||
for (auto &dir_entry : boost::filesystem::directory_iterator(cache_dir))
|
||||
if (boost::filesystem::is_regular_file(dir_entry.status()) && boost::algorithm::iends_with(dir_entry.path().filename().string(), ".idx")) {
|
||||
Index idx;
|
||||
try {
|
||||
|
@ -65,7 +65,7 @@ public:
|
||||
|
||||
const_iterator begin() const { return m_configs.begin(); }
|
||||
const_iterator end() const { return m_configs.end(); }
|
||||
const_iterator find(const Semver &ver);
|
||||
const_iterator find(const Semver &ver) const;
|
||||
const std::vector<Version>& configs() const { return m_configs; }
|
||||
// Finds a recommended config to be installed for the current Slic3r version.
|
||||
// Returns configs().end() if such version does not exist in the index. This shall never happen
|
||||
|
@ -46,11 +46,15 @@ void AppConfig::set_defaults()
|
||||
set("no_defaults", "1");
|
||||
if (get("show_incompatible_presets").empty())
|
||||
set("show_incompatible_presets", "0");
|
||||
// Version check is enabled by default in the config, but it is not implemented yet. // XXX
|
||||
|
||||
if (get("version_check").empty())
|
||||
set("version_check", "1");
|
||||
// TODO: proper URL
|
||||
if (get("version_check_url").empty())
|
||||
set("version_check_url", "https://gist.githubusercontent.com/vojtechkral/4d8fd4a3b8699a01ec892c264178461c/raw/e9187c3e15ceaf1a90f29b7c43cf3ccc746140f0/slic3rPE.version");
|
||||
if (get("preset_update").empty())
|
||||
set("preset_update", "1");
|
||||
|
||||
// Use OpenGL 1.1 even if OpenGL 2.0 is available. This is mainly to support some buggy Intel HD Graphics drivers.
|
||||
// https://github.com/prusa3d/Slic3r/issues/233
|
||||
if (get("use_legacy_opengl").empty())
|
||||
|
@ -69,12 +69,13 @@ public:
|
||||
void clear_section(const std::string §ion)
|
||||
{ m_storage[section].clear(); }
|
||||
|
||||
typedef std::map<std::string, std::map<std::string, std::set<std::string>>> VendorMap;
|
||||
bool get_variant(const std::string &vendor, const std::string &model, const std::string &variant) const;
|
||||
void set_variant(const std::string &vendor, const std::string &model, const std::string &variant, bool enable);
|
||||
void set_vendors(const AppConfig &from);
|
||||
void set_vendors(const std::map<std::string, std::map<std::string, std::set<std::string>>> &vendors) { m_vendors = vendors; m_dirty = true; }
|
||||
void set_vendors(std::map<std::string, std::map<std::string, std::set<std::string>>> &&vendors) { m_vendors = std::move(vendors); m_dirty = true; }
|
||||
const std::map<std::string, std::map<std::string, std::set<std::string>>> vendors() const { return m_vendors; }
|
||||
void set_vendors(const VendorMap &vendors) { m_vendors = vendors; m_dirty = true; }
|
||||
void set_vendors(VendorMap &&vendors) { m_vendors = std::move(vendors); m_dirty = true; }
|
||||
const VendorMap& vendors() const { return m_vendors; }
|
||||
|
||||
// return recent/skein_directory or recent/config_directory or empty string.
|
||||
std::string get_last_dir() const;
|
||||
@ -105,7 +106,7 @@ private:
|
||||
// Map of section, name -> value
|
||||
std::map<std::string, std::map<std::string, std::string>> m_storage;
|
||||
// Map of enabled vendors / models / variants
|
||||
std::map<std::string, std::map<std::string, std::set<std::string>>> m_vendors;
|
||||
VendorMap m_vendors;
|
||||
// Has any value been modified since the config.ini has been last saved or loaded?
|
||||
bool m_dirty;
|
||||
};
|
||||
|
@ -105,9 +105,6 @@ ConfigSnapshotDialog::ConfigSnapshotDialog(const Config::SnapshotDB &snapshot_db
|
||||
html->SetFonts(font.GetFaceName(), font.GetFaceName(), size);
|
||||
html->SetBorders(2);
|
||||
std::string text = generate_html_page(snapshot_db);
|
||||
FILE *file = ::fopen("d:\\temp\\configsnapshotdialog.html", "wt");
|
||||
fwrite(text.data(), 1, text.size(), file);
|
||||
fclose(file);
|
||||
html->SetPage(text.c_str());
|
||||
vsizer->Add(html, 1, wxEXPAND | wxALIGN_LEFT | wxRIGHT | wxBOTTOM, 0);
|
||||
html->Bind(wxEVT_HTML_LINK_CLICKED, &ConfigSnapshotDialog::onLinkClicked, this);
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "ConfigWizard_private.hpp"
|
||||
|
||||
#include <iostream> // XXX
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <wx/settings.h>
|
||||
#include <wx/stattext.h>
|
||||
@ -17,7 +17,6 @@
|
||||
#include "GUI.hpp"
|
||||
#include "slic3r/Utils/PresetUpdater.hpp"
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
@ -62,25 +61,25 @@ PrinterPicker::PrinterPicker(wxWindow *parent, const VendorProfile &vendor, cons
|
||||
auto namefont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
||||
namefont.SetWeight(wxFONTWEIGHT_BOLD);
|
||||
|
||||
for (auto model = models.cbegin(); model != models.cend(); ++model) {
|
||||
for (const auto &model : models) {
|
||||
auto *panel = new wxPanel(this);
|
||||
auto *sizer = new wxBoxSizer(wxVERTICAL);
|
||||
panel->SetSizer(sizer);
|
||||
|
||||
auto *title = new wxStaticText(panel, wxID_ANY, model->name, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
|
||||
auto *title = new wxStaticText(panel, wxID_ANY, model.name, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
|
||||
title->SetFont(namefont);
|
||||
sizer->Add(title, 0, wxBOTTOM, 3);
|
||||
|
||||
auto bitmap_file = wxString::Format("printers/%s_%s.png", vendor.id, model->id);
|
||||
auto bitmap_file = wxString::Format("printers/%s_%s.png", vendor.id, model.id);
|
||||
wxBitmap bitmap(GUI::from_u8(Slic3r::var(bitmap_file.ToStdString())), wxBITMAP_TYPE_PNG);
|
||||
auto *bitmap_widget = new wxStaticBitmap(panel, wxID_ANY, bitmap);
|
||||
sizer->Add(bitmap_widget, 0, wxBOTTOM, 3);
|
||||
|
||||
sizer->AddSpacer(20);
|
||||
|
||||
const auto model_id = model->id;
|
||||
const auto model_id = model.id;
|
||||
|
||||
for (const auto &variant : model->variants) {
|
||||
for (const auto &variant : model.variants) {
|
||||
const auto variant_name = variant.name;
|
||||
auto *cbox = new wxCheckBox(panel, wxID_ANY, wxString::Format("%s %s %s", variant.name, _(L("mm")), _(L("nozzle"))));
|
||||
bool enabled = appconfig_vendors.get_variant("PrusaResearch", model_id, variant_name);
|
||||
@ -177,16 +176,18 @@ PageWelcome::PageWelcome(ConfigWizard *parent) :
|
||||
{
|
||||
append_text(_(L("Hello, welcome to Slic3r Prusa Edition! TODO: This text.")));
|
||||
|
||||
const PresetBundle &bundle = wizard_p()->bundle_vendors;
|
||||
const auto &vendors = bundle.vendors;
|
||||
const auto vendor_prusa = std::find(vendors.cbegin(), vendors.cend(), VendorProfile("PrusaResearch"));
|
||||
// const PresetBundle &bundle = wizard_p()->bundle_vendors;
|
||||
// const auto &vendors = bundle.vendors;
|
||||
const auto &vendors = wizard_p()->vendors;
|
||||
// const auto vendor_prusa = std::find(vendors.cbegin(), vendors.cend(), VendorProfile("PrusaResearch"));
|
||||
const auto vendor_prusa = vendors.find("PrusaResearch");
|
||||
|
||||
if (vendor_prusa != vendors.cend()) {
|
||||
const auto &models = vendor_prusa->models;
|
||||
const auto &models = vendor_prusa->second.models;
|
||||
|
||||
AppConfig &appconfig_vendors = this->wizard_p()->appconfig_vendors;
|
||||
|
||||
printer_picker = new PrinterPicker(this, *vendor_prusa, appconfig_vendors);
|
||||
printer_picker = new PrinterPicker(this, vendor_prusa->second, appconfig_vendors);
|
||||
printer_picker->Bind(EVT_PRINTER_PICK, [this, &appconfig_vendors](const PrinterPickerEvent &evt) {
|
||||
appconfig_vendors.set_variant(evt.vendor_id, evt.model_id, evt.variant_name, evt.enable);
|
||||
this->on_variant_checked();
|
||||
@ -248,14 +249,17 @@ PageVendors::PageVendors(ConfigWizard *parent) :
|
||||
{
|
||||
append_text(_(L("Pick another vendor supported by Slic3r PE:")));
|
||||
|
||||
const PresetBundle &bundle = wizard_p()->bundle_vendors;
|
||||
// const PresetBundle &bundle = wizard_p()->bundle_vendors;
|
||||
// const auto &vendors = wizard_p()->vendors;
|
||||
auto boldfont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
||||
boldfont.SetWeight(wxFONTWEIGHT_BOLD);
|
||||
|
||||
AppConfig &appconfig_vendors = this->wizard_p()->appconfig_vendors;
|
||||
wxArrayString choices_vendors;
|
||||
|
||||
for (const auto &vendor : bundle.vendors) {
|
||||
// for (const auto &vendor : vendors) {
|
||||
for (const auto vendor_pair : wizard_p()->vendors) {
|
||||
const auto &vendor = vendor_pair.second;
|
||||
if (vendor.id == "PrusaResearch") { continue; }
|
||||
|
||||
auto *picker = new PrinterPicker(this, vendor, appconfig_vendors);
|
||||
@ -549,9 +553,25 @@ void ConfigWizardIndex::on_paint(wxPaintEvent & evt)
|
||||
void ConfigWizard::priv::load_vendors()
|
||||
{
|
||||
const auto vendor_dir = fs::path(Slic3r::data_dir()) / "vendor";
|
||||
const auto rsrc_vendor_dir = fs::path(resources_dir()) / "profiles";
|
||||
|
||||
// Load vendors from the "vendors" directory in datadir
|
||||
for (fs::directory_iterator it(vendor_dir); it != fs::directory_iterator(); ++it) {
|
||||
if (it->path().extension() == ".ini") {
|
||||
bundle_vendors.load_configbundle(it->path().string(), PresetBundle::LOAD_CFGBUNDLE_VENDOR_ONLY);
|
||||
auto vp = VendorProfile::from_ini(it->path());
|
||||
vendors[vp.id] = std::move(vp);
|
||||
}
|
||||
}
|
||||
|
||||
// Additionally load up vendors from the application resources directory, but only those not seen in the datadir
|
||||
for (fs::directory_iterator it(rsrc_vendor_dir); it != fs::directory_iterator(); ++it) {
|
||||
if (it->path().extension() == ".ini") {
|
||||
const auto id = it->path().stem().string();
|
||||
if (vendors.find(id) == vendors.end()) {
|
||||
auto vp = VendorProfile::from_ini(it->path());
|
||||
vendors_rsrc[vp.id] = it->path();
|
||||
vendors[vp.id] = std::move(vp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -624,11 +644,25 @@ void ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
|
||||
const bool is_custom_setup = page_welcome->page_next() == page_firmware;
|
||||
|
||||
if (! is_custom_setup) {
|
||||
const auto enabled_vendors = appconfig_vendors.vendors();
|
||||
for (const auto &vendor_rsrc : vendors_rsrc) {
|
||||
const auto vendor = enabled_vendors.find(vendor_rsrc.first);
|
||||
if (vendor == enabled_vendors.end()) { continue; }
|
||||
|
||||
size_t size_sum = 0;
|
||||
for (const auto &model : vendor->second) { size_sum += model.second.size(); }
|
||||
if (size_sum == 0) { continue; }
|
||||
|
||||
// This vendor needs to be installed
|
||||
PresetBundle::install_vendor_configbundle(vendor_rsrc.second);
|
||||
}
|
||||
|
||||
app_config->set_vendors(appconfig_vendors);
|
||||
app_config->set("version_check", page_update->version_check ? "1" : "0");
|
||||
app_config->set("preset_update", page_update->preset_update ? "1" : "0");
|
||||
if (fresh_start)
|
||||
app_config->reset_selections();
|
||||
// ^ TODO: replace with appropriate printer selection
|
||||
preset_bundle->load_presets(*app_config);
|
||||
} else {
|
||||
for (ConfigWizardPage *page = page_firmware; page != nullptr; page = page->page_next()) {
|
||||
|
@ -4,6 +4,9 @@
|
||||
#include "ConfigWizard.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/panel.h>
|
||||
@ -13,13 +16,15 @@
|
||||
|
||||
#include "libslic3r/PrintConfig.hpp"
|
||||
#include "AppConfig.hpp"
|
||||
#include "PresetBundle.hpp"
|
||||
#include "Preset.hpp"
|
||||
#include "BedShapeDialog.hpp"
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
// typedef std::unordered_map<std::string, VendorProfile> VendorMap;
|
||||
|
||||
enum {
|
||||
CONTENT_WIDTH = 500,
|
||||
@ -167,8 +172,9 @@ private:
|
||||
struct ConfigWizard::priv
|
||||
{
|
||||
ConfigWizard *q;
|
||||
AppConfig appconfig_vendors;
|
||||
PresetBundle bundle_vendors;
|
||||
AppConfig appconfig_vendors; // TODO: use order-preserving container
|
||||
std::unordered_map<std::string, VendorProfile> vendors; // TODO: just set?
|
||||
std::unordered_map<std::string, fs::path> vendors_rsrc;
|
||||
std::unique_ptr<DynamicPrintConfig> custom_config;
|
||||
|
||||
wxBoxSizer *topsizer = nullptr;
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include "AppConfig.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
@ -75,6 +77,11 @@ VendorProfile VendorProfile::from_ini(const ptree &tree, const boost::filesystem
|
||||
{
|
||||
static const std::string printer_model_key = "printer_model:";
|
||||
const std::string id = path.stem().string();
|
||||
|
||||
if (! boost::filesystem::exists(path)) {
|
||||
throw std::runtime_error((boost::format("Cannot load Vendor Config Bundle `%1%`: File not found: `%2%`.") % id % path).str());
|
||||
}
|
||||
|
||||
VendorProfile res(id);
|
||||
|
||||
auto get_or_throw = [&](const ptree &tree, const std::string &key) -> ptree::const_assoc_iterator
|
||||
|
@ -59,7 +59,8 @@ public:
|
||||
};
|
||||
std::vector<PrinterModel> models;
|
||||
|
||||
VendorProfile(std::string id) : id(std::move(id)), config_version(0, 0, 0) {}
|
||||
VendorProfile() {}
|
||||
VendorProfile(std::string id) : id(std::move(id)) {}
|
||||
|
||||
static VendorProfile from_ini(const boost::filesystem::path &path, bool load_all=true);
|
||||
static VendorProfile from_ini(const boost::property_tree::ptree &tree, const boost::filesystem::path &path, bool load_all=true);
|
||||
|
@ -713,8 +713,7 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
|
||||
|
||||
const VendorProfile *vendor_profile = nullptr;
|
||||
if (flags & (LOAD_CFGBNDLE_SYSTEM | LOAD_CFGBUNDLE_VENDOR_ONLY)) {
|
||||
boost::filesystem::path fspath(path);
|
||||
auto vp = VendorProfile::from_ini(tree, fspath.stem().string());
|
||||
auto vp = VendorProfile::from_ini(tree, path);
|
||||
if (vp.num_variants() == 0)
|
||||
return 0;
|
||||
vendor_profile = &(*this->vendors.insert(vp).first);
|
||||
|
@ -1,61 +1,148 @@
|
||||
#include "PresetUpdater.hpp"
|
||||
|
||||
#include <iostream> // XXX
|
||||
#include <algorithm>
|
||||
#include <thread>
|
||||
#include <stack>
|
||||
#include <stdexcept>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
#include <wx/app.h>
|
||||
#include <wx/event.h>
|
||||
#include <wx/msgdlg.h>
|
||||
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "slic3r/GUI/GUI.hpp"
|
||||
#include "slic3r/GUI/PresetBundle.hpp"
|
||||
#include "slic3r/Utils/Http.hpp"
|
||||
#include "slic3r/Utils/Semver.hpp"
|
||||
#include "slic3r/Config/Version.hpp"
|
||||
#include "slic3r/Config/Snapshot.hpp"
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
using Slic3r::GUI::Config::Index;
|
||||
using Slic3r::GUI::Config::Version;
|
||||
using Slic3r::GUI::Config::Snapshot;
|
||||
using Slic3r::GUI::Config::SnapshotDB;
|
||||
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
|
||||
// TODO: proper URL
|
||||
// TODO: Actually, use index
|
||||
static const std::string SLIC3R_VERSION_URL = "https://gist.githubusercontent.com/vojtechkral/4d8fd4a3b8699a01ec892c264178461c/raw/e9187c3e15ceaf1a90f29b7c43cf3ccc746140f0/slic3rPE.version";
|
||||
enum {
|
||||
SLIC3R_VERSION_BODY_MAX = 256,
|
||||
};
|
||||
|
||||
static const char *INDEX_FILENAME = "index.idx";
|
||||
static const char *TMP_EXTENSION = ".download";
|
||||
|
||||
|
||||
struct Update
|
||||
{
|
||||
fs::path source;
|
||||
fs::path target;
|
||||
Version version;
|
||||
|
||||
Update(fs::path &&source, const fs::path &target, const Version &version) :
|
||||
source(source),
|
||||
target(std::move(target)),
|
||||
version(version)
|
||||
{}
|
||||
|
||||
std::string name() { return source.stem().string(); }
|
||||
};
|
||||
|
||||
typedef std::vector<Update> Updates;
|
||||
|
||||
|
||||
struct PresetUpdater::priv
|
||||
{
|
||||
int version_online_event;
|
||||
bool version_check;
|
||||
bool preset_update;
|
||||
std::vector<Index> index_db;
|
||||
|
||||
bool enabled_version_check;
|
||||
bool enabled_config_update;
|
||||
std::string version_check_url;
|
||||
|
||||
fs::path cache_path;
|
||||
fs::path rsrc_path;
|
||||
fs::path vendor_path;
|
||||
|
||||
bool cancel;
|
||||
std::thread thread;
|
||||
|
||||
priv(int event);
|
||||
priv(int event, AppConfig *app_config);
|
||||
|
||||
void download(const std::set<VendorProfile> vendors) const;
|
||||
void set_download_prefs(AppConfig *app_config);
|
||||
bool get_file(const std::string &url, const fs::path &target_path) const;
|
||||
void prune_tmps() const;
|
||||
void sync_version() const;
|
||||
void sync_config(const std::set<VendorProfile> vendors) const;
|
||||
|
||||
void check_install_indices() const;
|
||||
Updates config_update() const;
|
||||
};
|
||||
|
||||
PresetUpdater::priv::priv(int event) :
|
||||
PresetUpdater::priv::priv(int event, AppConfig *app_config) :
|
||||
version_online_event(event),
|
||||
version_check(false),
|
||||
preset_update(false),
|
||||
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)
|
||||
{}
|
||||
|
||||
void PresetUpdater::priv::download(const std::set<VendorProfile> vendors) const
|
||||
{
|
||||
if (!version_check) { return; }
|
||||
set_download_prefs(app_config);
|
||||
check_install_indices();
|
||||
index_db = std::move(Index::load_db());
|
||||
}
|
||||
|
||||
// Download current Slic3r version
|
||||
Http::get(SLIC3R_VERSION_URL)
|
||||
void PresetUpdater::priv::set_download_prefs(AppConfig *app_config)
|
||||
{
|
||||
enabled_version_check = app_config->get("version_check") == "1";
|
||||
version_check_url = app_config->get("version_check_url");
|
||||
enabled_config_update = app_config->get("preset_update") == "1";
|
||||
}
|
||||
|
||||
bool PresetUpdater::priv::get_file(const std::string &url, const fs::path &target_path) const
|
||||
{
|
||||
std::cerr << "get_file(): " << url << " -> " << target_path << std::endl;
|
||||
|
||||
// TODO: Proper caching
|
||||
|
||||
bool res = false;
|
||||
fs::path tmp_path = target_path;
|
||||
tmp_path += TMP_EXTENSION;
|
||||
|
||||
Http::get(url)
|
||||
.on_progress([this](Http::Progress, bool &cancel) {
|
||||
if (cancel) { cancel = true; }
|
||||
})
|
||||
.on_complete([&](std::string body, unsigned http_status) {
|
||||
fs::fstream file(tmp_path, std::ios::out | std::ios::binary | std::ios::trunc);
|
||||
file.write(body.c_str(), body.size());
|
||||
fs::rename(tmp_path, target_path);
|
||||
res = true;
|
||||
})
|
||||
.perform_sync();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void PresetUpdater::priv::prune_tmps() const
|
||||
{
|
||||
for (fs::directory_iterator it(cache_path); it != fs::directory_iterator(); ++it) {
|
||||
if (it->path().extension() == TMP_EXTENSION) {
|
||||
fs::remove(it->path());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PresetUpdater::priv::sync_version() const
|
||||
{
|
||||
if (! enabled_version_check) { return; }
|
||||
|
||||
Http::get(version_check_url)
|
||||
.size_limit(SLIC3R_VERSION_BODY_MAX)
|
||||
.on_progress([this](Http::Progress, bool &cancel) {
|
||||
cancel = this->cancel;
|
||||
@ -67,38 +154,126 @@ void PresetUpdater::priv::download(const std::set<VendorProfile> vendors) const
|
||||
GUI::get_app()->QueueEvent(evt);
|
||||
})
|
||||
.perform_sync();
|
||||
}
|
||||
|
||||
if (!preset_update) { return; }
|
||||
void PresetUpdater::priv::sync_config(const std::set<VendorProfile> vendors) const
|
||||
{
|
||||
std::cerr << "sync_config()" << std::endl;
|
||||
|
||||
if (!enabled_config_update) { return; }
|
||||
|
||||
// Donwload vendor preset bundles
|
||||
for (const auto &vendor : vendors) {
|
||||
for (const auto &index : index_db) {
|
||||
if (cancel) { return; }
|
||||
|
||||
// TODO: Proper caching
|
||||
std::cerr << "Index: " << index.vendor() << std::endl;
|
||||
|
||||
auto target_path = cache_path / vendor.id;
|
||||
target_path += ".ini";
|
||||
const auto vendor_it = vendors.find(VendorProfile(index.vendor()));
|
||||
if (vendor_it == vendors.end()) { continue; }
|
||||
|
||||
Http::get(vendor.config_update_url)
|
||||
.on_progress([this](Http::Progress, bool &cancel) {
|
||||
cancel = this->cancel;
|
||||
})
|
||||
.on_complete([&](std::string body, unsigned http_status) {
|
||||
fs::fstream file(target_path, std::ios::out | std::ios::binary | std::ios::trunc);
|
||||
file.write(body.c_str(), body.size());
|
||||
})
|
||||
.perform_sync();
|
||||
const VendorProfile &vendor = *vendor_it;
|
||||
if (vendor.config_update_url.empty()) { continue; }
|
||||
|
||||
// Download a fresh index
|
||||
const auto idx_url = vendor.config_update_url + "/" + INDEX_FILENAME;
|
||||
const auto idx_path = cache_path / (vendor.id + ".idx");
|
||||
if (! get_file(idx_url, idx_path)) { continue; }
|
||||
if (cancel) { return; }
|
||||
|
||||
std::cerr << "Got a new index: " << idx_path << std::endl;
|
||||
|
||||
// Load the fresh index up
|
||||
Index new_index;
|
||||
new_index.load(idx_path);
|
||||
|
||||
// See if a there's a new version to download
|
||||
const auto recommended_it = new_index.recommended();
|
||||
if (recommended_it == new_index.end()) { continue; }
|
||||
const auto recommended = recommended_it->config_version;
|
||||
|
||||
std::cerr << "Current vendor version: " << vendor.config_version.to_string() << std::endl;
|
||||
std::cerr << "Recommended version:\t" << recommended.to_string() << std::endl;
|
||||
|
||||
if (vendor.config_version >= recommended) { continue; }
|
||||
|
||||
// Download a fresh bundle
|
||||
const auto bundle_url = (boost::format("%1%/%2%.ini") % vendor.config_update_url % recommended.to_string()).str();
|
||||
const auto bundle_path = cache_path / (vendor.id + ".ini");
|
||||
if (! get_file(bundle_url, bundle_path)) { continue; }
|
||||
if (cancel) { return; }
|
||||
|
||||
std::cerr << "Got a new bundle: " << bundle_path << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
PresetUpdater::PresetUpdater(int version_online_event, AppConfig *app_config) :
|
||||
p(new priv(version_online_event))
|
||||
void PresetUpdater::priv::check_install_indices() const
|
||||
{
|
||||
p->preset_update = app_config->get("preset_update") == "1";
|
||||
// preset_update implies version_check:
|
||||
p->version_check = p->preset_update || app_config->get("version_check") == "1";
|
||||
for (fs::directory_iterator it(rsrc_path); it != fs::directory_iterator(); ++it) {
|
||||
const auto &path = it->path();
|
||||
if (path.extension() == ".idx") {
|
||||
const auto path_in_cache = cache_path / path.filename();
|
||||
|
||||
// TODO: compare versions
|
||||
if (! fs::exists(path_in_cache)) {
|
||||
fs::copy_file(path, path_in_cache, fs::copy_option::overwrite_if_exists);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Updates PresetUpdater::priv::config_update() const
|
||||
{
|
||||
Updates updates;
|
||||
|
||||
for (const auto idx : index_db) {
|
||||
const auto bundle_path = vendor_path / (idx.vendor() + ".ini");
|
||||
|
||||
if (! fs::exists(bundle_path)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Perform a basic load and check the version
|
||||
const auto vp = VendorProfile::from_ini(bundle_path, false);
|
||||
|
||||
const auto ver_current = idx.find(vp.config_version);
|
||||
if (ver_current == idx.end()) {
|
||||
// TODO: throw / ignore ?
|
||||
}
|
||||
|
||||
const auto recommended = idx.recommended();
|
||||
if (recommended == idx.end()) {
|
||||
throw std::runtime_error((boost::format("Invalid index: `%1%`") % idx.vendor()).str());
|
||||
}
|
||||
|
||||
if (! ver_current->is_current_slic3r_supported()) {
|
||||
|
||||
// TODO: Downgrade situation
|
||||
|
||||
} else if (recommended->config_version > ver_current->config_version) {
|
||||
// Config bundle update situation
|
||||
|
||||
auto path_in_cache = cache_path / (idx.vendor() + ".ini");
|
||||
if (! fs::exists(path_in_cache)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto cached_vp = VendorProfile::from_ini(path_in_cache, false);
|
||||
if (cached_vp.config_version == recommended->config_version) {
|
||||
updates.emplace_back(std::move(path_in_cache), bundle_path, *recommended);
|
||||
} else {
|
||||
// XXX: ?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return updates;
|
||||
}
|
||||
|
||||
|
||||
PresetUpdater::PresetUpdater(int version_online_event, AppConfig *app_config) :
|
||||
p(new priv(version_online_event, app_config))
|
||||
{}
|
||||
|
||||
|
||||
// Public
|
||||
|
||||
@ -110,8 +285,10 @@ PresetUpdater::~PresetUpdater()
|
||||
}
|
||||
}
|
||||
|
||||
void PresetUpdater::download(PresetBundle *preset_bundle)
|
||||
void PresetUpdater::sync(AppConfig *app_config, PresetBundle *preset_bundle)
|
||||
{
|
||||
p->set_download_prefs(app_config);
|
||||
if (!p->enabled_version_check && !p->enabled_config_update) { return; }
|
||||
|
||||
// Copy the whole vendors data for use in the background thread
|
||||
// Unfortunatelly as of C++11, it needs to be copied again
|
||||
@ -119,23 +296,56 @@ void PresetUpdater::download(PresetBundle *preset_bundle)
|
||||
std::set<VendorProfile> vendors = preset_bundle->vendors;
|
||||
|
||||
p->thread = std::move(std::thread([this, vendors]() {
|
||||
this->p->download(std::move(vendors));
|
||||
this->p->prune_tmps();
|
||||
this->p->sync_version();
|
||||
this->p->sync_config(std::move(vendors));
|
||||
}));
|
||||
}
|
||||
|
||||
void PresetUpdater::init_vendors()
|
||||
void PresetUpdater::config_update(AppConfig *app_config)
|
||||
{
|
||||
const auto vendors_rources = fs::path(resources_dir()) / "profiles";
|
||||
const auto vendors_data = fs::path(Slic3r::data_dir()) / "vendor";
|
||||
if (! p->enabled_config_update) { return; }
|
||||
|
||||
for (fs::directory_iterator it(vendors_rources); it != fs::directory_iterator(); ++it) {
|
||||
if (it->path().extension() == ".ini") {
|
||||
auto vp = VendorProfile::from_ini(it->path(), false);
|
||||
const auto path_in_data = vendors_data / it->path().filename();
|
||||
const auto updates = p->config_update();
|
||||
if (updates.size() > 0) {
|
||||
const auto msg = _(L("Configuration update is available. Would you like to install it?"));
|
||||
|
||||
if (! fs::exists(path_in_data) || VendorProfile::from_ini(path_in_data, false).config_version < vp.config_version) {
|
||||
// FIXME: update vendor bundle properly when snapshotting is ready
|
||||
PresetBundle::install_vendor_configbundle(it->path());
|
||||
auto ext_msg = _(L(
|
||||
"Note that a full configuration snapshot will be created first. It can then be restored at any time "
|
||||
"should there be a problem with the new version.\n\n"
|
||||
"Updated configuration bundles:\n"
|
||||
));
|
||||
|
||||
for (const auto &update : updates) {
|
||||
ext_msg += update.target.stem().string() + " " + update.version.config_version.to_string();
|
||||
if (! update.version.comment.empty()) {
|
||||
ext_msg += std::string(" (") + update.version.comment + ")";
|
||||
}
|
||||
ext_msg += "\n";
|
||||
}
|
||||
|
||||
wxMessageDialog dlg(NULL, msg, _(L("Configuration update")), wxYES_NO|wxCENTRE);
|
||||
dlg.SetExtendedMessage(ext_msg);
|
||||
const auto res = dlg.ShowModal();
|
||||
std::cerr << "After modal" << std::endl;
|
||||
if (res == wxID_YES) {
|
||||
// User gave clearance, updates are go
|
||||
|
||||
SnapshotDB::singleton().take_snapshot(*app_config, Snapshot::SNAPSHOT_UPGRADE, "");
|
||||
|
||||
for (const auto &update : updates) {
|
||||
fs::copy_file(update.source, update.target, fs::copy_option::overwrite_if_exists);
|
||||
|
||||
PresetBundle bundle;
|
||||
bundle.load_configbundle(update.target.string(), PresetBundle::LOAD_CFGBNDLE_SYSTEM);
|
||||
|
||||
auto preset_remover = [](const Preset &preset) {
|
||||
fs::remove(preset.file);
|
||||
};
|
||||
|
||||
for (const auto &preset : bundle.prints) { preset_remover(preset); }
|
||||
for (const auto &preset : bundle.filaments) { preset_remover(preset); }
|
||||
for (const auto &preset : bundle.printers) { preset_remover(preset); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ public:
|
||||
PresetUpdater &operator=(const PresetUpdater &) = delete;
|
||||
~PresetUpdater();
|
||||
|
||||
void download(PresetBundle *preset_bundle); // XXX
|
||||
void sync(AppConfig *app_config, PresetBundle *preset_bundle);
|
||||
|
||||
static void init_vendors();
|
||||
void config_update(AppConfig *app_config);
|
||||
private:
|
||||
struct priv;
|
||||
std::unique_ptr<priv> p;
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
// FIXME:: operators=: leak, return
|
||||
|
||||
class Semver
|
||||
{
|
||||
@ -20,6 +19,8 @@ public:
|
||||
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<std::string> metadata = boost::none,
|
||||
boost::optional<std::string> prerelease = boost::none)
|
||||
|
@ -7,6 +7,6 @@
|
||||
|
||||
%name{Slic3r::PresetUpdater} class PresetUpdater {
|
||||
PresetUpdater(int version_online_event, AppConfig *app_config);
|
||||
void download(PresetBundle* preset_bundle);
|
||||
static void init_vendors();
|
||||
void sync(AppConfig *app_config, PresetBundle* preset_bundle);
|
||||
void config_update(AppConfig *app_config);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user