From b1b54e1dd71a6ab696477ec733ba6c4bc199ad3c Mon Sep 17 00:00:00 2001 From: Lenni0451 <20379977+Lenni0451@users.noreply.github.com> Date: Mon, 30 Jan 2023 18:31:44 +0100 Subject: [PATCH] Added semver version checking --- build.gradle | 1 + .../net/raphimc/viaproxy/tasks/UpdatedCheckTask.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c2f5073..8fd8f7c 100644 --- a/build.gradle +++ b/build.gradle @@ -94,6 +94,7 @@ dependencies { include("net.lenni0451.mcstructs:all:2.1.1") { exclude group: "com.google.code.gson", module: "gson" } + include "com.vdurmont:semver4j:3.1.0" } blossom { diff --git a/src/main/java/net/raphimc/viaproxy/tasks/UpdatedCheckTask.java b/src/main/java/net/raphimc/viaproxy/tasks/UpdatedCheckTask.java index 8a39854..39f6fd0 100644 --- a/src/main/java/net/raphimc/viaproxy/tasks/UpdatedCheckTask.java +++ b/src/main/java/net/raphimc/viaproxy/tasks/UpdatedCheckTask.java @@ -21,6 +21,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.vdurmont.semver4j.Semver; import net.raphimc.viaproxy.ViaProxy; import net.raphimc.viaproxy.ui.popups.DownloadPopup; import net.raphimc.viaproxy.util.logging.Logger; @@ -62,7 +63,16 @@ public class UpdatedCheckTask implements Runnable { JsonObject object = JsonParser.parseString(builder.toString()).getAsJsonObject(); String latestVersion = object.get("tag_name").getAsString().substring(1); - if (!VERSION.equals(latestVersion)) { + boolean updateAvailable; + try { + Semver versionSemver = new Semver(VERSION); + Semver latestVersionSemver = new Semver(latestVersion); + updateAvailable = latestVersionSemver.isGreaterThan(versionSemver); + if (versionSemver.isGreaterThan(latestVersionSemver)) Logger.LOGGER.warn("You are running a dev version of ViaProxy"); + } catch (Throwable t) { + updateAvailable = !VERSION.equals(latestVersion); + } + if (updateAvailable) { Logger.LOGGER.warn("You are running an outdated version of ViaProxy! Latest version: " + latestVersion); if (this.hasUI) { JsonArray assets = object.getAsJsonArray("assets");