@@ -4,9 +4,12 @@ import kotlinx.io.asSource
4
4
import kotlinx.io.buffered
5
5
import kotlinx.io.files.Path
6
6
import java.io.File
7
- import java.io.InputStream
7
+ import java.nio.file.FileSystems
8
8
import java.util.jar.JarFile
9
- import kotlin.io.path.*
9
+ import kotlin.io.path.ExperimentalPathApi
10
+ import kotlin.io.path.isRegularFile
11
+ import kotlin.io.path.pathString
12
+ import kotlin.io.path.walk
10
13
import kotlin.reflect.KClass
11
14
12
15
object PrefabsDSLExtensions {
@@ -60,20 +63,24 @@ object PrefabsDSLExtensions {
60
63
while (entries.hasMoreElements()) {
61
64
val entry = entries.nextElement()
62
65
if (entry.name.startsWith(directory) && ! entry.isDirectory) {
63
- yield (JarResource (
64
- classLoader,
65
- path = entry.name.substringAfter(directory).removePrefix(" /" ),
66
- resource = entry.name
67
- ))
66
+ yield (
67
+ JarResource (
68
+ classLoader,
69
+ path = entry.name.substringAfter(directory)
70
+ .removePrefix(FileSystems .getDefault().separator),
71
+ resource = entry.name
72
+ )
73
+ )
68
74
}
69
75
}
70
76
} else if (protocol == " file" ) {
71
77
val directoryPath = File (classLoader.getResource(directory)?.toURI() ? : return @sequence).toPath()
72
78
yieldAll(directoryPath.walk().filter { it.isRegularFile() }.map {
73
79
JarResource (
74
80
classLoader,
75
- path = it.toString().substringAfter(directoryPath.toString()).removePrefix(" /" ),
76
- resource = it.toString()
81
+ path = it.toString().substringAfter(directoryPath.toString())
82
+ .removePrefix(FileSystems .getDefault().separator),
83
+ resource = directory + it.toString().substringAfter(directoryPath.toString())
77
84
)
78
85
})
79
86
}
@@ -101,7 +108,7 @@ object PrefabsDSLExtensions {
101
108
val path : String ,
102
109
val resource : String
103
110
) {
104
- val nameWithoutExt = path.substringAfterLast(" / " ).substringBeforeLast(" ." )
111
+ val nameWithoutExt = path.substringAfterLast(FileSystems .getDefault().separator ).substringBeforeLast(" ." )
105
112
val ext = path.substringAfterLast(" ." )
106
113
val stream = classLoader.getResourceAsStream(resource)!!
107
114
}
0 commit comments