From 36da65b45e1a099e0d26933cb3e48dec7a5e7d4a Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sun, 29 Dec 2024 05:02:54 +0100 Subject: [PATCH] Fix issues --- .../engine/base/platform/Platform.kt | 21 ++++++++++++++++++- .../engine/base/platform/ProcessPlatform.kt | 2 ++ .../engine/base/utility/Environment.kt | 1 + .../engine/base/utility/Process.kt | 12 +++++------ .../engine/base/platform/PlatformImpl.kt | 1 + 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/Platform.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/Platform.kt index b8afc09..dea18af 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/Platform.kt +++ b/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/Platform.kt @@ -19,4 +19,23 @@ package de.staropensource.engine.base.platform -expect fun platformTerminate(exitcode: UByte) +/** + * Terminates the platform. + * + * @since v1-alpha10 + */ +internal expect fun platformTerminate(exitcode: UByte) + +/** + * Returns the time in milliseconds. + * + * Should only be used for + * comparing time intervals. + * **Should not be stored as + * this method may return a + * timestamp from platform + * to platform.** + * + * @since v1-alpha10 + */ +internal expect fun platformMilliseconds(): ULong diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/ProcessPlatform.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/ProcessPlatform.kt index 9f6f5a9..4563b2d 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/ProcessPlatform.kt +++ b/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/ProcessPlatform.kt @@ -37,8 +37,10 @@ abstract class ProcessPlatform ( /** * Initializes the process. * + * @throws Throwable on error * @since v1-alpha10 */ + @Throws(Throwable::class) abstract fun start() /** diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/Environment.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/Environment.kt index 1914a72..f5fe26a 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/Environment.kt +++ b/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/Environment.kt @@ -22,6 +22,7 @@ package de.staropensource.engine.base.utility import de.staropensource.engine.base.type.environment.GraphicsCard import de.staropensource.engine.base.type.environment.OperatingSystem import kotlinx.datetime.Instant +import kotlin.jvm.JvmStatic /** * Provides information about the diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/Process.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/Process.kt index a40be7a..c0b0124 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/Process.kt +++ b/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/Process.kt @@ -27,8 +27,8 @@ import de.staropensource.engine.base.implementable.stream.ReadStream import de.staropensource.engine.base.implementable.stream.Stream import de.staropensource.engine.base.implementable.stream.WriteStream import de.staropensource.engine.base.platform.ProcessPlatform +import de.staropensource.engine.base.platform.platformMilliseconds import de.staropensource.engine.base.platform.platformProcessCreate -import java.io.IOException import kotlin.Throws /** @@ -161,7 +161,7 @@ class Process : PlatformData { // Set properties this.executable = executable this.arguments = arguments - this.workingDirectory = workingDirectory ?: FileAccess(System.getProperty("user.dir")) + this.workingDirectory = workingDirectory ?: FileAccess.temporaryCacheDirectory!! this.launchedWithFreshEnvironment = freshEnvironment this.environmentVariables = environmentVariables.toMap() this.exitEvents = exitEvents.toMutableList() @@ -184,8 +184,8 @@ class Process : PlatformData { standardOutput.watch() standardError.watch() } - } catch (exception: IOException) { - throw IOAccessException("Unable to spawn new process", exception) + } catch (throwable: Throwable) { + throw IOAccessException("Unable to spawn new process", throwable) } } @@ -269,9 +269,9 @@ class Process : PlatformData { * @since v1-alpha10 */ fun waitForExit(maxTime: ULong = 0UL): Process { - val maxTimeReal: Long = System.currentTimeMillis().plus(maxTime.toLong()) + val maxTimeReal: ULong = platformMilliseconds() - while (maxTime == 0UL || System.currentTimeMillis() < maxTimeReal) + while (maxTime == 0UL || platformMilliseconds() < maxTimeReal) if (!isAlive()) break diff --git a/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/PlatformImpl.kt b/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/PlatformImpl.kt index 1bce42e..49e4636 100644 --- a/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/PlatformImpl.kt +++ b/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/PlatformImpl.kt @@ -20,3 +20,4 @@ package de.staropensource.engine.base.platform actual fun platformTerminate(exitcode: UByte) = Runtime.getRuntime().exit(exitcode.toInt()) +actual fun platformMilliseconds(): ULong = System.currentTimeMillis().toULong()