Fix version checking, add file validation

This commit is contained in:
Him188 2020-05-06 15:51:34 +08:00
parent b732b9731a
commit 8721c60493
3 changed files with 30 additions and 21 deletions

View File

@ -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"
}

View File

@ -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-")
}

View File

@ -122,6 +122,7 @@ object WrapperCli : CliktCommand(name = "mirai-warpper") {
}
WrapperMain.start(ConsoleType.Graphical)
} else {
WrapperMain.preStartInNonNative(console, update)
}
@ -192,13 +193,24 @@ object WrapperMain {
}
internal fun start(type: ConsoleType) {
val loader = MiraiClassLoader(
CoreUpdater.getProtocolLib()!!,
ConsoleUpdater.getFile()!!,
WrapperMain::class.java.classLoader
)
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"
@ -207,7 +219,12 @@ object WrapperMain {
}
).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()
}
}
}