This commit is contained in:
tooomm 2026-07-24 00:26:52 +02:00
parent 66d81e6f14
commit cc9cf9ba63
2 changed files with 27 additions and 9 deletions

View file

@ -44,13 +44,28 @@ void ReleaseChannel::checkForUpdates()
connect(response, &QNetworkReply::finished, this, &ReleaseChannel::releaseListFinished); connect(response, &QNetworkReply::finished, this, &ReleaseChannel::releaseListFinished);
} }
// Find compatible assets for host platform (Linux is not supported by in-client updater) // Find assets compatible with host platform (Linux is not supported by in-client updater)
std::optional<int> ReleaseChannel::getTargetVersionForCurrentOS(const QString &fileName) std::optional<int> ReleaseChannel::getTargetVersionForCurrentOS(const QString &fileName)
{ {
const QRegularExpression *regex = nullptr; const QRegularExpression *regex = nullptr;
static const std::optional<int> systemVersion = [] {
bool ok = false;
const QString versionString = QSysInfo::productVersion();
const int version = versionString.split('.').first().toInt(&ok);
if (!ok) {
qCWarning(ReleaseChannelLog) << "Unable to determine OS version from" << versionString;
return std::optional<int>();
}
return std::optional<int>{version};
}();
if (!systemVersion) {
return std::nullopt;
}
#if defined(Q_OS_MACOS) #if defined(Q_OS_MACOS)
const bool isIntel = [] { static const bool isIntel = [] {
// QSysInfo does not go through translation layers // QSysInfo does not go through translation layers
// We need to use sysctl to reliably detect the underlying architecture // We need to use sysctl to reliably detect the underlying architecture
char arch[255]; char arch[255];
@ -60,12 +75,16 @@ std::optional<int> ReleaseChannel::getTargetVersionForCurrentOS(const QString &f
} }
return false; return false;
}(); }();
// Apple (ARM) --> Cockatrice-3.0.0-macOS15.dmg
// Apple (x86) --> Cockatrice-3.0.0-macOS15_Intel.dmg
static const QRegularExpression macIntelRegex(R"(-macOS(\d+)_Intel\.[^.]+$)", static const QRegularExpression macIntelRegex(R"(-macOS(\d+)_Intel\.[^.]+$)",
QRegularExpression::CaseInsensitiveOption); QRegularExpression::CaseInsensitiveOption);
static const QRegularExpression macArmRegex(R"(-macOS(\d+)\.[^.]+$)", QRegularExpression::CaseInsensitiveOption); static const QRegularExpression macRegex(R"(-macOS(\d+)\.[^.]+$)", QRegularExpression::CaseInsensitiveOption);
regex = isIntel ? &macIntelRegex : &macArmRegex; regex = isIntel ? &macIntelRegex : &macRegex;
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)
// Windows (x86) --> Cockatrice-3.0.0-Windows10.exe
static const QRegularExpression winRegex(R"(-(?:Win|Windows)(\d+)\.[^.]+$)", static const QRegularExpression winRegex(R"(-(?:Win|Windows)(\d+)\.[^.]+$)",
QRegularExpression::CaseInsensitiveOption); QRegularExpression::CaseInsensitiveOption);
regex = &winRegex; regex = &winRegex;
@ -75,14 +94,13 @@ std::optional<int> ReleaseChannel::getTargetVersionForCurrentOS(const QString &f
return std::nullopt; return std::nullopt;
#endif #endif
// Any asset targeting an OS version smaller or equal to the current host works // Any asset targeting an OS version up to the current host version works
const int systemVersion = QSysInfo::productVersion().split('.').first().toInt();
auto match = regex->match(fileName); auto match = regex->match(fileName);
if (!match.hasMatch()) { if (!match.hasMatch()) {
return std::nullopt; return std::nullopt;
} }
const int targetVersion = match.captured(1).toInt(); const int targetVersion = match.captured(1).toInt();
if (targetVersion > systemVersion) { if (targetVersion > *systemVersion) {
return std::nullopt; return std::nullopt;
} }
return targetVersion; return targetVersion;

View file

@ -97,8 +97,8 @@ protected:
Release *lastRelease; Release *lastRelease;
protected: protected:
std::optional<int> getTargetVersionForCurrentOS(const QString &fileName); static std::optional<int> getTargetVersionForCurrentOS(const QString &fileName);
QString findBestDownloadUrl(const QVariantList &assets); static QString findBestDownloadUrl(const QVariantList &assets);
[[nodiscard]] virtual QString getReleaseChannelUrl() const = 0; [[nodiscard]] virtual QString getReleaseChannelUrl() const = 0;
public: public: