diff --git a/.gitignore b/.gitignore
index 1b2bd95..e23dba5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -141,5 +141,4 @@ fabric.properties
config.yml
-### Rust ###
-LauncherExe/target/
+src/test
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index 8545eb8..02211b9 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -3,7 +3,7 @@
-
+
diff --git a/src/main/java/tech/nevets/jaml/JAML.java b/src/main/java/tech/nevets/jaml/JAML.java
index 302cd5c..5082fa0 100644
--- a/src/main/java/tech/nevets/jaml/JAML.java
+++ b/src/main/java/tech/nevets/jaml/JAML.java
@@ -1,10 +1,9 @@
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 tech.nevets.jaml.util.ProfileUtils;
import java.io.File;
import java.io.IOException;
@@ -27,8 +26,6 @@ public class JAML {
DiscordRP.update("", "");
guiHandler = new GuiHandler();
- Launch.main(new String[]{});
-
// try {
// System.out.println(VersionFetcher.getLatestVersion("release"));
// } catch (IOException e) {
@@ -36,23 +33,18 @@ public class JAML {
// }
try {
- activeProfile = Profiles.loadProfile(config.getString("launcher.default-profile"));
+ activeProfile = ProfileUtils.loadProfile(config.getString("launcher.default-profile"));
} catch (IOException e) {
System.out.println("Unable to load default profile: " + e.getMessage());
}
-
}
private static void makeDirs() {
- if (config == null) {
+ if (System.getenv("JAML_HOME") == null) {
path = Path.of(System.getenv("APPDATA") + "\\.jaml\\");
} else {
- if (config.getString("launcher.path") == "default") {
- path = Path.of(System.getenv("APPDATA") + "\\.jaml\\");
- } else {
- path = Path.of(config.getString("launcher.path"));
- }
+ path = Path.of(System.getenv("JAML_HOME"));
}
try {
diff --git a/src/main/java/tech/nevets/jaml/Launch.java b/src/main/java/tech/nevets/jaml/Launch.java
index dac5044..d516428 100644
--- a/src/main/java/tech/nevets/jaml/Launch.java
+++ b/src/main/java/tech/nevets/jaml/Launch.java
@@ -7,15 +7,6 @@ import java.util.ArrayList;
public class Launch {
- public static void main(String[] args) {
-
- try {
- 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();
diff --git a/src/main/java/tech/nevets/jaml/Version.java b/src/main/java/tech/nevets/jaml/Version.java
index 306e1c0..e1b2d7c 100644
--- a/src/main/java/tech/nevets/jaml/Version.java
+++ b/src/main/java/tech/nevets/jaml/Version.java
@@ -38,4 +38,8 @@ public class Version {
public void setUrl(URL url) {
this.url = url;
}
+
+ public String toString() {
+ return "version: " + id + ", type: " + type + ", json 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
index 5713786..49898da 100644
--- a/src/main/java/tech/nevets/jaml/gui/FirstLaunchGui.java
+++ b/src/main/java/tech/nevets/jaml/gui/FirstLaunchGui.java
@@ -3,7 +3,7 @@ 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.ProfileUtils;
import tech.nevets.jaml.util.Encryptor;
import javax.swing.*;
@@ -110,7 +110,7 @@ public class FirstLaunchGui implements Runnable, ActionListener {
profile.setLoader(loaderField.getText());
profile.setOfflineMode(Boolean.parseBoolean(offlineModeField.getText()));
try {
- Profiles.createProfile(profile);
+ ProfileUtils.createProfile(profile);
} catch (IOException e) {
e.printStackTrace();
}
diff --git a/src/main/java/tech/nevets/jaml/gui/NewProfileGui.java b/src/main/java/tech/nevets/jaml/gui/NewProfileGui.java
index 3972ce1..27e3cab 100644
--- a/src/main/java/tech/nevets/jaml/gui/NewProfileGui.java
+++ b/src/main/java/tech/nevets/jaml/gui/NewProfileGui.java
@@ -2,7 +2,7 @@ package tech.nevets.jaml.gui;
import tech.nevets.jaml.JAML;
import tech.nevets.jaml.Profile;
-import tech.nevets.jaml.Profiles;
+import tech.nevets.jaml.util.ProfileUtils;
import tech.nevets.jaml.util.Encryptor;
import javax.swing.*;
@@ -116,7 +116,7 @@ public class NewProfileGui implements Runnable, ActionListener {
profile.setLoader(loaderField.getText());
profile.setOfflineMode(Boolean.parseBoolean(offlineModeField.getText()));
try {
- Profiles.createProfile(profile);
+ ProfileUtils.createProfile(profile);
} catch (IOException e) {
e.printStackTrace();
}
diff --git a/src/main/java/tech/nevets/jaml/Profiles.java b/src/main/java/tech/nevets/jaml/util/ProfileUtils.java
similarity index 88%
rename from src/main/java/tech/nevets/jaml/Profiles.java
rename to src/main/java/tech/nevets/jaml/util/ProfileUtils.java
index 170849b..ca0ed9f 100644
--- a/src/main/java/tech/nevets/jaml/Profiles.java
+++ b/src/main/java/tech/nevets/jaml/util/ProfileUtils.java
@@ -1,11 +1,13 @@
-package tech.nevets.jaml;
+package tech.nevets.jaml.util;
import com.google.gson.*;
+import tech.nevets.jaml.JAML;
+import tech.nevets.jaml.Profile;
import java.io.*;
import java.nio.file.Path;
-public class Profiles {
+public class ProfileUtils {
private static final Path PROFILE_PATH = Path.of(JAML.path + "\\profiles\\");
public static void createProfile(Profile profile) throws IOException {
diff --git a/src/main/java/tech/nevets/jaml/util/SemanticVersioner.java b/src/main/java/tech/nevets/jaml/util/SemanticVersioner.java
deleted file mode 100644
index a4da4cf..0000000
--- a/src/main/java/tech/nevets/jaml/util/SemanticVersioner.java
+++ /dev/null
@@ -1,58 +0,0 @@
-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
index 40f4b68..7666990 100644
--- a/src/main/java/tech/nevets/jaml/util/VersionFetcher.java
+++ b/src/main/java/tech/nevets/jaml/util/VersionFetcher.java
@@ -1,9 +1,11 @@
package tech.nevets.jaml.util;
import com.google.gson.Gson;
+import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;
import tech.nevets.jaml.JAML;
+import tech.nevets.jaml.Version;
import java.io.File;
import java.io.IOException;
@@ -11,19 +13,63 @@ 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"));
+ public static Version getVersion(String version) {
+ Gson gson = new Gson();
+ JsonObject versionManifestJson = getList();
+ JsonArray versionsJsonArray = versionManifestJson.getAsJsonArray("versions");
+ Version[] versionArray = gson.fromJson(versionsJsonArray, Version[].class);
- File versionManifestFile = new File(JAML.path + "\\data\\version.json");
+ for (Version value : versionArray) {
+ System.out.println(value.getId());
- return new Gson().fromJson(FileUtils.readFileToString(versionManifestFile), JsonObject.class);
+ if (value.getId().equalsIgnoreCase(version)) {
+ return value;
+ }
+ }
+ return null;
}
- public static String getLatestVersion(String branch) throws IOException {
+ public static Version getVersion(String version, String type) {
+ Gson gson = new Gson();
+ JsonObject versionManifestJson = getList();
+ JsonArray versionsJsonArray = versionManifestJson.getAsJsonArray("versions");
+ Version[] versionArray = gson.fromJson(versionsJsonArray, Version[].class);
+
+ for (Version value : versionArray) {
+ if (value.getType().equalsIgnoreCase(type)) {
+ if (value.getId().equalsIgnoreCase(version)) {
+ return value;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param branch, release or snapshot
+ * @return
+ * @throws IOException
+ */
+ public static String getLatestVersion(String branch) {
JsonObject versionManifestJson = getList();
JsonObject latestJsonObject = versionManifestJson.get("latest").getAsJsonObject();
return latestJsonObject.get(branch).getAsString();
}
+
+ @SuppressWarnings("Deprecated")
+ public static JsonObject getList() {
+ try {
+ 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);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
}