mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Fix version checking, add file validation
This commit is contained in:
parent
b732b9731a
commit
8721c60493
@ -46,7 +46,7 @@ internal object ConsoleUpdater {
|
||||
if (file.name.contains("mirai-console")) {
|
||||
when (consoleType) {
|
||||
ConsoleType.Pure -> {
|
||||
if (!file.name.contains("pure")) {
|
||||
if (!file.name.contains("graphical")) {
|
||||
return file
|
||||
}
|
||||
}
|
||||
@ -68,7 +68,7 @@ internal object ConsoleUpdater {
|
||||
suspend fun versionCheck(type: ConsoleType, strategy: VersionUpdateStrategy) {
|
||||
this.consoleType = type
|
||||
println("Fetching Newest Console Version of $type")
|
||||
val current = CoreUpdater.getCurrentVersion()
|
||||
val current = getCurrentVersion()
|
||||
if (current != "0.0.0" && strategy == VersionUpdateStrategy.KEEP) {
|
||||
println("Stay on current version.")
|
||||
return
|
||||
@ -97,10 +97,7 @@ internal object ConsoleUpdater {
|
||||
fun getCurrentVersion(): String {
|
||||
val file = getFile()
|
||||
if (file != null) {
|
||||
val numberVersion = """([0-9])*\.([0-9])*\.([0-9])*""".toRegex().find(file.name)?.value
|
||||
if (numberVersion != null) {
|
||||
return numberVersion + file.name.substringAfter(numberVersion).substringBefore(".jar")
|
||||
}
|
||||
return file.name.substringAfter(getProjectName() + "-").substringBefore(".jar")
|
||||
}
|
||||
return "0.0.0"
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ internal object CoreUpdater {
|
||||
getContent("mirai-core-qqandroid-jvm-$newest.jar")
|
||||
)
|
||||
//.addTask("https://raw.githubusercontent.com/mamoe/mirai-repo/master/shadow/mirai-core-qqandroid/mirai-core-qqandroid-$newest.jar", getContent("mirai-core-qqandroid-jvm-$newest.jar"))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,11 +53,7 @@ internal object CoreUpdater {
|
||||
*/
|
||||
fun getCurrentVersion(): String {
|
||||
val file = getProtocolLib() ?: return "0.0.0"
|
||||
val numberVersion = """([0-9])*\.([0-9])*\.([0-9])*""".toRegex().find(file.name)?.value
|
||||
if (numberVersion != null) {
|
||||
return numberVersion + file.name.substringAfter(numberVersion).substringBefore(".jar")
|
||||
}
|
||||
return "0.0.0"
|
||||
return file.name.substringBefore(".jar").substringAfter("mirai-core-qqandroid-jvm-")
|
||||
}
|
||||
|
||||
|
||||
|
@ -122,6 +122,7 @@ object WrapperCli : CliktCommand(name = "mirai-warpper") {
|
||||
}
|
||||
|
||||
WrapperMain.start(ConsoleType.Graphical)
|
||||
|
||||
} else {
|
||||
WrapperMain.preStartInNonNative(console, update)
|
||||
}
|
||||
@ -192,22 +193,38 @@ object WrapperMain {
|
||||
}
|
||||
|
||||
internal fun start(type: ConsoleType) {
|
||||
|
||||
val loader = MiraiClassLoader(
|
||||
CoreUpdater.getProtocolLib()!!,
|
||||
ConsoleUpdater.getFile()!!,
|
||||
WrapperMain::class.java.classLoader
|
||||
)
|
||||
|
||||
loader.loadClass("net.mamoe.mirai.BotFactoryJvm")
|
||||
loader.loadClass(
|
||||
when (type) {
|
||||
ConsoleType.Pure -> "net.mamoe.mirai.console.pure.MiraiConsolePureLoader"
|
||||
ConsoleType.Graphical -> "net.mamoe.mirai.console.graphical.MiraiConsoleGraphicalLoader"
|
||||
else -> return
|
||||
}
|
||||
).getMethod("load", String::class.java, String::class.java)
|
||||
.invoke(null, CoreUpdater.getCurrentVersion(), ConsoleUpdater.getCurrentVersion())
|
||||
try {
|
||||
loader.loadClass("net.mamoe.mirai.BotFactoryJvm")
|
||||
} catch (e: ClassNotFoundException) {
|
||||
System.err.println("Found mirai-core file broken, re-downloading...")
|
||||
loader.close()
|
||||
CoreUpdater.getProtocolLib()?.delete()
|
||||
WrapperCli.run()
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
loader.loadClass(
|
||||
when (type) {
|
||||
ConsoleType.Pure -> "net.mamoe.mirai.console.pure.MiraiConsolePureLoader"
|
||||
ConsoleType.Graphical -> "net.mamoe.mirai.console.graphical.MiraiConsoleGraphicalLoader"
|
||||
else -> return
|
||||
}
|
||||
).getMethod("load", String::class.java, String::class.java)
|
||||
.invoke(null, CoreUpdater.getCurrentVersion(), ConsoleUpdater.getCurrentVersion())
|
||||
} catch (e: ClassNotFoundException) {
|
||||
System.err.println("Found mirai-console file broken, re-downloading...")
|
||||
loader.close()
|
||||
ConsoleUpdater.getFile()?.delete()
|
||||
WrapperCli.run()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user