diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..8545eb8
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
index c4f2856..bdb4873 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,7 +2,6 @@
-
\ No newline at end of file
diff --git a/LauncherExe/Cargo.lock b/LauncherExe/Cargo.lock
deleted file mode 100644
index 0c6465f..0000000
--- a/LauncherExe/Cargo.lock
+++ /dev/null
@@ -1,7 +0,0 @@
-# This file is automatically @generated by Cargo.
-# It is not intended for manual editing.
-version = 3
-
-[[package]]
-name = "LauncherExe"
-version = "0.1.0"
diff --git a/LauncherExe/Cargo.toml b/LauncherExe/Cargo.toml
deleted file mode 100644
index f5a6875..0000000
--- a/LauncherExe/Cargo.toml
+++ /dev/null
@@ -1,8 +0,0 @@
-[package]
-name = "LauncherExe"
-version = "0.1.0"
-edition = "2021"
-
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[dependencies]
diff --git a/LauncherExe/LauncherExe.iml b/LauncherExe/LauncherExe.iml
deleted file mode 100644
index 6b25966..0000000
--- a/LauncherExe/LauncherExe.iml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/LauncherExe/src/main.rs b/LauncherExe/src/main.rs
deleted file mode 100644
index 909c04c..0000000
--- a/LauncherExe/src/main.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-use std::process::Command;
-
-fn main() {
-
- let mut cmd = Command::new("java");
- cmd.arg("-jar");
- cmd.arg("JAML.jar");
-
- match cmd.output() {
- Ok(output) => {
- },
- Err(e) => {
- println!("{}", e);
- }
- }
-}
diff --git a/build.gradle b/build.gradle
index 26e639c..3b0840a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,7 +4,7 @@ plugins {
}
group 'tech.nevets.jaml'
-version '0.4.0'
+version '0.4.1'
repositories {
mavenCentral()
@@ -26,6 +26,7 @@ dependencies {
implementation 'me.carleslc.Simple-YAML:Simple-Yaml:1.7.3'
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'net.arikia.dev:drpc:1.0'
+ implementation 'commons-io:commons-io:2.11.0'
}
shadowJar {
diff --git a/src/main/java/tech/nevets/jaml/Config.java b/src/main/java/tech/nevets/jaml/Config.java
index a62763a..dede4bd 100644
--- a/src/main/java/tech/nevets/jaml/Config.java
+++ b/src/main/java/tech/nevets/jaml/Config.java
@@ -5,17 +5,17 @@ import org.simpleyaml.configuration.file.YamlFile;
import java.io.IOException;
public class Config {
- private static final YamlFile ymlFile = new YamlFile(JAML.path + "\\config.yml");
+ private static final YamlFile YML_FILE = new YamlFile(JAML.path + "\\config.yml");
public static void loadConfig() {
try {
- if (!ymlFile.exists()) {
+ if (!YML_FILE.exists()) {
System.out.println("Config file not found, creating new one...");
- ymlFile.createNewFile(true);
+ YML_FILE.createNewFile(true);
System.out.println("Config file created!");
} else {
System.out.println("Loading Config file...");
- ymlFile.loadWithComments();
+ YML_FILE.loadWithComments();
System.out.println("Config file loaded!");
}
} catch (final Exception e) {
@@ -23,25 +23,55 @@ public class Config {
e.printStackTrace();
}
- ymlFile.addDefault("java.jdk8", "");
- ymlFile.addDefault("java.jdk16", "");
- ymlFile.addDefault("java.jdk17", "");
- ymlFile.addDefault("launcher.default-profile", "default");
- ymlFile.addDefault("launcher.path","default");
- ymlFile.setComment("launcher.path","Path to JAML files\n" + "default: " + JAML.path.toString());
- ymlFile.addDefault("launcher.verbose", false);
- ymlFile.setComment("launcher.verbose", "If true, will print out all the messages");
- ymlFile.addDefault("launcher.version", "0.1.0");
- ymlFile.setComment("launcher.version", "Jaml version, don't change it!");
+ YML_FILE.setComment("java",
+ "\n"
+ + " JJJJJJJJJJJ AAA MMMMMMMM MMMMMMMM LLLLLLLLLLL \n"
+ + " J:::::::::J A:::A M:::::::M M:::::::M L:::::::::L \n"
+ + " J:::::::::J A:::::A M::::::::M M::::::::M L:::::::::L \n"
+ + " JJ:::::::JJ A:::::::A M:::::::::M M:::::::::M LL:::::::LL \n"
+ + " J:::::J A:::::::::A M::::::::::M M::::::::::M L:::::L \n"
+ + " J:::::J A:::::A:::::A M:::::::::::M M:::::::::::M L:::::L \n"
+ + " J:::::J A:::::A A:::::A M:::::::M::::M M::::M:::::::M L:::::L \n"
+ + " J:::::j A:::::A A:::::A M::::::M M::::M M::::M M::::::M L:::::L \n"
+ + " J:::::J A:::::A A:::::A M::::::M M::::M::::M M::::::M L:::::L \n"
+ + " JJJJJJJ J:::::J A:::::AAAAAAAAA:::::A M::::::M M:::::::M M::::::M L:::::L \n"
+ + " J:::::J J:::::J A:::::::::::::::::::::A M::::::M M:::::M M::::::M L:::::L \n"
+ + " J::::::J J::::::J A:::::AAAAAAAAAAAAA:::::A M::::::M MMMMM M::::::M L:::::L LLLLLL\n"
+ + " J:::::::JJJ:::::::J A:::::A A:::::A M::::::M M::::::M LL:::::::LLLLLLLLL:::::L\n"
+ + " JJ:::::::::::::JJ A:::::A A:::::A M::::::M M::::::M L::::::::::::::::::::::L\n"
+ + " JJ:::::::::JJ A:::::A A:::::A M::::::M M::::::M L::::::::::::::::::::::L\n"
+ + " JJJJJJJJJ AAAAAAA AAAAAAA MMMMMMMM MMMMMMMM LLLLLLLLLLLLLLLLLLLLLLLL\n"
+ );
+
+ YML_FILE.addDefault("java.jdk8", "");
+ YML_FILE.setComment("java.jdk8", "Set these to the bin directory of each JDK version");
+ YML_FILE.addDefault("java.jdk16", "");
+ YML_FILE.addDefault("java.jdk17", "");
+ YML_FILE.addDefault("launcher.default-profile", "default");
+ YML_FILE.setComment("launcher.default-profile", "Set's the profile that will be loaded automatically");
+ YML_FILE.addDefault("launcher.path","default");
+ YML_FILE.setComment("launcher.path","Path to JAML files\n" + "default: " + JAML.path.toString());
+ YML_FILE.addDefault("launcher.first-launch", true);
+ YML_FILE.setComment("launcher.first-launch", "Do Not Change, will regenerate files");
+ YML_FILE.addDefault("launcher.verbose", false);
+ YML_FILE.setComment("launcher.verbose", "If true, will print out all the messages");
+ YML_FILE.addDefault("launcher.version", "0.1.0");
+ YML_FILE.setComment("launcher.version", "Jaml version, don't change it!");
try {
- ymlFile.save();
+ YML_FILE.save();
} catch (IOException e) {
e.printStackTrace();
}
}
public static YamlFile getConfig() {
- return ymlFile;
+ return YML_FILE;
}
+
+ public static void reloadConfig() {
+ CONFIG = getConfig();
+ }
+
+ public static YamlFile CONFIG = getConfig();
}
diff --git a/src/main/java/tech/nevets/jaml/DiscordRP.java b/src/main/java/tech/nevets/jaml/DiscordRP.java
index 22ff0ba..8036a9f 100644
--- a/src/main/java/tech/nevets/jaml/DiscordRP.java
+++ b/src/main/java/tech/nevets/jaml/DiscordRP.java
@@ -5,16 +5,14 @@ import net.arikia.dev.drpc.DiscordRPC;
import net.arikia.dev.drpc.DiscordRichPresence;
public class DiscordRP {
- //TODO Make this actually work
+ private static boolean running = true;
+ private static long created = 0;
- private boolean running = true;
- private long created = 0;
+ public static void start() {
+ created = System.currentTimeMillis();
- public void start() {
- this.created = System.currentTimeMillis();
-
- DiscordEventHandlers handlers = new DiscordEventHandlers.Builder().setReadyEventHandler((user) -> {
- System.out.println("Welcome " + user.username + "#" + user.discriminator + ".");
+ DiscordEventHandlers handlers = new DiscordEventHandlers.Builder().setReadyEventHandler(user -> {
+ System.out.println("Welcome " + user.username + "#" + user.discriminator + "!");
update("Starting...", "");
}).build();
@@ -28,12 +26,12 @@ public class DiscordRP {
}).start();
}
- public void shutdown() {
+ public static void shutdown() {
running = false;
DiscordRPC.discordShutdown();
}
- public void update(String firstLine, String secondLine) {
+ public static void update(String firstLine, String secondLine) {
DiscordRichPresence.Builder b = new DiscordRichPresence.Builder(secondLine);
b.setBigImage("large", "");
b.setDetails(firstLine);
@@ -41,4 +39,4 @@ public class DiscordRP {
DiscordRPC.discordUpdatePresence(b.build());
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/tech/nevets/jaml/FirstLaunch.java b/src/main/java/tech/nevets/jaml/FirstLaunch.java
new file mode 100644
index 0000000..6789a06
--- /dev/null
+++ b/src/main/java/tech/nevets/jaml/FirstLaunch.java
@@ -0,0 +1,16 @@
+package tech.nevets.jaml;
+
+import java.io.IOException;
+
+public class FirstLaunch {
+ public FirstLaunch() {
+ System.out.println("First Launch!");
+
+ Config.CONFIG.set("launcher.first-launch", false);
+ try {
+ Config.CONFIG.save();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/tech/nevets/jaml/JAML.java b/src/main/java/tech/nevets/jaml/JAML.java
index 793b820..302cd5c 100644
--- a/src/main/java/tech/nevets/jaml/JAML.java
+++ b/src/main/java/tech/nevets/jaml/JAML.java
@@ -1,36 +1,47 @@
package tech.nevets.jaml;
+import net.arikia.dev.drpc.DiscordRPC;
+import org.apache.commons.io.FileUtils;
import org.simpleyaml.configuration.file.YamlFile;
import tech.nevets.jaml.gui.GuiHandler;
+import tech.nevets.jaml.util.VersionFetcher;
+import java.io.File;
import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
import java.nio.file.Path;
+import java.nio.file.Paths;
public class JAML {
- public static YamlFile config;
+ public static YamlFile config = Config.CONFIG;
public static Path path;
- public static DiscordRP drp = new DiscordRP();
public static GuiHandler guiHandler;
public static Profile activeProfile;
public static void main(String[] args) {
+ DiscordRP.start();
makeDirs();
Config.loadConfig();
- config = Config.getConfig();
+ DiscordRP.update("", "");
+ guiHandler = new GuiHandler();
+
+ Launch.main(new String[]{});
+
+// try {
+// System.out.println(VersionFetcher.getLatestVersion("release"));
+// } catch (IOException e) {
+// e.printStackTrace();
+// }
try {
- Profiles pfs = new Profiles();
- activeProfile = pfs.loadProfile(config.getString("launcher.default-profile"));
+ activeProfile = Profiles.loadProfile(config.getString("launcher.default-profile"));
} catch (IOException e) {
System.out.println("Unable to load default profile: " + e.getMessage());
}
- drp.start();
- guiHandler = new GuiHandler();
-
- drp.shutdown();
}
private static void makeDirs() {
@@ -69,5 +80,29 @@ public class JAML {
} catch (Exception e) {
e.printStackTrace();
}
+
+ try {
+ Path dataPath = Path.of(path + "\\data\\");
+ if (!dataPath.toFile().exists()) {
+ dataPath.toFile().mkdirs();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ copyAssets();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void copyAssets() throws IOException, URISyntaxException {
+ URL resource = JAML.class.getResource("/assets/");
+ File assets = Paths.get(resource.toURI()).toFile();
+
+ if (!Path.of(path + "\\data\\").toFile().exists()) {
+ FileUtils.copyDirectory(assets, new File(path + "\\assets\\"));
+ }
}
}
\ No newline at end of file
diff --git a/src/main/java/tech/nevets/jaml/Launch.java b/src/main/java/tech/nevets/jaml/Launch.java
index 086cf84..dac5044 100644
--- a/src/main/java/tech/nevets/jaml/Launch.java
+++ b/src/main/java/tech/nevets/jaml/Launch.java
@@ -1,18 +1,70 @@
package tech.nevets.jaml;
-import java.io.File;
+import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
public class Launch {
- public static void launch() {
- String[] command = {"echo", "Hello, World!"};
- ProcessBuilder builder = new ProcessBuilder(command);
- builder.directory(new File(JAML.path + "\\process"));
+
+ public static void main(String[] args) {
+
try {
- Process process = builder.start();
- } catch (IOException ex) {
- ex.printStackTrace();
+ new Launch(parseCommand(17, 4096, "-XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M "), true);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public Launch(ArrayList commandArray, boolean printConsole) throws IOException {
+ StringBuilder sb = new StringBuilder();
+
+ for (String commandString : commandArray) {
+ sb.append(commandString);
+ sb.append(" ");
+ }
+
+ String command = sb.toString();
+
+ System.out.println(command);
+
+ Process process = Runtime.getRuntime().exec(command);
+
+ if (printConsole) {
+ printResults(process);
+ }
+
+ process.destroy();
+ }
+
+ public static ArrayList parseCommand(int jdkVersion, int memoryAmount, String garbageCollection) {
+ ArrayList cmd = new ArrayList();
+ if (jdkVersion == 8) {
+ cmd.add(("\"" + Config.CONFIG.getString("java.jdk8") + "\\javaw.exe\""));
+ } else if (jdkVersion == 16) {
+ cmd.add(("\"" + Config.CONFIG.getString("java.jdk16") + "\\javaw.exe\""));
+ } else if (jdkVersion == 17) {
+ cmd.add(("\"" + Config.CONFIG.getString("java.jdk17") + "\\java.exe\""));
+ }
+
+ cmd.add(("-Xmx" + memoryAmount + "M"));
+ cmd.add(("-Xms" + memoryAmount + "M"));
+ cmd.add((garbageCollection));
+ cmd.add("-Dlog4j2.formatMsgNoLookups=true -Dlog4j.configurationFile=assets\\log_configs\\client-1.12.xml");
+ cmd.add("-Djava.library.path=versions\\1.18.1\\natives\" \"-cp\" \"libraries\\com\\mojang\\blocklist\\1.0.6\\blocklist-1.0.6.jar;libraries\\com\\mojang\\patchy\\2.1.6\\patchy-2.1.6.jar;libraries\\com\\github\\oshi\\oshi-core\\5.8.2\\oshi-core-5.8.2.jar;libraries\\net\\java\\dev\\jna\\jna\\5.9.0\\jna-5.9.0.jar;libraries\\net\\java\\dev\\jna\\jna-platform\\5.9.0\\jna-platform-5.9.0.jar;libraries\\org\\slf4j\\slf4j-api\\1.8.0-beta4\\slf4j-api-1.8.0-beta4.jar;libraries\\org\\apache\\logging\\log4j\\log4j-slf4j18-impl\\2.14.1\\log4j-slf4j18-impl-2.14.1.jar;libraries\\com\\ibm\\icu\\icu4j\\69.1\\icu4j-69.1.jar;libraries\\com\\mojang\\javabridge\\1.2.24\\javabridge-1.2.24.jar;libraries\\net\\sf\\jopt-simple\\jopt-simple\\5.0.4\\jopt-simple-5.0.4.jar;libraries\\io\\netty\\netty-all\\4.1.68.Final\\netty-all-4.1.68.Final.jar;libraries\\com\\google\\guava\\failureaccess\\1.0.1\\failureaccess-1.0.1.jar;libraries\\com\\google\\guava\\guava\\31.0.1-jre\\guava-31.0.1-jre.jar;libraries\\org\\apache\\commons\\commons-lang3\\3.12.0\\commons-lang3-3.12.0.jar;libraries\\commons-io\\commons-io\\2.11.0\\commons-io-2.11.0.jar;libraries\\commons-codec\\commons-codec\\1.15\\commons-codec-1.15.jar;libraries\\com\\mojang\\brigadier\\1.0.18\\brigadier-1.0.18.jar;libraries\\com\\mojang\\datafixerupper\\4.0.26\\datafixerupper-4.0.26.jar;libraries\\com\\google\\code\\gson\\gson\\2.8.8\\gson-2.8.8.jar;libraries\\com\\mojang\\authlib\\3.2.38\\authlib-3.2.38.jar;libraries\\org\\apache\\commons\\commons-compress\\1.21\\commons-compress-1.21.jar;libraries\\org\\apache\\httpcomponents\\httpclient\\4.5.13\\httpclient-4.5.13.jar;libraries\\commons-logging\\commons-logging\\1.2\\commons-logging-1.2.jar;libraries\\org\\apache\\httpcomponents\\httpcore\\4.4.14\\httpcore-4.4.14.jar;libraries\\it\\unimi\\dsi\\fastutil\\8.5.6\\fastutil-8.5.6.jar;libraries\\org\\apache\\logging\\log4j\\log4j-api\\2.14.1\\log4j-api-2.14.1.jar;libraries\\org\\apache\\logging\\log4j\\log4j-core\\2.14.1\\log4j-core-2.14.1.jar;libraries\\org\\lwjgl\\lwjgl\\3.2.2\\lwjgl-3.2.2.jar;libraries\\org\\lwjgl\\lwjgl-jemalloc\\3.2.2\\lwjgl-jemalloc-3.2.2.jar;libraries\\org\\lwjgl\\lwjgl-openal\\3.2.2\\lwjgl-openal-3.2.2.jar;libraries\\org\\lwjgl\\lwjgl-opengl\\3.2.2\\lwjgl-opengl-3.2.2.jar;libraries\\org\\lwjgl\\lwjgl-glfw\\3.2.2\\lwjgl-glfw-3.2.2.jar;libraries\\org\\lwjgl\\lwjgl-stb\\3.2.2\\lwjgl-stb-3.2.2.jar;libraries\\org\\lwjgl\\lwjgl-tinyfd\\3.2.2\\lwjgl-tinyfd-3.2.2.jar;libraries\\com\\mojang\\text2speech\\1.11.3\\text2speech-1.11.3.jar;versions\\1.18.1\\1.18.1.jar\"");
+ cmd.add("net.minecraft.client.main.Main");
+ cmd.add("--username Name --version 1.18.1 --gameDir . --assetsDir assets --assetIndex 1.18 --uuid 0f28983a46ce33b1aed45cdc95bf44c3 --accessToken 00000000000000000000000000000000 --clientId 0000 --xuid 0000 --userType mojang --versionType release");
+
+ return cmd;
+ }
+
+ private static void printResults(Process process) throws IOException {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ String line = "";
+ while ((line = reader.readLine()) != null) {
+ System.out.println(line);
}
- System.exit(0);
}
}
+
+
diff --git a/src/main/java/tech/nevets/jaml/Profiles.java b/src/main/java/tech/nevets/jaml/Profiles.java
index 88ba0e3..170849b 100644
--- a/src/main/java/tech/nevets/jaml/Profiles.java
+++ b/src/main/java/tech/nevets/jaml/Profiles.java
@@ -6,11 +6,11 @@ import java.io.*;
import java.nio.file.Path;
public class Profiles {
- private static final Path profilePath = Path.of(JAML.path + "\\profiles\\");
+ private static final Path PROFILE_PATH = Path.of(JAML.path + "\\profiles\\");
public static void createProfile(Profile profile) throws IOException {
String profileName = profile.getProfileName();
- Writer writer = new FileWriter(profilePath + "\\" + profileName + ".json");
+ Writer writer = new FileWriter(PROFILE_PATH + "\\" + profileName + ".json");
GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
@@ -18,12 +18,13 @@ public class Profiles {
String jsonString = gson.toJson(profile);
writer.write(jsonString);
writer.close();
+
+ loadProfile(profileName);
}
- public Profile loadProfile(String profileName) throws FileNotFoundException {
- BufferedReader reader = new BufferedReader(new FileReader(profilePath + "\\" + profileName + ".json"));
- Profile profile = new Gson().fromJson(reader, Profile.class);
+ public static Profile loadProfile(String profileName) throws FileNotFoundException {
+ BufferedReader reader = new BufferedReader(new FileReader(PROFILE_PATH + "\\" + profileName + ".json"));
- return profile;
+ return new Gson().fromJson(reader, Profile.class);
}
}
diff --git a/src/main/java/tech/nevets/jaml/Version.java b/src/main/java/tech/nevets/jaml/Version.java
new file mode 100644
index 0000000..306e1c0
--- /dev/null
+++ b/src/main/java/tech/nevets/jaml/Version.java
@@ -0,0 +1,41 @@
+package tech.nevets.jaml;
+
+import java.net.URL;
+
+public class Version {
+ private String id;
+ private String type;
+ private URL url;
+
+ public Version() {}
+
+ public Version(String id, String type, URL url) {
+ this.id = id;
+ this.type = type;
+ this.url = url;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public URL getUrl() {
+ return url;
+ }
+
+ public void setUrl(URL url) {
+ this.url = url;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/tech/nevets/jaml/gui/FirstLaunchGui.java b/src/main/java/tech/nevets/jaml/gui/FirstLaunchGui.java
new file mode 100644
index 0000000..5713786
--- /dev/null
+++ b/src/main/java/tech/nevets/jaml/gui/FirstLaunchGui.java
@@ -0,0 +1,126 @@
+package tech.nevets.jaml.gui;
+
+import tech.nevets.jaml.FirstLaunch;
+import tech.nevets.jaml.JAML;
+import tech.nevets.jaml.Profile;
+import tech.nevets.jaml.Profiles;
+import tech.nevets.jaml.util.Encryptor;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.IOException;
+import java.nio.file.Path;
+
+public class FirstLaunchGui implements Runnable, ActionListener {
+ //TODO Formatting
+ private JFrame frame;
+ private JPanel panel;
+
+ private JTextField emailField;
+ private JPasswordField passwordField;
+ private JTextField gamePathField;
+ private JTextField versionField;
+ private JTextField loaderField;
+ private JTextField offlineModeField;
+
+ public void startGui() {
+ frame = new JFrame("Create First Profile");
+
+ JLabel emailLabel = new JLabel("Email:");
+ emailLabel.setBounds(10, 50, 80, 25);
+ emailField = new JTextField(20);
+
+ JLabel passwordLabel = new JLabel("Password:");
+ passwordLabel.setBounds(100, 50, 165, 25);
+ passwordField = new JPasswordField(20);
+
+ JLabel gamePathLabel = new JLabel("Game Path:");
+ gamePathLabel.setBounds(10, 80, 80, 25);
+ gamePathField = new JTextField(20);
+
+ JButton gamePathButton = new JButton("Choose Path");
+ gamePathButton.setBounds(200, 80, 25, 25);
+ gamePathButton.addActionListener(ae -> {
+ JFileChooser fileChooser = new JFileChooser(System.getenv("APPDATA") + "\\.minecraft\\");
+ fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ fileChooser.showSaveDialog(null);
+ if (fileChooser.getSelectedFile() == null) { return; }
+ gamePathField.setText(fileChooser.getSelectedFile().toString());
+ fileChooser.setVisible(false);
+ });
+
+ JLabel versionLabel = new JLabel("Version:");
+ versionLabel.setBounds(100, 80, 165, 25);
+ versionField = new JTextField(20);
+
+ JLabel loaderLabel = new JLabel("Loader:");
+ loaderLabel.setBounds(10, 110, 80, 25);
+ loaderField = new JTextField(20);
+
+ JLabel offlineModeLabel = new JLabel("Offline Mode:");
+ offlineModeLabel.setBounds(100, 110, 165, 25);
+ offlineModeField = new JTextField(20);
+
+ JButton button = new JButton("Create Profile");
+ button.addActionListener(this);
+
+ panel = new JPanel();
+ panel.setBorder(BorderFactory.createEmptyBorder(300, 300, 100, 300));
+ panel.setLayout(new GridLayout(0, 1));
+ panel.add(emailLabel);
+ panel.add(emailField);
+ panel.add(passwordLabel);
+ panel.add(passwordField);
+ panel.add(gamePathLabel);
+ panel.add(gamePathField);
+ panel.add(gamePathButton);
+ panel.add(versionLabel);
+ panel.add(versionField);
+ panel.add(loaderLabel);
+ panel.add(loaderField);
+ panel.add(offlineModeLabel);
+ panel.add(offlineModeField);
+ panel.add(button);
+
+ frame.add(panel, BorderLayout.CENTER);
+ frame.setSize(500, 500);
+ frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ frame.setTitle("JAML");
+ frame.setIconImage(new ImageIcon(JAML.path + "\\assets\\icon.png").getImage());
+ frame.pack();
+ frame.setVisible(true);
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ Profile profile = new Profile();
+ profile.setProfileName("default");
+ profile.setEmail(emailField.getText());
+
+ if (passwordField.getPassword().length > 0){
+ profile.setHashedPassword(Encryptor.encrypt(String.valueOf(passwordField.getPassword())).getData());
+ profile.setKey(Encryptor.encrypt(String.valueOf(passwordField.getPassword())).getKey());
+ profile.setSalt(Encryptor.encrypt(String.valueOf(passwordField.getPassword())).getSalt());
+ }
+
+ profile.setGamePath(Path.of(gamePathField.getText()));
+ profile.setVersion(versionField.getText());
+ profile.setLoader(loaderField.getText());
+ profile.setOfflineMode(Boolean.parseBoolean(offlineModeField.getText()));
+ try {
+ Profiles.createProfile(profile);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ frame.dispose();
+ }
+
+ @Override
+ public void run() {
+ new FirstLaunch();
+ startGui();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/tech/nevets/jaml/gui/GuiHandler.java b/src/main/java/tech/nevets/jaml/gui/GuiHandler.java
index c4a69a6..d8ad080 100644
--- a/src/main/java/tech/nevets/jaml/gui/GuiHandler.java
+++ b/src/main/java/tech/nevets/jaml/gui/GuiHandler.java
@@ -1,8 +1,16 @@
package tech.nevets.jaml.gui;
+import tech.nevets.jaml.Config;
+
public class GuiHandler {
public GuiHandler() {
+ if (Config.CONFIG.getBoolean("launcher.first-launch")) {
+ FirstLaunchGui firstLaunchGui = new FirstLaunchGui();
+ Thread firstLaunchThread = new Thread(firstLaunchGui);
+ firstLaunchThread.start();
+ }
+
HomeGui homeGui = new HomeGui();
Thread homeGuiThread = new Thread(homeGui);
homeGuiThread.start();
diff --git a/src/main/java/tech/nevets/jaml/gui/NewProfileGui.java b/src/main/java/tech/nevets/jaml/gui/NewProfileGui.java
index 21e8820..3972ce1 100644
--- a/src/main/java/tech/nevets/jaml/gui/NewProfileGui.java
+++ b/src/main/java/tech/nevets/jaml/gui/NewProfileGui.java
@@ -47,7 +47,7 @@ public class NewProfileGui implements Runnable, ActionListener {
JButton gamePathButton = new JButton("Choose Path");
gamePathButton.setBounds(200, 80, 25, 25);
gamePathButton.addActionListener(ae -> {
- JFileChooser fileChooser = new JFileChooser(JAML.path.toString());
+ JFileChooser fileChooser = new JFileChooser(System.getenv("APPDATA") + "\\.minecraft\\");
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.showSaveDialog(null);
if (fileChooser.getSelectedFile() == null) { return; }
diff --git a/src/main/java/tech/nevets/jaml/util/MultiReturn.java b/src/main/java/tech/nevets/jaml/util/DataCompressor.java
similarity index 51%
rename from src/main/java/tech/nevets/jaml/util/MultiReturn.java
rename to src/main/java/tech/nevets/jaml/util/DataCompressor.java
index f07b466..7e8edbb 100644
--- a/src/main/java/tech/nevets/jaml/util/MultiReturn.java
+++ b/src/main/java/tech/nevets/jaml/util/DataCompressor.java
@@ -1,17 +1,12 @@
package tech.nevets.jaml.util;
-public class MultiReturn {
+public class DataCompressor {
- private String data;
- private String key;
- private String salt;
+ private final String data;
+ private final String key;
+ private final String salt;
- public MultiReturn(String data, String key) {
- this.data = data;
- this.key = key;
- }
-
- public MultiReturn(String data, String key, String salt) {
+ public DataCompressor(String data, String key, String salt) {
this.data = data;
this.key = key;
this.salt = salt;
diff --git a/src/main/java/tech/nevets/jaml/util/Encryptor.java b/src/main/java/tech/nevets/jaml/util/Encryptor.java
index 7141427..bfa5061 100644
--- a/src/main/java/tech/nevets/jaml/util/Encryptor.java
+++ b/src/main/java/tech/nevets/jaml/util/Encryptor.java
@@ -13,7 +13,7 @@ import java.util.Random;
public class Encryptor {
- public static MultiReturn encrypt(String textToEncrypt) {
+ public static DataCompressor encrypt(String textToEncrypt) {
String key = generateHash();
String salt = generateHash();
String hashedData = null;
@@ -35,12 +35,12 @@ public class Encryptor {
System.out.println("Error while encrypting: " + e.getMessage());
}
- MultiReturn pair = new MultiReturn(hashedData, key, salt);
+ DataCompressor pair = new DataCompressor(hashedData, key, salt);
return pair;
}
- public static String decrypt(MultiReturn pair) {
+ public static String decrypt(DataCompressor pair) {
String hash = pair.getData();
String key = pair.getKey();
String salt = pair.getSalt();
diff --git a/src/main/java/tech/nevets/jaml/util/SemanticVersioner.java b/src/main/java/tech/nevets/jaml/util/SemanticVersioner.java
new file mode 100644
index 0000000..a4da4cf
--- /dev/null
+++ b/src/main/java/tech/nevets/jaml/util/SemanticVersioner.java
@@ -0,0 +1,58 @@
+package tech.nevets.jaml.util;
+
+public class SemanticVersioner implements Comparable {
+ private String version;
+
+ public SemanticVersioner(String version) {
+ if (version == null) {
+ throw new IllegalArgumentException("Version cannot be null");
+ }
+
+ if (!version.matches("[0-9]+(\\.[0-9]+)*")) {
+ throw new IllegalArgumentException("Invalid version format");
+ }
+
+ this.version = version;
+ }
+
+ public final String get() {
+ return this.version;
+ }
+
+ @Override
+ public int compareTo(SemanticVersioner sv) {
+ if(sv == null)
+ return 1;
+ String[] thisParts = this.get().split("\\.");
+ String[] svParts = sv.get().split("\\.");
+ int length = Math.max(thisParts.length, svParts.length);
+ for(int i = 0; i < length; i++) {
+ int thisPart = i < thisParts.length ?
+ Integer.parseInt(thisParts[i]) : 0;
+ int svPart = i < svParts.length ?
+ Integer.parseInt(svParts[i]) : 0;
+ if(thisPart < svPart)
+ return -1;
+ if(thisPart > svPart)
+ return 1;
+ }
+ return 0;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+
+ if (o == null) {
+ return false;
+ }
+
+ if (this.getClass() != o.getClass()) {
+ return false;
+ }
+
+ return this.compareTo((SemanticVersioner) o) == 0;
+ }
+}
diff --git a/src/main/java/tech/nevets/jaml/util/VersionFetcher.java b/src/main/java/tech/nevets/jaml/util/VersionFetcher.java
new file mode 100644
index 0000000..40f4b68
--- /dev/null
+++ b/src/main/java/tech/nevets/jaml/util/VersionFetcher.java
@@ -0,0 +1,29 @@
+package tech.nevets.jaml.util;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import org.apache.commons.io.FileUtils;
+import tech.nevets.jaml.JAML;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+public class VersionFetcher {
+
+ public static JsonObject getList() throws IOException {
+ URL versionManifestUrl = new URL("https://launchermeta.mojang.com/mc/game/version_manifest.json");
+ FileUtils.copyURLToFile(versionManifestUrl, new File(JAML.path + "\\data\\version.json"));
+
+ File versionManifestFile = new File(JAML.path + "\\data\\version.json");
+
+ return new Gson().fromJson(FileUtils.readFileToString(versionManifestFile), JsonObject.class);
+ }
+
+ public static String getLatestVersion(String branch) throws IOException {
+ JsonObject versionManifestJson = getList();
+ JsonObject latestJsonObject = versionManifestJson.get("latest").getAsJsonObject();
+
+ return latestJsonObject.get(branch).getAsString();
+ }
+}
diff --git a/src/main/resources/assets/icon.png b/src/main/resources/assets/icon.png
new file mode 100644
index 0000000..2fc8243
Binary files /dev/null and b/src/main/resources/assets/icon.png differ
diff --git a/src/main/resources/assets/jaml.png b/src/main/resources/assets/jaml.png
new file mode 100644
index 0000000..5191507
Binary files /dev/null and b/src/main/resources/assets/jaml.png differ