1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/pkg/parsers/operatingsystem/windows_os_string.go
Cory Snider 9aacaeb667 pkg/parsers: support Windows 11; drop ProductName
Microsoft has stopped updating the ProductName registry value in Windows
11; it reads as Windows 10. And Microsoft has made it very difficult to
look up the real product name programmatically so that applications do
not attempt to parse it. (Ever wonder why they skipped Windows 9?) The
only documented and supported mechanisms require WMI or WinRT. The
product name has no bearing on application compatibility so it is not
worth doing any heroics to display the correct name. The build number
and Update Build Revision is sufficient information to identify a
specific build of Windows. Stop displaying the ProductName so as not to
confuse users with incorrect information.

Microsoft has frozen the ReleaseId registry value at 2009 when they
switched to semi-annual releases and alpha-numeric versions. The release
version as displayed by winver.exe and Settings -> System -> About on
Windows 20H2 and newer can be found in the new DisplayVersion registry
value. Replicate the way winver.exe displays the version by
preferentially reporting the DisplayVersion if present and reporting if
it is a Windows Server edition.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-03-04 16:08:34 -05:00

33 lines
722 B
Go

package operatingsystem // import "github.com/docker/docker/pkg/parsers/operatingsystem"
import (
"fmt"
"strings"
)
type windowsOSRelease struct {
IsServer bool
DisplayVersion string
Build uint32
UBR uint64
}
// String formats the OS release data similar to what is displayed by
// winver.exe.
func (r *windowsOSRelease) String() string {
var b strings.Builder
b.WriteString("Microsoft Windows")
if r.IsServer {
b.WriteString(" Server")
}
if r.DisplayVersion != "" {
b.WriteString(" Version ")
b.WriteString(r.DisplayVersion)
}
_, _ = fmt.Fprintf(&b, " (OS Build %d", r.Build)
if r.UBR > 0 {
_, _ = fmt.Fprintf(&b, ".%d", r.UBR)
}
b.WriteByte(')')
return b.String()
}