diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/newview/hippoUpdate.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/linden/indra/newview/hippoUpdate.cpp b/linden/indra/newview/hippoUpdate.cpp new file mode 100644 index 0000000..7a33487 --- /dev/null +++ b/linden/indra/newview/hippoUpdate.cpp | |||
@@ -0,0 +1,92 @@ | |||
1 | |||
2 | #include "hippoUpdate.h" | ||
3 | |||
4 | #include <cstdio> | ||
5 | #include <list> | ||
6 | #include <vector> | ||
7 | |||
8 | #include <stdtypes.h> | ||
9 | #include <llhttpclient.h> | ||
10 | #include <llmemory.h> | ||
11 | #include <llversionviewer.h> | ||
12 | #include "llviewercontrol.h" | ||
13 | #include "llviewernetwork.h" | ||
14 | #include "llweb.h" | ||
15 | #include <llwindow.h> | ||
16 | |||
17 | |||
18 | std::string gHippoChannel; | ||
19 | |||
20 | |||
21 | // static | ||
22 | bool HippoUpdate::checkUpdate() | ||
23 | { | ||
24 | llinfos << "Hippo Update Check..." << llendl; | ||
25 | |||
26 | // get channel name | ||
27 | gHippoChannel = gSavedSettings.getString("ChannelName"); | ||
28 | |||
29 | // get mac address | ||
30 | char macAddress[18]; | ||
31 | sprintf(macAddress, "%02x:%02x:%02x:%02x:%02x:%02x", | ||
32 | gMACAddress[0], gMACAddress[1], gMACAddress[2], gMACAddress[3], gMACAddress[4], gMACAddress[5]); | ||
33 | |||
34 | // build URL for update check | ||
35 | char url[1000]; | ||
36 | snprintf(url, 1000, | ||
37 | /* "http://update.mjm.game-host.org/os/viewer.php?" | ||
38 | "product=%s&channel=%s&" | ||
39 | "version_major=%d&version_minor=%d&version_patch=%d&version_base=%s&" | ||
40 | "platform=%s&mac=%s", | ||
41 | LL_PRODUCT, LL_CHANNEL_CSTR, | ||
42 | LL_VERSION_MAJOR, LL_VERSION_MINOR, LL_VERSION_PATCH, LL_VERSION_BASE, | ||
43 | LL_PLATFORM*/"", macAddress); | ||
44 | |||
45 | // query update server | ||
46 | std::string escaped_url = LLWeb::escapeURL(url); | ||
47 | LLSD response = LLHTTPClient::blockingGet(escaped_url.c_str()); | ||
48 | |||
49 | // check response, return on error | ||
50 | S32 status = response["status"].asInteger(); | ||
51 | if ((status != 200) || !response["body"].isMap()) { | ||
52 | llinfos << "Hippo Update failed (" << status << "): " | ||
53 | << (response["body"].isString()? response["body"].asString(): "<unknown error>") | ||
54 | << llendl; | ||
55 | return true; | ||
56 | } | ||
57 | |||
58 | // get data from response | ||
59 | LLSD data = response["body"]; | ||
60 | std::string webpage = (data.has("webpage") && data["webpage"].isString())? data["webpage"].asString(): ""; | ||
61 | std::string message = (data.has("message") && data["message"].isString())? data["message"].asString(): ""; | ||
62 | std::string yourVersion = (data.has("yourVersion") && data["yourVersion"].isString())? data["yourVersion"].asString(): ""; | ||
63 | std::string curVersion = (data.has("curVersion") && data["curVersion"].isString())? data["curVersion"].asString(): ""; | ||
64 | bool update = (data.has("update") && data["update"].isBoolean())? data["update"].asBoolean(): false; | ||
65 | bool mandatory = (data.has("mandatory") && data["mandatory"].isBoolean())? data["mandatory"].asBoolean(): false; | ||
66 | |||
67 | // log and return, if no update available | ||
68 | llinfos << "Your version is " << yourVersion << ", current version is " << curVersion << '.' << llendl; | ||
69 | if (!update) return true; | ||
70 | llinfos << "Update is " << (mandatory? "mandatory.": "optional.") << llendl; | ||
71 | |||
72 | // show update dialog | ||
73 | char msg[1000]; | ||
74 | snprintf(msg, 1000, | ||
75 | "There is a new viewer version available.\n" | ||
76 | "\n" | ||
77 | "Your version: %s\n" | ||
78 | "Current version: %s\n" | ||
79 | "%s\n" | ||
80 | "Do you want to visit the web site?", | ||
81 | yourVersion.c_str(), curVersion.c_str(), | ||
82 | mandatory? "\nThis is a mandatory update.\n": ""); | ||
83 | S32 button = OSMessageBox(msg, "Hippo OpenSim Viewer Update", OSMB_YESNO); | ||
84 | if (button == OSBTN_YES) { | ||
85 | llinfos << "Taking user to " << webpage << llendl; | ||
86 | LLWeb::loadURLExternal(webpage); | ||
87 | // exit the viewer | ||
88 | return false; | ||
89 | } | ||
90 | |||
91 | return !mandatory; | ||
92 | } | ||