Use curl to fetch updates on OS X

The update checker sometimes triggers crashes on startup on OS X when
trying to release the CFSocket, so hopefully sidestep whatever the issue
is by just using curl to retrieve the update list.

Originally committed to SVN as r6929.
This commit is contained in:
Thomas Goyne 2012-07-05 23:05:37 +00:00
parent 3dc9e4fbea
commit 8244271508
1 changed files with 41 additions and 1 deletions

View File

@ -72,6 +72,8 @@
#include <vector> #include <vector>
#endif #endif
#include <wx/sstream.h>
#include "compat.h" #include "compat.h"
#include "main.h" #include "main.h"
#include "string_codec.h" #include "string_codec.h"
@ -154,8 +156,10 @@ AegisubVersionCheckerThread::AegisubVersionCheckerThread(bool interactive)
{ {
register_event_handler(); register_event_handler();
#ifndef __APPLE__
if (!wxSocketBase::IsInitialized()) if (!wxSocketBase::IsInitialized())
wxSocketBase::Initialize(); wxSocketBase::Initialize();
#endif
Create(); Create();
Run(); Run();
@ -327,6 +331,42 @@ void AegisubVersionCheckerThread::DoCheck()
inserter(accept_tags, accept_tags.end())); inserter(accept_tags, accept_tags.end()));
#endif #endif
#ifdef __APPLE__
wxString cmd = wxString::Format(
"curl --silent --fail 'http://%s/%s?rev=%d&rel=%d&os=%s&lang=%s'",
UPDATE_CHECKER_SERVER,
UPDATE_CHECKER_BASE_URL,
GetSVNRevision(),
GetIsOfficialRelease()?1:0,
GetOSShortName(),
GetSystemLanguage());
// wxExecute only works on the main thread so use popen instead
char buf[1024];
FILE *pipe = popen(cmd.utf8_str(), "r");
if (!pipe)
throw VersionCheckError("Could not run curl");
wxString update_str;
while(fgets(buf, sizeof(buf), pipe))
update_str += buf;
int ret = pclose(pipe);
switch (ret)
{
case 0:
break;
case 6:
case 7:
throw VersionCheckError(STD_STR(_("Could not connect to updates server.")));
case 22:
throw VersionCheckError(STD_STR(_("Could not download from updates server.")));
default:
throw VersionCheckError(STD_STR(wxString::Format("curl failed with error code %d", ret)));
}
agi::scoped_ptr<wxStringInputStream> stream(new wxStringInputStream(update_str));
#else
wxString path = wxString::Format( wxString path = wxString::Format(
"%s?rev=%d&rel=%d&os=%s&lang=%s", "%s?rev=%d&rel=%d&os=%s&lang=%s",
UPDATE_CHECKER_BASE_URL, UPDATE_CHECKER_BASE_URL,
@ -350,7 +390,7 @@ void AegisubVersionCheckerThread::DoCheck()
if (http.GetResponse() < 200 || http.GetResponse() >= 300) { if (http.GetResponse() < 200 || http.GetResponse() >= 300) {
throw VersionCheckError(STD_STR(wxString::Format(_("HTTP request failed, got HTTP response %d."), http.GetResponse()))); throw VersionCheckError(STD_STR(wxString::Format(_("HTTP request failed, got HTTP response %d."), http.GetResponse())));
} }
#endif
wxTextInputStream text(*stream); wxTextInputStream text(*stream);
AegisubVersionCheckResultEvent result_event; AegisubVersionCheckResultEvent result_event;