Added getting elementaryOS version info. Extracted common method getDistribReleaseInfo()
This commit is contained in:
parent
be2a100b12
commit
ba7e960940
@ -206,6 +206,10 @@ class OSUtil {
|
|||||||
public static
|
public static
|
||||||
class Linux {
|
class Linux {
|
||||||
private static String info = null;
|
private static String info = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return os release info or ""
|
||||||
|
*/
|
||||||
public static
|
public static
|
||||||
String getInfo() {
|
String getInfo() {
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
@ -394,30 +398,49 @@ class OSUtil {
|
|||||||
return ubuntuVersion;
|
return ubuntuVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
String info = getInfo();
|
String distribReleaseInfo = getDistribReleaseInfo();
|
||||||
String releaseString = "DISTRIB_RELEASE=";
|
if (distribReleaseInfo != null) {
|
||||||
int index = info.indexOf(releaseString);
|
String[] split = distribReleaseInfo.split("\\.");
|
||||||
try {
|
|
||||||
if (index > -1) {
|
|
||||||
index += releaseString.length();
|
|
||||||
int newLine = info.indexOf(OS.LINE_SEPARATOR_UNIX, index);
|
|
||||||
if (newLine > index) {
|
|
||||||
String versionInfo = info.substring(index, newLine);
|
|
||||||
if (versionInfo.indexOf('.') > 0) {
|
|
||||||
String[] split = versionInfo.split("\\.");
|
|
||||||
|
|
||||||
ubuntuVersion = new int[] {Integer.parseInt(split[0]), Integer.parseInt(split[1])};
|
ubuntuVersion = new int[] {Integer.parseInt(split[0]), Integer.parseInt(split[1])};
|
||||||
return ubuntuVersion;
|
return ubuntuVersion;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Throwable ignored) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ubuntuVersion = new int[]{0,0};
|
ubuntuVersion = new int[]{0,0};
|
||||||
return ubuntuVersion;
|
return ubuntuVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static volatile int[] elementaryOSVersion = null;
|
||||||
|
public static
|
||||||
|
int[] getElementaryOSVersion() {
|
||||||
|
// 0.1 Jupiter. The first stable version of elementary OS was Jupiter, published on 31 March 2011 and based on Ubuntu 10.10. ...
|
||||||
|
// 0.2 Luna. elementary OS 0.2 "Luna" ...
|
||||||
|
// 0.3 Freya. elementary OS 0.3 "Freya" ...
|
||||||
|
// 0.4 Loki. elementary OS 0.4, known by its codename, "Loki", was released on 9 September 2016. ...
|
||||||
|
// 5.0 Juno
|
||||||
|
|
||||||
|
if (elementaryOSVersion != null) {
|
||||||
|
return elementaryOSVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isElementaryOS()) {
|
||||||
|
elementaryOSVersion = new int[]{0,0};
|
||||||
|
return elementaryOSVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
String distribReleaseInfo = getDistribReleaseInfo();
|
||||||
|
if (distribReleaseInfo != null) {
|
||||||
|
String[] split = distribReleaseInfo.split("\\.");
|
||||||
|
|
||||||
|
elementaryOSVersion = new int[] {Integer.parseInt(split[0]), Integer.parseInt(split[1])};
|
||||||
|
return elementaryOSVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
elementaryOSVersion = new int[]{0,0};
|
||||||
|
return elementaryOSVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static Boolean isKali = null;
|
private static Boolean isKali = null;
|
||||||
public static
|
public static
|
||||||
@ -428,6 +451,28 @@ class OSUtil {
|
|||||||
return isKali;
|
return isKali;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the `DISTRIB_RELEASE` info as a String, if possible. Otherwise NULL
|
||||||
|
*/
|
||||||
|
public static
|
||||||
|
String getDistribReleaseInfo() {
|
||||||
|
String info = getInfo();
|
||||||
|
String releaseString = "DISTRIB_RELEASE=";
|
||||||
|
int index = info.indexOf(releaseString);
|
||||||
|
try {
|
||||||
|
if (index > -1) {
|
||||||
|
index += releaseString.length();
|
||||||
|
int newLine = info.indexOf(OS.LINE_SEPARATOR_UNIX, index);
|
||||||
|
if (newLine > index) {
|
||||||
|
return info.substring(index, newLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static
|
public static
|
||||||
boolean isRoot() {
|
boolean isRoot() {
|
||||||
// this means we are running as sudo
|
// this means we are running as sudo
|
||||||
|
Loading…
Reference in New Issue
Block a user