v2.4.0: added version compatibility checks to github updates
This commit is contained in:
@@ -43,6 +43,11 @@ public class DeviceCompat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//return APi level on Android, major OS version on iOS, 0 on desktop
|
||||||
|
public static int getPlatformVersion(){
|
||||||
|
return Gdx.app.getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isAndroid(){
|
public static boolean isAndroid(){
|
||||||
return SharedLibraryLoader.isAndroid;
|
return SharedLibraryLoader.isAndroid;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.Net;
|
import com.badlogic.gdx.Net;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
|
import com.watabou.utils.DeviceCompat;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -37,6 +38,9 @@ public class GitHubUpdates extends UpdateService {
|
|||||||
private static Pattern descPattern = Pattern.compile("(.*?)(\r\n|\n|\r)(\r\n|\n|\r)---", Pattern.DOTALL + Pattern.MULTILINE);
|
private static Pattern descPattern = Pattern.compile("(.*?)(\r\n|\n|\r)(\r\n|\n|\r)---", Pattern.DOTALL + Pattern.MULTILINE);
|
||||||
private static Pattern versionCodePattern = Pattern.compile("internal version number: ([0-9]*)", Pattern.CASE_INSENSITIVE);
|
private static Pattern versionCodePattern = Pattern.compile("internal version number: ([0-9]*)", Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
|
private static Pattern minAndroidPattern = Pattern.compile("Android .*\\(API ([0-9]*)\\)\\+ Devices", Pattern.CASE_INSENSITIVE);
|
||||||
|
private static Pattern minIOSPattern = Pattern.compile("iOS ([0-9]*)\\+ Devices", Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsUpdatePrompts() {
|
public boolean supportsUpdatePrompts() {
|
||||||
return true;
|
return true;
|
||||||
@@ -71,11 +75,31 @@ public class GitHubUpdates extends UpdateService {
|
|||||||
|
|
||||||
if (m.find()){
|
if (m.find()){
|
||||||
int releaseVersion = Integer.parseInt(m.group(1));
|
int releaseVersion = Integer.parseInt(m.group(1));
|
||||||
if (releaseVersion > latestVersionCode
|
|
||||||
&& (includeBetas || !b.getBoolean("prerelease"))){
|
|
||||||
latestRelease = b;
|
//skip release that aren't the latest update (or an update at all)
|
||||||
latestVersionCode = releaseVersion;
|
if (releaseVersion <= latestVersionCode) {
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// or that are betas when we haven't opted in
|
||||||
|
} else if (!includeBetas && !b.getBoolean("prerelease")){
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// or that aren't compatible
|
||||||
|
} else if (DeviceCompat.isDesktop()){
|
||||||
|
Matcher minAndroid = minAndroidPattern.matcher(b.getString("body"));
|
||||||
|
if (minAndroid.find() && DeviceCompat.getPlatformVersion() < Integer.parseInt(minAndroid.group(1))){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if (DeviceCompat.isiOS()){
|
||||||
|
Matcher minIOS = minIOSPattern.matcher(b.getString("body"));
|
||||||
|
if (minIOS.find() && DeviceCompat.getPlatformVersion() < Integer.parseInt(minIOS.group(1))){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
latestRelease = b;
|
||||||
|
latestVersionCode = releaseVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user