Skip to content

Commit

Permalink
A lot of changes to beta management
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Mar 11, 2024
1 parent a60be81 commit 1bc5120
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
org.gradle.jvmargs=-Xmx1G

# Version and packaging info
version=3.1.0
version=3.2.0
maven_group=net.hypercubemc
archives_base_name=Iris-Installer

Expand Down
14 changes: 6 additions & 8 deletions src/main/java/net/hypercubemc/iris_installer/InstallerMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,24 @@
public class InstallerMeta {
private final String metaUrl;
private String betaSnippet;
private boolean hasBeta;
private final List<InstallerMeta.Version> versions = new ArrayList<>();

public InstallerMeta(String url) {
this.metaUrl = url;
}

public void load() throws IOException, JSONException {
System.out.println(metaUrl);

JSONObject json = readJsonFromUrl(this.metaUrl);
betaSnippet = json.getString("betaVersionSnippet");
hasBeta = json.getBoolean("hasBeta");
json.getJSONArray("versions").toList().forEach(element -> versions.add(new Version((HashMap) element)));
betaSnippet = "Distant Horizons";
json.getJSONArray("versions").toList().forEach(element -> versions.add(new Version((HashMap<String, Object>) element)));
}

public String getBetaSnippet() {
return betaSnippet;
}

public boolean hasBeta() {
return hasBeta;
}

public List<InstallerMeta.Version> getVersions() {
return this.versions;
}
Expand All @@ -58,13 +54,15 @@ public static JSONObject readJsonFromUrl(String url) throws IOException {

public static class Version {
boolean outdated;
boolean hasBeta;
boolean snapshot;
String name;

public Version(HashMap<String, Object> jsonObject) {
this.name = (String) jsonObject.get("name");
this.snapshot = (boolean) jsonObject.get("snapshot");
this.outdated = (boolean) jsonObject.get("outdated");
this.hasBeta = (boolean) jsonObject.get("hasBeta");
}

@Override
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/net/hypercubemc/iris_installer/NewInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ public NewInstaller() {
outdatedText2.setForeground(newTextColor);
}

if (!INSTALLER_META.hasBeta()) {
betaSelection.setVisible(false);
if (!selectedVersion.hasBeta) {
betaSelection.setEnabled(false);
betaSelection.setSelected(false);
}

gameVersionList.removeAllItems();
Expand Down Expand Up @@ -166,14 +167,16 @@ public boolean installFromZip(File zip) {
ZipEntry entry = zipIn.getNextEntry();
// iterates over entries in the zip file
if (!installAsMod) {
getInstallDir().resolve("iris-reserved/").toFile().mkdir();
getInstallDir().resolve(betaSelection.isSelected() ? "iris-beta-reserved/" : "iris-reserved/").toFile().mkdir();
}

getInstallDir().resolve("shaderpacks").toFile().mkdir();

while (entry != null) {
String entryName = entry.getName();

if (!installAsMod && entryName.startsWith("mods/")) {
entryName = entryName.replace("mods/", "iris-reserved/" + selectedVersion + "/");
entryName = entryName.replace("mods/", (betaSelection.isSelected() ? "iris-beta-reserved/" : "iris-reserved/") + selectedVersion + "/");
}

File filePath = getInstallDir().resolve(entryName).toFile();
Expand Down Expand Up @@ -321,7 +324,7 @@ private void initComponents() {
installType.add(standaloneType);
standaloneType.setFont(standaloneType.getFont().deriveFont((float)16));
standaloneType.setSelected(true);
standaloneType.setText("Iris Install");
standaloneType.setText("Iris Only");
standaloneType.setToolTipText("This installs Iris and Sodium by itself, without any mods.");
standaloneType.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
Expand All @@ -332,7 +335,7 @@ public void mouseClicked(java.awt.event.MouseEvent evt) {

installType.add(fabricType);
fabricType.setFont(fabricType.getFont().deriveFont((float)16));
fabricType.setText("Fabric Install");
fabricType.setText("Iris + Fabric");
fabricType.setToolTipText("This installs Iris and Sodium alongside an installation of Fabric.");
fabricType.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
Expand Down Expand Up @@ -441,20 +444,21 @@ private void gameVersionListItemStateChanged(java.awt.event.ItemEvent evt) {//GE

if (selectedVersion.outdated) {
outdatedText1.setText(outdatedPlaceholder.replace("<version>", selectedVersion.name));
betaSelection.setVisible(false);
betaSelection.setSelected(false);
betaSelection.setEnabled(false);
outdatedText1.setVisible(true);
outdatedText2.setText("The Iris version you get will most likely be outdated.");
outdatedText2.setVisible(true);
} else if (selectedVersion.snapshot) {
outdatedText1.setText(snapshotPlaceholder.replace("<version>", selectedVersion.name));
betaSelection.setVisible(false);
betaSelection.setSelected(false);
betaSelection.setEnabled(false);
outdatedText1.setVisible(true);
outdatedText2.setText("lose support at any time.");
outdatedText2.setVisible(true);
} else {
if (INSTALLER_META.hasBeta()) {
betaSelection.setVisible(true);
}
betaSelection.setEnabled(selectedVersion.hasBeta);
betaSelection.setSelected(false);
outdatedText1.setVisible(false);
outdatedText2.setVisible(false);
}
Expand All @@ -474,9 +478,9 @@ private void installButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIR

try {
URL loaderVersionUrl = new URL("https://raw.githubusercontent.com/IrisShaders/Iris-Installer-Maven/master/latest-loader");
String profileName = installAsMod ? "Fabric Loader " : "Iris & Sodium for ";
String profileName = installAsMod ? "Fabric Loader " : (betaSelection.isSelected() ? "Iris " + INSTALLER_META.getBetaSnippet() + " BETA for " : "Iris & Sodium for ");
VanillaLauncherIntegration.Icon profileIcon = installAsMod ? VanillaLauncherIntegration.Icon.FABRIC : VanillaLauncherIntegration.Icon.IRIS;
Path modsFolder0 = installAsMod ? getInstallDir().resolve("mods") : getInstallDir().resolve("iris-reserved").resolve(selectedVersion.name);
Path modsFolder0 = installAsMod ? getInstallDir().resolve("mods") : getInstallDir().resolve(betaSelection.isSelected() ? "iris-beta-reserved/" : "iris-reserved/").resolve(selectedVersion.name);

String loaderVersion = Main.LOADER_META.getLatestVersion(false).getVersion();
boolean success = VanillaLauncherIntegration.installToLauncher(this, getVanillaGameDir(), getInstallDir(), modsFolder0, profileName + selectedVersion.name, selectedVersion.name, loaderName, loaderVersion, profileIcon);
Expand Down Expand Up @@ -538,7 +542,7 @@ private void installButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIR
installDir.mkdir();
}

File modsFolder = installAsMod ? getInstallDir().resolve("mods").toFile() : getInstallDir().resolve("iris-reserved").resolve(selectedVersion.name).toFile();
File modsFolder = installAsMod ? getInstallDir().resolve("mods").toFile() : getInstallDir().resolve(betaSelection.isSelected() ? "iris-beta-reserved/" : "iris-reserved/").resolve(selectedVersion.name).toFile();
File[] modsFolderContents = modsFolder.listFiles();

if (modsFolderContents != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static void installProfile(Component parent, Path mcDir, Path instanceDi
String key = it.next();

JSONObject foundProfile = profiles.getJSONObject(key);
if (foundProfile.has("lastVersionId") && foundProfile.getString("lastVersionId").equals(versionId) && foundProfile.has("gameDir") && foundProfile.getString("gameDir").equals(instanceDir.toString())) {
if (!profileName.toLowerCase(Locale.ROOT).contains("beta") && foundProfile.has("lastVersionId") && foundProfile.getString("lastVersionId").equals(versionId) && foundProfile.has("gameDir") && foundProfile.getString("gameDir").equals(instanceDir.toString())) {
foundProfileName = key;
}
}
Expand Down

0 comments on commit 1bc5120

Please sign in to comment.