Dev channel to GitHub (#2557)
This commit is contained in:
parent
6d07709174
commit
d7e5b29d41
2 changed files with 50 additions and 39 deletions
|
@ -125,7 +125,7 @@ void DlgUpdate::finishedUpdateCheck(bool needToUpdate, bool isCompatible, Releas
|
||||||
//If there is an update, save its URL and work out its name
|
//If there is an update, save its URL and work out its name
|
||||||
updateUrl = release->getDownloadUrl();
|
updateUrl = release->getDownloadUrl();
|
||||||
|
|
||||||
QMessageBox::StandardButton reply;
|
int reply;
|
||||||
reply = QMessageBox::question(this, "Update Available",
|
reply = QMessageBox::question(this, "Update Available",
|
||||||
tr("A new version is available:<br/>%1<br/>published on %2 ."
|
tr("A new version is available:<br/>%1<br/>published on %2 ."
|
||||||
"<br/>More informations are available on the <a href=\"%3\">release changelog</a>"
|
"<br/>More informations are available on the <a href=\"%3\">release changelog</a>"
|
||||||
|
|
|
@ -4,16 +4,18 @@
|
||||||
|
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
#define STABLERELEASE_URL "https://api.github.com/repos/Cockatrice/Cockatrice/releases/latest"
|
#define STABLERELEASE_URL "https://api.github.com/repos/Cockatrice/Cockatrice/releases/latest"
|
||||||
#define STABLETAG_URL "https://api.github.com/repos/Cockatrice/Cockatrice/git/refs/tags/"
|
#define STABLETAG_URL "https://api.github.com/repos/Cockatrice/Cockatrice/git/refs/tags/"
|
||||||
#define STABLEMANUALDOWNLOAD_URL "https://github.com/Cockatrice/Cockatrice/releases/latest"
|
#define STABLEMANUALDOWNLOAD_URL "https://github.com/Cockatrice/Cockatrice/releases/latest"
|
||||||
|
|
||||||
#define DEVRELEASE_URL "https://api.github.com/repos/Cockatrice/Cockatrice/commits/master"
|
#define DEVRELEASE_URL "https://api.github.com/repos/Cockatrice/Cockatrice/releases"
|
||||||
#define DEVFILES_URL "https://api.bintray.com/packages/cockatrice/Cockatrice/Cockatrice-git/files"
|
#define DEVMANUALDOWNLOAD_URL "https://github.com/Cockatrice/Cockatrice/releases/"
|
||||||
#define DEVDOWNLOAD_URL "https://dl.bintray.com/cockatrice/Cockatrice/"
|
|
||||||
#define DEVMANUALDOWNLOAD_URL "https://bintray.com/cockatrice/Cockatrice/Cockatrice-git/_latestVersion#files"
|
|
||||||
#define DEVRELEASE_DESCURL "https://github.com/Cockatrice/Cockatrice/compare/%1...%2"
|
#define DEVRELEASE_DESCURL "https://github.com/Cockatrice/Cockatrice/compare/%1...%2"
|
||||||
|
|
||||||
#define GIT_SHORT_HASH_LEN 7
|
#define GIT_SHORT_HASH_LEN 7
|
||||||
|
|
||||||
int ReleaseChannel::sharedIndex = 0;
|
int ReleaseChannel::sharedIndex = 0;
|
||||||
|
@ -66,8 +68,8 @@ bool ReleaseChannel::downloadMatchesCurrentOS(const QString &fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
auto exeName = arch + ".exe";
|
auto exeName = arch + ".exe";
|
||||||
auto exeDebugName = devSnapshotEnd + ".exe";
|
auto exeDevName = devSnapshotEnd + ".exe";
|
||||||
return (fileName.endsWith(exeName) || fileName.endsWith(exeDebugName));
|
return (fileName.endsWith(exeName) || fileName.endsWith(exeDevName));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -117,7 +119,7 @@ void StableReleaseChannel::releaseListFinished()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!lastRelease)
|
if (!lastRelease)
|
||||||
lastRelease = new Release;
|
lastRelease = new Release;
|
||||||
|
|
||||||
lastRelease->setName(resultMap["name"].toString());
|
lastRelease->setName(resultMap["name"].toString());
|
||||||
|
@ -219,63 +221,75 @@ QString DevReleaseChannel::getReleaseChannelUrl() const
|
||||||
return QString(DEVRELEASE_URL);
|
return QString(DEVRELEASE_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DevReleaseChannel::releaseListFinished()
|
void DevReleaseChannel::releaseListFinished()
|
||||||
{
|
{
|
||||||
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
|
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
|
||||||
bool ok;
|
QByteArray jsonData = reply->readAll();
|
||||||
QString tmp = QString(reply->readAll());
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
QVariantMap resultMap = QtJson::Json::parse(tmp, ok).toMap();
|
QJsonDocument doc = QJsonDocument::fromJson(jsonData);
|
||||||
if (!ok) {
|
QJsonArray array = doc.array();
|
||||||
qWarning() << "No reply received from the release update server:" << tmp;
|
|
||||||
|
/*
|
||||||
|
* Get the latest release on GitHub
|
||||||
|
* This can be either a pre-release or a published release
|
||||||
|
* depending on timing. Both are acceptable.
|
||||||
|
*/
|
||||||
|
QVariantMap resultMap = array.at(0).toObject().toVariantMap();
|
||||||
|
|
||||||
|
if (array.size() == 0 || resultMap.size() == 0) {
|
||||||
|
qWarning() << "No reply received from the release update server:" << QString(jsonData);
|
||||||
emit error(tr("No reply received from the release update server."));
|
emit error(tr("No reply received from the release update server."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(resultMap.contains("commit") &&
|
// Make sure resultMap has all elements we'll need
|
||||||
resultMap.contains("html_url") &&
|
if (!resultMap.contains("assets") ||
|
||||||
resultMap.contains("sha") &&
|
!resultMap.contains("author") ||
|
||||||
resultMap["commit"].toMap().contains("author") &&
|
!resultMap.contains("tag_name") ||
|
||||||
resultMap["commit"].toMap()["author"].toMap().contains("date"))) {
|
!resultMap.contains("target_commitish") ||
|
||||||
qWarning() << "Invalid received from the release update server:" << tmp;
|
!resultMap.contains("assets_url") ||
|
||||||
|
!resultMap.contains("created_at"))
|
||||||
|
{
|
||||||
|
qWarning() << "Invalid received from the release update server:" << resultMap;
|
||||||
emit error(tr("Invalid reply received from the release update server."));
|
emit error(tr("Invalid reply received from the release update server."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!lastRelease)
|
if (lastRelease == nullptr)
|
||||||
lastRelease = new Release;
|
lastRelease = new Release;
|
||||||
|
|
||||||
|
lastRelease->setCommitHash(resultMap["target_commitish"].toString());
|
||||||
lastRelease->setCommitHash(resultMap["sha"].toString());
|
lastRelease->setPublishDate(resultMap["created_at"].toDate());
|
||||||
lastRelease->setPublishDate(resultMap["commit"].toMap()["author"].toMap()["date"].toDate());
|
|
||||||
|
|
||||||
QString shortHash = lastRelease->getCommitHash().left(GIT_SHORT_HASH_LEN);
|
QString shortHash = lastRelease->getCommitHash().left(GIT_SHORT_HASH_LEN);
|
||||||
lastRelease->setName("Commit " + shortHash);
|
lastRelease->setName(QString("%1 (%2)").arg(resultMap["tag_name"].toString()).arg(shortHash));
|
||||||
|
|
||||||
lastRelease->setDescriptionUrl(QString(DEVRELEASE_DESCURL).arg(VERSION_COMMIT, shortHash));
|
lastRelease->setDescriptionUrl(QString(DEVRELEASE_DESCURL).arg(VERSION_COMMIT, shortHash));
|
||||||
|
|
||||||
qDebug() << "Got reply from release server, size=" << tmp.size()
|
qDebug() << "Got reply from release server, size=" << resultMap.size()
|
||||||
<< "name=" << lastRelease->getName()
|
<< "name=" << lastRelease->getName()
|
||||||
<< "desc=" << lastRelease->getDescriptionUrl()
|
<< "desc=" << lastRelease->getDescriptionUrl()
|
||||||
<< "commit=" << lastRelease->getCommitHash()
|
<< "commit=" << lastRelease->getCommitHash()
|
||||||
<< "date=" << lastRelease->getPublishDate();
|
<< "date=" << lastRelease->getPublishDate();
|
||||||
|
|
||||||
qDebug() << "Searching for a corresponding file on the dev channel: " << QString(DEVFILES_URL);
|
QString devBuildDownloadUrl = resultMap["assets_url"].toString();
|
||||||
response = netMan->get(QNetworkRequest(QString(DEVFILES_URL)));
|
|
||||||
|
qDebug() << "Searching for a corresponding file on the dev channel: " << devBuildDownloadUrl;
|
||||||
|
response = netMan->get(QNetworkRequest(devBuildDownloadUrl));
|
||||||
connect(response, SIGNAL(finished()), this, SLOT(fileListFinished()));
|
connect(response, SIGNAL(finished()), this, SLOT(fileListFinished()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevReleaseChannel::fileListFinished()
|
void DevReleaseChannel::fileListFinished()
|
||||||
{
|
{
|
||||||
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
|
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
|
||||||
bool ok;
|
QByteArray jsonData = reply->readAll();
|
||||||
QString tmp = QString(reply->readAll());
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
bool ok;
|
||||||
|
|
||||||
QVariantList resultList = QtJson::Json::parse(tmp, ok).toList();
|
QVariantList resultList = QtJson::Json::parse(jsonData, ok).toList();
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
qWarning() << "No reply received from the file update server:" << tmp;
|
qWarning() << "No reply received from the file update server:" << QString(jsonData);
|
||||||
emit error(tr("No reply received from the file update server."));
|
emit error(tr("No reply received from the file update server."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -290,20 +304,17 @@ void DevReleaseChannel::fileListFinished()
|
||||||
foreach(QVariant file, resultList)
|
foreach(QVariant file, resultList)
|
||||||
{
|
{
|
||||||
QVariantMap map = file.toMap();
|
QVariantMap map = file.toMap();
|
||||||
if(!map.contains("version"))
|
|
||||||
continue;
|
|
||||||
if(!map["version"].toString().endsWith(shortHash))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if(!downloadMatchesCurrentOS(map["build"].toString()))
|
QString url = map["browser_download_url"].toString();
|
||||||
|
|
||||||
|
if (!downloadMatchesCurrentOS(url))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
compatibleVersion = true;
|
compatibleVersion = true;
|
||||||
QString url = QString(DEVDOWNLOAD_URL) + map["path"].toString();
|
|
||||||
lastRelease->setDownloadUrl(url);
|
lastRelease->setDownloadUrl(url);
|
||||||
qDebug() << "Found compatible version url=" << url;
|
qDebug() << "Found compatible version url=" << url;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit finishedCheck(needToUpdate, compatibleVersion, lastRelease);
|
emit finishedCheck(needToUpdate, compatibleVersion, lastRelease);
|
||||||
}
|
}
|
Loading…
Reference in a new issue