From 4ad3ea818889bafc6ce0e3701c69ac31c61b2795 Mon Sep 17 00:00:00 2001 From: twanvl Date: Fri, 30 May 2008 19:34:21 +0000 Subject: [PATCH] Added the old update checker again (with #ifdef) git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@892 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/settings.cpp | 3 + src/data/settings.hpp | 6 ++ src/gui/update_checker.cpp | 114 ++++++++++++++++++++++++++++++------- 3 files changed, 101 insertions(+), 22 deletions(-) diff --git a/src/data/settings.cpp b/src/data/settings.cpp index f64e51ac..a9088c22 100644 --- a/src/data/settings.cpp +++ b/src/data/settings.cpp @@ -153,6 +153,9 @@ Settings::Settings() , symbol_grid_size (30) , symbol_grid (true) , symbol_grid_snap (false) + #if USE_OLD_STYLE_UPDATE_CHECKER + , updates_url (_("http://magicseteditor.sourceforge.net/updates")) + #endif , package_versions_url (_("http://magicseteditor.sourceforge.net/packages")) , installer_list_url (_("http://magicseteditor.sourceforge.net/installers")) , check_updates (CHECK_IF_CONNECTED) diff --git a/src/data/settings.hpp b/src/data/settings.hpp index 3fae64ea..3acb8e0b 100644 --- a/src/data/settings.hpp +++ b/src/data/settings.hpp @@ -24,6 +24,9 @@ DECLARE_POINTER_TYPE(Field); DECLARE_POINTER_TYPE(Value); DECLARE_POINTER_TYPE(AutoReplace); +// For now, use the old style update checker +#define USE_OLD_STYLE_UPDATE_CHECKER 1 + // ----------------------------------------------------------------------------- : Extra data structures /// When to check for updates? @@ -167,6 +170,9 @@ class Settings { String apprentice_location; // --------------------------------------------------- : Update checking + #if USE_OLD_STYLE_UPDATE_CHECKER + String updates_url; + #endif String package_versions_url; ///< latest package versions String installer_list_url; ///< available installers CheckUpdates check_updates; diff --git a/src/gui/update_checker.cpp b/src/gui/update_checker.cpp index c31f835d..57780ba5 100644 --- a/src/gui/update_checker.cpp +++ b/src/gui/update_checker.cpp @@ -24,19 +24,41 @@ DECLARE_TYPEOF_COLLECTION(PackageDependencyP); // ----------------------------------------------------------------------------- : Update data -/// Information on the latest available versions -class VersionData : public IntrusivePtrBase { - public: - vector packages; ///< Available packages + versions - String new_updates_url; ///< updates url has moved? - - DECLARE_REFLECTION(); -}; +#if !USE_OLD_STYLE_UPDATE_CHECKER -IMPLEMENT_REFLECTION_NO_SCRIPT(VersionData) { - REFLECT_NO_SCRIPT(packages); - REFLECT_NO_SCRIPT(new_updates_url); -} + /// Information on the latest available versions + class VersionData : public IntrusivePtrBase { + public: + vector packages; ///< Available packages + versions + String new_updates_url; ///< updates url has moved? + + DECLARE_REFLECTION(); + }; + + IMPLEMENT_REFLECTION_NO_SCRIPT(VersionData) { + REFLECT_NO_SCRIPT(packages); + REFLECT_NO_SCRIPT(new_updates_url); + } + +#else + + /// Information on the latest available version + class VersionData : public IntrusivePtrBase { + public: + Version version; ///< Latest version number of MSE + String description; ///< html description of the latest MSE release + String new_updates_url; ///< updates url has moved? + + DECLARE_REFLECTION(); + }; + + IMPLEMENT_REFLECTION(VersionData) { + REFLECT(version); + REFLECT(description); + REFLECT(new_updates_url); + } + +#endif // The information for the latest version VersionDataP update_version_data; @@ -48,15 +70,19 @@ volatile bool checking_updates = false; bool update_data_found() { return !!update_version_data; } bool update_available() { if (!update_version_data) return false; - // updates to any installed package? - FOR_EACH_CONST(p, update_version_data->packages) { - if (!settings.check_updates_all && p->package != mse_package) continue; - Version v; - if (packages.installedVersion(p->package, v) && v < p->version) { - return true; + #if !USE_OLD_STYLE_UPDATE_CHECKER + // updates to any installed package? + FOR_EACH_CONST(p, update_version_data->packages) { + if (!settings.check_updates_all && p->package != mse_package) continue; + Version v; + if (packages.installedVersion(p->package, v) && v < p->version) { + return true; + } } - } - return false; + return false; + #else + return update_version_data->version > app_version; + #endif } // ----------------------------------------------------------------------------- : Update checking @@ -75,7 +101,12 @@ class CheckUpdateThread : public wxThread { if (checking_updates) return; // don't check multiple times simultaniously checking_updates = true; try { - wxURL url(settings.package_versions_url); + #if !USE_OLD_STYLE_UPDATE_CHECKER + String& the_url = settings.package_versions_url; + #else + String& the_url = settings.updates_url; + #endif + wxURL url(the_url); wxInputStream* isP = url.GetInputStream(); if (!isP) return; // failed to get data InputStreamP is(isP); @@ -86,7 +117,7 @@ class CheckUpdateThread : public wxThread { reader.handle(version_data); // has the updates url changed? if (!version_data->new_updates_url.empty()) { - settings.package_versions_url = version_data->new_updates_url; + the_url = version_data->new_updates_url; } // Make available update_version_data = version_data; @@ -123,9 +154,48 @@ void check_updates_now(bool async) { // ----------------------------------------------------------------------------- : Dialog +#if !USE_OLD_STYLE_UPDATE_CHECKER void show_update_dialog(Window* parent) { if (!update_available() || shown_dialog) return; // we already have the latest version, or this has already been displayed. shown_dialog = true; (new PackagesWindow(parent))->Show(); } + +// ----------------------------------------------------------------------------- : Dialog (old style) +#else // !USE_OLD_STYLE_UPDATE_CHECKER + +#include + +// A HTML control that opens all pages in an actual browser +struct HtmlWindowToBrowser : public wxHtmlWindow { + HtmlWindowToBrowser(Window* parent, int id, const wxPoint& pos, const wxSize& size, long flags) + : wxHtmlWindow(parent, id, pos, size, flags) + {} + + virtual void OnLinkClicked(const wxHtmlLinkInfo& info) { + wxLaunchDefaultBrowser( info.GetHref() ); + } +}; + +void show_update_dialog(Window* parent) { + if (!update_available() || shown_dialog) return; // we already have the latest version, or this has already been displayed. + // Show update dialog + wxDialog* dlg = new wxDialog(parent, wxID_ANY, _TITLE_("updates available"), wxDefaultPosition); + // controls + wxHtmlWindow* html = new HtmlWindowToBrowser(dlg, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER); + html->SetPage(update_version_data->description); + wxButton* close = new wxButton(dlg, wxID_OK, _BUTTON_("close")); + close->SetDefault(); + // layout + wxSizer* s = new wxBoxSizer(wxVERTICAL); + s->Add(html, 1, wxEXPAND | wxALL, 8); + s->Add(close, 0, wxALIGN_RIGHT | wxALL & ~wxTOP, 8); + dlg->SetSizer(s); + dlg->SetSize(400,400); + dlg->Show(); + // And never show it again this run + shown_dialog = true; +} + +#endif // !USE_OLD_STYLE_UPDATE_CHECKER