From 441a9b26b230a962f0940af656d79af48227e7a9 Mon Sep 17 00:00:00 2001 From: JFronny Date: Fri, 5 May 2023 18:49:56 +0200 Subject: [PATCH] Remove manifold and add JPMS in every project except wrapper, launchwrapper and launcher-gtk --- build.gradle.kts | 2 - .../main/kotlin/inceptum.manifold.gradle.kts | 2 + common/build.gradle.kts | 1 - .../jfronny/inceptum/common/GsonPreset.java | 24 ++-- .../inceptum/common/InceptumConfig.java | 6 +- .../InceptumEnvironmentInitializer.java | 2 +- .../gitlab/jfronny/inceptum/common/Net.java | 10 +- .../jfronny/inceptum/common/ObjectCache.java | 6 +- .../jfronny/inceptum/common/Updater.java | 63 +++++----- .../gitlab/jfronny/inceptum/common/Utils.java | 17 +-- .../jfronny/inceptum/common/api/MavenApi.java | 108 +++++++++++------- common/src/main/java/module-info.java | 15 +++ launcher-cli/build.gradle.kts | 1 - .../inceptum/cli/BaseInstanceCommand.java | 8 +- .../gitlab/jfronny/inceptum/cli/CliMain.java | 2 +- .../gitlab/jfronny/inceptum/cli/Command.java | 12 +- .../jfronny/inceptum/cli/CommandArgs.java | 4 +- .../jfronny/inceptum/cli/HelpBuilder.java | 6 +- .../inceptum/cli/commands/ExportCommand.java | 10 +- .../inceptum/cli/commands/HelpCommand.java | 8 +- .../inceptum/cli/commands/ImportCommand.java | 2 +- .../cli/commands/JvmStateCommand.java | 2 +- .../inceptum/cli/commands/LaunchCommand.java | 12 +- .../inceptum/cli/commands/ListCommand.java | 18 +-- .../inceptum/cli/commands/ModCommand.java | 46 ++++---- launcher-cli/src/main/java/module-info.java | 6 + launcher-dist/build.gradle.kts | 19 ++- launcher-dist/src/main/java/module-info.java | 4 + launcher-imgui/build.gradle.kts | 1 - .../jfronny/inceptum/imgui/GuiMain.java | 20 ++-- .../imgui/control/InstanceManageControls.java | 32 +++--- .../inceptum/imgui/control/InstanceView.java | 10 +- .../jfronny/inceptum/imgui/control/Tab.java | 2 +- .../inceptum/imgui/window/AddModWindow.java | 58 +++++----- .../inceptum/imgui/window/GuiUtil.java | 6 +- .../inceptum/imgui/window/MainWindow.java | 6 +- .../imgui/window/NewInstanceWindow.java | 6 +- .../dialog/ProcessStateWatcherWindow.java | 4 +- .../imgui/window/edit/ArgumentsTab.java | 16 +-- .../inceptum/imgui/window/edit/ExportTab.java | 14 +-- .../imgui/window/edit/GeneralTab.java | 18 +-- .../imgui/window/edit/InstanceEditWindow.java | 10 +- .../inceptum/imgui/window/edit/ModsTab.java | 58 +++++----- launcher-imgui/src/main/java/module-info.java | 12 ++ launcher/build.gradle.kts | 5 +- .../inceptum/launcher/api/CurseforgeApi.java | 24 ++-- .../inceptum/launcher/api/FabricMetaApi.java | 20 ++-- .../jfronny/inceptum/launcher/api/McApi.java | 24 ++-- .../inceptum/launcher/api/ModrinthApi.java | 8 +- .../launcher/api/account/AccountManager.java | 6 +- .../api/account/MicrosoftAccount.java | 56 ++++----- .../api/account/MicrosoftAuthAPI.java | 16 +-- .../api/account/MicrosoftAuthServer.java | 39 ++++--- .../gson/MicrosoftAccountAdapter.java | 2 +- .../gson/MinecraftArgumentAdapter.java | 2 +- .../launcher/gson/ModMetaSourcesAdapter.java | 2 +- .../launcher/gson/ModSourceAdapter.java | 16 +-- .../inceptum/launcher/gson/RulesAdapter.java | 2 +- .../launcher/model/inceptum/ModMeta.java | 12 +- .../response/OauthTokenResponse.java | 2 +- .../system/exporter/CleanupFileVisitor.java | 4 +- .../system/exporter/CurseForgeExporter.java | 20 ++-- .../launcher/system/exporter/Exporter.java | 19 +-- .../system/exporter/ModrinthExporter.java | 16 +-- .../system/exporter/MultiMCExporter.java | 14 +-- .../system/importer/CurseForgeImporter.java | 36 +++--- .../launcher/system/importer/Importer.java | 22 ++-- .../launcher/system/importer/Importers.java | 2 +- .../system/importer/ModrinthImporter.java | 34 +++--- .../system/importer/MultiMCImporter.java | 12 +- .../launcher/system/instance/Instance.java | 14 +-- .../system/instance/InstanceList.java | 14 +-- .../system/instance/InstanceListWatcher.java | 2 +- .../launcher/system/instance/LoaderInfo.java | 2 +- .../launcher/system/instance/ModManager.java | 18 +-- .../launcher/system/instance/ModPath.java | 12 +- .../system/launch/InstanceLauncher.java | 74 ++++++------ .../launcher/system/mds/FileScanTask.java | 12 +- .../inceptum/launcher/system/mds/MdsMod.java | 46 ++++---- .../system/mds/ModsDirScannerImpl.java | 40 +++---- .../system/mds/NamedThreadFactory.java | 6 +- .../launcher/system/mds/noop/NoopMod.java | 2 +- .../launcher/system/setup/SetupStepInfo.java | 2 +- .../inceptum/launcher/system/setup/Steps.java | 22 ++-- .../setup/steps/DownloadAssetsStep.java | 12 +- .../setup/steps/DownloadClientStep.java | 6 +- .../system/setup/steps/DownloadJavaStep.java | 14 +-- .../setup/steps/DownloadLibrariesStep.java | 24 ++-- .../system/setup/steps/RunMdsStep.java | 4 +- .../system/setup/steps/SetupDirsStep.java | 6 +- .../system/setup/steps/WriteMetadataStep.java | 6 +- .../system/source/CurseforgeModSource.java | 30 ++--- .../system/source/DirectModSource.java | 2 +- .../launcher/system/source/ModSource.java | 2 +- .../system/source/ModrinthModSource.java | 54 ++++----- .../inceptum/launcher/util/ProcessUtils.java | 2 +- .../util/VersionInfoLibraryResolver.java | 12 +- launcher/src/main/java/module-info.java | 32 ++++++ .../jfronny/inceptum/wrapper/Wrapper.java | 2 +- 99 files changed, 840 insertions(+), 738 deletions(-) create mode 100644 common/src/main/java/module-info.java create mode 100644 launcher-cli/src/main/java/module-info.java create mode 100644 launcher-dist/src/main/java/module-info.java create mode 100644 launcher-imgui/src/main/java/module-info.java create mode 100644 launcher/src/main/java/module-info.java diff --git a/build.gradle.kts b/build.gradle.kts index f1a0d49..15d8457 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,8 +13,6 @@ allprojects { val jfCommonsVersion by extra("1.3-SNAPSHOT") val gsonCompileVersion by extra("1.3-SNAPSHOT") val jbAnnotationsVersion by extra("24.0.1") -// launcher -val jlhttpVersion by extra("2.6") // launcher-imgui val lwjglVersion by extra("3.3.2") val imguiVersion by extra("1.86.10") diff --git a/buildSrc/src/main/kotlin/inceptum.manifold.gradle.kts b/buildSrc/src/main/kotlin/inceptum.manifold.gradle.kts index 6846553..4720634 100644 --- a/buildSrc/src/main/kotlin/inceptum.manifold.gradle.kts +++ b/buildSrc/src/main/kotlin/inceptum.manifold.gradle.kts @@ -3,6 +3,8 @@ plugins { id("jf.manifold") } +project.extra["manifoldVersion"] = "2023.1.7" + dependencies { val jfCommonsVersion: String by rootProject.extra diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 0e38c0a..cb2e0d0 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -5,7 +5,6 @@ plugins { id("inceptum.library") id("jf.codegen") id("inceptum.gson-compile") - id("inceptum.manifold") } dependencies { diff --git a/common/src/main/java/io/gitlab/jfronny/inceptum/common/GsonPreset.java b/common/src/main/java/io/gitlab/jfronny/inceptum/common/GsonPreset.java index 1560dbf..087ca64 100644 --- a/common/src/main/java/io/gitlab/jfronny/inceptum/common/GsonPreset.java +++ b/common/src/main/java/io/gitlab/jfronny/inceptum/common/GsonPreset.java @@ -6,29 +6,29 @@ import io.gitlab.jfronny.gson.stream.JsonWriter; public class GsonPreset { public static class Config { public static void configure(JsonReader reader) { - reader.isSerializeSpecialFloatingPointValues = true; - reader.isLenient = true; + reader.setSerializeSpecialFloatingPointValues(true); + reader.setLenient(true); } public static void configure(JsonWriter writer) { - writer.serializeNulls = true; - writer.isSerializeSpecialFloatingPointValues = true; - writer.isLenient = true; - writer.indent = " "; - writer.omitQuotes = true; + writer.setSerializeNulls(true); + writer.setSerializeSpecialFloatingPointValues(true); + writer.setLenient(true); + writer.setIndent(" "); + writer.setOmitQuotes(true); } } public static class Api { public static void configure(JsonReader reader) { - reader.isSerializeSpecialFloatingPointValues = true; - reader.isLenient = true; + reader.setSerializeSpecialFloatingPointValues(true); + reader.setLenient(true); } public static void configure(JsonWriter writer) { - writer.serializeNulls = false; - writer.isSerializeSpecialFloatingPointValues = true; - writer.isLenient = false; + writer.setSerializeNulls(false); + writer.setSerializeSpecialFloatingPointValues(true); + writer.setLenient(false); } } } diff --git a/common/src/main/java/io/gitlab/jfronny/inceptum/common/InceptumConfig.java b/common/src/main/java/io/gitlab/jfronny/inceptum/common/InceptumConfig.java index e46fa4b..98d7aeb 100644 --- a/common/src/main/java/io/gitlab/jfronny/inceptum/common/InceptumConfig.java +++ b/common/src/main/java/io/gitlab/jfronny/inceptum/common/InceptumConfig.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.common; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.common.InceptumConfig.GC_InceptumConfig; +import io.gitlab.jfronny.inceptum.common.GC_InceptumConfig; import io.gitlab.jfronny.gson.compile.annotations.GComment; import io.gitlab.jfronny.gson.compile.annotations.GSerializable; import io.gitlab.jfronny.inceptum.common.model.inceptum.UpdateChannel; @@ -29,8 +29,8 @@ public class InceptumConfig { public static String authorName = "Inceptum"; public static void load() throws IOException { - if (!Files.exists(MetaHolder.CONFIG_PATH.parent)) - Files.createDirectories(MetaHolder.CONFIG_PATH.parent); + if (!Files.exists(MetaHolder.CONFIG_PATH.getParent())) + Files.createDirectories(MetaHolder.CONFIG_PATH.getParent()); if (!Files.exists(MetaHolder.CONFIG_PATH)) { Path gLaunch2 = MetaHolder.BASE_PATH.resolve("glaunch2.json"); Path json = MetaHolder.BASE_PATH.resolve("inceptum.json"); diff --git a/common/src/main/java/io/gitlab/jfronny/inceptum/common/InceptumEnvironmentInitializer.java b/common/src/main/java/io/gitlab/jfronny/inceptum/common/InceptumEnvironmentInitializer.java index 56dc196..9a03f3c 100644 --- a/common/src/main/java/io/gitlab/jfronny/inceptum/common/InceptumEnvironmentInitializer.java +++ b/common/src/main/java/io/gitlab/jfronny/inceptum/common/InceptumEnvironmentInitializer.java @@ -9,7 +9,7 @@ import java.io.IOException; public class InceptumEnvironmentInitializer { public static void initialize() throws IOException { Logger.registerFactory(InceptumEnvironmentInitializer::defaultFactory); - HttpUtils.userAgent = "jfmods/inceptum/" + BuildMetadata.VERSION; + HttpUtils.setUserAgent("jfmods/inceptum/" + BuildMetadata.VERSION); InceptumConfig.load(); } diff --git a/common/src/main/java/io/gitlab/jfronny/inceptum/common/Net.java b/common/src/main/java/io/gitlab/jfronny/inceptum/common/Net.java index fa566e3..d5e3272 100644 --- a/common/src/main/java/io/gitlab/jfronny/inceptum/common/Net.java +++ b/common/src/main/java/io/gitlab/jfronny/inceptum/common/Net.java @@ -65,11 +65,11 @@ public class Net { if (url.startsWith("/")) res.append(url); else res.append("/").append(url); int i = 0; - for (Map.Entry entry : params) { + for (Map.Entry entry : params.entrySet()) { res.append(i++ == 0 ? '?' : '&') - .append(URLEncoder.encode(entry.key, StandardCharsets.UTF_8)) + .append(URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8)) .append('=') - .append(URLEncoder.encode(entry.value, StandardCharsets.UTF_8)); + .append(URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8)); } return res.toString(); } @@ -83,12 +83,12 @@ public class Net { } public static void downloadFile(String url, Path path) throws IOException, URISyntaxException { - if (!Files.exists(path.parent)) Files.createDirectories(path.parent); + if (!Files.exists(path.getParent())) Files.createDirectories(path.getParent()); Files.write(path, downloadData(url)); } public static void downloadFile(String url, String sha1, Path path) throws IOException, URISyntaxException { - if (!Files.exists(path.parent)) Files.createDirectories(path.parent); + if (!Files.exists(path.getParent())) Files.createDirectories(path.getParent()); Files.write(path, downloadData(url, sha1)); } } diff --git a/common/src/main/java/io/gitlab/jfronny/inceptum/common/ObjectCache.java b/common/src/main/java/io/gitlab/jfronny/inceptum/common/ObjectCache.java index 3b1da9c..0b647c5 100644 --- a/common/src/main/java/io/gitlab/jfronny/inceptum/common/ObjectCache.java +++ b/common/src/main/java/io/gitlab/jfronny/inceptum/common/ObjectCache.java @@ -30,10 +30,10 @@ public class ObjectCache { public T get(String key, ThrowingSupplier download, ThrowingFunction builder) throws IOException, TEx { if (!container.containsKey(key)) { Path cd = cacheDir.resolve(key); - if (Files.exists(cd)) container[key] = builder.apply(Files.readString(cd)); - else container[key] = builder.apply(download.get()); + if (Files.exists(cd)) container.put(key, builder.apply(Files.readString(cd))); + else container.put(key, builder.apply(download.get())); } //noinspection unchecked - return (T) container[key]; + return (T) container.get(key); } } diff --git a/common/src/main/java/io/gitlab/jfronny/inceptum/common/Updater.java b/common/src/main/java/io/gitlab/jfronny/inceptum/common/Updater.java index 2c82e76..34ed7f8 100644 --- a/common/src/main/java/io/gitlab/jfronny/inceptum/common/Updater.java +++ b/common/src/main/java/io/gitlab/jfronny/inceptum/common/Updater.java @@ -1,7 +1,7 @@ package io.gitlab.jfronny.inceptum.common; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.common.model.inceptum.UpdateMetadata.GC_UpdateMetadata; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.common.model.inceptum.WrapperConfig.GC_WrapperConfig; +import io.gitlab.jfronny.inceptum.common.model.inceptum.GC_UpdateMetadata; +import io.gitlab.jfronny.inceptum.common.model.inceptum.GC_WrapperConfig; import io.gitlab.jfronny.commons.OSUtils; import io.gitlab.jfronny.inceptum.common.api.MavenApi; import io.gitlab.jfronny.inceptum.common.model.inceptum.*; @@ -16,6 +16,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.*; import java.util.function.Consumer; +import java.util.stream.Collectors; import java.util.stream.Stream; public class Updater { @@ -32,38 +33,38 @@ public class Updater { } public static void update(UpdateMetadata source, boolean relaunch) throws IOException, URISyntaxException { - Utils.LOGGER.info("Downloading version " + source.version); + Utils.LOGGER.info("Downloading version " + source.version()); WrapperConfig config = new WrapperConfig( new LinkedHashSet<>(), - new LinkedHashSet<>(source.repositories), + new LinkedHashSet<>(source.repositories()), new HashMap<>() ); - source.natives.forEach((k, v) -> config.natives[k] = new LinkedHashSet<>(v)); + source.natives().forEach((k, v) -> config.natives().put(k, new LinkedHashSet<>(v))); - DependencyNode node = downloadLibrary(source.repositories, "io.gitlab.jfronny.inceptum:launcher-dist:" + source.version, config.libraries); + DependencyNode node = downloadLibrary(source.repositories(), "io.gitlab.jfronny.inceptum:launcher-dist:" + source.version(), config.libraries()); Utils.LOGGER.info("Downloaded Dependencies:\n" + node); - List currentLibraries = new LinkedList<>(config.libraries); - if (source.natives.containsKey(Utils.currentFlavor)) { + List currentLibraries = new LinkedList<>(config.libraries()); + if (source.natives().containsKey(Utils.getCurrentFlavor())) { Set natives = new LinkedHashSet<>(); - for (String lib : source.natives[Utils.currentFlavor]) { - downloadLibrary(source.repositories, lib, natives); + for (String lib : source.natives().get(Utils.getCurrentFlavor())) { + downloadLibrary(source.repositories(), lib, natives); } currentLibraries.addAll(natives); - config.natives[Utils.currentFlavor] = natives; + config.natives().put(Utils.getCurrentFlavor(), natives); } GC_WrapperConfig.write(config, MetaHolder.WRAPPER_CONFIG_PATH); if (relaunch) { - Runtime.runtime.addShutdownHook(new Thread(() -> { + Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { - new ProcessBuilder(OSUtils.jvmBinary, + new ProcessBuilder(OSUtils.getJvmBinary(), "-cp", buildClasspath(currentLibraries.stream()) .map(Path::toString) - .join(File.pathSeparatorChar) + .collect(Collectors.joining(String.valueOf(File.pathSeparatorChar))) ).inheritIO().start(); } catch (IOException e) { Utils.LOGGER.error("Could not relaunch", e); @@ -73,31 +74,31 @@ public class Updater { } public static List getLaunchClasspath(WrapperConfig wrapperConfig) throws IOException, URISyntaxException { - Set natives = wrapperConfig.natives[Utils.currentFlavor]; + Set natives = wrapperConfig.natives().get(Utils.getCurrentFlavor()); if (natives == null) natives = new LinkedHashSet<>(); - Set libs = wrapperConfig.libraries; + Set libs = wrapperConfig.libraries(); if (libs == null) libs = new LinkedHashSet<>(); boolean configChanged = false; for (String lib : libs) { - Path p = ArtifactMeta.parse(lib).localPath; + Path p = ArtifactMeta.parse(lib).getLocalPath(); if (!Files.exists(p)) { configChanged = true; - downloadLibrary(wrapperConfig.repositories, lib, libs); + downloadLibrary(wrapperConfig.repositories(), lib, libs); } } for (String lib : natives) { - Path p = ArtifactMeta.parse(lib).localPath; + Path p = ArtifactMeta.parse(lib).getLocalPath(); if (!Files.exists(p)) { configChanged = true; - downloadLibrary(wrapperConfig.repositories, lib, natives); + downloadLibrary(wrapperConfig.repositories(), lib, natives); } } if (configChanged) GC_WrapperConfig.write(wrapperConfig, MetaHolder.WRAPPER_CONFIG_PATH); - return buildClasspath(libs.stream().concat(natives.stream())).toList(); + return buildClasspath(Stream.concat(libs.stream(), natives.stream())).toList(); } private static Stream buildClasspath(Stream libraries) { @@ -106,7 +107,7 @@ public class Updater { private static DependencyNode downloadLibrary(Set repositories, final String artifact, Set libraries) throws IOException, URISyntaxException { List suppressed = new LinkedList<>(); - for (String repository : Stream.of(PROJECT_MAVEN).concat(repositories.stream())) { + for (String repository : Stream.concat(Stream.of(PROJECT_MAVEN), repositories.stream()).toList()) { ArtifactMeta meta; try { meta = MavenApi.getMetadata(repository, artifact); @@ -122,12 +123,12 @@ public class Updater { suppressed.add(notFound); continue; } catch (IOException | URISyntaxException | XMLStreamException | SAXException e) { - throw new IOException("Could not download artifact " + meta.mavenNotation + " from " + repository, e); + throw new IOException("Could not download artifact " + meta.getMavenNotation() + " from " + repository, e); } Set dependencies = new LinkedHashSet<>(); - if (pom.dependencies != null) { - for (MavenDependency dependency : pom.dependencies) { - String mvnName = dependency.groupId + ":" + dependency.artifactId + ":" + dependency.version; + if (pom.dependencies() != null) { + for (MavenDependency dependency : pom.dependencies()) { + String mvnName = dependency.groupId() + ":" + dependency.artifactId() + ":" + dependency.version(); dependencies.add(downloadLibrary(repositories, mvnName, libraries)); } } @@ -156,12 +157,12 @@ public class Updater { case Stable -> stable; }; if (checkEnv) { - if (info.jvm > Runtime.version().feature()) throw new UpdateCheckException("A newer JVM is required to use the latest inceptum version. Please update!", "Outdated Java"); - if (info.wrapperVersion != BuildMetadata.WRAPPER_VERSION) throw new UpdateCheckException("A different version of the Inceptum Wrapper is required for this update!", "Mismatched Wrapper"); + if (info.jvm() > Runtime.version().feature()) throw new UpdateCheckException("A newer JVM is required to use the latest inceptum version. Please update!", "Outdated Java"); + if (info.wrapperVersion() != BuildMetadata.WRAPPER_VERSION) throw new UpdateCheckException("A different version of the Inceptum Wrapper is required for this update!", "Mismatched Wrapper"); } if (versionCompare) { - Utils.LOGGER.info("Latest version is " + info.version + ", current is " + BuildMetadata.VERSION); - if (BuildMetadata.BUILD_TIME >= info.buildTime) { + Utils.LOGGER.info("Latest version is " + info.version() + ", current is " + BuildMetadata.VERSION); + if (BuildMetadata.BUILD_TIME >= info.buildTime()) { Utils.LOGGER.info("Up-to-date"); return null; } @@ -177,7 +178,7 @@ public class Updater { return switch (channel) { case CI -> ARTIFACTS_URL; case Stable -> STABLE_URL; - } + "/Inceptum-" + Utils.currentFlavor + ".jar"; + } + "/Inceptum-" + Utils.getCurrentFlavor() + ".jar"; } public static class UpdateCheckException extends Exception { diff --git a/common/src/main/java/io/gitlab/jfronny/inceptum/common/Utils.java b/common/src/main/java/io/gitlab/jfronny/inceptum/common/Utils.java index ae9fb46..0d14315 100644 --- a/common/src/main/java/io/gitlab/jfronny/inceptum/common/Utils.java +++ b/common/src/main/java/io/gitlab/jfronny/inceptum/common/Utils.java @@ -13,6 +13,7 @@ import java.nio.file.FileSystem; import java.nio.file.Path; import java.util.Arrays; import java.util.regex.Pattern; +import java.util.stream.Collectors; public class Utils { public static final int CACHE_SIZE = 128; @@ -24,9 +25,9 @@ public class Utils { public static void openWebBrowser(URI uri) { try { if (OSUtils.TYPE == OSUtils.Type.LINUX && OSUtils.executablePathContains("xdg-open")) { - Runtime.runtime.exec(new String[]{"xdg-open", uri.toString()}); - } else if (Desktop.isDesktopSupported && Desktop.desktop.isSupported(Desktop.Action.BROWSE)) { - Desktop.desktop.browse(uri); + Runtime.getRuntime().exec(new String[]{"xdg-open", uri.toString()}); + } else if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { + Desktop.getDesktop().browse(uri); } } catch (Exception e) { Utils.LOGGER.error("Error opening web browser!", e); @@ -36,9 +37,9 @@ public class Utils { public static void openFile(File file) { try { if (OSUtils.TYPE == OSUtils.Type.LINUX && OSUtils.executablePathContains("xdg-open")) { - Runtime.runtime.exec(new String[]{"xdg-open", file.absoluteFile.toString()}); - } else if (Desktop.isDesktopSupported && Desktop.desktop.isSupported(Desktop.Action.BROWSE)) { - Desktop.desktop.open(file); + Runtime.getRuntime().exec(new String[]{"xdg-open", file.getAbsoluteFile().toString()}); + } else if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { + Desktop.getDesktop().open(file); } } catch (Exception e) { Utils.LOGGER.error("Error opening file!", e); @@ -67,8 +68,8 @@ public class Utils { return Arrays.stream(segments) .map(s -> s.startsWith(separator) ? s.substring(separator.length()) : s) .map(s -> s.endsWith(separator) ? s.substring(0, s.length() - separator.length()) : s) - .filter(s -> !s.isEmpty) - .join(separator); + .filter(s -> !s.isEmpty()) + .collect(Collectors.joining(separator)); } public static String getCurrentFlavor() { diff --git a/common/src/main/java/io/gitlab/jfronny/inceptum/common/api/MavenApi.java b/common/src/main/java/io/gitlab/jfronny/inceptum/common/api/MavenApi.java index 0964c23..9ba6f8b 100644 --- a/common/src/main/java/io/gitlab/jfronny/inceptum/common/api/MavenApi.java +++ b/common/src/main/java/io/gitlab/jfronny/inceptum/common/api/MavenApi.java @@ -5,8 +5,7 @@ import io.gitlab.jfronny.inceptum.common.Net; import io.gitlab.jfronny.inceptum.common.Utils; import io.gitlab.jfronny.inceptum.common.model.maven.*; import org.jetbrains.annotations.Nullable; -import org.w3c.dom.Document; -import org.w3c.dom.Node; +import org.w3c.dom.*; import org.xml.sax.SAXException; import javax.xml.parsers.*; @@ -30,16 +29,16 @@ public class MavenApi { } public static Path downloadLibrary(String repo, ArtifactMeta meta) throws IOException, URISyntaxException { - Path res = meta.localPath; + Path res = meta.getLocalPath(); Net.downloadFile(Utils.join("/", repo, meta.getJarPath(true)), res); return res; } public static Pom getPom(String repo, ArtifactMeta meta) throws IOException, SAXException, URISyntaxException, XMLStreamException { - try (InputStream is = HttpUtils.get(Utils.join("/", repo, meta.pomPath)).sendInputStream()) { + try (InputStream is = HttpUtils.get(Utils.join("/", repo, meta.getPomPath())).sendInputStream()) { Document doc = FACTORY.parse(is); - doc.documentElement.normalize(); - if (!"project".equals(doc.documentElement.nodeName)) throw new IOException("Illegal document name"); + doc.getDocumentElement().normalize(); + if (!"project".equals(doc.getDocumentElement().getNodeName())) throw new IOException("Illegal document name"); String modelVersion = null; String groupId = null; String artifactId = null; @@ -47,46 +46,46 @@ public class MavenApi { String packaging = null; List dependencies = null; String classifier = null; - for (Node node : doc.documentElement.childNodes) { - switch (node.nodeName) { - case "modelVersion" -> modelVersion = node.textContent; + for (Node node : children(doc.getDocumentElement())) { + switch (node.getNodeName()) { + case "modelVersion" -> modelVersion = node.getTextContent(); case "parent" -> { // Dirty hack to get slf4j working: simply assume the groupId and version of the parent is also the groupId of this if (groupId == null) { - for (Node child : node.childNodes) { - switch (child.nodeName) { + for (Node child : children(node)) { + switch (child.getNodeName()) { case "groupId" -> { if (groupId == null) { - groupId = child.textContent; + groupId = child.getTextContent(); } } case "version" -> { if (version == null) { - version = child.textContent; + version = child.getTextContent(); } } } } } } - case "groupId" -> groupId = node.textContent; + case "groupId" -> groupId = node.getTextContent(); case "artifactId" -> { - artifactId = node.textContent; + artifactId = node.getTextContent(); } case "version" -> { - version = node.textContent; + version = node.getTextContent(); } - case "packaging" -> packaging = node.textContent; + case "packaging" -> packaging = node.getTextContent(); case "dependencies" -> { dependencies = new LinkedList<>(); - for (Node dep : node.childNodes) { + for (Node dep : children(node)) { MavenDependency resolved = parseDependency(dep); if (resolved != null) { dependencies.add(resolved); } } } - case "classifier" -> classifier = node.textContent; + case "classifier" -> classifier = node.getTextContent(); default -> {} } } @@ -103,17 +102,17 @@ public class MavenApi { String artifactId = null; String version = null; String scope = null; - for (Node node : doc.childNodes) { - switch (node.nodeName) { - case "groupId" -> groupId = node.textContent; - case "artifactId" -> artifactId = node.textContent; - case "version" -> version = node.textContent; + for (Node node : children(doc)) { + switch (node.getNodeName()) { + case "groupId" -> groupId = node.getTextContent(); + case "artifactId" -> artifactId = node.getTextContent(); + case "version" -> version = node.getTextContent(); case "scope" -> { - scope = node.textContent; + scope = node.getTextContent(); if (!RUNTIME_SCOPES.contains(scope)) return null; } case "optional" -> { - if (node.textContent.equals("true")) return null; + if (node.getTextContent().equals("true")) return null; } } } @@ -133,28 +132,28 @@ public class MavenApi { public static ArtifactMeta getMetadata(String repo, String artifact) throws IOException, SAXException, URISyntaxException { ArtifactMeta sourceMeta = ArtifactMeta.parse(artifact); - try (InputStream is = HttpUtils.get(Utils.join("/", repo, sourceMeta.metadataPath)).sendInputStream()) { + try (InputStream is = HttpUtils.get(Utils.join("/", repo, sourceMeta.getMetadataPath())).sendInputStream()) { Document doc = FACTORY.parse(is); - doc.documentElement.normalize(); - if (!"metadata".equals(doc.documentElement.nodeName)) throw new IOException("Illegal document name"); + doc.getDocumentElement().normalize(); + if (!"metadata".equals(doc.getDocumentElement().getNodeName())) throw new IOException("Illegal document name"); String groupId = null; String artifactId = null; String version = null; String snapshotVersion = null; - for (Node node : doc.documentElement.childNodes) { - switch (node.nodeName) { - case "groupId" -> groupId = node.textContent; - case "artifactId" -> artifactId = node.textContent; - case "version" -> version = node.textContent; + for (Node node : children(doc.getDocumentElement())) { + switch (node.getNodeName()) { + case "groupId" -> groupId = node.getTextContent(); + case "artifactId" -> artifactId = node.getTextContent(); + case "version" -> version = node.getTextContent(); case "versioning" -> { - for (Node node1 : node.childNodes) { - if (node1.nodeName.equals("snapshot")) { + for (Node node1 : children(node)) { + if (node1.getNodeName().equals("snapshot")) { String timestamp = null; String buildNumber = null; - for (Node node2 : node1.childNodes) { - switch (node2.nodeName) { - case "timestamp" -> timestamp = node2.textContent; - case "buildNumber" -> buildNumber = node2.textContent; + for (Node node2 : children(node1)) { + switch (node2.getNodeName()) { + case "timestamp" -> timestamp = node2.getTextContent(); + case "buildNumber" -> buildNumber = node2.getTextContent(); default -> {} } } @@ -170,7 +169,34 @@ public class MavenApi { if (groupId == null) throw new IOException("Pom lacks groupId"); if (artifactId == null) throw new IOException("Pom lacks artifactId"); if (version == null) throw new IOException("Pom lacks version"); - return new ArtifactMeta(groupId, artifactId, version, sourceMeta.classifier, snapshotVersion); + return new ArtifactMeta(groupId, artifactId, version, sourceMeta.classifier(), snapshotVersion); } } + + private static Iterable children(Node node) { + return () -> new Iterator() { + NodeList children = node.getChildNodes(); + int index = 0; + + @Override + public boolean hasNext() { + while (index < children.getLength() && isWhitespace(children.item(index))) { + index++; + } + return index < children.getLength(); + } + + @Override + public Node next() { + if (!hasNext()) throw new NoSuchElementException(); + return children.item(index++); + } + }; + } + + private static boolean isWhitespace(Node node) { + if (node.getNodeType() == Node.TEXT_NODE && node.getTextContent().isBlank()) return true; + if (node.getNodeType() == Node.COMMENT_NODE) return true; + return false; + } } diff --git a/common/src/main/java/module-info.java b/common/src/main/java/module-info.java new file mode 100644 index 0000000..66ee0f5 --- /dev/null +++ b/common/src/main/java/module-info.java @@ -0,0 +1,15 @@ +module io.gitlab.jfronny.inceptum.common { + exports io.gitlab.jfronny.inceptum.common; + exports io.gitlab.jfronny.inceptum.common.api; + exports io.gitlab.jfronny.inceptum.common.model.inceptum; + exports io.gitlab.jfronny.inceptum.common.model.maven; + + 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.gson; + requires transitive io.gitlab.jfronny.gson.compile.core; + requires static org.jetbrains.annotations; + requires static io.gitlab.jfronny.gson.compile.annotations; +} \ No newline at end of file diff --git a/launcher-cli/build.gradle.kts b/launcher-cli/build.gradle.kts index cc57ee7..c099d75 100644 --- a/launcher-cli/build.gradle.kts +++ b/launcher-cli/build.gradle.kts @@ -1,6 +1,5 @@ plugins { id("inceptum.application") - id("inceptum.manifold") } application { diff --git a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/BaseInstanceCommand.java b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/BaseInstanceCommand.java index cb9ac63..69aa700 100644 --- a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/BaseInstanceCommand.java +++ b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/BaseInstanceCommand.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.cli; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta.GC_InstanceMeta; +import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_InstanceMeta; import io.gitlab.jfronny.inceptum.common.MetaHolder; import io.gitlab.jfronny.inceptum.common.Utils; import io.gitlab.jfronny.inceptum.launcher.system.instance.Instance; @@ -34,17 +34,17 @@ public abstract class BaseInstanceCommand extends Command { return; } Instance instance; - Path normalPath = Path.of(args[0]); + 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))); } else { - Path instancePath = MetaHolder.INSTANCE_DIR.resolve(args[0]).normalize(); + Path instancePath = MetaHolder.INSTANCE_DIR.resolve(args.get(0)).normalize(); if (!instancePath.startsWith(MetaHolder.INSTANCE_DIR)) { Utils.LOGGER.error("Specified instance path doesn't exist"); return; } if (!Files.exists(instancePath)) { - Utils.LOGGER.error("Invalid instance: \"" + args[0] + "\""); + Utils.LOGGER.error("Invalid instance: \"" + args.get(0) + "\""); return; } try { diff --git a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/CliMain.java b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/CliMain.java index 2b97cd3..e6ab904 100644 --- a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/CliMain.java +++ b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/CliMain.java @@ -22,7 +22,7 @@ public class CliMain { public static final Command COMMANDS_ROOT = new Command("Root command", "", List.of(), KNOWN_COMMANDS) { @Override protected void invoke(CommandArgs args) { - throw new RuntimeException("Could not find command: " + args[0]); + throw new RuntimeException("Could not find command: " + args.get(0)); } @Override diff --git a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/Command.java b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/Command.java index bc9e8b0..0a0d9a6 100644 --- a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/Command.java +++ b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/Command.java @@ -24,7 +24,7 @@ public abstract class Command { } public String getName() { - return aliases[0]; + return aliases.get(0); } public boolean enableLog() { @@ -36,22 +36,22 @@ public abstract class Command { public CommandResolution resolve(CommandArgs args) { if (args.length != 0) { for (Command command : subCommands) { - if (command.isAlias(args[0])) { + if (command.isAlias(args.get(0))) { CommandResolution resolution = command.resolve(args.subArgs()); - if (!aliases.isEmpty) resolution.resolvePath.add(0, aliases[0]); + if (!aliases.isEmpty()) resolution.resolvePath().add(0, aliases.get(0)); return resolution; } } } - return new CommandResolution(this, args, aliases.isEmpty + return new CommandResolution(this, args, aliases.isEmpty() ? new ArrayList<>() - : new ArrayList<>(List.of(aliases[0]))); + : new ArrayList<>(List.of(aliases.get(0)))); } public void buildHelp(HelpBuilder builder) { builder.writeCommand(aliases, help, usage); for (Command command : subCommands) { - command.buildHelp(aliases.isEmpty ? builder : builder.beginSubcommand(aliases[0])); + command.buildHelp(aliases.isEmpty() ? builder : builder.beginSubcommand(aliases.get(0))); } } } diff --git a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/CommandArgs.java b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/CommandArgs.java index a9a1ad1..e600262 100644 --- a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/CommandArgs.java +++ b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/CommandArgs.java @@ -16,11 +16,11 @@ public class CommandArgs implements Iterable { } public String last() { - return args[args.size() - 1]; + return args.get(args.size() - 1); } public String get(int index) { - return args[index]; + return args.get(index); } public List after(String param) { diff --git a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/HelpBuilder.java b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/HelpBuilder.java index 99ffadf..0a820c4 100644 --- a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/HelpBuilder.java +++ b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/HelpBuilder.java @@ -31,11 +31,11 @@ public class HelpBuilder { } public void writeCommand(List aliases, String help, String usage) { - if (aliases.isEmpty) return; + if (aliases.isEmpty()) return; String indent = " ".repeat(level * 2); builder.append('\n').append(indent).append("- "); for (int i = 0, aliasesSize = aliases.size(); i < aliasesSize; i++) { - String alias = aliases[i]; + String alias = aliases.get(i); builder.append(alias); if (i < aliasesSize - 1) builder.append(", "); @@ -46,7 +46,7 @@ public class HelpBuilder { for (String s : upper) { usagePrefix.append(" ").append(s); } - usagePrefix.append(" ").append(aliases[0]).append(" "); + usagePrefix.append(" ").append(aliases.get(0)).append(" "); builder.append("\n ") .append(indent) .append("Usage: ") diff --git a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ExportCommand.java b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ExportCommand.java index c79c5a6..2528787 100644 --- a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ExportCommand.java +++ b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ExportCommand.java @@ -25,8 +25,8 @@ public class ExportCommand extends BaseInstanceCommand { protected void invoke(CommandArgs args, Instance instance) throws Exception { if (args.length == 0) throw new IllegalAccessException("You must specify a target path"); if (args.length > 2) throw new IllegalAccessException("Too many arguments"); - if (args.length > 1) instance.meta.instanceVersion = args[1]; - Exporters.CURSE_FORGE.generate(new ProcessState(), instance, Paths.get(args[0])); + if (args.length > 1) instance.meta().instanceVersion = args.get(1); + Exporters.CURSE_FORGE.generate(new ProcessState(), instance, Paths.get(args.get(0))); } private static class MultiMCExportCommand extends BaseInstanceCommand { @@ -38,7 +38,7 @@ public class ExportCommand extends BaseInstanceCommand { protected void invoke(CommandArgs args, Instance instance) throws Exception { if (args.length == 0) throw new IllegalAccessException("You must specify a target path"); if (args.length != 1) throw new IllegalAccessException("Too many arguments"); - Exporters.MULTI_MC.generate(new ProcessState(), instance, Paths.get(args[0])); + Exporters.MULTI_MC.generate(new ProcessState(), instance, Paths.get(args.get(0))); } } @@ -51,8 +51,8 @@ public class ExportCommand extends BaseInstanceCommand { protected void invoke(CommandArgs args, Instance instance) throws Exception { if (args.length == 0) throw new IllegalAccessException("You must specify a target path"); if (args.length > 2) throw new IllegalAccessException("Too many arguments"); - if (args.length > 1) instance.meta.instanceVersion = args[1]; - Exporters.MODRINTH.generate(new ProcessState(), instance, Paths.get(args[0])); + if (args.length > 1) instance.meta().instanceVersion = args.get(1); + Exporters.MODRINTH.generate(new ProcessState(), instance, Paths.get(args.get(0))); } } } diff --git a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/HelpCommand.java b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/HelpCommand.java index e8bf501..d16ace9 100644 --- a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/HelpCommand.java +++ b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/HelpCommand.java @@ -19,16 +19,16 @@ public class HelpCommand extends Command { CliMain.COMMANDS_ROOT.buildHelp(help); } else { CommandResolution resolution = CliMain.COMMANDS_ROOT.resolve(args); - if (resolution.resolvePath.isEmpty) { + if (resolution.resolvePath().isEmpty()) { System.err.println("Could not find command matching your input"); invoke(new CommandArgs(List.of())); return; } printHeader(); - System.out.println("\nFound matching: \"" + String.join(" ", resolution.resolvePath) + "\""); - resolution.command.buildHelp(help); + System.out.println("\nFound matching: \"" + String.join(" ", resolution.resolvePath()) + "\""); + resolution.command().buildHelp(help); } - System.out.println(help.result); + System.out.println(help.getResult()); } private static void printHeader() { diff --git a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ImportCommand.java b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ImportCommand.java index 309735f..8494687 100644 --- a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ImportCommand.java +++ b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ImportCommand.java @@ -19,7 +19,7 @@ public class ImportCommand extends Command { if (args.length == 0) throw new IllegalAccessException("You must specify a pack file"); if (args.length != 1) throw new IllegalAccessException("Too many arguments"); ProcessState state = new ProcessState(); - String name = Importers.importPack(Paths.get(args[0]), state).path().fileName.toString(); + String name = Importers.importPack(Paths.get(args.get(0)), state).path().getFileName().toString(); System.out.println(OutputColors.GREEN_BOLD + "Imported as " + name + OutputColors.RESET); } } diff --git a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/JvmStateCommand.java b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/JvmStateCommand.java index 6282b96..96084f6 100644 --- a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/JvmStateCommand.java +++ b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/JvmStateCommand.java @@ -21,7 +21,7 @@ public class JvmStateCommand extends Command { System.out.println("Classloader " + loader + ":"); if (loader instanceof URLClassLoader uc) - System.out.println("\t" + Arrays.toString(uc.uRLs)); + System.out.println("\t" + Arrays.toString(uc.getURLs())); else System.out.println("\t(cannot display components as not a URLClassLoader)"); diff --git a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/LaunchCommand.java b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/LaunchCommand.java index 3379c92..3092914 100644 --- a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/LaunchCommand.java +++ b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/LaunchCommand.java @@ -46,15 +46,15 @@ public class LaunchCommand extends BaseInstanceCommand { return; } if (args.length > 1) { - InstanceMeta meta = instance.meta; + InstanceMeta meta = instance.meta(); if (meta.arguments == null) meta.arguments = new InstanceMeta.Arguments(new ArrayList<>(), new ArrayList<>(), new ArrayList<>()); else meta.arguments = new InstanceMeta.Arguments( - meta.arguments.jvm == null ? new ArrayList<>() : new ArrayList<>(meta.arguments.jvm), - meta.arguments.client == null ? new ArrayList<>() : new ArrayList<>(meta.arguments.client), - meta.arguments.server == null ? new ArrayList<>() : new ArrayList<>(meta.arguments.server) + meta.arguments.jvm() == null ? new ArrayList<>() : new ArrayList<>(meta.arguments.jvm()), + meta.arguments.client() == null ? new ArrayList<>() : new ArrayList<>(meta.arguments.client()), + meta.arguments.server() == null ? new ArrayList<>() : new ArrayList<>(meta.arguments.server()) ); - meta.arguments.client.addAll(args.after(0)); - meta.arguments.server.addAll(args.after(0)); + meta.arguments.client().addAll(args.after(0)); + meta.arguments.server().addAll(args.after(0)); } Steps.reDownload(instance, Steps.createProcessState()); if (server) { diff --git a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ListCommand.java b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ListCommand.java index abb10d5..f3269db 100644 --- a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ListCommand.java +++ b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ListCommand.java @@ -21,13 +21,13 @@ public class ListCommand extends Command { @Override protected void invoke(CommandArgs args) throws IOException { List paths = JFiles.list(MetaHolder.INSTANCE_DIR); - if (paths.isEmpty) System.out.println("No instances are currently present"); + if (paths.isEmpty()) System.out.println("No instances are currently present"); for (Path path : paths) { if (!Files.exists(path.resolve(Instance.CONFIG_NAME))) { System.out.println("- Invalid instance: " + path + " (no instance metadata)"); continue; } - System.out.println("- \"" + path.fileName.toString() + "\""); + System.out.println("- \"" + path.getFileName().toString() + "\""); Instance instance; try { instance = InstanceList.read(path); @@ -39,13 +39,13 @@ public class ListCommand extends Command { System.out.println(" Status: Setting up"); continue; } - System.out.println(" Status: " + (instance.isRunningLocked ? "Running" : "Stopped")); - System.out.println(" Version: " + instance.gameVersion); - if (instance.isFabric) System.out.println(" Fabric Loader: " + instance.loaderVersion); - if (instance.meta.java != null) System.out.println(" Custom Java: " + instance.meta.java); - if (instance.meta.minMem != null || instance.meta().maxMem != null) - System.out.println(" Memory:" + (instance.meta.minMem != null ? " Minimum: " + instance.meta.minMem : "") - + (instance.meta.maxMem != null ? " Maximum: " + instance.meta.maxMem : "")); + System.out.println(" Status: " + (instance.isRunningLocked() ? "Running" : "Stopped")); + System.out.println(" Version: " + instance.getGameVersion()); + if (instance.isFabric()) System.out.println(" Fabric Loader: " + instance.getLoaderVersion()); + if (instance.meta().java != null) System.out.println(" Custom Java: " + instance.meta().java); + if (instance.meta().minMem != null || instance.meta().maxMem != null) + System.out.println(" Memory:" + (instance.meta().minMem != null ? " Minimum: " + instance.meta().minMem : "") + + (instance.meta().maxMem != null ? " Maximum: " + instance.meta().maxMem : "")); } } } diff --git a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ModCommand.java b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ModCommand.java index 5ff5056..9996703 100644 --- a/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ModCommand.java +++ b/launcher-cli/src/main/java/io/gitlab/jfronny/inceptum/cli/commands/ModCommand.java @@ -46,26 +46,26 @@ public class ModCommand extends Command { @Override protected void invoke(CommandArgs args, Instance instance) throws IOException { - if (!instance.isFabric) { + if (!instance.isFabric()) { System.err.println("This is not a fabric instance"); return; } System.out.println("Scanning installed mods, this might take a while"); - instance.mds.runOnce((path, mod) -> { - boolean hasSources = !mod.metadata.sources.isEmpty; - boolean updatable = hasSources && mod.metadata.sources.values().stream().anyMatch(Optional::isPresent); + instance.mds().runOnce((path, mod) -> { + boolean hasSources = !mod.getMetadata().sources().isEmpty(); + boolean updatable = hasSources && mod.getMetadata().sources().values().stream().anyMatch(Optional::isPresent); if (filterUpdatable && !updatable) return; - System.out.println("- " + path.fileName.toString()); - System.out.println(" " + mod.name); - for (String s : mod.description) { + System.out.println("- " + path.getFileName().toString()); + System.out.println(" " + mod.getName()); + for (String s : mod.getDescription()) { System.out.println(" " + s); } if (hasSources) { System.out.println(" Sources:"); - for (var entry : mod.metadata.sources) { - System.out.println(" - " + entry.key.name + " (" + entry.key.version + ")"); - System.out.println(" Local: " + entry.key.jarPath.toString()); - if (entry.value.isPresent) System.out.println(" Updatable to: " + entry.value.get().version); + for (var entry : mod.getMetadata().sources().entrySet()) { + System.out.println(" - " + entry.getKey().getName() + " (" + entry.getKey().getVersion() + ")"); + System.out.println(" Local: " + entry.getKey().getJarPath().toString()); + if (entry.getValue().isPresent()) System.out.println(" Updatable to: " + entry.getValue().get().getVersion()); } } }); @@ -98,22 +98,22 @@ public class ModCommand extends Command { } Set mods = new HashSet<>(); for (String arg : args) { - Path p = instance.modsDir.resolve(arg); - if (!Files.exists(p)) p = instance.modsDir.resolve(arg + ".imod"); + Path p = instance.getModsDir().resolve(arg); + if (!Files.exists(p)) p = instance.getModsDir().resolve(arg + ".imod"); if (!Files.exists(p)) { - Utils.LOGGER.error("Nonexistant mod file: " + instance.modsDir.resolve(arg)); + Utils.LOGGER.error("Nonexistant mod file: " + instance.getModsDir().resolve(arg)); return; } mods.add(p); } - ModsDirScanner mds = instance.mds; - if (!ignoreDependencies && !mds.isComplete) { + ModsDirScanner mds = instance.mds(); + if (!ignoreDependencies && !mds.isComplete()) { Utils.LOGGER.error("Scanning mods dir to search for dependencies. This might take a while"); mds.runOnce((path, mod) -> System.out.println("Scanned " + path)); } for (Path mod : mods) { try { - mds[mod].delete(); + mds.get(mod).delete(); } catch (IOException e) { Utils.LOGGER.error("Could not delete " + mod, e); return; @@ -155,23 +155,23 @@ public class ModCommand extends Command { if (args.length == 0) { throw new IllegalArgumentException("You must specify mods to remove"); } - Set mods = pathSupplier.apply(args, instance.path); - ModsDirScanner mds = instance.mds; - if (!mds.isComplete) { + Set mods = pathSupplier.apply(args, instance.path()); + ModsDirScanner mds = instance.mds(); + if (!mds.isComplete()) { Utils.LOGGER.error("Scanning mods dir to search for dependencies. This might take a while"); mds.runOnce((path, mod) -> System.out.println("Scanned " + path)); } for (Path mod : mods) { try { - Mod md = mds[mod]; + Mod md = mds.get(mod); md.delete(); - md.metadata.sources.values().stream() + md.getMetadata().sources().values().stream() .filter(Optional::isPresent) .map(Optional::get) .findFirst() .ifPresentOrElse(update -> { try { - Utils.LOGGER.info("Updating " + mod + " to " + update.version); + Utils.LOGGER.info("Updating " + mod + " to " + update.getVersion()); md.update(update); Utils.LOGGER.info("Update completed"); } catch (IOException e) { diff --git a/launcher-cli/src/main/java/module-info.java b/launcher-cli/src/main/java/module-info.java new file mode 100644 index 0000000..ed5dc2e --- /dev/null +++ b/launcher-cli/src/main/java/module-info.java @@ -0,0 +1,6 @@ +module io.gitlab.jfronny.inceptum.launcher.cli { + exports io.gitlab.jfronny.inceptum.cli; + + requires transitive io.gitlab.jfronny.inceptum.launcher; + requires static org.jetbrains.annotations; +} \ No newline at end of file diff --git a/launcher-dist/build.gradle.kts b/launcher-dist/build.gradle.kts index 2c2161c..beb860f 100644 --- a/launcher-dist/build.gradle.kts +++ b/launcher-dist/build.gradle.kts @@ -1,6 +1,6 @@ plugins { id("inceptum.application-standalone") - id("org.beryx.runtime") version "1.13.0" + id("org.beryx.jlink") version "2.26.0" } application { @@ -50,14 +50,18 @@ val verifyFlavorConfiguration by tasks.registering { } } -tasks.runtime { dependsOn(verifyFlavorConfiguration) } -tasks.runtimeZip { dependsOn(verifyFlavorConfiguration) } -tasks.suggestModules { dependsOn(verifyFlavorConfiguration) } +tasks.prepareMergedJarsDir { dependsOn(verifyFlavorConfiguration) } +tasks.createMergedModule { dependsOn(verifyFlavorConfiguration) } +tasks.createDelegatingModules { dependsOn(verifyFlavorConfiguration) } +tasks.prepareModulesDir { dependsOn(verifyFlavorConfiguration) } +tasks.jlink { dependsOn(verifyFlavorConfiguration) } +tasks.jlinkZip { dependsOn(verifyFlavorConfiguration) } +tasks.suggestMergedModuleInfo { dependsOn(verifyFlavorConfiguration) } tasks.jpackageImage { dependsOn(verifyFlavorConfiguration) } tasks.jpackage { dependsOn(verifyFlavorConfiguration) } -if (crosscompile) System.setProperty("badass.runtime.jpackage.home", "/root/jpackage-win") -runtime { +if (crosscompile) System.setProperty("badass.jlink.jpackage.home", "/root/jpackage-win") +jlink { if (crosscompile) javaHome.set("/root/jpackage-win") addOptions( "--strip-debug", @@ -66,6 +70,9 @@ runtime { "--no-man-pages", "--verbose" ) + launcher { + name = application.applicationName + } if (crosscompile) targetPlatform("win", "/root/java") jpackage { imageName = application.applicationName diff --git a/launcher-dist/src/main/java/module-info.java b/launcher-dist/src/main/java/module-info.java new file mode 100644 index 0000000..84a048b --- /dev/null +++ b/launcher-dist/src/main/java/module-info.java @@ -0,0 +1,4 @@ +module io.gitlab.jfronny.inceptum.launcher.dist { + requires io.gitlab.jfronny.inceptum.launcher.imgui; + requires io.gitlab.jfronny.inceptum.launcher.cli; +} \ No newline at end of file diff --git a/launcher-imgui/build.gradle.kts b/launcher-imgui/build.gradle.kts index 020271d..8fe835c 100644 --- a/launcher-imgui/build.gradle.kts +++ b/launcher-imgui/build.gradle.kts @@ -1,6 +1,5 @@ plugins { id("inceptum.application") - id("inceptum.manifold") } application { diff --git a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/GuiMain.java b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/GuiMain.java index 91cebf4..c9431df 100644 --- a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/GuiMain.java +++ b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/GuiMain.java @@ -65,7 +65,7 @@ public class GuiMain { AccountManager.loadAccounts(); Utils.LOGGER.info("Initializing UI"); try { - InstanceList.forEach(instance -> instance.mds.start()); + InstanceList.forEach(instance -> instance.mds().start()); } catch (IOException e) { Utils.LOGGER.error("Could not initialize MDS", e); } @@ -149,7 +149,7 @@ public class GuiMain { GLFW.glfwGetWindowSize(handle, pWidth, pHeight); final GLFWVidMode vidmode = Objects.requireNonNull(GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor())); - GLFW.glfwSetWindowPos(handle, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight[0]) / 2); + GLFW.glfwSetWindowPos(handle, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2); } GLFW.glfwMakeContextCurrent(handle); @@ -186,7 +186,7 @@ public class GuiMain { io.addConfigFlags(ImGuiConfigFlags.ViewportsEnable); io.setConfigViewportsNoAutoMerge(true); try (InputStream is = LauncherEnv.class.getClassLoader().getResourceAsStream("font.ttf")) { - io.fontDefault = io.fonts.addFontFromMemoryTTF(Objects.requireNonNull(is).readAllBytes(), 16f); + io.setFontDefault(io.getFonts().addFontFromMemoryTTF(Objects.requireNonNull(is).readAllBytes(), 16f)); } catch (IOException e) { Utils.LOGGER.error("Could not load font", e); } @@ -206,24 +206,24 @@ public class GuiMain { if (WINDOWS.isEmpty()) exit(); else { for (Window window : WINDOWS.toArray(new Window[0])) { - if (window.isNew) window.preFirstDraw(); - String title = window.name + "##" + System.identityHashCode(window); - if (window.isCloseable) { - if (ImGui.begin(title, window.openState, window.flags)) { + if (window.isNew()) window.preFirstDraw(); + String title = window.getName() + "##" + System.identityHashCode(window); + if (window.isCloseable()) { + if (ImGui.begin(title, window.getOpenState(), window.getFlags())) { window.draw(); } } else { - if (ImGui.begin(title, window.flags)) { + if (ImGui.begin(title, window.getFlags())) { window.draw(); } } ImGui.end(); - if (!window.openState.get() && !window.isClosed) window.close(); + if (!window.getOpenState().get() && !window.isClosed()) window.close(); } } //end frame ImGui.render(); - imGuiGl3.renderDrawData(ImGui.drawData); + imGuiGl3.renderDrawData(ImGui.getDrawData()); if (ImGui.getIO().hasConfigFlags(ImGuiConfigFlags.ViewportsEnable)) { final long backupWindowPtr = GLFW.glfwGetCurrentContext(); diff --git a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/control/InstanceManageControls.java b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/control/InstanceManageControls.java index ca27195..4d5152a 100644 --- a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/control/InstanceManageControls.java +++ b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/control/InstanceManageControls.java @@ -33,22 +33,22 @@ public class InstanceManageControls { private FabricVersionLoaderInfo selectedFabric; public InstanceManageControls(@Nullable Instance instance) { - selected = getVersions(false)[0]; + selected = getVersions(false).get(0); if (instance != null) { for (VersionsListInfo ver : getVersions(true)) { - if (ver.id.equals(instance.gameVersion)) + if (ver.id.equals(instance.getGameVersion())) selected = ver; } } version.set(getVersions(snapshots.get()).indexOf(selected)); - name.set(instance == null ? InstanceNameTool.getDefaultName(selected.id, fabric.get()) : instance.name); - fabric.set(instance == null || instance.isFabric); + name.set(instance == null ? InstanceNameTool.getDefaultName(selected.id, fabric.get()) : instance.getName()); + fabric.set(instance == null || instance.isFabric()); List versions = FabricMetaApi.getLoaderVersions(selected); for (int i = 0, fabricLoaderInfoSize = versions.size(); i < fabricLoaderInfoSize; i++) { - FabricVersionLoaderInfo version = versions[i]; - if (instance != null && instance.isFabric - ? version.loader.version.equals(instance.loaderVersion) - : version.loader.stable) { + FabricVersionLoaderInfo version = versions.get(i); + if (instance != null && instance.isFabric() + ? version.loader.version().equals(instance.getLoaderVersion()) + : version.loader.stable()) { selectedFabric = version; fabricVersion.set(i); break; @@ -73,7 +73,7 @@ public class InstanceManageControls { InceptumConfig.snapshots = snapshots.get(); InceptumConfig.saveConfig(); //fix version index - int i = getVersions(InceptumConfig.snapshots).indexOf(getVersions(prev)[version.get()]); + int i = getVersions(InceptumConfig.snapshots).indexOf(getVersions(prev).get(version.get())); if (i == -1) version.set(0); else version.set(i); } @@ -83,13 +83,13 @@ public class InstanceManageControls { List vil = getVersions(InceptumConfig.snapshots); String originalStr = null; try { - originalStr = versionInfo.id; + originalStr = getVersionInfo().id; } catch (Throwable e) { Utils.LOGGER.error("Could not get version string", e); } if (ImGui.combo("Version", version, vil.stream().map(info -> info.id).toArray(String[]::new))) { VersionsListInfo prev = selected; - selected = vil[version.get()]; + selected = vil.get(version.get()); exchangeNameIfDefault(prev.id, fabric.get()); } List versions = FabricMetaApi.getLoaderVersions(selected); @@ -102,14 +102,14 @@ public class InstanceManageControls { } if (fabric.get()) { ImGui.sameLine(); - if (ImGui.combo("Loader", fabricVersion, versions.stream().map(info -> info.loader.version).toArray(String[]::new))) { + if (ImGui.combo("Loader", fabricVersion, versions.stream().map(info -> info.loader.version()).toArray(String[]::new))) { selectedFabric = versions.get(fabricVersion.get()); } } } try { if (originalStr != null && !originalStr.equals(getVersionInfo().id)) - modifiedVersion.accept(versionInfo.id); + modifiedVersion.accept(getVersionInfo().id); } catch (IOException e) { Utils.LOGGER.error("Could not compare version string", e); } @@ -128,10 +128,10 @@ public class InstanceManageControls { } public VersionInfo getVersionInfo() throws IOException { - return VERSION_INFO_CACHE.get(Tuple.of(selected.id, fabric.get() ? selectedFabric.loader.version : ""), () -> { + return VERSION_INFO_CACHE.get(Tuple.of(selected.id, fabric.get() ? selectedFabric.loader.version() : ""), () -> { VersionInfo vi = McApi.getVersionInfo(selected); if (fabric.get()) - vi = FabricMetaApi.addFabric(vi, selectedFabric.loader.version, FabricMetaApi.FabricVersionInfoType.Both); + vi = FabricMetaApi.addFabric(vi, selectedFabric.loader.version(), FabricMetaApi.FabricVersionInfoType.Both); return vi; }); } @@ -141,7 +141,7 @@ public class InstanceManageControls { } private List getVersions(boolean snapshots) { - ArrayList res = new ArrayList<>(VERSIONS.versions); + ArrayList res = new ArrayList<>(VERSIONS.versions()); res.removeIf(info -> !snapshots && !info.type.equals("release")); return res; } diff --git a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/control/InstanceView.java b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/control/InstanceView.java index 71fca21..06e18e0 100644 --- a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/control/InstanceView.java +++ b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/control/InstanceView.java @@ -15,26 +15,26 @@ import java.nio.file.Files; public class InstanceView { public static void draw() throws IOException { - if (InstanceList.isEmpty) { + if (InstanceList.isEmpty()) { ImGui.text("You have not yet created an instance"); ImGui.text("Use File->New Instance to do so"); return; } if (ImGui.beginTable("Instances", 2, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.Borders)) { for (Instance instance : InstanceList.ordered()) { - if (instance.isSetupLocked) { + if (instance.isSetupLocked()) { ImGui.tableNextColumn(); ImGui.text("Setting up"); ImGui.tableNextColumn(); ImGui.text("This instance is currently being set up"); continue; } - if (!Files.exists(instance.path.resolve(Instance.CONFIG_NAME))) { + if (!Files.exists(instance.path().resolve(Instance.CONFIG_NAME))) { Utils.LOGGER.error("Invalid instance (doesn't contain " + Instance.CONFIG_NAME + "): " + instance); continue; } ImGui.tableNextColumn(); - boolean runDisabled = instance.isRunningLocked; + boolean runDisabled = instance.isRunningLocked(); if (runDisabled) ImGui.beginDisabled(); if (ImGui.button(instance.toString())) { try { @@ -46,7 +46,7 @@ public class InstanceView { } if (runDisabled) ImGui.endDisabled(); ImGui.tableNextColumn(); - if (ImGui.button("Edit##" + instance.id)) { + if (ImGui.button("Edit##" + instance.id())) { try { GuiMain.open(new InstanceEditWindow(instance)); } catch (IOException e) { diff --git a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/control/Tab.java b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/control/Tab.java index 1d558eb..d589dfe 100644 --- a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/control/Tab.java +++ b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/control/Tab.java @@ -12,7 +12,7 @@ public abstract class Tab { protected abstract void renderInner(); public void render() { - if (isVisible && ImGui.beginTabItem(name)) { + if (isVisible() && ImGui.beginTabItem(name)) { renderInner(); ImGui.endTabItem(); } diff --git a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/AddModWindow.java b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/AddModWindow.java index 0edda97..7299f75 100644 --- a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/AddModWindow.java +++ b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/AddModWindow.java @@ -27,7 +27,7 @@ public class AddModWindow extends Window { private List cf = null; public AddModWindow(Instance instance) { - super(instance.name + " - Add Mods"); + super(instance.getName() + " - Add Mods"); this.instance = instance; } @@ -35,10 +35,10 @@ public class AddModWindow extends Window { String query = this.query.get(); new Thread(() -> { try { - ModrinthSearchResult ms = ModrinthApi.search(query, mrPage, instance.gameVersion, ModrinthProjectType.mod); + ModrinthSearchResult ms = ModrinthApi.search(query, mrPage, instance.getGameVersion(), ModrinthProjectType.mod); if (!this.query.get().equals(query)) return; mr = ms; - List cs = CurseforgeApi.search(instance.gameVersion, query, cfPage, "Popularity"); + List cs = CurseforgeApi.search(instance.getGameVersion(), query, cfPage, "Popularity"); if (!this.query.get().equals(query)) return; cf = cs; } catch (IOException e) { @@ -57,7 +57,7 @@ public class AddModWindow extends Window { if (ImGui.beginTabBar("ModsSelect")) { if (ImGui.beginTabItem("Modrinth")) { if (mr != null) { - boolean hasNext = (mr.offset + mr.hits.size() < mr.total_hits); + boolean hasNext = (mr.offset() + mr.hits().size() < mr.total_hits()); if (mrPage > 0) { if (ImGui.button("Previous Page")) { mrPage--; @@ -71,21 +71,21 @@ public class AddModWindow extends Window { reSearch(); } } - if (mr != null && ImGui.beginTable("mods" + instance.id, 3, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.Borders)) { - for (ModrinthSearchResult.ModResult mod : mr.hits) { - String modId = (mod.slug != null ? mod.slug : mod.project_id); + if (mr != null && ImGui.beginTable("mods" + instance.id(), 3, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.Borders)) { + for (ModrinthSearchResult.ModResult mod : mr.hits()) { + String modId = (mod.slug() != null ? mod.slug() : mod.project_id()); final String idPrefix = "local-"; - String projectId = mod.project_id.startsWith(idPrefix) ? mod.project_id.substring(idPrefix.length()) : mod.project_id; + String projectId = mod.project_id().startsWith(idPrefix) ? mod.project_id().substring(idPrefix.length()) : mod.project_id(); //TODO detail view ImGui.tableNextColumn(); - ImGui.text(mod.title); + ImGui.text(mod.title()); ImGui.tableNextColumn(); - ImGui.text(mod.description); + ImGui.text(mod.description()); ImGui.tableNextColumn(); boolean alreadyPresent = false; - for (Mod mdsMod : instance.mods) { - alreadyPresent = mdsMod.metadata.sources.keySet().stream() - .anyMatch(s -> s instanceof ModrinthModSource ms && ms.modId.equals(projectId)); + for (Mod mdsMod : instance.getMods()) { + alreadyPresent = mdsMod.getMetadata().sources().keySet().stream() + .anyMatch(s -> s instanceof ModrinthModSource ms && ms.getModId().equals(projectId)); if (alreadyPresent) break; } @@ -97,12 +97,12 @@ public class AddModWindow extends Window { ModrinthVersion beta = null; ModrinthVersion latest = null; for (ModrinthVersion version : ModrinthApi.getVersions(projectId)) { - if (version.game_versions.contains(instance.gameVersion) && version.loaders.contains("fabric")) { + if (version.game_versions().contains(instance.getGameVersion()) && version.loaders().contains("fabric")) { latest = version; - if (version.version_type == ModrinthVersion.VersionType.beta || version.version_type == ModrinthVersion.VersionType.release) { + if (version.version_type() == ModrinthVersion.VersionType.beta || version.version_type() == ModrinthVersion.VersionType.release) { beta = version; } - if (version.version_type == ModrinthVersion.VersionType.release) { + if (version.version_type() == ModrinthVersion.VersionType.release) { stable = version; } } @@ -115,7 +115,7 @@ public class AddModWindow extends Window { ModrinthVersion finalLatest = latest; new Thread(() -> { try { - ModManager.download(new ModrinthModSource(finalLatest.id), instance.modsDir.resolve((mod.slug == null ? projectId : mod.slug) + ModPath.EXT_IMOD), instance.mds).write(); + ModManager.download(new ModrinthModSource(finalLatest.id()), instance.getModsDir().resolve((mod.slug() == null ? projectId : mod.slug()) + ModPath.EXT_IMOD), instance.mds()).write(); } catch (IOException e) { LauncherEnv.showError("Could not download mod", e); } @@ -148,28 +148,28 @@ public class AddModWindow extends Window { reSearch(); } } - if (cf != null && ImGui.beginTable("curseforge" + instance.id, 3, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.Borders)) { + if (cf != null && ImGui.beginTable("curseforge" + instance.id(), 3, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.Borders)) { for (CurseforgeMod mod : cf) { //TODO detail view ImGui.tableNextColumn(); - ImGui.text(mod.name); + ImGui.text(mod.name()); ImGui.tableNextColumn(); - ImGui.text(mod.summary); + ImGui.text(mod.summary()); ImGui.tableNextColumn(); boolean alreadyPresent = false; - for (Mod mdsMod : instance.mds.mods) { - alreadyPresent = mdsMod.metadata.sources.keySet().stream() - .anyMatch(s -> s instanceof CurseforgeModSource ms && ms.projectId == mod.id); + for (Mod mdsMod : instance.mds().getMods()) { + alreadyPresent = mdsMod.getMetadata().sources().keySet().stream() + .anyMatch(s -> s instanceof CurseforgeModSource ms && ms.getProjectId() == mod.id()); if (alreadyPresent) break; } if (alreadyPresent) { ImGui.text("Installed"); } else { - if (ImGui.button("Add##" + mod.id)) { + if (ImGui.button("Add##" + mod.id())) { CurseforgeMod.LatestFileIndex latest = null; - for (CurseforgeMod.LatestFileIndex file : mod.latestFilesIndexes) { - if (file.gameVersion.equals(instance.gameVersion)) { + for (CurseforgeMod.LatestFileIndex file : mod.latestFilesIndexes()) { + if (file.gameVersion().equals(instance.getGameVersion())) { if (latest == null) latest = file; } } @@ -179,7 +179,7 @@ public class AddModWindow extends Window { CurseforgeMod.LatestFileIndex finalLatest = latest; new Thread(() -> { try { - ModManager.download(new CurseforgeModSource(mod.id, finalLatest.fileId), instance.modsDir.resolve((mod.slug == null ? mod.id : mod.slug) + ModPath.EXT_IMOD), instance.mds).write(); + ModManager.download(new CurseforgeModSource(mod.id(), finalLatest.fileId()), instance.getModsDir().resolve((mod.slug() == null ? mod.id() : mod.slug()) + ModPath.EXT_IMOD), instance.mds()).write(); } catch (IOException e) { LauncherEnv.showError("Could not download mod", e); } @@ -188,8 +188,8 @@ public class AddModWindow extends Window { } } ImGui.sameLine(); - if (ImGui.button("Web##" + mod.id)) { - Utils.openWebBrowser(new URI(mod.links.websiteUrl)); + if (ImGui.button("Web##" + mod.id())) { + Utils.openWebBrowser(new URI(mod.links().websiteUrl())); } } ImGui.endTable(); diff --git a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/GuiUtil.java b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/GuiUtil.java index a40f8e8..9f95881 100644 --- a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/GuiUtil.java +++ b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/GuiUtil.java @@ -43,15 +43,15 @@ public class GuiUtil { pState.updateStep("Starting install process"); GuiMain.open(new ProcessStateWatcherWindow("Creating Instance", "Could not create instance", pState, () -> { for (Step step : Steps.STEPS) { - if (state.isCancelled) { + if (state.isCancelled()) { try { - JFiles.deleteRecursive(MetaHolder.INSTANCE_DIR.resolve(state.name)); + JFiles.deleteRecursive(MetaHolder.INSTANCE_DIR.resolve(state.name())); } catch (IOException e) { Utils.LOGGER.error("Could not delete instance dir", e); } return; } - pState.incrementStep(step.name); + pState.incrementStep(step.getName()); step.execute(state); } LauncherEnv.showInfo("The instance was successfully created. You can now launch it using the main menu", "Successfully installed"); diff --git a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/MainWindow.java b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/MainWindow.java index 548a0e3..f98fddf 100644 --- a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/MainWindow.java +++ b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/MainWindow.java @@ -49,11 +49,11 @@ public class MainWindow extends Window { } if (ImGui.beginMenu("Account")) { if (ImGui.menuItem("New")) GuiMain.open(new MicrosoftLoginWindow()); - AuthInfo selected = AccountManager.selectedAccount; - List accounts = AccountManager.accounts; + AuthInfo selected = AccountManager.getSelectedAccount(); + List accounts = AccountManager.getAccounts(); int accountsSize = accounts.size(); for (int i = 0; i < accountsSize; i++) { - MicrosoftAccount account = accounts[i]; + MicrosoftAccount account = accounts.get(i); if (selected.equals(account)) accountIndex.set(i); if (ImGui.radioButton(account.minecraftUsername, accountIndex, i)) { AccountManager.switchAccount(account); diff --git a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/NewInstanceWindow.java b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/NewInstanceWindow.java index 9cb3bc5..1289ab7 100644 --- a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/NewInstanceWindow.java +++ b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/NewInstanceWindow.java @@ -32,7 +32,7 @@ public class NewInstanceWindow extends Window { imc.nameBox("OK", name -> { try { GuiUtil.createInstance(new SetupStepInfo(imc.getVersionInfo(), - imc.loaderInfo, + imc.getLoaderInfo(), name, Steps.createProcessState())); } catch (IOException e) { @@ -53,9 +53,9 @@ public class NewInstanceWindow extends Window { ProcessState state = new ProcessState(Importers.MAX_STEPS * packs.size(), "Initializing"); GuiMain.open(new ProcessStateWatcherWindow("Importing", "Could not import packs", state, () -> { for (Path pack : packs) { - if (state.isCancelled) return; + if (state.isCancelled()) return; Path imported = Importers.importPack(pack, state).path(); - if (!state.isCancelled) LauncherEnv.showInfo(pack.fileName + " has been successfully imported as " + imported.fileName, "Imported pack"); + if (!state.isCancelled()) LauncherEnv.showInfo(pack.getFileName() + " has been successfully imported as " + imported.getFileName(), "Imported pack"); } })); } diff --git a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/dialog/ProcessStateWatcherWindow.java b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/dialog/ProcessStateWatcherWindow.java index b897461..652ca24 100644 --- a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/dialog/ProcessStateWatcherWindow.java +++ b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/dialog/ProcessStateWatcherWindow.java @@ -32,8 +32,8 @@ public class ProcessStateWatcherWindow extends Window { @Override public void draw() { - ImGui.progressBar(state.progress); - ImGui.textUnformatted(state.currentStep); + ImGui.progressBar(state.getProgress()); + ImGui.textUnformatted(state.getCurrentStep()); if (ImGui.button("Cancel")) { state.cancel(); close(); diff --git a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/ArgumentsTab.java b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/ArgumentsTab.java index 9d2d3f5..3319827 100644 --- a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/ArgumentsTab.java +++ b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/ArgumentsTab.java @@ -19,19 +19,19 @@ public class ArgumentsTab extends Tab { public ArgumentsTab(InstanceEditWindow window) { super("Arguments"); this.window = window; - InstanceMeta meta = window.instance.meta; + InstanceMeta meta = window.instance.meta(); if (meta.arguments == null) meta.arguments = new InstanceMeta.Arguments(new LinkedList<>(), new LinkedList<>(), new LinkedList<>()); - if (meta.arguments.jvm == null) meta.arguments = meta.arguments.withJvm(new LinkedList<>()); - jvm.set(String.join("\n", meta.arguments.jvm)); - if (meta.arguments.client == null) meta.arguments = meta.arguments.withClient(new LinkedList<>()); - client.set(String.join("\n", meta.arguments.client)); - if (meta.arguments.server == null) meta.arguments = meta.arguments.withServer(new LinkedList<>()); - server.set(String.join("\n", meta.arguments.server)); + if (meta.arguments.jvm() == null) meta.arguments = meta.arguments.withJvm(new LinkedList<>()); + jvm.set(String.join("\n", meta.arguments.jvm())); + if (meta.arguments.client() == null) meta.arguments = meta.arguments.withClient(new LinkedList<>()); + client.set(String.join("\n", meta.arguments.client())); + if (meta.arguments.server() == null) meta.arguments = meta.arguments.withServer(new LinkedList<>()); + server.set(String.join("\n", meta.arguments.server())); } @Override protected void renderInner() { - InstanceMeta meta = window.instance.meta; + InstanceMeta meta = window.instance.meta(); if (ImGui.inputTextMultiline("JVM", jvm)) { meta.arguments = meta.arguments.withJvm(List.of(Utils.NEW_LINE.split(jvm.get()))); window.instance.writeMeta(); diff --git a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/ExportTab.java b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/ExportTab.java index b92b08d..85d6046 100644 --- a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/ExportTab.java +++ b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/ExportTab.java @@ -20,26 +20,26 @@ public class ExportTab extends Tab { public ExportTab(InstanceEditWindow window) { super("Export"); this.window = window; - instanceVersion.set(window.instance.meta.instanceVersion); + instanceVersion.set(window.instance.meta().instanceVersion); } @Override protected void renderInner() { if (ImGui.inputTextWithHint("Version", "Version of the exported Pack", instanceVersion)) { - window.instance.meta.instanceVersion = instanceVersion.get(); + window.instance.meta().instanceVersion = instanceVersion.get(); window.instance.writeMeta(); } - if (window.instance.mds.isComplete) { + if (window.instance.mds().isComplete()) { for (Exporter exporter : Exporters.EXPORTERS) { - if (ImGui.button(exporter.name)) { + if (ImGui.button(exporter.getName())) { String defaultName = exporter.getDefaultFileName(window.instance); - String filter = "*." + exporter.fileExtension; - Path exportPath = GuiMain.saveFileDialog("Export " + exporter.name + " Pack", defaultName, new String[]{filter}, exporter.name + " packs (" + filter + ")"); + String filter = "*." + exporter.getFileExtension(); + Path exportPath = GuiMain.saveFileDialog("Export " + exporter.getName() + " Pack", defaultName, new String[]{filter}, exporter.getName() + " packs (" + filter + ")"); if (exportPath != null) { ProcessState state = new ProcessState(Exporters.STEP_COUNT, "Initializing..."); GuiMain.open(new ProcessStateWatcherWindow("Exporting", "Could not export pack", state, () -> { exporter.generate(state, window.instance, exportPath); - if (!state.isCancelled) LauncherEnv.showInfo(window.instance.name + " has been successfully exported to " + exportPath, "Successfully exported"); + if (!state.isCancelled()) LauncherEnv.showInfo(window.instance.getName() + " has been successfully exported to " + exportPath, "Successfully exported"); })); } } diff --git a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/GeneralTab.java b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/GeneralTab.java index 7927bda..20ce3cc 100644 --- a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/GeneralTab.java +++ b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/GeneralTab.java @@ -28,7 +28,7 @@ public class GeneralTab extends Tab { super("General"); this.window = window; imc = new InstanceManageControls(window.instance); - String java = window.instance.meta.java; + String java = window.instance.meta().java; customJava = new ImBoolean(java != null); if (java != null) customJavaPath.set(java); } @@ -36,12 +36,12 @@ public class GeneralTab extends Tab { @Override protected void renderInner() { if (ImGui.button("Open Directory")) { - Utils.openFile(window.instance.path.toFile()); + Utils.openFile(window.instance.path().toFile()); } imc.nameBox("Rename", name -> { try { Path newPath = MetaHolder.INSTANCE_DIR.resolve(name); - Files.move(window.instance.path, newPath); + Files.move(window.instance.path(), newPath); GuiMain.open(new InstanceEditWindow(window.instance)); window.close(); } catch (IOException e) { @@ -51,13 +51,13 @@ public class GeneralTab extends Tab { imc.snapshotsBox(); imc.versionBox(ver -> { window.reDownload = true; - window.instance.meta.gameVersion = ver; + window.instance.meta().gameVersion = ver; window.instance.writeMeta(); }); if (ImGui.button("Delete")) LauncherEnv.showOkCancel("This instance will be removed forever (a long time)", "Are you sure?", () -> { try { - JFiles.deleteRecursive(window.instance.path); + JFiles.deleteRecursive(window.instance.path()); } catch (IOException e) { LauncherEnv.showError("Could not delete the instance", e); } @@ -65,15 +65,15 @@ public class GeneralTab extends Tab { }, R::nop); if (ImGui.checkbox("Custom Java", customJava)) { if (customJava.get()) { - window.instance.meta.java = OSUtils.jvmBinary; - customJavaPath.set(window.instance.meta.java); + window.instance.meta().java = OSUtils.getJvmBinary(); + customJavaPath.set(window.instance.meta().java); } else { - window.instance.meta.java = null; + window.instance.meta().java = null; } window.instance.writeMeta(); } if (customJava.get() && ImGui.inputText("Path", customJavaPath)) { - window.instance.meta.java = customJavaPath.get(); + window.instance.meta().java = customJavaPath.get(); window.instance.writeMeta(); } } diff --git a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/InstanceEditWindow.java b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/InstanceEditWindow.java index 695502e..1897c41 100644 --- a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/InstanceEditWindow.java +++ b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/InstanceEditWindow.java @@ -16,9 +16,9 @@ public class InstanceEditWindow extends Window { protected boolean lastTabWasMods = false; public InstanceEditWindow(Instance instance) throws IOException { - super(instance.name + " - Edit"); + super(instance.getName() + " - Edit"); this.instance = instance; - this.instance.mds.start(); + this.instance.mds().start(); this.tabs = List.of( new GeneralTab(this), new ArgumentsTab(this), @@ -29,15 +29,15 @@ public class InstanceEditWindow extends Window { @Override public void draw() { - if (instance.isSetupLocked) { + if (instance.isSetupLocked()) { ImGui.text("This instance is still being set up."); return; } - if (instance.isRunningLocked) { + if (instance.isRunningLocked()) { ImGui.text("This instance is running. Edits in this state will result in breakage."); } lastTabWasMods = false; - if (ImGui.beginTabBar("InstanceEdit" + instance.id)) { + if (ImGui.beginTabBar("InstanceEdit" + instance.id())) { for (Tab tab : tabs) tab.render(); ImGui.endTabBar(); } diff --git a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/ModsTab.java b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/ModsTab.java index 4fee2c2..43c1ebc 100644 --- a/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/ModsTab.java +++ b/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/ModsTab.java @@ -29,9 +29,9 @@ public class ModsTab extends Tab { @Override protected void renderInner() { window.lastTabWasMods = true; - if (!Files.exists(window.instance.modsDir)) { + if (!Files.exists(window.instance.getModsDir())) { try { - Files.createDirectories(window.instance.modsDir); + Files.createDirectories(window.instance.getModsDir()); } catch (IOException e) { Utils.LOGGER.error("Could not create mods directory which was missing from this modded instance", e); } @@ -41,12 +41,12 @@ public class ModsTab extends Tab { GuiMain.WINDOWS.add(new AddModWindow(window.instance)); } ImGui.sameLine(); - if (Files.exists(window.instance.modsDir) && ImGui.button("Show")) { - Utils.openFile(window.instance.modsDir.toFile()); + if (Files.exists(window.instance.getModsDir()) && ImGui.button("Show")) { + Utils.openFile(window.instance.getModsDir().toFile()); } ImGui.sameLine(); - if (Files.exists(window.instance.configDir) && ImGui.button("Configs")) { - Utils.openFile(window.instance.configDir.toFile()); + if (Files.exists(window.instance.getConfigDir()) && ImGui.button("Configs")) { + Utils.openFile(window.instance.getConfigDir().toFile()); } try { Set modSet = window.instance.getMods(); @@ -54,10 +54,10 @@ public class ModsTab extends Tab { float scannedPercentage = 0; boolean hasUnScanned = false; for (Mod mod : modSet) { - if (window.instance.mds.hasScanned(mod)) scannedPercentage++; + if (window.instance.mds().hasScanned(mod)) scannedPercentage++; else hasUnScanned = true; - for (Optional value : mod.metadata.sources.values()) { - if (value.isPresent) { + for (Optional value : mod.getMetadata().sources().values()) { + if (value.isPresent()) { updatesFound = true; break; } @@ -74,21 +74,21 @@ public class ModsTab extends Tab { ImGui.separator(); for (Mod mod : modSet) { updatesFound = false; - for (Optional value : mod.metadata.sources.values()) { - updatesFound |= value.isPresent; + for (Optional value : mod.getMetadata().sources().values()) { + updatesFound |= value.isPresent(); } if (filterUpdates.get() && !updatesFound) continue; - if (ImGui.checkbox("##" + mod.name, mod.isEnabled)) { - Path newSel = ModPath.toggle(mod.metadataPath); + if (ImGui.checkbox("##" + mod.getName(), mod.isEnabled())) { + Path newSel = ModPath.toggle(mod.getMetadataPath()); try { - Files.move(mod.metadataPath, newSel); - if (mod.metadataPath.equals(selected)) selected = newSel; + Files.move(mod.getMetadataPath(), newSel); + if (mod.getMetadataPath().equals(selected)) selected = newSel; } catch (IOException e) { LauncherEnv.showError("Could not change disabled state", e); } } ImGui.sameLine(); - if (ImGui.button(mod.name)) selected = mod.metadataPath; + if (ImGui.button(mod.getName())) selected = mod.getMetadataPath(); } } catch (IOException e) { Utils.LOGGER.error("Could not show mod list", e); @@ -98,24 +98,24 @@ public class ModsTab extends Tab { ImGui.beginGroup(); if (selected == null) { ImGui.text("Select a mod to view settings"); - } else if (window.instance.mds.hasScanned(selected)) { - Mod md = window.instance.mds[selected]; - ImGui.text(md.name); + } else if (window.instance.mds().hasScanned(selected)) { + Mod md = window.instance.mds().get(selected); + ImGui.text(md.getName()); ImGui.separator(); - for (String s : md.description) { + for (String s : md.getDescription()) { ImGui.text(s); } ImGui.separator(); - Map> sources = md.metadata.sources; + Map> sources = md.getMetadata().sources(); ImGui.text("Sources:"); - if (sources.isEmpty) + if (sources.isEmpty()) ImGui.bulletText("Local Drive"); else { - for (var source : sources) { - ImGui.bulletText(source.key.name); - source.value.ifPresent(update -> { + for (var source : sources.entrySet()) { + ImGui.bulletText(source.getKey().getName()); + source.getValue().ifPresent(update -> { ImGui.sameLine(); - if (ImGui.button("Update to " + update.version)) { + if (ImGui.button("Update to " + update.getVersion())) { try { selected = md.update(update); } catch (IOException e) { @@ -126,8 +126,8 @@ public class ModsTab extends Tab { } } if (ImGui.button("Delete")) { - if (!md.metadata.dependents.isEmpty) - LauncherEnv.showError("This mod still has the following dependent mods installed: " + String.join(", ", md.metadata.dependents), "Dependents present"); + if (!md.getMetadata().dependents().isEmpty()) + LauncherEnv.showError("This mod still has the following dependent mods installed: " + String.join(", ", md.getMetadata().dependents()), "Dependents present"); else { try { md.delete(); @@ -145,6 +145,6 @@ public class ModsTab extends Tab { @Override protected boolean isVisible() { - return window.instance.isFabric; + return window.instance.isFabric(); } } diff --git a/launcher-imgui/src/main/java/module-info.java b/launcher-imgui/src/main/java/module-info.java new file mode 100644 index 0000000..90b7cd8 --- /dev/null +++ b/launcher-imgui/src/main/java/module-info.java @@ -0,0 +1,12 @@ +module io.gitlab.jfronny.inceptum.launcher.imgui { + exports io.gitlab.jfronny.inceptum.imgui; + + requires transitive io.gitlab.jfronny.inceptum.launcher; + requires static org.jetbrains.annotations; + requires imgui.binding; + requires org.lwjgl; + requires org.lwjgl.glfw; + requires org.lwjgl.opengl; + requires org.lwjgl.tinyfd; + requires imgui.lwjgl3; +} \ No newline at end of file diff --git a/launcher/build.gradle.kts b/launcher/build.gradle.kts index 979f12b..ac999fc 100644 --- a/launcher/build.gradle.kts +++ b/launcher/build.gradle.kts @@ -1,14 +1,13 @@ plugins { id("inceptum.library") id("inceptum.gson-compile") - id("inceptum.manifold") } dependencies { - val jlhttpVersion: String by rootProject.extra + val jfCommonsVersion: String by rootProject.extra val jbAnnotationsVersion: String by rootProject.extra api(project(":common")) - implementation("net.freeutils:jlhttp:$jlhttpVersion") + implementation("io.gitlab.jfronny:commons-jlhttp:$jfCommonsVersion") compileOnly("org.jetbrains:annotations:$jbAnnotationsVersion") } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/CurseforgeApi.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/CurseforgeApi.java index 60164e7..4631e54 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/CurseforgeApi.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/CurseforgeApi.java @@ -1,9 +1,9 @@ package io.gitlab.jfronny.inceptum.launcher.api; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.curseforge.response.FingerprintMatchesResponse.GC_FingerprintMatchesResponse; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.curseforge.response.GetModFileResponse.GC_GetModFileResponse; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.curseforge.response.GetModResponse.GC_GetModResponse; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.curseforge.response.SearchResponse.GC_SearchResponse; +import io.gitlab.jfronny.inceptum.launcher.model.curseforge.response.GC_FingerprintMatchesResponse; +import io.gitlab.jfronny.inceptum.launcher.model.curseforge.response.GC_GetModFileResponse; +import io.gitlab.jfronny.inceptum.launcher.model.curseforge.response.GC_GetModResponse; +import io.gitlab.jfronny.inceptum.launcher.model.curseforge.response.GC_SearchResponse; import io.gitlab.jfronny.commons.HttpUtils; import io.gitlab.jfronny.inceptum.common.Net; import io.gitlab.jfronny.inceptum.launcher.model.curseforge.CurseforgeFile; @@ -43,7 +43,7 @@ public class CurseforgeApi { "gameVersion", gameVersion, "pageSize", Integer.toString(pageSize), "index", Integer.toString(page * pageSize) - )), GC_SearchResponse::read, API_KEY).data; + )), GC_SearchResponse::read, API_KEY).data(); } public static CurseforgeMod getMod(String slug) throws IOException { @@ -52,31 +52,31 @@ public class CurseforgeApi { "classId", "6", "slug", slug )), GC_SearchResponse::read, API_KEY); - if (response.pagination.totalCount != 1) { + if (response.pagination().totalCount() != 1) { throw new FileNotFoundException("Could not find mod with slug \"" + slug + "\""); } - return checkDistribution(response.data[0]); + return checkDistribution(response.data().get(0)); } 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.downloadObject(API_URL + "mods/" + id, GC_GetModResponse::read, API_KEY).data()); } private static CurseforgeMod checkDistribution(CurseforgeMod mod) { - if (!mod.allowModDistribution) { - throw new IllegalArgumentException("The author of the mod \"" + mod.slug + "\" has chosen to deliberately break your ability of downloading it.\n" + if (!mod.allowModDistribution()) { + throw new IllegalArgumentException("The author of the mod \"" + mod.slug() + "\" has chosen to deliberately break your ability of downloading it.\n" + "Please let them know that disabling third party downloads does nothing but make the users life harder for no reason."); } return mod; } 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.downloadObject(API_URL + "mods/" + modId + "/files/" + fileId, GC_GetModFileResponse::read, API_KEY).data(); } public static FingerprintMatchesResponse.Result checkFingerprint(long hash) throws IOException, URISyntaxException { try (Reader r = HttpUtils.post(API_URL + "fingerprints").bodyJson("{\"fingerprints\":[" + hash + "]}").sendReader()) { - return GC_FingerprintMatchesResponse.read(r).data; + return GC_FingerprintMatchesResponse.read(r).data(); } } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/FabricMetaApi.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/FabricMetaApi.java index a15d9b9..3bd1144 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/FabricMetaApi.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/FabricMetaApi.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.api; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.fabric.FabricVersionLoaderInfo.GC_FabricVersionLoaderInfo; +import io.gitlab.jfronny.inceptum.launcher.model.fabric.GC_FabricVersionLoaderInfo; import io.gitlab.jfronny.commons.cache.MemoryOperationResultCache; import io.gitlab.jfronny.gson.compile.util.GList; import io.gitlab.jfronny.gson.stream.JsonReader; @@ -44,17 +44,17 @@ public class FabricMetaApi { if (!(ver instanceof FabricVersionLoaderInfo.WithMeta verWithMeta)) throw new IOException("Doesn't hold metadata"); FabricVersionLoaderInfo.WithMeta.LauncherMeta meta = verWithMeta.launcherMeta; - if (meta.version != 1) throw new IOException("Unsupported fabric launcherMeta version: " + meta.version); - result.mainClass = type == FabricVersionInfoType.Server ? meta.mainClass.server : meta.mainClass.client; + if (meta.version() != 1) throw new IOException("Unsupported fabric launcherMeta version: " + meta.version()); + result.mainClass = type == FabricVersionInfoType.Server ? meta.mainClass().server() : meta.mainClass().client(); List libs = new ArrayList<>(version.libraries); - for (Library library : meta.libraries.common) + for (Library library : meta.libraries().common()) libs.add(convertLib(library)); if (type == FabricVersionInfoType.Client || type == FabricVersionInfoType.Both) { - for (Library library : meta.libraries.client) + for (Library library : meta.libraries().client()) libs.add(convertLib(library)); } if (type == FabricVersionInfoType.Server || type == FabricVersionInfoType.Both) { - for (Library library : meta.libraries.server) + for (Library library : meta.libraries().server()) libs.add(convertLib(library)); } libs.add(convertLib(new Library( @@ -62,7 +62,7 @@ public class FabricMetaApi { "https://maven.fabricmc.net/" ))); libs.add(convertLib(new Library( - ver.intermediary.maven, + ver.intermediary.maven(), "https://maven.fabricmc.net/" ))); result.libraries = List.copyOf(libs); @@ -71,18 +71,18 @@ public class FabricMetaApi { } private static VersionInfo.Library convertLib(Library library) { - String path = ArtifactMeta.parse(library.name).getJarPath(true); + String path = ArtifactMeta.parse(library.name()).getJarPath(true); return new VersionInfo.Library( new VersionInfo.Library.Downloads( new VersionInfo.Library.Downloads.Artifact( path, -1, null, - library.url + path + library.url() + path ), null ), - library.name, + library.name(), new HashMap<>(), new Rules(true) ); diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/McApi.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/McApi.java index d8a4bd8..5a3acd7 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/McApi.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/McApi.java @@ -1,10 +1,10 @@ package io.gitlab.jfronny.inceptum.launcher.api; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.mojang.AssetIndex.GC_AssetIndex; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.mojang.JvmFileInfo.GC_JvmFileInfo; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.mojang.JvmInfo.GC_JvmInfo; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.mojang.VersionInfo.GC_VersionInfo; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.mojang.VersionsList.GC_VersionsList; +import io.gitlab.jfronny.inceptum.launcher.model.mojang.GC_AssetIndex; +import io.gitlab.jfronny.inceptum.launcher.model.mojang.GC_JvmFileInfo; +import io.gitlab.jfronny.inceptum.launcher.model.mojang.GC_JvmInfo; +import io.gitlab.jfronny.inceptum.launcher.model.mojang.GC_VersionInfo; +import io.gitlab.jfronny.inceptum.launcher.model.mojang.GC_VersionsList; import io.gitlab.jfronny.commons.OSUtils; import io.gitlab.jfronny.inceptum.common.MetaHolder; import io.gitlab.jfronny.inceptum.common.Net; @@ -48,22 +48,22 @@ public class McApi { // 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); Map> vms = switch (OSUtils.TYPE) { - case WINDOWS -> info.windowsX64; - case LINUX -> info.linux; - case MAC_OS -> info.macOs; + case WINDOWS -> info.windowsX64(); + case LINUX -> info.linux(); + case MAC_OS -> info.macOs(); }; - List vmList = vms[component]; + List vmList = vms.get(component); if (vmList == null) 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; + if (jvm.version().name().startsWith(Integer.toString(majorVersion))) { + return downloadObject(jvm.manifest().url, jvm.manifest().sha1, GC_JvmFileInfo::read).files(); } } throw new IOException("JVM not found"); } public static void downloadAsset(AssetIndex.Asset asset, Path path) throws IOException, URISyntaxException { - Net.downloadFile("https://resources.download.minecraft.net/" + asset.hash.substring(0, 2) + "/" + asset.hash, asset.hash, path); + Net.downloadFile("https://resources.download.minecraft.net/" + asset.hash().substring(0, 2) + "/" + asset.hash(), asset.hash(), path); } } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/ModrinthApi.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/ModrinthApi.java index 453cb37..49f0f83 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/ModrinthApi.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/ModrinthApi.java @@ -1,8 +1,8 @@ package io.gitlab.jfronny.inceptum.launcher.api; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.modrinth.ModrinthProject.GC_ModrinthProject; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.modrinth.ModrinthSearchResult.GC_ModrinthSearchResult; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.modrinth.ModrinthVersion.GC_ModrinthVersion; +import io.gitlab.jfronny.inceptum.launcher.model.modrinth.GC_ModrinthProject; +import io.gitlab.jfronny.inceptum.launcher.model.modrinth.GC_ModrinthSearchResult; +import io.gitlab.jfronny.inceptum.launcher.model.modrinth.GC_ModrinthVersion; import io.gitlab.jfronny.gson.compile.util.GList; import io.gitlab.jfronny.gson.stream.JsonReader; import io.gitlab.jfronny.inceptum.common.Net; @@ -38,7 +38,7 @@ public class ModrinthApi { return GList.read(r, GC_ModrinthVersion::read); } }); - versions.sort(Comparator.comparing(version -> version.date_published)); + versions.sort(Comparator.comparing(ModrinthVersion::date_published)); return versions; } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/AccountManager.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/AccountManager.java index 67eccdd..53a99d3 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/AccountManager.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/AccountManager.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.api.account; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.api.account.MicrosoftAccount.GC_MicrosoftAccount; +import io.gitlab.jfronny.inceptum.launcher.api.account.GC_MicrosoftAccount; import io.gitlab.jfronny.commons.ref.R; import io.gitlab.jfronny.gson.compile.util.GList; import io.gitlab.jfronny.gson.stream.JsonReader; @@ -28,7 +28,7 @@ public class AccountManager { } public static boolean accountMissing() { - return ACCOUNTS.isEmpty; + return ACCOUNTS.isEmpty(); } public static List getAccounts() { @@ -81,7 +81,7 @@ public class AccountManager { if (ACCOUNTS.size() == 1) switchAccount(null); else - switchAccount(ACCOUNTS[0]); + switchAccount(ACCOUNTS.get(0)); } ACCOUNTS.remove(account); saveAccounts(); diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/MicrosoftAccount.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/MicrosoftAccount.java index 5e417ef..e351f81 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/MicrosoftAccount.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/MicrosoftAccount.java @@ -58,14 +58,14 @@ public class MicrosoftAccount { public boolean mustLogin; public MicrosoftAccount(MicrosoftAccountMeta meta) { - this.accountId = meta.accountId; - this.minecraftUsername = meta.minecraftUsername; - this.uuid = meta.uuid; - this.accessToken = meta.accessToken; - this.oauthToken = meta.oauthToken; - this.xstsAuth = meta.xstsAuth; - this.accessTokenExpiresAt = meta.accessTokenExpiresAt; - this.mustLogin = meta.mustLogin; + this.accountId = meta.accountId(); + this.minecraftUsername = meta.minecraftUsername(); + this.uuid = meta.uuid(); + this.accessToken = meta.accessToken(); + this.oauthToken = meta.oauthToken(); + this.xstsAuth = meta.xstsAuth(); + this.accessTokenExpiresAt = meta.accessTokenExpiresAt(); + this.mustLogin = meta.mustLogin(); } public MicrosoftAccountMeta toMeta() { @@ -90,14 +90,14 @@ public class MicrosoftAccount { LoginResponse loginResponse, Profile profile) { this.oauthToken = oauthTokenResponse; this.xstsAuth = xstsAuthResponse; - this.accessToken = loginResponse.accessToken; - this.minecraftUsername = profile.name; - this.uuid = profile.id; - this.accountId = loginResponse.username; + this.accessToken = loginResponse.accessToken(); + this.minecraftUsername = profile.name(); + this.uuid = profile.id(); + this.accountId = loginResponse.username(); this.mustLogin = false; this.accessTokenExpiresAt = new Date(); - this.accessTokenExpiresAt.time += loginResponse.expiresIn * 1000; + this.accessTokenExpiresAt.setTime(this.accessTokenExpiresAt.getTime() + loginResponse.expiresIn() * 1000); } public String getAccessToken() { @@ -110,8 +110,8 @@ public class MicrosoftAccount { public String getCurrentUsername() throws IOException, URISyntaxException { Profile profile = MicrosoftAuthAPI.getMcProfile(accessToken); - if (profile.name == null) throw new IOException("Got null name"); - return profile.name; + if (profile.name() == null) throw new IOException("Got null name"); + return profile.name(); } public void updateSkinPreCheck() { @@ -120,11 +120,11 @@ public class MicrosoftAccount { public String getSkinUrl() throws IOException, URISyntaxException { Profile profile = MicrosoftAuthAPI.getMcProfile(accessToken); - return Optional.of(profile.skins).orElse(new ArrayList<>()) + return Optional.of(profile.skins()).orElse(new ArrayList<>()) .stream() - .filter(s -> s.state.equalsIgnoreCase("ACTIVE")) + .filter(s -> s.state().equalsIgnoreCase("ACTIVE")) .findFirst() - .map(s -> s.url) + .map(Profile.Skin::url) .orElse(null); } @@ -134,9 +134,9 @@ public class MicrosoftAccount { public boolean refreshAccessToken(boolean force) { try { - if (force || new Date().after(this.oauthToken.expiresAt)) { + if (force || new Date().after(this.oauthToken.expiresAt())) { Utils.LOGGER.info("Oauth token expired. Attempting to refresh"); - OauthTokenResponse oauthTokenResponse = MicrosoftAuthAPI.refreshAccessToken(oauthToken.refreshToken); + OauthTokenResponse oauthTokenResponse = MicrosoftAuthAPI.refreshAccessToken(oauthToken.refreshToken()); if (oauthTokenResponse == null) { mustLogin = true; @@ -150,10 +150,10 @@ public class MicrosoftAccount { AccountManager.saveAccounts(); } - if (force || new Date().after(this.xstsAuth.notAfter)) { + if (force || new Date().after(this.xstsAuth.notAfter())) { Utils.LOGGER.info("xsts auth expired. Attempting to get new auth"); - XboxLiveAuthResponse xboxLiveAuthResponse = MicrosoftAuthAPI.getXBLToken(this.oauthToken.accessToken); - this.xstsAuth = MicrosoftAuthAPI.getXstsToken(xboxLiveAuthResponse.token); + XboxLiveAuthResponse xboxLiveAuthResponse = MicrosoftAuthAPI.getXBLToken(this.oauthToken.accessToken()); + this.xstsAuth = MicrosoftAuthAPI.getXstsToken(xboxLiveAuthResponse.token()); if (xstsAuth == null) { mustLogin = true; @@ -166,7 +166,7 @@ public class MicrosoftAccount { } if (force || new Date().after(this.accessTokenExpiresAt)) { - LoginResponse loginResponse = MicrosoftAuthAPI.loginToMinecraft(identityToken); + LoginResponse loginResponse = MicrosoftAuthAPI.loginToMinecraft(getIdentityToken()); if (loginResponse == null) { mustLogin = true; @@ -175,11 +175,11 @@ public class MicrosoftAccount { return false; } - this.accessToken = loginResponse.accessToken; - this.accountId = loginResponse.username; + this.accessToken = loginResponse.accessToken(); + this.accountId = loginResponse.username(); this.accessTokenExpiresAt = new Date(); - this.accessTokenExpiresAt.time += loginResponse.expiresIn * 1000; + this.accessTokenExpiresAt.setTime(this.accessTokenExpiresAt.getTime() + loginResponse.expiresIn() * 1000); AccountManager.saveAccounts(); } @@ -195,7 +195,7 @@ public class MicrosoftAccount { } private String getIdentityToken() { - return "XBL3.0 x=" + xstsAuth.displayClaims.xui[0].uhs + ";" + xstsAuth.token; + return "XBL3.0 x=" + xstsAuth.displayClaims().xui().get(0).uhs() + ";" + xstsAuth.token(); } public boolean ensureAccessTokenValid() { diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/MicrosoftAuthAPI.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/MicrosoftAuthAPI.java index 4dd1aaa..42b51e6 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/MicrosoftAuthAPI.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/MicrosoftAuthAPI.java @@ -1,13 +1,13 @@ package io.gitlab.jfronny.inceptum.launcher.api.account; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.microsoft.Entitlements.GC_Entitlements; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.microsoft.Profile.GC_Profile; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.microsoft.request.LoginRequest.GC_LoginRequest; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.microsoft.request.XblTokenRequest.GC_XblTokenRequest; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.microsoft.request.XstsTokenRequest.GC_XstsTokenRequest; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.microsoft.response.LoginResponse.GC_LoginResponse; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.microsoft.response.OauthTokenResponse.GC_OauthTokenResponse; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.microsoft.response.XboxLiveAuthResponse.GC_XboxLiveAuthResponse; +import io.gitlab.jfronny.inceptum.launcher.model.microsoft.GC_Entitlements; +import io.gitlab.jfronny.inceptum.launcher.model.microsoft.GC_Profile; +import io.gitlab.jfronny.inceptum.launcher.model.microsoft.request.GC_LoginRequest; +import io.gitlab.jfronny.inceptum.launcher.model.microsoft.request.GC_XblTokenRequest; +import io.gitlab.jfronny.inceptum.launcher.model.microsoft.request.GC_XstsTokenRequest; +import io.gitlab.jfronny.inceptum.launcher.model.microsoft.response.GC_LoginResponse; +import io.gitlab.jfronny.inceptum.launcher.model.microsoft.response.GC_OauthTokenResponse; +import io.gitlab.jfronny.inceptum.launcher.model.microsoft.response.GC_XboxLiveAuthResponse; import io.gitlab.jfronny.commons.HttpUtils; import io.gitlab.jfronny.inceptum.launcher.model.microsoft.Entitlements; import io.gitlab.jfronny.inceptum.launcher.model.microsoft.Profile; diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/MicrosoftAuthServer.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/MicrosoftAuthServer.java index 07d4920..32e4820 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/MicrosoftAuthServer.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/api/account/MicrosoftAuthServer.java @@ -1,11 +1,12 @@ package io.gitlab.jfronny.inceptum.launcher.api.account; +import io.gitlab.jfronny.commons.jlhttp.JLHTTPServer; +import io.gitlab.jfronny.commons.jlhttp.util.VirtualHost; import io.gitlab.jfronny.inceptum.common.Utils; import io.gitlab.jfronny.inceptum.launcher.LauncherEnv; import io.gitlab.jfronny.inceptum.launcher.model.microsoft.Entitlements; import io.gitlab.jfronny.inceptum.launcher.model.microsoft.Profile; import io.gitlab.jfronny.inceptum.launcher.model.microsoft.response.*; -import net.freeutils.httpserver.HTTPServer; import org.jetbrains.annotations.Nullable; import java.io.Closeable; @@ -15,8 +16,8 @@ import java.nio.charset.StandardCharsets; import java.util.Objects; public class MicrosoftAuthServer implements Closeable { - private static final HTTPServer server = new HTTPServer(MicrosoftAuthAPI.MICROSOFT_LOGIN_REDIRECT_PORT); - private static final HTTPServer.VirtualHost host = server.getVirtualHost(null); + private static final JLHTTPServer server = new JLHTTPServer(MicrosoftAuthAPI.MICROSOFT_LOGIN_REDIRECT_PORT); + private static final VirtualHost host = server.getVirtualHost(null); private final MicrosoftAccount previous; @@ -26,33 +27,33 @@ public class MicrosoftAuthServer implements Closeable { public void start() throws IOException { host.addContext("/", (req, res) -> { - if (req.params.containsKey("error")) { - res.headers.add("Content-Type", "text/plain"); + if (req.getParams().containsKey("error")) { + res.getHeaders().add("Content-Type", "text/plain"); res.send(500, "Error logging in. Check console for more information"); Utils.LOGGER.error("Error logging into Microsoft account: " + URLDecoder - .decode(req.params["error_description"], StandardCharsets.UTF_8)); + .decode(req.getParams().get("error_description"), StandardCharsets.UTF_8)); close(); return 0; } - if (!req.params.containsKey("code")) { - res.headers.add("Content-Type", "text/plain"); + if (!req.getParams().containsKey("code")) { + res.getHeaders().add("Content-Type", "text/plain"); res.send(400, "Code is missing"); close(); return 0; } try { - acquireAccessToken(req.params["code"]); + acquireAccessToken(req.getParams().get("code")); } catch (Exception e) { Utils.LOGGER.error("Error acquiring accessToken", e); - res.headers.add("Content-Type", "text/html"); + res.getHeaders().add("Content-Type", "text/html"); res.send(500, "Error logging in. Check console for more information"); close(); return 0; } - res.headers.add("Content-Type", "text/plain"); + res.getHeaders().add("Content-Type", "text/plain"); // #. {0} is the name of the launcher res.send(200, "Login complete. You can now close this window and go back to the Launcher"); close(); @@ -63,8 +64,8 @@ public class MicrosoftAuthServer implements Closeable { } private void addAccount(OauthTokenResponse oauthTokenResponse, XboxLiveAuthResponse xstsAuthResponse, LoginResponse loginResponse, Profile profile) { - if (this.previous != null || AccountManager.isAccountByName(loginResponse.username)) { - MicrosoftAccount account = (MicrosoftAccount) AccountManager.getAccountByName(loginResponse.username); + if (this.previous != null || AccountManager.isAccountByName(loginResponse.username())) { + MicrosoftAccount account = (MicrosoftAccount) AccountManager.getAccountByName(loginResponse.username()); if (account == null) { return; @@ -91,7 +92,7 @@ public class MicrosoftAuthServer implements Closeable { } private void acquireXBLToken(OauthTokenResponse oauthTokenResponse) throws Exception { - XboxLiveAuthResponse xblAuthResponse = MicrosoftAuthAPI.getXBLToken(oauthTokenResponse.accessToken); + XboxLiveAuthResponse xblAuthResponse = MicrosoftAuthAPI.getXBLToken(oauthTokenResponse.accessToken()); acquireXsts(oauthTokenResponse, xblAuthResponse.token()); } @@ -105,16 +106,16 @@ public class MicrosoftAuthServer implements Closeable { } private void acquireMinecraftToken(OauthTokenResponse oauthTokenResponse, XboxLiveAuthResponse xstsAuthResponse) throws Exception { - LoginResponse loginResponse = MicrosoftAuthAPI.loginToMinecraft("XBL3.0 x=" + xstsAuthResponse.displayClaims.xui[0].uhs + ";" + xstsAuthResponse.token); + LoginResponse loginResponse = MicrosoftAuthAPI.loginToMinecraft("XBL3.0 x=" + xstsAuthResponse.displayClaims().xui().get(0).uhs() + ";" + xstsAuthResponse.token()); if (loginResponse == null) { throw new Exception("Failed to login to Minecraft"); } - Entitlements entitlements = MicrosoftAuthAPI.getEntitlements(loginResponse.accessToken); + Entitlements entitlements = MicrosoftAuthAPI.getEntitlements(loginResponse.accessToken()); - if (!(entitlements.items.stream().anyMatch(i -> i.name.equalsIgnoreCase("product_minecraft")) - && entitlements.items.stream().anyMatch(i -> i.name.equalsIgnoreCase("game_minecraft")))) { + if (!(entitlements.items().stream().anyMatch(i -> i.name().equalsIgnoreCase("product_minecraft")) + && entitlements.items().stream().anyMatch(i -> i.name().equalsIgnoreCase("game_minecraft")))) { LauncherEnv.showError("This account doesn't have a valid purchase of Minecraft.\nPlease make sure you've bought the Java edition of Minecraft and then try again.", "Doesn't own Minecraft"); throw new Exception("Account does not own Minecraft"); } @@ -122,7 +123,7 @@ public class MicrosoftAuthServer implements Closeable { Profile profile = null; try { - profile = MicrosoftAuthAPI.getMcProfile(loginResponse.accessToken); + profile = MicrosoftAuthAPI.getMcProfile(loginResponse.accessToken()); } catch (Exception e) { LauncherEnv.showError(""" No Minecraft profiles were found for this account. Have you purchased Minecraft? diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/MicrosoftAccountAdapter.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/MicrosoftAccountAdapter.java index 83c51a7..8a636d8 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/MicrosoftAccountAdapter.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/MicrosoftAccountAdapter.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.gson; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.gson.MicrosoftAccountMeta.GC_MicrosoftAccountMeta; +import io.gitlab.jfronny.inceptum.launcher.gson.GC_MicrosoftAccountMeta; import io.gitlab.jfronny.gson.stream.JsonReader; import io.gitlab.jfronny.gson.stream.JsonWriter; import io.gitlab.jfronny.inceptum.launcher.api.account.MicrosoftAccount; diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/MinecraftArgumentAdapter.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/MinecraftArgumentAdapter.java index e3a2c18..82af1ab 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/MinecraftArgumentAdapter.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/MinecraftArgumentAdapter.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.gson; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.mojang.Rules.GC_Rules; +import io.gitlab.jfronny.inceptum.launcher.model.mojang.GC_Rules; import io.gitlab.jfronny.gson.JsonParseException; import io.gitlab.jfronny.gson.compile.util.GList; import io.gitlab.jfronny.gson.stream.*; diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/ModMetaSourcesAdapter.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/ModMetaSourcesAdapter.java index 4e2893a..169533b 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/ModMetaSourcesAdapter.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/ModMetaSourcesAdapter.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.gson; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.system.source.ModSource.GC_ModSource; +import io.gitlab.jfronny.inceptum.launcher.system.source.GC_ModSource; import io.gitlab.jfronny.gson.stream.JsonReader; import io.gitlab.jfronny.gson.stream.JsonWriter; import io.gitlab.jfronny.inceptum.launcher.model.inceptum.ModMeta.Sources; diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/ModSourceAdapter.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/ModSourceAdapter.java index 4234b3c..871784b 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/ModSourceAdapter.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/ModSourceAdapter.java @@ -14,25 +14,25 @@ public class ModSourceAdapter { writer.beginObject(); if (src instanceof ModrinthModSource mo) { writer.name("type").value("modrinth") - .name("id").value(mo.versionId); + .name("id").value(mo.getVersionId()); } else if (src instanceof DirectModSource di) { writer.name("type").value("direct") - .name("fileName").value(di.fileName) - .name("url").value(di.url) + .name("fileName").value(di.getFileName()) + .name("url").value(di.url()) .name("dependencies"); writer.beginArray(); - for (ModSource dependency : di.dependencies) { + for (ModSource dependency : di.dependencies()) { write(dependency, writer); } writer.endArray(); } else if (src instanceof CurseforgeModSource cu) { writer.name("type").value("curseforge"); - if (cu.shortName.matches("\\d+")) { - writer.name("projectId").value(cu.projectId); + if (cu.getShortName().matches("\\d+")) { + writer.name("projectId").value(cu.getProjectId()); } else { - writer.name("project").value(cu.shortName); + writer.name("project").value(cu.getShortName()); } - writer.name("fileId").value(cu.fileId); + writer.name("fileId").value(cu.getFileId()); } else throw new RuntimeException("ModSources with the type " + src.getClass() + " are not supported"); writer.endObject(); } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/RulesAdapter.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/RulesAdapter.java index 437a09d..9a02795 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/RulesAdapter.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/gson/RulesAdapter.java @@ -51,7 +51,7 @@ public class RulesAdapter { throw new JsonParseException("Unexpected action in argument: " + actionType); } if (hasFeatures) valid = false; - if (osName != null && !OSUtils.TYPE.mojName.equals(osName)) valid = false; + if (osName != null && !OSUtils.TYPE.getMojName().equals(osName)) valid = false; if (osVersion != null && !System.getProperty("os.version").matches(osVersion)) valid = false; if (actionType.equals("disallow")) valid = !valid; } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/model/inceptum/ModMeta.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/model/inceptum/ModMeta.java index 43a2d6a..7c34fd6 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/model/inceptum/ModMeta.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/model/inceptum/ModMeta.java @@ -86,7 +86,7 @@ public record ModMeta( boolean changed = false; if (!modrinth) { try { - addSource(new ModrinthModSource(ModrinthApi.getVersionByHash(sha1).id), gameVersion); + addSource(new ModrinthModSource(ModrinthApi.getVersionByHash(sha1).id()), gameVersion); changed = true; } catch (IOException e) { // not found @@ -95,9 +95,9 @@ public record ModMeta( if (!curseforge) { try { FingerprintMatchesResponse.Result cf = CurseforgeApi.checkFingerprint(murmur2); - if (!cf.exactMatches.isEmpty) { - FingerprintMatchesResponse.Result.Match f = cf.exactMatches[0]; - addSource(new CurseforgeModSource(f.id, f.file.id), gameVersion); + if (!cf.exactMatches().isEmpty()) { + FingerprintMatchesResponse.Result.Match f = cf.exactMatches().get(0); + addSource(new CurseforgeModSource(f.id(), f.file().id()), gameVersion); changed = true; } } catch (IOException | URISyntaxException e) { @@ -109,9 +109,9 @@ public record ModMeta( public void addSource(ModSource source, String gameVersion) { try { - sources[source] = source.getUpdate(gameVersion); + sources.put(source, source.getUpdate(gameVersion)); } catch (IOException e) { - Utils.LOGGER.error("Could not check " + source.name + " for updates", e); + Utils.LOGGER.error("Could not check " + source.getName() + " for updates", e); } } } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/model/microsoft/response/OauthTokenResponse.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/model/microsoft/response/OauthTokenResponse.java index 89e51b3..0406491 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/model/microsoft/response/OauthTokenResponse.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/model/microsoft/response/OauthTokenResponse.java @@ -32,7 +32,7 @@ public record OauthTokenResponse( private static Date getExpiresAt(Date expiresAt, long expiresIn) { if (expiresAt == null) { expiresAt = new Date(); - expiresAt.time += expiresIn * 1000; + expiresAt.setTime(expiresAt.getTime() + expiresIn * 1000); } return expiresAt; } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/CleanupFileVisitor.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/CleanupFileVisitor.java index 5e61fbd..9a51530 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/CleanupFileVisitor.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/CleanupFileVisitor.java @@ -9,7 +9,7 @@ import java.nio.file.attribute.BasicFileAttributes; public class CleanupFileVisitor implements FileVisitor { @Override public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes basicFileAttributes) throws IOException { - if (JFiles.list(path).isEmpty) { + if (JFiles.list(path).isEmpty()) { Files.delete(path); return FileVisitResult.SKIP_SUBTREE; } @@ -28,7 +28,7 @@ public class CleanupFileVisitor implements FileVisitor { @Override public FileVisitResult postVisitDirectory(Path path, IOException e) throws IOException { - if (Files.exists(path) && JFiles.list(path).isEmpty) { + if (Files.exists(path) && JFiles.list(path).isEmpty()) { Files.delete(path); } return FileVisitResult.CONTINUE; diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/CurseForgeExporter.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/CurseForgeExporter.java index 4acc1cf..8dddccb 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/CurseForgeExporter.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/CurseForgeExporter.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.system.exporter; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.curseforge.CurseforgeModpackManifest.GC_CurseforgeModpackManifest; +import io.gitlab.jfronny.inceptum.launcher.model.curseforge.GC_CurseforgeModpackManifest; import io.gitlab.jfronny.inceptum.common.InceptumConfig; import io.gitlab.jfronny.inceptum.launcher.model.curseforge.CurseforgeModpackManifest; import io.gitlab.jfronny.inceptum.launcher.system.instance.Instance; @@ -24,20 +24,20 @@ public class CurseForgeExporter extends Exporter { protected CurseforgeModpackManifest generateManifests(Path root, Instance instance, String version) throws IOException { CurseforgeModpackManifest manifest = new CurseforgeModpackManifest( new CurseforgeModpackManifest.Minecraft( - instance.gameVersion, + instance.getGameVersion(), new LinkedHashSet<>() ), "minecraftModpack", 1, - instance.name, + instance.getName(), version, InceptumConfig.authorName, null, // files OVERRIDES_DIR_DEFAULT ); - if (instance.isFabric) { - manifest.minecraft.modLoaders.add(new CurseforgeModpackManifest.Minecraft.ModLoader( - "fabric-" + instance.loaderVersion, + if (instance.isFabric()) { + manifest.minecraft().modLoaders().add(new CurseforgeModpackManifest.Minecraft.ModLoader( + "fabric-" + instance.getLoaderVersion(), true )); } @@ -48,17 +48,17 @@ public class CurseForgeExporter extends Exporter { @Override protected void addMods(Path root, Instance instance, Iterable mods, CurseforgeModpackManifest manifest, Path modsOverrides) throws IOException { modsLoop: for (Mod mod : mods) { - if (mod.needsInject) { - for (ModSource source : mod.metadata.sources.keySet()) { + if (mod.getNeedsInject()) { + for (ModSource source : mod.getMetadata().sources().keySet()) { if (source instanceof CurseforgeModSource cms) { - manifest.files.add(cms.toManifest()); + manifest.files().add(cms.toManifest()); continue modsLoop; } } } // Not available on CF Files.createDirectories(modsOverrides); - Files.copy(mod.jarPath, modsOverrides.resolve(mod.jarPath.fileName.toString())); + Files.copy(mod.getJarPath(), modsOverrides.resolve(mod.getJarPath().getFileName().toString())); } GC_CurseforgeModpackManifest.write(manifest, root.resolve("manifest.json")); } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/Exporter.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/Exporter.java index 0f2bf1e..31af3a5 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/Exporter.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/Exporter.java @@ -1,5 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.system.exporter; +import io.gitlab.jfronny.commons.StreamIterable; import io.gitlab.jfronny.inceptum.common.Utils; import io.gitlab.jfronny.inceptum.launcher.system.instance.Instance; import io.gitlab.jfronny.inceptum.launcher.system.instance.Mod; @@ -32,18 +33,18 @@ public abstract class Exporter { Path root = fs.getPath("."); Path overrides = fs.getPath(overridesDirName); state.incrementStep("Preparing manifests"); - Manifest manifest = generateManifests(root, instance, instance.meta.instanceVersion); - if (instance.isFabric) { + Manifest manifest = generateManifests(root, instance, instance.meta().instanceVersion); + if (instance.isFabric()) { state.incrementStep("Adding mods"); - addMods(root, instance, instance.mods.stream().filter(mod -> { - if (!mod.isEnabled) return false; - state.updateStep(mod.name); + addMods(root, instance, instance.getMods().stream().filter(mod -> { + if (!mod.isEnabled()) return false; + state.updateStep(mod.getName()); return true; }).toList(), manifest, overrides.resolve("mods")); } state.incrementStep("Adding files"); - filesLoop: for (Path path : IgnoringWalk.walk(instance.path)) { - Path relativePath = instance.path.relativize(path).normalize(); + filesLoop: for (Path path : new StreamIterable<>(IgnoringWalk.walk(instance.path()))) { + Path relativePath = instance.path().relativize(path).normalize(); Path target = overrides; for (Path segment : relativePath) { if (target == overrides && segment.toString().equals("mods")) continue filesLoop; @@ -51,7 +52,7 @@ public abstract class Exporter { target = target.resolve(segment.toString()); } state.updateStep(relativePath.toString()); - Files.createDirectories(target.parent); + Files.createDirectories(target.getParent()); Files.copy(path, target); } state.incrementStep("Cleaning up"); @@ -74,6 +75,6 @@ public abstract class Exporter { } public String getDefaultFileName(Instance instance) { - return instance.name + " " + instance.meta.instanceVersion + " (" + name + ")." + fileExtension; + return instance.getName() + " " + instance.meta().instanceVersion + " (" + name + ")." + fileExtension; } } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/ModrinthExporter.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/ModrinthExporter.java index a155806..c98bdf2 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/ModrinthExporter.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/ModrinthExporter.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.system.exporter; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.modrinth.ModrinthModpackManifest.GC_ModrinthModpackManifest; +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; import io.gitlab.jfronny.inceptum.launcher.system.instance.Mod; @@ -23,13 +23,13 @@ public class ModrinthExporter extends Exporter { 1, "minecraft", version, - instance.name, + instance.getName(), null, // summary new ArrayList<>(), new ModrinthModpackManifest.Dependencies( - instance.gameVersion, + instance.getGameVersion(), null, - instance.isFabric ? instance.loaderVersion : null, + instance.isFabric() ? instance.getLoaderVersion() : null, null ) ); @@ -40,17 +40,17 @@ public class ModrinthExporter extends Exporter { @Override protected void addMods(Path root, Instance instance, Iterable mods, ModrinthModpackManifest manifest, Path modsOverrides) throws IOException { modsLoop: for (Mod mod : mods) { - if (mod.needsInject) { - for (ModSource source : mod.metadata.sources.keySet()) { + if (mod.getNeedsInject()) { + for (ModSource source : mod.getMetadata().sources().keySet()) { if (source instanceof ModrinthModSource cms) { - manifest.files.add(cms.toManifest()); + manifest.files().add(cms.toManifest()); continue modsLoop; } } } // Not available on modrinth Files.createDirectories(modsOverrides); - Files.copy(mod.jarPath, modsOverrides.resolve(mod.jarPath.fileName.toString())); + Files.copy(mod.getJarPath(), modsOverrides.resolve(mod.getJarPath().getFileName().toString())); } GC_ModrinthModpackManifest.write(manifest, root.resolve("modrinth.index.json")); } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/MultiMCExporter.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/MultiMCExporter.java index 86a4e4e..ec93340 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/MultiMCExporter.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/exporter/MultiMCExporter.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.system.exporter; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.multimc.MMCPackMeta.GC_MMCPackMeta; +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; import io.gitlab.jfronny.inceptum.launcher.system.instance.Mod; @@ -43,16 +43,16 @@ public class MultiMCExporter extends Exporter { name=%s notes= totalTimePlayed=0 - """, Instant.now().toEpochMilli(), instance.name)); + """, Instant.now().toEpochMilli(), instance.getName())); } { MMCPackMeta manifest = new MMCPackMeta(new ArrayList<>(), 1); //TODO get version automatically - manifest.components.add(new MMCPackMeta.Component(true, false, "org.lwjgl3", "3.2.2")); - manifest.components.add(new MMCPackMeta.Component(false, true, "net.minecraft", instance.gameVersion)); + manifest.components().add(new MMCPackMeta.Component(true, false, "org.lwjgl3", "3.2.2")); + manifest.components().add(new MMCPackMeta.Component(false, true, "net.minecraft", instance.getGameVersion())); if (instance.isFabric()) { - manifest.components.add(new MMCPackMeta.Component(true, false, "net.fabricmc.intermediary", instance.gameVersion)); - manifest.components.add(new MMCPackMeta.Component(false, false, "net.fabricmc.fabric-loader", instance.loaderVersion)); + 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")); return manifest; @@ -62,6 +62,6 @@ public class MultiMCExporter extends Exporter { @Override protected void addMods(Path root, Instance instance, Iterable mods, MMCPackMeta mmcPackMeta, Path modsOverrides) throws IOException { Files.createDirectories(modsOverrides); - for (Mod mod : mods) Files.copy(mod.jarPath, modsOverrides.resolve(mod.jarPath.fileName.toString())); + for (Mod mod : mods) Files.copy(mod.getJarPath(), modsOverrides.resolve(mod.getJarPath().getFileName().toString())); } } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/CurseForgeImporter.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/CurseForgeImporter.java index 50aeff4..6905b9b 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/CurseForgeImporter.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/CurseForgeImporter.java @@ -1,7 +1,7 @@ package io.gitlab.jfronny.inceptum.launcher.system.importer; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.curseforge.CurseforgeModpackManifest.GC_CurseforgeModpackManifest; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.inceptum.ModMeta.GC_ModMeta; +import io.gitlab.jfronny.inceptum.launcher.model.curseforge.GC_CurseforgeModpackManifest; +import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_ModMeta; import io.gitlab.jfronny.inceptum.launcher.model.curseforge.CurseforgeModpackManifest; import io.gitlab.jfronny.inceptum.launcher.model.inceptum.ModMeta; import io.gitlab.jfronny.inceptum.launcher.system.instance.ModPath; @@ -20,34 +20,34 @@ public class CurseForgeImporter extends Importer { @Override protected IntermediaryManifest validateManifest(CurseforgeModpackManifest manifest, Path sourceRoot) throws IOException { - if (manifest.manifestVersion != 1) throw new IOException("Unsupported CurseForge modpack manifest version"); - if (!"minecraftModpack".equals(manifest.manifestType)) throw new IOException("Invalid input: not a minecraft modpack"); - if (manifest.minecraft == null) throw new IOException("Modpack missing minecraft metadata"); - if (manifest.minecraft.version == null) throw new IOException("Modpack missing minecraft version"); + if (manifest.manifestVersion() != 1) throw new IOException("Unsupported CurseForge modpack manifest version"); + if (!"minecraftModpack".equals(manifest.manifestType())) throw new IOException("Invalid input: not a minecraft modpack"); + if (manifest.minecraft() == null) throw new IOException("Modpack missing minecraft metadata"); + if (manifest.minecraft().version() == null) throw new IOException("Modpack missing minecraft version"); String fabric = null; - if (manifest.minecraft.modLoaders != null) { - for (CurseforgeModpackManifest.Minecraft.ModLoader loader : manifest.minecraft.modLoaders) { + if (manifest.minecraft().modLoaders() != null) { + for (CurseforgeModpackManifest.Minecraft.ModLoader loader : manifest.minecraft().modLoaders()) { final String idPrefix = "fabric-"; - if (!loader.id.startsWith(idPrefix)) throw new IOException("Unsupported mod loader"); - fabric = loader.id.substring(idPrefix.length()); + if (!loader.id().startsWith(idPrefix)) throw new IOException("Unsupported mod loader"); + fabric = loader.id().substring(idPrefix.length()); } } - return new IntermediaryManifest(manifest.name, manifest.overrides, manifest.minecraft.version, fabric); + return new IntermediaryManifest(manifest.name(), manifest.overrides(), manifest.minecraft().version(), fabric); } @Override protected void downloadMods(CurseforgeModpackManifest manifest, Path instanceDir, ProcessState state) throws IOException { - if (manifest.files != null) { + if (manifest.files() != null) { Path modsPath = instanceDir.resolve("mods"); - for (CurseforgeModpackManifest.File file : manifest.files) { - if (!file.required) continue; - CurseforgeModSource source = new CurseforgeModSource(file.projectID, file.fileID); - state.updateStep("Downloading " + source.name); + for (CurseforgeModpackManifest.File file : manifest.files()) { + if (!file.required()) continue; + CurseforgeModSource source = new CurseforgeModSource(file.projectID(), file.fileID()); + state.updateStep("Downloading " + source.getName()); ModDownload download = source.download(); - ModMeta imod = ModMeta.of(download.sha1, download.murmur2, source, manifest.minecraft.version); + ModMeta imod = ModMeta.of(download.sha1(), download.murmur2(), source, manifest.minecraft().version()); Files.createDirectories(modsPath); - GC_ModMeta.write(imod, modsPath.resolve(source.shortName + ModPath.EXT_IMOD)); + GC_ModMeta.write(imod, modsPath.resolve(source.getShortName() + ModPath.EXT_IMOD)); } } } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/Importer.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/Importer.java index d15868c..448ca4f 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/Importer.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/Importer.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.system.importer; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta.GC_InstanceMeta; +import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_InstanceMeta; import io.gitlab.jfronny.commons.io.JFiles; import io.gitlab.jfronny.commons.throwable.ThrowingFunction; import io.gitlab.jfronny.inceptum.common.MetaHolder; @@ -38,7 +38,7 @@ public abstract class Importer { protected abstract void downloadMods(T manifest, Path instanceDir, ProcessState state) throws IOException; private String createVersionString(String gameVersion, @Nullable String fabricVersion) throws IOException { - if (McApi.getVersions().versions.stream().filter(v -> v.id.equals(gameVersion)).findFirst().isEmpty) { + if (McApi.getVersions().versions().stream().filter(v -> v.id.equals(gameVersion)).findFirst().isEmpty()) { throw new IOException("Invalid minecraft version: " + gameVersion); } if (fabricVersion == null) { @@ -50,45 +50,45 @@ public abstract class Importer { } public Instance importPack(Path sourceRoot, ProcessState state) throws IOException { - if (state.isCancelled) return null; + if (state.isCancelled()) return null; state.incrementStep("Generating skeleton"); T manifest = manifestClass.apply(sourceRoot.resolve(manifestFile)); IntermediaryManifest man = validateManifest(manifest, sourceRoot); - String name = man.name; + String name = man.name(); if (name == null || !Utils.VALID_FILENAME.matcher(name).matches()) name = "New Pack"; name = InstanceNameTool.getNextValid(name); final Path iDir = MetaHolder.INSTANCE_DIR.resolve(name).toAbsolutePath().normalize(); Instance.setSetupLock(iDir, true); InstanceMeta meta = new InstanceMeta(); - meta.gameVersion = createVersionString(man.gameVersion, man.fabricVersion); + meta.gameVersion = createVersionString(man.gameVersion(), man.fabricVersion()); GC_InstanceMeta.write(meta, iDir.resolve(Instance.CONFIG_NAME)); - if (state.isCancelled) { + if (state.isCancelled()) { JFiles.deleteRecursive(iDir); return null; } state.incrementStep("Downloading mods"); downloadMods(manifest, iDir, state); - if (state.isCancelled) { + if (state.isCancelled()) { JFiles.deleteRecursive(iDir); return null; } state.incrementStep("Adding overrides"); if (man.overridesPath() != null) { - Path overridesPath = sourceRoot.resolve(man.overridesPath); + Path overridesPath = sourceRoot.resolve(man.overridesPath()); JFiles.listTo(overridesPath, path -> { - JFiles.copyRecursive(path, iDir.resolve(path.fileName.toString())); + JFiles.copyRecursive(path, iDir.resolve(path.getFileName().toString())); }); } - if (state.isCancelled) { + if (state.isCancelled()) { JFiles.deleteRecursive(iDir); return null; } Instance.setSetupLock(iDir, false); Instance instance = InstanceList.read(iDir); Steps.reDownload(instance, state); - if (state.isCancelled) { + if (state.isCancelled()) { JFiles.deleteRecursive(iDir); return null; } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/Importers.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/Importers.java index 3812a42..9e688c7 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/Importers.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/Importers.java @@ -42,7 +42,7 @@ public class Importers { state.updateStep("Downloading Pack"); Matcher m = CURSEFORGE_URL.matcher(url); if (m.matches()) { - url = CurseforgeApi.getFile(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2))).downloadUrl; + url = CurseforgeApi.getFile(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2))).downloadUrl(); } Net.downloadFile(url, tmp); return importPack(tmp, state); diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/ModrinthImporter.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/ModrinthImporter.java index 35ec5c2..7c41de9 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/ModrinthImporter.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/ModrinthImporter.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.system.importer; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.modrinth.ModrinthModpackManifest.GC_ModrinthModpackManifest; +import io.gitlab.jfronny.inceptum.launcher.model.modrinth.GC_ModrinthModpackManifest; import io.gitlab.jfronny.inceptum.common.Net; import io.gitlab.jfronny.inceptum.launcher.model.modrinth.ModrinthModpackManifest; import io.gitlab.jfronny.inceptum.launcher.util.ProcessState; @@ -16,37 +16,37 @@ public class ModrinthImporter extends Importer { @Override protected IntermediaryManifest validateManifest(ModrinthModpackManifest manifest, Path sourceRoot) throws IOException { - if (manifest.formatVersion != 1) throw new IOException("Unsupported Modrinth modpack manifest version"); - if (!"minecraft".equals(manifest.game)) throw new IOException("Invalid input: not a minecraft modpack"); - if (manifest.dependencies == null) throw new IOException("Modrinth manifest lacks dependency block"); - if (manifest.dependencies.minecraft == null) throw new IOException("Could not find minecraft version"); - if (manifest.dependencies.fabricLoader == null) { - for (ModrinthModpackManifest.File file : manifest.files) { - if (file.path == null) { + if (manifest.formatVersion() != 1) throw new IOException("Unsupported Modrinth modpack manifest version"); + if (!"minecraft".equals(manifest.game())) throw new IOException("Invalid input: not a minecraft modpack"); + if (manifest.dependencies() == null) throw new IOException("Modrinth manifest lacks dependency block"); + if (manifest.dependencies().minecraft() == null) throw new IOException("Could not find minecraft version"); + if (manifest.dependencies().fabricLoader() == null) { + for (ModrinthModpackManifest.File file : manifest.files()) { + if (file.path() == null) { throw new IOException("File lacks path"); } - if (file.path.startsWith("mods")) { + if (file.path().startsWith("mods")) { throw new IOException("Found mod files but no fabric loader. Other loaders are unsupported!"); } } } return new IntermediaryManifest( - manifest.name, + manifest.name(), "overrides", - manifest.dependencies.minecraft, - manifest.dependencies.fabricLoader + manifest.dependencies().minecraft(), + manifest.dependencies().fabricLoader() ); } @Override protected void downloadMods(ModrinthModpackManifest manifest, Path instanceDir, ProcessState state) throws IOException { - if (manifest.files != null) { - filesLoop: for (ModrinthModpackManifest.File file : manifest.files) { - Path path = instanceDir.parent.resolve(file.path).toAbsolutePath().normalize(); + if (manifest.files() != null) { + filesLoop: for (ModrinthModpackManifest.File file : manifest.files()) { + Path path = instanceDir.getParent().resolve(file.path()).toAbsolutePath().normalize(); if (!path.startsWith(instanceDir)) throw new IOException("Pack attempted to write file outside instance. This is unsupported!"); - String sha1 = file.hashes.sha1; + String sha1 = file.hashes().sha1(); IOException failedDownload = new IOException("Could not download file"); - for (String url : file.downloads) { + for (String url : file.downloads()) { try { Net.downloadFile(url, sha1, path); continue filesLoop; diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/MultiMCImporter.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/MultiMCImporter.java index 1750a51..67f9985 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/MultiMCImporter.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/MultiMCImporter.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.system.importer; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.multimc.MMCPackMeta.GC_MMCPackMeta; +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; @@ -16,8 +16,8 @@ public class MultiMCImporter extends Importer { @Override protected IntermediaryManifest validateManifest(MMCPackMeta manifest, Path sourceRoot) throws IOException { - if (manifest.formatVersion != 1) throw new IOException("Unsupported MultiMC format version"); - if (manifest.components == null) throw new IOException("MultiMC pack missing components"); + if (manifest.formatVersion() != 1) throw new IOException("Unsupported MultiMC format version"); + if (manifest.components() == null) throw new IOException("MultiMC pack missing components"); String gameVersion = null; String fabricVersion = null; String name = null; @@ -31,9 +31,9 @@ public class MultiMCImporter extends Importer { .orElse(null); } } - for (MMCPackMeta.Component component : manifest.components) { - if ("net.minecraft".equals(component.uid)) gameVersion = component.version; - if ("net.fabricmc.fabric-loader".equals(component.uid)) fabricVersion = component.version; + for (MMCPackMeta.Component component : manifest.components()) { + if ("net.minecraft".equals(component.uid())) gameVersion = component.version(); + if ("net.fabricmc.fabric-loader".equals(component.uid())) fabricVersion = component.version(); } if (gameVersion == null) throw new IOException("Pack lacks minecraft component"); return new IntermediaryManifest(name, ".minecraft", gameVersion, fabricVersion); diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/Instance.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/Instance.java index a9085e5..7916d28 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/Instance.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/Instance.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.system.instance; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta.GC_InstanceMeta; +import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_InstanceMeta; import io.gitlab.jfronny.commons.ref.R; import io.gitlab.jfronny.inceptum.common.Utils; import io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta; @@ -21,7 +21,7 @@ public record Instance(String id, Path path, InstanceMeta meta, ModsDirScanner m public static final String CONFIG_NAME = "instance.json"; public Instance(Path path, InstanceMeta meta) throws IOException { - this(generateId(path.fileName.toString()), path, meta, ModsDirScanner.get(path.resolve("mods"), meta)); + this(generateId(path.getFileName().toString()), path, meta, ModsDirScanner.get(path.resolve("mods"), meta)); } public Instance(String id, Path path, InstanceMeta meta, ModsDirScanner mds) { @@ -54,7 +54,7 @@ public record Instance(String id, Path path, InstanceMeta meta, ModsDirScanner m long time1 = meta.lastLaunched == null ? 0 : meta.lastLaunched; long time2 = entry.meta.lastLaunched == null ? 0 : entry.meta.lastLaunched; if (time1 == 0) { - if (time2 == 0) return path.fileName.toString().compareTo(entry.path.fileName.toString()); + if (time2 == 0) return path.getFileName().toString().compareTo(entry.path.getFileName().toString()); return -1; } if (time2 == 0) return 1; @@ -63,7 +63,7 @@ public record Instance(String id, Path path, InstanceMeta meta, ModsDirScanner m @Override public String toString() { - return path.fileName.toString(); + return path.getFileName().toString(); } public Path getModsDir() { @@ -80,7 +80,7 @@ public record Instance(String id, Path path, InstanceMeta meta, ModsDirScanner m } public String getName() { - return path.fileName.toString(); + return path.getFileName().toString(); } public boolean isFabric() { @@ -118,7 +118,7 @@ public record Instance(String id, Path path, InstanceMeta meta, ModsDirScanner m return true; Files.delete(path.resolve(LOCK_NAME)); } catch (IOException e) { - Utils.LOGGER.error("Could not read running lock of " + name, e); + Utils.LOGGER.error("Could not read running lock of " + getName(), e); } return false; } @@ -139,7 +139,7 @@ public record Instance(String id, Path path, InstanceMeta meta, ModsDirScanner m } return true; } catch (IOException e) { - Utils.LOGGER.error("Could not read running lock of " + name, e); + Utils.LOGGER.error("Could not read running lock of " + getName(), e); } return false; } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/InstanceList.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/InstanceList.java index ddbcb80..ad75beb 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/InstanceList.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/InstanceList.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.system.instance; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta.GC_InstanceMeta; +import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_InstanceMeta; import io.gitlab.jfronny.commons.io.JFiles; import io.gitlab.jfronny.commons.throwable.ThrowingConsumer; import io.gitlab.jfronny.commons.throwable.ThrowingRunnable; @@ -29,7 +29,7 @@ public class InstanceList { synchronized (metas) { for (var entry : metas.entrySet()) { try { - entry.value.close(); + entry.getValue().close(); } catch (IOException e) { Utils.LOGGER.error("Could not close reference to instance meta", e); } @@ -60,7 +60,7 @@ public class InstanceList { public static boolean isEmpty() throws IOException { if (!Files.exists(MetaHolder.INSTANCE_DIR)) return true; - return JFiles.list(MetaHolder.INSTANCE_DIR, InstanceList::isInstance).isEmpty; + return JFiles.list(MetaHolder.INSTANCE_DIR, InstanceList::isInstance).isEmpty(); } public static int size() throws IOException { @@ -74,12 +74,12 @@ public class InstanceList { Objects.requireNonNull(instancePath); synchronized (metas) { if (!metas.containsKey(instancePath)) { - metas[instancePath] = new IEntry( + metas.put(instancePath, new IEntry( instancePath, new FileBackedRef<>(instancePath.resolve(Instance.CONFIG_NAME), GC_InstanceMeta::read) - ); + )); } - return metas[instancePath].toPub(); + return metas.get(instancePath).toPub(); } } @@ -90,7 +90,7 @@ public class InstanceList { private record IEntry(Path path, FileBackedRef meta) implements Closeable { @Override public String toString() { - return path.fileName.toString(); + return path.getFileName().toString(); } public Instance toPub() throws IOException { diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/InstanceListWatcher.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/InstanceListWatcher.java index 3c1b6bf..66521e3 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/InstanceListWatcher.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/InstanceListWatcher.java @@ -47,7 +47,7 @@ public class InstanceListWatcher implements Closeable { } if (kind == ENTRY_DELETE) changed = true; } else if (Files.exists(dir.resolve(Instance.CONFIG_NAME))) { - String fn = child.fileName.toString(); + String fn = child.getFileName().toString(); if (fn.equals(Instance.CONFIG_NAME) || fn.equals(Instance.LOCK_NAME) || fn.equals(Instance.SETUP_LOCK_NAME)) { diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/LoaderInfo.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/LoaderInfo.java index 3582a07..d36102e 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/LoaderInfo.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/LoaderInfo.java @@ -10,6 +10,6 @@ public record LoaderInfo(Type type, String version) { } public LoaderInfo(FabricLoaderVersion fabricVersion) { - this(LoaderInfo.Type.Fabric, fabricVersion.version); + this(LoaderInfo.Type.Fabric, fabricVersion.version()); } } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/ModManager.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/ModManager.java index 1219fa4..098bcca 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/ModManager.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/ModManager.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.system.instance; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.inceptum.ModMeta.GC_ModMeta; +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; import io.gitlab.jfronny.inceptum.launcher.system.source.ModDownload; @@ -11,19 +11,19 @@ import java.nio.file.Path; public class ModManager { public static DownloadMeta download(ModSource ms, Path metaFile, ModsDirScanner mds) throws IOException { - for (Mod value : mds.mods) { - for (ModSource source : value.metadata.sources.keySet()) { + for (Mod value : mds.getMods()) { + for (ModSource source : value.getMetadata().sources().keySet()) { if (ms.equals(source)) { - return new DownloadMeta(new ModDownload(value.metadata.sha1, value.metadata.murmur2, value.jarPath), value.metadata, source, metaFile); + return new DownloadMeta(new ModDownload(value.getMetadata().sha1(), value.getMetadata().murmur2(), value.getJarPath()), value.getMetadata(), source, metaFile); } } } ModDownload md = ms.download(); - ModMeta manifest = ModMeta.of(md.sha1, md.murmur2, ms, mds.gameVersion); - for (ModSource depSrc : ms.getDependencies(mds.gameVersion)) { - DownloadMeta depMeta = download(depSrc, metaFile.parent.resolve(depSrc.shortName + ModPath.EXT_IMOD), mds); - depMeta.meta.dependents.add(metaFile.fileName.toString()); - manifest.dependencies.add(depMeta.metaFile.fileName.toString()); + ModMeta manifest = ModMeta.of(md.sha1(), md.murmur2(), ms, mds.getGameVersion()); + for (ModSource depSrc : ms.getDependencies(mds.getGameVersion())) { + DownloadMeta depMeta = download(depSrc, metaFile.getParent().resolve(depSrc.getShortName() + ModPath.EXT_IMOD), mds); + depMeta.meta.dependents().add(metaFile.getFileName().toString()); + manifest.dependencies().add(depMeta.metaFile.getFileName().toString()); depMeta.write(); } return new DownloadMeta(md, manifest, ms, metaFile); diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/ModPath.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/ModPath.java index d0a4d41..8906b9d 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/ModPath.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/ModPath.java @@ -24,11 +24,11 @@ public class ModPath { : fileName.endsWith(EXT_IMOD_DISABLED2) ? fileName.substring(0, fileName.length() - EXT_IMOD_DISABLED2.length()) : fileName.substring(0, fileName.length() - EXT_IMOD.length()); - return p.parent.resolve(fileName); + return p.getParent().resolve(fileName); } public static boolean hasImod(Path mod) { - Path parent = mod.parent; + Path parent = mod.getParent(); if (parent == null) { Utils.LOGGER.info("The mod file " + mod + " doesn't have a parent. What is happening here?"); return false; @@ -37,7 +37,7 @@ public class ModPath { } public static Path appendImod(Path p) { - return p.parent.resolve(fn(p) + EXT_IMOD); + return p.getParent().resolve(fn(p) + EXT_IMOD); } public static boolean isJar(Path p) { @@ -53,7 +53,7 @@ public class ModPath { fileName = fileName.endsWith(EXT_IMOD_DISABLED2) ? fileName.substring(0, fileName.length() - EXT_IMOD_DISABLED2.length()) + EXT_IMOD : fileName.substring(0, fileName.length() - EXT_DISABLED.length()); - return p.parent.resolve(fileName); + return p.getParent().resolve(fileName); } public static Path disable(Path p) { @@ -61,7 +61,7 @@ public class ModPath { fileName = fileName.endsWith(EXT_IMOD) ? fileName.substring(0, fileName.length() - EXT_IMOD.length()) + EXT_IMOD_DISABLED2 : fileName + EXT_DISABLED; - return p.parent.resolve(fileName); + return p.getParent().resolve(fileName); } public static Path toggle(Path p) { @@ -69,6 +69,6 @@ public class ModPath { } private static String fn(Path p) { - return p.fileName.toString(); + return p.getFileName().toString(); } } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/launch/InstanceLauncher.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/launch/InstanceLauncher.java index a6f3586..5555025 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/launch/InstanceLauncher.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/launch/InstanceLauncher.java @@ -29,7 +29,7 @@ public class InstanceLauncher { LauncherEnv.showError("You have not set up an account.\nDoing so is required to play Minecraft", "Not authenticated"); return; } - AuthInfo authInfo = AccountManager.selectedAccount; + AuthInfo authInfo = AccountManager.getSelectedAccount(); if (authInfo.equals(AccountManager.NULL_AUTH)) { try { String sysUser = System.getProperty("user.name"); @@ -38,7 +38,7 @@ public class InstanceLauncher { LauncherEnv.getInput("User name", "Please enter the username to use for this session", InceptumConfig.offlineAccountLastName, name -> { InceptumConfig.offlineAccountLastName = name.equals(sysUser) ? null : name; InceptumConfig.saveConfig(); - AuthInfo infoNew = new AuthInfo(name, authInfo.uuid, authInfo.accessToken, authInfo.userType); + AuthInfo infoNew = new AuthInfo(name, authInfo.uuid(), authInfo.accessToken(), authInfo.userType()); launchClient(instance, infoNew); }, R::nop); } catch (IOException e) { @@ -57,11 +57,11 @@ public class InstanceLauncher { public static void launch(Instance instance, LaunchType launchType, boolean restart, AuthInfo authInfo) throws LaunchException, IOException { if (authInfo == null) throw new LaunchException("authInfo is null"); - VersionsListInfo versionDataSimple = getVersion(instance.gameVersion); + VersionsListInfo versionDataSimple = getVersion(instance.getGameVersion()); VersionInfo versionInfo = McApi.getVersionInfo(versionDataSimple); // Add fabric metadata if using fabric - if (instance.isFabric) { - versionInfo = FabricMetaApi.addFabric(versionInfo, instance.loaderVersion, launchType.fabricMetaType); + if (instance.isFabric()) { + versionInfo = FabricMetaApi.addFabric(versionInfo, instance.getLoaderVersion(), launchType.fabricMetaType); } // Ensure libs/assets are present DownloadLibrariesStep.execute(versionInfo, new ProcessState()); @@ -70,39 +70,39 @@ public class InstanceLauncher { // JVM path { final VersionInfo lambdaVersionInfo = versionInfo; - args.add(Objects.requireNonNullElseGet(instance.meta.java, () -> + args.add(Objects.requireNonNullElseGet(instance.meta().java, () -> OSUtils.getJvmBinary(MetaHolder.NATIVES_DIR - .resolve(lambdaVersionInfo.javaVersion.component) - .resolve(Integer.toString(lambdaVersionInfo.javaVersion.majorVersion))) + .resolve(lambdaVersionInfo.javaVersion.component()) + .resolve(Integer.toString(lambdaVersionInfo.javaVersion.majorVersion()))) .toAbsolutePath().toString())); } // Java classpath StringBuilder classPath = new StringBuilder(); for (ArtifactInfo artifact : VersionInfoLibraryResolver.getRelevant(versionInfo)) { - classPath.append(MetaHolder.LIBRARIES_DIR.resolve(artifact.path)); + classPath.append(MetaHolder.LIBRARIES_DIR.resolve(artifact.path())); classPath.append(File.pathSeparatorChar); } Path gameJar = MetaHolder.LIBRARIES_DIR.resolve("net/minecraft/" + launchType.name).resolve(versionDataSimple.id + ".jar"); classPath.append(gameJar); classPath.append(File.pathSeparatorChar); - classPath.append(DownloadLibrariesStep.launchWrapperArtifact.localPath); + classPath.append(DownloadLibrariesStep.getLaunchWrapperArtifact().getLocalPath()); // JVM arguments - if (instance.meta.arguments != null && instance.meta.arguments.jvm != null) - args.addAll(instance.meta.arguments.jvm); + if (instance.meta().arguments != null && instance.meta().arguments.jvm() != null) + args.addAll(instance.meta().arguments.jvm()); if (launchType == LaunchType.Client && versionInfo.arguments != null) - args.addAll(parse(versionInfo.arguments.jvm, versionInfo, instance, classPath.toString(), authInfo)); - if (instance.meta.minMem != null) args.add("-Xms" + instance.meta.minMem); - if (instance.meta.maxMem != null) args.add("-Xmx" + instance.meta.maxMem); + args.addAll(parse(versionInfo.arguments.jvm(), versionInfo, instance, classPath.toString(), authInfo)); + if (instance.meta().minMem != null) args.add("-Xms" + instance.meta().minMem); + if (instance.meta().maxMem != null) args.add("-Xmx" + instance.meta().maxMem); // Forceload natives if (Files.exists(MetaHolder.FORCE_LOAD_PATH)) { args.add("-Dinceptum.forceloadNatives=" + MetaHolder.FORCE_LOAD_PATH); } // Fabric imods - if (instance.isFabric) { + if (instance.isFabric()) { StringBuilder fabricAddMods = new StringBuilder("-Dfabric.addMods="); - for (Mod mod : instance.mods) { - if (mod.isEnabled && mod.needsInject) { - fabricAddMods.append(mod.jarPath); + for (Mod mod : instance.getMods()) { + if (mod.isEnabled() && mod.getNeedsInject()) { + fabricAddMods.append(mod.getJarPath()); fabricAddMods.append(File.pathSeparatorChar); } } @@ -115,7 +115,7 @@ public class InstanceLauncher { // Game arguments if (launchType == LaunchType.Client) { if (versionInfo.arguments != null) - args.addAll(parse(versionInfo.arguments.game, versionInfo, instance, classPath.toString(), authInfo)); + args.addAll(parse(versionInfo.arguments.game(), versionInfo, instance, classPath.toString(), authInfo)); else if (versionInfo.minecraftArguments != null) { for (String s : versionInfo.minecraftArguments.split(" ")) { args.add(expandArg(s, versionInfo, instance, classPath.toString(), authInfo)); @@ -125,30 +125,30 @@ public class InstanceLauncher { if (instance.meta().arguments != null) { switch (launchType) { case Client -> { - if (instance.meta().arguments.client != null) - args.addAll(instance.meta.arguments.client); + if (instance.meta().arguments.client() != null) + args.addAll(instance.meta().arguments.client()); } case Server -> { - if (instance.meta().arguments.server != null) - args.addAll(instance.meta.arguments.server); + if (instance.meta().arguments.server() != null) + args.addAll(instance.meta().arguments.server()); } } } // Write launch time - instance.meta.lastLaunched = System.currentTimeMillis() / 1000L; + instance.meta().lastLaunched = System.currentTimeMillis() / 1000L; instance.writeMeta(); // Log command used to start Utils.LOGGER.info(String.join(" ", args)); // Create process ProcessBuilder pb = new ProcessBuilder(args.toArray(new String[0])); - pb.directory(instance.path.toFile()); + pb.directory(instance.path().toFile()); pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); pb.redirectError(ProcessBuilder.Redirect.INHERIT); AtomicReference proc = new AtomicReference<>(); Runnable starterRunner = () -> { try { proc.set(pb.start()); - instance.runningLock = proc.get().pid(); + instance.setRunningLock(proc.get().pid()); } catch (IOException e) { Utils.LOGGER.error("Could not start " + launchType.name, e); } @@ -157,7 +157,7 @@ public class InstanceLauncher { new Thread(() -> { while (true) { starterRunner.run(); - if (!proc.get().isAlive) { + if (!proc.get().isAlive()) { Utils.LOGGER.error("Could not create server process"); instance.isRunningLocked(); return; @@ -181,13 +181,13 @@ public class InstanceLauncher { } instance.isRunningLocked(); }); - th.isDaemon = true; + th.setDaemon(true); th.start(); } } private static String resolveMainClass(Instance instance, VersionInfo versionInfo, Path gameJar, LaunchType launchType) throws LaunchException { - if (launchType == LaunchType.Client || instance.isFabric) return versionInfo.mainClass; + if (launchType == LaunchType.Client || instance.isFabric()) return versionInfo.mainClass; // Identify main class using MANIFEST.MF final String linePrefix = "Main-Class: "; try (FileSystem fs = Utils.openZipFile(gameJar, false)) { @@ -203,7 +203,7 @@ public class InstanceLauncher { } private static VersionsListInfo getVersion(String minecraftVersion) throws LaunchException { - for (VersionsListInfo version : McApi.getVersions().versions) { + for (VersionsListInfo version : McApi.getVersions().versions()) { if (version.id.equals(minecraftVersion)) return version; } @@ -223,19 +223,19 @@ public class InstanceLauncher { private static String expandArg(String arg, VersionInfo info, Instance instance, String classPath, AuthInfo authInfo) { return arg // game args - .replace("${auth_player_name}", authInfo.name) + .replace("${auth_player_name}", authInfo.name()) .replace("${version_name}", "Inceptum") - .replace("${game_directory}", instance.path.toString()) + .replace("${game_directory}", instance.path().toString()) .replace("${assets_root}", MetaHolder.ASSETS_DIR.toString()) .replace("${assets_index_name}", info.assets) - .replace("${auth_uuid}", authInfo.uuid) - .replace("${auth_access_token}", authInfo.accessToken) - .replace("${user_type}", authInfo.userType) + .replace("${auth_uuid}", authInfo.uuid()) + .replace("${auth_access_token}", authInfo.accessToken()) + .replace("${user_type}", authInfo.userType()) .replace("${version_type}", info.type) .replace("${resolution_width}", "1920") //TODO has_custom_resolution .replace("${resolution_height}", "1080") //TODO has_custom_resolution // jvm args - .replace("${natives_directory}", MetaHolder.NATIVES_DIR.resolve(instance.gameVersion).toString()) + .replace("${natives_directory}", MetaHolder.NATIVES_DIR.resolve(instance.getGameVersion()).toString()) .replace("${launcher_name}", "Inceptum") .replace("${launcher_version}", BuildMetadata.VERSION) .replace("${classpath}", classPath) diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/FileScanTask.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/FileScanTask.java index 141ee92..b91b622 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/FileScanTask.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/FileScanTask.java @@ -1,7 +1,7 @@ package io.gitlab.jfronny.inceptum.launcher.system.mds; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.fabric.FabricModJson.GC_FabricModJson; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.inceptum.ModMeta.GC_ModMeta; +import io.gitlab.jfronny.inceptum.launcher.model.fabric.GC_FabricModJson; +import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_ModMeta; import io.gitlab.jfronny.gson.JsonParseException; import io.gitlab.jfronny.inceptum.common.Utils; import io.gitlab.jfronny.inceptum.launcher.model.fabric.FabricModJson; @@ -44,20 +44,20 @@ public record FileScanTask(ProtoInstance instance, Path file, BiConsumer getDependencies() { - return meta.dependencies.stream() - .map(instance.modsDir::resolve) - .map(instance.mds::get) + return meta.dependencies().stream() + .map(instance.modsDir()::resolve) + .map(instance.mds()::get) .collect(Collectors.toUnmodifiableSet()); } @Override public Set getDependents() { - return meta.dependents.stream() - .map(instance.modsDir::resolve) - .map(instance.mds::get) + return meta.dependents().stream() + .map(instance.modsDir()::resolve) + .map(instance.mds()::get) .collect(Collectors.toUnmodifiableSet()); } @Override public void removeDependency(Mod dependency) throws IOException { - meta.dependencies.remove(meta.dependencies.stream() - .filter(s -> dependency.equals(instance.mds[instance.modsDir.resolve(s)])) + meta.dependencies().remove(meta.dependencies().stream() + .filter(s -> dependency.equals(instance.mds().get(instance.modsDir().resolve(s)))) .findFirst() .orElseThrow(FileNotFoundException::new)); write(); @@ -112,12 +112,12 @@ public class MdsMod extends Mod { @Override public void removeDependent(Mod dependent) throws IOException { - meta.dependents.remove(meta.dependents.stream() - .filter(s -> dependent.equals(instance.mds[instance.modsDir.resolve(s)])) + meta.dependents().remove(meta.dependents().stream() + .filter(s -> dependent.equals(instance.mds().get(instance.modsDir().resolve(s)))) .findFirst() .orElseThrow(FileNotFoundException::new)); write(); - if (!meta.explicit && meta.dependents.isEmpty) delete(); + if (!meta.explicit() && meta.dependents().isEmpty()) delete(); } @Override diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/ModsDirScannerImpl.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/ModsDirScannerImpl.java index 5f68bf3..edf7823 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/ModsDirScannerImpl.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/ModsDirScannerImpl.java @@ -19,7 +19,7 @@ import static java.nio.file.StandardWatchEventKinds.*; class ModsDirScannerImpl implements ModsDirScanner { private static final Map SCANNERS = new HashMap<>(); - private static final ExecutorService POOL = Executors.newFixedThreadPool(Runtime.runtime.availableProcessors(), new NamedThreadFactory("mds")); + private static final ExecutorService POOL = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new NamedThreadFactory("mds")); private final Map descriptions = new HashMap<>(); private final Set scannedPaths = new HashSet<>(); private final Thread th; @@ -29,27 +29,27 @@ class ModsDirScannerImpl implements ModsDirScanner { private ModsDirScannerImpl(Path modsDir, InstanceMeta instance) throws IOException { this.instance = new ProtoInstance(modsDir, this, instance); - this.th = new Thread(this::scanTaskInternal, "mds-" + modsDir.parent.fileName); + this.th = new Thread(this::scanTaskInternal, "mds-" + modsDir.getParent().getFileName()); this.service = FileSystems.getDefault().newWatchService(); modsDir.register(service, ENTRY_MODIFY, ENTRY_CREATE, ENTRY_DELETE); } protected static ModsDirScannerImpl get(Path modsDir, InstanceMeta instance) throws IOException { if (SCANNERS.containsKey(modsDir)) { - ModsDirScannerImpl mds = SCANNERS[modsDir]; - if (mds.instance.meta.equals(instance)) return mds; + ModsDirScannerImpl mds = SCANNERS.get(modsDir); + if (mds.instance.meta().equals(instance)) return mds; mds.close(); } ModsDirScannerImpl mds = new ModsDirScannerImpl(modsDir, instance); - SCANNERS[modsDir] = mds; + SCANNERS.put(modsDir, mds); return mds; } @Override public boolean isComplete() { - if (!Files.isDirectory(instance.modsDir)) return true; + if (!Files.isDirectory(instance.modsDir())) return true; try { - for (Path path : JFiles.list(instance.modsDir)) { + for (Path path : JFiles.list(instance.modsDir())) { if (!descriptions.containsKey(path)) return false; } } catch (IOException e) { @@ -65,14 +65,14 @@ class ModsDirScannerImpl implements ModsDirScanner { @Override public String getGameVersion() { - return GameVersionParser.getGameVersion(instance.meta.gameVersion); + return GameVersionParser.getGameVersion(instance.meta().gameVersion); } @Override public Set getMods() throws IOException { Set mods = new TreeSet<>(); - if (Files.isDirectory(instance.modsDir)) { - for (Path path : JFiles.list(instance.modsDir)) { + if (Files.isDirectory(instance.modsDir())) { + for (Path path : JFiles.list(instance.modsDir())) { if (ModPath.isImod(path) && Files.exists(ModPath.trimImod(path))) continue; mods.add(get(path)); @@ -85,7 +85,7 @@ class ModsDirScannerImpl implements ModsDirScanner { public Mod get(Path path) { if (!Files.isRegularFile(path)) return null; if (!descriptions.containsKey(path)) return new NoopMod(path); // not yet scanned - return descriptions[path]; + return descriptions.get(path); } @Override @@ -96,7 +96,7 @@ class ModsDirScannerImpl implements ModsDirScanner { public boolean hasScanned(Path path) { return scannedPaths.contains(path) - || scannedPaths.contains(path.parent.resolve(path.fileName.toString() + ".imod")); + || scannedPaths.contains(path.getParent().resolve(path.getFileName().toString() + ".imod")); } private void scanTaskInternal() { @@ -108,34 +108,34 @@ class ModsDirScannerImpl implements ModsDirScanner { @Override public void runOnce(BiConsumer discovered) { try { - if (!Files.isDirectory(instance.modsDir)) { + if (!Files.isDirectory(instance.modsDir())) { return; } Set> tasks = new HashSet<>(); discovered = discovered.andThen((path, iwModDescription) -> { scannedPaths.add(path); - descriptions[path] = iwModDescription; + descriptions.put(path, iwModDescription); }); Set toScan; - if (descriptions.isEmpty) { - toScan = Set.copyOf(JFiles.list(instance.modsDir)); + if (descriptions.isEmpty()) { + toScan = Set.copyOf(JFiles.list(instance.modsDir())); } else { toScan = new HashSet<>(); WatchKey key = service.poll(); if (key != null) { for (WatchEvent event : key.pollEvents()) { if (event.context() instanceof Path p) { - toScan.add(instance.modsDir.resolve(p)); + toScan.add(instance.modsDir().resolve(p)); } } if (!key.reset()) Utils.LOGGER.warn("Could not reset config watch key"); } - JFiles.listTo(instance.modsDir, path -> { + JFiles.listTo(instance.modsDir(), path -> { if (!descriptions.containsKey(path)) toScan.add(path); }); } for (Path p : toScan) { - tasks.add(POOL.submit(new FileScanTask(instance, p, discovered, gameVersion))); + tasks.add(POOL.submit(new FileScanTask(instance, p, discovered, getGameVersion()))); } for (Future task : tasks) { try { @@ -164,6 +164,6 @@ class ModsDirScannerImpl implements ModsDirScanner { public void close() throws IOException { disposed = true; service.close(); - SCANNERS.remove(instance.modsDir); + SCANNERS.remove(instance.modsDir()); } } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/NamedThreadFactory.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/NamedThreadFactory.java index b782d4b..1372d21 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/NamedThreadFactory.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/NamedThreadFactory.java @@ -11,14 +11,14 @@ public class NamedThreadFactory implements ThreadFactory { private final String namePrefix; public NamedThreadFactory(String name) { - this.group = Thread.currentThread().threadGroup; + this.group = Thread.currentThread().getThreadGroup(); this.namePrefix = name + "-" + poolNumber.getAndIncrement() + "-"; } public Thread newThread(Runnable r) { Thread t = new Thread(this.group, r, this.namePrefix + this.threadNumber.getAndIncrement(), 0L); - if (t.isDaemon) t.isDaemon = false; - if (t.priority != 5) t.priority = 5; + if (t.isDaemon()) t.setDaemon(false); + if (t.getPriority() != 5) t.setPriority(5); return t; } } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/noop/NoopMod.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/noop/NoopMod.java index 0734a7b..07b0797 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/noop/NoopMod.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/noop/NoopMod.java @@ -19,7 +19,7 @@ public class NoopMod extends Mod { @Override public String getName() { - return path.fileName.toString(); + return path.getFileName().toString(); } @Override diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/SetupStepInfo.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/SetupStepInfo.java index cf6ef6e..07e3f18 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/SetupStepInfo.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/SetupStepInfo.java @@ -13,6 +13,6 @@ public record SetupStepInfo(VersionInfo version, } public boolean isCancelled() { - return currentState.isCancelled; + return currentState.isCancelled(); } } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/Steps.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/Steps.java index 07e97fc..2ca6f4b 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/Steps.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/Steps.java @@ -28,25 +28,25 @@ public class Steps { } public static void reDownload(Instance instance, ProcessState state) throws IOException { - if (instance.isLocked) return; + if (instance.isLocked()) return; boolean found = false; - for (VersionsListInfo version : McApi.getVersions().versions) { - if (version.id.equals(instance.gameVersion)) { + for (VersionsListInfo version : McApi.getVersions().versions()) { + if (version.id.equals(instance.getGameVersion())) { found = true; VersionInfo vi = McApi.getVersionInfo(version); - if (instance.isFabric) - vi = FabricMetaApi.addFabric(vi, instance.loaderVersion, FabricMetaApi.FabricVersionInfoType.Both); - LoaderInfo li = instance.isFabric - ? new LoaderInfo(LoaderInfo.Type.Fabric, instance.loaderVersion) + if (instance.isFabric()) + vi = FabricMetaApi.addFabric(vi, instance.getLoaderVersion(), FabricMetaApi.FabricVersionInfoType.Both); + LoaderInfo li = instance.isFabric() + ? new LoaderInfo(LoaderInfo.Type.Fabric, instance.getLoaderVersion()) : LoaderInfo.NONE; - SetupStepInfo info = new SetupStepInfo(vi, li, instance.name, state); + SetupStepInfo info = new SetupStepInfo(vi, li, instance.getName(), state); for (Step step : Steps.STEPS) { - state.incrementStep(step.name); + state.incrementStep(step.getName()); step.execute(info); - if (state.isCancelled) return; + if (state.isCancelled()) return; } } } - if (!found) throw new IOException("Could not identify minecraft version " + instance.gameVersion); + if (!found) throw new IOException("Could not identify minecraft version " + instance.getGameVersion()); } } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadAssetsStep.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadAssetsStep.java index a759a9f..d7c64ff 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadAssetsStep.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadAssetsStep.java @@ -14,14 +14,14 @@ public class DownloadAssetsStep implements Step { public void execute(SetupStepInfo info) throws IOException { Path o = MetaHolder.ASSETS_DIR.resolve("objects"); try { - for (var entry : McApi.getAssetIndex(info.version).objects) { - if (info.isCancelled) return; - Path fPath = o.resolve(entry.value.hash.substring(0, 2)); + for (var entry : McApi.getAssetIndex(info.version()).objects().entrySet()) { + if (info.isCancelled()) return; + Path fPath = o.resolve(entry.getValue().hash().substring(0, 2)); if (!Files.exists(fPath)) Files.createDirectories(fPath); - fPath = fPath.resolve(entry.value.hash); + fPath = fPath.resolve(entry.getValue().hash()); if (Files.exists(fPath)) continue; - info.setState("Downloading asset: " + entry.key); - McApi.downloadAsset(entry.value, fPath); + info.setState("Downloading asset: " + entry.getKey()); + McApi.downloadAsset(entry.getValue(), fPath); } } catch (Throwable e) { throw new IOException("Could not download assets", e); diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadClientStep.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadClientStep.java index 2a7481a..a407e1e 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadClientStep.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadClientStep.java @@ -18,18 +18,18 @@ public class DownloadClientStep implements Step { Path serverPath = MetaHolder.LIBRARIES_DIR.resolve("net/minecraft/server"); if (!Files.exists(clientPath)) Files.createDirectories(clientPath); if (!Files.exists(serverPath)) Files.createDirectories(serverPath); - String minecraftVersion = GameVersionParser.getGameVersion(info.version.id); + String minecraftVersion = GameVersionParser.getGameVersion(info.version().id); clientPath = clientPath.resolve(minecraftVersion + ".jar"); serverPath = serverPath.resolve(minecraftVersion + ".jar"); try { if (!Files.exists(clientPath)) { - MojangFileDownload client = info.version.downloads.client; + MojangFileDownload client = info.version().downloads.client(); info.setState("Downloading Client"); Net.downloadFile(client.url, client.sha1, clientPath); } Utils.LOGGER.info(serverPath.toString()); if (!Files.exists(serverPath)) { - MojangFileDownload server = info.version.downloads.server; + MojangFileDownload server = info.version().downloads.server(); if (new ComparableVersion(minecraftVersion).compareTo("1.18") >= 0) { info.setState("Downloading Bundler"); Path p = Files.createTempFile("bundler", ".jar"); diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadJavaStep.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadJavaStep.java index 8b87625..eb91e0b 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadJavaStep.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadJavaStep.java @@ -16,23 +16,23 @@ import java.nio.file.Path; public class DownloadJavaStep implements Step { @Override public void execute(SetupStepInfo info) throws IOException { - VersionInfo.JavaVersion ver = info.version.javaVersion; - Path jvmDir = MetaHolder.NATIVES_DIR.resolve(ver.component).resolve(Integer.toString(ver.majorVersion)); + VersionInfo.JavaVersion ver = info.version().javaVersion; + Path jvmDir = MetaHolder.NATIVES_DIR.resolve(ver.component()).resolve(Integer.toString(ver.majorVersion())); if (Files.exists(jvmDir)) return; info.setState("Downloading JVM"); Files.createDirectories(jvmDir); - for (var entry : McApi.getJvm(ver.component, ver.majorVersion)) { - Path tPath = jvmDir.resolve(entry.key); - switch (entry.value.type) { + for (var entry : McApi.getJvm(ver.component(), ver.majorVersion()).entrySet()) { + Path tPath = jvmDir.resolve(entry.getKey()); + switch (entry.getValue().type()) { case "file" -> { - MojangFileDownload mf = entry.value.downloads.raw; + MojangFileDownload mf = entry.getValue().downloads().raw(); info.setState("jvm: Downloading " + tPath); try { Net.downloadFile(mf.url, mf.sha1, tPath); } catch (URISyntaxException e) { throw new IOException("Could not download jvm", e); } - if (entry.value.executable) { + if (entry.getValue().executable()) { if (!tPath.toFile().setExecutable(true)) info.setState("Could not set executable bit for " + tPath); } } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadLibrariesStep.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadLibrariesStep.java index a63e63e..2f70f15 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadLibrariesStep.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadLibrariesStep.java @@ -19,7 +19,7 @@ import java.nio.file.*; public class DownloadLibrariesStep implements Step { @Override public void execute(SetupStepInfo info) throws IOException { - execute(info.version, info.currentState); + execute(info.version(), info.currentState()); } @Override @@ -29,22 +29,22 @@ public class DownloadLibrariesStep implements Step { public static void execute(VersionInfo version, ProcessState currentState) throws IOException { for (ArtifactInfo artifact : VersionInfoLibraryResolver.getRelevant(version)) { - if (currentState.isCancelled) return; - Path path = MetaHolder.LIBRARIES_DIR.resolve(artifact.path); + if (currentState.isCancelled()) return; + Path path = MetaHolder.LIBRARIES_DIR.resolve(artifact.path()); if (!Files.exists(path)) { - currentState.updateStep("Downloading library: " + artifact.path); - if (!Files.exists(path.parent)) Files.createDirectories(path.parent); - if (!artifact.url.endsWith(".jar")) { - Utils.LOGGER.info("Not a valid URL for a jar: " + artifact.url); + currentState.updateStep("Downloading library: " + artifact.path()); + if (!Files.exists(path.getParent())) Files.createDirectories(path.getParent()); + if (!artifact.url().endsWith(".jar")) { + Utils.LOGGER.info("Not a valid URL for a jar: " + artifact.url()); continue; } try { - Net.downloadFile(artifact.url, artifact.sha1, path); + Net.downloadFile(artifact.url(), artifact.sha1(), path); } catch (URISyntaxException e) { throw new IOException("Could not download library", e); } } - if (artifact.isNative) { + if (artifact.isNative()) { currentState.updateStep("Extracting natives"); try (FileSystem libFs = Utils.openZipFile(path, false)) { JFiles.copyRecursive(libFs.getPath("."), MetaHolder.NATIVES_DIR.resolve(GameVersionParser.getGameVersion(version.id))); @@ -56,9 +56,9 @@ public class DownloadLibrariesStep implements Step { } ArtifactMeta artifact = getLaunchWrapperArtifact(); - if (!Files.exists(artifact.localPath)) { + if (!Files.exists(artifact.getLocalPath())) { try { - MavenApi.downloadLibrary(Updater.PROJECT_MAVEN, MavenApi.getMetadata(Updater.PROJECT_MAVEN, artifact.mavenNotation)); + MavenApi.downloadLibrary(Updater.PROJECT_MAVEN, MavenApi.getMetadata(Updater.PROJECT_MAVEN, artifact.getMavenNotation())); } catch (URISyntaxException | SAXException e) { throw new IOException("Could not download launchwrapper", e); } @@ -68,7 +68,7 @@ public class DownloadLibrariesStep implements Step { public static ArtifactMeta getLaunchWrapperArtifact() throws FileNotFoundException { String version = BuildMetadata.IS_PUBLIC ? BuildMetadata.VERSION : null; try { - if (version == null) version = Updater.getUpdate(false, false).version; + if (version == null) version = Updater.getUpdate(false, false).version(); } catch (Updater.UpdateCheckException ignored) { } if (version == null) throw new FileNotFoundException("Could not find a valid launch wrapper version"); diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/RunMdsStep.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/RunMdsStep.java index 32d43b6..6a6b85e 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/RunMdsStep.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/RunMdsStep.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.system.setup.steps; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta.GC_InstanceMeta; +import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_InstanceMeta; import io.gitlab.jfronny.inceptum.common.MetaHolder; import io.gitlab.jfronny.inceptum.launcher.system.instance.Instance; import io.gitlab.jfronny.inceptum.launcher.system.mds.ModsDirScanner; @@ -14,7 +14,7 @@ public class RunMdsStep implements Step { @Override public void execute(SetupStepInfo info) throws IOException { info.setState("Running MDS"); - Path instance = MetaHolder.INSTANCE_DIR.resolve(info.name); + Path instance = MetaHolder.INSTANCE_DIR.resolve(info.name()); ModsDirScanner.get(instance.resolve("mods"), GC_InstanceMeta.read(instance.resolve(Instance.CONFIG_NAME))) .runOnce((path, iwModDescription) -> info.setState("Scanned " + path)); } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/SetupDirsStep.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/SetupDirsStep.java index 3cd739e..001edc0 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/SetupDirsStep.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/SetupDirsStep.java @@ -15,14 +15,14 @@ public class SetupDirsStep implements Step { @Override public void execute(SetupStepInfo info) throws IOException { info.setState("Setting up instance dirs"); - Path iDir = MetaHolder.INSTANCE_DIR.resolve(info.name); + Path iDir = MetaHolder.INSTANCE_DIR.resolve(info.name()); Instance.setSetupLock(iDir, true); if (!Files.exists(iDir)) { Files.createDirectories(iDir.resolve("resourcepacks")); Files.createDirectories(iDir.resolve("saves")); Files.createDirectories(iDir.resolve("screenshots")); } - if (info.loader.type != LoaderInfo.Type.None) { + if (info.loader().type() != LoaderInfo.Type.None) { if (!Files.exists(iDir.resolve("mods"))) Files.createDirectories(iDir.resolve("mods")); if (!Files.exists(iDir.resolve("config"))) @@ -32,7 +32,7 @@ public class SetupDirsStep implements Step { if (!Files.exists(eulaTxt)) { Files.writeString(eulaTxt, "eula=true"); } - Files.createDirectories(MetaHolder.NATIVES_DIR.resolve(GameVersionParser.getGameVersion(info.version.id))); + Files.createDirectories(MetaHolder.NATIVES_DIR.resolve(GameVersionParser.getGameVersion(info.version().id))); } @Override diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/WriteMetadataStep.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/WriteMetadataStep.java index 03a0b3a..aa47b16 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/WriteMetadataStep.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/WriteMetadataStep.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.launcher.system.setup.steps; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta.GC_InstanceMeta; +import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_InstanceMeta; import io.gitlab.jfronny.inceptum.common.MetaHolder; import io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta; import io.gitlab.jfronny.inceptum.launcher.system.instance.Instance; @@ -15,11 +15,11 @@ public class WriteMetadataStep implements Step { @Override public void execute(SetupStepInfo info) throws IOException { info.setState("Writing metadata"); - Path instance = MetaHolder.INSTANCE_DIR.resolve(info.name); + Path instance = MetaHolder.INSTANCE_DIR.resolve(info.name()); Path metaPath = instance.resolve(Instance.CONFIG_NAME); if (!Files.exists(metaPath)) { InstanceMeta meta = new InstanceMeta(); - meta.gameVersion = info.version.id; + meta.gameVersion = info.version().id; GC_InstanceMeta.write(meta, metaPath); } Instance.setSetupLock(instance, false); diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/CurseforgeModSource.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/CurseforgeModSource.java index a14a38e..38b71e3 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/CurseforgeModSource.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/CurseforgeModSource.java @@ -33,7 +33,7 @@ public final class CurseforgeModSource implements ModSource { public CurseforgeModSource(String projectSlug, int fileId) throws IOException { this.mod = CurseforgeApi.getMod(projectSlug); - this.projectId = mod.id; + this.projectId = mod.id(); this.fileId = fileId; this.current = CurseforgeApi.getFile(projectId, fileId); } @@ -42,7 +42,7 @@ public final class CurseforgeModSource implements ModSource { public ModDownload download() throws IOException { Path path = getJarPath(); try { - Net.downloadFile(current.downloadUrl, path); + Net.downloadFile(current.downloadUrl(), path); } catch (URISyntaxException e) { throw new IOException("Could not download file", e); } @@ -54,11 +54,11 @@ public final class CurseforgeModSource implements ModSource { public Set getDependencies(String gameVersion) throws IOException { return DEPENDENCIES_CACHE.get(Tuple.of(projectId, fileId), () -> { Set deps = new HashSet<>(); - for (CurseforgeFile.Dependency dependency : current.dependencies) { - if (dependency.relationType == 3) { //TODO support other types (IDs are documented on field declaration) - for (CurseforgeMod.LatestFileIndex index : CurseforgeApi.getMod(dependency.modId).latestFilesIndexes) { - if (index.gameVersion.equals(gameVersion)) { - deps.add(new CurseforgeModSource(dependency.modId, index.fileId)); + for (CurseforgeFile.Dependency dependency : current.dependencies()) { + if (dependency.relationType() == 3) { //TODO support other types (IDs are documented on field declaration) + for (CurseforgeMod.LatestFileIndex index : CurseforgeApi.getMod(dependency.modId()).latestFilesIndexes()) { + if (index.gameVersion().equals(gameVersion)) { + deps.add(new CurseforgeModSource(dependency.modId(), index.fileId())); break; } } @@ -71,11 +71,11 @@ public final class CurseforgeModSource implements ModSource { @Override public Optional getUpdate(String gameVersion) throws IOException { return UPDATE_CACHE.get(Tuple.of(projectId, fileId, gameVersion), () -> { - for (CurseforgeMod.LatestFileIndex file : mod.latestFilesIndexes) { - if (file.gameVersion.equals(gameVersion)) { - return file.fileId == fileId + for (CurseforgeMod.LatestFileIndex file : mod.latestFilesIndexes()) { + if (file.gameVersion().equals(gameVersion)) { + return file.fileId() == fileId ? Optional.empty() - : Optional.of(new CurseforgeModSource(projectId, file.fileId)); + : Optional.of(new CurseforgeModSource(projectId, file.fileId())); } } return Optional.empty(); @@ -84,22 +84,22 @@ public final class CurseforgeModSource implements ModSource { @Override public String getVersion() { - return current.displayName; + return current.displayName(); } @Override public String getName() { - return "curseforge/" + shortName + '/' + current.id; + return "curseforge/" + getShortName() + '/' + current.id(); } @Override public String getShortName() { - return mod.slug == null ? Integer.toString(mod.id) : mod.slug; + return mod.slug() == null ? Integer.toString(mod.id()) : mod.slug(); } @Override public String getFileName() { - return current.fileName; + return current.fileName(); } @Override diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/DirectModSource.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/DirectModSource.java index f500ef7..ead6ccd 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/DirectModSource.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/DirectModSource.java @@ -17,7 +17,7 @@ public record DirectModSource(String fileName, String url, Set depend @Override public ModDownload download() throws IOException { - Path p = jarPath; + Path p = getJarPath(); try { Net.downloadFile(url, p); //TODO test } catch (URISyntaxException e) { diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/ModSource.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/ModSource.java index 552bc21..45b820b 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/ModSource.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/ModSource.java @@ -29,6 +29,6 @@ public interface ModSource { boolean equals(ModSource other); default Path getJarPath() { - return MetaHolder.LIBRARIES_DIR.resolve("com").resolve(name).resolve(fileName); + return MetaHolder.LIBRARIES_DIR.resolve("com").resolve(getName()).resolve(getFileName()); } } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/ModrinthModSource.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/ModrinthModSource.java index 4eac8c6..7cba70e 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/ModrinthModSource.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/source/ModrinthModSource.java @@ -25,29 +25,29 @@ public final class ModrinthModSource implements ModSource { public ModrinthModSource(String versionId) throws IOException { this.versionId = versionId; this.current = ModrinthApi.getVersion(versionId); - this.mod = ModrinthApi.getMod(modId); + this.mod = ModrinthApi.getMod(getModId()); } @Override public ModDownload download() throws IOException { - ModrinthVersion.File file = current.files[0]; - Path path = jarPath; + ModrinthVersion.File file = current.files().get(0); + Path path = getJarPath(); try { - Net.downloadFile(file.url, file.hashes.sha1, path); + Net.downloadFile(file.url(), file.hashes().sha1(), path); } catch (URISyntaxException e) { throw new IOException("Could not download file", e); } - return new ModDownload(file.hashes.sha1, HashUtils.murmur2(Files.readAllBytes(path)), path); + return new ModDownload(file.hashes().sha1(), HashUtils.murmur2(Files.readAllBytes(path)), path); } @Override public Set getDependencies(String gameVersion) throws IOException { return DEPENDENCIES_CACHE.get(versionId, () -> { Set deps = new HashSet<>(); - for (ModrinthVersion.Dependency dependency : current.dependencies) { + for (ModrinthVersion.Dependency dependency : current.dependencies()) { //TODO show optional dependencies - if (dependency.dependency_type == ModrinthVersion.Dependency.DependencyType.required) - deps.add(new ModrinthModSource(dependency.version_id)); + if (dependency.dependency_type() == ModrinthVersion.Dependency.DependencyType.required) + deps.add(new ModrinthModSource(dependency.version_id())); } return Set.copyOf(deps); }); @@ -59,49 +59,49 @@ public final class ModrinthModSource implements ModSource { ModrinthVersion stable = null; ModrinthVersion beta = null; ModrinthVersion latest = null; - for (ModrinthVersion version : ModrinthApi.getVersions(modId)) { - if (version.game_versions.contains(gameVersion) && version.loaders.contains("fabric")) { + for (ModrinthVersion version : ModrinthApi.getVersions(getModId())) { + if (version.game_versions().contains(gameVersion) && version.loaders().contains("fabric")) { latest = version; - if (version.version_type == ModrinthVersion.VersionType.beta || version.version_type == ModrinthVersion.VersionType.release) + if (version.version_type() == ModrinthVersion.VersionType.beta || version.version_type() == ModrinthVersion.VersionType.release) beta = version; - if (version.version_type == ModrinthVersion.VersionType.release) + if (version.version_type() == ModrinthVersion.VersionType.release) stable = version; } } - ModrinthVersion next = switch (current.version_type) { + ModrinthVersion next = switch (current.version_type()) { case alpha -> latest; case beta -> beta; case release -> stable; }; if (next == null) return Optional.empty(); - if (next.version_number.equals(current.version_number)) return Optional.empty(); - return Optional.of(new ModrinthModSource(next.id)); + if (next.version_number().equals(current.version_number())) return Optional.empty(); + return Optional.of(new ModrinthModSource(next.id())); }); } @Override public String getVersion() { - return current.version_number; + return current.version_number(); } @Override public String getName() { - return "modrinth/" + shortName + '/' + current.version_number; + return "modrinth/" + getShortName() + '/' + current.version_number(); } @Override public String getShortName() { - return (mod.slug == null ? mod.id : mod.slug); + return (mod.slug() == null ? mod.id() : mod.slug()); } @Override public String getFileName() { - return current.files[0].filename; + return current.files().get(0).filename(); } @Override public boolean equals(ModSource other) { - return other instanceof ModrinthModSource ms && ms.modId.equals(modId) && ms.versionId.equals(versionId); + return other instanceof ModrinthModSource ms && ms.getModId().equals(getModId()) && ms.versionId.equals(versionId); } public String getVersionId() { @@ -109,20 +109,20 @@ public final class ModrinthModSource implements ModSource { } public String getModId() { - return current.project_id; + return current.project_id(); } public ModrinthModpackManifest.File toManifest() throws IOException { - ModrinthVersion.File orig = current.files[0]; + ModrinthVersion.File orig = current.files().get(0); return new ModrinthModpackManifest.File( - "mods/" + orig.filename, + "mods/" + orig.filename(), new ModrinthHashes( - orig.hashes.sha1, - orig.hashes.sha512 + orig.hashes().sha1(), + orig.hashes().sha512() ), null, // env - List.of(orig.url), - Files.size(jarPath) + List.of(orig.url()), + Files.size(getJarPath()) ); } } diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/util/ProcessUtils.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/util/ProcessUtils.java index 2e9e657..716a92c 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/util/ProcessUtils.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/util/ProcessUtils.java @@ -25,7 +25,7 @@ public class ProcessUtils { Runtime rt = Runtime.getRuntime(); Process pr = rt.exec(command); - try (InputStreamReader isReader = new InputStreamReader(pr.inputStream); + try (InputStreamReader isReader = new InputStreamReader(pr.getInputStream()); BufferedReader bReader = new BufferedReader(isReader)) { String strLine; while ((strLine = bReader.readLine()) != null) { diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/util/VersionInfoLibraryResolver.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/util/VersionInfoLibraryResolver.java index 8c0d146..93285e9 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/util/VersionInfoLibraryResolver.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/util/VersionInfoLibraryResolver.java @@ -12,15 +12,15 @@ public class VersionInfoLibraryResolver { public static Set getRelevant(VersionInfo version) { Set artifacts = new LinkedHashSet<>(); for (VersionInfo.Library library : version.libraries) { - if (library.rules != null && !library.rules.allow) continue; - if (library.downloads.classifiers != null && library.natives != null && library.natives.containsKey(OSUtils.TYPE.mojName)) { - artifacts.add(new ArtifactInfo(library.downloads.classifiers[library.natives[OSUtils.TYPE.mojName]], true)); + if (library.rules() != null && !library.rules().allow()) continue; + if (library.downloads().classifiers() != null && library.natives() != null && library.natives().containsKey(OSUtils.TYPE.getMojName())) { + artifacts.add(new ArtifactInfo(library.downloads().classifiers().get(library.natives().get(OSUtils.TYPE.getMojName())), true)); } - if (library.downloads.artifact == null) { - Utils.LOGGER.info("Null library artifact @ " + library.name); + if (library.downloads().artifact() == null) { + Utils.LOGGER.info("Null library artifact @ " + library.name()); continue; } - artifacts.add(new ArtifactInfo(library.downloads.artifact, false)); + artifacts.add(new ArtifactInfo(library.downloads().artifact(), false)); } return artifacts; } diff --git a/launcher/src/main/java/module-info.java b/launcher/src/main/java/module-info.java new file mode 100644 index 0000000..91c081c --- /dev/null +++ b/launcher/src/main/java/module-info.java @@ -0,0 +1,32 @@ +module io.gitlab.jfronny.inceptum.launcher { + exports io.gitlab.jfronny.inceptum.launcher; + exports io.gitlab.jfronny.inceptum.launcher.api; + exports io.gitlab.jfronny.inceptum.launcher.api.account; + exports io.gitlab.jfronny.inceptum.launcher.gson; + exports io.gitlab.jfronny.inceptum.launcher.model.curseforge; + exports io.gitlab.jfronny.inceptum.launcher.model.curseforge.response; + exports io.gitlab.jfronny.inceptum.launcher.model.fabric; + exports io.gitlab.jfronny.inceptum.launcher.model.inceptum; + exports io.gitlab.jfronny.inceptum.launcher.model.microsoft; + exports io.gitlab.jfronny.inceptum.launcher.model.microsoft.request; + exports io.gitlab.jfronny.inceptum.launcher.model.microsoft.response; + exports io.gitlab.jfronny.inceptum.launcher.model.modrinth; + exports io.gitlab.jfronny.inceptum.launcher.model.mojang; + exports io.gitlab.jfronny.inceptum.launcher.model.multimc; + exports io.gitlab.jfronny.inceptum.launcher.system.exporter; + exports io.gitlab.jfronny.inceptum.launcher.system.importer; + exports io.gitlab.jfronny.inceptum.launcher.system.instance; + exports io.gitlab.jfronny.inceptum.launcher.system.launch; + exports io.gitlab.jfronny.inceptum.launcher.system.mds; + exports io.gitlab.jfronny.inceptum.launcher.system.mds.noop; + exports io.gitlab.jfronny.inceptum.launcher.system.setup; + exports io.gitlab.jfronny.inceptum.launcher.system.setup.steps; + exports io.gitlab.jfronny.inceptum.launcher.system.source; + exports io.gitlab.jfronny.inceptum.launcher.util; + exports io.gitlab.jfronny.inceptum.launcher.util.gitignore; + + requires transitive io.gitlab.jfronny.inceptum.common; + requires io.gitlab.jfronny.commons.jlhttp; + requires static org.jetbrains.annotations; + requires static io.gitlab.jfronny.gson.compile.annotations; +} \ No newline at end of file diff --git a/wrapper/src/main/java/io/gitlab/jfronny/inceptum/wrapper/Wrapper.java b/wrapper/src/main/java/io/gitlab/jfronny/inceptum/wrapper/Wrapper.java index 917741b..9526722 100644 --- a/wrapper/src/main/java/io/gitlab/jfronny/inceptum/wrapper/Wrapper.java +++ b/wrapper/src/main/java/io/gitlab/jfronny/inceptum/wrapper/Wrapper.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.wrapper; -import gsoncompile.extensions.io.gitlab.jfronny.inceptum.common.model.inceptum.WrapperConfig.GC_WrapperConfig; +import io.gitlab.jfronny.inceptum.common.model.inceptum.GC_WrapperConfig; import io.gitlab.jfronny.commons.ref.R; import io.gitlab.jfronny.inceptum.common.*; import io.gitlab.jfronny.inceptum.common.model.inceptum.UpdateChannel;