mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-05 10:52:26 +08:00
version loader
This commit is contained in:
parent
2eda9e764a
commit
fe5ce262e9
@ -7,6 +7,9 @@ import kotlin.math.pow
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
const val CONSOLE_PURE = "Pure"
|
||||
const val CONSOLE_TERMINAL = "Terminal"
|
||||
const val CONSOLE_GRAPHICAL = "Graphical"
|
||||
|
||||
|
||||
object ConsoleUpdator{
|
||||
|
||||
@ -77,7 +80,7 @@ object ConsoleUpdator{
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCurrentVersion():String{
|
||||
fun getCurrentVersion():String{
|
||||
val file = getFile()
|
||||
if(file != null) {
|
||||
val numberVersion = """([0-9])*\.([0-9])*\.([0-9])*""".toRegex().find(file.name)?.value
|
||||
@ -104,7 +107,4 @@ object ConsoleUpdator{
|
||||
LibManager.clearLibs()
|
||||
LibManager.addDependencyRequest("net/mamoe",getProjectName(),version)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -40,6 +40,7 @@ object CoreUpdator {
|
||||
}
|
||||
|
||||
|
||||
|
||||
suspend fun versionCheck(){
|
||||
println("Fetching Newest Core Version .. ")
|
||||
val newest = getNewestVersion()
|
||||
@ -91,7 +92,7 @@ object CoreUpdator {
|
||||
* 判断当前版本
|
||||
* 默认返回 "0.0.0"
|
||||
*/
|
||||
private fun getCurrentVersion(): String {
|
||||
fun getCurrentVersion(): String {
|
||||
val file = getProtocolLib()
|
||||
if (file == null || getCore() == null) return "0.0.0"
|
||||
val numberVersion = """([0-9])*\.([0-9])*\.([0-9])*""".toRegex().find(file.name)?.value
|
||||
|
@ -18,6 +18,7 @@ import io.ktor.utils.io.jvm.javaio.copyTo
|
||||
import kotlinx.coroutines.*
|
||||
import java.io.File
|
||||
import java.net.URLClassLoader
|
||||
import java.util.*
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
|
||||
@ -33,12 +34,27 @@ object WrapperMain {
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
println("You are running Mirai-Console-Wrapper under " + System.getProperty("user.dir"))
|
||||
println("Starting version check...")
|
||||
/**
|
||||
* ask for type
|
||||
*/
|
||||
val type = CONSOLE_PURE
|
||||
|
||||
var type = WrapperProperties.determineConsoleType(WrapperProperties.content)
|
||||
if(type!=null){
|
||||
println("Starting Mirai Console $type, reset by clear /content/")
|
||||
}else{
|
||||
println("Please select Console Type")
|
||||
println("请选择 Console 版本")
|
||||
println("=> Pure : pure console")
|
||||
println("=> Graphical : [Not Supported Yet] graphical UI except unix")
|
||||
println("=> Terminal : [Not Supported Yet] console in unix")
|
||||
val scanner = Scanner(System.`in`)
|
||||
while (type == null){
|
||||
var input = scanner.next()
|
||||
input = input.toUpperCase()[0] + input.toLowerCase().substring(1)
|
||||
println("Selecting $input")
|
||||
type = WrapperProperties.determineConsoleType(input)
|
||||
}
|
||||
WrapperProperties.content = type
|
||||
}
|
||||
|
||||
println("Starting version check...")
|
||||
runBlocking {
|
||||
launch {
|
||||
CoreUpdator.versionCheck()
|
||||
@ -59,11 +75,15 @@ object WrapperMain {
|
||||
ConsoleUpdator.getFile()!!,
|
||||
this.javaClass.classLoader
|
||||
)
|
||||
loader.loadClass("net.mamoe.mirai.BotFactoryJvm")
|
||||
loader.loadClass(
|
||||
"net.mamoe.mirai.console.pure.MiraiConsolePureLoader"
|
||||
).getMethod("main", Array<String>(0) {"null"}.javaClass)
|
||||
.invoke(null,args)
|
||||
when(type) {
|
||||
CONSOLE_PURE -> {
|
||||
loader.loadClass("net.mamoe.mirai.BotFactoryJvm")
|
||||
loader.loadClass(
|
||||
"net.mamoe.mirai.console.pure.MiraiConsolePureLoader"
|
||||
).getMethod("load", String::class.java,String::class.java)
|
||||
.invoke(null,CoreUpdator.getCurrentVersion(),ConsoleUpdator.getCurrentVersion())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,4 +96,28 @@ class MiraiClassLoader(
|
||||
core.toURI().toURL(),
|
||||
protocol.toURI().toURL(),
|
||||
console.toURI().toURL()
|
||||
), parent)
|
||||
), parent)
|
||||
|
||||
|
||||
object WrapperProperties{
|
||||
val contentFile by lazy{
|
||||
File(contentPath.absolutePath + "/.wrapper.txt").also {
|
||||
if(!it.exists())it.createNewFile()
|
||||
}
|
||||
}
|
||||
|
||||
var content
|
||||
get() = contentFile.readText()
|
||||
set(value) = contentFile.writeText(value)
|
||||
|
||||
|
||||
fun determineConsoleType(
|
||||
type:String
|
||||
):String?{
|
||||
if(type == CONSOLE_PURE || type == CONSOLE_GRAPHICAL || type == CONSOLE_TERMINAL){
|
||||
return type
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
@ -8,6 +8,9 @@ plugins {
|
||||
id("com.jfrog.bintray")
|
||||
}
|
||||
|
||||
|
||||
apply(plugin = "com.github.johnrengelman.shadow")
|
||||
|
||||
val kotlinVersion: String by rootProject.ext
|
||||
val atomicFuVersion: String by rootProject.ext
|
||||
val coroutinesVersion: String by rootProject.ext
|
||||
|
@ -24,12 +24,10 @@ import net.mamoe.mirai.utils.cryptor.ECDH
|
||||
|
||||
object MiraiConsole {
|
||||
/**
|
||||
* 发布的版本号 统一修改位置
|
||||
* 发布的版本名
|
||||
*/
|
||||
const val version = "0.3.1"
|
||||
const val coreVersion = "v0.23.0"
|
||||
const val build = "Alpha"
|
||||
|
||||
const val build = "Pkmon"
|
||||
lateinit var version:String
|
||||
|
||||
/**
|
||||
* 获取从Console登陆上的Bot, Bots
|
||||
@ -61,8 +59,11 @@ object MiraiConsole {
|
||||
*/
|
||||
var start = false
|
||||
|
||||
|
||||
fun start(
|
||||
frontEnd: MiraiConsoleUI
|
||||
frontEnd: MiraiConsoleUI,
|
||||
coreVersion: String = "0.0.0",
|
||||
consoleVersion: String = "0.0.0"
|
||||
) {
|
||||
if (start) {
|
||||
return
|
||||
@ -70,14 +71,14 @@ object MiraiConsole {
|
||||
start = true
|
||||
|
||||
/* 初始化前端 */
|
||||
this.version = consoleVersion
|
||||
this.frontEnd = frontEnd
|
||||
frontEnd.pushVersion(version, build, "Loading")
|
||||
this.frontEnd.pushVersion(consoleVersion, build, coreVersion)
|
||||
logger("Mirai-console now running under $path")
|
||||
logger("Get news in github: https://github.com/mamoe/mirai")
|
||||
logger("Mirai为开源项目,请自觉遵守开源项目协议")
|
||||
logger("Powered by Mamoe Technologies and contributors")
|
||||
|
||||
|
||||
/* 加载ECDH */
|
||||
try {
|
||||
ECDH()
|
||||
|
@ -15,8 +15,15 @@ import kotlin.concurrent.thread
|
||||
class MiraiConsolePureLoader {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
MiraiConsole.start(MiraiConsoleUIPure())
|
||||
fun load(
|
||||
coreVersion: String,
|
||||
consoleVersion: String
|
||||
) {
|
||||
MiraiConsole.start(
|
||||
MiraiConsoleUIPure(),
|
||||
coreVersion,
|
||||
consoleVersion
|
||||
)
|
||||
Runtime.getRuntime().addShutdownHook(thread(start = false) {
|
||||
MiraiConsole.stop()
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user