From 9091c838e468382fb206ff93dbac1c11ac59c1ea Mon Sep 17 00:00:00 2001 From: Gravita Date: Thu, 18 Nov 2021 16:46:32 +0700 Subject: [PATCH] [FEATURE] ClientProfile libraries --- .../launcher/profiles/ClientProfile.java | 44 ++++++++--- .../profiles/ClientProfileBuilder.java | 78 ++++++++++++++++++- .../pro/gravit/launcher/hasher/HashedDir.java | 5 ++ 3 files changed, 114 insertions(+), 13 deletions(-) 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 816dc942..67a4ded1 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -38,8 +38,6 @@ public final class ClientProfile implements Comparable { @LauncherNetworkAPI private List updateExclusions; @LauncherNetworkAPI - private List updateShared; - @LauncherNetworkAPI private List updateVerify; @LauncherNetworkAPI private Set updateOptional; @@ -52,6 +50,8 @@ public final class ClientProfile implements Comparable { @LauncherNetworkAPI private List clientArgs; @LauncherNetworkAPI + private List libraries; + @LauncherNetworkAPI private List compatClasses; @LauncherNetworkAPI private Map properties; @@ -83,12 +83,42 @@ public final class ClientProfile implements Comparable { @LauncherNetworkAPI private String mainClass; + public static class ClientProfileLibrary { + public final String zone; + public final String name; + public final String path; + + public ClientProfileLibrary(String zone, String name, String path) { + this.zone = zone; + this.name = name; + this.path = path; + } + + public ClientProfileLibrary(String name, String path) { + this.zone = "libraries"; + this.name = name; + this.path = path; + } + + public ClientProfileLibrary(String name) { + this.zone = "libraries"; + this.name = name; + this.path = convertMavenNameToPath(name); + } + + public static String convertMavenNameToPath(String name) { + String[] mavenIdSplit = name.split(":"); + return String.format("%s/%s/%s/%s-%s.jar", mavenIdSplit[0].replaceAll("\\.", "/"), + mavenIdSplit[1], mavenIdSplit[2], mavenIdSplit[1], mavenIdSplit[2]); + } + } + public ClientProfile() { update = new ArrayList<>(); updateExclusions = new ArrayList<>(); - updateShared = new ArrayList<>(); updateVerify = new ArrayList<>(); updateOptional = new HashSet<>(); + libraries = new ArrayList<>(); jvmArgs = new ArrayList<>(); classPath = new ArrayList<>(); altClassPath = new ArrayList<>(); @@ -102,12 +132,12 @@ public ClientProfile() { runtimeInClientConfig = RuntimeInClientConfig.NONE; } - public ClientProfile(List update, List updateExclusions, List updateShared, List updateVerify, Set updateOptional, List jvmArgs, List classPath, List altClassPath, List clientArgs, List compatClasses, Map properties, List servers, SecurityManagerConfig securityManagerConfig, ClassLoaderConfig classLoaderConfig, SignedClientConfig signedClientConfig, RuntimeInClientConfig runtimeInClientConfig, String version, String assetIndex, String dir, String assetDir, int recommendJavaVersion, int minJavaVersion, int maxJavaVersion, boolean warnMissJavaVersion, ProfileDefaultSettings settings, int sortIndex, UUID uuid, String title, String info, boolean updateFastCheck, String mainClass) { + public ClientProfile(List update, List updateExclusions, List updateVerify, Set updateOptional, List libraries, List jvmArgs, List classPath, List altClassPath, List clientArgs, List compatClasses, Map properties, List servers, SecurityManagerConfig securityManagerConfig, ClassLoaderConfig classLoaderConfig, SignedClientConfig signedClientConfig, RuntimeInClientConfig runtimeInClientConfig, String version, String assetIndex, String dir, String assetDir, int recommendJavaVersion, int minJavaVersion, int maxJavaVersion, boolean warnMissJavaVersion, ProfileDefaultSettings settings, int sortIndex, UUID uuid, String title, String info, boolean updateFastCheck, String mainClass) { this.update = update; this.updateExclusions = updateExclusions; - this.updateShared = updateShared; this.updateVerify = updateVerify; this.updateOptional = updateOptional; + this.libraries = libraries; this.jvmArgs = jvmArgs; this.classPath = classPath; this.altClassPath = altClassPath; @@ -264,10 +294,6 @@ public OptionalFile getOptionalFile(String file) { return null; } - public Collection getShared() { - return updateShared; - } - public int getServerPort() { ServerProfile profile = getDefaultServerProfile(); return profile == null ? 25565 : profile.serverPort; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileBuilder.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileBuilder.java index 32a17dd6..e59b7494 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileBuilder.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileBuilder.java @@ -7,9 +7,9 @@ public class ClientProfileBuilder { private List update = new ArrayList<>(); private List updateExclusions = new ArrayList<>(); - private List updateShared = new ArrayList<>(); private List updateVerify = new ArrayList<>(); private Set updateOptional = new HashSet<>(); + private List libraries = new ArrayList<>(); private List jvmArgs = new ArrayList<>(); private List classPath = new ArrayList<>(); private List altClassPath = new ArrayList<>(); @@ -42,13 +42,18 @@ public ClientProfileBuilder setUpdate(List update) { return this; } + public ClientProfileBuilder update(String value) { + this.update.add(value); + return this; + } + public ClientProfileBuilder setUpdateExclusions(List updateExclusions) { this.updateExclusions = updateExclusions; return this; } - public ClientProfileBuilder setUpdateShared(List updateShared) { - this.updateShared = updateShared; + public ClientProfileBuilder updateExclusions(String value) { + this.updateExclusions.add(value); return this; } @@ -57,26 +62,76 @@ public ClientProfileBuilder setUpdateVerify(List updateVerify) { return this; } + public ClientProfileBuilder updateVerify(String value) { + this.updateVerify.add(value); + return this; + } + + public ClientProfileBuilder setLibraries(List libraries) { + this.libraries = libraries; + return this; + } + + public ClientProfileBuilder library(ClientProfile.ClientProfileLibrary library) { + this.libraries.add(library); + return this; + } + + public ClientProfileBuilder library(String zone, String name, String path) { + this.libraries.add(new ClientProfile.ClientProfileLibrary(zone, name, path)); + return this; + } + + public ClientProfileBuilder library(String name, String path) { + this.libraries.add(new ClientProfile.ClientProfileLibrary(name, path)); + return this; + } + + public ClientProfileBuilder library(String name) { + this.libraries.add(new ClientProfile.ClientProfileLibrary(name)); + return this; + } + public ClientProfileBuilder setUpdateOptional(Set updateOptional) { this.updateOptional = updateOptional; return this; } + public ClientProfileBuilder optional(OptionalFile value) { + this.updateOptional.add(value); + return this; + } + public ClientProfileBuilder setJvmArgs(List jvmArgs) { this.jvmArgs = jvmArgs; return this; } + public ClientProfileBuilder jvmArgs(String value) { + this.jvmArgs.add(value); + return this; + } + public ClientProfileBuilder setClassPath(List classPath) { this.classPath = classPath; return this; } + public ClientProfileBuilder classPath(String value) { + this.classPath.add(value); + return this; + } + public ClientProfileBuilder setAltClassPath(List altClassPath) { this.altClassPath = altClassPath; return this; } + public ClientProfileBuilder altClassPath(String value) { + this.altClassPath.add(value); + return this; + } + public ClientProfileBuilder setClientArgs(List clientArgs) { this.clientArgs = clientArgs; return this; @@ -87,16 +142,31 @@ public ClientProfileBuilder setCompatClasses(List compatClasses) { return this; } + public ClientProfileBuilder compatClasses(String value) { + this.compatClasses.add(value); + return this; + } + public ClientProfileBuilder setProperties(Map properties) { this.properties = properties; return this; } + public ClientProfileBuilder property(String key, String value) { + this.properties.put(key, value); + return this; + } + public ClientProfileBuilder setServers(List servers) { this.servers = servers; return this; } + public ClientProfileBuilder server(ClientProfile.ServerProfile serverProfile) { + this.servers.add(serverProfile); + return this; + } + public ClientProfileBuilder setSecurityManagerConfig(ClientProfile.SecurityManagerConfig securityManagerConfig) { this.securityManagerConfig = securityManagerConfig; return this; @@ -193,6 +263,6 @@ public ClientProfileBuilder setMainClass(String mainClass) { } public ClientProfile createClientProfile() { - return new ClientProfile(update, updateExclusions, updateShared, updateVerify, updateOptional, jvmArgs, classPath, altClassPath, clientArgs, compatClasses, properties, servers, securityManagerConfig, classLoaderConfig, signedClientConfig, runtimeInClientConfig, version, assetIndex, dir, assetDir, recommendJavaVersion, minJavaVersion, maxJavaVersion, warnMissJavaVersion, settings, sortIndex, uuid, title, info, updateFastCheck, mainClass); + return new ClientProfile(update, updateExclusions, updateVerify, updateOptional, libraries, jvmArgs, classPath, altClassPath, clientArgs, compatClasses, properties, servers, securityManagerConfig, classLoaderConfig, signedClientConfig, runtimeInClientConfig, version, assetIndex, dir, assetDir, recommendJavaVersion, minJavaVersion, maxJavaVersion, warnMissJavaVersion, settings, sortIndex, uuid, title, info, updateFastCheck, mainClass); } } \ No newline at end of file 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 83d3d6a2..657795f7 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java @@ -59,6 +59,11 @@ public Diff diff(HashedDir other, FileNameMatcher matcher) { return new Diff(mismatch, extra); } + public Diff diffWithoutExtra(HashedDir other, FileNameMatcher matcher) { + HashedDir mismatch = sideDiff(other, matcher, new LinkedList<>(), true); + return new Diff(mismatch, null); + } + public Diff compare(HashedDir other, FileNameMatcher matcher) { HashedDir mismatch = sideDiff(other, matcher, new LinkedList<>(), true); HashedDir extra = other.sideDiff(this, matcher, new LinkedList<>(), false);