From 14d0e00235f73e6345d97bda9ac88a8c6ccec653 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 19 Feb 2017 10:35:15 +0000 Subject: [PATCH 1/2] wallet2_api: add updates check api --- src/wallet/api/wallet_manager.cpp | 28 ++++++++++++++++++++++++++++ src/wallet/wallet2_api.h | 3 +++ 2 files changed, 31 insertions(+) diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp index 38f24e3d9..359b57349 100644 --- a/src/wallet/api/wallet_manager.cpp +++ b/src/wallet/api/wallet_manager.cpp @@ -33,11 +33,16 @@ #include "wallet.h" #include "common_defines.h" #include "common/dns_utils.h" +#include "common/util.h" +#include "common/updates.h" +#include "version.h" #include "net/http_client.h" #include #include +#undef MONERO_DEFAULT_LOG_CATEGORY +#define MONERO_DEFAULT_LOG_CATEGORY "WalletAPI" namespace epee { unsigned int g_test_dbg_lock_sleep = 0; @@ -443,6 +448,29 @@ std::string WalletManagerImpl::resolveOpenAlias(const std::string &address, bool return addresses.front(); } +std::tuple WalletManager::checkUpdates(const std::string &software, const std::string &subdir) +{ +#ifdef BUILD_TAG + static const char buildtag[] = BOOST_PP_STRINGIZE(BUILD_TAG); +#else + static const char buildtag[] = "source"; +#endif + + std::string version, hash; + MDEBUG("Checking for a new " << software << " version for " << buildtag); + if (!tools::check_updates(software, buildtag, version, hash)) + return std::make_tuple(false, "", "", "", ""); + + if (tools::vercmp(version.c_str(), MONERO_VERSION) > 0) + { + std::string user_url = tools::get_update_url(software, subdir, buildtag, version, true); + std::string auto_url = tools::get_update_url(software, subdir, buildtag, version, false); + MGINFO("Version " << version << " of " << software << " for " << buildtag << " is available: " << user_url << ", SHA256 hash " << hash); + return std::make_tuple(true, version, hash, user_url, auto_url); + } + return std::make_tuple(false, "", "", "", ""); +} + ///////////////////// WalletManagerFactory implementation ////////////////////// WalletManager *WalletManagerFactory::getWalletManager() diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h index 3a819444a..eec4f8b8f 100644 --- a/src/wallet/wallet2_api.h +++ b/src/wallet/wallet2_api.h @@ -703,6 +703,9 @@ struct WalletManager //! resolves an OpenAlias address to a monero address virtual std::string resolveOpenAlias(const std::string &address, bool &dnssec_valid) const = 0; + + //! checks for an update and returns version, hash and url + static std::tuple checkUpdates(const std::string &software, const std::string &subdir); }; From ada0e23a84f728477bc4dfe4b0ee92d936a9e983 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 22 Feb 2017 13:04:07 +0000 Subject: [PATCH 2/2] updates: fix user/auto url split --- src/common/updates.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/updates.cpp b/src/common/updates.cpp index 8878bb062..5b1acf5fa 100644 --- a/src/common/updates.cpp +++ b/src/common/updates.cpp @@ -97,7 +97,7 @@ namespace tools std::string get_update_url(const std::string &software, const std::string &subdir, const std::string &buildtag, const std::string &version, bool user) { - static const char *base = user ? "https://downloads.getmonero.org/" : "http://updates.getmonero.org/"; + const char *base = user ? "https://downloads.getmonero.org/" : "http://updates.getmonero.org/"; #ifdef _WIN32 static const char extension[] = ".zip"; #else