123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- ' Copyright (c) 2019-2023 Bruce A Henderson
- '
- ' This software is provided 'as-is', without any express or implied
- ' warranty. In no event will the authors be held liable for any damages
- ' arising from the use of this software.
- '
- ' Permission is granted to anyone to use this software for any purpose,
- ' including commercial applications, and to alter it and redistribute it
- ' freely, subject to the following restrictions:
- '
- ' 1. The origin of this software must not be misrepresented; you must not
- ' claim that you wrote the original software. If you use this software
- ' in a product, an acknowledgment in the product documentation would be
- ' appreciated but is not required.
- '
- ' 2. Altered source versions must be plainly marked as such, and must not be
- ' misrepresented as being the original software.
- '
- ' 3. This notice may not be removed or altered from any source
- ' distribution.
- '
- SuperStrict
- Rem
- bbdoc: Platform utils
- End Rem
- Module BRL.Platform
- ModuleInfo "Version: 1.04"
- ModuleInfo "Author: Bruce A Henderson"
- ModuleInfo "License: zlib/libpng"
- ModuleInfo "History: 1.04"
- ModuleInfo "History: Improved calculation for Win32."
- ModuleInfo "History: 1.03"
- ModuleInfo "History: Added PhysicalProcessorCount()."
- ModuleInfo "History: Added build number for Win32 OS version."
- ModuleInfo "History: 1.02"
- ModuleInfo "History: Fixed for Android."
- ModuleInfo "History: 1.01"
- ModuleInfo "History: Added LogicalProcessorCount()."
- ModuleInfo "History: 1.00"
- ModuleInfo "History: Initial Release"
- Import BRL.TextStream
- Import Pub.macos
- ?android
- Import SDL.SDL
- ?
- ?win32
- Import "win32_glue.c"
- ?Not win32 And Not android And Not haiku and not macos
- Import "glue.c"
- ?haiku
- Import "haiku_glue.c"
- ?macos
- Import "macos_glue.c"
- ?linux
- Import "linux.bmx"
- ?
- Private
- Global _version:String
- Public
- Rem
- bbdoc: Returns a #String representation of the OS version.
- about: On Linux, this will return something like "Ubuntu" or "Fedora".
- On Windows and macOS, this will return the version number, such as "10.11"
- End Rem
- Function OSVersion:String()
- If _version Then
- Return _version
- End If
- ?linux
- Return LinuxVersion()
- ?macos
- Return MacOSVersion()
- ?win32
- Return WindowsVersion()
- ?haiku
- Return HaikuVersion()
- ?
- End Function
- Function LinuxVersion:String()
- ?Not linux
- Return ""
- ?linux And Not android
- If _version Then
- Return _version
- End If
-
- Local rel:String[] = LoadText("/etc/os-release").Split("~n")
- For Local line:String = EachIn rel
- If line.StartsWith("NAME") Then
- Local parts:String[] = line.Split("=")
- If parts.length > 1 Then
- _version = parts[1].Replace("~q", "").Trim()
- Return _version
- End If
- End If
- Next
- ?android
- Return "Android"
- ?
- End Function
- Function MacOSVersion:String()
- ?Not macos
- Return ""
- ?macos
- If _version Then
- Return _version
- End If
- Local major:Int, minor:Int, patch:Int
- NSOSVersion(major, minor, patch)
- _version = major + "." + minor + "." + patch
- Return _version
- ?
- End Function
- Private
- Extern
- ?win32
- Function bmx_os_getwindowsversion(major:Int Var, minor:Int Var, build:Int Var)
- ?haiku
- Function bmx_os_gethaikuversion:String()
- ?
- End Extern
- Public
- Function WindowsVersion:String()
- ?Not win32
- Return ""
- ?win32
- If _version Then
- Return _version
- End If
- Local major:Int
- Local minor:Int
- Local build:Int
- bmx_os_getwindowsversion(major, minor, build)
- _version = major + "." + minor + "." + build
- Return _version
- ?
- End Function
- Function HaikuVersion:String()
- ?Not haiku
- Return ""
- ?haiku
- If _version Then
- Return _version
- End If
-
- _version = bmx_os_gethaikuversion()
- Return _version
- ?
- End Function
- Rem
- bbdoc: Returns the number of logical processors available.
- about: Logical processors are the number of physical processors times the number of threads that can run on each.
- End Rem
- Function LogicalProcessorCount:Int()
- ?Not android
- Return bmx_os_getproccount()
- ?android
- Return SDLGetCPUCount()
- ?
- End Function
- Rem
- bbdoc: Returns the number of physical processors available.
- End Rem
- Function PhysicalProcessorCount:Int()
- ?Not android And Not linux
- Return bmx_os_getphysproccount()
- ?linux And Not android
- Local count:Int = _linux_physical_processor_count()
- If Not count Then
- Return LogicalProcessorCount()
- End If
- Return count
- ?android
- Return SDLGetCPUCount()
- ?
- End Function
- Extern
- Function bmx_os_getproccount:Int()
- Function bmx_os_getphysproccount:Int()
- End Extern
|