Updating: Add localized links

This commit is contained in:
Vojtech Kral 2019-05-13 18:38:48 +02:00
parent 62847736c8
commit 6c5bdeadc3
6 changed files with 102 additions and 46 deletions

View File

@ -8,6 +8,7 @@ name = Prusa Research
config_version = 0.8.0-beta config_version = 0.8.0-beta
# Where to get the updates from? # Where to get the updates from?
config_update_url = https://raw.githubusercontent.com/prusa3d/Slic3r-settings/master/live/PrusaResearch/ config_update_url = https://raw.githubusercontent.com/prusa3d/Slic3r-settings/master/live/PrusaResearch/
changelog_url = http://files.prusa3d.com/?latest=slicer-profiles&lng=%1%
# The printer models will be shown by the Configuration Wizard in this order, # 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. # also the first model installed & the first nozzle installed will be activated after install.

View File

@ -127,11 +127,16 @@ VendorProfile VendorProfile::from_ini(const ptree &tree, const boost::filesystem
res.config_version = std::move(*config_version); res.config_version = std::move(*config_version);
} }
auto config_update_url = vendor_section.find("config_update_url"); const auto config_update_url = vendor_section.find("config_update_url");
if (config_update_url != vendor_section.not_found()) { if (config_update_url != vendor_section.not_found()) {
res.config_update_url = config_update_url->second.data(); res.config_update_url = config_update_url->second.data();
} }
const auto changelog_url = vendor_section.find("changelog_url");
if (changelog_url != vendor_section.not_found()) {
res.changelog_url = changelog_url->second.data();
}
if (! load_all) { if (! load_all) {
return res; return res;
} }

View File

