summaryrefslogtreecommitdiffstats
path: root/core/src/main/java/dev/figboot/launcher
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/java/dev/figboot/launcher')
-rw-r--r--core/src/main/java/dev/figboot/launcher/core/Launcher.java24
-rw-r--r--core/src/main/java/dev/figboot/launcher/core/LauncherInterfaceAccess.java7
-rw-r--r--core/src/main/java/dev/figboot/launcher/core/config/LauncherConfiguration.java8
-rw-r--r--core/src/main/java/dev/figboot/launcher/core/config/SimpleLauncherConfiguration.java24
-rw-r--r--core/src/main/java/dev/figboot/launcher/core/system/CurrentSystemInfo.java147
-rw-r--r--core/src/main/java/dev/figboot/launcher/core/system/SystemInfo.java38
-rw-r--r--core/src/main/java/dev/figboot/launcher/core/task/Task.java5
-rw-r--r--core/src/main/java/dev/figboot/launcher/core/version/CompleteVersion.java4
-rw-r--r--core/src/main/java/dev/figboot/launcher/core/version/VersionInfo.java11
-rw-r--r--core/src/main/java/dev/figboot/launcher/core/version/VersionManifest.java5
-rw-r--r--core/src/main/java/dev/figboot/launcher/core/version/VersionStorage.java10
11 files changed, 283 insertions, 0 deletions
diff --git a/core/src/main/java/dev/figboot/launcher/core/Launcher.java b/core/src/main/java/dev/figboot/launcher/core/Launcher.java
new file mode 100644
index 0000000..a95fed4
--- /dev/null
+++ b/core/src/main/java/dev/figboot/launcher/core/Launcher.java
@@ -0,0 +1,24 @@
+package dev.figboot.launcher.core;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+
+public class Launcher {
+ private static final Logger LOGGER = LoggerFactory.getLogger(Launcher.class);
+
+ protected final LauncherInterfaceAccess iface;
+ protected final ScheduledExecutorService service;
+
+ public Launcher(LauncherInterfaceAccess iface) {
+ this.iface = iface;
+ service = new ScheduledThreadPoolExecutor(4);
+ }
+
+ public void loadVersions() throws IOException {
+
+ }
+}
diff --git a/core/src/main/java/dev/figboot/launcher/core/LauncherInterfaceAccess.java b/core/src/main/java/dev/figboot/launcher/core/LauncherInterfaceAccess.java
new file mode 100644
index 0000000..b1292ae
--- /dev/null
+++ b/core/src/main/java/dev/figboot/launcher/core/LauncherInterfaceAccess.java
@@ -0,0 +1,7 @@
+package dev.figboot.launcher.core;
+
+import dev.figboot.launcher.core.task.Task;
+
+public interface LauncherInterfaceAccess {
+ Task createTask(String description);
+}
diff --git a/core/src/main/java/dev/figboot/launcher/core/config/LauncherConfiguration.java b/core/src/main/java/dev/figboot/launcher/core/config/LauncherConfiguration.java
new file mode 100644
index 0000000..99bcca4
--- /dev/null
+++ b/core/src/main/java/dev/figboot/launcher/core/config/LauncherConfiguration.java
@@ -0,0 +1,8 @@
+package dev.figboot.launcher.core.config;
+
+import java.nio.file.Path;
+
+public interface LauncherConfiguration {
+ Path getConfigPath();
+ Path getInstancesPath();
+}
diff --git a/core/src/main/java/dev/figboot/launcher/core/config/SimpleLauncherConfiguration.java b/core/src/main/java/dev/figboot/launcher/core/config/SimpleLauncherConfiguration.java
new file mode 100644
index 0000000..15ab1be
--- /dev/null
+++ b/core/src/main/java/dev/figboot/launcher/core/config/SimpleLauncherConfiguration.java
@@ -0,0 +1,24 @@
+package dev.figboot.launcher.core.config;
+
+import dev.figboot.launcher.core.system.SystemInfo;
+
+import java.nio.file.Path;
+
+public class SimpleLauncherConfiguration implements LauncherConfiguration {
+ //private final Path configPath, instancePath;
+
+ public SimpleLauncherConfiguration() {
+
+ //configPath = FileSystems.getDefault().
+ }
+
+ @Override
+ public Path getConfigPath() {
+ return null;
+ }
+
+ @Override
+ public Path getInstancesPath() {
+ return null;
+ }
+}
diff --git a/core/src/main/java/dev/figboot/launcher/core/system/CurrentSystemInfo.java b/core/src/main/java/dev/figboot/launcher/core/system/CurrentSystemInfo.java
new file mode 100644
index 0000000..0c67506
--- /dev/null
+++ b/core/src/main/java/dev/figboot/launcher/core/system/CurrentSystemInfo.java
@@ -0,0 +1,147 @@
+package dev.figboot.launcher.core.system;
+
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
+class CurrentSystemInfo implements SystemInfo {
+ private static final Logger LOGGER = LoggerFactory.getLogger(CurrentSystemInfo.class);
+
+ private static CurrentSystemInfo info = null;
+
+ static synchronized CurrentSystemInfo get() {
+ if (info != null) {
+ return info;
+ }
+
+ return (info = gather());
+ }
+
+ private static String logSystemProperty(String key, String value, boolean custom) {
+ LOGGER.info("System property: \"{}\" = {}{}", key, value == null ? "(unset)" : value, custom ? " (*)" : "");
+ return value;
+ }
+
+ private static String getSystemProperty(String key) {
+ String customVal = System.getProperty("dev.figboot.launcher.core.SystemInfo." + key);
+ if (customVal != null)
+ return logSystemProperty(key, customVal, true);
+ return logSystemProperty(key, System.getProperty(key), false);
+ }
+
+ private static boolean isBitMismatchCondition(OperatingSystem os) {
+ if (System.getProperty("dev.figboot.launcher.core.SystemInfo.acknowledgeBitMismatch") != null) return false;
+ if (os != OperatingSystem.WINDOWS) return false; // seems like only windows users typically have this issue
+
+ String realArch = System.getenv("PROCESSOR_ARCHITEW6432");
+ return realArch != null && realArch.equalsIgnoreCase("amd64");
+ }
+
+ private static String getRuntimePlatform(OperatingSystem os, String arch) {
+ for (RuntimePlatformRule rule : JRE_PLAT_RULES) {
+ if (rule.matches(os, arch)) {
+ LOGGER.info("Java runtime platform detected as '{}'.", rule.platform);
+ return rule.platform;
+ }
+ }
+
+ LOGGER.info("Java runtime platform not detected. Please file a bug report if you believe your platform should be detected.");
+ return "gamecore";
+ }
+
+ private static CurrentSystemInfo gather() {
+ String osName = getSystemProperty("os.name");
+ String osArch = getSystemProperty("os.arch");
+ String osVersion = getSystemProperty("os.version");
+
+ String fileSep = getSystemProperty("file.separator");
+ String pathSep = getSystemProperty("path.separator");
+
+ OperatingSystem detectedOS = OperatingSystem.UNKNOWN;
+ int archBits;
+
+ for (Map.Entry<OperatingSystem, Pattern> ent : OS_PATTERNS.entrySet()) {
+ if (ent.getValue().matcher(osName).find()) { // NOTE: not necessarily a complete match
+ LOGGER.info("Detected operating system: {}", ent.getKey());
+ detectedOS = ent.getKey();
+ }
+ }
+
+ if (detectedOS == OperatingSystem.UNKNOWN) {
+ LOGGER.warn("Unknown operating system \"{}\"! The launcher may not function correctly.", osName);
+ LOGGER.warn("Try specifying \"windows\" or \"macos\" or \"linux\" in the \"dev.figboot.launcher.core.SystemInfo.os.name\" system property, " +
+ "and consider filing a bug report with your OS details if you believe your OS should be detected automatically.");
+ }
+
+ if (osArch.contains("64")) { // seems to work well enough.
+ archBits = 64;
+ } else {
+ archBits = 32;
+
+ if (isBitMismatchCondition(detectedOS)) {
+ /* NOTE: it's not safe to just pretend we're on 64-bit windows, since WOW64 mode changes various things
+ * about the application's environment. I don't intend to do more than just send a warning in the log. */
+ LOGGER.warn("It appears that you're using a 32-bit version of java on 64-bit Windows. You may have issues " +
+ "launching the game when using Mojang-provided java runtimes. To suppress this warning, define the " +
+ "\"dev.figboot.launcher.core.SystemInfo.acknowledgeBitMismatch\" system property.");
+ }
+ }
+
+ return new CurrentSystemInfo(detectedOS, getRuntimePlatform(detectedOS, osArch), archBits, osArch, osVersion, fileSep, pathSep);
+ }
+
+ @Getter private final OperatingSystem operatingSystem;
+ @Getter private final String runtimePlatform;
+ @Getter private final int archBits;
+
+ @Getter private final String archName;
+ @Getter private final String osVersion;
+
+ @Getter private final String fileSeparator;
+ @Getter private final String pathSeparator;
+
+ private static final Pattern ARCH_X8664 = Pattern.compile("^((x(86_)?|amd|ia)64)$", Pattern.CASE_INSENSITIVE);
+ private static final Pattern ARCH_X86 = Pattern.compile("^(x86(_?32)?|i[3-6]86|ia32|x32)$", Pattern.CASE_INSENSITIVE);
+ private static final Pattern ARCH_ARM64 = Pattern.compile("^aarch64$", Pattern.CASE_INSENSITIVE);
+ private static final Pattern ARCH_PPC = Pattern.compile("^ppc$", Pattern.CASE_INSENSITIVE);
+
+ private static final RuntimePlatformRule[] JRE_PLAT_RULES = {
+ new RuntimePlatformRule(OperatingSystem.WINDOWS, ARCH_X8664, "windows-x64"),
+ new RuntimePlatformRule(OperatingSystem.WINDOWS, ARCH_X86, "windows-x86"),
+ new RuntimePlatformRule(OperatingSystem.WINDOWS, ARCH_ARM64, "windows-arm64"),
+ new RuntimePlatformRule(OperatingSystem.MACOS, ARCH_PPC, "mac-os"),
+ new RuntimePlatformRule(OperatingSystem.MACOS, ARCH_ARM64, "mac-os-arm64"),
+ new RuntimePlatformRule(OperatingSystem.LINUX, ARCH_X8664, "linux"),
+ new RuntimePlatformRule(OperatingSystem.LINUX, ARCH_X86, "linux-i386")
+ };
+
+ private static final Map<OperatingSystem, Pattern> OS_PATTERNS;
+
+ static {
+ OS_PATTERNS = new EnumMap<>(OperatingSystem.class);
+
+ OS_PATTERNS.put(OperatingSystem.WINDOWS, Pattern.compile("^windows", Pattern.CASE_INSENSITIVE));
+ OS_PATTERNS.put(OperatingSystem.MACOS, Pattern.compile("^(darwin$|mac)", Pattern.CASE_INSENSITIVE));
+
+ // are BSDs and other UNIXs "close enough" to being Linux?
+ OS_PATTERNS.put(OperatingSystem.LINUX, Pattern.compile("^linux", Pattern.CASE_INSENSITIVE));
+ }
+
+ @RequiredArgsConstructor
+ private static class RuntimePlatformRule {
+ private final OperatingSystem os;
+ private final Pattern archPattern;
+ private final String platform;
+
+ boolean matches(OperatingSystem os, String arch) {
+ return this.os == os && archPattern.matcher(arch).find();
+ }
+ }
+}
diff --git a/core/src/main/java/dev/figboot/launcher/core/system/SystemInfo.java b/core/src/main/java/dev/figboot/launcher/core/system/SystemInfo.java
new file mode 100644
index 0000000..2ed8237
--- /dev/null
+++ b/core/src/main/java/dev/figboot/launcher/core/system/SystemInfo.java
@@ -0,0 +1,38 @@
+package dev.figboot.launcher.core.system;
+
+import lombok.RequiredArgsConstructor;
+
+public interface SystemInfo {
+ static SystemInfo current() {
+ return CurrentSystemInfo.get();
+ }
+
+ OperatingSystem getOperatingSystem();
+ String getRuntimePlatform();
+ int getArchBits();
+
+ String getArchName();
+ String getOsVersion();
+
+ String getFileSeparator();
+ String getPathSeparator();
+
+ @RequiredArgsConstructor
+ enum OperatingSystem {
+ WINDOWS,
+ MACOS,
+ LINUX,
+ UNKNOWN;
+
+ public OperatingSystem getByVersionName(String name) {
+ switch (name) {
+ case "windows": return WINDOWS;
+ case "osx": return MACOS;
+ case "linux": return LINUX;
+ }
+
+ // don't return UNKNOWN here, it could mask a launcher bug
+ throw new IllegalArgumentException("unknown OS family name: '" + name + "'");
+ }
+ }
+}
diff --git a/core/src/main/java/dev/figboot/launcher/core/task/Task.java b/core/src/main/java/dev/figboot/launcher/core/task/Task.java
new file mode 100644
index 0000000..9fb603a
--- /dev/null
+++ b/core/src/main/java/dev/figboot/launcher/core/task/Task.java
@@ -0,0 +1,5 @@
+package dev.figboot.launcher.core.task;
+
+public interface Task {
+ void complete();
+}
diff --git a/core/src/main/java/dev/figboot/launcher/core/version/CompleteVersion.java b/core/src/main/java/dev/figboot/launcher/core/version/CompleteVersion.java
new file mode 100644
index 0000000..b69b857
--- /dev/null
+++ b/core/src/main/java/dev/figboot/launcher/core/version/CompleteVersion.java
@@ -0,0 +1,4 @@
+package dev.figboot.launcher.core.version;
+
+public interface CompleteVersion extends VersionInfo {
+}
diff --git a/core/src/main/java/dev/figboot/launcher/core/version/VersionInfo.java b/core/src/main/java/dev/figboot/launcher/core/version/VersionInfo.java
new file mode 100644
index 0000000..4ffb588
--- /dev/null
+++ b/core/src/main/java/dev/figboot/launcher/core/version/VersionInfo.java
@@ -0,0 +1,11 @@
+package dev.figboot.launcher.core.version;
+
+import java.util.Date;
+
+public interface VersionInfo {
+ String getId();
+ Object getType();
+ Date getTime();
+ Date getUpdateTime();
+ int getComplianceLevel();
+}
diff --git a/core/src/main/java/dev/figboot/launcher/core/version/VersionManifest.java b/core/src/main/java/dev/figboot/launcher/core/version/VersionManifest.java
new file mode 100644
index 0000000..2bc4ac6
--- /dev/null
+++ b/core/src/main/java/dev/figboot/launcher/core/version/VersionManifest.java
@@ -0,0 +1,5 @@
+package dev.figboot.launcher.core.version;
+
+public interface VersionManifest extends VersionStorage<VersionInfo> {
+
+}
diff --git a/core/src/main/java/dev/figboot/launcher/core/version/VersionStorage.java b/core/src/main/java/dev/figboot/launcher/core/version/VersionStorage.java
new file mode 100644
index 0000000..7381d5a
--- /dev/null
+++ b/core/src/main/java/dev/figboot/launcher/core/version/VersionStorage.java
@@ -0,0 +1,10 @@
+package dev.figboot.launcher.core.version;
+
+public interface VersionStorage<V extends VersionInfo> {
+ /**
+ * Gets an (already loaded) version from this storage's cache.
+ * @param id the version id (string)
+ * @return the version info or null
+ */
+ V getVersion(String id);
+}