listen, it's scuffed but it works 👍 (fabric)

This commit is contained in:
NotCoded committed 2023-10-21 21:12:40 +02:00
1 parent ed51370c56
commit 7dbbc87874
10 files changed
+286 -21

No files matched your search

+4
View File
@@ -38,3 +38,7 @@ bin/
### Mac OS ###
.DS_Store
### cache ###
cache/
+1 -1
View File
@@ -7,7 +7,7 @@ sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
group = 'com.nexia'
version = '1.0.1'
version = '1.0.2'
repositories {
mavenCentral()
@@ -1,6 +1,7 @@
package com.nexia.installer;
import com.nexia.installer.util.InstallerHelper;
import com.nexia.installer.util.fabric.FabricInstallerHelper;
import javax.swing.*;
import java.awt.*;
@@ -11,13 +12,18 @@ import java.util.function.Supplier;
public class InstallerGUI extends JFrame {
public static InstallerGUI instance;
public JPanel vanilla;
public JPanel fabric;
public JTabbedPane pane;
public InstallerGUI() {
InstallerHelper helper = new InstallerHelper();
JPanel panel = helper.setPanel(this);
this.vanilla = new InstallerHelper().setPanel(this);
this.fabric = new FabricInstallerHelper().setPanel(this);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
add(panel);
instance = this;
}
@@ -43,6 +49,15 @@ public class InstallerGUI extends JFrame {
}
InstallerGUI gui = new InstallerGUI();
gui.pane = new JTabbedPane(JTabbedPane.TOP);
gui.pane.addTab(Main.BUNDLE.getString("installer.tab.vanilla"), gui.vanilla);
gui.pane.addTab(Main.BUNDLE.getString("installer.tab.fabric"), gui.fabric);
gui.setContentPane(gui.pane);
gui.updateSize(true);
gui.setTitle(Main.BUNDLE.getString("installer.title"));
gui.setIconImage(Main.icon);
@@ -50,7 +65,7 @@ public class InstallerGUI extends JFrame {
gui.setVisible(true);
}
public void updateSize(boolean updateMinimum) {
private void updateSize(boolean updateMinimum) {
if (updateMinimum) setMinimumSize(null);
setPreferredSize(null);
pack();
@@ -55,7 +55,7 @@ public class InstallerHelper {
buttonInstall.addActionListener(e -> {
buttonInstall.setEnabled(false);
try {
install();
launch();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
@@ -107,7 +107,7 @@ public class InstallerHelper {
c.gridx = 0;
}
private void install() throws IOException {
public void launch() throws IOException {
String stringGameVersion = (String) gameVersionComboBox.getSelectedItem();
VersionHandler.GameVersion gameVersion = VersionHandler.identifyGameVersion(stringGameVersion);
@@ -1,14 +1,12 @@
package com.nexia.installer.util;
import com.nexia.installer.InstallerGUI;
import com.nexia.installer.Main;
import com.nexia.installer.game.VersionHandler;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -115,7 +113,7 @@ public class InstallerUtils {
}).start();
}
private static ProfileInstaller.LauncherType showLauncherTypeSelection() {
public static ProfileInstaller.LauncherType showLauncherTypeSelection() {
Object[] options = { Main.BUNDLE.getString("installer.prompt.launcher.type.xbox"), Main.BUNDLE.getString("installer.prompt.launcher.type.win32")};
int result = JOptionPane.showOptionDialog(null,
@@ -135,7 +133,7 @@ public class InstallerUtils {
return result == JOptionPane.YES_OPTION ? ProfileInstaller.LauncherType.MICROSOFT_STORE : ProfileInstaller.LauncherType.WIN32;
}
private static void showDone(VersionHandler.GameVersion gameVersion) throws URISyntaxException, IOException {
private static void showDone(VersionHandler.GameVersion gameVersion) {
Object[] options = {"OK", "Install Fabric"};
int result = JOptionPane.showOptionDialog(null,
MessageFormat.format(Main.BUNDLE.getString("installer.prompt.install.done"), gameVersion.getVersion()),
@@ -147,6 +145,6 @@ public class InstallerUtils {
options[0]
);
if(result == JOptionPane.NO_OPTION && Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) Desktop.getDesktop().browse(new URI("https://github.com/rizecookey/fabric-installer/releases"));
if(result == JOptionPane.NO_OPTION) InstallerGUI.instance.pane.setSelectedComponent(InstallerGUI.instance.fabric);
}
}
@@ -81,13 +81,17 @@ public class ProfileInstaller {
}
public enum LauncherType {
WIN32("launcher_profiles.json"),
MICROSOFT_STORE("launcher_profiles_microsoft_store.json");
WIN32("win32", "launcher_profiles.json"),
MICROSOFT_STORE("microsoft_store", "launcher_profiles_microsoft_store.json");
public final String profileJsonName;
LauncherType(String profileJsonName) {
public final String name;
LauncherType(String name, String profileJsonName) {
this.name = name;
this.profileJsonName = profileJsonName;
}
}
}
@@ -25,7 +25,7 @@ public class Utils {
public static void extractZip(Path file, Path path) throws IOException {
ZipInputStream zipIn = new ZipInputStream(Files.newInputStream(Paths.get(file.toString())));
ZipEntry entry = zipIn.getNextEntry();
String filePath = "";
String filePath;
// iterates over entries in the zip file
while (entry != null) {
filePath = path + File.separator + entry.getName();
@@ -136,9 +136,7 @@ public class Utils {
return "data:image/png;base64," + Base64.getEncoder().encodeToString(Arrays.copyOf(ret, offset));
} catch (IOException e) {
e.printStackTrace();
}
return "furnace"; // Fallback to furnace icon if we cant load CTS icon.
return "furnace"; // Fallback to furnace icon if we cant load Nexia icon.
}
}
}
@@ -0,0 +1,199 @@
package com.nexia.installer.util.fabric;
import com.nexia.installer.InstallerGUI;
import com.nexia.installer.Main;
import com.nexia.installer.util.InstallerHelper;
import com.nexia.installer.util.InstallerUtils;
import com.nexia.installer.util.ProfileInstaller;
import com.nexia.installer.util.Utils;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.List;
public class FabricInstallerHelper extends InstallerHelper {
public static JButton buttonInstall;
public static JButton buttonFabric;
public JComboBox<String> gameVersionComboBox;
public JTextField installLocation;
public JButton selectFolderButton;
public static JCheckBox createProfile;
@Override
public JPanel setPanel(InstallerGUI gui) {
JPanel panel = new JPanel(new GridBagLayout());
panel.setBorder(new EmptyBorder(4, 4, 4, 4));
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(6, 4, 6, 4);
c.gridx = c.gridy = 0;
addRow(panel, c, "installer.prompt.game.version",
gameVersionComboBox = new JComboBox<>(),
createSpacer()
);
for(FabricVersionHandler.GameVersion version : FabricVersionHandler.versions) {
gameVersionComboBox.addItem(version.getVersion());
}
addRow(panel, c, "installer.prompt.select.location",
installLocation = new JTextField(20),
selectFolderButton = new JButton());
selectFolderButton.setText("...");
selectFolderButton.setPreferredSize(new Dimension(installLocation.getPreferredSize().height, installLocation.getPreferredSize().height));
selectFolderButton.addActionListener(e -> InstallerGUI.selectInstallLocation(() -> installLocation.getText(), s -> installLocation.setText(s)));
addRow(panel, c, null,
createProfile = new JCheckBox(Main.BUNDLE.getString("installer.option.create.profile"), true));
installLocation.setText(InstallerUtils.findDefaultInstallDir().toString());
addLastRow(panel, c,
buttonInstall = new JButton(Main.BUNDLE.getString("installer.button.install")));
buttonInstall.addActionListener(e -> {
buttonInstall.setEnabled(false);
try {
launch();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
addLastRow(panel, c,
buttonFabric = new JButton(Main.BUNDLE.getString("installer.button.fabric")));
buttonFabric.addActionListener(e -> {
try {
Process process = Runtime.getRuntime().exec("java -jar cache/" + getJarFile().getName());
while(process.isAlive()) {
buttonFabric.setEnabled(false);
}
buttonFabric.setEnabled(true);
} catch (IOException ex) {
try {
getJarFile().delete();
} catch (IOException exc) {
// what the fuck
exc.printStackTrace();
}
buttonFabric.setEnabled(false);
}
});
return panel;
}
@Override
public void launch() throws IOException {
String stringGameVersion = (String) gameVersionComboBox.getSelectedItem();
FabricVersionHandler.GameVersion gameVersion = FabricVersionHandler.identifyGameVersion(stringGameVersion);
if(gameVersion == null) return;
Path mcPath = Paths.get(installLocation.getText());
if (!Files.exists(mcPath)) {
throw new RuntimeException(Main.BUNDLE.getString("installer.exception.no.launcher.directory"));
}
final ProfileInstaller profileInstaller = new ProfileInstaller(mcPath);
ProfileInstaller.LauncherType launcherType;
String launcherThing = "";
// can you tell i have no fucking idea what im doing?
if(InstallerHelper.createProfile.isSelected()) {
List<ProfileInstaller.LauncherType> types = profileInstaller.getInstalledLauncherTypes();
if (types.isEmpty()) {
throw new RuntimeException(Main.BUNDLE.getString("installer.exception.no.launcher.profile"));
} else {
launcherType = InstallerUtils.showLauncherTypeSelection();
if (launcherType == null) {
return;
}
launcherThing = "-launcher " + launcherType.name;
}
}
System.out.println("Installing Fabric " + gameVersion.getVersion() + " (" + gameVersion.getCodeName() + ")");
// help - Opens this menu
//client -dir <install dir> -mcversion <minecraft version, default latest> -loader <loader version, default latest> -launcher [win32, microsoft_store]
//server -dir <install dir, default current dir> -mcversion <minecraft version, default latest> -loader <loader version, default latest> -downloadMinecraft
String[] cmd2 = new String[]{"java", "-jar", "cache/" + getJarFile().getName(), "client", "-dir" + "\"" + mcPath.toAbsolutePath() + "\"", "-mcversion", gameVersion.codeName, launcherThing};
Process process = Runtime.getRuntime().exec(cmd2);
// instead of checking if is done, ykyk
// lets just show them its already done!
// who would notice!!!
this.showDone(gameVersion);
buttonInstall.setEnabled(true);
}
private File getJarFile() throws IOException {
Path currentDir = new File("").toPath();
Path cacheDir = currentDir.resolve("cache");
String fileName = "fabric-installer-" + getFabricVersion() + ".jar";
URL url = new URL("https://github.com/rizecookey/fabric-installer/releases/latest/download/" + fileName);
if(!Files.exists(cacheDir)) {
Files.createDirectories(cacheDir);
Utils.downloadFile(url, cacheDir.resolve(fileName));
return new File(cacheDir.toFile(), fileName);
}
for(File file : cacheDir.toFile().listFiles()) {
if(file.getName().equals(fileName)) {
return file;
} else {
file.delete();
Files.createDirectory(cacheDir);
Utils.downloadFile(url, cacheDir.resolve(fileName));
return new File(cacheDir.toFile(), fileName);
}
}
return null;
}
private String getFabricVersion() {
return "0.11.1";
}
private void showDone(FabricVersionHandler.GameVersion gameVersion) {
Object[] options = {"OK", "Install Vanilla"};
int result = JOptionPane.showOptionDialog(null,
MessageFormat.format(Main.BUNDLE.getString("installer.prompt.install.done.fabric"), gameVersion.getVersion()),
Main.BUNDLE.getString("installer.title"),
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
options,
options[0]
);
if(result == JOptionPane.NO_OPTION) InstallerGUI.instance.pane.setSelectedComponent(InstallerGUI.instance.vanilla);
}
}
@@ -0,0 +1,42 @@
package com.nexia.installer.util.fabric;
import java.util.ArrayList;
import java.util.List;
public class FabricVersionHandler {
public static List<GameVersion> versions = new ArrayList<>();
public static GameVersion CombatTest8c = new GameVersion("Combat Test 8c", "1.16_combat-6");
public static GameVersion CombatTest7c = new GameVersion("Combat Test 7c", "1.16_combat-3");
public static GameVersion CombatTest1 = new GameVersion("1.14.3 - Combat Test", "1.14_combat-212796");
public static class GameVersion {
String version;
String codeName;
public GameVersion(String version, String codeName) {
this.version = version;
this.codeName = codeName;
FabricVersionHandler.versions.add(this);
}
public String getVersion() {
return version;
}
public String getCodeName() {
return codeName;
}
}
public static GameVersion identifyGameVersion(String version) {
if(version.trim().isEmpty()) return null;
for(GameVersion gameVersion : FabricVersionHandler.versions) {
if(version.equalsIgnoreCase(gameVersion.getCodeName()) || version.equalsIgnoreCase(gameVersion.getVersion())) return gameVersion;
}
return null;
}
}
@@ -2,9 +2,14 @@ installer.prompt.game.version=Minecraft Version:
installer.prompt.select.location=Select Install Location:
installer.button.install=Install
installer.prompt.install.done={0} has been installed, if you want to install fabric then click on the "Install Fabric" button.
installer.prompt.install.done.fabric={0} has been installed, if you want to install vanilla then click on the "Install Vanilla" button.
installer.exception.no.launcher.directory=No launcher directory found!
installer.prompt.launcher.type.body=The Combat Test Installer has detected 2 different installations of the Minecraft Launcher, which launcher do you wish to install the Combat Tests to?\n\n- Select Microsoft Store if you are playing Minecraft through the Xbox App or the Windows Store.\n- Select Standalone if you downloaded the Minecraft launcher directly from the Minecraft.net website.\n\nIf you are unsure try the Microsoft Store option first, you can always re-run the installer.
installer.prompt.launcher.type.xbox=Microsoft Store / Xbox
installer.prompt.launcher.type.win32=Standalone (Win32)
installer.title=Combat Test Installer
installer.option.create.profile=Create profile
installer.button.fabric=Open the Fabric Installer
installer.tab.vanilla=Vanilla
installer.tab.fabric=Fabric