@ -44,6 +44,7 @@ public:
std::string id; std::string id;
Semver config_version; Semver config_version;
std::string config_update_url; std::string config_update_url;
std::string changelog_url;
struct PrinterVariant { struct PrinterVariant {
PrinterVariant() {} PrinterVariant() {}

View File

@ -1,5 +1,8 @@
#include "UpdateDialogs.hpp" #include "UpdateDialogs.hpp"
#include <cstring>
#include <boost/format.hpp>
#include <wx/settings.h> #include <wx/settings.h>
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/event.h> #include <wx/event.h>
@ -21,7 +24,11 @@ namespace Slic3r {
namespace GUI { namespace GUI {
static const std::string CONFIG_UPDATE_WIKI_URL("https://github.com/prusa3d/Slic3r/wiki/Slic3r-PE-1.40-configuration-update"); static const char* URL_CHANGELOG = "http://files.prusa3d.com/file/?type=slicerstable&lng=%1%";
static const char* URL_DOWNLOAD = "https://www.prusa3d.com/downloads&lng=%1%";
static const char* URL_DEV = "https://github.com/prusa3d/PrusaSlicer/releases/tag/version_%1%";
static const std::string CONFIG_UPDATE_WIKI_URL("https://github.com/prusa3d/PrusaSlicer/wiki/Slic3r-PE-1.40-configuration-update");
// MsgUpdateSlic3r // MsgUpdateSlic3r
@ -31,15 +38,8 @@ MsgUpdateSlic3r::MsgUpdateSlic3r(const Semver &ver_current, const Semver &ver_on
ver_current(ver_current), ver_current(ver_current),
ver_online(ver_online) ver_online(ver_online)
{ {
const auto url = wxString::Format("https://github.com/prusa3d/Slic3r/releases/tag/version_%s", ver_online.to_string()); const auto version = Semver::parse(SLIC3R_VERSION);
auto *link = new wxHyperlinkCtrl(this, wxID_ANY, url, url); const bool dev_version = version->prerelease() != nullptr;
auto *text = new wxStaticText(this, wxID_ANY, _(L("To download, follow the link below.")));
const auto link_width = link->GetSize().GetWidth();
const int content_width = CONTENT_WIDTH * wxGetApp().em_unit();
text->Wrap(content_width > link_width ? content_width : link_width);
content_sizer->Add(text);
content_sizer->AddSpacer(VERT_SPACING);
auto *versions = new wxFlexGridSizer(2, 0, VERT_SPACING); auto *versions = new wxFlexGridSizer(2, 0, VERT_SPACING);
versions->Add(new wxStaticText(this, wxID_ANY, _(L("Current version:")))); versions->Add(new wxStaticText(this, wxID_ANY, _(L("Current version:"))));
@ -49,7 +49,25 @@ MsgUpdateSlic3r::MsgUpdateSlic3r(const Semver &ver_current, const Semver &ver_on
content_sizer->Add(versions); content_sizer->Add(versions);
content_sizer->AddSpacer(VERT_SPACING); content_sizer->AddSpacer(VERT_SPACING);
content_sizer->Add(link); if (dev_version) {
const std::string url = (boost::format(URL_DEV) % ver_online.to_string()).str();
const wxString url_wx = from_u8(url);
auto *link = new wxHyperlinkCtrl(this, wxID_ANY, _(L("Changelog && Download")), url_wx);
content_sizer->Add(link);
} else {
const auto lang_code = wxGetApp().current_language_code().ToStdString();
const std::string url_log = (boost::format(URL_CHANGELOG) % lang_code).str();
const wxString url_log_wx = from_u8(url_log);
auto *link_log = new wxHyperlinkCtrl(this, wxID_ANY, _(L("Open changelog page")), url_log_wx);
content_sizer->Add(link_log);
const std::string url_dw = (boost::format(URL_DOWNLOAD) % lang_code).str();
const wxString url_dw_wx = from_u8(url_dw);
auto *link_dw = new wxHyperlinkCtrl(this, wxID_ANY, _(L("Open download page")), url_dw_wx);
content_sizer->Add(link_dw);
}
content_sizer->AddSpacer(2*VERT_SPACING); content_sizer->AddSpacer(2*VERT_SPACING);
cbox = new wxCheckBox(this, wxID_ANY, _(L("Don't notify about new releases any more"))); cbox = new wxCheckBox(this, wxID_ANY, _(L("Don't notify about new releases any more")));
@ -69,7 +87,7 @@ bool MsgUpdateSlic3r::disable_version_check() const
// MsgUpdateConfig // MsgUpdateConfig
MsgUpdateConfig::MsgUpdateConfig(const std::unordered_map<std::string, std::string> &updates) : MsgUpdateConfig::MsgUpdateConfig(const std::vector<Update> &updates) :
MsgDialog(nullptr, _(L("Configuration update")), _(L("Configuration update is available")), wxID_NONE) MsgDialog(nullptr, _(L("Configuration update")), _(L("Configuration update is available")), wxID_NONE)
{ {
auto *text = new wxStaticText(this, wxID_ANY, _(L( auto *text = new wxStaticText(this, wxID_ANY, _(L(
@ -82,12 +100,31 @@ MsgUpdateConfig::MsgUpdateConfig(const std::unordered_map<std::string, std::stri
content_sizer->Add(text); content_sizer->Add(text);
content_sizer->AddSpacer(VERT_SPACING); content_sizer->AddSpacer(VERT_SPACING);
auto *versions = new wxFlexGridSizer(2, 0, VERT_SPACING); const auto lang_code = wxGetApp().current_language_code().ToStdString();
auto *versions = new wxBoxSizer(wxVERTICAL);
for (const auto &update : updates) { for (const auto &update : updates) {
auto *text_vendor = new wxStaticText(this, wxID_ANY, update.first); auto *flex = new wxFlexGridSizer(2, 0, VERT_SPACING);
auto *text_vendor = new wxStaticText(this, wxID_ANY, update.vendor);
text_vendor->SetFont(boldfont); text_vendor->SetFont(boldfont);
versions->Add(text_vendor); flex->Add(text_vendor);
versions->Add(new wxStaticText(this, wxID_ANY, update.second)); flex->Add(new wxStaticText(this, wxID_ANY, update.version.to_string()));
if (! update.comment.empty()) {
flex->Add(new wxStaticText(this, wxID_ANY, _(L("Comment:"))), 0, wxALIGN_RIGHT);
flex->Add(new wxStaticText(this, wxID_ANY, from_u8(update.comment)));
}
versions->Add(flex);
if (! update.changelog_url.empty()) {
auto *line = new wxBoxSizer(wxHORIZONTAL);
auto changelog_url = (boost::format(update.changelog_url) % lang_code).str();
line->AddSpacer(3*VERT_SPACING);
line->Add(new wxHyperlinkCtrl(this, wxID_ANY, _(L("Open changelog page")), changelog_url));
versions->Add(line);
}
} }
content_sizer->Add(versions); content_sizer->Add(versions);

View File

@ -3,6 +3,7 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <vector>
#include "slic3r/Utils/Semver.hpp" #include "slic3r/Utils/Semver.hpp"
#include "MsgDialog.hpp" #include "MsgDialog.hpp"
@ -40,8 +41,22 @@ private:
class MsgUpdateConfig : public MsgDialog class MsgUpdateConfig : public MsgDialog
{ {
public: public:
// updates is a map of "vendor name" -> "version (comment)" struct Update
MsgUpdateConfig(const std::unordered_map<std::string, std::string> &updates); {
std::string vendor;
Semver version;
std::string comment;
std::string changelog_url;
Update(std::string vendor, Semver version, std::string comment, std::string changelog_url)
: vendor(std::move(vendor))
, version(std::move(version))
, comment(std::move(comment))
, changelog_url(std::move(changelog_url))
{}
};
MsgUpdateConfig(const std::vector<Update> &updates);
MsgUpdateConfig(MsgUpdateConfig &&) = delete; MsgUpdateConfig(MsgUpdateConfig &&) = delete;
MsgUpdateConfig(const MsgUpdateConfig &) = delete; MsgUpdateConfig(const MsgUpdateConfig &) = delete;
MsgUpdateConfig &operator=(MsgUpdateConfig &&) = delete; MsgUpdateConfig &operator=(MsgUpdateConfig &&) = delete;

View File

@ -50,15 +50,17 @@ struct Update
fs::path source; fs::path source;
fs::path target; fs::path target;
Version version; Version version;
std::string vendor;
std::string changelog_url;
Update(fs::path &&source, fs::path &&target, const Version &version) : Update(fs::path &&source, fs::path &&target, const Version &version, std::string vendor, std::string changelog_url)
source(std::move(source)), : source(std::move(source))
target(std::move(target)), , target(std::move(target))
version(version) , version(version)
, vendor(std::move(vendor))
, changelog_url(std::move(changelog_url))
{} {}
std::string name() const { return source.stem().string(); }
friend std::ostream& operator<<(std::ostream& os , const Update &self) { friend std::ostream& operator<<(std::ostream& os , const Update &self) {
os << "Update(" << self.source.string() << " -> " << self.target.string() << ')'; os << "Update(" << self.source.string() << " -> " << self.target.string() << ')';
return os; return os;
@ -69,14 +71,14 @@ struct Incompat
{ {
fs::path bundle; fs::path bundle;
Version version; Version version;
std::string vendor;
Incompat(fs::path &&bundle, const Version &version) : Incompat(fs::path &&bundle, const Version &version, std::string vendor)
bundle(std::move(bundle)), : bundle(std::move(bundle))
version(version) , version(version)
, vendor(std::move(vendor))
{} {}
std::string name() const { return bundle.stem().string(); }
friend std::ostream& operator<<(std::ostream& os , const Incompat &self) { friend std::ostream& operator<<(std::ostream& os , const Incompat &self) {
os << "Incompat(" << self.bundle.string() << ')'; os << "Incompat(" << self.bundle.string() << ')';
return os; return os;
@ -351,7 +353,7 @@ Updates PresetUpdater::priv::get_config_updates() const
} }
// Perform a basic load and check the version // Perform a basic load and check the version
const auto vp = VendorProfile::from_ini(bundle_path, false); auto vp = VendorProfile::from_ini(bundle_path, false);
// Getting a recommended version from the latest index, wich may have been downloaded // Getting a recommended version from the latest index, wich may have been downloaded
// from the internet, or installed / updated from the installation resources. // from the internet, or installed / updated from the installation resources.
@ -376,7 +378,7 @@ Updates PresetUpdater::priv::get_config_updates() const
if (ver_current_found && !ver_current->is_current_slic3r_supported()) { if (ver_current_found && !ver_current->is_current_slic3r_supported()) {
BOOST_LOG_TRIVIAL(warning) << "Current Slic3r incompatible with installed bundle: " << bundle_path.string(); BOOST_LOG_TRIVIAL(warning) << "Current Slic3r incompatible with installed bundle: " << bundle_path.string();
updates.incompats.emplace_back(std::move(bundle_path), *ver_current); updates.incompats.emplace_back(std::move(bundle_path), *ver_current, vp.name);
} else if (recommended->config_version > vp.config_version) { } else if (recommended->config_version > vp.config_version) {
// Config bundle update situation // Config bundle update situation
@ -406,12 +408,12 @@ Updates PresetUpdater::priv::get_config_updates() const
auto new_vp = VendorProfile::from_ini(path_src, false); auto new_vp = VendorProfile::from_ini(path_src, false);
bool found = false; bool found = false;
if (new_vp.config_version == recommended->config_version) { if (new_vp.config_version == recommended->config_version) {
updates.updates.emplace_back(std::move(path_src), std::move(bundle_path), *recommended); updates.updates.emplace_back(std::move(path_src), std::move(bundle_path), *recommended, vp.name, vp.changelog_url);
found = true; found = true;
} else if (! path_in_rsrc.empty() && fs::exists(path_in_rsrc)) { } else if (! path_in_rsrc.empty() && fs::exists(path_in_rsrc)) {
new_vp = VendorProfile::from_ini(path_in_rsrc, false); new_vp = VendorProfile::from_ini(path_in_rsrc, false);
if (new_vp.config_version == recommended->config_version) { if (new_vp.config_version == recommended->config_version) {
updates.updates.emplace_back(std::move(path_in_rsrc), std::move(bundle_path), *recommended); updates.updates.emplace_back(std::move(path_in_rsrc), std::move(bundle_path), *recommended, vp.name, vp.changelog_url);
found = true; found = true;
} }
} }
@ -560,6 +562,7 @@ void PresetUpdater::slic3r_update_notify()
p->enabled_version_check = false; p->enabled_version_check = false;
} }
} }
app_config->set("version_online_seen", ver_online_str); app_config->set("version_online_seen", ver_online_str);
} }
} }
@ -574,8 +577,6 @@ bool PresetUpdater::config_update() const
std::unordered_map<std::string, wxString> incompats_map; std::unordered_map<std::string, wxString> incompats_map;
for (const auto &incompat : updates.incompats) { for (const auto &incompat : updates.incompats) {
auto vendor = incompat.name();
const auto min_slic3r = incompat.version.min_slic3r_version; const auto min_slic3r = incompat.version.min_slic3r_version;
const auto max_slic3r = incompat.version.max_slic3r_version; const auto max_slic3r = incompat.version.max_slic3r_version;
wxString restrictions; wxString restrictions;
@ -590,7 +591,7 @@ bool PresetUpdater::config_update() const
restrictions = wxString::Format(_(L("requires max. %s")), max_slic3r.to_string()); restrictions = wxString::Format(_(L("requires max. %s")), max_slic3r.to_string());
} }
incompats_map.emplace(std::make_pair(std::move(vendor), std::move(restrictions))); incompats_map.emplace(std::make_pair(incompat.vendor, std::move(restrictions)));
} }
p->had_config_update = true; // This needs to be done before a dialog is shown because of OnIdle() + CallAfter() in Perl p->had_config_update = true; // This needs to be done before a dialog is shown because of OnIdle() + CallAfter() in Perl
@ -613,19 +614,15 @@ bool PresetUpdater::config_update() const
else if (updates.updates.size() > 0) { else if (updates.updates.size() > 0) {
BOOST_LOG_TRIVIAL(info) << boost::format("Update of %1% bundles available. Asking for confirmation ...") % updates.updates.size(); BOOST_LOG_TRIVIAL(info) << boost::format("Update of %1% bundles available. Asking for confirmation ...") % updates.updates.size();
std::unordered_map<std::string, std::string> updates_map; std::vector<GUI::MsgUpdateConfig::Update> updates_msg;
for (const auto &update : updates.updates) { for (const auto &update : updates.updates) {
auto vendor = update.name(); std::string changelog_url = update.version.config_version.prerelease() == nullptr ? update.changelog_url : std::string();
auto ver_str = update.version.config_version.to_string(); updates_msg.emplace_back(update.vendor, update.version.config_version, update.version.comment, std::move(changelog_url));
if (! update.version.comment.empty()) {
ver_str += std::string(" (") + update.version.comment + ")";
}
updates_map.emplace(std::make_pair(std::move(vendor), std::move(ver_str)));
} }
p->had_config_update = true; // Ditto, see above p->had_config_update = true; // Ditto, see above
GUI::MsgUpdateConfig dlg(std::move(updates_map)); GUI::MsgUpdateConfig dlg(updates_msg);
const auto res = dlg.ShowModal(); const auto res = dlg.ShowModal();
if (res == wxID_OK) { if (res == wxID_OK) {
@ -655,7 +652,7 @@ void PresetUpdater::install_bundles_rsrc(std::vector<std::string> bundles, bool
for (const auto &bundle : bundles) { for (const auto &bundle : bundles) {
auto path_in_rsrc = p->rsrc_path / bundle; auto path_in_rsrc = p->rsrc_path / bundle;
auto path_in_vendors = p->vendor_path / bundle; auto path_in_vendors = p->vendor_path / bundle;
updates.updates.emplace_back(std::move(path_in_rsrc), std::move(path_in_vendors), Version()); updates.updates.emplace_back(std::move(path_in_rsrc), std::move(path_in_vendors), Version(), "", "");
} }
p->perform_updates(std::move(updates), snapshot); p->perform_updates(std::move(updates), snapshot);