[FEATURE] Введение общего интерфейса для всех Optional

This commit is contained in:
Gravit 2019-01-22 11:18:48 +07:00
parent 792755f097
commit 1a1c6b6c5a
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
5 changed files with 135 additions and 112 deletions

View file

@ -10,6 +10,8 @@
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.profiles.PlayerProfile; 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.Request;
import ru.gravit.launcher.request.update.LegacyLauncherRequest; import ru.gravit.launcher.request.update.LegacyLauncherRequest;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
@ -32,7 +34,6 @@
import java.net.URL; import java.net.URL;
import java.nio.file.FileVisitResult; import java.nio.file.FileVisitResult;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor; import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermission;
@ -68,11 +69,11 @@ public static final class Params extends StreamObject {
@LauncherAPI @LauncherAPI
public final PlayerProfile pp; public final PlayerProfile pp;
@LauncherAPI @LauncherAPI
public final Set<ClientProfile.OptionalFile> updateOptional; public final Set<OptionalFile> updateOptional;
@LauncherAPI @LauncherAPI
public final Set<ClientProfile.OptionalArgs> optionalClientArgs; public final Set<OptionalArgs> optionalClientArgs;
@LauncherAPI @LauncherAPI
public final Set<ClientProfile.OptionalArgs> optionalClassPath; public final Set<OptionalArgs> optionalClassPath;
@LauncherAPI @LauncherAPI
public final String accessToken; public final String accessToken;
@LauncherAPI @LauncherAPI
@ -96,13 +97,13 @@ public Params(byte[] launcherDigest, Path assetDir, Path clientDir, PlayerProfil
this.updateOptional = new HashSet<>(); this.updateOptional = new HashSet<>();
this.optionalClientArgs = new HashSet<>(); this.optionalClientArgs = new HashSet<>();
this.optionalClassPath = 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); 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); 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); if (s.mark) optionalClassPath.add(s);
} }
// Client paths // Client paths
@ -133,7 +134,7 @@ public Params(HInput input) throws Exception {
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
String file = input.readString(512); String file = input.readString(512);
boolean mark = input.readBoolean(); boolean mark = input.readBoolean();
updateOptional.add(new ClientProfile.OptionalFile(file, mark)); updateOptional.add(new OptionalFile(file, mark));
} }
len = input.readLength(256); len = input.readLength(256);
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
@ -141,7 +142,7 @@ public Params(HInput input) throws Exception {
boolean mark = input.readBoolean(); boolean mark = input.readBoolean();
String[] optArgs = new String[len]; String[] optArgs = new String[len];
for (int j = 0; j < len2; ++j) optArgs[j] = input.readString(512); 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); len = input.readLength(256);
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
@ -149,7 +150,7 @@ public Params(HInput input) throws Exception {
boolean mark = input.readBoolean(); boolean mark = input.readBoolean();
String[] optArgs = new String[len]; String[] optArgs = new String[len];
for (int j = 0; j < len2; ++j) optArgs[j] = input.readString(512); 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 // Client params
pp = new PlayerProfile(input); pp = new PlayerProfile(input);
@ -171,18 +172,18 @@ public void write(HOutput output) throws IOException {
output.writeString(assetDir.toString(), 0); output.writeString(assetDir.toString(), 0);
output.writeString(clientDir.toString(), 0); output.writeString(clientDir.toString(), 0);
output.writeLength(updateOptional.size(), 128); output.writeLength(updateOptional.size(), 128);
for (ClientProfile.OptionalFile s : updateOptional) { for (OptionalFile s : updateOptional) {
output.writeString(s.file, 512); output.writeString(s.file, 512);
output.writeBoolean(s.mark); output.writeBoolean(s.mark);
} }
output.writeLength(optionalClientArgs.size(), 256); output.writeLength(optionalClientArgs.size(), 256);
for (ClientProfile.OptionalArgs s : optionalClientArgs) { for (OptionalArgs s : optionalClientArgs) {
output.writeLength(s.args.length, 16); output.writeLength(s.args.length, 16);
output.writeBoolean(s.mark); output.writeBoolean(s.mark);
for (String f : s.args) output.writeString(f, 512); for (String f : s.args) output.writeString(f, 512);
} }
output.writeLength(optionalClassPath.size(), 256); output.writeLength(optionalClassPath.size(), 256);
for (ClientProfile.OptionalArgs s : optionalClassPath) { for (OptionalArgs s : optionalClassPath) {
output.writeLength(s.args.length, 16); output.writeLength(s.args.length, 16);
output.writeBoolean(s.mark); output.writeBoolean(s.mark);
for (String f : s.args) output.writeString(f, 512); for (String f : s.args) output.writeString(f, 512);
@ -284,7 +285,7 @@ private static void addClientArgs(Collection<String> args, ClientProfile profile
Collections.addAll(args, "--server", profile.getServerAddress()); Collections.addAll(args, "--server", profile.getServerAddress());
Collections.addAll(args, "--port", Integer.toString(profile.getServerPort())); 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); if (optionalArgs.mark) Collections.addAll(args, optionalArgs.args);
} }
// Add window size args // Add window size args
@ -426,7 +427,7 @@ public static Process launch(
String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString();
Collections.addAll(args, profile.getJvmArgs()); Collections.addAll(args, profile.getJvmArgs());
if (profile.getOptionalJVMArgs() != null) { if (profile.getOptionalJVMArgs() != null) {
for (ClientProfile.OptionalArgs addArgs : profile.getOptionalJVMArgs()) { for (OptionalArgs addArgs : profile.getOptionalJVMArgs()) {
if (addArgs.mark) Collections.addAll(args, addArgs.args); if (addArgs.mark) Collections.addAll(args, addArgs.args);
} }
} }
@ -512,7 +513,7 @@ public static void main(String... args) throws Throwable {
for (Path classpathURL : classPath) { for (Path classpathURL : classPath) {
LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString());
} }
for (ClientProfile.OptionalArgs optionalArgs : params.optionalClassPath) { for (OptionalArgs optionalArgs : params.optionalClassPath) {
if (!optionalArgs.mark) continue; if (!optionalArgs.mark) continue;
LinkedList<Path> optionalClassPath = resolveClassPathList(params.clientDir, optionalArgs.args); LinkedList<Path> optionalClassPath = resolveClassPathList(params.clientDir, optionalArgs.args);
for (Path classpathURL : optionalClassPath) { for (Path classpathURL : optionalClassPath) {
@ -535,7 +536,7 @@ public static void main(String... args) throws Throwable {
// Verify current state of all dirs // Verify current state of all dirs
//verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest);
HashedDir hdir = clientHDir.object; 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; if (params.updateOptional.contains(s)) s.mark = true;
else hdir.removeR(s.file); else hdir.removeR(s.file);
} }
@ -574,7 +575,7 @@ public void launchLocal(SignedObjectHolder<HashedDir> assetHDir, SignedObjectHol
// Verify current state of all dirs // Verify current state of all dirs
//verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest);
HashedDir hdir = clientHDir.object; 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; if (params.updateOptional.contains(s)) s.mark = true;
else hdir.removeR(s.file); else hdir.removeR(s.file);
} }

View file

@ -3,6 +3,8 @@
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.FileNameMatcher;
import ru.gravit.launcher.hasher.HashedDir; 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.IOHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
@ -79,66 +81,6 @@ public String toString() {
@LauncherAPI @LauncherAPI
private int serverPort; 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<OptionalFile> 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 // Updater and client watch service
@LauncherAPI @LauncherAPI
private final List<String> update = new ArrayList<>(); private final List<String> update = new ArrayList<>();
@ -165,12 +107,6 @@ public OptionalArgs(String[] args, boolean mark) {
private final List<String> clientArgs = new ArrayList<>(); private final List<String> clientArgs = new ArrayList<>();
@LauncherAPI @LauncherAPI
private final List<String> whitelist = new ArrayList<>(); private final List<String> whitelist = new ArrayList<>();
@LauncherAPI
private final List<OptionalArgs> optionalJVMArgs = new ArrayList<>();
@LauncherAPI
private final List<OptionalArgs> optionalClientArgs = new ArrayList<>();
@LauncherAPI
private final List<OptionalArgs> optionalClassPath = new ArrayList<>();
@Override @Override
public int compareTo(ClientProfile o) { public int compareTo(ClientProfile o) {
@ -192,21 +128,6 @@ public String[] getClassPath() {
return classPath.toArray(new String[0]); return classPath.toArray(new String[0]);
} }
@LauncherAPI
public List<OptionalArgs> getOptionalJVMArgs() {
return optionalJVMArgs;
}
@LauncherAPI
public List<OptionalArgs> getOptionalClientArgs() {
return optionalClientArgs;
}
@LauncherAPI
public List<OptionalArgs> getOptionalClassPath() {
return optionalClassPath;
}
@LauncherAPI @LauncherAPI
public String[] getClientArgs() { public String[] getClientArgs() {
return clientArgs.toArray(new String[0]); return clientArgs.toArray(new String[0]);
@ -269,22 +190,22 @@ public void updateOptionalGraph() {
if (file.dependenciesFile != null) { if (file.dependenciesFile != null) {
file.dependencies = new OptionalFile[file.dependenciesFile.length]; file.dependencies = new OptionalFile[file.dependenciesFile.length];
for (int i = 0; i < file.dependenciesFile.length; ++i) { 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) { if (file.conflictFile != null) {
file.conflict = new OptionalFile[file.conflictFile.length]; file.conflict = new OptionalFile[file.conflictFile.length];
for (int i = 0; i < file.conflictFile.length; ++i) { 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 @LauncherAPI
public OptionalFile getOptionalFile(String file) { public OptionalFile getOptionalFile(String file, OptionalType type) {
for (OptionalFile f : updateOptional) for (OptionalFile f : updateOptional)
if (f.file.equals(file)) return f; if (f.type.equals(type) && f.name.equals(file)) return f;
return null; return null;
} }
@ -294,10 +215,12 @@ public Collection<String> getShared() {
} }
@LauncherAPI @LauncherAPI
public void markOptional(String opt) { public void markOptional(String name, OptionalType type) {
if (!updateOptional.contains(new OptionalFile(opt))) OptionalFile file = getOptionalFile(name,type);
throw new SecurityException(String.format("Optional mod %s not found in optionalList", opt)); if(file == null)
OptionalFile file = getOptionalFile(opt); {
throw new SecurityException(String.format("Optional %s not found in optionalList", name));
}
markOptional(file); markOptional(file);
} }
@ -321,10 +244,12 @@ public void markOptional(OptionalFile file) {
} }
@LauncherAPI @LauncherAPI
public void unmarkOptional(String opt) { public void unmarkOptional(String name, OptionalType type) {
if (!updateOptional.contains(new OptionalFile(opt))) OptionalFile file = getOptionalFile(name,type);
throw new SecurityException(String.format("Optional mod %s not found in optionalList", opt)); if(file == null)
OptionalFile file = getOptionalFile(opt); {
throw new SecurityException(String.format("Optional %s not found in optionalList", name));
}
unmarkOptional(file); unmarkOptional(file);
} }
@ -355,7 +280,11 @@ public void unmarkOptional(OptionalFile file) {
public void pushOptional(HashedDir dir, boolean digest) { public void pushOptional(HashedDir dir, boolean digest) {
for (OptionalFile opt : updateOptional) { 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);
}
} }
} }

View file

@ -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;
}

View file

@ -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<OptionalFile> 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;
}
}

View file

@ -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
}