From 1a1c6b6c5a6e9f89f3ccd70b7ac2a1bc86a9f2f5 Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 22 Jan 2019 11:18:48 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=92=D0=B2=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BE=D0=B1=D1=89=D0=B5=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=D0=B0=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=B2=D1=81=D0=B5=D1=85=20Optional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/client/ClientLauncher.java | 37 +++--- .../launcher/profiles/ClientProfile.java | 117 ++++-------------- .../profiles/optional/OptionalDepend.java | 10 ++ .../profiles/optional/OptionalFile.java | 67 ++++++++++ .../profiles/optional/OptionalType.java | 16 +++ 5 files changed, 135 insertions(+), 112 deletions(-) create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalDepend.java create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalFile.java create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalType.java diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index fa950ead..78e706a2 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -10,6 +10,8 @@ import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.launcher.profiles.optional.OptionalArgs; +import ru.gravit.launcher.profiles.optional.OptionalFile; import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.update.LegacyLauncherRequest; import ru.gravit.launcher.serialize.HInput; @@ -32,7 +34,6 @@ import java.net.URL; import java.nio.file.FileVisitResult; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.PosixFilePermission; @@ -68,11 +69,11 @@ public static final class Params extends StreamObject { @LauncherAPI public final PlayerProfile pp; @LauncherAPI - public final Set updateOptional; + public final Set updateOptional; @LauncherAPI - public final Set optionalClientArgs; + public final Set optionalClientArgs; @LauncherAPI - public final Set optionalClassPath; + public final Set optionalClassPath; @LauncherAPI public final String accessToken; @LauncherAPI @@ -96,13 +97,13 @@ public Params(byte[] launcherDigest, Path assetDir, Path clientDir, PlayerProfil this.updateOptional = new HashSet<>(); this.optionalClientArgs = new HashSet<>(); this.optionalClassPath = new HashSet<>(); - for (ClientProfile.OptionalFile s : Launcher.profile.getOptional()) { + for (OptionalFile s : Launcher.profile.getOptional()) { if (s.mark) updateOptional.add(s); } - for (ClientProfile.OptionalArgs s : Launcher.profile.getOptionalClientArgs()) { + for (OptionalArgs s : Launcher.profile.getOptionalClientArgs()) { if (s.mark) optionalClientArgs.add(s); } - for (ClientProfile.OptionalArgs s : Launcher.profile.getOptionalClassPath()) { + for (OptionalArgs s : Launcher.profile.getOptionalClassPath()) { if (s.mark) optionalClassPath.add(s); } // Client paths @@ -133,7 +134,7 @@ public Params(HInput input) throws Exception { for (int i = 0; i < len; ++i) { String file = input.readString(512); boolean mark = input.readBoolean(); - updateOptional.add(new ClientProfile.OptionalFile(file, mark)); + updateOptional.add(new OptionalFile(file, mark)); } len = input.readLength(256); for (int i = 0; i < len; ++i) { @@ -141,7 +142,7 @@ public Params(HInput input) throws Exception { boolean mark = input.readBoolean(); String[] optArgs = new String[len]; for (int j = 0; j < len2; ++j) optArgs[j] = input.readString(512); - optionalClientArgs.add(new ClientProfile.OptionalArgs(optArgs, mark)); + optionalClientArgs.add(new OptionalArgs(optArgs, mark)); } len = input.readLength(256); for (int i = 0; i < len; ++i) { @@ -149,7 +150,7 @@ public Params(HInput input) throws Exception { boolean mark = input.readBoolean(); String[] optArgs = new String[len]; for (int j = 0; j < len2; ++j) optArgs[j] = input.readString(512); - optionalClassPath.add(new ClientProfile.OptionalArgs(optArgs, mark)); + optionalClassPath.add(new OptionalArgs(optArgs, mark)); } // Client params pp = new PlayerProfile(input); @@ -171,18 +172,18 @@ public void write(HOutput output) throws IOException { output.writeString(assetDir.toString(), 0); output.writeString(clientDir.toString(), 0); output.writeLength(updateOptional.size(), 128); - for (ClientProfile.OptionalFile s : updateOptional) { + for (OptionalFile s : updateOptional) { output.writeString(s.file, 512); output.writeBoolean(s.mark); } output.writeLength(optionalClientArgs.size(), 256); - for (ClientProfile.OptionalArgs s : optionalClientArgs) { + for (OptionalArgs s : optionalClientArgs) { output.writeLength(s.args.length, 16); output.writeBoolean(s.mark); for (String f : s.args) output.writeString(f, 512); } output.writeLength(optionalClassPath.size(), 256); - for (ClientProfile.OptionalArgs s : optionalClassPath) { + for (OptionalArgs s : optionalClassPath) { output.writeLength(s.args.length, 16); output.writeBoolean(s.mark); for (String f : s.args) output.writeString(f, 512); @@ -284,7 +285,7 @@ private static void addClientArgs(Collection args, ClientProfile profile Collections.addAll(args, "--server", profile.getServerAddress()); Collections.addAll(args, "--port", Integer.toString(profile.getServerPort())); } - for (ClientProfile.OptionalArgs optionalArgs : params.optionalClientArgs) { + for (OptionalArgs optionalArgs : params.optionalClientArgs) { if (optionalArgs.mark) Collections.addAll(args, optionalArgs.args); } // Add window size args @@ -426,7 +427,7 @@ public static Process launch( String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); Collections.addAll(args, profile.getJvmArgs()); if (profile.getOptionalJVMArgs() != null) { - for (ClientProfile.OptionalArgs addArgs : profile.getOptionalJVMArgs()) { + for (OptionalArgs addArgs : profile.getOptionalJVMArgs()) { if (addArgs.mark) Collections.addAll(args, addArgs.args); } } @@ -512,7 +513,7 @@ public static void main(String... args) throws Throwable { for (Path classpathURL : classPath) { LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); } - for (ClientProfile.OptionalArgs optionalArgs : params.optionalClassPath) { + for (OptionalArgs optionalArgs : params.optionalClassPath) { if (!optionalArgs.mark) continue; LinkedList optionalClassPath = resolveClassPathList(params.clientDir, optionalArgs.args); for (Path classpathURL : optionalClassPath) { @@ -535,7 +536,7 @@ public static void main(String... args) throws Throwable { // Verify current state of all dirs //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); HashedDir hdir = clientHDir.object; - for (ClientProfile.OptionalFile s : Launcher.profile.getOptional()) { + for (OptionalFile s : Launcher.profile.getOptional()) { if (params.updateOptional.contains(s)) s.mark = true; else hdir.removeR(s.file); } @@ -574,7 +575,7 @@ public void launchLocal(SignedObjectHolder assetHDir, SignedObjectHol // Verify current state of all dirs //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); HashedDir hdir = clientHDir.object; - for (ClientProfile.OptionalFile s : Launcher.profile.getOptional()) { + for (OptionalFile s : Launcher.profile.getOptional()) { if (params.updateOptional.contains(s)) s.mark = true; else hdir.removeR(s.file); } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java index b5d6476c..5c78c576 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java @@ -3,6 +3,8 @@ import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.HashedDir; +import ru.gravit.launcher.profiles.optional.OptionalFile; +import ru.gravit.launcher.profiles.optional.OptionalType; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.VerifyHelper; @@ -79,66 +81,6 @@ public String toString() { @LauncherAPI private int serverPort; - public static class OptionalFile { - @LauncherAPI - public String file; - @LauncherAPI - public boolean mark; - @LauncherAPI - public String name; - @LauncherAPI - public String info; - @LauncherAPI - public String[] dependenciesFile; - @LauncherAPI - public String[] conflictFile; - @LauncherAPI - public transient OptionalFile[] dependencies; - @LauncherAPI - public transient OptionalFile[] conflict; - @LauncherAPI - public int subTreeLevel = 1; - @LauncherAPI - public boolean isAdminOnly = false; - @LauncherAPI - public transient Set dependenciesCount; - - public OptionalFile(String file, boolean mark) { - this.file = file; - this.mark = mark; - } - - public OptionalFile(String file) { - this.file = file; - this.mark = false; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - OptionalFile that = (OptionalFile) o; - return Objects.equals(file, that.file); - } - - @Override - public int hashCode() { - return Objects.hash(file); - } - } - - public static class OptionalArgs { - @LauncherAPI - public boolean mark; - @LauncherAPI - public String[] args; - - public OptionalArgs(String[] args, boolean mark) { - this.mark = mark; - this.args = args; - } - } - // Updater and client watch service @LauncherAPI private final List update = new ArrayList<>(); @@ -165,12 +107,6 @@ public OptionalArgs(String[] args, boolean mark) { private final List clientArgs = new ArrayList<>(); @LauncherAPI private final List whitelist = new ArrayList<>(); - @LauncherAPI - private final List optionalJVMArgs = new ArrayList<>(); - @LauncherAPI - private final List optionalClientArgs = new ArrayList<>(); - @LauncherAPI - private final List optionalClassPath = new ArrayList<>(); @Override public int compareTo(ClientProfile o) { @@ -192,21 +128,6 @@ public String[] getClassPath() { return classPath.toArray(new String[0]); } - @LauncherAPI - public List getOptionalJVMArgs() { - return optionalJVMArgs; - } - - @LauncherAPI - public List getOptionalClientArgs() { - return optionalClientArgs; - } - - @LauncherAPI - public List getOptionalClassPath() { - return optionalClassPath; - } - @LauncherAPI public String[] getClientArgs() { return clientArgs.toArray(new String[0]); @@ -269,22 +190,22 @@ public void updateOptionalGraph() { if (file.dependenciesFile != null) { file.dependencies = new OptionalFile[file.dependenciesFile.length]; for (int i = 0; i < file.dependenciesFile.length; ++i) { - file.dependencies[i] = getOptionalFile(file.dependenciesFile[i]); + file.dependencies[i] = getOptionalFile(file.dependenciesFile[i].name, file.dependenciesFile[i].type); } } if (file.conflictFile != null) { file.conflict = new OptionalFile[file.conflictFile.length]; for (int i = 0; i < file.conflictFile.length; ++i) { - file.conflict[i] = getOptionalFile(file.conflictFile[i]); + file.conflict[i] = getOptionalFile(file.conflictFile[i].name, file.conflictFile[i].type); } } } } @LauncherAPI - public OptionalFile getOptionalFile(String file) { + public OptionalFile getOptionalFile(String file, OptionalType type) { for (OptionalFile f : updateOptional) - if (f.file.equals(file)) return f; + if (f.type.equals(type) && f.name.equals(file)) return f; return null; } @@ -294,10 +215,12 @@ public Collection getShared() { } @LauncherAPI - public void markOptional(String opt) { - if (!updateOptional.contains(new OptionalFile(opt))) - throw new SecurityException(String.format("Optional mod %s not found in optionalList", opt)); - OptionalFile file = getOptionalFile(opt); + public void markOptional(String name, OptionalType type) { + OptionalFile file = getOptionalFile(name,type); + if(file == null) + { + throw new SecurityException(String.format("Optional %s not found in optionalList", name)); + } markOptional(file); } @@ -321,10 +244,12 @@ public void markOptional(OptionalFile file) { } @LauncherAPI - public void unmarkOptional(String opt) { - if (!updateOptional.contains(new OptionalFile(opt))) - throw new SecurityException(String.format("Optional mod %s not found in optionalList", opt)); - OptionalFile file = getOptionalFile(opt); + public void unmarkOptional(String name, OptionalType type) { + OptionalFile file = getOptionalFile(name,type); + if(file == null) + { + throw new SecurityException(String.format("Optional %s not found in optionalList", name)); + } unmarkOptional(file); } @@ -355,7 +280,11 @@ public void unmarkOptional(OptionalFile file) { public void pushOptional(HashedDir dir, boolean digest) { for (OptionalFile opt : updateOptional) { - if (!opt.mark) dir.removeR(opt.file); + if (opt.type.equals(OptionalType.FILE) && !opt.mark) + { + for(String file : opt.files) + dir.removeR(file); + } } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalDepend.java b/libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalDepend.java new file mode 100644 index 00000000..c49d9ddb --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalDepend.java @@ -0,0 +1,10 @@ +package ru.gravit.launcher.profiles.optional; + +import ru.gravit.launcher.LauncherAPI; + +public class OptionalDepend { + @LauncherAPI + public String name; + @LauncherAPI + public OptionalType type; +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalFile.java b/libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalFile.java new file mode 100644 index 00000000..4f82ece4 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalFile.java @@ -0,0 +1,67 @@ +package ru.gravit.launcher.profiles.optional; + +import ru.gravit.launcher.LauncherAPI; + +import java.util.Objects; +import java.util.Set; + +public class OptionalFile { + @LauncherAPI + public String[] files; + @LauncherAPI + public OptionalType type; + @LauncherAPI + public boolean mark; + @LauncherAPI + public boolean visible; + @LauncherAPI + public String name; + @LauncherAPI + public String info; + @LauncherAPI + public OptionalDepend[] dependenciesFile; + @LauncherAPI + public OptionalDepend[] conflictFile; + @LauncherAPI + public transient OptionalFile[] dependencies; + @LauncherAPI + public transient OptionalFile[] conflict; + @LauncherAPI + public int subTreeLevel = 1; + @LauncherAPI + public long permissions = 0L; + @LauncherAPI + public transient Set dependenciesCount; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + OptionalFile that = (OptionalFile) o; + return Objects.equals(name, that.name); + } + + public int hashCode() { + return Objects.hash(name); + } + + public OptionalType getType() { + return OptionalType.FILE; + } + + public String getName() { + return name; + } + + public boolean isVisible() { + return visible; + } + + public boolean isMark() { + return mark; + } + + public long getPermissions() { + return permissions; + } +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalType.java b/libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalType.java new file mode 100644 index 00000000..2bcacf60 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalType.java @@ -0,0 +1,16 @@ +package ru.gravit.launcher.profiles.optional; + +import ru.gravit.launcher.LauncherAPI; + +@LauncherAPI +public enum OptionalType +{ + @LauncherAPI + FILE, + @LauncherAPI + CLASSPATH, + @LauncherAPI + JVMARGS, + @LauncherAPI + CLIENTARGS +}