mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-09 18:00:33 +08:00
more simple download task
This commit is contained in:
parent
24e7bf41a9
commit
daffe2c9d6
@ -89,22 +89,20 @@ object ConsoleUpdator{
|
||||
return "0.0.0"
|
||||
}
|
||||
|
||||
private fun getProjectName():String{
|
||||
return if (consoleType == CONSOLE_PURE) {
|
||||
"mirai-console"
|
||||
} else {
|
||||
"mirai-console-$consoleType"
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun downloadConsole(version:String){
|
||||
tryNTimesOrQuit(3,"Failed to download Console, please seek for help") {
|
||||
kotlin.runCatching {
|
||||
println("Downloading newest Console from Aliyun")
|
||||
Http.downloadRequest(Links[consoleType]!!["aliyun"] ?: error("Unknown Console Type"), version)
|
||||
}.getOrElse {
|
||||
println("Downloading newest Console from JCenter")
|
||||
Http.downloadRequest(Links[consoleType]!!["jcenter"] ?: error("Unknown Console Type"), version)
|
||||
}
|
||||
.saveToContent(if (consoleType == CONSOLE_PURE) {
|
||||
"mirai-console-$version.jar"
|
||||
} else {
|
||||
"mirai-console-$consoleType-$version.jar"
|
||||
})
|
||||
|
||||
Http.downloadMavenArchive("net/mamoe",getProjectName(),version)
|
||||
.saveToContent("${getProjectName()}-$version.jar")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -125,25 +125,15 @@ object CoreUpdator {
|
||||
coroutineScope {
|
||||
launch {
|
||||
tryNTimesOrQuit(3,"Failed to download newest Protocol lib, please seek for help") {
|
||||
kotlin.runCatching {
|
||||
println("Downloading newest Protocol lib from Aliyun")
|
||||
Http.downloadRequest(Links.libAliyun, version)
|
||||
}.getOrElse {
|
||||
println("Downloading newest Protocol lib from JCenter")
|
||||
Http.downloadRequest(Links.libJcenter, version)
|
||||
}.saveToContent("mirai-core-qqandroid-jvm-$version.jar")
|
||||
Http.downloadMavenArchive("net/mamoe","mirai-core-qqandroid-jvm",version)
|
||||
.saveToContent("mirai-core-qqandroid-jvm-$version.jar")
|
||||
}
|
||||
}
|
||||
|
||||
launch {
|
||||
tryNTimesOrQuit(3,"Failed to download newest core, please seek for help") {
|
||||
kotlin.runCatching {
|
||||
println("Downloading newest Mirai Core from Aliyun")
|
||||
Http.downloadRequest(Links.coreAliyun, version)
|
||||
}.getOrElse {
|
||||
println("Downloading newest Mirai Core from JCenter")
|
||||
Http.downloadRequest(Links.coreJcenter, version)
|
||||
}.saveToContent("mirai-core-jvm-$version.jar")
|
||||
Http.downloadMavenArchive("net/mamoe","mirai-core-jvm",version)
|
||||
.saveToContent("mirai-core-jvm-$version.jar")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,10 +37,73 @@ inline fun <R> tryNTimesOrQuit(repeat: Int, errorHint: String, block: (Int) -> R
|
||||
}
|
||||
|
||||
|
||||
suspend inline fun HttpClient.downloadRequest(url: String, version: String): ByteReadChannel {
|
||||
return this.get<HttpResponse>(url.replace("{version}", version)).content
|
||||
suspend inline fun HttpClient.downloadRequest(url: String): ByteReadChannel {
|
||||
return this.get<HttpResponse>(url).content
|
||||
}
|
||||
|
||||
private val jcenterPath = "https://jcenter.bintray.com/{group}/{project}/{version}/:{project}-{version}.{extension}"
|
||||
private val aliyunPath = "https://maven.aliyun.com/nexus/content/repositories/jcenter/{group}/{project}/{version}/{project}-{version}.{extension}"
|
||||
|
||||
|
||||
suspend fun HttpClient.downloadMaven(
|
||||
groupName: String,
|
||||
projectName: String,
|
||||
version: String,
|
||||
extension: String
|
||||
):ByteReadChannel{
|
||||
return kotlin.runCatching {
|
||||
downloadRequest(
|
||||
aliyunPath
|
||||
.replace(
|
||||
"{group}",groupName
|
||||
)
|
||||
.replace(
|
||||
"{project}",projectName
|
||||
)
|
||||
.replace(
|
||||
"{extension}",extension
|
||||
)
|
||||
.replace(
|
||||
"{version}",version
|
||||
)
|
||||
)
|
||||
}.getOrElse {
|
||||
downloadRequest(
|
||||
jcenterPath
|
||||
.replace(
|
||||
"{group}",groupName
|
||||
)
|
||||
.replace(
|
||||
"{project}",projectName
|
||||
)
|
||||
.replace(
|
||||
"{extension}",extension
|
||||
)
|
||||
.replace(
|
||||
"{version}",version
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
suspend inline fun HttpClient.downloadMavenArchive(
|
||||
groupName: String,
|
||||
projectName: String,
|
||||
version: String
|
||||
):ByteReadChannel{
|
||||
return downloadMaven(groupName,projectName,version,"jar")
|
||||
}
|
||||
|
||||
suspend inline fun HttpClient.downloadMavenPom(
|
||||
groupName: String,
|
||||
projectName: String,
|
||||
version: String
|
||||
):ByteReadChannel{
|
||||
return downloadMaven(groupName,projectName,version,"pom")
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 只要填content path后面的就可以
|
||||
*/
|
||||
|
@ -24,15 +24,27 @@ object LibManager{
|
||||
* 全部完成后使用 @link downloadIfNeeded()开始下载
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 由Pom content提供必要依赖
|
||||
* LibManager会检查所有dependency的dependency
|
||||
*/
|
||||
fun addDependencyByPom(pomContent:String){
|
||||
internal fun addDependencyByPom(pomContent:String){
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 由Pom Path提供必要依赖
|
||||
* LibManager会进行下载和递归处理
|
||||
*/
|
||||
fun addDependencyRequest(link:String){
|
||||
val stream = kotlin.runCatching {
|
||||
val jcenterPath = "https://jcenter.bintray.com/{group}/{project}/{version}/:{project}-{version}.pom"
|
||||
val aliyunPath = "https://maven.aliyun.com/nexus/content/repositories/jcenter/{group}/{project}/{version}/{project}-{version}.pom"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通的增加一个dependency
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user