' Classes/System/OperatingSystem.ab

#require <Classes/System/Version.ab>

Namespace System

Class OperatingSystem
	' Inherits ICloneable', ISerializable
Public
	' Constractor
	Sub OperatingSystem(platform As PlatformID, version As Version)
		pf = platform
		ver = version
		sp = ""
	End Sub

	Sub OperatingSystem(vi As OSVERSIONINFOA)
		pf = vi.dwPlatformId As PlatformID
		ver = New Version(vi.dwMajorVersion, vi.dwMinorVersion, vi.dwBuildNumber)
		sp = New String(vi.szCSDVersion As PCSTR)
	End Sub

	Sub OperatingSystem(vi As OSVERSIONINFOW)
		pf = vi.dwPlatformId As PlatformID
		ver = New Version(vi.dwMajorVersion, vi.dwMinorVersion, vi.dwBuildNumber)
		sp = New String(vi.szCSDVersion As PCSTR)
	End Sub

	' Properties
	Const Function Platform() As PlatformID
		Return pf
	End Function

	Const Function Version() As Version
		Return ver
	End Function

	Const Function ServicePack() As String
		Return sp
	End Function

	Const Function VersionString() As String
		Select Case pf
			Case PlatformID.Win32S
				VersionString = "Microsoft Win32S "
			Case PlatformID.Win32Windows
				VersionString = "Microsoft Windows "
			Case PlatformID.Win32NT
				VersionString = "Microsoft Windows NT "
			Case PlatformID.WinCE
				VersionString = "Microsoft Windows CE "
			Case PlatformID.Unix
				VersionString = "<unknown> "
		End Select
		VersionString = VersionString + ver.ToString
		If String.IsNullOrEmpty(sp) <> False Then
			VersionString = VersionString + " " + sp
		End If
	End Function

	' Methods
	Override Function ToString() As String
		Return VersionString
	End Function

	Override Function GetHashCode() As Long
		Return pf.GetHashCode Xor ver.GetHashCode Xor sp.GetHashCode
	End Function

Private
	pf As PlatformID
	ver As Version
	sp As String
End Class

Enum PlatformID
	Win32S = VER_PLATFORM_WIN32s '0
	Win32Windows = VER_PLATFORM_WIN32_WINDOWS '1
	Win32NT = VER_PLATFORM_WIN32_NT '2
	WinCE = VER_PLATFORM_WIN32_CE '3
	Unix = 4
End Enum

End Namespace
