From ff34a08afd055a374e05414fd01cf6c1a2ad254c Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sat, 5 Jun 2010 20:16:30 +0000 Subject: [PATCH] Make update checker use a compile-time list of tags to determine the appropriate updates to list, instead of a hard-coded OS check. The list of accepted tags is defined by the UPDATE_CHECKER_ACCEPT_TAGS macro. If this macro is undefined, the update checker will still compile, but will reject all updates with tags. Updates #1132. Originally committed to SVN as r4440. --- aegisub/src/config/config_windows0.h | 12 +++++++ aegisub/src/dialog_version_check.cpp | 47 ++++++++++++++++++---------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/aegisub/src/config/config_windows0.h b/aegisub/src/config/config_windows0.h index 591661751..0bc6e88d7 100644 --- a/aegisub/src/config/config_windows0.h +++ b/aegisub/src/config/config_windows0.h @@ -112,6 +112,18 @@ //#define FINAL_RELEASE +// Specify tags the update checker accepts +// See for details on tags. +// Depending on who will be using your build, you may or may not want to have the +// "source" tag in here. If the string is empty, the update checker will reject any +// update offered. +#if defined(_M_IX86) +# define UPDATE_CHECKER_ACCEPT_TAGS "windows source" +#elif defined(_M_X64) +# define UPDATE_CHECKER_ACCEPT_TAGS "win64 source" +#endif + + ///////////// NOT RECOMMENDED ///////////// diff --git a/aegisub/src/dialog_version_check.cpp b/aegisub/src/dialog_version_check.cpp index 3a2143b56..636784cbc 100644 --- a/aegisub/src/dialog_version_check.cpp +++ b/aegisub/src/dialog_version_check.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include #endif @@ -323,6 +324,17 @@ static wxString GetSystemLanguage() void AegisubVersionCheckerThread::DoCheck() { + std::set accept_tags; +#ifdef UPDATE_CHECKER_ACCEPT_TAGS + { + wxStringTokenizer tk(wxString(UPDATE_CHECKER_ACCEPT_TAGS, wxConvUTF8), _T(" ")); + while (tk.HasMoreTokens()) + { + accept_tags.insert(tk.GetNextToken()); + } + } +#endif + const wxString servername = _T("updates.aegisub.org"); const wxString base_updates_path = _T("/trunk"); @@ -344,7 +356,7 @@ void AegisubVersionCheckerThread::DoCheck() std::auto_ptr stream(http.GetInputStream(path)); if (stream.get() == 0) // check for null-pointer - throw VersionCheckError("Could not connect to updates server."); + throw VersionCheckError(STD_STR(_("Could not download from updates server."))); if (http.GetResponse() < 200 || http.GetResponse() >= 300) { const std::string str_err = STD_STR(wxString::Format(_("HTTP request failed, got HTTP response %d."), http.GetResponse())); @@ -367,7 +379,7 @@ void AegisubVersionCheckerThread::DoCheck() wxString line_type = parsed[0]; wxString line_revision = parsed[1]; - wxString line_platform = parsed[2]; + wxString line_tags_str = parsed[2]; wxString line_url = inline_string_decode(parsed[3]); wxString line_friendlyname = inline_string_decode(parsed[4]); wxString line_description = inline_string_decode(parsed[5]); @@ -378,24 +390,25 @@ void AegisubVersionCheckerThread::DoCheck() continue; } - // check if the OS is right - wxOperatingSystemId osid = wxGetOsVersion(); - if (line_platform == _T("windows") && !(osid & wxOS_WINDOWS_NT)) + // check if the tags match + if (line_tags_str.IsEmpty() || line_tags_str == _T("all")) { - continue; + // looking good } - if (line_platform == _T("mac") && !(osid & wxOS_MAC_OSX_DARWIN)) + else { - continue; - } - if (line_platform == _T("source") && (osid & wxOS_WINDOWS_NT || osid & wxOS_MAC_OSX_DARWIN)) - { - // TODO: support interested-in-source-releases flag - continue; - } - if (!(line_platform == _T("windows") || line_platform == _T("mac") || line_platform == _T("source") || line_platform == _T("all"))) - { - continue; + bool accepts_all_tags = true; + wxStringTokenizer tk(line_tags_str, _T(" ")); + while (tk.HasMoreTokens()) + { + if (accept_tags.find(tk.GetNextToken()) == accept_tags.end()) + { + accepts_all_tags = false; + break; + } + } + if (!accepts_all_tags) + continue; } if (line_type == _T("upgrade") || line_type == _T("bugfix"))