From 82c550f37f2cdfc3f891b242ba7360e673d7999d Mon Sep 17 00:00:00 2001 From: NikkyAI Date: Mon, 19 Feb 2018 16:03:37 +0100 Subject: [PATCH] experimental 1.7.10 fixes, improved version comparison in update checker --- 1.7.10/build.gradle | 1 - .../kotlin/matterlink/update/UpdateChecker.kt | 57 +++++++++++++------ gradle.properties | 2 +- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/1.7.10/build.gradle b/1.7.10/build.gradle index 304edbe..f0e9cae 100644 --- a/1.7.10/build.gradle +++ b/1.7.10/build.gradle @@ -35,7 +35,6 @@ minecraft { srgExtra "PK: kotlin matterlink/repack/kotlin" srgExtra "PK: org/jetbrains/annotations matterlink/repack/org/jetbrains/annotations" 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/intelij matterlink/repack/org/intelij" } diff --git a/core/src/main/kotlin/matterlink/update/UpdateChecker.kt b/core/src/main/kotlin/matterlink/update/UpdateChecker.kt index 5990ef6..30f36e9 100644 --- a/core/src/main/kotlin/matterlink/update/UpdateChecker.kt +++ b/core/src/main/kotlin/matterlink/update/UpdateChecker.kt @@ -16,14 +16,20 @@ class UpdateChecker : Runnable { override fun run() { val gson = Gson() - val currentModVersion = instance.modVersion - val currentMCVersion = instance.mcVersion - val currentVersion = currentMCVersion + "-" + currentModVersion - instance.info("Checking for new versions...") + if (instance.modVersion.endsWith("-dev")) { + + } + 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 buffer: BufferedReader = response.entity.content.bufferedReader() @@ -33,7 +39,7 @@ class UpdateChecker : Runnable { gson.fromJson(content, Array::class.java) .filter { - it.gameVersion.contains(currentMCVersion) + it.gameVersion.contains(instance.mcVersion) } .sortedByDescending { it.fileName.substringAfterLast(" ") } @@ -42,31 +48,48 @@ class UpdateChecker : Runnable { return } + val modVersionChunks = instance.modVersion + .replace("-dev", "") + .split('.') + .map { + it.toInt() + } + val possibleUpdates = mutableListOf() apiUpdateList.forEach { instance.debug(it.toString()) - val version = it.fileName.substringAfter("-") - if(version > currentModVersion) - { + val version = it.fileName.substringAfterLast("-").split('.').map { it.toInt() } + 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 } } - if(possibleUpdates.isEmpty()) return - val latest= possibleUpdates[0] + if (possibleUpdates.isEmpty()) return + val latest = possibleUpdates[0] possibleUpdates.sortByDescending { it.fileName.substringAfter(" ") } 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") possibleUpdates.forEach { instance.info("version: {} download: {}", it.fileName, it.downloadURL) } instance.warn("Mod out of date! New $version available at ${latest.downloadURL}") - MessageHandler.transmit(ApiMessage( - username = cfg.relay.systemUser, - text = "Matterlink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}" - )) +// MessageHandler.transmit(ApiMessage( +// username = cfg.relay.systemUser, +// text = "Matterlink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}" +// )) } - } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index af514e7..bada6d6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ mod_name = MatterLink -mod_version = 1.4.3 +mod_version = 1.4.4 forgelin_version = 1.6.0 \ No newline at end of file