From 7ca9b991b632fa191d07ed18cd61a2f55a4c1675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Thu, 9 Jun 2022 19:01:22 +0200 Subject: [PATCH] Add limited support for (#244) Parse and don't allow skipping updates if present. The code recognizes both inside (Sparkle 1 way) and in scope (Sparkle 2). This does not parse the specific version string embedded in the criticalUpdate tag. The UI prevents the user from skipping the update or choosing to be reminded later, but isn't outright user hostile and doesn't prevent them from closing the window. That's because we don't know the circumstance - the user may e.g. be doing something urgent at the moment. Co-authored-by: Edwin Clement --- src/appcast.cpp | 6 ++++++ src/appcast.h | 4 ++++ src/ui.cpp | 34 +++++++++++++++++++--------------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/appcast.cpp b/src/appcast.cpp index 1dad7fa7..40c3c5e3 100644 --- a/src/appcast.cpp +++ b/src/appcast.cpp @@ -56,6 +56,7 @@ namespace #define NODE_LINK "link" #define NODE_ENCLOSURE "enclosure" #define NODE_MIN_OS_VERSION NS_SPARKLE_NAME("minimumSystemVersion") +#define NODE_CRITICAL_UPDATE NS_SPARKLE_NAME("criticalUpdate") #define ATTR_URL "url" #define ATTR_VERSION NS_SPARKLE_NAME("version") #define ATTR_SHORTVERSION NS_SPARKLE_NAME("shortVersionString") @@ -180,6 +181,11 @@ void XMLCALL OnStartElement(void *data, const char *name, const char **attrs) ctxt.items[size-1].InstallerArguments = value; } } + else if (strcmp(name, NODE_CRITICAL_UPDATE) == 0) + { + if (!ctxt.items.empty()) + ctxt.items.back().CriticalUpdate = true; + } } } diff --git a/src/appcast.h b/src/appcast.h index 99dfadc6..d9127c76 100644 --- a/src/appcast.h +++ b/src/appcast.h @@ -67,6 +67,10 @@ struct Appcast // Arguments passed on the the updater executable std::string InstallerArguments; + // CriticalUpdate? + bool CriticalUpdate = false; + + /** Initializes the struct with data from XML appcast feed. diff --git a/src/ui.cpp b/src/ui.cpp index 0b679cb8..447a5fe0 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -457,6 +457,8 @@ class UpdateDialog : public WinSparkleDialog wxStaticText *m_message; wxGauge *m_progress; wxStaticText *m_progressLabel; + wxButton *m_skipVersionButton; + wxButton *m_remindLaterButton; wxButton *m_closeButton; wxSizer *m_closeButtonSizer; wxButton *m_runInstallerButton; @@ -533,23 +535,15 @@ UpdateDialog::UpdateDialog() m_buttonSizer = new wxBoxSizer(wxHORIZONTAL); + m_skipVersionButton = new wxButton(this, ID_SKIP_VERSION, _("Skip this version")); + m_remindLaterButton = new wxButton(this, ID_REMIND_LATER, _("Remind me later")); + m_installButton = new wxButton(this, ID_INSTALL, _("Install update")); + m_updateButtonsSizer = new wxBoxSizer(wxHORIZONTAL); - m_updateButtonsSizer->Add - ( - new wxButton(this, ID_SKIP_VERSION, _("Skip this version")), - wxSizerFlags().Border(wxRIGHT, PX(20)) - ); + m_updateButtonsSizer->Add(m_skipVersionButton, wxSizerFlags().Border(wxRIGHT, PX(20))); m_updateButtonsSizer->AddStretchSpacer(1); - m_updateButtonsSizer->Add - ( - new wxButton(this, ID_REMIND_LATER, _("Remind me later")), - wxSizerFlags().Border(wxRIGHT, PX(10)) - ); - m_updateButtonsSizer->Add - ( - m_installButton = new wxButton(this, ID_INSTALL, _("Install update")), - wxSizerFlags() - ); + m_updateButtonsSizer->Add(m_remindLaterButton, wxSizerFlags().Border(wxRIGHT, PX(10))); + m_updateButtonsSizer->Add(m_installButton, wxSizerFlags()); m_buttonSizer->Add(m_updateButtonsSizer, wxSizerFlags(1)); m_closeButtonSizer = new wxBoxSizer(wxHORIZONTAL); @@ -895,6 +889,16 @@ void UpdateDialog::StateUpdateAvailable(const Appcast& info, bool installAutomat HIDE(m_closeButtonSizer); HIDE(m_runInstallerButtonSizer); SHOW(m_updateButtonsSizer); + if (info.CriticalUpdate) + { + HIDE(m_skipVersionButton); + HIDE(m_remindLaterButton); + } + else + { + SHOW(m_skipVersionButton); + SHOW(m_remindLaterButton); + } DoShowElement(m_releaseNotesSizer, showRelnotes); MakeResizable(showRelnotes); }