Delegate Gson/etc initialization to InceptumEnvironmentInitializer, set custom user agent for HttpUtils

This commit is contained in:
Johannes Frohnmeyer 2022-07-04 13:22:28 +02:00
parent fdc1394493
commit 663e143c4b
Signed by: Johannes
GPG Key ID: E76429612C2929F4
4 changed files with 26 additions and 15 deletions

View File

@ -41,7 +41,7 @@ ext {
lwjglVersion = '3.3.1'
imguiVersion = '1.86.4'
logbackVersion = '1.3.0-alpha15'
jfCommonsVersion = '2022.6.27+12-28-9'
jfCommonsVersion = '2022.7.4+11-13-3'
jgitVersion = '6.1.0.202203080745-r'
flavorProp = project.hasProperty('flavor') ? project.getProperty('flavor') : 'custom'
flavor = flavorProp

View File

@ -6,14 +6,12 @@ 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.ConfigHolder;
import io.gitlab.jfronny.inceptum.util.MetaHolder;
import io.gitlab.jfronny.inceptum.util.mds.ModsDirScanner;
import io.gitlab.jfronny.inceptum.util.Utils;
import io.gitlab.jfronny.inceptum.util.api.McApi;
import java.io.IOException;
@ -29,19 +27,20 @@ public class Inceptum {
throw new IllegalStateException("Mismatching classloader between two classes. Something is wrong here");
}
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());
GsonHolder.register();
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);
}
ConfigHolder.load();
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();

View File

@ -1,7 +1,6 @@
package io.gitlab.jfronny.inceptum;
import io.gitlab.jfronny.commons.*;
import io.gitlab.jfronny.commons.serialize.gson.api.*;
import io.gitlab.jfronny.inceptum.model.inceptum.*;
import io.gitlab.jfronny.inceptum.util.*;
@ -17,8 +16,7 @@ public class Wrapper {
public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, URISyntaxException, NoSuchFieldException {
System.out.println("Inceptum Wrapper v" + MetaHolder.VERSION.version + " (" + MetaHolder.VERSION.flavor + ")");
GsonHolder.register();
ConfigHolder.load();
InceptumEnvironmentInitializer.initialize();
if (!Files.exists(INCEPTUM_LIB_DIR)) downloadLatest();
Optional<Path> localBinary = selectLocalBinary();
if (localBinary.isEmpty()) {

View File

@ -0,0 +1,14 @@
package io.gitlab.jfronny.inceptum.util;
import io.gitlab.jfronny.commons.HttpUtils;
import io.gitlab.jfronny.commons.serialize.gson.api.GsonHolder;
import java.io.IOException;
public class InceptumEnvironmentInitializer {
public static void initialize() throws IOException {
HttpUtils.setUserAgent("jfmods/inceptum/" + MetaHolder.VERSION.version.toString());
GsonHolder.register();
ConfigHolder.load();
}
}