From d8422f9cc9be75a301faf389299b841658297b3a Mon Sep 17 00:00:00 2001 From: Scyu_ Date: Mon, 28 Oct 2024 22:17:07 +0000 Subject: [PATCH] chore: fix tests --- .../geary/prefabs/PrefabsDSLExtensions.kt | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/addons/geary-prefabs/src/jvmMain/kotlin/com/mineinabyss/geary/prefabs/PrefabsDSLExtensions.kt b/addons/geary-prefabs/src/jvmMain/kotlin/com/mineinabyss/geary/prefabs/PrefabsDSLExtensions.kt index f0464e33..2216e41c 100644 --- a/addons/geary-prefabs/src/jvmMain/kotlin/com/mineinabyss/geary/prefabs/PrefabsDSLExtensions.kt +++ b/addons/geary-prefabs/src/jvmMain/kotlin/com/mineinabyss/geary/prefabs/PrefabsDSLExtensions.kt @@ -4,9 +4,12 @@ import kotlinx.io.asSource import kotlinx.io.buffered import kotlinx.io.files.Path import java.io.File -import java.io.InputStream +import java.nio.file.FileSystems import java.util.jar.JarFile -import kotlin.io.path.* +import kotlin.io.path.ExperimentalPathApi +import kotlin.io.path.isRegularFile +import kotlin.io.path.pathString +import kotlin.io.path.walk import kotlin.reflect.KClass object PrefabsDSLExtensions { @@ -60,11 +63,14 @@ object PrefabsDSLExtensions { while (entries.hasMoreElements()) { val entry = entries.nextElement() if (entry.name.startsWith(directory) && !entry.isDirectory) { - yield(JarResource( - classLoader, - path = entry.name.substringAfter(directory).removePrefix("/"), - resource = entry.name - )) + yield( + JarResource( + classLoader, + path = entry.name.substringAfter(directory) + .removePrefix(FileSystems.getDefault().separator), + resource = entry.name + ) + ) } } } else if (protocol == "file") { @@ -72,8 +78,9 @@ object PrefabsDSLExtensions { yieldAll(directoryPath.walk().filter { it.isRegularFile() }.map { JarResource( classLoader, - path = it.toString().substringAfter(directoryPath.toString()).removePrefix("/"), - resource = it.toString() + path = it.toString().substringAfter(directoryPath.toString()) + .removePrefix(FileSystems.getDefault().separator), + resource = directory + it.toString().substringAfter(directoryPath.toString()) ) }) } @@ -101,7 +108,7 @@ object PrefabsDSLExtensions { val path: String, val resource: String ) { - val nameWithoutExt = path.substringAfterLast("/").substringBeforeLast(".") + val nameWithoutExt = path.substringAfterLast(FileSystems.getDefault().separator).substringBeforeLast(".") val ext = path.substringAfterLast(".") val stream = classLoader.getResourceAsStream(resource)!! }