mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-03-20 16:18:24 +03:00
Attach jars and new adding libs system p.1
This commit is contained in:
parent
349bfc82fb
commit
81ef824b85
4 changed files with 34 additions and 8 deletions
|
@ -260,6 +260,8 @@ public static void main(String... args) throws Throwable {
|
||||||
|
|
||||||
public final Path dir;
|
public final Path dir;
|
||||||
|
|
||||||
|
public final Path launcherLibraries;
|
||||||
|
|
||||||
public final List<String> args;
|
public final List<String> args;
|
||||||
|
|
||||||
public final Path configFile;
|
public final Path configFile;
|
||||||
|
@ -327,7 +329,8 @@ public static void main(String... args) throws Throwable {
|
||||||
|
|
||||||
public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecException {
|
public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecException {
|
||||||
this.dir = dir;
|
this.dir = dir;
|
||||||
Files.createDirectories(dir);
|
launcherLibraries = dir.resolve("launcher-libraries");
|
||||||
|
if (!Files.isDirectory(launcherLibraries)) Files.createDirectory(launcherLibraries);
|
||||||
this.args = Arrays.asList(args);
|
this.args = Arrays.asList(args);
|
||||||
configFile = dir.resolve("LaunchServer.conf");
|
configFile = dir.resolve("LaunchServer.conf");
|
||||||
publicKeyFile = dir.resolve("public.key");
|
publicKeyFile = dir.resolve("public.key");
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
public class StarterAgent {
|
public class StarterAgent {
|
||||||
|
|
||||||
public static final class StarterVisitor extends SimpleFileVisitor<Path> {
|
public static final class StarterVisitor extends SimpleFileVisitor<Path> {
|
||||||
private Instrumentation inst;
|
private final Instrumentation inst;
|
||||||
|
|
||||||
public StarterVisitor(Instrumentation inst) {
|
private StarterVisitor(Instrumentation inst) {
|
||||||
this.inst = inst;
|
this.inst = inst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
import ru.gravit.launcher.Launcher;
|
import ru.gravit.launcher.Launcher;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.binary.tasks.AttachJarsTask;
|
||||||
import ru.gravit.launchserver.binary.tasks.LauncherBuildTask;
|
import ru.gravit.launchserver.binary.tasks.LauncherBuildTask;
|
||||||
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
|
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
|
||||||
import ru.gravit.launchserver.binary.tasks.ProGuardBuildTask;
|
import ru.gravit.launchserver.binary.tasks.ProGuardBuildTask;
|
||||||
|
@ -40,6 +41,7 @@ public void init() {
|
||||||
tasks.add(new UnpackBuildTask(server));
|
tasks.add(new UnpackBuildTask(server));
|
||||||
tasks.add(new MainBuildTask(server));
|
tasks.add(new MainBuildTask(server));
|
||||||
if(server.config.enabledProGuard) tasks.add(new ProGuardBuildTask(server));
|
if(server.config.enabledProGuard) tasks.add(new ProGuardBuildTask(server));
|
||||||
|
tasks.add(new AttachJarsTask(server));
|
||||||
if(server.config.stripLineNumbers) tasks.add(new StripLineNumbersTask(server));
|
if(server.config.stripLineNumbers) tasks.add(new StripLineNumbersTask(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,37 @@
|
||||||
package ru.gravit.launchserver.binary.tasks.api;
|
package ru.gravit.launchserver.binary.tasks;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.instrument.Instrumentation;
|
||||||
|
import java.nio.file.FileVisitResult;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.SimpleFileVisitor;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.binary.tasks.LauncherBuildTask;
|
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
public class AttachJarsTask implements LauncherBuildTask {
|
public class AttachJarsTask implements LauncherBuildTask {
|
||||||
|
private static final class ListFileVisitor extends SimpleFileVisitor<Path> {
|
||||||
|
private final List<Path> lst;
|
||||||
|
|
||||||
|
private ListFileVisitor(List<Path> lst) {
|
||||||
|
this.lst = lst;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||||
|
if (file.toFile().getName().endsWith(".jar"))
|
||||||
|
lst.add(file);
|
||||||
|
return super.visitFile(file, attrs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final LaunchServer srv;
|
private final LaunchServer srv;
|
||||||
private final List<Path> jars;
|
private final List<Path> jars;
|
||||||
private final List<String> exclusions;
|
private final List<String> exclusions;
|
||||||
|
@ -40,13 +58,16 @@ public Path process(Path inputFile) throws IOException {
|
||||||
IOHelper.transfer(input, output);
|
IOHelper.transfer(input, output);
|
||||||
e = input.getNextEntry();
|
e = input.getNextEntry();
|
||||||
}
|
}
|
||||||
attach(output);
|
List<Path> coreAttach = new ArrayList<>();
|
||||||
|
IOHelper.walk(srv.launcherLibraries, new ListFileVisitor(coreAttach), true);
|
||||||
|
attach(output, coreAttach);
|
||||||
|
attach(output, jars);
|
||||||
}
|
}
|
||||||
return outputFile;
|
return outputFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attach(ZipOutputStream output) throws IOException {
|
private void attach(ZipOutputStream output, List<Path> lst) throws IOException {
|
||||||
for (Path p : jars) {
|
for (Path p : lst) {
|
||||||
try (ZipInputStream input = IOHelper.newZipInput(p)) {
|
try (ZipInputStream input = IOHelper.newZipInput(p)) {
|
||||||
ZipEntry e = input.getNextEntry();
|
ZipEntry e = input.getNextEntry();
|
||||||
while (e != null) {
|
while (e != null) {
|
Loading…
Reference in a new issue