diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-06-22 18:04:38 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-06-22 18:04:38 (GMT) |
| commit | eb52f759de6f0805865fb7f31444f2b1421b4d25 (patch) | |
| tree | 49b259400c8946a8bea84c7af3f758f86a59d976 /src/client | |
| parent | 55d90a44a8425f70b08d864570e255f4bad8ba4c (diff) | |
| download | powder-eb52f759de6f0805865fb7f31444f2b1421b4d25.zip powder-eb52f759de6f0805865fb7f31444f2b1421b4d25.tar.gz | |
Success/Failure return from Asyn Task, Prompt to visit website upon update failure
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/Client.cpp | 33 | ||||
| -rw-r--r-- | src/client/Client.h | 16 | ||||
| -rw-r--r-- | src/client/HTTP.cpp | 19 |
3 files changed, 47 insertions, 21 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp index ec88927..d0a7bee 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -114,7 +114,7 @@ Client::Client(): stampsLib.close(); //Begin version check - versionCheckRequest = http_async_req_start(NULL, SERVER "/Version.json", NULL, 0, 1); + versionCheckRequest = http_async_req_start(NULL, SERVER "/Download/Version.json", NULL, 0, 1); } void Client::Tick() @@ -127,7 +127,6 @@ void Client::Tick() char * data = http_async_req_stop(versionCheckRequest, &status, &dataLength); versionCheckRequest = NULL; - notifyUpdateAvailable(); if(status != 200) { if(data) @@ -144,25 +143,42 @@ void Client::Tick() json::Object stableVersion = objDocument["Stable"]; json::Object betaVersion = objDocument["Beta"]; + json::Object snapshotVersion = objDocument["Snapshot"]; json::Number stableMajor = stableVersion["Major"]; json::Number stableMinor = stableVersion["Minor"]; json::Number stableBuild = stableVersion["Build"]; + json::String stableFile = stableVersion["File"]; json::Number betaMajor = betaVersion["Major"]; json::Number betaMinor = betaVersion["Minor"]; json::Number betaBuild = betaVersion["Build"]; + json::String betaFile = betaVersion["File"]; + + json::Number snapshotMajor = snapshotVersion["Major"]; + json::Number snapshotMinor = snapshotVersion["Minor"]; + json::Number snapshotBuild = snapshotVersion["Build"]; + json::String snapshotFile = snapshotVersion["File"]; + + if(stableMajor.Value()>SAVE_VERSION || (stableMinor.Value()>MINOR_VERSION && stableMajor.Value()==SAVE_VERSION) || stableBuild.Value()>BUILD_NUM) + { + updateAvailable = true; + updateInfo = UpdateInfo(stableMajor.Value(), stableMinor.Value(), stableBuild.Value(), stableFile.Value(), UpdateInfo::Stable); + } #ifdef BETA - if( (betaMajor.Value()>SAVE_VERSION || (betaMinor.Value()>MINOR_VERSION && betaMajor.Value()==SAVE_VERSION) || betaBuild.Value()>BUILD_NUM) || - (stableMajor.Value()>SAVE_VERSION || (stableMinor.Value()>MINOR_VERSION && stableMajor.Value()==SAVE_VERSION) || stableBuild.Value()>BUILD_NUM)) + if(betaMajor.Value()>SAVE_VERSION || (betaMinor.Value()>MINOR_VERSION && betaMajor.Value()==SAVE_VERSION) || betaBuild.Value()>BUILD_NUM) { updateAvailable = true; + updateInfo = UpdateInfo(betaMajor.Value(), betaMinor.Value(), betaBuild.Value(), betaFile.Value(), UpdateInfo::Beta); } -#else - if(stableMajor.Value()>SAVE_VERSION || (stableMinor.Value()>MINOR_VERSION && stableMajor.Value()==SAVE_VERSION) || stableBuild.Value()>BUILD_NUM) +#endif + +#ifdef SNAPSHOT + if(snapshotMajor.Value()>SAVE_VERSION || (snapshotMinor.Value()>MINOR_VERSION && snapshotMajor.Value()==SAVE_VERSION) || snapshotBuild.Value()>BUILD_NUM) { updateAvailable = true; + updateInfo = UpdateInfo(snapshotMajor.Value(), snapshotMinor.Value(), snapshotBuild.Value(), snapshotFile.Value(), UpdateInfo::Snapshot); } #endif @@ -182,6 +198,11 @@ void Client::Tick() } } +UpdateInfo Client::GetUpdateInfo() +{ + return updateInfo; +} + void Client::notifyUpdateAvailable() { for (std::vector<ClientListener*>::iterator iterator = listeners.begin(), end = listeners.end(); iterator != end; ++iterator) diff --git a/src/client/Client.h b/src/client/Client.h index 8c1fae7..b2822d4 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -27,11 +27,25 @@ enum RequestStatus { RequestOkay, RequestFailure }; +class UpdateInfo +{ +public: + enum BuildType { Stable, Beta, Snapshot }; + std::string File; + int Major; + int Minor; + int Build; + BuildType Type; + UpdateInfo() : Major(0), Minor(0), Build(0), File(""), Type(Stable) {} + UpdateInfo(int major, int minor, int build, std::string file, BuildType type) : Major(major), Minor(minor), Build(build), File(file), Type(type) {} +}; + class ClientListener; class Client: public Singleton<Client> { private: void * versionCheckRequest; bool updateAvailable; + UpdateInfo updateInfo; std::string lastError; @@ -59,6 +73,8 @@ private: public: vector<ClientListener*> listeners; + UpdateInfo GetUpdateInfo(); + Client(); ~Client(); diff --git a/src/client/HTTP.cpp b/src/client/HTTP.cpp index a8e5764..d622a81 100644 --- a/src/client/HTTP.cpp +++ b/src/client/HTTP.cpp @@ -468,7 +468,7 @@ int http_async_req_status(void *ctx) if (cx->txdl) { // generate POST - cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 121 + 128 + cx->txdl + cx->thlen); + cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 141 + 128 + cx->txdl + cx->thlen); cx->tptr = 0; cx->tlen = 0; cx->tlen += sprintf(cx->tbuf+cx->tlen, "POST %s HTTP/1.1\n", cx->path); @@ -484,12 +484,7 @@ int http_async_req_status(void *ctx) cx->thlen = 0; } cx->tlen += sprintf(cx->tbuf+cx->tlen, "Content-Length: %d\n", cx->txdl); - cx->tlen += sprintf(cx->tbuf+cx->tlen, "User-Agent: PowderToy/%d.%d (%s; M%d) TPTPP/%s%d.%d.%d%s\n", SAVE_VERSION, MINOR_VERSION, IDENT_PLATFORM, 0, IDENT_VERSION, SAVE_VERSION, MINOR_VERSION, BUILD_NUM, IDENT_RELTYPE); -//#ifdef BETA -// cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION); -//#else -// cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION); -//#endif + cx->tlen += sprintf(cx->tbuf+cx->tlen, "User-Agent: PowderToy/%d.%d (%s; %s; M%d) TPTPP/%d.%d.%d%s\n", SAVE_VERSION, MINOR_VERSION, IDENT_PLATFORM, IDENT_BUILD, 0, SAVE_VERSION, MINOR_VERSION, BUILD_NUM, IDENT_RELTYPE); cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n"); memcpy(cx->tbuf+cx->tlen, cx->txd, cx->txdl); cx->tlen += cx->txdl; @@ -500,7 +495,7 @@ int http_async_req_status(void *ctx) else { // generate GET - cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 89 + 128 + cx->thlen); + cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 100 + 128 + cx->thlen); cx->tptr = 0; cx->tlen = 0; cx->tlen += sprintf(cx->tbuf+cx->tlen, "GET %s HTTP/1.1\n", cx->path); @@ -515,13 +510,7 @@ int http_async_req_status(void *ctx) } if (!cx->keep) cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\n"); - cx->tlen += sprintf(cx->tbuf+cx->tlen, "User-Agent: PowderToy/%d.%d (%s; M%d) TPTPP/%s%d.%d.%d%s\n", SAVE_VERSION, MINOR_VERSION, IDENT_PLATFORM, 0, IDENT_VERSION, SAVE_VERSION, MINOR_VERSION, BUILD_NUM, IDENT_RELTYPE); - -/*#ifdef BETA - cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION); -#else - cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION); -#endif*/ + cx->tlen += sprintf(cx->tbuf+cx->tlen, "User-Agent: PowderToy/%d.%d (%s; %s; M%d) TPTPP/%d.%d.%d%s\n", SAVE_VERSION, MINOR_VERSION, IDENT_PLATFORM, IDENT_BUILD, 0, SAVE_VERSION, MINOR_VERSION, BUILD_NUM, IDENT_RELTYPE); cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n"); } cx->state = HTS_XMIT; |
