Make wxUpdCheckThread::wxResult scoped enum

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2020-02-12 12:35:25 +01:00
parent de9535b961
commit e2cf7d09f8
3 changed files with 23 additions and 22 deletions

View File

@ -38,6 +38,7 @@ int CALLBACK WinMain(_In_ HINSTANCE hInstance, _In_ HINSTANCE hPrevInstance, _In
// Initialize locale. // Initialize locale.
wxLocale locale; wxLocale locale;
#pragma warning(suppress: 26812) // wxLanguage is unscoped
wxLanguage lang_ui; wxLanguage lang_ui;
if (wxInitializeLocale(locale, &lang_ui)) { if (wxInitializeLocale(locale, &lang_ui)) {
// Do not add translation catalog, to keep log messages in English. // Do not add translation catalog, to keep log messages in English.
@ -60,8 +61,8 @@ int CALLBACK WinMain(_In_ HINSTANCE hInstance, _In_ HINSTANCE hPrevInstance, _In
wxUpdCheckThread worker(lang_ui == wxLANGUAGE_DEFAULT ? wxT("en_US") : wxLocale::GetLanguageCanonicalName(lang_ui)); wxUpdCheckThread worker(lang_ui == wxLANGUAGE_DEFAULT ? wxT("en_US") : wxLocale::GetLanguageCanonicalName(lang_ui));
wxUpdCheckThread::wxResult res = worker.CheckForUpdate(); wxUpdCheckThread::wxResult res = worker.CheckForUpdate();
switch (res) { switch (res) {
case wxUpdCheckThread::wxUpdUpdateAvailable: return worker.LaunchUpdate(NULL, true) ? 0 : 1; case wxUpdCheckThread::wxResult::UpdateAvailable: return worker.LaunchUpdate(NULL, true) ? 0 : 1;
case wxUpdCheckThread::wxUpdUpToDate : return 0; case wxUpdCheckThread::wxResult::UpToDate : return 0;
default : return res; default : return static_cast<int>(res);
} }
} }

View File

@ -49,14 +49,14 @@ public:
/// ///
/// Thread exit codes /// Thread exit codes
/// ///
enum wxResult { enum class wxResult {
wxUpdUninitialized = -1, ///< Initialization failed Uninitialized = -1, ///< Initialization failed
wxUpdAborted = -2, ///< Thread aborted Aborted = -2, ///< Thread aborted
wxUpdRepoUnavailable = -3, ///< No update package information available RepoUnavailable = -3, ///< No update package information available
wxUpdPkgUnavailable = -4, ///< Update package not available PkgUnavailable = -4, ///< Update package not available
wxUpdUpdateAvailable = 0, ///< Update downloaded, verified and prepared to install UpdateAvailable = 0, ///< Update downloaded, verified and prepared to install
wxUpdUpToDate, ///< Product is up-to-date UpToDate, ///< Product is up-to-date
}; };
wxUpdCheckThread(const wxString &langId, wxEvtHandler *parent = NULL); wxUpdCheckThread(const wxString &langId, wxEvtHandler *parent = NULL);

View File

@ -78,7 +78,7 @@ wxThread::ExitCode wxUpdCheckThread::Entry()
// NOTE: here we assume that using the m_parent pointer is safe, // NOTE: here we assume that using the m_parent pointer is safe,
// (in this case this is assured by the wxZRColaCharSelect destructor) // (in this case this is assured by the wxZRColaCharSelect destructor)
wxThreadEvent *e = new wxThreadEvent(wxEVT_UPDATER_CHECK_COMPLETE); wxThreadEvent *e = new wxThreadEvent(wxEVT_UPDATER_CHECK_COMPLETE);
e->SetInt(result); e->SetInt(static_cast<int>(result));
wxQueueEvent(m_parent, e); wxQueueEvent(m_parent, e);
} }
@ -95,35 +95,35 @@ bool wxUpdCheckThread::TestDestroy()
wxUpdCheckThread::wxResult wxUpdCheckThread::DoCheckForUpdate() wxUpdCheckThread::wxResult wxUpdCheckThread::DoCheckForUpdate()
{ {
if (!m_ok) if (!m_ok)
return wxUpdUninitialized; return wxResult::Uninitialized;
// Download update catalogue. // Download update catalogue.
if (TestDestroy()) return wxUpdAborted; if (TestDestroy()) return wxResult::Aborted;
wxScopedPtr<wxXmlDocument> doc(GetCatalogue()); wxScopedPtr<wxXmlDocument> doc(GetCatalogue());
if (doc) { if (doc) {
// Parse the update catalogue to check for an update package availability. // Parse the update catalogue to check for an update package availability.
if (TestDestroy()) return wxUpdAborted; if (TestDestroy()) return wxResult::Aborted;
if (ParseCatalogue(*doc)) { if (ParseCatalogue(*doc)) {
// Save update package meta-information for the next time. // Save update package meta-information for the next time.
if (TestDestroy()) return wxUpdAborted; if (TestDestroy()) return wxResult::Aborted;
WriteUpdatePackageMeta(); WriteUpdatePackageMeta();
} else { } else {
wxLogStatus(_("Update check complete. Your product is up to date.")); wxLogStatus(_("Update check complete. Your product is up to date."));
WriteUpdatePackageMeta(); WriteUpdatePackageMeta();
return wxUpdUpToDate; return wxResult::UpToDate;
} }
} else { } else {
// Update download catalogue failed, or repository database didn't change. Read a cached version of update package meta-information? // Update download catalogue failed, or repository database didn't change. Read a cached version of update package meta-information?
if (TestDestroy()) return wxUpdAborted; if (TestDestroy()) return wxResult::Aborted;
if (!ReadUpdatePackageMeta()) { if (!ReadUpdatePackageMeta()) {
// Reset CatalogueLastModified to force update catalogue download next time. // Reset CatalogueLastModified to force update catalogue download next time.
m_config.DeleteEntry(wxT("CatalogueLastModified"), false); m_config.DeleteEntry(wxT("CatalogueLastModified"), false);
return wxUpdRepoUnavailable; return wxResult::RepoUnavailable;
} }
if (m_version <= PRODUCT_VERSION) { if (m_version <= PRODUCT_VERSION) {
wxLogStatus(_("Update check complete. Your product is up to date.")); wxLogStatus(_("Update check complete. Your product is up to date."));
return wxUpdUpToDate; return wxResult::UpToDate;
} }
} }
@ -132,11 +132,11 @@ wxUpdCheckThread::wxResult wxUpdCheckThread::DoCheckForUpdate()
m_fileName += m_versionStr; m_fileName += m_versionStr;
m_fileName += wxT(".msi"); m_fileName += wxT(".msi");
if (TestDestroy()) return wxUpdAborted; if (TestDestroy()) return wxResult::Aborted;
if (!DownloadUpdatePackage()) if (!DownloadUpdatePackage())
return wxUpdPkgUnavailable; return wxResult::PkgUnavailable;
return wxUpdUpdateAvailable; return wxResult::UpdateAvailable;
} }