mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
91 lines
2.8 KiB
Groovy
91 lines
2.8 KiB
Groovy
|
|
import java.security.MessageDigest
|
|
|
|
def downloadFiles = [
|
|
[
|
|
name: 'Minecraft26.2.jar',
|
|
url: 'https://piston-data.mojang.com/v1/objects/2dc72797acbc1b63fc16a11c4ac393605f453754/client.jar',
|
|
path: 'libraries/minecraft/Minecraft26.2.jar',
|
|
sha1: '2dc72797acbc1b63fc16a11c4ac393605f453754'
|
|
],
|
|
[
|
|
name: 'brigadier-1.3.10.jar',
|
|
url: 'https://libraries.minecraft.net/com/mojang/brigadier/1.3.10/brigadier-1.3.10.jar',
|
|
path: 'libraries/minecraft/com/mojang/brigadier/1.3.10/brigadier-1.3.10.jar',
|
|
sha1: 'd15b53a14cf20fdcaa98f731af5dda654452c010'
|
|
]
|
|
]
|
|
|
|
def downloadDependencies = tasks.register('downloadDependencies') {
|
|
outputs.files(downloadFiles.collect {
|
|
rootProject.file(it.path)
|
|
})
|
|
|
|
doLast {
|
|
downloadFiles.each { dependency ->
|
|
File target = rootProject.file(dependency.path)
|
|
|
|
if (target.exists()) {
|
|
String checksum = MessageDigest.getInstance('SHA-1')
|
|
.digest(target.bytes)
|
|
.encodeHex()
|
|
.toString()
|
|
|
|
if (checksum == dependency.sha1) {
|
|
println "[OrangeX] Already downloaded: ${dependency.name}"
|
|
return
|
|
}
|
|
}
|
|
|
|
target.parentFile.mkdirs()
|
|
|
|
File temp = new File(target.parentFile, target.name + '.tmp')
|
|
|
|
try {
|
|
println "[OrangeX] Downloading: ${dependency.name}"
|
|
|
|
def connection = new URL(dependency.url).openConnection()
|
|
connection.connectTimeout = 15000
|
|
connection.readTimeout = 120000
|
|
|
|
connection.inputStream.withCloseable { input ->
|
|
temp.withOutputStream { output ->
|
|
output << input
|
|
}
|
|
}
|
|
|
|
String checksum = MessageDigest.getInstance('SHA-1')
|
|
.digest(temp.bytes)
|
|
.encodeHex()
|
|
.toString()
|
|
|
|
if (checksum != dependency.sha1) {
|
|
throw new GradleException(
|
|
"SHA-1 mismatch: ${dependency.name}"
|
|
)
|
|
}
|
|
|
|
if (!temp.renameTo(target)) {
|
|
throw new GradleException(
|
|
"Failed to move: ${dependency.name}"
|
|
)
|
|
}
|
|
|
|
println "[OrangeX] Downloaded: ${dependency.name}"
|
|
|
|
} finally {
|
|
temp.delete()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
tasks.named('build') {
|
|
dependsOn downloadDependencies
|
|
}
|
|
|
|
rootProject.subprojects {
|
|
tasks.withType(JavaCompile).configureEach {
|
|
dependsOn downloadDependencies
|
|
}
|
|
} |