experimental 1.7.10 fixes, improved version comparison in update checker

This commit is contained in:
NikkyAI 2018-02-19 16:03:37 +01:00
parent 6a77fbc3f3
commit 82c550f37f
3 changed files with 41 additions and 19 deletions

View File

@ -35,7 +35,6 @@ minecraft {
srgExtra "PK: kotlin matterlink/repack/kotlin" srgExtra "PK: kotlin matterlink/repack/kotlin"
srgExtra "PK: org/jetbrains/annotations matterlink/repack/org/jetbrains/annotations" srgExtra "PK: org/jetbrains/annotations matterlink/repack/org/jetbrains/annotations"
srgExtra "PK: com/google/gson matterlink/repack/com/google/gson" srgExtra "PK: com/google/gson matterlink/repack/com/google/gson"
srgExtra "PK: org/apache/commons matterlink/repack/org/apache/commons"
srgExtra "PK: org/apache/http matterlink/repack/org/apache/http" srgExtra "PK: org/apache/http matterlink/repack/org/apache/http"
srgExtra "PK: org/intelij matterlink/repack/org/intelij" srgExtra "PK: org/intelij matterlink/repack/org/intelij"
} }

View File

@ -16,14 +16,20 @@ class UpdateChecker : Runnable {
override fun run() { override fun run() {
val gson = Gson() val gson = Gson()
val currentModVersion = instance.modVersion
val currentMCVersion = instance.mcVersion
val currentVersion = currentMCVersion + "-" + currentModVersion
instance.info("Checking for new versions...") instance.info("Checking for new versions...")
if (instance.modVersion.endsWith("-dev")) {
}
val client: HttpClient = HttpClients.createDefault() val client: HttpClient = HttpClients.createDefault()
val response: HttpResponse = client.execute(HttpGet("http://bit.ly/matterlinkfiles")) val request = HttpGet("https://goo.gl/5CMc1N")
with(instance) {
request.setHeader("User-Agent", "Minecraft/$mcVersion MatterLink/$modVersion")
}
val response: HttpResponse = client.execute(request)
val apiUpdateList = if (200 == response.statusLine.statusCode) { //HTTP 200 OK val apiUpdateList = if (200 == response.statusLine.statusCode) { //HTTP 200 OK
val buffer: BufferedReader = response.entity.content.bufferedReader() val buffer: BufferedReader = response.entity.content.bufferedReader()
@ -33,7 +39,7 @@ class UpdateChecker : Runnable {
gson.fromJson(content, Array<CurseFile>::class.java) gson.fromJson(content, Array<CurseFile>::class.java)
.filter { .filter {
it.gameVersion.contains(currentMCVersion) it.gameVersion.contains(instance.mcVersion)
} }
.sortedByDescending { it.fileName.substringAfterLast(" ") } .sortedByDescending { it.fileName.substringAfterLast(" ") }
@ -42,31 +48,48 @@ class UpdateChecker : Runnable {
return return
} }
val modVersionChunks = instance.modVersion
.replace("-dev", "")
.split('.')
.map {
it.toInt()
}
val possibleUpdates = mutableListOf<CurseFile>() val possibleUpdates = mutableListOf<CurseFile>()
apiUpdateList.forEach { apiUpdateList.forEach {
instance.debug(it.toString()) instance.debug(it.toString())
val version = it.fileName.substringAfter("-") val version = it.fileName.substringAfterLast("-").split('.').map { it.toInt() }
if(version > currentModVersion) var bigger = false
{ version.forEachIndexed { index, chunk ->
if (!bigger) {
val currentChunk = modVersionChunks.getOrNull(index) ?: 0
instance.debug("$chunk > $currentChunk")
if(chunk < currentChunk)
return@forEach
bigger = chunk > currentChunk
}
}
if (bigger) {
possibleUpdates += it possibleUpdates += it
} }
} }
if(possibleUpdates.isEmpty()) return if (possibleUpdates.isEmpty()) return
val latest= possibleUpdates[0] val latest = possibleUpdates[0]
possibleUpdates.sortByDescending { it.fileName.substringAfter(" ") } possibleUpdates.sortByDescending { it.fileName.substringAfter(" ") }
val count = possibleUpdates.count() val count = possibleUpdates.count()
val version = if(count == 1) "version" else "versions" val version = if (count == 1) "version" else "versions"
instance.info("Matterlink out of date! You are $count $version behind") instance.info("Matterlink out of date! You are $count $version behind")
possibleUpdates.forEach { possibleUpdates.forEach {
instance.info("version: {} download: {}", it.fileName, it.downloadURL) instance.info("version: {} download: {}", it.fileName, it.downloadURL)
} }
instance.warn("Mod out of date! New $version available at ${latest.downloadURL}") instance.warn("Mod out of date! New $version available at ${latest.downloadURL}")
MessageHandler.transmit(ApiMessage( // MessageHandler.transmit(ApiMessage(
username = cfg.relay.systemUser, // username = cfg.relay.systemUser,
text = "Matterlink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}" // text = "Matterlink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}"
)) // ))
} }
} }

View File

@ -1,3 +1,3 @@
mod_name = MatterLink mod_name = MatterLink
mod_version = 1.4.3 mod_version = 1.4.4
forgelin_version = 1.6.0 forgelin_version = 1.6.0