diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 44c716a7..2720e668 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -476,6 +476,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO profile = Launcher.gsonManager.gson.fromJson(reader, ClientProfile.class); } profile.verify(); + profile.setProfileFilePath(file); // Add SIGNED profile to result list result.add(profile); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/DeleteProfileCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/DeleteProfileCommand.java new file mode 100644 index 00000000..0331f614 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/DeleteProfileCommand.java @@ -0,0 +1,56 @@ +package pro.gravit.launchserver.command.profiles; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; +import pro.gravit.utils.helper.IOHelper; + +import java.nio.file.Files; + +public class DeleteProfileCommand extends Command { + private final transient Logger logger = LogManager.getLogger(ListProfilesCommand.class); + public DeleteProfileCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[uuid/title]"; + } + + @Override + public String getUsageDescription() { + return "permanently delete profile"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args, 1); + ClientProfile profile = null; + for(var p : server.getProfiles()) { + if(p.getUUID().toString().equals(args[0]) || p.getTitle().equals(args[1])) { + profile = p; + break; + } + } + if(profile == null) { + logger.error("Profile {} not found", args[0]); + return; + } + var clientDir = server.updatesDir.resolve(profile.getDir()).toAbsolutePath(); + logger.warn("THIS ACTION DELETE PROFILE AND ALL FILES IN {}", clientDir); + if(!showApplyDialog("Continue?")) { + return; + } + logger.info("Delete {}", clientDir); + IOHelper.deleteDir(clientDir, true); + var profileFile = profile.getProfileFilePath(); + if(profileFile == null) { + profileFile = server.profilesDir.resolve(profile.getTitle().concat(".json")); + } + logger.info("Delete {}", profileFile); + Files.deleteIfExists(profileFile); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/ListProfilesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/ListProfilesCommand.java new file mode 100644 index 00000000..8eaa913e --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/ListProfilesCommand.java @@ -0,0 +1,30 @@ +package pro.gravit.launchserver.command.profiles; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; + +public class ListProfilesCommand extends Command { + private final transient Logger logger = LogManager.getLogger(ListProfilesCommand.class); + public ListProfilesCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return null; + } + + @Override + public String getUsageDescription() { + return "show all profiles"; + } + + @Override + public void invoke(String... args) throws Exception { + for(var profile : server.getProfiles()) { + logger.info("{} ({}) {}", profile.getTitle(), profile.getVersion().toString(), profile.isLimited() ? "limited" : ""); + } + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/ProfilesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/ProfilesCommand.java index 395c1945..c9d7a2c7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/ProfilesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/ProfilesCommand.java @@ -9,6 +9,8 @@ public ProfilesCommand(LaunchServer server) { this.childCommands.put("make", new MakeProfileCommand(server)); this.childCommands.put("save", new SaveProfilesCommand(server)); this.childCommands.put("clone", new CloneProfileCommand(server)); + this.childCommands.put("list", new ListProfilesCommand(server)); + this.childCommands.put("delete", new DeleteProfileCommand(server)); } @Override diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleManager.java index db3668a4..bb510661 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleManager.java @@ -2,7 +2,6 @@ import pro.gravit.launcher.core.LauncherTrustManager; import pro.gravit.launcher.base.modules.*; -import pro.gravit.utils.PublicURLClassLoader; import pro.gravit.utils.Version; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java index 810e96b0..3c268cac 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java @@ -12,12 +12,13 @@ import java.lang.reflect.Type; import java.net.InetSocketAddress; +import java.nio.file.Path; import java.util.*; public final class ClientProfile implements Comparable { private static final FileNameMatcher ASSET_MATCHER = new FileNameMatcher( new String[0], new String[]{"indexes", "objects"}, new String[0]); - + private transient Path profileFilePath; @LauncherNetworkAPI private String title; @LauncherNetworkAPI @@ -461,6 +462,14 @@ public List getFlags() { return flags; } + public Path getProfileFilePath() { + return profileFilePath; + } + + public void setProfileFilePath(Path profileFilePath) { + this.profileFilePath = profileFilePath; + } + public enum ClassLoaderConfig { AGENT, LAUNCHER, MODULE, SYSTEM_ARGS } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java b/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java deleted file mode 100644 index 90b73309..00000000 --- a/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java +++ /dev/null @@ -1,59 +0,0 @@ -package pro.gravit.utils; - -import java.net.URL; -import java.net.URLClassLoader; - -public class PublicURLClassLoader extends URLClassLoader { - - /** - * Constructs a new URLClassLoader for the specified URLs using the - * default delegation parent {@code ClassLoader}. The URLs will - * be searched in the order specified for classes and resources after - * first searching in the parent class loader. Any URL that ends with - * a '/' is assumed to refer to a directory. Otherwise, the URL is - * assumed to refer to a JAR file which will be downloaded and opened - * as needed. - * - *

