2021-10-29 22:50:42 +02:00
|
|
|
package io.gitlab.jfronny.inceptum;
|
2021-10-27 22:00:08 +02:00
|
|
|
|
2022-04-28 23:13:37 +02:00
|
|
|
import io.gitlab.jfronny.commons.serialize.gson.GsonHolder;
|
2022-01-18 18:43:39 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.frontend.cli.CommandResolution;
|
|
|
|
import io.gitlab.jfronny.inceptum.frontend.cli.Commands;
|
2022-01-23 18:53:16 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.frontend.gui.window.dialog.AlertWindow;
|
|
|
|
import io.gitlab.jfronny.inceptum.frontend.gui.window.dialog.TextBoxWindow;
|
2021-10-31 16:59:25 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.gson.*;
|
2022-01-19 19:14:13 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.util.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;
|
2022-01-18 18:43:39 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.util.ConfigHolder;
|
2021-11-02 13:43:18 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.util.MetaHolder;
|
2022-01-23 17:10:19 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.util.mds.ModsDirScanner;
|
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-27 22:00:08 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
2021-11-24 19:53:06 +01:00
|
|
|
import java.util.Scanner;
|
|
|
|
import java.util.function.Consumer;
|
2021-10-27 22:00:08 +02:00
|
|
|
|
2021-10-29 22:50:42 +02:00
|
|
|
public class Inceptum {
|
2021-11-02 13:43:18 +01:00
|
|
|
public static boolean IS_GUI;
|
2021-10-27 22:00:08 +02:00
|
|
|
|
2022-01-04 17:48:01 +01:00
|
|
|
public static void main(String[] args) throws Exception {
|
2022-01-19 19:14:13 +01:00
|
|
|
if (Wrapper.class.getClassLoader() != Inceptum.class.getClassLoader()) {
|
|
|
|
throw new IllegalStateException("Mismatching classloader between two classes. Something is wrong here");
|
|
|
|
}
|
|
|
|
|
2022-01-18 18:43:39 +01:00
|
|
|
GsonHolder.registerTypeAdapter(MinecraftArgument.class, new MinecraftArgumentDeserializer());
|
|
|
|
GsonHolder.registerTypeAdapter(Rules.class, new RulesDeserializer());
|
|
|
|
GsonHolder.registerTypeAdapter(OauthTokenResponse.class, new OauthTokenResponseDeserializer());
|
|
|
|
GsonHolder.registerTypeAdapter(ModSource.class, new ModSourceTypeAdapter());
|
|
|
|
GsonHolder.registerTypeAdapter(ModSourceMapDeserializer.modSourceMapType, new ModSourceMapDeserializer());
|
2022-04-28 23:13:37 +02:00
|
|
|
GsonHolder.register();
|
2022-01-18 18:43:39 +01:00
|
|
|
|
2022-01-04 17:48:01 +01:00
|
|
|
CommandResolution command = Commands.resolve(args, false);
|
|
|
|
if (command.command().enableLog()) {
|
2022-01-18 18:43:39 +01:00
|
|
|
Utils.LOGGER.info("Launching Inceptum v" + MetaHolder.VERSION.version + " (" + MetaHolder.VERSION.flavor + ")");
|
|
|
|
Utils.LOGGER.info("Loading from " + MetaHolder.BASE_PATH);
|
2021-10-30 22:05:24 +02:00
|
|
|
}
|
2022-01-18 18:43:39 +01:00
|
|
|
ConfigHolder.load();
|
|
|
|
if (!Files.exists(MetaHolder.CACHE_DIR)) Files.createDirectories(MetaHolder.CACHE_DIR);
|
2021-11-02 13:43:18 +01:00
|
|
|
try {
|
|
|
|
McApi.getVersions();
|
2022-01-18 18:43:39 +01:00
|
|
|
Utils.clearDirectory(MetaHolder.CACHE_DIR);
|
2021-11-02 13:43:18 +01:00
|
|
|
}
|
|
|
|
catch (IOException e) {
|
2022-01-18 18:43:39 +01:00
|
|
|
Utils.LOGGER.error("Could not connect to the internet");
|
2021-11-02 13:43:18 +01:00
|
|
|
}
|
2022-01-18 18:43:39 +01:00
|
|
|
if (!Files.exists(MetaHolder.INSTANCE_DIR)) Files.createDirectories(MetaHolder.INSTANCE_DIR);
|
|
|
|
if (!Files.exists(MetaHolder.ASSETS_DIR)) Files.createDirectories(MetaHolder.ASSETS_DIR);
|
|
|
|
if (!Files.exists(MetaHolder.LIBRARIES_DIR)) Files.createDirectories(MetaHolder.LIBRARIES_DIR);
|
|
|
|
if (Files.exists(MetaHolder.FORCE_LOAD_PATH)) {
|
|
|
|
Utils.LOGGER.info("Force-Loading libraries:");
|
|
|
|
Utils.ls(MetaHolder.FORCE_LOAD_PATH, path -> {
|
|
|
|
Utils.LOGGER.info("Loading " + path);
|
2021-12-08 21:50:32 +01:00
|
|
|
try {
|
|
|
|
System.load(path.toAbsolutePath().toString());
|
|
|
|
}
|
|
|
|
catch (UnsatisfiedLinkError le) {
|
2022-01-18 18:43:39 +01:00
|
|
|
Utils.LOGGER.error("Could not load library", le);
|
2021-12-08 21:50:32 +01:00
|
|
|
}
|
2021-11-11 17:59:35 +01:00
|
|
|
});
|
|
|
|
}
|
2021-10-30 22:05:24 +02:00
|
|
|
|
2022-01-04 17:48:01 +01:00
|
|
|
command.invoke();
|
2022-01-04 23:32:05 +01:00
|
|
|
ModsDirScanner.closeAll();
|
2021-10-28 21:31:51 +02:00
|
|
|
}
|
|
|
|
|
2021-10-30 22:05:24 +02:00
|
|
|
public static void showError(String message, String title) {
|
2022-01-18 18:43:39 +01:00
|
|
|
Utils.LOGGER.error(message);
|
2021-10-30 22:05:24 +02:00
|
|
|
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) {
|
2022-01-18 18:43:39 +01:00
|
|
|
Utils.LOGGER.error(message, t);
|
2021-10-30 22:05:24 +02:00
|
|
|
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) {
|
2022-01-18 18:43:39 +01:00
|
|
|
Utils.LOGGER.info(message);
|
2021-10-30 22:05:24 +02:00
|
|
|
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) {
|
2022-01-18 18:43:39 +01:00
|
|
|
Utils.LOGGER.info(message);
|
2021-10-30 22:05:24 +02:00
|
|
|
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-11-24 19:53:06 +01:00
|
|
|
|
|
|
|
public static void getInput(String prompt, String defaultValue, Consumer<String> ok, Runnable cancel) throws IOException {
|
|
|
|
if (IS_GUI) InceptumGui.WINDOWS.add(new TextBoxWindow(prompt, prompt, defaultValue, ok, cancel));
|
|
|
|
else {
|
|
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
System.out.println(prompt);
|
|
|
|
System.out.print("> ");
|
|
|
|
ok.accept(scanner.nextLine());
|
|
|
|
}
|
|
|
|
}
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|