Commit 924283da authored by twanvl's avatar twanvl

Added the old update checker again (with #ifdef)

parent f3a680f1
...@@ -153,6 +153,9 @@ Settings::Settings() ...@@ -153,6 +153,9 @@ Settings::Settings()
, symbol_grid_size (30) , symbol_grid_size (30)
, symbol_grid (true) , symbol_grid (true)
, symbol_grid_snap (false) , 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")) , package_versions_url (_("http://magicseteditor.sourceforge.net/packages"))
, installer_list_url (_("http://magicseteditor.sourceforge.net/installers")) , installer_list_url (_("http://magicseteditor.sourceforge.net/installers"))
, check_updates (CHECK_IF_CONNECTED) , check_updates (CHECK_IF_CONNECTED)
......
...@@ -24,6 +24,9 @@ DECLARE_POINTER_TYPE(Field); ...@@ -24,6 +24,9 @@ DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Value); DECLARE_POINTER_TYPE(Value);
DECLARE_POINTER_TYPE(AutoReplace); DECLARE_POINTER_TYPE(AutoReplace);
// For now, use the old style update checker
#define USE_OLD_STYLE_UPDATE_CHECKER 1
// ----------------------------------------------------------------------------- : Extra data structures // ----------------------------------------------------------------------------- : Extra data structures
/// When to check for updates? /// When to check for updates?
...@@ -167,6 +170,9 @@ class Settings { ...@@ -167,6 +170,9 @@ class Settings {
String apprentice_location; String apprentice_location;
// --------------------------------------------------- : Update checking // --------------------------------------------------- : Update checking
#if USE_OLD_STYLE_UPDATE_CHECKER
String updates_url;
#endif
String package_versions_url; ///< latest package versions String package_versions_url; ///< latest package versions
String installer_list_url; ///< available installers String installer_list_url; ///< available installers
CheckUpdates check_updates; CheckUpdates check_updates;
......
...@@ -24,19 +24,41 @@ DECLARE_TYPEOF_COLLECTION(PackageDependencyP); ...@@ -24,19 +24,41 @@ DECLARE_TYPEOF_COLLECTION(PackageDependencyP);
// ----------------------------------------------------------------------------- : Update data // ----------------------------------------------------------------------------- : Update data
/// Information on the latest available versions #if !USE_OLD_STYLE_UPDATE_CHECKER
class VersionData : public IntrusivePtrBase<VersionData> {
/// Information on the latest available versions
class VersionData : public IntrusivePtrBase<VersionData> {
public: public:
vector<PackageDependencyP> packages; ///< Available packages + versions vector<PackageDependencyP> packages; ///< Available packages + versions
String new_updates_url; ///< updates url has moved? String new_updates_url; ///< updates url has moved?
DECLARE_REFLECTION(); DECLARE_REFLECTION();
}; };
IMPLEMENT_REFLECTION_NO_SCRIPT(VersionData) { IMPLEMENT_REFLECTION_NO_SCRIPT(VersionData) {
REFLECT_NO_SCRIPT(packages); REFLECT_NO_SCRIPT(packages);
REFLECT_NO_SCRIPT(new_updates_url); REFLECT_NO_SCRIPT(new_updates_url);
} }
#else
/// Information on the latest available version
class VersionData : public IntrusivePtrBase<VersionData> {
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 // The information for the latest version
VersionDataP update_version_data; VersionDataP update_version_data;
...@@ -48,6 +70,7 @@ volatile bool checking_updates = false; ...@@ -48,6 +70,7 @@ volatile bool checking_updates = false;
bool update_data_found() { return !!update_version_data; } bool update_data_found() { return !!update_version_data; }
bool update_available() { bool update_available() {
if (!update_version_data) return false; if (!update_version_data) return false;
#if !USE_OLD_STYLE_UPDATE_CHECKER
// updates to any installed package? // updates to any installed package?
FOR_EACH_CONST(p, update_version_data->packages) { FOR_EACH_CONST(p, update_version_data->packages) {
if (!settings.check_updates_all && p->package != mse_package) continue; if (!settings.check_updates_all && p->package != mse_package) continue;
...@@ -57,6 +80,9 @@ bool update_available() { ...@@ -57,6 +80,9 @@ bool update_available() {
} }
} }
return false; return false;
#else
return update_version_data->version > app_version;
#endif
} }
// ----------------------------------------------------------------------------- : Update checking // ----------------------------------------------------------------------------- : Update checking
...@@ -75,7 +101,12 @@ class CheckUpdateThread : public wxThread { ...@@ -75,7 +101,12 @@ class CheckUpdateThread : public wxThread {
if (checking_updates) return; // don't check multiple times simultaniously if (checking_updates) return; // don't check multiple times simultaniously
checking_updates = true; checking_updates = true;
try { 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(); wxInputStream* isP = url.GetInputStream();
if (!isP) return; // failed to get data if (!isP) return; // failed to get data
InputStreamP is(isP); InputStreamP is(isP);
...@@ -86,7 +117,7 @@ class CheckUpdateThread : public wxThread { ...@@ -86,7 +117,7 @@ class CheckUpdateThread : public wxThread {
reader.handle(version_data); reader.handle(version_data);
// has the updates url changed? // has the updates url changed?
if (!version_data->new_updates_url.empty()) { 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 // Make available
update_version_data = version_data; update_version_data = version_data;
...@@ -123,9 +154,48 @@ void check_updates_now(bool async) { ...@@ -123,9 +154,48 @@ void check_updates_now(bool async) {
// ----------------------------------------------------------------------------- : Dialog // ----------------------------------------------------------------------------- : Dialog
#if !USE_OLD_STYLE_UPDATE_CHECKER
void show_update_dialog(Window* parent) { void show_update_dialog(Window* parent) {
if (!update_available() || shown_dialog) return; // we already have the latest version, or this has already been displayed. if (!update_available() || shown_dialog) return; // we already have the latest version, or this has already been displayed.
shown_dialog = true; shown_dialog = true;
(new PackagesWindow(parent))->Show(); (new PackagesWindow(parent))->Show();
} }
// ----------------------------------------------------------------------------- : Dialog (old style)
#else // !USE_OLD_STYLE_UPDATE_CHECKER
#include <wx/html/htmlwin.h>
// 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment