From 1a1f31db2c65fbdfcfdfb1cb252255a6b66b850b Mon Sep 17 00:00:00 2001 From: soloturn Date: Sun, 28 Feb 2021 17:08:24 +0100 Subject: [PATCH] 1.7.94-10-asdf is newer than 1.7.94 part of #12 --- README.md | 10 +++++---- .../com/rarchives/ripme/ui/UpdateUtils.java | 22 +++++++++++++------ .../rarchives/ripme/ui/UpdateUtilsTest.java | 17 ++++++++++++++ 3 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 src/test/java/com/rarchives/ripme/ui/UpdateUtilsTest.java diff --git a/README.md b/README.md index be773987..7514e697 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,13 @@ RipMe is an album ripper for various websites. It is a cross-platform tool that ## Downloads -Download `ripme.jar` from the [latest release](https://github.com/ripmeapp/ripme/releases). +Download `ripme.jar` from the [latest release](/releases). For information about running the `.jar` file, see +[the How To Run wiki](https://github.com/ripmeapp/ripme/wiki/How-To-Run-RipMe). -**Note: If you're currently using version 1.2.x, 1.3.x or 1.7.49, you will not automatically get updates to the newest versions. We recommend downloading the latest version from the link above.** - -For information about running the `.jar` file, see [the How To Run wiki](https://github.com/ripmeapp/ripme/wiki/How-To-Run-RipMe). +The version number like ripme-1.7.94-17-2167aa34-feature_auto_release.jar contains a release number (1.7.94), given by +a person the number of commits since this version (17). The commit SHA (2167aa34) is there uniquely referencing the +source code ripme was built from. If it is not built from the main branch, the branch name (feature/auto-release) is +given. ## Installation diff --git a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java index 8c1b415e..d2379940 100644 --- a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java +++ b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java @@ -23,7 +23,8 @@ import com.rarchives.ripme.utils.Utils; public class UpdateUtils { private static final Logger logger = Logger.getLogger(UpdateUtils.class); - private static final String DEFAULT_VERSION = "1.7.94"; + // do not update the default version without adjusting the unit test. the real version comes from METAINF.MF + private static final String DEFAULT_VERSION = "1.7.94-10-b6345398"; private static final String REPO_NAME = "ripmeapp/ripme"; private static final String updateJsonURL = "https://raw.githubusercontent.com/" + REPO_NAME + "/master/ripme.json"; private static String mainFileName; @@ -165,7 +166,7 @@ public class UpdateUtils { } } - private static boolean isNewerVersion(String latestVersion) { + static boolean isNewerVersion(String latestVersion) { // If we're testing the update utils we want the program to always try to update if (Utils.getConfigBoolean("testing.always_try_to_update", false)) { logger.info("isNewerVersion is returning true because the key \"testing.always_try_to_update\" is true"); @@ -194,11 +195,18 @@ public class UpdateUtils { } private static int[] versionStringToInt(String version) { - String strippedVersion = version.split("-")[0]; - String[] strVersions = strippedVersion.split("\\."); - int[] intVersions = new int[strVersions.length]; - for (int i = 0; i < strVersions.length; i++) { - intVersions[i] = Integer.parseInt(strVersions[i]); + // a version string looks like 1.7.94, 1.7.94-10-something + // 10 is the number of commits since the 1.7.94 tag, so newer + // the int array returned then contains e.g. 1.7.94.0 or 1.7.94.10 + String[] strVersions = version.split("[\\.-]"); + // not consider more than 4 components of version, loop only the real number + // of components or maximum 4 components of the version string + int[] intVersions = new int[4]; + for (int i = 0; i < Math.min(4,strVersions.length); i++) { + // if it is an integer, set it, otherwise leave default 0 + if (strVersions[i].matches("\\d+")) { + intVersions[i] = Integer.parseInt(strVersions[i]); + } } return intVersions; } diff --git a/src/test/java/com/rarchives/ripme/ui/UpdateUtilsTest.java b/src/test/java/com/rarchives/ripme/ui/UpdateUtilsTest.java new file mode 100644 index 00000000..2f9ba697 --- /dev/null +++ b/src/test/java/com/rarchives/ripme/ui/UpdateUtilsTest.java @@ -0,0 +1,17 @@ +package com.rarchives.ripme.ui; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class UpdateUtilsTest { + + @Test + public void testIsNewerVersion() { + UpdateUtils updateUtils = new UpdateUtils(); + Assertions.assertFalse(updateUtils.isNewerVersion("1.7.94")); + Assertions.assertFalse(updateUtils.isNewerVersion("1.7.94-9-asdf")); + Assertions.assertTrue(updateUtils.isNewerVersion("1.7.94-11-asdf")); + Assertions.assertTrue(updateUtils.isNewerVersion("1.7.95")); + } + +} \ No newline at end of file