mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-27 00:14:40 -07:00
combined logic + better regex
This commit is contained in:
parent
315879fe6b
commit
3ad7bae16d
1 changed files with 24 additions and 39 deletions
|
|
@ -49,6 +49,8 @@ std::optional<int> ReleaseChannel::getTargetVersionForCurrentOS(const QString &f
|
||||||
{
|
{
|
||||||
#if defined(Q_OS_MACOS)
|
#if defined(Q_OS_MACOS)
|
||||||
const bool isIntel = [] {
|
const bool isIntel = [] {
|
||||||
|
// QSysInfo does not go through translation layers
|
||||||
|
// We need to use sysctl to reliably detect the underlying architecture
|
||||||
char arch[255];
|
char arch[255];
|
||||||
size_t len = sizeof(arch);
|
size_t len = sizeof(arch);
|
||||||
if (sysctlbyname("machdep.cpu.brand_string", arch, &len, nullptr, 0) == 0) {
|
if (sysctlbyname("machdep.cpu.brand_string", arch, &len, nullptr, 0) == 0) {
|
||||||
|
|
@ -56,48 +58,32 @@ std::optional<int> ReleaseChannel::getTargetVersionForCurrentOS(const QString &f
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}();
|
}();
|
||||||
const int systemVersion = QSysInfo::productVersion().split(".")[0].toInt();
|
static const QRegularExpression macIntelRegex(R"(macOS(\d+)_Intel\.[^.]+$)", QRegularExpression::CaseInsensitiveOption);
|
||||||
if (isIntel) {
|
static const QRegularExpression macArmRegex(R"(macOS(\d+)\.[^.]+$)", QRegularExpression::CaseInsensitiveOption);
|
||||||
static QRegularExpression regex(R"(macOS(\d+)_Intel)");
|
const QRegularExpression ®ex = isIntel ? macIntelRegex : macArmRegex;
|
||||||
auto match = regex.match(fileName);
|
|
||||||
if (!match.hasMatch()) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
int version = match.captured(1).toInt();
|
|
||||||
if (version <= systemVersion) {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
static QRegularExpression regex(R"(macOS(\d+)(?!_Intel))");
|
|
||||||
auto match = regex.match(fileName);
|
|
||||||
if (!match.hasMatch()) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
int version = match.captured(1).toInt();
|
|
||||||
if (version <= systemVersion) {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
return std::nullopt;
|
|
||||||
|
|
||||||
#elif defined(Q_OS_WIN)
|
#elif defined(Q_OS_WIN)
|
||||||
#if Q_PROCESSOR_WORDSIZE == 8
|
#if Q_PROCESSOR_WORDSIZE != 8 // non 64-bit host
|
||||||
const int systemVersion = QSysInfo::productVersion().split(".")[0].toInt();
|
|
||||||
static QRegularExpression regex(R"(Windows(\d+))");
|
|
||||||
auto match = regex.match(fileName);
|
|
||||||
if (!match.hasMatch()) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
int version = match.captured(1).toInt();
|
|
||||||
if (version <= systemVersion) {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return std::nullopt;
|
|
||||||
#else
|
|
||||||
Q_UNUSED(fileName);
|
Q_UNUSED(fileName);
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
#endif
|
#endif
|
||||||
|
static const QRegularExpression regex(R"(Win(?:dows)?(\d+)\.[^.]+$)", QRegularExpression::CaseInsensitiveOption);
|
||||||
|
|
||||||
|
#else // if the OS doesn't fit one of the above #defines, then it will never match
|
||||||
|
Q_UNUSED(fileName);
|
||||||
|
return std::nullopt;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const int systemVersion = QSysInfo::productVersion().split('.').first().toInt();
|
||||||
|
auto match = regex.match(fileName);
|
||||||
|
if (!match.hasMatch()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
const int targetVersion = match.captured(1).toInt();
|
||||||
|
if (targetVersion > systemVersion) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
return targetVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ReleaseChannel::findBestDownloadUrl(const QVariantList &assets)
|
QString ReleaseChannel::findBestDownloadUrl(const QVariantList &assets)
|
||||||
|
|
@ -119,8 +105,7 @@ QString ReleaseChannel::findBestDownloadUrl(const QVariantList &assets)
|
||||||
}
|
}
|
||||||
if (!bestUrl.isEmpty()) {
|
if (!bestUrl.isEmpty()) {
|
||||||
qCInfo(ReleaseChannelLog)
|
qCInfo(ReleaseChannelLog)
|
||||||
<< "Selected compatible asset version=" << bestVersion
|
<< "Best compatible asset=" << bestUrl;
|
||||||
<< "url=" << bestUrl;
|
|
||||||
}
|
}
|
||||||
return bestUrl;
|
return bestUrl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue