Fix OS version information on old windows

This commit is contained in:
Ivan Matkov 2017-12-18 19:38:16 +03:00
Родитель f31e9d0e85
Коммит 9e074d843b
1 изменённых файлов: 19 добавлений и 6 удалений

Просмотреть файл

@ -51,14 +51,27 @@ namespace Microsoft.AppCenter.Utils
protected override string GetOsBuild()
{
using (var hklmKey = Microsoft.Win32.Registry.LocalMachine)
using (var hklmKey = Win32.Registry.LocalMachine)
using (var subKey = hklmKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"))
{
object majorVersion = subKey.GetValue("CurrentMajorVersionNumber");
object minorVersion = subKey.GetValue("CurrentMinorVersionNumber");
object buildNumber = subKey.GetValue("CurrentBuildNumber");
object revisionNumber = subKey.GetValue("UBR");
return $"{majorVersion}.{minorVersion}.{buildNumber}.{revisionNumber}";
// CurrentMajorVersionNumber present in registry starting with Windows 10
var majorVersion = subKey.GetValue("CurrentMajorVersionNumber");
if (majorVersion != null)
{
var minorVersion = subKey.GetValue("CurrentMinorVersionNumber", "0");
var buildNumber = subKey.GetValue("CurrentBuildNumber", "0");
var revisionNumber = subKey.GetValue("UBR", "0");
return $"{majorVersion}.{minorVersion}.{buildNumber}.{revisionNumber}";
}
else
{
// If CurrentMajorVersionNumber not present in registry then use CurrentVersion
var version = subKey.GetValue("CurrentVersion", "0.0");
var buildNumber = subKey.GetValue("CurrentBuild", "0");
var buildLabEx = subKey.GetValue("BuildLabEx")?.ToString().Split('.');
var revisionNumber = buildLabEx?.Length >= 2 ? buildLabEx[1] : "0";
return $"{version}.{buildNumber}.{revisionNumber}";
}
}
}