mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-11 04:43:51 +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
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
const val CONSOLE_PURE = "Pure"
|
const val CONSOLE_PURE = "Pure"
|
||||||
|
const val CONSOLE_TERMINAL = "Terminal"
|
||||||
|
const val CONSOLE_GRAPHICAL = "Graphical"
|
||||||
|
|
||||||
|
|
||||||
object ConsoleUpdator{
|
object ConsoleUpdator{
|
||||||
|
|
||||||
@ -77,7 +80,7 @@ object ConsoleUpdator{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCurrentVersion():String{
|
fun getCurrentVersion():String{
|
||||||
val file = getFile()
|
val file = getFile()
|
||||||
if(file != null) {
|
if(file != null) {
|
||||||
val numberVersion = """([0-9])*\.([0-9])*\.([0-9])*""".toRegex().find(file.name)?.value
|
val numberVersion = """([0-9])*\.([0-9])*\.([0-9])*""".toRegex().find(file.name)?.value
|
||||||
@ -104,7 +107,4 @@ object ConsoleUpdator{
|
|||||||
LibManager.clearLibs()
|
LibManager.clearLibs()
|
||||||
LibManager.addDependencyRequest("net/mamoe",getProjectName(),version)
|
LibManager.addDependencyRequest("net/mamoe",getProjectName(),version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -40,6 +40,7 @@ object CoreUpdator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
suspend fun versionCheck(){
|
suspend fun versionCheck(){
|
||||||
println("Fetching Newest Core Version .. ")
|
println("Fetching Newest Core Version .. ")
|
||||||
val newest = getNewestVersion()
|
val newest = getNewestVersion()
|
||||||
@ -91,7 +92,7 @@ object CoreUpdator {
|
|||||||
* 判断当前版本
|
* 判断当前版本
|
||||||
* 默认返回 "0.0.0"
|
* 默认返回 "0.0.0"
|
||||||
*/
|
*/
|
||||||
private fun getCurrentVersion(): String {
|
fun getCurrentVersion(): String {
|
||||||
val file = getProtocolLib()
|
val file = getProtocolLib()
|
||||||
if (file == null || getCore() == null) return "0.0.0"
|
if (file == null || getCore() == null) return "0.0.0"
|
||||||
val numberVersion = """([0-9])*\.([0-9])*\.([0-9])*""".toRegex().find(file.name)?.value
|
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 kotlinx.coroutines.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.URLClassLoader
|
import java.net.URLClassLoader
|
||||||
|
import java.util.*
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
|
|
||||||
@ -33,12 +34,27 @@ object WrapperMain {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
println("You are running Mirai-Console-Wrapper under " + System.getProperty("user.dir"))
|
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 {
|
runBlocking {
|
||||||
launch {
|
launch {
|
||||||
CoreUpdator.versionCheck()
|
CoreUpdator.versionCheck()
|
||||||
@ -59,11 +75,15 @@ object WrapperMain {
|
|||||||
ConsoleUpdator.getFile()!!,
|
ConsoleUpdator.getFile()!!,
|
||||||
this.javaClass.classLoader
|
this.javaClass.classLoader
|
||||||
)
|
)
|
||||||
|
when(type) {
|
||||||
|
CONSOLE_PURE -> {
|
||||||
loader.loadClass("net.mamoe.mirai.BotFactoryJvm")
|
loader.loadClass("net.mamoe.mirai.BotFactoryJvm")
|
||||||
loader.loadClass(
|
loader.loadClass(
|
||||||
"net.mamoe.mirai.console.pure.MiraiConsolePureLoader"
|
"net.mamoe.mirai.console.pure.MiraiConsolePureLoader"
|
||||||
).getMethod("main", Array<String>(0) {"null"}.javaClass)
|
).getMethod("load", String::class.java,String::class.java)
|
||||||
.invoke(null,args)
|
.invoke(null,CoreUpdator.getCurrentVersion(),ConsoleUpdator.getCurrentVersion())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,3 +97,27 @@ class MiraiClassLoader(
|
|||||||
protocol.toURI().toURL(),
|
protocol.toURI().toURL(),
|
||||||
console.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")
|
id("com.jfrog.bintray")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
apply(plugin = "com.github.johnrengelman.shadow")
|
||||||
|
|
||||||
val kotlinVersion: String by rootProject.ext
|
val kotlinVersion: String by rootProject.ext
|
||||||
val atomicFuVersion: String by rootProject.ext
|
val atomicFuVersion: String by rootProject.ext
|
||||||
val coroutinesVersion: String by rootProject.ext
|
val coroutinesVersion: String by rootProject.ext
|
||||||
|
@ -24,12 +24,10 @@ import net.mamoe.mirai.utils.cryptor.ECDH
|
|||||||
|
|
||||||
object MiraiConsole {
|
object MiraiConsole {
|
||||||
/**
|
/**
|
||||||
* 发布的版本号 统一修改位置
|
* 发布的版本名
|
||||||
*/
|
*/
|
||||||
const val version = "0.3.1"
|
const val build = "Pkmon"
|
||||||
const val coreVersion = "v0.23.0"
|
lateinit var version:String
|
||||||
const val build = "Alpha"
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取从Console登陆上的Bot, Bots
|
* 获取从Console登陆上的Bot, Bots
|
||||||
@ -61,8 +59,11 @@ object MiraiConsole {
|
|||||||
*/
|
*/
|
||||||
var start = false
|
var start = false
|
||||||
|
|
||||||
|
|
||||||
fun start(
|
fun start(
|
||||||
frontEnd: MiraiConsoleUI
|
frontEnd: MiraiConsoleUI,
|
||||||
|
coreVersion: String = "0.0.0",
|
||||||
|
consoleVersion: String = "0.0.0"
|
||||||
) {
|
) {
|
||||||
if (start) {
|
if (start) {
|
||||||
return
|
return
|
||||||
@ -70,14 +71,14 @@ object MiraiConsole {
|
|||||||
start = true
|
start = true
|
||||||
|
|
||||||
/* 初始化前端 */
|
/* 初始化前端 */
|
||||||
|
this.version = consoleVersion
|
||||||
this.frontEnd = frontEnd
|
this.frontEnd = frontEnd
|
||||||
frontEnd.pushVersion(version, build, "Loading")
|
this.frontEnd.pushVersion(consoleVersion, build, coreVersion)
|
||||||
logger("Mirai-console now running under $path")
|
logger("Mirai-console now running under $path")
|
||||||
logger("Get news in github: https://github.com/mamoe/mirai")
|
logger("Get news in github: https://github.com/mamoe/mirai")
|
||||||
logger("Mirai为开源项目,请自觉遵守开源项目协议")
|
logger("Mirai为开源项目,请自觉遵守开源项目协议")
|
||||||
logger("Powered by Mamoe Technologies and contributors")
|
logger("Powered by Mamoe Technologies and contributors")
|
||||||
|
|
||||||
|
|
||||||
/* 加载ECDH */
|
/* 加载ECDH */
|
||||||
try {
|
try {
|
||||||
ECDH()
|
ECDH()
|
||||||
|
@ -15,8 +15,15 @@ import kotlin.concurrent.thread
|
|||||||
class MiraiConsolePureLoader {
|
class MiraiConsolePureLoader {
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun load(
|
||||||
MiraiConsole.start(MiraiConsoleUIPure())
|
coreVersion: String,
|
||||||
|
consoleVersion: String
|
||||||
|
) {
|
||||||
|
MiraiConsole.start(
|
||||||
|
MiraiConsoleUIPure(),
|
||||||
|
coreVersion,
|
||||||
|
consoleVersion
|
||||||
|
)
|
||||||
Runtime.getRuntime().addShutdownHook(thread(start = false) {
|
Runtime.getRuntime().addShutdownHook(thread(start = false) {
|
||||||
MiraiConsole.stop()
|
MiraiConsole.stop()
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user