Add more properties to Environment class
All checks were successful
PRs & Pushes / test (push) Successful in 3m3s
PRs & Pushes / build (push) Successful in 3m5s
PRs & Pushes / build-apidoc (push) Successful in 3m3s

Will probably add more tomorrow
This commit is contained in:
JeremyStar™ 2024-12-17 04:29:20 +01:00
parent d5a03c885b
commit 5e1dd3fc35
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -22,6 +22,7 @@ package de.staropensource.engine.base.utility
import de.staropensource.engine.base.Engine.Companion.logger
import de.staropensource.engine.base.utility.Environment.OperatingSystem.*
import kotlinx.datetime.Instant
import oshi.PlatformEnum
import oshi.SystemInfo
@ -38,15 +39,46 @@ class Environment private constructor() {
* @since v1-alpha10
*/
companion object {
// -----> Properties
/**
* The operating system family
* this program is running under.
*
* @since v1-alpha10
*/
var operatingSystem: OperatingSystem = OperatingSystem.UNKNOWN
internal set
var operatingSystem: OperatingSystem = UNKNOWN
private set
/**
* Returns the maximum amount of bits this operating system supports.
*
* This might be 32, 64 or even higher.
*
* @since v1-alpha10
*/
var bitAmount: Int = 0
private set
/**
* The point in time where the
* operating system was started at.
*
* @since v1-alpha10
*/
var startTime: Instant = Instant.fromEpochMilliseconds(0)
private set
/**
* Contains if this process is elevated ie.
* has superuser/administrator permissions.
*
* @since v1-alpha10
*/
var elevated: Boolean = false
private set
// -----> Update methods
/**
* Unsets the environment.
*
@ -54,7 +86,10 @@ class Environment private constructor() {
*/
@JvmStatic
internal fun unset() {
operatingSystem = OperatingSystem.UNKNOWN
operatingSystem = UNKNOWN
bitAmount = 0
startTime = Instant.fromEpochMilliseconds(0)
elevated = false
}
/**
@ -69,6 +104,7 @@ class Environment private constructor() {
logger.diag("Running environment detection")
// Detect operating system
when (SystemInfo.getCurrentPlatform()) {
PlatformEnum.LINUX, PlatformEnum.GNU, PlatformEnum.KFREEBSD -> operatingSystem = LINUX
PlatformEnum.FREEBSD -> operatingSystem = FREEBSD
@ -79,6 +115,11 @@ class Environment private constructor() {
PlatformEnum.MACOS -> operatingSystem = MACOS
else -> logger.crash("Unsupported operating system '" + os.family + "'")
}
// Detect other metadata
bitAmount = os.bitness
startTime = Instant.fromEpochSeconds(epochSeconds = os.systemBootTime)
elevated = os.isElevated
}
}
@ -104,7 +145,8 @@ class Environment private constructor() {
/**
* Identifies that the application is running
* under the [Linux](https://kernel.org) kernel.
* under the [Linux](https://kernel.org) kernel
* on some kind of Linux distribution.
*
* @since v1-alpha10
*/
@ -112,7 +154,8 @@ class Environment private constructor() {
/**
* Identifies that the application is running
* under the [FreeBSD](https://freebsd.org) kernel.
* under the [FreeBSD](https://freebsd.org) kernel
* and likely the FreeBSD operating system.
*
* @since v1-alpha10
*/
@ -120,7 +163,8 @@ class Environment private constructor() {
/**
* Identifies that the application is running
* under the [NetBSD](https://netbsd.org) kernel.
* under the [NetBSD](https://netbsd.org) kernel
* and likely the NetBSD operating system.
*
* @since v1-alpha10
*/
@ -128,7 +172,8 @@ class Environment private constructor() {
/**
* Identifies that the application is running
* under the [OpenBSD](https://openbsd.org) kernel.
* under the [OpenBSD](https://openbsd.org) kernel
* and likely the OpenBSD operating system.
*
* @since v1-alpha10
*/