If there is a security manager, this method first - * calls the security manager's {@code checkCreateClassLoader} method - * to ensure creation of a class loader is allowed. - * - * @param urls the URLs from which to load classes and resources - * @throws SecurityException if a security manager exists and its - * {@code checkCreateClassLoader} method doesn't allow - * creation of a class loader. - * @throws NullPointerException if {@code urls} is {@code null}. - */ - public PublicURLClassLoader(URL[] urls) { - super(urls); - } - - /** - * Constructs a new URLClassLoader for the given URLs. The URLs will be - * searched in the order specified for classes and resources after first - * searching in the specified parent class loader. Any {@code jar:} - * scheme URL is assumed to refer to a JAR file. Any {@code file:} scheme - * URL that ends with a '/' is assumed to refer to a directory. Otherwise, - * the URL is assumed to refer to a JAR file which will be downloaded and - * opened as needed. - * - *

If there is a security manager, this method first - * calls the security manager's {@code checkCreateClassLoader} method - * to ensure creation of a class loader is allowed. - * - * @param urls the URLs from which to load classes and resources - * @param parent the parent class loader for delegation - * @throws SecurityException if a security manager exists and its - * {@code checkCreateClassLoader} method doesn't allow - * creation of a class loader. - * @throws NullPointerException if {@code urls} is {@code null}. - */ - public PublicURLClassLoader(URL[] urls, ClassLoader parent) { - super(urls, parent); - } - - @Override - public void addURL(URL url) { - super.addURL(url); - } -} diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java index 0c8425de..0f008c38 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java @@ -12,6 +12,8 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.Collections; import java.util.Set; +import java.util.jar.JarFile; +import java.util.jar.Manifest; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.Deflater; @@ -82,6 +84,15 @@ public static void close(OutputStream out) { } } + public static Manifest getManifest(Class clazz) { + Path path = getCodeSource(clazz); + try(JarFile jar = new JarFile(path.toFile())) { + return jar.getManifest(); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + public static URL convertToURL(String url) { try { return new URL(url); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java index ba1bbf85..af0d7c6e 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java @@ -1,17 +1,12 @@ package pro.gravit.utils.helper; -import java.io.File; import java.lang.invoke.MethodHandles; import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; import java.lang.management.RuntimeMXBean; -import java.net.MalformedURLException; -import java.net.URL; import java.security.cert.X509Certificate; import java.util.Arrays; -import java.util.Collection; import java.util.Locale; -import java.util.Map; public final class JVMHelper { @@ -77,45 +72,11 @@ public static String getNativePrefix(JVMHelper.OS OS_TYPE) { }; } - public static void appendVars(ProcessBuilder builder, Map vars) { - builder.environment().putAll(vars); - } - - public static Class firstClass(String... names) throws ClassNotFoundException { - for (String name : names) - try { - return Class.forName(name, false, LOADER); - } catch (ClassNotFoundException ignored) { - // Expected - } - throw new ClassNotFoundException(Arrays.toString(names)); - } - public static void fullGC() { RUNTIME.gc(); LogHelper.debug("Used heap: %d MiB", RUNTIME.totalMemory() - RUNTIME.freeMemory() >> 20); } - public static String[] getClassPath() { - return System.getProperty("java.class.path").split(File.pathSeparator); - } - - public static URL[] getClassPathURL() { - String[] cp = System.getProperty("java.class.path").split(File.pathSeparator); - URL[] list = new URL[cp.length]; - - for (int i = 0; i < cp.length; i++) { - URL url = null; - try { - url = new URL(cp[i]); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - list[i] = url; - } - return list; - } - public static X509Certificate[] getCertificates(Class clazz) { Object[] signers = clazz.getSigners(); if (signers == null) return null; @@ -140,10 +101,6 @@ private static int getCorrectOSArch() { return System.getProperty("os.arch").contains("64") ? 64 : 32; } - public static String getEnvPropertyCaseSensitive(String name) { - return System.getenv().get(name); - } - public static boolean isJVMMatchesSystemArch() { return JVM_BITS == OS_BITS; } @@ -152,16 +109,6 @@ public static String jvmProperty(String name, String value) { return String.format("-D%s=%s", name, value); } - public static String systemToJvmProperty(String name) { - return String.format("-D%s=%s", name, System.getProperties().getProperty(name)); - } - - public static void addSystemPropertyToArgs(Collection args, String name) { - String property = System.getProperty(name); - if (property != null) - args.add(String.format("-D%s=%s", name, property)); - } - public static void verifySystemProperties(Class mainClass, boolean requireSystem) { Locale.setDefault(Locale.US); // Verify class loader diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java index 79f655a7..b8b8215f 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java @@ -7,7 +7,6 @@ import pro.gravit.launcher.base.request.auth.GetPublicKeyRequest; import pro.gravit.launcher.base.request.websockets.StdWebSocketService; import pro.gravit.launcher.server.ServerWrapper; -import pro.gravit.utils.PublicURLClassLoader; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; diff --git a/modules b/modules index 875cbb46..c176ddfe 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 875cbb463dc432bc48300e4f3a7e5b3b21c6267e +Subproject commit c176ddfef61247e98e3832921877ec4a79cdcc63