Inceptum/launcher/src/main/java/io/gitlab/jfronny/inceptum/Inceptum.java
JFronny 35ffea6feb
Get rid of JGit, please use a normal git install.
.gitignore is now parsed manually during export
2022-08-02 16:55:16 +02:00

107 lines
4.7 KiB
Java

package io.gitlab.jfronny.inceptum;
import io.gitlab.jfronny.commons.serialize.gson.api.GsonHolder;
import io.gitlab.jfronny.inceptum.frontend.cli.CommandResolution;
import io.gitlab.jfronny.inceptum.frontend.cli.Commands;
import io.gitlab.jfronny.inceptum.frontend.gui.window.dialog.AlertWindow;
import io.gitlab.jfronny.inceptum.frontend.gui.window.dialog.TextBoxWindow;
import io.gitlab.jfronny.inceptum.gson.*;
import io.gitlab.jfronny.inceptum.util.*;
import io.gitlab.jfronny.inceptum.util.source.ModSource;
import io.gitlab.jfronny.inceptum.model.microsoft.OauthTokenResponse;
import io.gitlab.jfronny.inceptum.model.mojang.MinecraftArgument;
import io.gitlab.jfronny.inceptum.model.mojang.Rules;
import io.gitlab.jfronny.inceptum.util.mds.ModsDirScanner;
import io.gitlab.jfronny.inceptum.util.api.McApi;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Scanner;
import java.util.function.Consumer;
public class Inceptum {
public static boolean IS_GUI;
public static void main(String[] args) throws Exception {
if (Utils.class.getClassLoader() != Inceptum.class.getClassLoader()) {
throw new IllegalStateException("Mismatching classloader between two classes. Something is wrong here");
}
CommandResolution command = Commands.resolve(args, false);
if (command.command().enableLog()) {
Utils.LOGGER.info("Launching Inceptum v" + MetaHolder.VERSION.version + " (" + MetaHolder.VERSION.flavor + ")");
Utils.LOGGER.info("Loading from " + MetaHolder.BASE_PATH);
}
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());
InceptumEnvironmentInitializer.initialize();
if (!Files.exists(MetaHolder.CACHE_DIR)) Files.createDirectories(MetaHolder.CACHE_DIR);
try {
McApi.getVersions();
Utils.clearDirectory(MetaHolder.CACHE_DIR);
}
catch (IOException e) {
Utils.LOGGER.error("Could not connect to the internet");
}
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);
try {
System.load(path.toAbsolutePath().toString());
}
catch (UnsatisfiedLinkError le) {
Utils.LOGGER.error("Could not load library", le);
}
});
}
command.invoke();
ModsDirScanner.closeAll();
}
public static void showError(String message, String title) {
Utils.LOGGER.error(message);
if (IS_GUI) InceptumGui.WINDOWS.add(new AlertWindow(title, message));
}
public static void showError(String message, Throwable t) {
Utils.LOGGER.error(message, t);
if (IS_GUI) InceptumGui.WINDOWS.add(new AlertWindow(message, t.toString()));
}
public static void showInfo(String message, String title) {
Utils.LOGGER.info(message);
if (IS_GUI) InceptumGui.WINDOWS.add(new AlertWindow(title, message));
}
public static void showOkCancel(String message, String title, Runnable ok, Runnable cancel) {
showOkCancel(message, title, ok, cancel, false);
}
public static void showOkCancel(String message, String title, Runnable ok, Runnable cancel, boolean defaultCancel) {
Utils.LOGGER.info(message);
if (IS_GUI) InceptumGui.WINDOWS.add(new AlertWindow(title, message, ok, cancel));
else if (!defaultCancel) ok.run();
}
public static void getInput(String prompt, String details, String defaultValue, Consumer<String> ok, Runnable cancel) throws IOException {
if (IS_GUI) InceptumGui.WINDOWS.add(new TextBoxWindow(prompt, details, defaultValue, ok, cancel));
else {
Scanner scanner = new Scanner(System.in);
System.out.println(prompt);
System.out.print("> ");
ok.accept(scanner.nextLine());
}
}
}