mirror of
https://github.com/cemu-project/Cemu.git
synced 2026-06-12 17:44:59 -06:00
logging: Improve Windows OS version detection (#1949)
This commit is contained in:
parent
326933b248
commit
e4fa470140
@ -499,21 +499,43 @@ namespace CafeSystem
|
||||
std::string GetWindowsNamedVersion(uint32& buildNumber)
|
||||
{
|
||||
char productName[256];
|
||||
char buildNumberStr[32];
|
||||
char featureVersion[32];
|
||||
HKEY hKey;
|
||||
DWORD dwType = REG_SZ;
|
||||
DWORD dwSize = sizeof(productName);
|
||||
buildNumber = 0;
|
||||
featureVersion[0] = '\0';
|
||||
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
|
||||
{
|
||||
if (RegQueryValueExA(hKey, "ProductName", NULL, &dwType, (LPBYTE)productName, &dwSize) != ERROR_SUCCESS)
|
||||
strcpy(productName, "Windows");
|
||||
dwType = REG_SZ;
|
||||
dwSize = sizeof(buildNumberStr);
|
||||
if (RegQueryValueExA(hKey, "CurrentBuildNumber", NULL, &dwType, (LPBYTE)buildNumberStr, &dwSize) == ERROR_SUCCESS)
|
||||
buildNumber = (uint32)atoi(buildNumberStr);
|
||||
dwType = REG_SZ;
|
||||
dwSize = sizeof(featureVersion);
|
||||
if (RegQueryValueExA(hKey, "DisplayVersion", NULL, &dwType, (LPBYTE)featureVersion, &dwSize) != ERROR_SUCCESS)
|
||||
{
|
||||
dwType = REG_SZ;
|
||||
dwSize = sizeof(featureVersion);
|
||||
if (RegQueryValueExA(hKey, "ReleaseId", NULL, &dwType, (LPBYTE)featureVersion, &dwSize) != ERROR_SUCCESS)
|
||||
featureVersion[0] = '\0';
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
OSVERSIONINFO osvi;
|
||||
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
|
||||
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
GetVersionEx(&osvi);
|
||||
buildNumber = osvi.dwBuildNumber;
|
||||
return std::string(productName);
|
||||
std::string result(productName);
|
||||
// ProductName still reads as "Windows 10" on Windows 11. Find and replace with "Windows 11" based on build number.
|
||||
if (buildNumber >= 22000)
|
||||
{
|
||||
size_t pos = result.find("Windows 10");
|
||||
if (pos != std::string::npos)
|
||||
result.replace(pos, 10, "Windows 11");
|
||||
}
|
||||
if (featureVersion[0] != '\0')
|
||||
result += fmt::format(" {}", featureVersion);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user