From 5e1dd3fc35d77122aad206ba93a64b1998990afd Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Tue, 17 Dec 2024 04:29:20 +0100 Subject: [PATCH] Add more properties to Environment class Will probably add more tomorrow --- .../engine/base/utility/Environment.kt | 59 ++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/base/src/main/kotlin/de/staropensource/engine/base/utility/Environment.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/Environment.kt index 122a806..b278258 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/utility/Environment.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/utility/Environment.kt @@ -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 */