mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-18 14:40:56 +00:00
Add support for specifying minimum kernel versions in the update manifest
This commit is contained in:
@@ -68,6 +68,32 @@ QString AutoUpdateChecker::getPlatform()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AutoUpdateChecker::compareVersion(QVector<int>& version1, QVector<int>& version2) {
|
||||||
|
for (int i = 0;; i++) {
|
||||||
|
int v1Val = 0;
|
||||||
|
int v2Val = 0;
|
||||||
|
|
||||||
|
// Treat missing decimal places as 0
|
||||||
|
if (i < version1.count()) {
|
||||||
|
v1Val = version1[i];
|
||||||
|
}
|
||||||
|
if (i < version2.count()) {
|
||||||
|
v2Val = version2[i];
|
||||||
|
}
|
||||||
|
if (i >= version1.count() && i >= version2.count()) {
|
||||||
|
// Equal versions
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (v1Val < v2Val) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (v1Val > v2Val) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AutoUpdateChecker::handleUpdateCheckRequestFinished(QNetworkReply* reply)
|
void AutoUpdateChecker::handleUpdateCheckRequestFinished(QNetworkReply* reply)
|
||||||
{
|
{
|
||||||
Q_ASSERT(reply->isFinished());
|
Q_ASSERT(reply->isFinished());
|
||||||
@@ -119,46 +145,47 @@ void AutoUpdateChecker::handleUpdateCheckRequestFinished(QNetworkReply* reply)
|
|||||||
|
|
||||||
if (updateObj["arch"] == QSysInfo::buildCpuArchitecture() &&
|
if (updateObj["arch"] == QSysInfo::buildCpuArchitecture() &&
|
||||||
updateObj["platform"] == getPlatform()) {
|
updateObj["platform"] == getPlatform()) {
|
||||||
|
|
||||||
|
// Check the kernel version minimum if one exists
|
||||||
|
if (updateObj.contains("kernel_version_at_least") && updateObj["kernel_version_at_least"].isString()) {
|
||||||
|
QVector<int> requiredVersionQuad;
|
||||||
|
QVector<int> actualVersionQuad;
|
||||||
|
|
||||||
|
QString requiredVersion = updateObj["kernel_version_at_least"].toString();
|
||||||
|
QString actualVersion = QSysInfo::kernelVersion();
|
||||||
|
parseStringToVersionQuad(requiredVersion, requiredVersionQuad);
|
||||||
|
parseStringToVersionQuad(actualVersion, actualVersionQuad);
|
||||||
|
|
||||||
|
if (compareVersion(actualVersionQuad, requiredVersionQuad) < 0) {
|
||||||
|
qDebug() << "Skipping manifest entry due to kernel version (" << actualVersion << "<" << requiredVersion << ")";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "Found update manifest match for current platform";
|
qDebug() << "Found update manifest match for current platform";
|
||||||
|
|
||||||
QString latestVersion = updateObj["version"].toString();
|
QString latestVersion = updateObj["version"].toString();
|
||||||
qDebug() << "Latest version of Moonlight for this platform is:" << latestVersion;
|
qDebug() << "Latest version of Moonlight for this platform is:" << latestVersion;
|
||||||
|
|
||||||
QVector<int> latestVersionQuad;
|
QVector<int> latestVersionQuad;
|
||||||
|
|
||||||
parseStringToVersionQuad(latestVersion, latestVersionQuad);
|
parseStringToVersionQuad(latestVersion, latestVersionQuad);
|
||||||
|
|
||||||
for (int i = 0;; i++) {
|
int res = compareVersion(m_CurrentVersionQuad, latestVersionQuad);
|
||||||
int latestVer = 0;
|
if (res < 0) {
|
||||||
int currentVer = 0;
|
// m_CurrentVersionQuad < latestVersionQuad
|
||||||
|
qDebug() << "Update available";
|
||||||
// Treat missing decimal places as 0
|
emit onUpdateAvailable(updateObj["version"].toString(),
|
||||||
if (i < latestVersionQuad.count()) {
|
updateObj["browser_url"].toString());
|
||||||
latestVer = latestVersionQuad[i];
|
return;
|
||||||
}
|
}
|
||||||
if (i < m_CurrentVersionQuad.count()) {
|
else if (res > 0) {
|
||||||
currentVer = m_CurrentVersionQuad[i];
|
qDebug() << "Update manifest version lower than current version";
|
||||||
}
|
return;
|
||||||
if (i >= latestVersionQuad.count() && i >= m_CurrentVersionQuad.count()) {
|
}
|
||||||
break;
|
else {
|
||||||
}
|
qDebug() << "Update manifest version equal to current version";
|
||||||
|
return;
|
||||||
if (currentVer < latestVer) {
|
|
||||||
qDebug() << "Update available";
|
|
||||||
|
|
||||||
emit onUpdateAvailable(updateObj["version"].toString(),
|
|
||||||
updateObj["browser_url"].toString());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (currentVer > latestVer) {
|
|
||||||
qDebug() << "Update manifest version lower than current version";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Update manifest version equal to current version";
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -166,8 +193,8 @@ void AutoUpdateChecker::handleUpdateCheckRequestFinished(QNetworkReply* reply)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qWarning() << "No entry in update manifest found for current platform: "
|
qWarning() << "No entry in update manifest found for current platform:"
|
||||||
<< QSysInfo::buildCpuArchitecture() << getPlatform();
|
<< QSysInfo::buildCpuArchitecture() << getPlatform() << QSysInfo::kernelVersion();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qWarning() << "Update checking failed with error: " << reply->error();
|
qWarning() << "Update checking failed with error: " << reply->error();
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
void parseStringToVersionQuad(QString& string, QVector<int>& version);
|
void parseStringToVersionQuad(QString& string, QVector<int>& version);
|
||||||
|
|
||||||
|
int compareVersion(QVector<int>& version1, QVector<int>& version2);
|
||||||
|
|
||||||
QString getPlatform();
|
QString getPlatform();
|
||||||
|
|
||||||
QVector<int> m_CurrentVersionQuad;
|
QVector<int> m_CurrentVersionQuad;
|
||||||
|
|||||||
Reference in New Issue
Block a user