From b2a3e5672ab41c43ba514434f0bd1c6baef4da0c Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 12 Sep 2020 13:41:58 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE][EXPERIMENTAL]=20=D0=9D=D0=BE=D0=B2?= =?UTF-8?q?=D1=8B=D0=B9=20API=20=D0=BE=D0=BF=D1=86=D0=B8=D0=BE=D0=BD=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20=D0=BC=D0=BE=D0=B4=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/LaunchServerStarter.java | 2 + .../manangers/LaunchServerGsonManager.java | 2 + .../pro/gravit/launcher/LauncherEngine.java | 4 + .../client/ClientLauncherEntryPoint.java | 13 +- .../client/ClientLauncherProcess.java | 32 ++++- .../launcher/profiles/ClientProfile.java | 12 +- .../profiles/optional/OptionalFile.java | 6 + .../profiles/optional/OptionalView.java | 113 ++++++++++++++++++ .../optional/actions/OptionalAction.java | 19 +++ .../actions/OptionalActionClassPath.java | 8 ++ .../actions/OptionalActionClientArgs.java | 7 ++ .../optional/actions/OptionalActionFile.java | 29 +++++ .../actions/OptionalActionJvmArgs.java | 7 ++ .../websockets/ClientWebSocketService.java | 2 + .../pro/gravit/launcher/hasher/HashedDir.java | 41 +++++++ .../gravit/launcher/server/ServerWrapper.java | 2 + 16 files changed, 284 insertions(+), 15 deletions(-) create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalAction.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionClassPath.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionClientArgs.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionFile.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionJvmArgs.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 5da93a4f..7e012dfe 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -4,6 +4,7 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherTrustManager; import pro.gravit.launcher.modules.events.PreConfigPhase; +import pro.gravit.launcher.profiles.optional.actions.OptionalAction; import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launchserver.auth.handler.AuthHandler; import pro.gravit.launchserver.auth.protect.ProtectHandler; @@ -213,6 +214,7 @@ public static void registerAll() { DaoProvider.registerProviders(); AuthRequest.registerProviders(); HWIDProvider.registerProviders(); + OptionalAction.registerProviders(); } public static void generateConfigIfNotExists(Path configFile, CommandHandler commandHandler, LaunchServer.LaunchServerEnv env) throws IOException { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java index f19ca95f..b4d3d9c8 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java @@ -3,6 +3,7 @@ import com.google.gson.GsonBuilder; import pro.gravit.launcher.managers.GsonManager; import pro.gravit.launcher.modules.events.PreGsonPhase; +import pro.gravit.launcher.profiles.optional.actions.OptionalAction; import pro.gravit.launcher.request.JsonResultSerializeAdapter; import pro.gravit.launcher.request.WebSocketEvent; import pro.gravit.launcher.request.auth.AuthRequest; @@ -39,6 +40,7 @@ public void registerAdapters(GsonBuilder builder) { builder.registerTypeAdapter(WebSocketEvent.class, new JsonResultSerializeAdapter()); builder.registerTypeAdapter(AuthRequest.AuthPasswordInterface.class, new UniversalJsonAdapter<>(AuthRequest.providers)); builder.registerTypeAdapter(HWIDProvider.class, new UniversalJsonAdapter<>(HWIDProvider.providers)); + builder.registerTypeAdapter(OptionalAction.class, new UniversalJsonAdapter<>(OptionalAction.providers)); modulesManager.invokeEvent(new PreGsonPhase(builder)); //ClientWebSocketService.appendTypeAdapters(builder); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 1b3bcdf3..3d30f34d 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -13,8 +13,10 @@ import pro.gravit.launcher.managers.ClientGsonManager; import pro.gravit.launcher.managers.ConsoleManager; import pro.gravit.launcher.modules.events.PreConfigPhase; +import pro.gravit.launcher.profiles.optional.actions.OptionalAction; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.RequestException; +import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.RestoreSessionRequest; import pro.gravit.launcher.request.websockets.StdWebSocketService; import pro.gravit.launcher.utils.NativeJVMHalt; @@ -113,6 +115,8 @@ public static void main(String... args) throws Throwable { } public static void initGson(ClientModuleManager modulesManager) { + AuthRequest.registerProviders(); + OptionalAction.registerProviders(); Launcher.gsonManager = new ClientGsonManager(modulesManager); Launcher.gsonManager.initGson(); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java index cf1ebcc0..ef0cb3d0 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java @@ -14,8 +14,11 @@ import pro.gravit.launcher.modules.events.PreConfigPhase; import pro.gravit.launcher.patches.FMLPatcher; import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.profiles.optional.actions.OptionalAction; +import pro.gravit.launcher.profiles.optional.actions.OptionalActionClassPath; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.RequestException; +import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.RestoreSessionRequest; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.utils.DirWatcher; @@ -95,9 +98,10 @@ public static void main(String[] args) throws Throwable { List classpath = new LinkedList<>(); resolveClassPathStream(clientDir, params.profile.getClassPath()).map(IOHelper::toURL).collect(Collectors.toCollection(() -> classpath)); - params.profile.pushOptionalClassPath((opt) -> { - resolveClassPathStream(clientDir, opt).map(IOHelper::toURL).collect(Collectors.toCollection(() -> classpath)); - }); + for(OptionalAction a : params.actions) { + if(a instanceof OptionalActionClassPath) + resolveClassPathStream(clientDir, ((OptionalActionClassPath) a).args).map(IOHelper::toURL).collect(Collectors.toCollection(() -> classpath)); + } classLoader = new ClientClassLoader(classpath.toArray(new URL[0]), ClassLoader.getSystemClassLoader()); Thread.currentThread().setContextClassLoader(classLoader); classLoader.nativePath = clientDir.resolve("natives").toString(); @@ -145,7 +149,6 @@ public static void main(String[] args) throws Throwable { // if (params.updateOptional.contains(s)) s.mark = true; // else hdir.removeR(s.file); //} - Launcher.profile.pushOptionalFile(params.clientHDir, false); // Start WatchService, and only then client CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start(); CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start(); @@ -162,6 +165,8 @@ public static void main(String[] args) throws Throwable { } private static void initGson(ClientModuleManager moduleManager) { + AuthRequest.registerProviders(); + OptionalAction.registerProviders(); Launcher.gsonManager = new ClientGsonManager(moduleManager); Launcher.gsonManager.initGson(); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java index 3d958746..50789552 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java @@ -10,6 +10,10 @@ import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.PlayerProfile; +import pro.gravit.launcher.profiles.optional.OptionalView; +import pro.gravit.launcher.profiles.optional.actions.OptionalAction; +import pro.gravit.launcher.profiles.optional.actions.OptionalActionClientArgs; +import pro.gravit.launcher.profiles.optional.actions.OptionalActionJvmArgs; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.utils.Version; @@ -49,17 +53,17 @@ public ClientLauncherProcess(Path executeFile, Path workDir, Path javaDir, Strin public ClientLauncherProcess(Path clientDir, Path assetDir, Path javaDir, ClientProfile profile, PlayerProfile playerProfile, String accessToken, HashedDir clientHDir, HashedDir assetHDir, HashedDir jvmHDir) { - this(clientDir, assetDir, javaDir, clientDir.resolve("resourcepacks"), profile, playerProfile, accessToken, clientHDir, assetHDir, jvmHDir); + this(clientDir, assetDir, javaDir, clientDir.resolve("resourcepacks"), profile, playerProfile, null, accessToken, clientHDir, assetHDir, jvmHDir); } public ClientLauncherProcess(Path clientDir, Path assetDir, ClientProfile profile, PlayerProfile playerProfile, String accessToken, HashedDir clientHDir, HashedDir assetHDir, HashedDir jvmHDir) { - this(clientDir, assetDir, Paths.get(System.getProperty("java.home")), clientDir.resolve("resourcepacks"), profile, playerProfile, accessToken, clientHDir, assetHDir, jvmHDir); + this(clientDir, assetDir, Paths.get(System.getProperty("java.home")), clientDir.resolve("resourcepacks"), profile, playerProfile, null, accessToken, clientHDir, assetHDir, jvmHDir); } public ClientLauncherProcess(Path clientDir, Path assetDir, Path javaDir, Path resourcePackDir, - ClientProfile profile, PlayerProfile playerProfile, String accessToken, + ClientProfile profile, PlayerProfile playerProfile, OptionalView view, String accessToken, HashedDir clientHDir, HashedDir assetHDir, HashedDir jvmHDir) { this.workDir = clientDir.toAbsolutePath(); this.javaDir = javaDir; @@ -74,6 +78,10 @@ public ClientLauncherProcess(Path clientDir, Path assetDir, Path javaDir, Path r this.params.assetHDir = assetHDir; this.params.clientHDir = clientHDir; this.params.javaHDir = jvmHDir; + if(view != null) + { + this.params.actions = view.getEnabledActions(); + } this.bits = JVMHelper.JVM_BITS; applyClientProfile(); } @@ -88,7 +96,13 @@ public static String getPathSeparator() { private void applyClientProfile() { this.systemClassPath.add(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toAbsolutePath().toString()); Collections.addAll(this.jvmArgs, this.params.profile.getJvmArgs()); - this.params.profile.pushOptionalJvmArgs(this.jvmArgs); + for(OptionalAction a : this.params.actions) + { + if(a instanceof OptionalActionJvmArgs) + { + this.jvmArgs.addAll(((OptionalActionJvmArgs) a).args); + } + } this.systemEnv.put("JAVA_HOME", javaDir.toString()); Collections.addAll(this.systemClassPath, this.params.profile.getAlternativeClassPath()); if (params.ram > 0) { @@ -193,6 +207,8 @@ public static class ClientParams { public int height; + public Set actions = new HashSet<>(); + //======== public UUID session; @@ -263,7 +279,13 @@ private void addModernClientArgs(Collection args) { Collections.addAll(args, "--server", profile.getServerAddress()); Collections.addAll(args, "--port", Integer.toString(profile.getServerPort())); } - profile.pushOptionalClientArgs(args); + for(OptionalAction a : actions) + { + if(a instanceof OptionalActionClientArgs) + { + args.addAll(((OptionalActionClientArgs) a).args); + } + } // Add window size args if (fullScreen) Collections.addAll(args, "--fullscreen", Boolean.toString(true)); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index 693e0c7b..286e8cc1 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -194,7 +194,7 @@ public OptionalFile getOptionalFile(String file, OptionalType type) { public Collection getShared() { return updateShared; } - + @Deprecated public void markOptional(OptionalFile file) { if (file.mark) return; @@ -213,7 +213,7 @@ public void markOptional(OptionalFile file) { } } } - + @Deprecated public void unmarkOptional(OptionalFile file) { if (!file.mark) return; file.mark = false; @@ -239,7 +239,7 @@ public void unmarkOptional(OptionalFile file) { } } } - + @Deprecated public void pushOptionalFile(HashedDir dir, boolean digest) { for (OptionalFile opt : updateOptional) { if (opt.type.equals(OptionalType.FILE) && !opt.mark) { @@ -248,7 +248,7 @@ public void pushOptionalFile(HashedDir dir, boolean digest) { } } } - + @Deprecated public void pushOptionalJvmArgs(Collection jvmArgs1) { for (OptionalFile opt : updateOptional) { if (opt.type.equals(OptionalType.JVMARGS) && opt.mark) { @@ -256,7 +256,7 @@ public void pushOptionalJvmArgs(Collection jvmArgs1) { } } } - + @Deprecated public void pushOptionalClientArgs(Collection clientArgs1) { for (OptionalFile opt : updateOptional) { if (opt.type.equals(OptionalType.CLIENTARGS) && opt.mark) { @@ -264,7 +264,7 @@ public void pushOptionalClientArgs(Collection clientArgs1) { } } } - + @Deprecated public void pushOptionalClassPath(pushOptionalClassPathCallback callback) throws IOException { for (OptionalFile opt : updateOptional) { if (opt.type.equals(OptionalType.CLASSPATH) && opt.mark) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java index c2a5fc21..3addee6e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java @@ -1,12 +1,14 @@ package pro.gravit.launcher.profiles.optional; import pro.gravit.launcher.LauncherNetworkAPI; +import pro.gravit.launcher.profiles.optional.actions.OptionalAction; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.utils.helper.LogHelper; import java.io.IOException; import java.util.Collection; +import java.util.List; import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -16,10 +18,14 @@ public class OptionalFile { @LauncherNetworkAPI public final long permissions = 0L; @LauncherNetworkAPI + @Deprecated public String[] list; @LauncherNetworkAPI + @Deprecated public OptionalType type; @LauncherNetworkAPI + public List actions; + @LauncherNetworkAPI public boolean mark; @LauncherNetworkAPI public boolean visible = true; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java new file mode 100644 index 00000000..071bf9d9 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java @@ -0,0 +1,113 @@ +package pro.gravit.launcher.profiles.optional; + +import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.profiles.optional.actions.OptionalAction; + +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +public class OptionalView { + public Set enabled = new HashSet<>(); + public Set all; + + @SuppressWarnings("unchecked") + public Set getActionsByClass(Class clazz) + { + Set results = new HashSet<>(); + for(OptionalFile e : enabled) + { + if(e.actions != null) + { + for(OptionalAction a : e.actions) + { + if(clazz.isAssignableFrom(a.getClass())) + { + results.add((T) a); + } + } + } + } + return results; + } + + public Set getEnabledActions() + { + Set results = new HashSet<>(); + for(OptionalFile e : enabled) + { + if(e.actions != null) + { + results.addAll(e.actions); + } + } + return results; + } + + public Set getDisabledActions() + { + Set results = new HashSet<>(); + for(OptionalFile e : all) + { + if(enabled.contains(e)) continue; + if(e.actions != null) + { + results.addAll(e.actions); + } + } + return results; + } + + public void enable(OptionalFile file) + { + if(enabled.contains(file)) return; + enabled.add(file); + file.watchEvent(true); + if (file.dependencies != null) { + for (OptionalFile dep : file.dependencies) { + if (dep.dependenciesCount == null) dep.dependenciesCount = new HashSet<>(); + dep.dependenciesCount.add(file); + enable(dep); + } + } + if (file.conflict != null) { + for (OptionalFile conflict : file.conflict) { + disable(conflict); + } + } + } + public void disable(OptionalFile file) + { + if(!enabled.remove(file)) return; + file.watchEvent(false); + if (file.dependenciesCount != null) { + for (OptionalFile f : file.dependenciesCount) { + if (f.isPreset) continue; + disable(f); + } + file.dependenciesCount.clear(); + file.dependenciesCount = null; + } + if (file.dependencies != null) { + for (OptionalFile f : file.dependencies) { + if (!enabled.contains(f)) continue; + if (f.dependenciesCount == null) { + disable(f); + } else if (f.dependenciesCount.size() <= 1) { + f.dependenciesCount.clear(); + f.dependenciesCount = null; + disable(f); + } + } + } + } + public OptionalView(ClientProfile profile) + { + this.all = profile.getOptional(); + for(OptionalFile f : this.all) + { + if(f.mark) enable(f); + } + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalAction.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalAction.java new file mode 100644 index 00000000..e6dd8483 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalAction.java @@ -0,0 +1,19 @@ +package pro.gravit.launcher.profiles.optional.actions; + +import pro.gravit.utils.ProviderMap; + +public class OptionalAction { + public static ProviderMap providers = new ProviderMap<>(); + private static boolean registerProviders = false; + public static void registerProviders() + { + if(!registerProviders) + { + providers.register("file", OptionalActionFile.class); + providers.register("clientArgs", OptionalActionClientArgs.class); + providers.register("jvmArgs", OptionalActionJvmArgs.class); + providers.register("classpath", OptionalActionClassPath.class); + registerProviders = true; + } + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionClassPath.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionClassPath.java new file mode 100644 index 00000000..b3d592cd --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionClassPath.java @@ -0,0 +1,8 @@ +package pro.gravit.launcher.profiles.optional.actions; + +import java.util.List; + +public class OptionalActionClassPath extends OptionalAction { + public String[] args; + public boolean useAltClasspath = false; +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionClientArgs.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionClientArgs.java new file mode 100644 index 00000000..32d907ee --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionClientArgs.java @@ -0,0 +1,7 @@ +package pro.gravit.launcher.profiles.optional.actions; + +import java.util.List; + +public class OptionalActionClientArgs extends OptionalAction { + public List args; +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionFile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionFile.java new file mode 100644 index 00000000..4b9d5e53 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionFile.java @@ -0,0 +1,29 @@ +package pro.gravit.launcher.profiles.optional.actions; + +import pro.gravit.launcher.hasher.HashedDir; + +import java.util.List; +import java.util.Map; + +public class OptionalActionFile extends OptionalAction { + public Map files; + public void injectToHashedDir(HashedDir dir) + { + if(files == null) return; + files.forEach((k,v) -> { + HashedDir.FindRecursiveResult firstPath = dir.findRecursive(k); + if (v != null && !v.isEmpty()) { + HashedDir.FindRecursiveResult secondPath = dir.findRecursive(v); + firstPath.parent.moveTo(firstPath.name, secondPath.parent, secondPath.name); + } + }); + } + public void disableInHashedDir(HashedDir dir) + { + if(files == null) return; + files.forEach((k,v) -> { + HashedDir.FindRecursiveResult firstPath = dir.findRecursive(k); + firstPath.parent.remove(firstPath.name); + }); + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionJvmArgs.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionJvmArgs.java new file mode 100644 index 00000000..a5e5150e --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionJvmArgs.java @@ -0,0 +1,7 @@ +package pro.gravit.launcher.profiles.optional.actions; + +import java.util.List; + +public class OptionalActionJvmArgs extends OptionalAction { + public List args; +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java index bdf77791..7f0ef48e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -9,6 +9,7 @@ import pro.gravit.launcher.events.request.*; import pro.gravit.launcher.hasher.HashedEntry; import pro.gravit.launcher.hasher.HashedEntryAdapter; +import pro.gravit.launcher.profiles.optional.actions.OptionalAction; import pro.gravit.launcher.request.WebSocketEvent; import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.utils.ProviderMap; @@ -40,6 +41,7 @@ public static void appendTypeAdapters(GsonBuilder builder) { builder.registerTypeAdapter(WebSocketEvent.class, new UniversalJsonAdapter<>(ClientWebSocketService.results)); builder.registerTypeAdapter(WebSocketRequest.class, new UniversalJsonAdapter<>(ClientWebSocketService.requests)); builder.registerTypeAdapter(AuthRequest.AuthPasswordInterface.class, new UniversalJsonAdapter<>(AuthRequest.providers)); + builder.registerTypeAdapter(OptionalAction.class, new UniversalJsonAdapter<>(OptionalAction.providers)); } private static URI createURL(String address) { diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java index e46894c1..cfdda33d 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java @@ -100,6 +100,47 @@ public void removeR(String name) { } } } + public void moveTo(String elementName, HashedDir target, String targetElementName) + { + HashedEntry entry = map.remove(elementName); + target.map.put(targetElementName, entry); + } + public static class FindRecursiveResult + { + public HashedDir parent; + public HashedEntry entry; + public String name; + + public FindRecursiveResult(HashedDir parent, HashedEntry entry, String name) { + this.parent = parent; + this.entry = entry; + this.name = name; + } + } + public FindRecursiveResult findRecursive(String path) + { + StringTokenizer t = new StringTokenizer(path, "/"); + HashedDir current = this; + HashedEntry entry = null; + String name = null; + while (t.hasMoreTokens()) { + name = t.nextToken(); + HashedEntry e = current.map.get(name); + if (e.getType() == Type.DIR) { + if(!t.hasMoreTokens()) { + entry = e; + break; + } + else { + current = ((HashedDir) e); + } + } else { + entry = e; + break; + } + } + return new FindRecursiveResult(current, entry, name); + } public HashedEntry getEntry(String name) { return map.get(name); diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index 28e56e90..1b4edb25 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -8,6 +8,7 @@ import pro.gravit.launcher.modules.events.PostInitPhase; import pro.gravit.launcher.modules.events.PreConfigPhase; import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.profiles.optional.actions.OptionalAction; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.RequestException; import pro.gravit.launcher.request.auth.AuthRequest; @@ -115,6 +116,7 @@ public boolean loopAuth(int count, int sleeptime) { public void run(String... args) throws Throwable { initGson(modulesManager); AuthRequest.registerProviders(); + OptionalAction.registerProviders(); if (args.length > 0 && args[0].equals("setup") && !disableSetup) { LogHelper.debug("Read ServerWrapperConfig.json"); loadConfig();