mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FIX] Исправлена логика выявления типа версии - часть 2.
This commit is contained in:
parent
012870cf26
commit
2a59e8fe0b
2 changed files with 27 additions and 44 deletions
|
@ -8,6 +8,7 @@
|
|||
import java.util.Locale;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -26,6 +27,7 @@ public class Updater extends TimerTask {
|
|||
private static final Version VERSION = Launcher.getVersion();
|
||||
private final Timer taskPool;
|
||||
private final GHRepository gravitLauncher;
|
||||
private Version parent = VERSION;
|
||||
|
||||
public Updater(LaunchServer srv) {
|
||||
this.taskPool = new Timer("Updater thread", true);
|
||||
|
@ -37,7 +39,6 @@ public Updater(LaunchServer srv) {
|
|||
LogHelper.error(e);
|
||||
}
|
||||
this.gravitLauncher = gravitLauncherTmp;
|
||||
|
||||
run();
|
||||
if (srv.config.updatesNotify) taskPool.schedule(this, new Date(System.currentTimeMillis()+period), period);
|
||||
}
|
||||
|
@ -47,6 +48,7 @@ public void run() {
|
|||
try {
|
||||
GHRelease rel = gravitLauncher.getLatestRelease();
|
||||
Version relV = parseVer(rel.getTagName());
|
||||
if (!relV.equals(parent)) parent = relV;
|
||||
if (VERSION.major >= relV.major || VERSION.minor >= relV.minor
|
||||
|| VERSION.patch >= relV.patch || VERSION.build >= relV.build) return;
|
||||
if (relV.release.equals(Type.STABLE) || relV.release.equals(Type.LTS)) {
|
||||
|
@ -68,9 +70,9 @@ public void run() {
|
|||
|
||||
private static Version parseVer(String relS) {
|
||||
Matcher verMatcher = startingVerPattern.matcher(relS);
|
||||
if (!verMatcher.find()) return null;
|
||||
if (!verMatcher.find()) return VERSION;
|
||||
String[] ver = pointPatternStriper.split(relS.substring(verMatcher.start(), verMatcher.end()));
|
||||
if (ver.length < 3) return null;
|
||||
if (ver.length < 3) return VERSION;
|
||||
return new Version(Integer.parseInt(ver[0]), Integer.parseInt(ver[1]),
|
||||
Integer.parseInt(ver[2]), ver.length > 3 ? Integer.parseInt(ver[3]) : 0, findRelType(relS.substring(verMatcher.end()+1)));
|
||||
}
|
||||
|
@ -79,16 +81,11 @@ private static Type findRelType(String substring) {
|
|||
if (substring.length() < 3 || substring.isEmpty()) return Type.UNKNOWN;
|
||||
String tS = substring;
|
||||
if (tS.startsWith("-")) tS = tS.substring(1);
|
||||
tS = tS.toUpperCase(Locale.ENGLISH);
|
||||
Type t = Type.UNKNOWN;
|
||||
try {
|
||||
t = Type.valueOf(tS);
|
||||
} catch (Throwable ign) { // ignore it
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(parseVer("v3.4.5.6-stable").release);
|
||||
final String wrk = tS.toLowerCase(Locale.ENGLISH);
|
||||
final AtomicReference<Type> t = new AtomicReference<Type>(Type.UNKNOWN);
|
||||
Type.unModTypes.forEach((s, type) -> {
|
||||
if (wrk.startsWith(s)) t.set(type);
|
||||
});
|
||||
return t.get();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
import ru.gravit.launcher.LauncherAPI;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class Version {
|
||||
|
@ -68,34 +73,8 @@ public int hashCode() {
|
|||
|
||||
@LauncherAPI
|
||||
public String getReleaseStatus() {
|
||||
String result;
|
||||
switch (release) {
|
||||
case LTS:
|
||||
result = "lts";
|
||||
break;
|
||||
case STABLE:
|
||||
result = "stable";
|
||||
break;
|
||||
case BETA:
|
||||
result = "beta";
|
||||
break;
|
||||
case ALPHA:
|
||||
result = "alpha";
|
||||
break;
|
||||
case DEV:
|
||||
result = "dev";
|
||||
break;
|
||||
case EXPERIMENTAL:
|
||||
result = "experimental";
|
||||
break;
|
||||
case UNKNOWN:
|
||||
result = "";
|
||||
break;
|
||||
default:
|
||||
result = "";
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
if (release.equals(Type.UNKNOWN)) return "";
|
||||
return release.name().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -112,6 +91,13 @@ public enum Type {
|
|||
ALPHA,
|
||||
DEV,
|
||||
EXPERIMENTAL,
|
||||
UNKNOWN
|
||||
UNKNOWN;
|
||||
|
||||
private static final Map<String, Type> types = new HashMap<>();
|
||||
public static final Map<String, Type> unModTypes = Collections.unmodifiableMap(types);
|
||||
|
||||
static {
|
||||
Arrays.asList(values()).stream().forEach(type -> types.put(type.name().substring(0, type.name().length() < 3 ? type.name().length() : 3), type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue