summaryrefslogtreecommitdiff
path: root/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ExtractNativesTask.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-06-19 03:37:52 +0200
committerLinnea Gräf <nea@nea.moe>2024-06-19 03:37:52 +0200
commit4b077b1a9c9a262cf730796f3876a86d6fa1064b (patch)
treea660180847b995d607949bc4e950876efdbc7cde /plugin/src/main/kotlin/moe/nea/archenemy/mojang/ExtractNativesTask.kt
parent4d778b97ee33485af5236ad6bdfdd2949fd69cc2 (diff)
downloadarchenemy-4b077b1a9c9a262cf730796f3876a86d6fa1064b.tar.gz
archenemy-4b077b1a9c9a262cf730796f3876a86d6fa1064b.tar.bz2
archenemy-4b077b1a9c9a262cf730796f3876a86d6fa1064b.zip
Add more code to make the client run workHEADmaster
Diffstat (limited to 'plugin/src/main/kotlin/moe/nea/archenemy/mojang/ExtractNativesTask.kt')
-rw-r--r--plugin/src/main/kotlin/moe/nea/archenemy/mojang/ExtractNativesTask.kt45
1 files changed, 45 insertions, 0 deletions
diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ExtractNativesTask.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ExtractNativesTask.kt
new file mode 100644
index 0000000..a3c33ed
--- /dev/null
+++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ExtractNativesTask.kt
@@ -0,0 +1,45 @@
+package moe.nea.archenemy.mojang
+
+import moe.nea.archenemy.util.readZipFs
+import org.gradle.api.DefaultTask
+import org.gradle.api.file.DirectoryProperty
+import org.gradle.api.provider.ListProperty
+import org.gradle.api.tasks.Input
+import org.gradle.api.tasks.Internal
+import org.gradle.api.tasks.OutputDirectory
+import org.gradle.api.tasks.TaskAction
+import java.io.File
+
+abstract class ExtractNativesTask : DefaultTask() {
+
+ @get:OutputDirectory
+ abstract val nativeDirectory: DirectoryProperty
+
+ @get:Input
+ abstract val natives: ListProperty<MojangVersionMetadata.Library>
+
+ @Internal
+ fun getNativeDirectoryPath(): File {
+ return nativeDirectory.get().asFile
+ }
+
+ @TaskAction
+ fun extractNatives() {
+ val nativeDirectory = nativeDirectory.get().asFile
+ natives.get().forEach {
+ val extract = it.extract ?: return@forEach
+ val file = project.configurations
+ .detachedConfiguration(project.dependencies.create(it.getArtifactCoordinate()))
+ .files
+ .single().toPath()
+ file.readZipFs { path, inputStream ->
+ if (extract.exclude.any { path.startsWith(it) }) return@readZipFs
+ val targetFile = nativeDirectory.resolve(path)
+ targetFile.parentFile.mkdirs()
+ targetFile.outputStream().use { output ->
+ inputStream.copyTo(output)
+ }
+ }
+ }
+ }
+} \ No newline at end of file