Skip to content
This repository was archived by the owner on Oct 29, 2019. It is now read-only.

Commit fbdf0e6

Browse files
committed
Add BETA option for installing to install latest beta
1 parent 6cbfab6 commit fbdf0e6

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>cc.hyperium.installer</groupId>
88
<artifactId>Installer</artifactId>
9-
<version>1.4</version>
9+
<version>1.5</version>
1010

1111
<properties>
1212
<kotlin.version>1.2.50</kotlin.version>

src/main/java/cc/hyperium/installer/steps/VersionScreen.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ public void addComponents(Container c) {
5858
Arrays.stream(InstallerUtils.getManifest().getVersions()).filter(vm -> vm.getTargetInstaller() <= Installer.API_VERSION)
5959
.forEach(vm -> versions.addItem(vm.getName()));
6060

61+
versions.addItem("BETA");
6162
versions.setSelectedItem(InstallerMain.INSTANCE.getConfig().getVersion().getName());
62-
versions.addActionListener(e -> InstallerMain.INSTANCE.getConfig().setVersion(Arrays.stream(InstallerUtils.getManifest().getVersions()).filter(v -> v.getName().equals(versions.getSelectedItem())).findFirst().get()));
63+
versions.addActionListener(e -> {
64+
InstallerMain.INSTANCE.getConfig().setVersion(Arrays.stream(InstallerUtils.getManifest().getVersions()).filter(v -> v.getName().equals(versions.getSelectedItem())).findFirst().orElseGet(() -> InstallerUtils.getManifest().getLatest_beta()));
65+
});
6366
versions.setBounds(c.getWidth() / 2 - tw / 2, c.getHeight() / 2 + 5, 250, 20);
6467
versions.setBackground(Colors.DARK.brighter());
6568
versions.setForeground(Color.WHITE);

src/main/java/cc/hyperium/utils/InstallerUtils.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import cc.hyperium.installer.api.entities.InstallerManifest;
44
import cc.hyperium.installer.utils.JsonHolder;
55
import com.google.gson.Gson;
6+
import com.google.gson.JsonArray;
7+
import com.google.gson.JsonElement;
68
import org.apache.commons.io.IOUtils;
79
import org.apache.http.client.HttpClient;
810
import org.apache.http.client.methods.HttpGet;
@@ -15,6 +17,7 @@
1517
import java.net.URL;
1618
import java.net.URLClassLoader;
1719
import java.security.MessageDigest;
20+
import java.util.Iterator;
1821
import java.util.Locale;
1922

2023
/*
@@ -55,10 +58,6 @@ else if (OS.contains("nux"))
5558
return os;
5659
}
5760

58-
public enum OSType {
59-
Windows, MacOS, Linux, Other
60-
}
61-
6261
public static JsonHolder get(String url) {
6362
try {
6463
return new JsonHolder(getRaw(url));
@@ -77,8 +76,18 @@ public static InstallerManifest getManifest() {
7776
Gson gson = new Gson();
7877

7978
try {
80-
InstallerManifest im = gson.fromJson(get("https://api.hyperium.cc/versions").getObject(), InstallerManifest.class);
81-
manifest = new InstallerManifest(im.getLatest(), im.getVersions(), gson.fromJson(InstallerUtils.getRaw("https://raw.githubusercontent.com/HyperiumClient/Hyperium-Repo/master/installer/addons.json"), InstallerManifest.class).getAddons());
79+
JsonHolder jsonHolder = get("https://api.hyperium.cc/versions");
80+
JsonArray versions = jsonHolder.optJSONArray("versions");
81+
Iterator<JsonElement> iterator = versions.iterator();
82+
while (iterator.hasNext()) {
83+
JsonHolder jsonHolder1 = new JsonHolder(iterator.next().getAsJsonObject());
84+
if (jsonHolder1.optBoolean("beta")) {
85+
iterator.remove();
86+
}
87+
}
88+
InstallerManifest im = gson.fromJson(jsonHolder.getObject(), InstallerManifest.class);
89+
90+
manifest = new InstallerManifest(im.getLatest(), im.getLatest_beta(), im.getVersions(), gson.fromJson(InstallerUtils.getRaw("https://raw.githubusercontent.com/HyperiumClient/Hyperium-Repo/master/installer/addons.json"), InstallerManifest.class).getAddons());
8291
} catch (Exception e) {
8392
e.printStackTrace();
8493
}
@@ -116,4 +125,8 @@ public static Class<?> loadClass(URL url, String c) throws ClassNotFoundExceptio
116125
return new URLClassLoader(new URL[]{url}).loadClass(c);
117126
}
118127

128+
public enum OSType {
129+
Windows, MacOS, Linux, Other
130+
}
131+
119132
}

src/main/kotlin/cc/hyperium/installer/api/entities/InstallerManifest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import java.util.*
77
*/
88
data class InstallerManifest(
99
val latest: VersionManifest,
10+
val latest_beta: VersionManifest,
1011
val versions: Array<VersionManifest>,
1112
val addons: MutableList<AddonManifest> = mutableListOf()
13+
1214
) {
1315
override fun equals(other: Any?): Boolean {
1416
if (this === other) return true

0 commit comments

Comments
 (0)