chore: update to jfCommons 1.7
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Johannes Frohnmeyer 2024-06-03 14:40:44 +02:00
parent aae97feeca
commit 787833f732
Signed by: Johannes
GPG Key ID: E76429612C2929F4
89 changed files with 498 additions and 385 deletions

View File

@ -9,16 +9,6 @@ allprojects {
group = "io.gitlab.jfronny.inceptum"
}
// common
val jfCommonsVersion by extra(libs.versions.jf.commons.get())
val gsonCompileVersion by extra(libs.versions.gson.compile.get())
val jbAnnotationsVersion by extra(libs.versions.annotations.get())
// launcher-imgui
val lwjglVersion by extra(libs.versions.lwjgl.get())
val imguiVersion by extra(libs.versions.imgui.get())
// launcher-gtk
val javagiVersion by extra(libs.versions.javagi.get())
val flavorProp: String by extra(prop("flavor", "custom"))
if (!setOf("custom", "maven", "fat", "windows", "linux", "macos").contains(flavorProp)) throw IllegalStateException("Unsupported flavor: $flavorProp")
val flavor: String by extra(if (flavorProp != "custom") flavorProp else OS.TYPE.codename)
@ -28,6 +18,8 @@ val isRelease by extra(project.hasProperty("release"))
val buildTime by extra(System.currentTimeMillis())
val wrapperVersion by extra(1)
val lwjglVersion = libs.versions.lwjgl.get()
val imguiVersion = libs.versions.imgui.get()
tasks.register("exportMetadata") {
doLast {
projectDir.resolve("version.json").writeText(

View File

@ -4,11 +4,10 @@ plugins {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
dependencies {
api(libs.findLibrary("gson-compile-core").orElseThrow())
compileOnly(libs.findLibrary("gson-compile-annotations").orElseThrow())
annotationProcessor(libs.findLibrary("gson-compile-processor").orElseThrow())
compileOnly(libs.findLibrary("commons-serialize-generator-annotations").orElseThrow())
annotationProcessor(libs.findLibrary("commons-serialize-generator").orElseThrow())
}
tasks.withType<JavaCompile> {
options.compilerArgs.add("-AgsonCompileNoReflect")
options.compilerArgs.addAll(listOf("-AserializeProcessorNoReflect"))
}

View File

@ -0,0 +1,33 @@
package io.gitlab.jfronny.inceptum.common;
import io.gitlab.jfronny.commons.serialize.SerializeReader;
import io.gitlab.jfronny.commons.serialize.Token;
import io.gitlab.jfronny.commons.serialize.json.JsonWriter;
import io.gitlab.jfronny.commons.throwable.ThrowingBiConsumer;
import io.gitlab.jfronny.commons.throwable.ThrowingFunction;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
public class GList {
public static <T, TEx extends Exception, Reader extends SerializeReader<TEx, Reader>> List<T> read(Reader reader, ThrowingFunction<Reader, T, TEx> read) throws TEx {
if (reader.isLenient() && reader.peek() != Token.BEGIN_ARRAY) return List.of(read.apply(reader));
reader.beginArray();
List<T> res = new LinkedList<>();
while (reader.hasNext()) {
if (reader.peek() == Token.NULL) {
reader.nextNull();
res.add(null);
} else res.add(read.apply(reader));
}
reader.endArray();
return res;
}
public static <T> void write(JsonWriter writer, List<T> list, ThrowingBiConsumer<T, JsonWriter, IOException> write) throws IOException {
writer.beginArray();
for (T t : list) write.accept(t, writer);
writer.endArray();
}
}

View File

@ -1,34 +1,76 @@
package io.gitlab.jfronny.inceptum.common;
import io.gitlab.jfronny.gson.stream.JsonReader;
import io.gitlab.jfronny.gson.stream.JsonWriter;
import io.gitlab.jfronny.commons.serialize.SerializeReader;
import io.gitlab.jfronny.commons.serialize.SerializeWriter;
import io.gitlab.jfronny.commons.serialize.json.JsonReader;
import io.gitlab.jfronny.commons.serialize.json.JsonTransport;
import io.gitlab.jfronny.commons.serialize.json.JsonWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
public class GsonPreset {
public static class Config {
public static void configure(JsonReader reader) {
public static Config CONFIG = new Config();
public static Api API = new Api();
public static class Config extends JsonTransport {
public static <TEx extends Exception, Reader extends SerializeReader<TEx, Reader>> void configure(Reader reader) {
reader.setSerializeSpecialFloatingPointValues(true);
reader.setLenient(true);
}
public static void configure(JsonWriter writer) {
public static <TEx extends Exception, Writer extends SerializeWriter<TEx, Writer>> void configure(Writer writer) {
writer.setSerializeNulls(true);
writer.setSerializeSpecialFloatingPointValues(true);
writer.setLenient(true);
writer.setIndent(" ");
writer.setOmitQuotes(true);
if (writer instanceof JsonWriter jw) {
jw.setIndent(" ");
jw.setOmitQuotes(true);
jw.setNewline("\n");
jw.setCommentUnexpectedNames(true);
}
}
@Override
public JsonWriter createWriter(Writer target) throws IOException {
JsonWriter jw = super.createWriter(target);
configure(jw);
return jw;
}
@Override
public JsonReader createReader(Reader source) {
JsonReader jr = super.createReader(source);
configure(jr);
return jr;
}
}
public static class Api {
public static void configure(JsonReader reader) {
public static class Api extends JsonTransport {
public static <TEx extends Exception, Reader extends SerializeReader<TEx, Reader>> void configure(Reader reader) {
reader.setSerializeSpecialFloatingPointValues(true);
reader.setLenient(true);
}
public static void configure(JsonWriter writer) {
public static <TEx extends Exception, Writer extends SerializeWriter<TEx, Writer>> void configure(Writer writer) {
writer.setSerializeNulls(false);
writer.setSerializeSpecialFloatingPointValues(true);
writer.setLenient(false);
}
@Override
public JsonWriter createWriter(Writer target) throws IOException {
JsonWriter jw = super.createWriter(target);
configure(jw);
return jw;
}
@Override
public JsonReader createReader(Reader source) {
JsonReader jr = super.createReader(source);
configure(jr);
return jr;
}
}
}

View File

@ -1,14 +1,14 @@
package io.gitlab.jfronny.inceptum.common;
import io.gitlab.jfronny.gson.compile.annotations.GComment;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GComment;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.model.inceptum.UpdateChannel;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@GSerializable(configure = GsonPreset.Config.class, isStatic = true)
@GSerializable(isStatic = true)
public class InceptumConfig {
@GComment("Whether to show snapshots in the version selector for new instances")
public static boolean snapshots = false;
@ -41,12 +41,12 @@ public class InceptumConfig {
saveConfig();
}
}
GC_InceptumConfig.read(MetaHolder.CONFIG_PATH);
GC_InceptumConfig.deserialize(MetaHolder.CONFIG_PATH, GsonPreset.CONFIG);
}
public static void saveConfig() {
try {
GC_InceptumConfig.write(MetaHolder.CONFIG_PATH);
GC_InceptumConfig.serialize(MetaHolder.CONFIG_PATH, GsonPreset.CONFIG);
} catch (IOException e) {
Utils.LOGGER.error("Could not save config", e);
}

View File

@ -1,19 +1,20 @@
package io.gitlab.jfronny.inceptum.common;
import io.gitlab.jfronny.commons.http.client.HttpClient;
import io.gitlab.jfronny.commons.logging.Logger;
import io.gitlab.jfronny.commons.logging.StdoutLogger;
import io.gitlab.jfronny.commons.logger.HotswapLoggerFinder;
import io.gitlab.jfronny.commons.logger.StdoutLogger;
import io.gitlab.jfronny.commons.logger.SystemLoggerPlus;
import java.io.IOException;
public class InceptumEnvironmentInitializer {
public static void initialize() throws IOException {
Logger.registerFactory(InceptumEnvironmentInitializer::defaultFactory);
HotswapLoggerFinder.updateAllStrategies(InceptumEnvironmentInitializer::defaultFactory);
HttpClient.setUserAgent("jfmods/inceptum/" + BuildMetadata.VERSION);
InceptumConfig.load();
}
public static Logger defaultFactory(String name) {
return StdoutLogger.fancy(name);
public static SystemLoggerPlus defaultFactory(String name, Module module, System.Logger.Level level) {
return StdoutLogger.fancy(name, module, level);
}
}

View File

@ -2,6 +2,9 @@ package io.gitlab.jfronny.inceptum.common;
import io.gitlab.jfronny.commons.http.client.HttpClient;
import io.gitlab.jfronny.commons.io.HashUtils;
import io.gitlab.jfronny.commons.serialize.json.JsonReader;
import io.gitlab.jfronny.commons.serialize.json.JsonTransport;
import io.gitlab.jfronny.commons.throwable.ThrowingBiFunction;
import io.gitlab.jfronny.commons.throwable.ThrowingFunction;
import io.gitlab.jfronny.commons.throwable.ThrowingSupplier;
@ -34,22 +37,42 @@ public class Net {
return downloadObject(url, func, true);
}
public static <T> T downloadJObject(String url, ThrowingFunction<JsonReader, T, IOException> func) throws IOException {
return downloadJObject(url, func, true);
}
public static <T> T downloadObject(String url, ThrowingFunction<String, T, IOException> func, boolean cache) throws IOException {
return downloadObject(url, () -> HttpClient.get(url).sendString(), func, cache);
}
public static <T> T downloadJObject(String url, ThrowingFunction<JsonReader, T, IOException> func, boolean cache) throws IOException {
return downloadJObject(url, () -> HttpClient.get(url).sendString(), func, cache);
}
public static <T> T downloadObject(String url, ThrowingFunction<String, T, IOException> func, String apiKey) throws IOException {
return downloadObject(url, () -> downloadStringAuthenticated(url, apiKey), func, true);
}
public static <T> T downloadJObject(String url, ThrowingFunction<JsonReader, T, IOException> func, String apiKey) throws IOException {
return downloadJObject(url, () -> downloadStringAuthenticated(url, apiKey), func, true);
}
public static <T> T downloadObject(String url, String sha1, ThrowingFunction<String, T, IOException> func) throws IOException {
return downloadObject(url, sha1, func, true);
}
public static <T> T downloadJObject(String url, String sha1, ThrowingFunction<JsonReader, T, IOException> func) throws IOException {
return downloadJObject(url, sha1, func, true);
}
public static <T> T downloadObject(String url, String sha1, ThrowingFunction<String, T, IOException> func, boolean cache) throws IOException {
return downloadObject(url, () -> downloadString(url, sha1), func, cache);
}
public static <T> T downloadJObject(String url, String sha1, ThrowingFunction<JsonReader, T, IOException> func, boolean cache) throws IOException {
return downloadJObject(url, () -> downloadString(url, sha1), func, cache);
}
private static <T> T downloadObject(String url, ThrowingSupplier<String, Exception> sourceString, ThrowingFunction<String, T, IOException> func, boolean cache) throws IOException {
try {
ThrowingSupplier<T, Exception> builder = () -> func.apply(sourceString.get());
@ -59,6 +82,10 @@ public class Net {
}
}
public static <T> T downloadJObject(String url, ThrowingSupplier<String, Exception> sourceString, ThrowingFunction<JsonReader, T, IOException> func, boolean cache) throws IOException {
return downloadObject(url, sourceString, s -> func.apply(GsonPreset.API.createReader(s)), cache);
}
public static String buildUrl(String host, String url, Map<String, String> params) {
StringBuilder res = new StringBuilder(host);
if (res.toString().endsWith("/")) res = new StringBuilder(res.substring(0, res.length() - 1));

View File

@ -1,6 +1,7 @@
package io.gitlab.jfronny.inceptum.common;
import io.gitlab.jfronny.commons.OSUtils;
import io.gitlab.jfronny.commons.serialize.json.JsonTransport;
import io.gitlab.jfronny.inceptum.common.api.MavenApi;
import io.gitlab.jfronny.inceptum.common.model.inceptum.*;
import io.gitlab.jfronny.inceptum.common.model.maven.*;
@ -53,7 +54,7 @@ public class Updater {
config.natives().put(Utils.getCurrentFlavor(), natives);
}
GC_WrapperConfig.write(config, MetaHolder.WRAPPER_CONFIG_PATH);
GC_WrapperConfig.serialize(config, MetaHolder.WRAPPER_CONFIG_PATH, GsonPreset.CONFIG);
if (relaunch) {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
@ -94,7 +95,7 @@ public class Updater {
}
}
if (configChanged) GC_WrapperConfig.write(wrapperConfig, MetaHolder.WRAPPER_CONFIG_PATH);
if (configChanged) GC_WrapperConfig.serialize(wrapperConfig, MetaHolder.WRAPPER_CONFIG_PATH, GsonPreset.CONFIG);
return buildClasspath(Stream.concat(libs.stream(), natives.stream())).toList();
}
@ -141,10 +142,10 @@ public class Updater {
public static @Nullable UpdateMetadata check(UpdateChannel channel, boolean versionCompare, boolean checkEnv, Consumer<UpdateChannel> channelInvalid) throws UpdateCheckException {
try {
UpdateMetadata experimental = Net.downloadObject(ARTIFACTS_URL + "version.json", json -> GC_UpdateMetadata.read(json));
UpdateMetadata experimental = Net.downloadObject(ARTIFACTS_URL + "version.json", json -> GC_UpdateMetadata.deserialize(json, GsonPreset.API));
UpdateMetadata stable = null;
try {
stable = Net.downloadObject(STABLE_URL + "version.json", json -> GC_UpdateMetadata.read(json));
stable = Net.downloadObject(STABLE_URL + "version.json", json -> GC_UpdateMetadata.deserialize(json, GsonPreset.API));
} catch (Throwable ignored) {}
if (stable == null && channel == UpdateChannel.Stable) {
channel = UpdateChannel.CI;

View File

@ -2,7 +2,7 @@ package io.gitlab.jfronny.inceptum.common;
import io.gitlab.jfronny.commons.OSUtils;
import io.gitlab.jfronny.commons.io.JFiles;
import io.gitlab.jfronny.commons.logging.Logger;
import io.gitlab.jfronny.commons.logger.SystemLoggerPlus;
import java.awt.*;
import java.io.File;
@ -19,7 +19,7 @@ public class Utils {
public static final int CACHE_SIZE = 128;
public static final Pattern NEW_LINE = Pattern.compile("[\r\n]+");
public static final Pattern VALID_FILENAME = Pattern.compile("[a-zA-Z0-9_\\-.][a-zA-Z0-9 _\\-.]*[a-zA-Z0-9_\\-.]");
public static final Logger LOGGER = Logger.forName("Inceptum");
public static final SystemLoggerPlus LOGGER = SystemLoggerPlus.forName("Inceptum");
private static ClassLoader SYSTEM_LOADER = ClassLoader.getSystemClassLoader();
public static void openWebBrowser(URI uri) {

View File

@ -1,12 +1,12 @@
package io.gitlab.jfronny.inceptum.common.model.inceptum;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.Map;
import java.util.Set;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record UpdateMetadata(int wrapperVersion,
String version,
long buildTime,

View File

@ -1,11 +1,11 @@
package io.gitlab.jfronny.inceptum.common.model.inceptum;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.Map;
import java.util.Set;
@GSerializable(configure = GsonPreset.Config.class)
@GSerializable
public record WrapperConfig(Set<String> libraries, Set<String> repositories, Map<String, Set<String>> natives) {
}

View File

@ -7,12 +7,11 @@ module io.gitlab.jfronny.inceptum.common {
requires transitive java.desktop;
requires java.xml;
requires transitive io.gitlab.jfronny.commons;
requires transitive io.gitlab.jfronny.commons.gson;
requires transitive io.gitlab.jfronny.commons.http.client;
requires transitive io.gitlab.jfronny.commons.io;
requires transitive io.gitlab.jfronny.commons.logging;
requires transitive io.gitlab.jfronny.gson;
requires transitive io.gitlab.jfronny.gson.compile.core;
requires transitive io.gitlab.jfronny.commons.logger;
requires transitive io.gitlab.jfronny.commons.serialize.json;
requires static org.jetbrains.annotations;
requires static io.gitlab.jfronny.gson.compile.annotations;
requires static io.gitlab.jfronny.commons.serialize.generator.annotations;
requires io.gitlab.jfronny.commons.serialize;
}

View File

@ -1,6 +1,5 @@
[versions]
jf-commons = "1.5-SNAPSHOT"
gson-compile = "1.4-SNAPSHOT"
jf-commons = "1.7-SNAPSHOT"
annotations = "24.0.1"
lwjgl = "3.3.2"
imgui = "1.86.10"
@ -36,12 +35,10 @@ commons = { module = "io.gitlab.jfronny:commons", version.ref = "jf-commons" }
commons-http-client = { module = "io.gitlab.jfronny:commons-http-client", version.ref = "jf-commons" }
commons-http-server = { module = "io.gitlab.jfronny:commons-http-server", version.ref = "jf-commons" }
commons-io = { module = "io.gitlab.jfronny:commons-io", version.ref = "jf-commons" }
commons-logging = { module = "io.gitlab.jfronny:commons-logging", version.ref = "jf-commons" }
commons-serialize-gson = { module = "io.gitlab.jfronny:commons-serialize-gson", version.ref = "jf-commons" }
gson-compile-core = { module = "io.gitlab.jfronny.gson:gson-compile-core", version.ref = "gson-compile" }
gson-compile-annotations = { module = "io.gitlab.jfronny.gson:gson-compile-annotations", version.ref = "gson-compile" }
gson-compile-processor = { module = "io.gitlab.jfronny.gson:gson-compile-processor", version.ref = "gson-compile" }
commons-logger = { module = "io.gitlab.jfronny:commons-logger", version.ref = "jf-commons" }
commons-serialize-json = { module = "io.gitlab.jfronny:commons-serialize-json", version.ref = "jf-commons" }
commons-serialize-generator-annotations = { module = "io.gitlab.jfronny:commons-serialize-generator-annotations", version.ref = "jf-commons" }
commons-serialize-generator = { module = "io.gitlab.jfronny:commons-serialize-generator", version.ref = "jf-commons" }
annotations = { module = "org.jetbrains:annotations", version.ref = "annotations" }
@ -49,4 +46,4 @@ annotations = { module = "org.jetbrains:annotations", version.ref = "annotations
lwjgl = ["lwjgl-core", "lwjgl-glfw", "lwjgl-opengl", "lwjgl-tinyfd"]
lwjgl-natives = ["lwjgl-core-natives", "lwjgl-glfw-natives", "lwjgl-opengl-natives", "lwjgl-tinyfd-natives"]
javagi = ["javagi-glib", "javagi-gtk", "javagi-adw"]
commons = ["commons", "commons-http-client", "commons-io", "commons-logging", "commons-serialize-gson"]
commons = ["commons", "commons-http-client", "commons-io", "commons-logger", "commons-serialize-json"]

View File

@ -1,5 +1,6 @@
package io.gitlab.jfronny.inceptum.cli;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.common.MetaHolder;
import io.gitlab.jfronny.inceptum.common.Utils;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_InstanceMeta;
@ -36,7 +37,7 @@ public abstract class BaseInstanceCommand extends Command {
Instance instance;
Path normalPath = Path.of(args.get(0));
if (Files.exists(normalPath.resolve(Instance.CONFIG_NAME))) {
instance = new Instance(normalPath, GC_InstanceMeta.read(normalPath.resolve(Instance.CONFIG_NAME)));
instance = new Instance(normalPath, GC_InstanceMeta.deserialize(normalPath.resolve(Instance.CONFIG_NAME), GsonPreset.CONFIG));
} else {
Path instancePath = MetaHolder.INSTANCE_DIR.resolve(args.get(0)).normalize();
if (!instancePath.startsWith(MetaHolder.INSTANCE_DIR)) {

View File

@ -1,6 +1,6 @@
package io.gitlab.jfronny.inceptum.cli.commands;
import io.gitlab.jfronny.commons.logging.OutputColors;
import io.gitlab.jfronny.commons.logger.OutputColors;
import io.gitlab.jfronny.inceptum.cli.Command;
import io.gitlab.jfronny.inceptum.cli.CommandArgs;
import io.gitlab.jfronny.inceptum.launcher.system.importer.Importers;

View File

@ -24,7 +24,8 @@ tasks.shadowJar {
archiveBaseName.set("Inceptum")
exclude("about.html")
exclude("plugin.properties")
exclude("META-INF/**")
// exclude("META-INF/**")
mergeServiceFiles()
}
(components["java"] as AdhocComponentWithVariants).withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) {

View File

@ -16,8 +16,6 @@ samWithReceiver {
}
dependencies {
val javagiVersion: String by rootProject.extra
implementation(libs.bundles.javagi)
implementation(projects.launcher)
}

View File

@ -1,6 +1,6 @@
package io.gitlab.jfronny.inceptum.gtk.util
import io.gitlab.jfronny.commons.logging.Logger
import io.gitlab.jfronny.commons.logger.SystemLoggerPlus
import io.gitlab.jfronny.inceptum.common.Utils
object Log : Logger by Utils.LOGGER
object Log : SystemLoggerPlus by Utils.LOGGER

View File

@ -10,6 +10,6 @@ module io.gitlab.jfronny.inceptum.launcher.gtk {
// Should theoretically already be included transitively through inceptum.launcher and inceptum.common
requires io.gitlab.jfronny.commons;
requires io.gitlab.jfronny.commons.io;
requires io.gitlab.jfronny.commons.logging;
requires io.gitlab.jfronny.commons.logger;
requires java.desktop;
}

View File

@ -5,7 +5,9 @@ import imgui.ImGuiIO;
import imgui.flag.ImGuiConfigFlags;
import imgui.gl3.ImGuiImplGl3;
import imgui.glfw.ImGuiImplGlfw;
import io.gitlab.jfronny.commons.logging.*;
import io.gitlab.jfronny.commons.logger.CompoundLogger;
import io.gitlab.jfronny.commons.logger.HotswapLoggerFinder;
import io.gitlab.jfronny.commons.logger.MemoryLogger;
import io.gitlab.jfronny.inceptum.common.*;
import io.gitlab.jfronny.inceptum.common.model.inceptum.UpdateMetadata;
import io.gitlab.jfronny.inceptum.imgui.window.MainWindow;
@ -32,7 +34,7 @@ import java.nio.file.Paths;
import java.util.*;
public class GuiMain {
public static final MemoryLogger MEMLOG = new MemoryLogger("Inceptum");
public static final MemoryLogger MEMLOG = new MemoryLogger("Inceptum", System.Logger.Level.INFO);
public static final Set<Window> WINDOWS = new LinkedHashSet<>();
private static final ImGuiImplGlfw imGuiGlfw = new ImGuiImplGlfw();
private static final ImGuiImplGl3 imGuiGl3 = new ImGuiImplGl3();
@ -54,7 +56,7 @@ public class GuiMain {
}
public static void showGui() {
Logger.registerFactory(name -> new CompoundLogger(name, InceptumEnvironmentInitializer.defaultFactory(name), MEMLOG));
HotswapLoggerFinder.updateAllStrategies((name, module, level) -> new CompoundLogger(name, new System.Logger[] { InceptumEnvironmentInitializer.defaultFactory(name, module, level), MEMLOG }));
UpdateMetadata update = null;
Updater.UpdateCheckException updateCheckFail = null;
try {

View File

@ -1,6 +1,7 @@
package io.gitlab.jfronny.inceptum.launcher.api;
import io.gitlab.jfronny.commons.http.client.HttpClient;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.common.Net;
import io.gitlab.jfronny.inceptum.launcher.model.curseforge.CurseforgeFile;
import io.gitlab.jfronny.inceptum.launcher.model.curseforge.CurseforgeMod;
@ -27,7 +28,7 @@ public class CurseforgeApi {
private static final int pageSize = 20;
public static List<CurseforgeMod> search(String gameVersion, String query, int page, String sort) throws IOException {
return Net.downloadObject(Net.buildUrl(API_URL, "mods/search", Map.of(
return Net.downloadJObject(Net.buildUrl(API_URL, "mods/search", Map.of(
"gameId", "432", // minecraft
"modLoaderType", "4", // fabric
"classId", "6", // mods
@ -38,27 +39,27 @@ public class CurseforgeApi {
"gameVersion", gameVersion,
"pageSize", Integer.toString(pageSize),
"index", Integer.toString(page * pageSize)
)), GC_SearchResponse::read, API_KEY).data();
)), GC_SearchResponse::deserialize, API_KEY).data();
}
public static CurseforgeMod getMod(String slug) throws IOException {
SearchResponse response = Net.downloadObject(Net.buildUrl(API_URL, "mods/search", Map.of(
SearchResponse response = Net.downloadJObject(Net.buildUrl(API_URL, "mods/search", Map.of(
"gameId", "432",
"classId", "6",
"slug", slug
)), GC_SearchResponse::read, API_KEY);
)), GC_SearchResponse::deserialize, API_KEY);
if (response.pagination().totalCount() != 1) {
throw new FileNotFoundException("Could not find mod with slug \"" + slug + "\"");
}
return checkDistribution(response.data().get(0));
return checkDistribution(response.data().getFirst());
}
public static CurseforgeMod getMod(int id) throws IOException {
return checkDistribution(Net.downloadObject(API_URL + "mods/" + id, GC_GetModResponse::read, API_KEY).data());
return checkDistribution(Net.downloadJObject(API_URL + "mods/" + id, GC_GetModResponse::deserialize, API_KEY).data());
}
public static String getDescription(int id) throws IOException {
return Net.downloadObject(API_URL + "mods/" + id + "/description", GC_GetModDescriptionResponse::read, API_KEY).data();
return Net.downloadJObject(API_URL + "mods/" + id + "/description", GC_GetModDescriptionResponse::deserialize, API_KEY).data();
}
private static CurseforgeMod checkDistribution(CurseforgeMod mod) {
@ -70,12 +71,12 @@ public class CurseforgeApi {
}
public static CurseforgeFile getFile(int modId, int fileId) throws IOException {
return Net.downloadObject(API_URL + "mods/" + modId + "/files/" + fileId, GC_GetModFileResponse::read, API_KEY).data();
return Net.downloadJObject(API_URL + "mods/" + modId + "/files/" + fileId, GC_GetModFileResponse::deserialize, API_KEY).data();
}
public static FingerprintMatchesResponse.Result checkFingerprint(long hash) throws IOException, URISyntaxException {
try (Reader r = HttpClient.post(API_URL + "fingerprints").bodyJson("{\"fingerprints\":[" + hash + "]}").sendReader()) {
return GC_FingerprintMatchesResponse.read(r).data();
return GC_FingerprintMatchesResponse.deserialize(r, GsonPreset.API).data();
}
}

View File

@ -1,8 +1,8 @@
package io.gitlab.jfronny.inceptum.launcher.api;
import io.gitlab.jfronny.commons.io.cache.MemoryOperationResultCache;
import io.gitlab.jfronny.gson.compile.util.GList;
import io.gitlab.jfronny.gson.stream.JsonReader;
import io.gitlab.jfronny.commons.serialize.json.JsonReader;
import io.gitlab.jfronny.inceptum.common.GList;
import io.gitlab.jfronny.inceptum.common.Net;
import io.gitlab.jfronny.inceptum.common.Utils;
import io.gitlab.jfronny.inceptum.common.model.maven.ArtifactMeta;
@ -23,10 +23,8 @@ public class FabricMetaApi {
public static List<FabricVersionLoaderInfo> getLoaderVersions(VersionsListInfo version) {
try {
return LOADER_VERSIONS_CACHE.get(version, () -> {
return Net.downloadObject(META_URL + "v2/versions/loader/" + version.id, s -> {
try (JsonReader r = new JsonReader(new StringReader(s))) {
return GList.read(r, GC_FabricVersionLoaderInfo::read);
}
return Net.downloadJObject(META_URL + "v2/versions/loader/" + version.id, s -> {
return GList.read(s, GC_FabricVersionLoaderInfo::deserialize);
});
});
} catch (IOException e) {
@ -35,7 +33,7 @@ public class FabricMetaApi {
}
public static FabricVersionLoaderInfo getLoaderVersion(String gameVersion, String fabricVersion) throws IOException {
return Net.downloadObject(META_URL + "v2/versions/loader/" + gameVersion + "/" + fabricVersion, GC_FabricVersionLoaderInfo.WithMeta::read);
return Net.downloadJObject(META_URL + "v2/versions/loader/" + gameVersion + "/" + fabricVersion, GC_FabricVersionLoaderInfo.WithMeta::deserialize);
}
public static VersionInfo addFabric(VersionInfo version, String fabricVersion, FabricVersionInfoType type) throws IOException {

View File

@ -1,6 +1,7 @@
package io.gitlab.jfronny.inceptum.launcher.api;
import io.gitlab.jfronny.commons.OSUtils;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.common.MetaHolder;
import io.gitlab.jfronny.inceptum.common.Net;
import io.gitlab.jfronny.inceptum.launcher.model.mojang.*;
@ -12,19 +13,20 @@ import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import static io.gitlab.jfronny.inceptum.common.Net.downloadJObject;
import static io.gitlab.jfronny.inceptum.common.Net.downloadObject;
public class McApi {
public static VersionsList getVersions() {
try {
return downloadObject("https://launchermeta.mojang.com/mc/game/version_manifest_v2.json", GC_VersionsList::read);
return downloadJObject("https://launchermeta.mojang.com/mc/game/version_manifest_v2.json", GC_VersionsList::deserialize);
} catch (IOException e) {
throw new RuntimeException("Could not load version manifest", e);
}
}
public static VersionInfo getVersionInfo(VersionsListInfo listInfo) throws IOException {
return downloadObject(listInfo.url, listInfo.sha1, GC_VersionInfo::read);
return downloadJObject(listInfo.url, listInfo.sha1, GC_VersionInfo::deserialize);
}
public static AssetIndex getAssetIndex(VersionInfo info) throws IOException, URISyntaxException {
@ -36,12 +38,12 @@ public class McApi {
} catch (IOException | URISyntaxException e) {
if (!Files.exists(file)) throw e;
}
return GC_AssetIndex.read(file);
return GC_AssetIndex.deserialize(file, GsonPreset.API);
}
public static Map<String, JvmFileInfo.File> getJvm(String component, int majorVersion) throws IOException {
// https://github.com/ATLauncher/ATLauncher/blob/master/src/main/java/com/atlauncher/constants/Constants.java#L123
JvmInfo info = Net.downloadObject("https://launchermeta.mojang.com/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json", GC_JvmInfo::read);
JvmInfo info = downloadJObject("https://launchermeta.mojang.com/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json", GC_JvmInfo::deserialize);
Map<String, List<JvmInfo.Jvm>> vms = switch (OSUtils.TYPE) {
case WINDOWS -> info.windowsX64();
case LINUX -> info.linux();
@ -52,7 +54,7 @@ public class McApi {
throw new IOException("Invalid component: " + component + " (available: " + String.join(", ", vms.keySet()));
for (JvmInfo.Jvm jvm : vmList) {
if (jvm.version().name().startsWith(Integer.toString(majorVersion))) {
return downloadObject(jvm.manifest().url, jvm.manifest().sha1, GC_JvmFileInfo::read).files();
return downloadJObject(jvm.manifest().url, jvm.manifest().sha1, GC_JvmFileInfo::deserialize).files();
}
}
throw new IOException("JVM not found");

View File

@ -1,7 +1,7 @@
package io.gitlab.jfronny.inceptum.launcher.api;
import io.gitlab.jfronny.gson.compile.util.GList;
import io.gitlab.jfronny.gson.stream.JsonReader;
import io.gitlab.jfronny.commons.serialize.json.JsonReader;
import io.gitlab.jfronny.inceptum.common.GList;
import io.gitlab.jfronny.inceptum.common.Net;
import io.gitlab.jfronny.inceptum.launcher.model.modrinth.*;
@ -16,31 +16,27 @@ public class ModrinthApi {
//TODO search by categories: facets:[["versions:$ver","versions:$ver"],["categories:$cat","categories:$cat"]]
//TODO filter server/client-only mods
public static ModrinthSearchResult search(String query, int page, String version, ModrinthProjectType type) throws IOException {
return Net.downloadObject(Net.buildUrl(API_HOST, "v2/search", Map.of(
return Net.downloadJObject(Net.buildUrl(API_HOST, "v2/search", Map.of(
"query", query,
"facets", "[[\"versions:" + version + "\"],[\"categories:fabric\"],[\"project_type:" + type + "\"]]",
"index", "relevance",
"offset", Integer.toString(page * ITEMS_PER_PAGE),
"limit", Integer.toString(ITEMS_PER_PAGE)
)), GC_ModrinthSearchResult::read);
)), GC_ModrinthSearchResult::deserialize);
}
public static ModrinthProject getMod(String id) throws IOException {
return Net.downloadObject(API_HOST + "v2/project/" + id, GC_ModrinthProject::read);
return Net.downloadJObject(API_HOST + "v2/project/" + id, GC_ModrinthProject::deserialize);
}
public static List<ModrinthVersion> getVersions(String mod) throws IOException {
List<ModrinthVersion> versions = Net.downloadObject(API_HOST + "v2/project/" + mod + "/version", s -> {
try (JsonReader r = new JsonReader(new StringReader(s))) {
return GList.read(r, GC_ModrinthVersion::read);
}
});
List<ModrinthVersion> versions = Net.downloadJObject(API_HOST + "v2/project/" + mod + "/version", s -> GList.read(s, GC_ModrinthVersion::deserialize));
versions.sort(Comparator.comparing(ModrinthVersion::date_published));
return versions;
}
public static ModrinthVersion getVersion(String id) throws IOException {
return Net.downloadObject(API_HOST + "v2/version/" + id, GC_ModrinthVersion::read);
return Net.downloadJObject(API_HOST + "v2/version/" + id, GC_ModrinthVersion::deserialize);
}
public static ModrinthLatest getLatestVersions(String mod, String gameVersion) throws IOException {
@ -60,6 +56,6 @@ public class ModrinthApi {
}
public static ModrinthVersion getVersionByHash(String sha1) throws IOException {
return Net.downloadObject(API_HOST + "v2/version_file/" + sha1 + "?algorithm=sha1", GC_ModrinthVersion::read);
return Net.downloadJObject(API_HOST + "v2/version_file/" + sha1 + "?algorithm=sha1", GC_ModrinthVersion::deserialize);
}
}

View File

@ -1,8 +1,7 @@
package io.gitlab.jfronny.inceptum.launcher.api.account;
import io.gitlab.jfronny.gson.compile.util.GList;
import io.gitlab.jfronny.gson.stream.JsonReader;
import io.gitlab.jfronny.gson.stream.JsonWriter;
import io.gitlab.jfronny.commons.serialize.json.JsonReader;
import io.gitlab.jfronny.commons.serialize.json.JsonWriter;
import io.gitlab.jfronny.inceptum.common.*;
import io.gitlab.jfronny.inceptum.launcher.LauncherEnv;
@ -41,7 +40,7 @@ public class AccountManager {
public static void saveAccounts() {
try (JsonWriter w = new JsonWriter(Files.newBufferedWriter(MetaHolder.ACCOUNTS_PATH))) {
GsonPreset.Config.configure(w);
GList.write(w, ACCOUNTS, GC_MicrosoftAccount::write);
GList.write(w, ACCOUNTS, GC_MicrosoftAccount::serialize);
} catch (IOException e) {
Utils.LOGGER.error("Could not save accounts", e);
}
@ -52,7 +51,7 @@ public class AccountManager {
if (Files.exists(MetaHolder.ACCOUNTS_PATH)) {
try (JsonReader r = new JsonReader(Files.newBufferedReader(MetaHolder.ACCOUNTS_PATH))) {
GsonPreset.Config.configure(r);
ACCOUNTS.addAll(GList.read(r, GC_MicrosoftAccount::read));
ACCOUNTS.addAll(GList.read(r, GC_MicrosoftAccount::deserialize));
} catch (IOException e) {
Utils.LOGGER.error("Could not load accounts", e);
}
@ -79,7 +78,7 @@ public class AccountManager {
if (ACCOUNTS.size() == 1)
switchAccount(null);
else
switchAccount(ACCOUNTS.get(0));
switchAccount(ACCOUNTS.getFirst());
}
ACCOUNTS.remove(account);
saveAccounts();

View File

@ -1,6 +1,6 @@
package io.gitlab.jfronny.inceptum.launcher.api.account;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.common.Utils;
import io.gitlab.jfronny.inceptum.launcher.LauncherEnv;
@ -13,7 +13,7 @@ import java.io.IOException;
import java.net.URISyntaxException;
import java.util.*;
@GSerializable(with = MicrosoftAccountAdapter.class, configure = GsonPreset.Config.class)
@GSerializable(with = MicrosoftAccountAdapter.class)
public class MicrosoftAccount {
/**
* The username/email/id of the account.

View File

@ -1,6 +1,7 @@
package io.gitlab.jfronny.inceptum.launcher.api.account;
import io.gitlab.jfronny.commons.http.client.HttpClient;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.launcher.model.microsoft.*;
import io.gitlab.jfronny.inceptum.launcher.model.microsoft.request.*;
import io.gitlab.jfronny.inceptum.launcher.model.microsoft.response.*;
@ -38,7 +39,7 @@ public class MicrosoftAuthAPI {
"redirect_uri", MICROSOFT_LOGIN_REDIRECT_URL,
"scope", String.join(" ", MICROSOFT_LOGIN_SCOPES)))
.sendReader()) {
return GC_OauthTokenResponse.read(r);
return GC_OauthTokenResponse.deserialize(r, GsonPreset.API);
}
}
@ -49,14 +50,14 @@ public class MicrosoftAuthAPI {
"grant_type", "refresh_token",
"redirect_uri", MICROSOFT_LOGIN_REDIRECT_URL))
.sendReader()) {
return GC_OauthTokenResponse.read(r);
return GC_OauthTokenResponse.deserialize(r, GsonPreset.API);
}
}
public static XboxLiveAuthResponse getXBLToken(String accessToken) throws IOException, URISyntaxException {
try (Reader r = HttpClient.post(MICROSOFT_XBL_AUTH_TOKEN_URL)
.header("x-xbl-contract-version", "1")
.bodyJson(GC_XblTokenRequest.toJson(new XblTokenRequest(
.bodyJson(GsonPreset.API.write(writer -> GC_XblTokenRequest.serialize(new XblTokenRequest(
new XblTokenRequest.Properties(
"RPS",
"user.auth.xboxlive.com",
@ -64,48 +65,48 @@ public class MicrosoftAuthAPI {
),
"http://auth.xboxlive.com",
"JWT"
)))
), writer)))
.sendReader()) {
return GC_XboxLiveAuthResponse.read(r);
return GC_XboxLiveAuthResponse.deserialize(r, GsonPreset.API);
}
}
public static XboxLiveAuthResponse getXstsToken(String xblToken) throws IOException, URISyntaxException {
try (Reader r = HttpClient.post(MICROSOFT_XSTS_AUTH_TOKEN_URL)
.header("x-xbl-contract-version", "1")
.bodyJson(GC_XstsTokenRequest.toJson(new XstsTokenRequest(
.bodyJson(GsonPreset.API.write(writer -> GC_XstsTokenRequest.serialize(new XstsTokenRequest(
new XstsTokenRequest.Properties(
"RETAIL",
List.of(xblToken)
),
"rp://api.minecraftservices.com/",
"JWT"
)))
), writer)))
.sendReader()) {
return GC_XboxLiveAuthResponse.read(r);
return GC_XboxLiveAuthResponse.deserialize(r, GsonPreset.API);
}
}
public static LoginResponse loginToMinecraft(String xstsToken) throws IOException, URISyntaxException {
try (Reader r = HttpClient.post(MICROSOFT_MINECRAFT_LOGIN_URL)
.bodyJson(GC_LoginRequest.toJson(new LoginRequest(
.bodyJson(GsonPreset.API.write(writer -> GC_LoginRequest.serialize(new LoginRequest(
xstsToken,
"PC_LAUNCHER"
)))
), writer)))
.sendReader()) {
return GC_LoginResponse.read(r);
return GC_LoginResponse.deserialize(r, GsonPreset.API);
}
}
public static Entitlements getEntitlements(String accessToken) throws IOException, URISyntaxException {
try (Reader r = HttpClient.get(MICROSOFT_MINECRAFT_ENTITLEMENTS_URL + UUID.randomUUID()).bearer(accessToken).sendReader()) {
return GC_Entitlements.read(r);
return GC_Entitlements.deserialize(r, GsonPreset.API);
}
}
public static Profile getMcProfile(String accessToken) throws IOException, URISyntaxException {
try (Reader r = HttpClient.get(MICROSOFT_MINECRAFT_PROFILE_URL).bearer(accessToken).sendReader()) {
return GC_Profile.read(r);
return GC_Profile.deserialize(r, GsonPreset.API);
}
}
}

View File

@ -1,18 +1,17 @@
package io.gitlab.jfronny.inceptum.launcher.gson;
import io.gitlab.jfronny.gson.stream.JsonReader;
import io.gitlab.jfronny.gson.stream.JsonWriter;
import io.gitlab.jfronny.commons.serialize.MalformedDataException;
import io.gitlab.jfronny.commons.serialize.SerializeReader;
import io.gitlab.jfronny.commons.serialize.SerializeWriter;
import io.gitlab.jfronny.inceptum.launcher.api.account.MicrosoftAccount;
import java.io.IOException;
public class MicrosoftAccountAdapter {
public static void write(MicrosoftAccount value, JsonWriter writer) throws IOException {
GC_MicrosoftAccountMeta.write(value == null ? null : value.toMeta(), writer);
public static <TEx extends Exception, Writer extends SerializeWriter<TEx, Writer>> void serialize(MicrosoftAccount value, Writer writer) throws TEx, MalformedDataException {
GC_MicrosoftAccountMeta.serialize(value == null ? null : value.toMeta(), writer);
}
public static MicrosoftAccount read(JsonReader reader) throws IOException {
MicrosoftAccountMeta meta = GC_MicrosoftAccountMeta.read(reader);
public static <TEx extends Exception, Reader extends SerializeReader<TEx, Reader>> MicrosoftAccount deserialize(Reader reader) throws TEx, MalformedDataException {
MicrosoftAccountMeta meta = GC_MicrosoftAccountMeta.deserialize(reader);
return meta == null ? null : new MicrosoftAccount(meta);
}
}

View File

@ -1,12 +1,12 @@
package io.gitlab.jfronny.inceptum.launcher.gson;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.launcher.model.microsoft.response.OauthTokenResponse;
import io.gitlab.jfronny.inceptum.launcher.model.microsoft.response.XboxLiveAuthResponse;
import java.util.Date;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record MicrosoftAccountMeta(String accountId, String minecraftUsername, String uuid, String accessToken, OauthTokenResponse oauthToken, XboxLiveAuthResponse xstsAuth, Date accessTokenExpiresAt, boolean mustLogin) {
}

View File

@ -1,32 +1,33 @@
package io.gitlab.jfronny.inceptum.launcher.gson;
import io.gitlab.jfronny.gson.JsonParseException;
import io.gitlab.jfronny.gson.compile.util.GList;
import io.gitlab.jfronny.gson.stream.*;
import io.gitlab.jfronny.commons.serialize.MalformedDataException;
import io.gitlab.jfronny.commons.serialize.SerializeReader;
import io.gitlab.jfronny.commons.serialize.SerializeWriter;
import io.gitlab.jfronny.commons.serialize.Token;
import io.gitlab.jfronny.inceptum.common.GList;
import io.gitlab.jfronny.inceptum.launcher.model.mojang.*;
import java.io.IOException;
import java.util.List;
import java.util.Set;
public class MinecraftArgumentAdapter {
public static void write(MinecraftArgument rules, JsonWriter writer) throws IOException {
public static <TEx extends Exception, Writer extends SerializeWriter<TEx, Writer>> void serialize(MinecraftArgument rules, Writer writer) throws TEx {
throw new UnsupportedOperationException();
}
public static MinecraftArgument read(JsonReader reader) throws IOException {
if (reader.peek() == JsonToken.STRING) return new MinecraftArgument(Set.of(reader.nextString()));
public static <TEx extends Exception, Reader extends SerializeReader<TEx, Reader>> MinecraftArgument deserialize(Reader reader) throws TEx, MalformedDataException {
if (reader.peek() == Token.STRING) return new MinecraftArgument(Set.of(reader.nextString()));
Rules rules = null;
List<String> value = null;
reader.beginObject();
while (reader.hasNext()) {
switch (reader.nextName()) {
case "rules" -> rules = GC_Rules.read(reader);
case "value" -> value = GList.read(reader, JsonReader::nextString);
case "rules" -> rules = GC_Rules.deserialize(reader);
case "value" -> value = GList.read(reader, Reader::nextString);
}
}
reader.endObject();
if (rules == null || value == null) throw new JsonParseException("Not a valid minecraft argument");
if (rules == null || value == null) throw new MalformedDataException("Not a valid minecraft argument");
if (!rules.allow()) return new MinecraftArgument(Set.of());
return new MinecraftArgument(Set.copyOf(value));
}

View File

@ -1,26 +1,26 @@
package io.gitlab.jfronny.inceptum.launcher.gson;
import io.gitlab.jfronny.gson.stream.JsonReader;
import io.gitlab.jfronny.gson.stream.JsonWriter;
import io.gitlab.jfronny.commons.serialize.MalformedDataException;
import io.gitlab.jfronny.commons.serialize.SerializeReader;
import io.gitlab.jfronny.commons.serialize.SerializeWriter;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.ModMeta.Sources;
import io.gitlab.jfronny.inceptum.launcher.system.source.GC_ModSource;
import io.gitlab.jfronny.inceptum.launcher.system.source.ModSource;
import java.io.IOException;
import java.util.Optional;
public class ModMetaSourcesAdapter {
public static void write(Sources value, JsonWriter writer) throws IOException {
public static <TEx extends Exception, Writer extends SerializeWriter<TEx, Writer>> void serialize(Sources value, Writer writer) throws TEx, MalformedDataException {
writer.beginArray();
for (ModSource source : value.keySet()) GC_ModSource.write(source, writer);
for (ModSource source : value.keySet()) GC_ModSource.serialize(source, writer);
writer.endArray();
}
public static Sources read(JsonReader reader) throws IOException {
public static <TEx extends Exception, Reader extends SerializeReader<TEx, Reader>> Sources deserialize(Reader reader) throws TEx, MalformedDataException {
reader.beginArray();
Sources sources = new Sources();
while (reader.hasNext()) {
sources.put(GC_ModSource.read(reader), Optional.empty());
sources.put(GC_ModSource.deserialize(reader), Optional.empty());
}
reader.endArray();
return sources;

View File

@ -1,8 +1,8 @@
package io.gitlab.jfronny.inceptum.launcher.gson;
import io.gitlab.jfronny.gson.JsonParseException;
import io.gitlab.jfronny.gson.stream.JsonReader;
import io.gitlab.jfronny.gson.stream.JsonWriter;
import io.gitlab.jfronny.commons.serialize.MalformedDataException;
import io.gitlab.jfronny.commons.serialize.SerializeReader;
import io.gitlab.jfronny.commons.serialize.SerializeWriter;
import io.gitlab.jfronny.inceptum.launcher.system.source.*;
import java.io.IOException;
@ -10,34 +10,38 @@ import java.util.LinkedHashSet;
import java.util.Set;
public class ModSourceAdapter {
public static void write(ModSource src, JsonWriter writer) throws IOException {
public static <TEx extends Exception, Writer extends SerializeWriter<TEx, Writer>> void serialize(ModSource src, Writer writer) throws TEx {
writer.beginObject();
if (src instanceof ModrinthModSource mo) {
writer.name("type").value("modrinth")
switch (src) {
case ModrinthModSource mo -> writer.name("type").value("modrinth")
.name("id").value(mo.getVersionId());
} else if (src instanceof DirectModSource di) {
writer.name("type").value("direct")
.name("fileName").value(di.getFileName())
.name("url").value(di.url())
.name("dependencies");
writer.beginArray();
for (ModSource dependency : di.dependencies()) {
write(dependency, writer);
case DirectModSource di -> {
writer.name("type").value("direct")
.name("fileName").value(di.getFileName())
.name("url").value(di.url())
.name("dependencies");
writer.beginArray();
for (ModSource dependency : di.dependencies()) {
serialize(dependency, writer);
}
writer.endArray();
}
writer.endArray();
} else if (src instanceof CurseforgeModSource cu) {
writer.name("type").value("curseforge");
if (cu.getShortName().matches("\\d+")) {
writer.name("projectId").value(cu.getProjectId());
} else {
writer.name("project").value(cu.getShortName());
case CurseforgeModSource cu -> {
writer.name("type").value("curseforge");
if (cu.getShortName().matches("\\d+")) {
writer.name("projectId").value(cu.getProjectId());
} else {
writer.name("project").value(cu.getShortName());
}
writer.name("fileId").value(cu.getFileId());
}
writer.name("fileId").value(cu.getFileId());
} else throw new RuntimeException("ModSources with the type " + src.getClass() + " are not supported");
case null, default ->
throw new RuntimeException("ModSources with the type " + (src == null ? null : src.getClass()) + " are not supported");
}
writer.endObject();
}
public static ModSource read(JsonReader reader) throws IOException {
public static <TEx extends Exception, Reader extends SerializeReader<TEx, Reader>> ModSource deserialize(Reader reader) throws TEx, MalformedDataException {
String type = null;
String mr$id = null;
@ -63,34 +67,40 @@ public class ModSourceAdapter {
case "dependencies" -> {
direct$dependencies = new LinkedHashSet<>();
reader.beginArray();
while (reader.hasNext()) direct$dependencies.add(read(reader));
while (reader.hasNext()) direct$dependencies.add(deserialize(reader));
reader.endArray();
}
}
}
reader.endObject();
if (type == null) throw new JsonParseException("Expected ModSource to contain a type");
return switch (type) {
case "modrinth" -> {
if (mr$id == null) throw new JsonParseException("Expected ModrinthModSource to contain a version ID");
yield new ModrinthModSource(mr$id);
}
case "curseforge" -> {
if (cf$fileId == null)
throw new JsonParseException("Expected a fileId in this curseforge project");
if (cf$projectId != null) yield new CurseforgeModSource(cf$projectId, cf$fileId);
else if (cf$project != null) yield new CurseforgeModSource(cf$project, cf$fileId);
else throw new JsonParseException("Expected a projectId in this curseforge project");
}
case "direct" -> {
if (direct$fileName == null) throw new JsonParseException("Expected direct download to have a fileName");
if (direct$url == null) throw new JsonParseException("Expected direct download to have a url");
if (direct$dependencies == null) yield new DirectModSource(direct$fileName, direct$url, Set.of());
else {
yield new DirectModSource(direct$fileName, direct$url, direct$dependencies);
if (type == null) throw new MalformedDataException("Expected ModSource to contain a type");
try {
return switch (type) {
case "modrinth" -> {
if (mr$id == null) throw new MalformedDataException("Expected ModrinthModSource to contain a version ID");
yield new ModrinthModSource(mr$id);
}
}
default -> throw new JsonParseException("Unexpected ModSource type: " + type);
};
case "curseforge" -> {
if (cf$fileId == null)
throw new MalformedDataException("Expected a fileId in this curseforge project");
if (cf$projectId != null) yield new CurseforgeModSource(cf$projectId, cf$fileId);
else if (cf$project != null) yield new CurseforgeModSource(cf$project, cf$fileId);
else throw new MalformedDataException("Expected a projectId in this curseforge project");
}
case "direct" -> {
if (direct$fileName == null) throw new MalformedDataException("Expected direct download to have a fileName");
if (direct$url == null) throw new MalformedDataException("Expected direct download to have a url");
if (direct$dependencies == null) yield new DirectModSource(direct$fileName, direct$url, Set.of());
else {
yield new DirectModSource(direct$fileName, direct$url, direct$dependencies);
}
}
default -> throw new MalformedDataException("Unexpected ModSource type: " + type);
};
} catch (MalformedDataException mde) {
throw mde;
} catch (IOException e) {
throw new MalformedDataException("Failed to read ModSource", e);
}
}
}

View File

@ -1,19 +1,17 @@
package io.gitlab.jfronny.inceptum.launcher.gson;
import io.gitlab.jfronny.commons.OSUtils;
import io.gitlab.jfronny.gson.JsonParseException;
import io.gitlab.jfronny.gson.stream.JsonReader;
import io.gitlab.jfronny.gson.stream.JsonWriter;
import io.gitlab.jfronny.commons.serialize.MalformedDataException;
import io.gitlab.jfronny.commons.serialize.SerializeReader;
import io.gitlab.jfronny.commons.serialize.SerializeWriter;
import io.gitlab.jfronny.inceptum.launcher.model.mojang.Rules;
import java.io.IOException;
public class RulesAdapter {
public static void write(Rules rules, JsonWriter writer) throws IOException {
public static <TEx extends Exception, Writer extends SerializeWriter<TEx, Writer>> void serialize(Rules rules, Writer writer) throws TEx {
throw new UnsupportedOperationException();
}
public static Rules read(JsonReader reader) throws IOException {
public static <TEx extends Exception, Reader extends SerializeReader<TEx, Reader>> Rules deserialize(Reader reader) throws TEx, MalformedDataException {
boolean valid = true;
reader.beginArray();
while (reader.hasNext()) {
@ -48,7 +46,7 @@ public class RulesAdapter {
}
reader.endObject();
if (actionType == null || (!actionType.equals("allow") && !actionType.equals("disallow"))) {
throw new JsonParseException("Unexpected action in argument: " + actionType);
throw new MalformedDataException("Unexpected action in argument: " + actionType);
}
if (hasFeatures) valid = false;
if (osName != null && !OSUtils.TYPE.getMojName().equals(osName)) valid = false;

View File

@ -1,12 +1,12 @@
package io.gitlab.jfronny.inceptum.launcher.model.curseforge;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.Date;
import java.util.List;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record CurseforgeFile(
int id,
int gameId,
@ -52,11 +52,11 @@ public record CurseforgeFile(
/* Possible algorithms:
1=Sha1
2=Md5*/
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Hash(String value, int algo) {
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record GameVersion(String gameVersionName,
String gameVersionPadded,
String gameVersion,
@ -71,11 +71,11 @@ public record CurseforgeFile(
4=Tool
5=Incompatible
6=Include*/
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Dependency(int modId, int relationType) {
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Module(String name, long fingerprint) {
}
}

View File

@ -1,12 +1,12 @@
package io.gitlab.jfronny.inceptum.launcher.model.curseforge;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.Date;
import java.util.List;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record CurseforgeMod(
int id,
int gameId,
@ -45,11 +45,11 @@ public record CurseforgeMod(
boolean isAvailable,
int thumbsUpCount
) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Links(String websiteUrl, String wikiUrl, String issuesUrl, String sourcesUrl) {
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Category(int id,
int gameId,
String name,
@ -62,11 +62,11 @@ public record CurseforgeMod(
int primaryCategoryId) {
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Author(int id, String name, String url) {
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Logo(int id,
int modId,
String title,
@ -75,7 +75,7 @@ public record CurseforgeMod(
String url) {
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Screenshot(int id,
int modId,
String title,
@ -84,7 +84,7 @@ public record CurseforgeMod(
String url) {
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record LatestFileIndex(String gameVersion,
int fileId,
String filename,

View File

@ -1,11 +1,11 @@
package io.gitlab.jfronny.inceptum.launcher.model.curseforge;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.Set;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record CurseforgeModpackManifest(Minecraft minecraft,
String manifestType,
int manifestVersion,
@ -14,14 +14,14 @@ public record CurseforgeModpackManifest(Minecraft minecraft,
String author,
Set<File> files,
String overrides) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Minecraft(String version, Set<ModLoader> modLoaders) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record ModLoader(String id, boolean primary) {
}
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record File(int projectID, int fileID, boolean required) {
}
}

View File

@ -1,21 +1,21 @@
package io.gitlab.jfronny.inceptum.launcher.model.curseforge.response;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.launcher.model.curseforge.CurseforgeFile;
import java.util.List;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record FingerprintMatchesResponse(Result data) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Result(boolean isCacheBuilt,
List<Match> exactMatches,
List<Integer> exactFingerprints,
List<Match> partialMatches,
List<Integer> installedFingerprints,
List<Integer> unmatchedFingerprints) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Match(int id, CurseforgeFile file, List<CurseforgeFile> latestFiles) {
}
}

View File

@ -1,8 +1,8 @@
package io.gitlab.jfronny.inceptum.launcher.model.curseforge.response;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record GetModDescriptionResponse(String data) {
}

View File

@ -1,9 +1,9 @@
package io.gitlab.jfronny.inceptum.launcher.model.curseforge.response;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.launcher.model.curseforge.CurseforgeFile;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record GetModFileResponse(CurseforgeFile data) {
}

View File

@ -1,9 +1,9 @@
package io.gitlab.jfronny.inceptum.launcher.model.curseforge.response;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.launcher.model.curseforge.CurseforgeMod;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record GetModResponse(CurseforgeMod data) {
}

View File

@ -1,14 +1,14 @@
package io.gitlab.jfronny.inceptum.launcher.model.curseforge.response;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.launcher.model.curseforge.CurseforgeMod;
import java.util.List;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record SearchResponse(List<CurseforgeMod> data, Pagination pagination) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Pagination(int index, int pageSite, int resultCount, int totalCount) {
}
}

View File

@ -1,8 +1,8 @@
package io.gitlab.jfronny.inceptum.launcher.model.fabric;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record FabricLoaderVersion(String separator, int build, String maven, String version, boolean stable) {
}

View File

@ -1,8 +1,8 @@
package io.gitlab.jfronny.inceptum.launcher.model.fabric;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record FabricModJson(String id, String name, String description, String version) {
}

View File

@ -1,29 +1,29 @@
package io.gitlab.jfronny.inceptum.launcher.model.fabric;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.List;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public class FabricVersionLoaderInfo {
public FabricLoaderVersion loader;
public IntermediaryVersion intermediary;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public static class WithMeta extends FabricVersionLoaderInfo {
public LauncherMeta launcherMeta;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record LauncherMeta(int version, Libraries libraries, MainClass mainClass) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Libraries(List<Library> client, List<Library> common, List<Library> server) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Library(String name, String url) {
}
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record MainClass(String client, String server) {
}
}

View File

@ -1,8 +1,8 @@
package io.gitlab.jfronny.inceptum.launcher.model.fabric;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record IntermediaryVersion(String maven, String version, boolean stable) {
}

View File

@ -1,13 +1,12 @@
package io.gitlab.jfronny.inceptum.launcher.model.inceptum;
import io.gitlab.jfronny.gson.compile.annotations.GPrefer;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GPrefer;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import java.util.List;
import java.util.Objects;
@GSerializable(configure = GsonPreset.Config.class)
@GSerializable
public class InstanceMeta {
public String instanceVersion = "1.0";
public String gameVersion;
@ -43,11 +42,12 @@ public class InstanceMeta {
arguments = Arguments.checked(arguments);
}
@GSerializable(configure = GsonPreset.Config.class)
@GSerializable
public record Arguments(List<String> jvm, List<String> client, List<String> server) {
public static final Arguments EMPTY = new Arguments(List.of(), List.of(), List.of());
@GPrefer public Arguments {}
@GPrefer
public Arguments {}
public static Arguments checked(Arguments of) {
if (of == null) return EMPTY;

View File

@ -3,9 +3,8 @@ package io.gitlab.jfronny.inceptum.launcher.model.inceptum;
import io.gitlab.jfronny.commons.data.MutCollection;
import io.gitlab.jfronny.commons.data.delegate.DelegateMap;
import io.gitlab.jfronny.commons.io.HashUtils;
import io.gitlab.jfronny.gson.compile.annotations.GPrefer;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GPrefer;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.Utils;
import io.gitlab.jfronny.inceptum.launcher.api.CurseforgeApi;
import io.gitlab.jfronny.inceptum.launcher.api.ModrinthApi;
@ -21,7 +20,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
@GSerializable(configure = GsonPreset.Config.class)
@GSerializable
public record ModMeta(
Sources sources, //key: source, value: update
String sha1,
@ -30,7 +29,7 @@ public record ModMeta(
List<String> dependencies, // by file name
boolean explicit
) {
@GSerializable(with = ModMetaSourcesAdapter.class, configure = GsonPreset.Config.class)
@GSerializable(with = ModMetaSourcesAdapter.class)
public static class Sources extends DelegateMap<ModSource, Optional<ModSource>> {
public Sources() {
super(MutCollection.mapOf());

View File

@ -1,13 +1,13 @@
package io.gitlab.jfronny.inceptum.launcher.model.microsoft;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.List;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Entitlements(List<StoreItem> items, String signature) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record StoreItem(String name, String signature) {
}
}

View File

@ -1,17 +1,17 @@
package io.gitlab.jfronny.inceptum.launcher.model.microsoft;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.List;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Profile(String id, String name, List<Skin> skins, List<Cape> capes) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Skin(String id, String state, String url, String variant, String alias) {
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Cape(String id) {
}
}

View File

@ -1,8 +1,8 @@
package io.gitlab.jfronny.inceptum.launcher.model.microsoft.request;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record LoginRequest(String xtoken, String platform) {
}

View File

@ -1,14 +1,13 @@
package io.gitlab.jfronny.inceptum.launcher.model.microsoft.request;
import io.gitlab.jfronny.gson.annotations.SerializedName;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.commons.serialize.annotations.SerializedName;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record XblTokenRequest(@SerializedName("Properties") Properties properties,
@SerializedName("RelyingParty") String relyingParty,
@SerializedName("TokenType") String tokenType) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Properties(@SerializedName("AuthMethod") String authMethod,
@SerializedName("SiteName") String siteName,
@SerializedName("RpsTicket") String rpsTicket) {

View File

@ -1,16 +1,15 @@
package io.gitlab.jfronny.inceptum.launcher.model.microsoft.request;
import io.gitlab.jfronny.gson.annotations.SerializedName;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.commons.serialize.annotations.SerializedName;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import java.util.List;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record XstsTokenRequest(@SerializedName("Properties") Properties properties,
@SerializedName("RelyingParty") String relyingParty,
@SerializedName("TokenType") String tokenType) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Properties(@SerializedName("SandboxId") String sandboxId, @SerializedName("UserTokens") List<String> userTokens) {
}
}

View File

@ -1,10 +1,9 @@
package io.gitlab.jfronny.inceptum.launcher.model.microsoft.response;
import io.gitlab.jfronny.gson.annotations.SerializedName;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.commons.serialize.annotations.SerializedName;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record LoginResponse(String username,
@SerializedName("access_token") String accessToken,
@SerializedName("token_type") String tokenType,

View File

@ -1,13 +1,12 @@
package io.gitlab.jfronny.inceptum.launcher.model.microsoft.response;
import io.gitlab.jfronny.gson.annotations.SerializedName;
import io.gitlab.jfronny.gson.compile.annotations.GPrefer;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.commons.serialize.annotations.SerializedName;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GPrefer;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import java.util.Date;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record OauthTokenResponse(
@SerializedName("token_type") String tokenType,
@SerializedName("expires_in") int expiresIn,

View File

@ -1,20 +1,19 @@
package io.gitlab.jfronny.inceptum.launcher.model.microsoft.response;
import io.gitlab.jfronny.gson.annotations.SerializedName;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.commons.serialize.annotations.SerializedName;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import java.util.Date;
import java.util.List;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record XboxLiveAuthResponse(@SerializedName("IssueInstant") Date issueInstant,
@SerializedName("NotAfter") Date notAfter,
@SerializedName("Token") String token,
@SerializedName("DisplayClaims") DisplayClaims displayClaims) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record DisplayClaims(List<XUIClaim> xui) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record XUIClaim(String uhs) {
}
}

View File

@ -1,8 +1,8 @@
package io.gitlab.jfronny.inceptum.launcher.model.modrinth;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record ModrinthHashes(String sha1, String sha512) {
}

View File

@ -1,13 +1,12 @@
package io.gitlab.jfronny.inceptum.launcher.model.modrinth;
import io.gitlab.jfronny.gson.annotations.SerializedName;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.commons.serialize.annotations.SerializedName;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record ModrinthModpackManifest(
int formatVersion, // 1
String game, // "minecraft"
@ -17,15 +16,15 @@ public record ModrinthModpackManifest(
List<File> files,
Dependencies dependencies
) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record File(String path, ModrinthHashes hashes, @Nullable Env env, List<String> downloads, long fileSize) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Env(ModrinthDependencyType client, ModrinthDependencyType server) {
}
}
// All are nullable
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Dependencies(String minecraft,
String forge,
@SerializedName("fabric-loader") String fabricLoader,

View File

@ -1,12 +1,12 @@
package io.gitlab.jfronny.inceptum.launcher.model.modrinth;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.Date;
import java.util.List;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record ModrinthProject(
String id,
String slug,
@ -34,15 +34,15 @@ public record ModrinthProject(
List<DonationUrl> donation_urls,
List<GalleryItem> gallery
) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record DonationUrl(String id, String platform, String url) {
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record License(String id, String name, String url) {
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record GalleryItem(String url, boolean featured, String title, String description, Date created) {
}
}

View File

@ -1,14 +1,14 @@
package io.gitlab.jfronny.inceptum.launcher.model.modrinth;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.Date;
import java.util.List;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record ModrinthSearchResult(List<ModResult> hits, int offset, int limit, int total_hits) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record ModResult(
String project_id,
ModrinthProjectType project_type,

View File

@ -1,12 +1,12 @@
package io.gitlab.jfronny.inceptum.launcher.model.modrinth;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.Date;
import java.util.List;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record ModrinthVersion(
String id,
String project_id,
@ -28,11 +28,11 @@ public record ModrinthVersion(
alpha, beta, release
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record File(ModrinthHashes hashes, String url, String filename, boolean primary) {
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Dependency(String version_id, String project_id, DependencyType dependency_type) {
public enum DependencyType {
required,

View File

@ -1,13 +1,13 @@
package io.gitlab.jfronny.inceptum.launcher.model.mojang;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.Map;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record AssetIndex(Map<String, Asset> objects) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Asset(String hash, int size) {
}
}

View File

@ -1,15 +1,15 @@
package io.gitlab.jfronny.inceptum.launcher.model.mojang;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.Map;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record JvmFileInfo(Map<String, File> files) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record File(Downloads downloads, boolean executable, String type) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Downloads(MojangFileDownload lzma, MojangFileDownload raw) {
}
}

View File

@ -1,23 +1,22 @@
package io.gitlab.jfronny.inceptum.launcher.model.mojang;
import io.gitlab.jfronny.gson.annotations.SerializedName;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.commons.serialize.annotations.SerializedName;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import java.util.List;
import java.util.Map;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record JvmInfo(Map<String, List<Jvm>> linux,
@SerializedName("mac-os") Map<String, List<Jvm>> macOs,
@SerializedName("windows-x64") Map<String, List<Jvm>> windowsX64) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Jvm(Availability availability, MojangFileDownload manifest, Version version) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Availability(int group, int progress) {
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Version(String name, String released) {
}
}

View File

@ -1,13 +1,13 @@
package io.gitlab.jfronny.inceptum.launcher.model.mojang;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.launcher.gson.MinecraftArgumentAdapter;
import java.util.LinkedHashSet;
import java.util.Set;
@GSerializable(with = MinecraftArgumentAdapter.class, configure = GsonPreset.Api.class)
@GSerializable(with = MinecraftArgumentAdapter.class)
public record MinecraftArgument(Set<String> arg) implements Cloneable {
@Override
protected MinecraftArgument clone() {

View File

@ -1,9 +1,9 @@
package io.gitlab.jfronny.inceptum.launcher.model.mojang;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public class MojangFileDownload implements Cloneable {
public String sha1;
public int size;

View File

@ -1,10 +1,10 @@
package io.gitlab.jfronny.inceptum.launcher.model.mojang;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.launcher.gson.RulesAdapter;
@GSerializable(with = RulesAdapter.class, configure = GsonPreset.Api.class)
@GSerializable(with = RulesAdapter.class)
public record Rules(boolean allow) implements Cloneable {
@Override
protected Rules clone() {

View File

@ -1,13 +1,12 @@
package io.gitlab.jfronny.inceptum.launcher.model.mojang;
import io.gitlab.jfronny.gson.compile.annotations.GPrefer;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GPrefer;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import java.util.*;
@SuppressWarnings("MethodDoesntCallSuperMethod")
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public class VersionInfo extends VersionsListInfo implements Cloneable {
public Arguments arguments;
public AssetIndex assetIndex;
@ -36,7 +35,7 @@ public class VersionInfo extends VersionsListInfo implements Cloneable {
return clone;
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Arguments(List<MinecraftArgument> game, List<MinecraftArgument> jvm) implements Cloneable {
@Override
public Arguments clone() {
@ -47,7 +46,7 @@ public class VersionInfo extends VersionsListInfo implements Cloneable {
}
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public static class AssetIndex extends MojangFileDownload {
public String id;
public int totalSize;
@ -62,7 +61,7 @@ public class VersionInfo extends VersionsListInfo implements Cloneable {
}
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Downloads(MojangFileDownload client,
MojangFileDownload client_mappings,
MojangFileDownload server,
@ -78,7 +77,7 @@ public class VersionInfo extends VersionsListInfo implements Cloneable {
}
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record JavaVersion(String component, int majorVersion) implements Cloneable {
@Override
public JavaVersion clone() {
@ -86,7 +85,7 @@ public class VersionInfo extends VersionsListInfo implements Cloneable {
}
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Library(Downloads downloads, String name, Map<String, String> natives, Rules rules) implements Cloneable {
@Override
public Library clone() {
@ -100,7 +99,7 @@ public class VersionInfo extends VersionsListInfo implements Cloneable {
return clone;
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Downloads(Artifact artifact, Map<String, Artifact> classifiers) implements Cloneable {
@Override
public Downloads clone() {
@ -109,7 +108,7 @@ public class VersionInfo extends VersionsListInfo implements Cloneable {
return clone;
}
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public static class Artifact extends MojangFileDownload implements Cloneable {
public String path;

View File

@ -1,13 +1,13 @@
package io.gitlab.jfronny.inceptum.launcher.model.mojang;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.List;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record VersionsList(Latest latest, List<VersionsListInfo> versions) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Latest(String release, String snapshot) {
}
}

View File

@ -1,12 +1,12 @@
package io.gitlab.jfronny.inceptum.launcher.model.mojang;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.Date;
import java.util.Objects;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public class VersionsListInfo {
public String id;
public String type;

View File

@ -1,13 +1,13 @@
package io.gitlab.jfronny.inceptum.launcher.model.multimc;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import java.util.List;
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record MMCPackMeta(List<Component> components, int formatVersion) {
@GSerializable(configure = GsonPreset.Api.class)
@GSerializable
public record Component(boolean dependencyOnly, boolean important, String uid, String version) {
}
}

View File

@ -1,5 +1,6 @@
package io.gitlab.jfronny.inceptum.launcher.system.exporter;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.common.InceptumConfig;
import io.gitlab.jfronny.inceptum.launcher.model.curseforge.CurseforgeModpackManifest;
import io.gitlab.jfronny.inceptum.launcher.model.curseforge.GC_CurseforgeModpackManifest;
@ -41,7 +42,7 @@ public class CurseForgeExporter extends Exporter<CurseforgeModpackManifest> {
true
));
}
GC_CurseforgeModpackManifest.write(manifest, root.resolve("manifest.json"));
GC_CurseforgeModpackManifest.serialize(manifest, root.resolve("manifest.json"), GsonPreset.API);
return manifest;
}
@ -60,6 +61,6 @@ public class CurseForgeExporter extends Exporter<CurseforgeModpackManifest> {
Files.createDirectories(modsOverrides);
Files.copy(mod.getJarPath(), modsOverrides.resolve(mod.getJarPath().getFileName().toString()));
}
GC_CurseforgeModpackManifest.write(manifest, root.resolve("manifest.json"));
GC_CurseforgeModpackManifest.serialize(manifest, root.resolve("manifest.json"), GsonPreset.API);
}
}

View File

@ -1,5 +1,6 @@
package io.gitlab.jfronny.inceptum.launcher.system.exporter;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.launcher.model.modrinth.GC_ModrinthModpackManifest;
import io.gitlab.jfronny.inceptum.launcher.model.modrinth.ModrinthModpackManifest;
import io.gitlab.jfronny.inceptum.launcher.system.instance.Instance;
@ -33,7 +34,7 @@ public class ModrinthExporter extends Exporter<ModrinthModpackManifest> {
null
)
);
GC_ModrinthModpackManifest.write(manifest, root.resolve("modrinth.index.json"));
GC_ModrinthModpackManifest.serialize(manifest, root.resolve("modrinth.index.json"), GsonPreset.API);
return manifest;
}
@ -52,6 +53,6 @@ public class ModrinthExporter extends Exporter<ModrinthModpackManifest> {
Files.createDirectories(modsOverrides);
Files.copy(mod.getJarPath(), modsOverrides.resolve(mod.getJarPath().getFileName().toString()));
}
GC_ModrinthModpackManifest.write(manifest, root.resolve("modrinth.index.json"));
GC_ModrinthModpackManifest.serialize(manifest, root.resolve("modrinth.index.json"), GsonPreset.API);
}
}

View File

@ -1,5 +1,6 @@
package io.gitlab.jfronny.inceptum.launcher.system.exporter;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.launcher.model.multimc.GC_MMCPackMeta;
import io.gitlab.jfronny.inceptum.launcher.model.multimc.MMCPackMeta;
import io.gitlab.jfronny.inceptum.launcher.system.instance.Instance;
@ -54,7 +55,7 @@ public class MultiMCExporter extends Exporter<MMCPackMeta> {
manifest.components().add(new MMCPackMeta.Component(true, false, "net.fabricmc.intermediary", instance.getGameVersion()));
manifest.components().add(new MMCPackMeta.Component(false, false, "net.fabricmc.fabric-loader", instance.getLoaderVersion()));
}
GC_MMCPackMeta.write(manifest, root.resolve("mmc-pack.json"));
GC_MMCPackMeta.serialize(manifest, root.resolve("mmc-pack.json"), GsonPreset.API);
return manifest;
}
}

View File

@ -1,5 +1,6 @@
package io.gitlab.jfronny.inceptum.launcher.system.importer;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.launcher.model.curseforge.CurseforgeModpackManifest;
import io.gitlab.jfronny.inceptum.launcher.model.curseforge.GC_CurseforgeModpackManifest;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_ModMeta;
@ -15,7 +16,7 @@ import java.nio.file.Path;
public class CurseForgeImporter extends Importer<CurseforgeModpackManifest> {
public CurseForgeImporter() {
super("CurseForge", "manifest.json", GC_CurseforgeModpackManifest::read);
super("CurseForge", "manifest.json", path -> GC_CurseforgeModpackManifest.deserialize(path, GsonPreset.API));
}
@Override
@ -47,7 +48,7 @@ public class CurseForgeImporter extends Importer<CurseforgeModpackManifest> {
ModDownload download = source.download();
ModMeta imod = ModMeta.of(download.sha1(), download.murmur2(), source, manifest.minecraft().version());
Files.createDirectories(modsPath);
GC_ModMeta.write(imod, modsPath.resolve(source.getShortName() + ModPath.EXT_IMOD));
GC_ModMeta.serialize(imod, modsPath.resolve(source.getShortName() + ModPath.EXT_IMOD), GsonPreset.CONFIG);
}
}
}

View File

@ -2,6 +2,7 @@ package io.gitlab.jfronny.inceptum.launcher.system.importer;
import io.gitlab.jfronny.commons.io.JFiles;
import io.gitlab.jfronny.commons.throwable.ThrowingFunction;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.common.MetaHolder;
import io.gitlab.jfronny.inceptum.common.Utils;
import io.gitlab.jfronny.inceptum.launcher.api.FabricMetaApi;
@ -61,7 +62,7 @@ public abstract class Importer<T> {
Instance.setSetupLock(iDir, true);
InstanceMeta meta = new InstanceMeta();
meta.gameVersion = createVersionString(man.gameVersion(), man.fabricVersion());
GC_InstanceMeta.write(meta, iDir.resolve(Instance.CONFIG_NAME));
GC_InstanceMeta.serialize(meta, iDir.resolve(Instance.CONFIG_NAME), GsonPreset.CONFIG);
if (state.isCancelled()) {
JFiles.deleteRecursive(iDir);

View File

@ -1,5 +1,6 @@
package io.gitlab.jfronny.inceptum.launcher.system.importer;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.common.Net;
import io.gitlab.jfronny.inceptum.launcher.model.modrinth.GC_ModrinthModpackManifest;
import io.gitlab.jfronny.inceptum.launcher.model.modrinth.ModrinthModpackManifest;
@ -11,7 +12,7 @@ import java.nio.file.Path;
public class ModrinthImporter extends Importer<ModrinthModpackManifest> {
public ModrinthImporter() {
super("Modrinth", "modrinth.index.json", GC_ModrinthModpackManifest::read);
super("Modrinth", "modrinth.index.json", path -> GC_ModrinthModpackManifest.deserialize(path, GsonPreset.API));
}
@Override

View File

@ -1,5 +1,6 @@
package io.gitlab.jfronny.inceptum.launcher.system.importer;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.launcher.model.multimc.GC_MMCPackMeta;
import io.gitlab.jfronny.inceptum.launcher.model.multimc.MMCPackMeta;
import io.gitlab.jfronny.inceptum.launcher.util.ProcessState;
@ -11,7 +12,7 @@ import java.util.stream.Stream;
public class MultiMCImporter extends Importer<MMCPackMeta> {
public MultiMCImporter() {
super("MultiMC", "mmc-pack.json", GC_MMCPackMeta::read);
super("MultiMC", "mmc-pack.json", path -> GC_MMCPackMeta.deserialize(path, GsonPreset.API));
}
@Override

View File

@ -1,6 +1,7 @@
package io.gitlab.jfronny.inceptum.launcher.system.instance;
import io.gitlab.jfronny.commons.ref.R;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.common.Utils;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_InstanceMeta;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta;
@ -154,7 +155,7 @@ public record Instance(String id, Path path, InstanceMeta meta, ModsDirScanner m
public void writeMeta() {
try {
GC_InstanceMeta.write(meta, path.resolve(CONFIG_NAME));
GC_InstanceMeta.serialize(meta, path.resolve(CONFIG_NAME), GsonPreset.CONFIG);
} catch (IOException e) {
Utils.LOGGER.error("Could not write instance config", e);
}

View File

@ -3,6 +3,7 @@ package io.gitlab.jfronny.inceptum.launcher.system.instance;
import io.gitlab.jfronny.commons.io.JFiles;
import io.gitlab.jfronny.commons.throwable.ThrowingConsumer;
import io.gitlab.jfronny.commons.throwable.ThrowingRunnable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.common.MetaHolder;
import io.gitlab.jfronny.inceptum.common.Utils;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_InstanceMeta;
@ -76,7 +77,7 @@ public class InstanceList {
if (!metas.containsKey(instancePath)) {
metas.put(instancePath, new IEntry(
instancePath,
new FileBackedRef<>(instancePath.resolve(Instance.CONFIG_NAME), GC_InstanceMeta::read)
new FileBackedRef<>(instancePath.resolve(Instance.CONFIG_NAME), GC_InstanceMeta::deserialize, GsonPreset.CONFIG)
));
}
return metas.get(instancePath).toPub();

View File

@ -1,5 +1,6 @@
package io.gitlab.jfronny.inceptum.launcher.system.instance;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_ModMeta;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.ModMeta;
import io.gitlab.jfronny.inceptum.launcher.system.mds.ModsDirScanner;
@ -31,7 +32,7 @@ public class ModManager {
public record DownloadMeta(ModDownload download, ModMeta meta, ModSource source, Path metaFile) {
public void write() throws IOException {
GC_ModMeta.write(meta, metaFile);
GC_ModMeta.serialize(meta, metaFile, GsonPreset.CONFIG);
}
}
}

View File

@ -1,6 +1,6 @@
package io.gitlab.jfronny.inceptum.launcher.system.mds.threaded;
import io.gitlab.jfronny.gson.JsonParseException;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.common.Utils;
import io.gitlab.jfronny.inceptum.launcher.model.fabric.FabricModJson;
import io.gitlab.jfronny.inceptum.launcher.model.fabric.GC_FabricModJson;
@ -25,7 +25,7 @@ public record FileScanTask(ProtoInstance instance, Path file, BiConsumer<Path, M
if (ModPath.isJar(file)) discover(file, ModPath.appendImod(file));
else if (ModPath.isImod(file)) discover(ModPath.trimImod(file), file);
else discovered.accept(file, new NoopMod(file));
} catch (IOException | URISyntaxException | JsonParseException e) {
} catch (IOException | URISyntaxException e) {
Utils.LOGGER.error("Could not scan file for mod info", e);
}
}
@ -33,14 +33,14 @@ public record FileScanTask(ProtoInstance instance, Path file, BiConsumer<Path, M
private void discover(Path jarPath, Path imodPath) throws IOException, URISyntaxException {
boolean managed = false;
ModMeta meta;
if (Files.exists(imodPath)) meta = GC_ModMeta.read(imodPath);
if (Files.exists(imodPath)) meta = GC_ModMeta.deserialize(imodPath, GsonPreset.CONFIG);
else {
meta = ModMeta.of(jarPath);
GC_ModMeta.write(meta, imodPath);
GC_ModMeta.serialize(meta, imodPath, GsonPreset.CONFIG);
}
boolean modified = false;
if (meta.initialize(gameVersion)) {
GC_ModMeta.write(meta, imodPath);
GC_ModMeta.serialize(meta, imodPath, GsonPreset.CONFIG);
modified = true;
}
ModSource selectedSource = null;
@ -60,12 +60,12 @@ public record FileScanTask(ProtoInstance instance, Path file, BiConsumer<Path, M
jarPath = selectedSource.getJarPath();
managed = true;
} else if (!Files.exists(jarPath)) throw new IOException("Mod has no jar and no sources");
if (modified) meta = GC_ModMeta.read(imodPath);
if (modified) meta = GC_ModMeta.deserialize(imodPath, GsonPreset.CONFIG);
FabricModJson fmj;
try (FileSystem fs = Utils.openZipFile(jarPath, false)) {
Path fmjPath = fs.getPath("fabric.mod.json");
if (Files.exists(fmjPath)) fmj = GC_FabricModJson.read(fmjPath);
if (Files.exists(fmjPath)) fmj = GC_FabricModJson.deserialize(fmjPath, GsonPreset.API);
else fmj = null;
}

View File

@ -1,5 +1,6 @@
package io.gitlab.jfronny.inceptum.launcher.system.mds.threaded;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.launcher.model.fabric.FabricModJson;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_ModMeta;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.ModMeta;
@ -131,6 +132,6 @@ public class MdsMod extends Mod {
}
private void write() throws IOException {
GC_ModMeta.write(meta, imodPath);
GC_ModMeta.serialize(meta, imodPath, GsonPreset.CONFIG);
}
}

View File

@ -1,5 +1,6 @@
package io.gitlab.jfronny.inceptum.launcher.system.setup.steps;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.common.MetaHolder;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_InstanceMeta;
import io.gitlab.jfronny.inceptum.launcher.system.instance.Instance;
@ -15,7 +16,7 @@ public class RunMdsStep implements Step {
public void execute(SetupStepInfo info) throws IOException {
info.setState("Running MDS");
Path instance = MetaHolder.INSTANCE_DIR.resolve(info.name());
ModsDirScanner.get(instance.resolve("mods"), GC_InstanceMeta.read(instance.resolve(Instance.CONFIG_NAME)))
ModsDirScanner.get(instance.resolve("mods"), GC_InstanceMeta.deserialize(instance.resolve(Instance.CONFIG_NAME), GsonPreset.CONFIG))
.runOnce((path, iwModDescription) -> info.setState("Scanned " + path));
}

View File

@ -1,5 +1,6 @@
package io.gitlab.jfronny.inceptum.launcher.system.setup.steps;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.common.MetaHolder;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_InstanceMeta;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta;
@ -20,7 +21,7 @@ public class WriteMetadataStep implements Step {
if (!Files.exists(metaPath)) {
InstanceMeta meta = new InstanceMeta();
meta.gameVersion = info.version().id;
GC_InstanceMeta.write(meta, metaPath);
GC_InstanceMeta.serialize(meta, metaPath, GsonPreset.CONFIG);
}
if (!Files.exists(instance.resolve(".gitignore"))) {
Files.writeString(instance.resolve(".gitignore"), """

View File

@ -1,6 +1,6 @@
package io.gitlab.jfronny.inceptum.launcher.system.source;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
import io.gitlab.jfronny.inceptum.common.MetaHolder;
import io.gitlab.jfronny.inceptum.launcher.gson.ModSourceAdapter;
@ -10,7 +10,7 @@ import java.nio.file.Path;
import java.util.Optional;
import java.util.Set;
@GSerializable(with = ModSourceAdapter.class, configure = GsonPreset.Api.class)
@GSerializable(with = ModSourceAdapter.class)
public interface ModSource {
ModDownload download() throws IOException;

View File

@ -30,7 +30,7 @@ public final class ModrinthModSource implements ModSource {
@Override
public ModDownload download() throws IOException {
ModrinthVersion.File file = current.files().get(0);
ModrinthVersion.File file = current.files().getFirst();
Path path = getJarPath();
try {
Net.downloadFile(file.url(), file.hashes().sha1(), path);
@ -80,7 +80,7 @@ public final class ModrinthModSource implements ModSource {
@Override
public String getFileName() {
return current.files().get(0).filename();
return current.files().getFirst().filename();
}
@Override
@ -117,7 +117,7 @@ public final class ModrinthModSource implements ModSource {
}
public ModrinthModpackManifest.File toManifest() throws IOException {
ModrinthVersion.File orig = current.files().get(0);
ModrinthVersion.File orig = current.files().getFirst();
return new ModrinthModpackManifest.File(
"mods/" + orig.filename(),
new ModrinthHashes(

View File

@ -1,5 +1,7 @@
package io.gitlab.jfronny.inceptum.launcher.util;
import io.gitlab.jfronny.commons.serialize.json.JsonReader;
import io.gitlab.jfronny.commons.serialize.json.JsonTransport;
import io.gitlab.jfronny.commons.throwable.ThrowingFunction;
import java.io.Closeable;
@ -19,6 +21,14 @@ public class FileBackedRef<T> implements Closeable {
filePath.getParent().register(service, StandardWatchEventKinds.ENTRY_MODIFY);
}
public FileBackedRef(Path filePath, ThrowingFunction<JsonReader, T, IOException> read, JsonTransport transport) throws IOException {
this(filePath, path -> {
try (JsonReader reader = transport.createReader(Files.newBufferedReader(path))) {
return read.apply(reader);
}
});
}
public T get() throws IOException {
WatchKey key = service.poll();
boolean update = cache == null;

View File

@ -28,5 +28,6 @@ module io.gitlab.jfronny.inceptum.launcher {
requires transitive io.gitlab.jfronny.inceptum.common;
requires transitive io.gitlab.jfronny.commons.http.server;
requires static org.jetbrains.annotations;
requires static io.gitlab.jfronny.gson.compile.annotations;
requires static io.gitlab.jfronny.commons.serialize.generator.annotations;
requires io.gitlab.jfronny.commons.serialize;
}

View File

@ -26,7 +26,7 @@ public class Wrapper {
throw new FileNotFoundException("Something went wrong while downloading the latest version.");
}
}
List<Path> classpath = Updater.getLaunchClasspath(GC_WrapperConfig.read(MetaHolder.WRAPPER_CONFIG_PATH));
List<Path> classpath = Updater.getLaunchClasspath(GC_WrapperConfig.deserialize(MetaHolder.WRAPPER_CONFIG_PATH, GsonPreset.CONFIG));
if (!BuildMetadata.IS_RELEASE) {
System.out.println("Using classpath: " + classpath.stream().map(Path::toString).collect(Collectors.joining("" + File.pathSeparator)));
}