desktop: Try to find out the Windows 10 release number

There is a registry key holding the release number, it turns out. It's a
useful datapoint for reports, although there's no guarantee that Windows
won't fake it in the future. It's also easier to identify a release this
way than through the full build number.
This commit is contained in:
Iris Morelle 2020-01-09 21:58:14 -03:00
parent 29298c139f
commit 59af19db70

View file

@ -72,6 +72,23 @@ bool on_wine()
return GetProcAddress(ntdll, "wine_get_version") != nullptr;
}
/**
* Tries to find out the Windows 10 release number.
*
* This depends on the registry having special information in it. This may or
* may not break in the future or be faked by the application compatibility
* layer. Take with a grain of salt.
*/
std::string windows_release_id()
{
char buf[256]{""};
DWORD size = sizeof(buf);
const auto res = RegGetValueA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ReleaseId", RRF_RT_REG_SZ, nullptr, buf, &size);
return std::string{res == ERROR_SUCCESS ? buf : ""};
}
#endif
#if defined(_X11)
@ -241,6 +258,11 @@ std::string os_version()
case 1000:
if(v.wProductType == VER_NT_WORKSTATION) {
version = "10";
const auto& release_id = windows_release_id();
if(!release_id.empty()) {
version += ' ';
version += release_id;
}
break;
} // else fallback to default
default: