1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-08 12:40:44 +00:00

Add OS.get_version_alias() to return a human-readable Windows/macOS version number

Windows 11's major version number is actually 10.x.x, which can be confusing
if you don't know about this quirk. `OS.get_version_alias()` avoids this
by displaying the "branding" version number and the build number as a suffix,
so that individual updates can still be distinguished from each other.

On macOS, `OS.get_version_alias()` returns the version number prepended
with the version name (e.g. Sequoia for macOS 15).

On other operating systems, this returns the same value as `OS.get_version()`.
This commit is contained in:
Hugo Locurcio
2024-12-13 17:16:14 +01:00
parent 7f5c469292
commit 928982891e
11 changed files with 105 additions and 5 deletions

View File

@@ -582,7 +582,7 @@ String OS_Windows::get_distribution_name() const {
String OS_Windows::get_version() const {
RtlGetVersionPtr version_ptr = (RtlGetVersionPtr)GetProcAddress(GetModuleHandle("ntdll.dll"), "RtlGetVersion");
if (version_ptr != nullptr) {
RTL_OSVERSIONINFOW fow;
RTL_OSVERSIONINFOEXW fow;
ZeroMemory(&fow, sizeof(fow));
fow.dwOSVersionInfoSize = sizeof(fow);
if (version_ptr(&fow) == 0x00000000) {
@@ -592,6 +592,64 @@ String OS_Windows::get_version() const {
return "";
}
String OS_Windows::get_version_alias() const {
RtlGetVersionPtr version_ptr = (RtlGetVersionPtr)GetProcAddress(GetModuleHandle("ntdll.dll"), "RtlGetVersion");
if (version_ptr != nullptr) {
RTL_OSVERSIONINFOEXW fow;
ZeroMemory(&fow, sizeof(fow));
fow.dwOSVersionInfoSize = sizeof(fow);
if (version_ptr(&fow) == 0x00000000) {
String windows_string;
if (fow.wProductType != VER_NT_WORKSTATION && fow.dwMajorVersion == 10 && fow.dwBuildNumber >= 26100) {
windows_string = "Server 2025";
} else if (fow.dwMajorVersion == 10 && fow.dwBuildNumber >= 20348) {
// Builds above 20348 correspond to Windows 11 / Windows Server 2022.
// Their major version numbers are still 10 though, not 11.
if (fow.wProductType != VER_NT_WORKSTATION) {
windows_string += "Server 2022";
} else {
windows_string += "11";
}
} else if (fow.dwMajorVersion == 10) {
if (fow.wProductType != VER_NT_WORKSTATION && fow.dwBuildNumber >= 17763) {
windows_string += "Server 2019";
} else {
if (fow.wProductType != VER_NT_WORKSTATION) {
windows_string += "Server 2016";
} else {
windows_string += "10";
}
}
} else if (fow.dwMajorVersion == 6 && fow.dwMinorVersion == 3) {
if (fow.wProductType != VER_NT_WORKSTATION) {
windows_string = "Server 2012 R2";
} else {
windows_string += "8.1";
}
} else if (fow.dwMajorVersion == 6 && fow.dwMinorVersion == 2) {
if (fow.wProductType != VER_NT_WORKSTATION) {
windows_string += "Server 2012";
} else {
windows_string += "8";
}
} else if (fow.dwMajorVersion == 6 && fow.dwMinorVersion == 1) {
if (fow.wProductType != VER_NT_WORKSTATION) {
windows_string = "Server 2008 R2";
} else {
windows_string += "7";
}
} else {
windows_string += "Unknown";
}
// Windows versions older than 7 cannot run Godot.
return vformat("%s (build %d)", windows_string, (int64_t)fow.dwBuildNumber);
}
}
return "";
}
Vector<String> OS_Windows::get_video_adapter_driver_info() const {
if (RenderingServer::get_singleton() == nullptr) {
return Vector<String>();