Commit e2fe0b3c authored by Ashot's avatar Ashot
Browse files

Resolved merge conflict

Showing with 42 additions and 27 deletions
+42 -27
......@@ -1307,7 +1307,7 @@ void BitcoinGUI::handleRestart(QStringList args)
void BitcoinGUI::checkUpdate()
{
UpdateDialog::GetInstance()->setParent(this, Qt::Dialog);
if (updater.Check())
if (updater.GetStatus() != boost::none && updater.GetStatus())
{
UpdateDialog::GetInstance()->setCurrentVersion(QString::fromStdString(FormatVersion(CLIENT_VERSION)));
UpdateDialog::GetInstance()->setUpdateVersion(QString::fromStdString(FormatVersion(updater.GetVersion())));
......
......@@ -180,11 +180,11 @@ Value update(const Array& params, bool fHelp)
throw runtime_error("Too many parameters\n");
}
if (updater.Check() == boost::none)
if (updater.GetStatus() == boost::none)
{
throw runtime_error("An error occurred while checking for an update. \nCheck debug.log for more info.\n");
}
else if (updater.Check())
else if (updater.GetStatus())
{
// There is an update
Object obj;
......@@ -200,11 +200,11 @@ Value update(const Array& params, bool fHelp)
if (strCommand == "download")
{
if (updater.Check() == boost::none)
if (updater.GetStatus() == boost::none)
{
throw runtime_error("An error occurred while checking for an update. \nCheck debug.log for more info.\n");
}
else if (!updater.Check())
else if (!updater.GetStatus())
{
return "You are running the latest version of Crown - " + FormatVersion(CLIENT_VERSION);
}
......@@ -239,11 +239,11 @@ Value update(const Array& params, bool fHelp)
throw runtime_error("The command 'unzip' could not be found. Please install it and try again.");
}
if (updater.Check() == boost::none)
if (updater.GetStatus() == boost::none)
{
throw runtime_error("An error occurred while checking for an update. \nCheck debug.log for more info.\n");
}
else if (!updater.Check())
else if (!updater.GetStatus())
{
return "You are running the latest version of Crown - " + FormatVersion(CLIENT_VERSION);
}
......
......@@ -5,6 +5,7 @@
#include "clientversion.h"
#include "util.h"
#include "chainparams.h"
#include "rpcprotocol.h"
#include <stdio.h>
#include <curl/curl.h>
......@@ -108,27 +109,27 @@ bool Updater::LoadUpdateInfo()
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, GetUpdateData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &updateData);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
if (res == CURLE_OK)
{
jsonData = ParseJson(updateData);
version = GetVersionFromJson();
LogPrintf("Updater::GetUpdateInfo() - Got version from json: %d\n", version);
if (version > CLIENT_VERSION && NeedToBeUpdated())
if (res == CURLE_OK)
{
LogPrintf("Updater::GetUpdateInfo() - Version is old\n");
// There is an update
status = true;
long response_code;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
if (response_code == HTTP_OK)
{
CheckAndUpdateStatus(updateData);
result = true;
}
else
{
LogPrintf("Updater::GetUpdateInfo() - Error! Server response code - %d\n", response_code);
}
}
result = true;
}
else
{
LogPrintf("Updater::GetUpdateInfo() - Error! Couldn't get data json. Error code - %d\n", res);
result = false;
else
{
LogPrintf("Updater::GetUpdateInfo() - Error! Couldn't get data json. Error code - %d\n", res);
}
curl_easy_cleanup(curl);
}
return result;
}
......@@ -263,7 +264,20 @@ void Updater::StopDownload()
stopDownload = true;
}
boost::optional<bool> Updater::Check()
void Updater::CheckAndUpdateStatus(const std::string& updateData)
{
jsonData = ParseJson(updateData);
version = GetVersionFromJson();
LogPrintf("Updater::GetUpdateInfo() - Got version from json: %d\n", version);
if (version > CLIENT_VERSION && NeedToBeUpdated())
{
LogPrintf("Updater::GetUpdateInfo() - Version is old\n");
// There is an update
status = true;
}
}
boost::optional<bool> Updater::GetStatus()
{
boost::optional<bool> result = boost::none;
if (LoadUpdateInfo())
......
......@@ -31,7 +31,7 @@ public:
MAC_OS,
};
Updater();
boost::optional<bool> Check();
boost::optional<bool> GetStatus();
int GetVersion() const
{
return version;
......@@ -70,6 +70,7 @@ private:
std::string GetUrl(const Value& value);
std::string GetSha256sum(Value value);
void SetCAPath(CURL* curl);
void CheckAndUpdateStatus(const std::string& updateData);
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment