1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-09-03 10:53:25 +02:00

1.7.94-10-asdf is newer than 1.7.94

part of #12
This commit is contained in:
soloturn
2021-02-28 17:08:24 +01:00
parent 2347e74970
commit 1a1f31db2c
3 changed files with 38 additions and 11 deletions

View File

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

View File

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