Skip to content
Extraits de code Groupes Projets
Valider 4fc08f94 rédigé par Niels Martin Hansen's avatar Niels Martin Hansen
Parcourir les fichiers

Write a new HTTP client for the update checker for Mac builds, to avoid the...

Write a new HTTP client for the update checker for Mac builds, to avoid the problems the wx one causes. Fixes #1197 by the virtue of no longer depending on wxHTTP.

Originally committed to SVN as r5993.
parent 6a37e0c1
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -48,6 +48,12 @@ ...@@ -48,6 +48,12 @@
#include <winsock2.h> #include <winsock2.h>
#endif #endif
#ifdef __WXMAC__
// We use a CFHTTP based implementation on Mac
#include <Carbon/Carbon.h>
#include <wx/sstream.h>
#endif
#include <wx/string.h> #include <wx/string.h>
#include <wx/event.h> #include <wx/event.h>
#include <wx/thread.h> #include <wx/thread.h>
...@@ -227,7 +233,7 @@ static const wxChar * GetOSShortName() ...@@ -227,7 +233,7 @@ static const wxChar * GetOSShortName()
else else
return _T("windows"); // future proofing? I doubt we run on nt4 return _T("windows"); // future proofing? I doubt we run on nt4
} }
else if (osid & wxOS_MAC_OSX_DARWIN && osver_maj == 0x10) // yes 0x10, not decimal 10, don't ask me else if (osid & wxOS_MAC_OSX_DARWIN && osver_maj == 10) // 10 decimal, previously 0x10... sigh
{ {
// ugliest hack in the world? nah. // ugliest hack in the world? nah.
static wxChar osxstring[] = _T("osx00"); static wxChar osxstring[] = _T("osx00");
...@@ -313,58 +319,14 @@ static wxString GetSystemLanguage() ...@@ -313,58 +319,14 @@ static wxString GetSystemLanguage()
#endif #endif
void AegisubVersionCheckerThread::DoCheck() static void ProcessUpdateFileLine(const std::set<wxString> &accept_tags, AegisubVersionCheckResultEvent &result_event, const wxString &line)
{
std::set<wxString> 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("/2.1.9");
wxString querystring = wxString::Format(
_T("?rev=%d&rel=%d&os=%s&lang=%s"),
GetSVNRevision(),
GetIsOfficialRelease()?1:0,
GetOSShortName(),
GetSystemLanguage().c_str());
wxString path = base_updates_path + querystring;
wxHTTP http;
http.SetHeader(_T("Connection"), _T("Close"));
http.SetFlags(wxSOCKET_WAITALL|wxSOCKET_BLOCK);
if (!http.Connect(servername))
throw VersionCheckError(_("Could not connect to updates server."));
std::auto_ptr<wxInputStream> stream(http.GetInputStream(path));
if (stream.get() == 0) // check for null-pointer
throw VersionCheckError(_("Could not download from updates server."));
if (http.GetResponse() < 200 || http.GetResponse() >= 300)
throw VersionCheckError(wxString::Format(_("HTTP request failed, got HTTP response %d."), http.GetResponse()));
wxTextInputStream text(*stream);
AegisubVersionCheckResultEvent result_event;
while (!stream->Eof() && stream->GetSize() > 0)
{ {
wxString line = text.ReadLine();
wxStringTokenizer tkn(line, _T("|"), wxTOKEN_RET_EMPTY_ALL); wxStringTokenizer tkn(line, _T("|"), wxTOKEN_RET_EMPTY_ALL);
wxArrayString parsed; wxArrayString parsed;
while (tkn.HasMoreTokens()) { while (tkn.HasMoreTokens()) {
parsed.Add(tkn.GetNextToken()); parsed.Add(tkn.GetNextToken());
} }
if (parsed.Count() != 6) continue; if (parsed.Count() != 6) return;
wxString line_type = parsed[0]; wxString line_type = parsed[0];
wxString line_revision = parsed[1]; wxString line_revision = parsed[1];
...@@ -376,7 +338,7 @@ void AegisubVersionCheckerThread::DoCheck() ...@@ -376,7 +338,7 @@ void AegisubVersionCheckerThread::DoCheck()
if ((line_type == _T("branch") || line_type == _T("dev")) && GetIsOfficialRelease()) if ((line_type == _T("branch") || line_type == _T("dev")) && GetIsOfficialRelease())
{ {
// stable runners don't want unstable, not interesting, skip // stable runners don't want unstable, not interesting, skip
continue; return;
} }
// check if the tags match // check if the tags match
...@@ -397,7 +359,7 @@ void AegisubVersionCheckerThread::DoCheck() ...@@ -397,7 +359,7 @@ void AegisubVersionCheckerThread::DoCheck()
} }
} }
if (!accepts_all_tags) if (!accepts_all_tags)
continue; return;
} }
if (line_type == _T("upgrade") || line_type == _T("bugfix")) if (line_type == _T("upgrade") || line_type == _T("bugfix"))
...@@ -409,11 +371,11 @@ void AegisubVersionCheckerThread::DoCheck() ...@@ -409,11 +371,11 @@ void AegisubVersionCheckerThread::DoCheck()
// maybe interesting, check revision // maybe interesting, check revision
long new_revision = 0; long new_revision = 0;
if (!line_revision.ToLong(&new_revision)) continue; if (!line_revision.ToLong(&new_revision)) return;
if (new_revision <= GetSVNRevision()) if (new_revision <= GetSVNRevision())
{ {
// too old, not interesting, skip // too old, not interesting, skip
continue; return;
} }
} }
...@@ -421,6 +383,107 @@ void AegisubVersionCheckerThread::DoCheck() ...@@ -421,6 +383,107 @@ void AegisubVersionCheckerThread::DoCheck()
result_event.AddUpdate(line_url, line_friendlyname, line_description); result_event.AddUpdate(line_url, line_friendlyname, line_description);
} }
void AegisubVersionCheckerThread::DoCheck()
{
std::set<wxString> 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("/2.1.9");
wxString querystring = wxString::Format(
_T("?rev=%d&rel=%d&os=%s&lang=%s"),
GetSVNRevision(),
GetIsOfficialRelease()?1:0,
GetOSShortName(),
GetSystemLanguage().c_str());
wxString path = base_updates_path + querystring;
#ifndef __WXMAC__
wxHTTP http;
http.SetHeader(_T("Connection"), _T("Close"));
http.SetFlags(wxSOCKET_WAITALL|wxSOCKET_BLOCK);
if (!http.Connect(servername))
throw VersionCheckError(_("Could not connect to updates server."));
std::auto_ptr<wxInputStream> stream(http.GetInputStream(path));
if (stream.get() == 0) // check for null-pointer
throw VersionCheckError(_("Could not download from updates server."));
if (http.GetResponse() < 200 || http.GetResponse() >= 300)
throw VersionCheckError(wxString::Format(_("HTTP request failed, got HTTP response %d."), http.GetResponse()));
wxTextInputStream text(*stream);
AegisubVersionCheckResultEvent result_event;
while (!stream->Eof() && stream->GetSize() > 0)
{
wxString line = text.ReadLine();
ProcessUpdateFileLine(accept_tags, result_event, line);
}
#else // is __WXMAC__
CFReadStreamRef stream;
{
wxString url = wxString("http://") + servername + path;
CFStringRef cfurlstr = CFStringCreateWithCString(kCFAllocatorDefault, url.utf8_str(), kCFStringEncodingUTF8);
CFURLRef urlobj = CFURLCreateWithString(kCFAllocatorDefault, cfurlstr, 0);
CFDataRef bodyData = CFStringCreateExternalRepresentation(kCFAllocatorDefault, CFSTR(""), kCFStringEncodingUTF8, 0);
CFHTTPMessageRef httpmsg = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), urlobj, kCFHTTPVersion1_1);
CFHTTPMessageSetHeaderFieldValue(httpmsg, CFSTR("User-Agent"), CFSTR("Aegisub"));
CFHTTPMessageSetHeaderFieldValue(httpmsg, CFSTR("Connection"), CFSTR("Close"));
CFHTTPMessageSetBody(httpmsg, bodyData);
stream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, httpmsg);
CFRelease(httpmsg);
CFRelease(bodyData);
CFRelease(urlobj);
}
CFReadStreamSetProperty(stream, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue);
CFReadStreamOpen(stream);
wxString result_body;
do {
const CFIndex buffer_len = 512;
UInt8 buf[buffer_len];
CFIndex read_len = CFReadStreamRead(stream, buf, buffer_len);
if (read_len <= 0) break;
result_body += wxString(buf, wxConvUTF8, read_len);
} while (true);
CFHTTPMessageRef httpresp = (CFHTTPMessageRef)CFReadStreamCopyProperty(stream, kCFStreamPropertyHTTPResponseHeader);
AegisubVersionCheckResultEvent result_event;
int http_code = CFHTTPMessageGetResponseStatusCode(httpresp);
if (http_code >= 200 && http_code < 300)
{
wxStringInputStream strstream(result_body);
wxTextInputStream text(strstream);
while (!strstream.Eof() && strstream.GetSize() > 0)
{
wxString line = text.ReadLine();
ProcessUpdateFileLine(accept_tags, result_event, line);
}
}
else
{
throw VersionCheckError(wxString::Format(_("HTTP request failed, got HTTP response %d."), http_code));
}
CFRelease(stream);
#endif
if (result_event.GetUpdates().size() == 1) if (result_event.GetUpdates().size() == 1)
{ {
result_event.SetMainText(_("An update to Aegisub was found.")); result_event.SetMainText(_("An update to Aegisub was found."));
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter