2021-10-29 22:50:42 +02:00
|
|
|
package io.gitlab.jfronny.inceptum;
|
2021-10-27 22:00:08 +02:00
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.GsonBuilder;
|
2021-11-24 16:02:33 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.cli.InvokedCommandDescription;
|
2021-10-31 16:59:25 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.gson.*;
|
|
|
|
import io.gitlab.jfronny.inceptum.model.ComparableVersion;
|
|
|
|
import io.gitlab.jfronny.inceptum.model.inceptum.Config;
|
2021-11-02 16:44:26 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.model.inceptum.source.ModSource;
|
2021-10-29 22:50:42 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.model.microsoft.OauthTokenResponse;
|
|
|
|
import io.gitlab.jfronny.inceptum.model.mojang.MinecraftArgument;
|
|
|
|
import io.gitlab.jfronny.inceptum.model.mojang.Rules;
|
2021-11-02 13:43:18 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.util.MetaHolder;
|
2021-10-29 22:50:42 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.util.Utils;
|
2021-11-02 13:43:18 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.util.api.McApi;
|
2021-10-30 22:05:24 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.windows.AlertWindow;
|
2021-10-30 19:26:59 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2021-10-27 22:00:08 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2021-10-28 23:27:47 +02:00
|
|
|
import java.lang.reflect.Modifier;
|
2021-10-27 22:00:08 +02:00
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
|
|
|
//TODO allow instance sync through metadata
|
2021-10-29 22:50:42 +02:00
|
|
|
public class Inceptum {
|
2021-11-02 13:43:18 +01:00
|
|
|
public static final Path CACHE_DIR = MetaHolder.BASE_PATH.resolve("cache");
|
|
|
|
public static final Path INSTANCE_DIR = MetaHolder.BASE_PATH.resolve("instances");
|
|
|
|
public static final Path ASSETS_DIR = MetaHolder.BASE_PATH.resolve("assets");
|
|
|
|
public static final Path LIBRARIES_DIR = MetaHolder.BASE_PATH.resolve("libraries");
|
|
|
|
public static final Path NATIVES_DIR = MetaHolder.BASE_PATH.resolve("natives");
|
|
|
|
private static final Path CONFIG_PATH = MetaHolder.BASE_PATH.resolve("glaunch2.json");
|
|
|
|
public static final Path ACCOUNTS_PATH = MetaHolder.BASE_PATH.resolve("accounts.json");
|
2021-11-11 20:11:20 +01:00
|
|
|
public static final Path FORCE_LOAD_PATH = NATIVES_DIR.resolve("forceload");
|
2021-10-30 19:26:59 +02:00
|
|
|
public static final Logger LOGGER = LoggerFactory.getLogger("Inceptum");
|
2021-10-27 22:00:08 +02:00
|
|
|
public static final Gson GSON = new GsonBuilder()
|
|
|
|
.registerTypeAdapter(MinecraftArgument.class, new MinecraftArgumentDeserializer())
|
2021-10-27 22:07:07 +02:00
|
|
|
.registerTypeAdapter(Rules.class, new RulesDeserializer())
|
2021-10-29 22:50:42 +02:00
|
|
|
.registerTypeAdapter(OauthTokenResponse.class, new OauthTokenResponseDeserializer())
|
2021-10-31 16:59:25 +01:00
|
|
|
.registerTypeAdapter(ComparableVersion.class, new ComparableVersionAdapter())
|
2021-11-02 16:44:26 +01:00
|
|
|
.registerTypeAdapter(ModSource.class, new ModSourceTypeAdapter())
|
2021-11-04 14:07:34 +01:00
|
|
|
.registerTypeAdapter(ModSourceMapDeserializer.modSourceMapType, new ModSourceMapDeserializer())
|
2021-10-28 23:27:47 +02:00
|
|
|
.excludeFieldsWithModifiers(Modifier.TRANSIENT)
|
|
|
|
.excludeFieldsWithModifiers(Modifier.PRIVATE)
|
|
|
|
.addSerializationExclusionStrategy(new GsonIgnoreExclusionStrategy())
|
|
|
|
.setPrettyPrinting()
|
2021-10-27 22:00:08 +02:00
|
|
|
.create();
|
2021-11-02 13:43:18 +01:00
|
|
|
|
2021-10-27 22:07:07 +02:00
|
|
|
public static Config CONFIG;
|
2021-11-02 13:43:18 +01:00
|
|
|
public static boolean IS_GUI;
|
2021-10-27 22:00:08 +02:00
|
|
|
|
2021-11-24 16:02:33 +01:00
|
|
|
public static void main(String[] _args) throws Exception {
|
|
|
|
InvokedCommandDescription arg = new InvokedCommandDescription(_args);
|
|
|
|
if (arg.command.enableLog()) {
|
2021-11-02 13:43:18 +01:00
|
|
|
LOGGER.info("Launching Inceptum v" + MetaHolder.VERSION.version + " (" + MetaHolder.VERSION.flavor + ")");
|
|
|
|
LOGGER.info("Loading from " + MetaHolder.BASE_PATH);
|
2021-10-30 22:05:24 +02:00
|
|
|
}
|
|
|
|
if (!Files.exists(CONFIG_PATH.getParent())) Files.createDirectories(CONFIG_PATH.getParent());
|
2021-10-27 22:07:07 +02:00
|
|
|
if (!Files.exists(CONFIG_PATH)) Utils.writeObject(CONFIG_PATH, new Config());
|
|
|
|
CONFIG = Utils.loadObject(CONFIG_PATH, Config.class);
|
2021-10-27 22:00:08 +02:00
|
|
|
if (!Files.exists(CACHE_DIR)) Files.createDirectories(CACHE_DIR);
|
2021-11-02 13:43:18 +01:00
|
|
|
try {
|
|
|
|
McApi.getVersions();
|
|
|
|
Utils.clearDirectory(CACHE_DIR);
|
|
|
|
}
|
|
|
|
catch (IOException e) {
|
|
|
|
Inceptum.LOGGER.error("Could not connect to the internet");
|
|
|
|
}
|
2021-10-27 22:00:08 +02:00
|
|
|
if (!Files.exists(INSTANCE_DIR)) Files.createDirectories(INSTANCE_DIR);
|
|
|
|
if (!Files.exists(ASSETS_DIR)) Files.createDirectories(ASSETS_DIR);
|
|
|
|
if (!Files.exists(LIBRARIES_DIR)) Files.createDirectories(LIBRARIES_DIR);
|
2021-11-11 20:11:20 +01:00
|
|
|
if (Files.exists(FORCE_LOAD_PATH)) {
|
2021-11-11 17:59:35 +01:00
|
|
|
Inceptum.LOGGER.info("Force-Loading libraries:");
|
2021-11-11 20:11:20 +01:00
|
|
|
Utils.ls(FORCE_LOAD_PATH, path -> {
|
2021-11-11 17:59:35 +01:00
|
|
|
Inceptum.LOGGER.info("Loading " + path);
|
2021-11-11 20:42:22 +01:00
|
|
|
System.load(path.toAbsolutePath().toString());
|
2021-11-11 17:59:35 +01:00
|
|
|
});
|
|
|
|
}
|
2021-10-30 22:05:24 +02:00
|
|
|
|
2021-11-24 16:02:33 +01:00
|
|
|
arg.command.invoke(arg);
|
2021-10-28 21:31:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void saveConfig() {
|
|
|
|
try {
|
|
|
|
Utils.writeObject(CONFIG_PATH, CONFIG);
|
|
|
|
} catch (IOException e) {
|
|
|
|
LOGGER.error("Could not save config", e);
|
|
|
|
}
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|
|
|
|
|
2021-10-30 22:05:24 +02:00
|
|
|
public static void showError(String message, String title) {
|
|
|
|
LOGGER.error(message);
|
|
|
|
if (IS_GUI) InceptumGui.WINDOWS.add(new AlertWindow(title, message));
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|
|
|
|
|
2021-10-30 22:05:24 +02:00
|
|
|
public static void showError(String message, Throwable t) {
|
|
|
|
LOGGER.error(message, t);
|
|
|
|
if (IS_GUI) InceptumGui.WINDOWS.add(new AlertWindow(message, t.toString()));
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|
|
|
|
|
2021-10-30 22:05:24 +02:00
|
|
|
public static void showInfo(String message, String title) {
|
|
|
|
LOGGER.info(message);
|
|
|
|
if (IS_GUI) InceptumGui.WINDOWS.add(new AlertWindow(title, message));
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|
|
|
|
|
2021-10-30 22:05:24 +02:00
|
|
|
public static void showOkCancel(String message, String title, Runnable ok, Runnable cancel) {
|
2021-10-31 16:59:25 +01:00
|
|
|
showOkCancel(message, title, ok, cancel, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void showOkCancel(String message, String title, Runnable ok, Runnable cancel, boolean defaultCancel) {
|
2021-10-30 22:05:24 +02:00
|
|
|
LOGGER.info(message);
|
|
|
|
if (IS_GUI) InceptumGui.WINDOWS.add(new AlertWindow(title, message, ok, cancel));
|
2021-10-31 16:59:25 +01:00
|
|
|
else if (!defaultCancel) ok.run();
|
2021-10-28 21:31:51 +02:00
|
|
|
}
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|