mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] Перестройка optionalClientArgs/optionalJVMArgs/optionalClassPath
This commit is contained in:
parent
1a1c6b6c5a
commit
6d39f514ca
6 changed files with 61 additions and 100 deletions
|
@ -343,8 +343,8 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
|||
publicKey = (RSAPublicKey) pair.getPublic();
|
||||
privateKey = (RSAPrivateKey) pair.getPrivate();
|
||||
|
||||
// Write key pair files
|
||||
LogHelper.info("Writing RSA keypair files");
|
||||
// Write key pair list
|
||||
LogHelper.info("Writing RSA keypair list");
|
||||
IOHelper.write(publicKeyFile, publicKey.getEncoded());
|
||||
IOHelper.write(privateKeyFile, privateKey.getEncoded());
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public boolean allowDelete() {
|
|||
}
|
||||
|
||||
public void tryUnpack() throws IOException {
|
||||
LogHelper.info("Unpacking launcher native guard files and runtime");
|
||||
LogHelper.info("Unpacking launcher native guard list and runtime");
|
||||
UnpackHelper.unpackZipNoCheck("guard.zip", server.launcherBinary.guardDir);
|
||||
UnpackHelper.unpackZipNoCheck("runtime.zip", server.launcherBinary.runtimeDir);
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
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;
|
||||
|
@ -69,12 +67,6 @@ public static final class Params extends StreamObject {
|
|||
@LauncherAPI
|
||||
public final PlayerProfile pp;
|
||||
@LauncherAPI
|
||||
public final Set<OptionalFile> updateOptional;
|
||||
@LauncherAPI
|
||||
public final Set<OptionalArgs> optionalClientArgs;
|
||||
@LauncherAPI
|
||||
public final Set<OptionalArgs> optionalClassPath;
|
||||
@LauncherAPI
|
||||
public final String accessToken;
|
||||
@LauncherAPI
|
||||
public final boolean autoEnter;
|
||||
|
@ -94,18 +86,6 @@ public static final class Params extends StreamObject {
|
|||
public Params(byte[] launcherDigest, Path assetDir, Path clientDir, PlayerProfile pp, String accessToken,
|
||||
boolean autoEnter, boolean fullScreen, int ram, int width, int height) {
|
||||
this.launcherDigest = launcherDigest.clone();
|
||||
this.updateOptional = new HashSet<>();
|
||||
this.optionalClientArgs = new HashSet<>();
|
||||
this.optionalClassPath = new HashSet<>();
|
||||
for (OptionalFile s : Launcher.profile.getOptional()) {
|
||||
if (s.mark) updateOptional.add(s);
|
||||
}
|
||||
for (OptionalArgs s : Launcher.profile.getOptionalClientArgs()) {
|
||||
if (s.mark) optionalClientArgs.add(s);
|
||||
}
|
||||
for (OptionalArgs s : Launcher.profile.getOptionalClassPath()) {
|
||||
if (s.mark) optionalClassPath.add(s);
|
||||
}
|
||||
// Client paths
|
||||
this.assetDir = assetDir;
|
||||
this.clientDir = clientDir;
|
||||
|
@ -127,31 +107,6 @@ public Params(HInput input) throws Exception {
|
|||
// Client paths
|
||||
assetDir = IOHelper.toPath(input.readString(0));
|
||||
clientDir = IOHelper.toPath(input.readString(0));
|
||||
updateOptional = new HashSet<>();
|
||||
optionalClientArgs = new HashSet<>();
|
||||
optionalClassPath = new HashSet<>();
|
||||
int len = input.readLength(128);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String file = input.readString(512);
|
||||
boolean mark = input.readBoolean();
|
||||
updateOptional.add(new OptionalFile(file, mark));
|
||||
}
|
||||
len = input.readLength(256);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
int len2 = input.readLength(16);
|
||||
boolean mark = input.readBoolean();
|
||||
String[] optArgs = new String[len];
|
||||
for (int j = 0; j < len2; ++j) optArgs[j] = input.readString(512);
|
||||
optionalClientArgs.add(new OptionalArgs(optArgs, mark));
|
||||
}
|
||||
len = input.readLength(256);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
int len2 = input.readLength(16);
|
||||
boolean mark = input.readBoolean();
|
||||
String[] optArgs = new String[len];
|
||||
for (int j = 0; j < len2; ++j) optArgs[j] = input.readString(512);
|
||||
optionalClassPath.add(new OptionalArgs(optArgs, mark));
|
||||
}
|
||||
// Client params
|
||||
pp = new PlayerProfile(input);
|
||||
byte[] encryptedAccessToken = input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH);
|
||||
|
@ -171,24 +126,6 @@ public void write(HOutput output) throws IOException {
|
|||
// Client paths
|
||||
output.writeString(assetDir.toString(), 0);
|
||||
output.writeString(clientDir.toString(), 0);
|
||||
output.writeLength(updateOptional.size(), 128);
|
||||
for (OptionalFile s : updateOptional) {
|
||||
output.writeString(s.file, 512);
|
||||
output.writeBoolean(s.mark);
|
||||
}
|
||||
output.writeLength(optionalClientArgs.size(), 256);
|
||||
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 (OptionalArgs s : optionalClassPath) {
|
||||
output.writeLength(s.args.length, 16);
|
||||
output.writeBoolean(s.mark);
|
||||
for (String f : s.args) output.writeString(f, 512);
|
||||
}
|
||||
// Client params
|
||||
pp.write(output);
|
||||
try {
|
||||
output.writeByteArray(SecurityHelper.encrypt(Launcher.getConfig().secretKeyClient.getBytes(), accessToken.getBytes()), SecurityHelper.CRYPTO_MAX_LENGTH);
|
||||
|
@ -285,9 +222,7 @@ private static void addClientArgs(Collection<String> args, ClientProfile profile
|
|||
Collections.addAll(args, "--server", profile.getServerAddress());
|
||||
Collections.addAll(args, "--port", Integer.toString(profile.getServerPort()));
|
||||
}
|
||||
for (OptionalArgs optionalArgs : params.optionalClientArgs) {
|
||||
if (optionalArgs.mark) Collections.addAll(args, optionalArgs.args);
|
||||
}
|
||||
profile.pushOptionalClientArgs(args);
|
||||
// Add window size args
|
||||
if (params.fullScreen)
|
||||
Collections.addAll(args, "--fullscreen", Boolean.toString(true));
|
||||
|
@ -426,11 +361,7 @@ public static Process launch(
|
|||
// Add classpath and main class
|
||||
String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString();
|
||||
Collections.addAll(args, profile.getJvmArgs());
|
||||
if (profile.getOptionalJVMArgs() != null) {
|
||||
for (OptionalArgs addArgs : profile.getOptionalJVMArgs()) {
|
||||
if (addArgs.mark) Collections.addAll(args, addArgs.args);
|
||||
}
|
||||
}
|
||||
profile.pushOptionalJvmArgs(args);
|
||||
Collections.addAll(args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path
|
||||
Collections.addAll(args, "-javaagent:".concat(pathLauncher));
|
||||
if (wrapper)
|
||||
|
@ -513,14 +444,12 @@ public static void main(String... args) throws Throwable {
|
|||
for (Path classpathURL : classPath) {
|
||||
LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString());
|
||||
}
|
||||
for (OptionalArgs optionalArgs : params.optionalClassPath) {
|
||||
if (!optionalArgs.mark) continue;
|
||||
LinkedList<Path> optionalClassPath = resolveClassPathList(params.clientDir, optionalArgs.args);
|
||||
profile.pushOptionalClassPath(cp -> {
|
||||
LinkedList<Path> optionalClassPath = resolveClassPathList(params.clientDir, cp);
|
||||
for (Path classpathURL : optionalClassPath) {
|
||||
LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString());
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath());
|
||||
classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader());
|
||||
Thread.currentThread().setContextClassLoader(classLoader);
|
||||
|
@ -536,10 +465,11 @@ 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 (OptionalFile s : Launcher.profile.getOptional()) {
|
||||
if (params.updateOptional.contains(s)) s.mark = true;
|
||||
else hdir.removeR(s.file);
|
||||
}
|
||||
//for (OptionalFile s : Launcher.profile.getOptional()) {
|
||||
// if (params.updateOptional.contains(s)) s.mark = true;
|
||||
// else hdir.removeR(s.file);
|
||||
//}
|
||||
Launcher.profile.pushOptionalFile(hdir,false);
|
||||
verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest);
|
||||
verifyHDir(params.clientDir, hdir, clientMatcher, digest);
|
||||
Launcher.modulesManager.postInitModules();
|
||||
|
@ -575,10 +505,11 @@ public void launchLocal(SignedObjectHolder<HashedDir> assetHDir, SignedObjectHol
|
|||
// Verify current state of all dirs
|
||||
//verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest);
|
||||
HashedDir hdir = clientHDir.object;
|
||||
for (OptionalFile s : Launcher.profile.getOptional()) {
|
||||
if (params.updateOptional.contains(s)) s.mark = true;
|
||||
else hdir.removeR(s.file);
|
||||
}
|
||||
//for (OptionalFile s : Launcher.profile.getOptional()) {
|
||||
// if (params.updateOptional.contains(s)) s.mark = true;
|
||||
// else hdir.removeR(s.file);
|
||||
//}
|
||||
Launcher.profile.pushOptionalFile(hdir,false);
|
||||
verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest);
|
||||
verifyHDir(params.clientDir, hdir, clientMatcher, digest);
|
||||
Launcher.modulesManager.postInitModules();
|
||||
|
|
|
@ -224,7 +224,7 @@ private void deleteExtraDir(Path subDir, HashedDir subHDir, boolean flag) throws
|
|||
String name = mapEntry.getKey();
|
||||
Path path = subDir.resolve(name);
|
||||
|
||||
// Delete files and dirs based on type
|
||||
// Delete list and dirs based on type
|
||||
HashedEntry entry = mapEntry.getValue();
|
||||
HashedEntry.Type entryType = entry.getType();
|
||||
switch (entryType) {
|
||||
|
@ -308,7 +308,7 @@ protected SignedObjectHolder<HashedDir> requestDo(HInput input, HOutput output)
|
|||
// Get diff between local and remote dir
|
||||
SignedObjectHolder<HashedDir> remoteHDirHolder = new SignedObjectHolder<>(input, config.publicKey, HashedDir::new);
|
||||
HashedDir hackHackedDir = remoteHDirHolder.object;
|
||||
Launcher.profile.pushOptional(hackHackedDir, !Launcher.profile.isUpdateFastCheck());
|
||||
Launcher.profile.pushOptionalFile(hackHackedDir, !Launcher.profile.isUpdateFastCheck());
|
||||
HashedDir.Diff diff = hackHackedDir.diff(localDir, matcher);
|
||||
totalSize = diff.mismatch.size();
|
||||
boolean compress = input.readBoolean();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package ru.gravit.launcher.profiles;
|
||||
|
||||
import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;
|
||||
import ru.gravit.launcher.LauncherAPI;
|
||||
import ru.gravit.launcher.hasher.FileNameMatcher;
|
||||
import ru.gravit.launcher.hasher.HashedDir;
|
||||
|
@ -8,7 +9,9 @@
|
|||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
public final class ClientProfile implements Comparable<ClientProfile> {
|
||||
|
@ -217,8 +220,7 @@ public Collection<String> getShared() {
|
|||
@LauncherAPI
|
||||
public void markOptional(String name, OptionalType type) {
|
||||
OptionalFile file = getOptionalFile(name, type);
|
||||
if(file == null)
|
||||
{
|
||||
if (file == null) {
|
||||
throw new SecurityException(String.format("Optional %s not found in optionalList", name));
|
||||
}
|
||||
markOptional(file);
|
||||
|
@ -246,8 +248,7 @@ public void markOptional(OptionalFile file) {
|
|||
@LauncherAPI
|
||||
public void unmarkOptional(String name, OptionalType type) {
|
||||
OptionalFile file = getOptionalFile(name, type);
|
||||
if(file == null)
|
||||
{
|
||||
if (file == null) {
|
||||
throw new SecurityException(String.format("Optional %s not found in optionalList", name));
|
||||
}
|
||||
unmarkOptional(file);
|
||||
|
@ -278,16 +279,45 @@ public void unmarkOptional(OptionalFile file) {
|
|||
}
|
||||
}
|
||||
|
||||
public void pushOptional(HashedDir dir, boolean digest) {
|
||||
public void pushOptionalFile(HashedDir dir, boolean digest) {
|
||||
for (OptionalFile opt : updateOptional) {
|
||||
if (opt.type.equals(OptionalType.FILE) && !opt.mark)
|
||||
{
|
||||
for(String file : opt.files)
|
||||
if (opt.type.equals(OptionalType.FILE) && !opt.mark) {
|
||||
for (String file : opt.list)
|
||||
dir.removeR(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void pushOptionalJvmArgs(Collection<String> jvmArgs1)
|
||||
{
|
||||
for (OptionalFile opt : updateOptional) {
|
||||
if (opt.type.equals(OptionalType.JVMARGS) && opt.mark) {
|
||||
jvmArgs1.addAll(Arrays.asList(opt.list));
|
||||
}
|
||||
}
|
||||
}
|
||||
public void pushOptionalClientArgs(Collection<String> clientArgs1)
|
||||
{
|
||||
for (OptionalFile opt : updateOptional) {
|
||||
if (opt.type.equals(OptionalType.CLIENTARGS) && opt.mark) {
|
||||
clientArgs1.addAll(Arrays.asList(opt.list));
|
||||
}
|
||||
}
|
||||
}
|
||||
public void pushOptionalClassPath(pushOptionalClassPathCallback callback) throws IOException
|
||||
{
|
||||
for (OptionalFile opt : updateOptional) {
|
||||
if (opt.type.equals(OptionalType.CLASSPATH) && opt.mark) {
|
||||
callback.run(opt.list);
|
||||
}
|
||||
}
|
||||
}
|
||||
@FunctionalInterface
|
||||
public interface pushOptionalClassPathCallback
|
||||
{
|
||||
void run(String[] opt) throws IOException;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public int getServerPort() {
|
||||
return serverPort;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
public class OptionalFile {
|
||||
@LauncherAPI
|
||||
public String[] files;
|
||||
public String[] list;
|
||||
@LauncherAPI
|
||||
public OptionalType type;
|
||||
@LauncherAPI
|
||||
|
|
Loading…
Reference in a new issue