From 42139835d5cb0da51d49e12eff444428f1b5f195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Liru=20F=C3=A6rs?= Date: Fri, 7 Feb 2020 08:02:44 -0500 Subject: [PATCH] Redo update checker responder to be more like unstable branch --- indra/newview/shupdatechecker.cpp | 172 +++++++++++++----------------- 1 file changed, 74 insertions(+), 98 deletions(-) diff --git a/indra/newview/shupdatechecker.cpp b/indra/newview/shupdatechecker.cpp index e4582bbd4..187653d87 100644 --- a/indra/newview/shupdatechecker.cpp +++ b/indra/newview/shupdatechecker.cpp @@ -10,116 +10,95 @@ #include + +void onNotifyButtonPress(const LLSD& notification, const LLSD& response, std::string name, std::string url) +{ + S32 option = LLNotificationsUtil::getSelectedOption(notification, response); + if (option == 0) // URL + { + if (gViewerWindow) + { + gViewerWindow->getWindow()->spawnWebBrowser(LLWeb::escapeURL(url), true); + } + } +} + +void onCompleted(const LLSD& data, bool release) +{ + S32 build(LLVersionInfo::getBuild()); + std::string viewer_version = llformat("%s (%i)", LLVersionInfo::getShortVersion().c_str(), build); + +#if LL_WINDOWS + constexpr auto platform = "windows"; +#elif LL_LINUX + constexpr auto platform = "linux"; +#elif LL_DARWIN + constexpr auto platform = "apple"; +#endif + std::string recommended_version = data["recommended"][platform]; + std::string minimum_version = data["minimum"][platform]; + + S32 minimum_build, recommended_build; + sscanf(recommended_version.c_str(), "%*i.%*i.%*i (%i)", &recommended_build); + sscanf(minimum_version.c_str(), "%*i.%*i.%*i (%i)", &minimum_build); + + LL_INFOS("GetUpdateInfoResponder") << build << LL_ENDL; + LLSD args; + args["CURRENT_VER"] = viewer_version; + args["RECOMMENDED_VER"] = recommended_version; + args["MINIMUM_VER"] = minimum_version; + args["URL"] = data["url"].asString(); + args["TYPE"] = release ? "Viewer" : "Alpha"; + + static LLCachedControl lastver(release ? "SinguLastKnownReleaseBuild" : "SinguLastKnownAlphaBuild", 0); + + if (build < minimum_build || build < recommended_build) + { + if (lastver.get() < recommended_build) + { + lastver = recommended_build; + LLUI::sIgnoresGroup->setWarning("UrgentUpdateModal", true); + LLUI::sIgnoresGroup->setWarning("UrgentUpdate", true); + LLUI::sIgnoresGroup->setWarning("RecommendedUpdate", true); + } + const std::string&& notification = build < minimum_build ? + LLUI::sIgnoresGroup->getWarning("UrgentUpdateModal") ? "UrgentUpdateModal" : "UrgentUpdate" : + "RecommendedUpdate"; //build < recommended_build + LLNotificationsUtil::add(notification, args, LLSD(), boost::bind(onNotifyButtonPress, _1, _2, notification, data["url"].asString())); + } +} + extern AIHTTPTimeoutPolicy getUpdateInfoResponder_timeout; /////////////////////////////////////////////////////////////////////////////// // GetUpdateInfoResponder -class GetUpdateInfoResponder : public LLHTTPClient::ResponderWithCompleted +class GetUpdateInfoResponder final : public LLHTTPClient::ResponderWithCompleted { LOG_CLASS(GetUpdateInfoResponder); - public: - GetUpdateInfoResponder(std::string type) - : mType(type) - {} - void onNotifyButtonPress(const LLSD& notification, const LLSD& response, std::string name, std::string url) + GetUpdateInfoResponder(std::string type) : mType(type) {} + void completedRaw(LLChannelDescriptors const& channels, buffer_ptr_t const& buffer) override { - S32 option = LLNotificationsUtil::getSelectedOption(notification, response); - if (option == 0) // URL - { - std::string escaped_url = LLWeb::escapeURL(url); - if (gViewerWindow) - { - gViewerWindow->getWindow()->spawnWebBrowser(escaped_url, true); - } - } - if (option == 1) // Later - {} - } - /*virtual*/ void completedRaw(LLChannelDescriptors const& channels, buffer_ptr_t const& buffer) - { - LLBufferStream istr(channels, buffer.get()); - std::stringstream strstrm; - strstrm << istr.rdbuf(); - const std::string body = strstrm.str(); - if (mStatus != HTTP_OK) { LL_WARNS() << "Failed to get update info (" << mStatus << ")" << LL_ENDL; return; } - auto root = nlohmann::json::parse(body, nullptr, false); - if (root.is_discarded()) + LLBufferStream istr(channels, buffer.get()); + std::stringstream strstrm; + strstrm << istr.rdbuf(); + LLSD data = LlsdFromJsonString(strstrm.str()); + if (data.isUndefined()) { - LL_WARNS() << "Failed to parse json string from body:\n" << body << LL_ENDL; - return; // TODO: Should we say something here for the user? + LL_WARNS() << "Failed to parse json string from body." << LL_ENDL; + // TODO: Should we say something here for the user? } - - std::string viewer_version = llformat("%s (%i)", LLVersionInfo::getShortVersion().c_str(), LLVersionInfo::getBuild()); - - const auto data = root[mType]; -#if LL_WINDOWS - constexpr auto platform = "windows"; -#elif LL_LINUX - constexpr auto platform = "linux"; -#elif LL_DARWIN - constexpr auto platform = "apple"; -#endif - std::string recommended_version = data["recommended"][platform]; - std::string minimum_version = data["minimum"][platform]; - - S32 minimum_build, recommended_build; - sscanf(recommended_version.c_str(), "%*i.%*i.%*i (%i)", &recommended_build); - sscanf(minimum_version.c_str(), "%*i.%*i.%*i (%i)", &minimum_build); - - LL_INFOS() << LLVersionInfo::getBuild() << LL_ENDL; - LLSD args; - args["CURRENT_VER"] = viewer_version; - args["RECOMMENDED_VER"] = recommended_version; - args["MINIMUM_VER"] = minimum_version; - args["URL"] = data["url"].get(); - args["TYPE"] = mType == "release" ? "Viewer" : "Alpha"; - - static LLCachedControl sLastKnownReleaseBuild("SinguLastKnownReleaseBuild", 0); - static LLCachedControl sLastKnownAlphaBuild("SinguLastKnownAlphaBuild", 0); - - LLCachedControl& lastver = mType == "release" ? sLastKnownReleaseBuild : sLastKnownAlphaBuild; - - if (LLVersionInfo::getBuild() < minimum_build || LLVersionInfo::getBuild() < recommended_build) - { - if (lastver.get() < recommended_build) - { - lastver = recommended_build; - LLUI::sIgnoresGroup->setWarning("UrgentUpdateModal", true); - LLUI::sIgnoresGroup->setWarning("UrgentUpdate", true); - LLUI::sIgnoresGroup->setWarning("RecommendedUpdate", true); - } - std::string notificaiton; - if (LLVersionInfo::getBuild() < minimum_build) - { - if (LLUI::sIgnoresGroup->getWarning("UrgentUpdateModal")) - { - notificaiton = "UrgentUpdateModal"; - } - else - { - notificaiton = "UrgentUpdate"; - } - } - else if (LLVersionInfo::getBuild() < recommended_build) - { - notificaiton = "RecommendedUpdate"; - } - if (!notificaiton.empty()) - { - LLNotificationsUtil::add(notificaiton, args, LLSD(), boost::bind(&GetUpdateInfoResponder::onNotifyButtonPress, this, _1, _2, notificaiton, data["url"])); - } - } + else onCompleted(data[mType], mType == "release") } protected: - /*virtual*/ AIHTTPTimeoutPolicy const& getHTTPTimeoutPolicy(void) const { return getUpdateInfoResponder_timeout; } - /*virtual*/ char const* getName(void) const { return "GetUpdateInfoResponder"; } + AIHTTPTimeoutPolicy const& getHTTPTimeoutPolicy() const override { return getUpdateInfoResponder_timeout; } + char const* getName() const override { return "GetUpdateInfoResponder"; } private: std::string mType; @@ -133,18 +112,15 @@ void check_for_updates() { std::string type; auto& channel = LLVersionInfo::getChannel(); - if (channel == std::string("Singularity")) + if (channel == "Singularity") { type = "release"; } - else if (channel == std::string("Singularity Test") || channel == std::string("Singularity Alpha") || channel == "Singularity Beta") + else if (channel == "Singularity Test" || channel == "Singularity Alpha" || channel == "Singularity Beta") { type = "alpha"; } - else - { - return; - } + else return; LLHTTPClient::get(url, new GetUpdateInfoResponder(type)); } }