Version fetcher works properly
This commit is contained in:
parent
89a9976c32
commit
87fff58656
3
.gitignore
vendored
3
.gitignore
vendored
@ -141,5 +141,4 @@ fabric.properties
|
||||
|
||||
config.yml
|
||||
|
||||
### Rust ###
|
||||
LauncherExe/target/
|
||||
src/test
|
||||
|
@ -3,7 +3,7 @@
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<Languages>
|
||||
<language minSize="49" name="Java" />
|
||||
<language minSize="88" name="Java" />
|
||||
</Languages>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
|
@ -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 {
|
||||
|
@ -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<String> commandArray, boolean printConsole) throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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 {
|
@ -1,58 +0,0 @@
|
||||
package tech.nevets.jaml.util;
|
||||
|
||||
public class SemanticVersioner implements Comparable<SemanticVersioner> {
|
||||
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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user