Don't extract ZIPs, just bundle them

This commit is contained in:
dfsek
2020-12-04 22:30:30 -07:00
parent b5fdeef535
commit a38fcef6f1
+8 -16
View File
@@ -1,3 +1,4 @@
//import java.util.zip.ZipFile
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.net.URL import java.net.URL
@@ -5,8 +6,6 @@ import java.nio.channels.Channels
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Paths import java.nio.file.Paths
import java.nio.file.StandardCopyOption import java.nio.file.StandardCopyOption
//import java.util.zip.ZipFile
import java.util.zip.ZipInputStream
plugins { plugins {
java java
@@ -164,9 +163,9 @@ val downloadDefaultPacks = tasks.create("downloadDefaultPacks") {
file("${buildDir}/resources/main/packs/").deleteRecursively() file("${buildDir}/resources/main/packs/").deleteRecursively()
val defaultPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/default.zip") val defaultPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/default.zip")
downloadAndUnzipPack(defaultPackUrl) downloadPack(defaultPackUrl)
val netherPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/nether.zip") val netherPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/nether.zip")
downloadAndUnzipPack(netherPackUrl) downloadPack(netherPackUrl)
} }
} }
tasks.processResources.get().dependsOn(downloadDefaultPacks) tasks.processResources.get().dependsOn(downloadDefaultPacks)
@@ -229,16 +228,9 @@ fun gitClone(name: String) {
} }
} }
fun downloadAndUnzipPack(packUrl: URL) { fun downloadPack(packUrl: URL) {
ZipInputStream(packUrl.openStream()).use { zip -> val fileName = packUrl.file.substring(packUrl.file.lastIndexOf("/"))
while (true) { val file = file("${buildDir}/resources/main/packs/${fileName}")
val entry = zip.nextEntry ?: break file.parentFile.mkdirs()
if (entry.isDirectory) file.outputStream().write(packUrl.readBytes())
file("${buildDir}/resources/main/packs/${entry.name}").mkdirs()
else
file("${buildDir}/resources/main/packs/${entry.name}").outputStream().use { output ->
output.write(zip.readBytes())
}
}
}
} }