platform.bmx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. ' Copyright (c) 2019-2020 Bruce A Henderson
  2. '
  3. ' This software is provided 'as-is', without any express or implied
  4. ' warranty. In no event will the authors be held liable for any damages
  5. ' arising from the use of this software.
  6. '
  7. ' Permission is granted to anyone to use this software for any purpose,
  8. ' including commercial applications, and to alter it and redistribute it
  9. ' freely, subject to the following restrictions:
  10. '
  11. ' 1. The origin of this software must not be misrepresented; you must not
  12. ' claim that you wrote the original software. If you use this software
  13. ' in a product, an acknowledgment in the product documentation would be
  14. ' appreciated but is not required.
  15. '
  16. ' 2. Altered source versions must be plainly marked as such, and must not be
  17. ' misrepresented as being the original software.
  18. '
  19. ' 3. This notice may not be removed or altered from any source
  20. ' distribution.
  21. '
  22. SuperStrict
  23. Rem
  24. bbdoc: Platform utils
  25. End Rem
  26. Module BRL.Platform
  27. ModuleInfo "Version: 1.02"
  28. ModuleInfo "Author: Bruce A Henderson"
  29. ModuleInfo "License: zlib/libpng"
  30. ModuleInfo "History: 1.02"
  31. ModuleInfo "History: Fixed for Android."
  32. ModuleInfo "History: 1.01"
  33. ModuleInfo "History: Added LogicalProcessorCount()."
  34. ModuleInfo "History: 1.00"
  35. ModuleInfo "History: Initial Release"
  36. Import BRL.TextStream
  37. Import Pub.macos
  38. ?android
  39. Import SDL.SDL
  40. ?
  41. ?win32
  42. Import "win32_glue.c"
  43. ?Not win32 And Not android And Not haiku
  44. Import "glue.c"
  45. ?haiku
  46. Import "haiku_glue.c"
  47. ?
  48. Private
  49. Global _version:String
  50. Public
  51. Rem
  52. bbdoc: Returns a #String representation of the OS version.
  53. about: On Linux, this will return something like "Ubuntu" or "Fedora".
  54. On Windows and macOS, this will return the version number, such as "10.11"
  55. End Rem
  56. Function OSVersion:String()
  57. If _version Then
  58. Return _version
  59. End If
  60. ?linux
  61. Return LinuxVersion()
  62. ?macos
  63. Return MacOSVersion()
  64. ?win32
  65. Return WindowsVersion()
  66. ?haiku
  67. Return HaikuVersion()
  68. ?
  69. End Function
  70. Function LinuxVersion:String()
  71. ?Not linux
  72. Return ""
  73. ?linux And Not android
  74. If _version Then
  75. Return _version
  76. End If
  77. Local rel:String[] = LoadText("/etc/os-release").Split("~n")
  78. For Local line:String = EachIn rel
  79. If line.StartsWith("NAME") Then
  80. Local parts:String[] = line.Split("=")
  81. If parts.length > 1 Then
  82. _version = parts[1].Replace("~q", "").Trim()
  83. Return _version
  84. End If
  85. End If
  86. Next
  87. ?android
  88. Return "Android"
  89. ?
  90. End Function
  91. Function MacOSVersion:String()
  92. ?Not macos
  93. Return ""
  94. ?macos
  95. If _version Then
  96. Return _version
  97. End If
  98. Local major:Int, minor:Int, patch:Int
  99. NSOSVersion(major, minor, patch)
  100. _version = major + "." + minor + "." + patch
  101. Return _version
  102. ?
  103. End Function
  104. Private
  105. Extern
  106. ?win32
  107. Function bmx_os_getwindowsversion(major:Int Var, minor:Int Var)
  108. ?haiku
  109. Function bmx_os_gethaikuversion:String()
  110. ?
  111. End Extern
  112. Public
  113. Function WindowsVersion:String()
  114. ?Not win32
  115. Return ""
  116. ?win32
  117. If _version Then
  118. Return _version
  119. End If
  120. Local major:Int
  121. Local minor:Int
  122. bmx_os_getwindowsversion(major, minor)
  123. _version = major + "." + minor
  124. Return _version
  125. ?
  126. End Function
  127. Function HaikuVersion:String()
  128. ?Not haiku
  129. Return ""
  130. ?haiku
  131. If _version Then
  132. Return _version
  133. End If
  134. _version = bmx_os_gethaikuversion()
  135. Return _version
  136. ?
  137. End Function
  138. Rem
  139. bbdoc: Returns the number of logical processors available.
  140. about: Logical processors are the number of physical processors times the number of threads that can run on each.
  141. End Rem
  142. Function LogicalProcessorCount:Int()
  143. ?Not android
  144. Return bmx_os_getproccount()
  145. ?android
  146. Return SDLGetCPUCount()
  147. ?
  148. End Function
  149. Extern
  150. Function bmx_os_getproccount:Int()
  151. End Extern