From df9d05a49c33b85a0708944c1eb0a579f6ba25a6 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sat, 6 Jul 2024 03:24:02 +0700 Subject: [PATCH] [FEATURE] Support -Dlaunchserver.dir.modules and -Dlaunchserver.dir.launcher-modules --- .../java/pro/gravit/launchserver/LaunchServer.java | 10 +++++++++- .../pro/gravit/launchserver/LaunchServerStarter.java | 9 +++++---- .../launchermodules/LauncherModuleLoader.java | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index d3a435ea..1e283ffd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -82,6 +82,8 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab */ public final Path profilesDir; public final Path tmpDir; + public final Path modulesDir; + public final Path launcherModulesDir; /** * This object contains runtime configuration */ @@ -136,6 +138,8 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La launcherLibraries = directories.launcherLibrariesDir; launcherLibrariesCompile = directories.launcherLibrariesCompileDir; launcherPack = directories.launcherPackDir; + modulesDir = directories.modules; + launcherModulesDir = directories.launcherModules; this.shardId = shardId; if(!Files.isDirectory(launcherPack)) { Files.createDirectories(launcherPack); @@ -488,7 +492,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO public static class LaunchServerDirectories { public static final String UPDATES_NAME = "updates", PROFILES_NAME = "profiles", TRUSTSTORE_NAME = "truststore", LAUNCHERLIBRARIES_NAME = "launcher-libraries", - LAUNCHERLIBRARIESCOMPILE_NAME = "launcher-libraries-compile", LAUNCHERPACK_NAME = "launcher-pack", KEY_NAME = ".keys"; + LAUNCHERLIBRARIESCOMPILE_NAME = "launcher-libraries-compile", LAUNCHERPACK_NAME = "launcher-pack", KEY_NAME = ".keys", MODULES = "modules", LAUNCHER_MODULES = "launcher-modules"; public Path updatesDir; public Path profilesDir; public Path launcherLibrariesDir; @@ -498,6 +502,8 @@ public static class LaunchServerDirectories { public Path dir; public Path trustStore; public Path tmpDir; + public Path modules; + public Path launcherModules; public void collect() { if (updatesDir == null) updatesDir = getPath(UPDATES_NAME); @@ -509,6 +515,8 @@ public void collect() { if(launcherPackDir == null) launcherPackDir = getPath(LAUNCHERPACK_NAME); if (keyDirectory == null) keyDirectory = getPath(KEY_NAME); + if (modules == null) modules = getPath(MODULES); + if (launcherModules == null) launcherModules = getPath(LAUNCHER_MODULES); if (tmpDir == null) tmpDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve("launchserver-%s".formatted(SecurityHelper.randomStringToken())); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 0ddb43b3..061ebaaa 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -52,10 +52,13 @@ public static void main(String[] args) throws Exception { try { Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider"); Security.addProvider(new BouncyCastleProvider()); - } catch (ClassNotFoundException ex) { + } catch (ClassNotFoundException | NoClassDefFoundError ex) { LogHelper.error("Library BouncyCastle not found! Is directory 'libraries' empty?"); return; } + LaunchServer.LaunchServerDirectories directories = new LaunchServer.LaunchServerDirectories(); + directories.dir = dir; + directories.collect(); CertificateManager certificateManager = new CertificateManager(); try { certificateManager.readTrustStore(dir.resolve("truststore")); @@ -79,7 +82,7 @@ public static void main(String[] args) throws Exception { LaunchServerRuntimeConfig runtimeConfig; LaunchServerConfig config; LaunchServer.LaunchServerEnv env = LaunchServer.LaunchServerEnv.PRODUCTION; - LaunchServerModulesManager modulesManager = new LaunchServerModulesManager(dir.resolve("modules"), dir.resolve("config"), certificateManager.trustManager); + LaunchServerModulesManager modulesManager = new LaunchServerModulesManager(directories.modules, dir.resolve("config"), certificateManager.trustManager); modulesManager.autoload(); modulesManager.initModules(null); registerAll(); @@ -124,8 +127,6 @@ public static void main(String[] args) throws Exception { } LaunchServer.LaunchServerConfigManager launchServerConfigManager = new BasicLaunchServerConfigManager(configFile, runtimeConfigFile); - LaunchServer.LaunchServerDirectories directories = new LaunchServer.LaunchServerDirectories(); - directories.dir = dir; LaunchServer server = new LaunchServerBuilder() .setDirectories(directories) .setEnv(env) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java b/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java index f50945a5..922efc05 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java @@ -33,7 +33,7 @@ public class LauncherModuleLoader { public LauncherModuleLoader(LaunchServer server) { this.server = server; - modulesDir = server.dir.resolve("launcher-modules"); + modulesDir = server.launcherModulesDir; } public void init() {