From f6fad0630fef4e2a228ad444750c1a3eb7659c46 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Sat, 11 Jan 2025 15:50:13 -0500 Subject: [PATCH] macos: don't assume that all macOS major versions are simple numeric values (#3836) Related to https://github.com/open-goal/launcher/pull/664 Likely Fixes https://github.com/open-goal/launcher/issues/663 --- common/util/os.cpp | 9 +++++++-- common/util/os.h | 2 +- game/main.cpp | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/common/util/os.cpp b/common/util/os.cpp index f77491c1c4d..e928bc5cf72 100644 --- a/common/util/os.cpp +++ b/common/util/os.cpp @@ -2,6 +2,7 @@ #include "common/common_types.h" #include "common/log/log.h" +#include "common/util/string_util.h" #ifdef __APPLE__ #include @@ -112,7 +113,7 @@ CpuInfo& get_cpu_info() { return gCpuInfo; } -std::optional get_macos_version() { +std::optional get_macos_major_version() { #ifndef __APPLE__ return {}; #else @@ -124,7 +125,11 @@ std::optional get_macos_version() { return {}; } try { - return std::stod(buffer); + std::string macos_major_version = buffer; + if (str_util::contains(buffer, ".")) { + macos_major_version = str_util::split_string(macos_major_version, ".")[0]; + } + return std::stod(macos_major_version); } catch (std::exception& e) { lg::error("Error occured when attempting to convert sysctl value {} to number", buffer); return {}; diff --git a/common/util/os.h b/common/util/os.h index 79dc63b0293..809800f258b 100644 --- a/common/util/os.h +++ b/common/util/os.h @@ -18,4 +18,4 @@ struct CpuInfo { CpuInfo& get_cpu_info(); -std::optional get_macos_version(); +std::optional get_macos_major_version(); diff --git a/game/main.cpp b/game/main.cpp index 3322e468a31..f4048709e3d 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -182,8 +182,8 @@ int main(int argc, char** argv) { // Check if we are on a modern enough version of macOS so that AVX can be // emulated via rosetta #ifdef __APPLE__ - auto macos_version = get_macos_version(); - if (macos_version < 15.0) { + auto macos_major_version = get_macos_major_version(); + if (macos_major_version < 15.0) { lg::info( "Your CPU does not support AVX. But the newer version of Rosetta supports it, update to " "atleast Sequoia to run OpenGOAL!");