Add more properties to Environment class
Will probably add more tomorrow
This commit is contained in:
parent
d5a03c885b
commit
5e1dd3fc35
1 changed files with 52 additions and 7 deletions
|
@ -22,6 +22,7 @@ package de.staropensource.engine.base.utility
|
||||||
|
|
||||||
import de.staropensource.engine.base.Engine.Companion.logger
|
import de.staropensource.engine.base.Engine.Companion.logger
|
||||||
import de.staropensource.engine.base.utility.Environment.OperatingSystem.*
|
import de.staropensource.engine.base.utility.Environment.OperatingSystem.*
|
||||||
|
import kotlinx.datetime.Instant
|
||||||
import oshi.PlatformEnum
|
import oshi.PlatformEnum
|
||||||
import oshi.SystemInfo
|
import oshi.SystemInfo
|
||||||
|
|
||||||
|
@ -38,15 +39,46 @@ class Environment private constructor() {
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
companion object {
|
companion object {
|
||||||
|
// -----> Properties
|
||||||
/**
|
/**
|
||||||
* The operating system family
|
* The operating system family
|
||||||
* this program is running under.
|
* this program is running under.
|
||||||
*
|
*
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
var operatingSystem: OperatingSystem = OperatingSystem.UNKNOWN
|
var operatingSystem: OperatingSystem = UNKNOWN
|
||||||
internal set
|
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.
|
* Unsets the environment.
|
||||||
*
|
*
|
||||||
|
@ -54,7 +86,10 @@ class Environment private constructor() {
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
internal fun unset() {
|
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")
|
logger.diag("Running environment detection")
|
||||||
|
|
||||||
|
// Detect operating system
|
||||||
when (SystemInfo.getCurrentPlatform()) {
|
when (SystemInfo.getCurrentPlatform()) {
|
||||||
PlatformEnum.LINUX, PlatformEnum.GNU, PlatformEnum.KFREEBSD -> operatingSystem = LINUX
|
PlatformEnum.LINUX, PlatformEnum.GNU, PlatformEnum.KFREEBSD -> operatingSystem = LINUX
|
||||||
PlatformEnum.FREEBSD -> operatingSystem = FREEBSD
|
PlatformEnum.FREEBSD -> operatingSystem = FREEBSD
|
||||||
|
@ -79,6 +115,11 @@ class Environment private constructor() {
|
||||||
PlatformEnum.MACOS -> operatingSystem = MACOS
|
PlatformEnum.MACOS -> operatingSystem = MACOS
|
||||||
else -> logger.crash("Unsupported operating system '" + os.family + "'")
|
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
|
* 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
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
|
@ -112,7 +154,8 @@ class Environment private constructor() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifies that the application is running
|
* 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
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
|
@ -120,7 +163,8 @@ class Environment private constructor() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifies that the application is running
|
* 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
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
|
@ -128,7 +172,8 @@ class Environment private constructor() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifies that the application is running
|
* 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
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue