Index: ps/trunk/source/lib/sysdep/os/win/wversion.h =================================================================== --- ps/trunk/source/lib/sysdep/os/win/wversion.h +++ ps/trunk/source/lib/sysdep/os/win/wversion.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -23,11 +23,6 @@ #ifndef INCLUDED_WVERSION #define INCLUDED_WVERSION -/** - * @return CurrentVersion string from registry - **/ -extern const wchar_t* wversion_String(); - // (same format as WINVER) const size_t WVERSION_2K = 0x0500; const size_t WVERSION_XP = 0x0501; @@ -39,13 +34,8 @@ const size_t WVERSION_10 = 0x0604; /** - * @return one of the above WVERSION* values - **/ -size_t wversion_Number(); - -/** * @return short textual representation of the version **/ -extern const char* wversion_Family(); +const char* wversion_Family(); #endif // #ifndef INCLUDED_WVERSION Index: ps/trunk/source/lib/sysdep/os/win/wversion.cpp =================================================================== --- ps/trunk/source/lib/sysdep/os/win/wversion.cpp +++ ps/trunk/source/lib/sysdep/os/win/wversion.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -24,66 +24,20 @@ #include "lib/sysdep/os/win/wversion.h" #include "lib/sysdep/os/win/win.h" -#include "lib/sysdep/os/win/winit.h" #include -WINIT_REGISTER_EARLY_INIT(wversion_Init); - - -static wchar_t windowsVersionString[20]; -static size_t windowsVersion; // see WVERSION_* - - const char* wversion_Family() { - ENSURE(windowsVersion != 0); - switch(windowsVersion) - { - case WVERSION_2K: - return "Win2k"; - case WVERSION_XP: - return "WinXP"; - case WVERSION_XP64: - return "WinXP64"; - case WVERSION_VISTA: - return "Vista"; - case WVERSION_7: - return "Win7"; - case WVERSION_8: - return "Win8"; - case WVERSION_8_1: - return "Win8.1"; - case WVERSION_10: - return "Win10"; - default: - return "Windows"; - } -} - - -const wchar_t* wversion_String() -{ - ENSURE(windowsVersionString[0] != '\0'); - return windowsVersionString; -} - -size_t wversion_Number() -{ - ENSURE(windowsVersion != 0); - return windowsVersion; -} - - -static Status wversion_Init() -{ + size_t windowsVersion = 0; // note: don't use GetVersion[Ex] because it gives the version of the // emulated OS when running an app with compatibility shims enabled. HKEY hKey; if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) { + wchar_t windowsVersionString[32]; DWORD size = sizeof(windowsVersionString); - (void)RegQueryValueExW(hKey, L"CurrentVersion", 0, 0, (LPBYTE)windowsVersionString, &size); + UNUSED2(RegQueryValueExW(hKey, L"CurrentVersion", 0, 0, reinterpret_cast(windowsVersionString), &size)); unsigned major = 0, minor = 0; // ICC 11.1.082 generates incorrect code for the following: @@ -104,5 +58,26 @@ else DEBUG_WARN_ERR(ERR::LOGIC); - return INFO::OK; + ENSURE(windowsVersion != 0); + switch(windowsVersion) + { + case WVERSION_2K: + return "Win2k"; + case WVERSION_XP: + return "WinXP"; + case WVERSION_XP64: + return "WinXP64"; + case WVERSION_VISTA: + return "Vista"; + case WVERSION_7: + return "Win7"; + case WVERSION_8: + return "Win8"; + case WVERSION_8_1: + return "Win8.1"; + case WVERSION_10: + return "Win10"; + default: + return "Windows"; + } }