Skip to content

Commit

Permalink
Merge pull request #2 from nexia-cts/dev
Browse files Browse the repository at this point in the history
add installing fabric support
  • Loading branch information
not-coded authored Oct 23, 2023
2 parents ed51370 + a479383 commit 45938bd
Show file tree
Hide file tree
Showing 12 changed files with 349 additions and 24 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ bin/
.vscode/

### Mac OS ###
.DS_Store
.DS_Store


### cache ###
cache/
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
23 changes: 19 additions & 4 deletions src/main/java/com/nexia/installer/InstallerGUI.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -11,13 +12,18 @@
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;
}

Expand All @@ -43,14 +49,23 @@ public static void load() throws UnsupportedLookAndFeelException, ClassNotFoundE
}

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);
gui.setLocationRelativeTo(null);
gui.setVisible(true);
}

public void updateSize(boolean updateMinimum) {
private void updateSize(boolean updateMinimum) {
if (updateMinimum) setMinimumSize(null);
setPreferredSize(null);
pack();
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/nexia/installer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ public ResourceBundle newBundle(String baseName, Locale locale, String format, C

public static void main(String[] args) throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException, IllegalAccessException {

os = OS.LINUX;

if(System.getProperty("os.name").startsWith("Windows")){
os = OS.WINDOWS;
System.setProperty("javax.net.ssl.trustStoreType", "WINDOWS-ROOT");
}

if(System.getProperty("os.name").startsWith("lin"))
os = OS.LINUX;

if(System.getProperty("os.name").startsWith("mac"))
os = OS.MAC;

Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/nexia/installer/util/HttpAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.nexia.installer.util;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpAPI {

public static String userAgent = "Mozilla/5.0 (compatible; combat-test-installer; +https://github.com/nexia-cts/combat-test-installer)";

public static String get(String url) {
try {
URL apiUrl = new URL(url);

HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();

connection.setRequestProperty("User-Agent", userAgent);
connection.setRequestMethod("GET");

BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
StringBuilder response = new StringBuilder();
while ((line = reader.readLine()) != null) {
response.append(line);
}

reader.close();
connection.disconnect();

return response.toString();
} catch (Exception ignored) { return null; }
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/nexia/installer/util/InstallerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public JPanel setPanel(InstallerGUI gui) {
buttonInstall.addActionListener(e -> {
buttonInstall.setEnabled(false);
try {
install();
launch();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
Expand Down Expand Up @@ -107,7 +107,7 @@ public void addRow(Container parent, GridBagConstraints c, boolean last, String
c.gridx = 0;
}

private void install() throws IOException {
public void launch() throws IOException {

String stringGameVersion = (String) gameVersionComboBox.getSelectedItem();
VersionHandler.GameVersion gameVersion = VersionHandler.identifyGameVersion(stringGameVersion);
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/nexia/installer/util/InstallerUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -115,7 +113,7 @@ public static void install(Path mcDir, VersionHandler.GameVersion gameVersion) {
}).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,
Expand All @@ -135,7 +133,7 @@ private static ProfileInstaller.LauncherType showLauncherTypeSelection() {
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()),
Expand All @@ -147,6 +145,6 @@ private static void showDone(VersionHandler.GameVersion gameVersion) throws URIS
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);
}
}
10 changes: 7 additions & 3 deletions src/main/java/com/nexia/installer/util/ProfileInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ private static Json createProfile(String name) {
}

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;
}

}
}
6 changes: 2 additions & 4 deletions src/main/java/com/nexia/installer/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -136,9 +136,7 @@ public static String getProfileIcon() {

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 Nexia icon.
}

return "furnace"; // Fallback to furnace icon if we cant load CTS icon.
}
}
Loading

0 comments on commit 45938bd

Please sign in to comment.