mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[FEATURE] Directory launcher-pack
This commit is contained in:
parent
b2d2059ebd
commit
a7d3cba949
4 changed files with 37 additions and 3 deletions
|
@ -67,6 +67,7 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab
|
|||
* The path to the folder with compile-only libraries for the launcher
|
||||
*/
|
||||
public final Path launcherLibrariesCompile;
|
||||
public final Path launcherPack;
|
||||
/**
|
||||
* The path to the folder with updates/webroot
|
||||
*/
|
||||
|
@ -137,6 +138,10 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
|
|||
this.service = Executors.newScheduledThreadPool(config.netty.performance.schedulerThread);
|
||||
launcherLibraries = directories.launcherLibrariesDir;
|
||||
launcherLibrariesCompile = directories.launcherLibrariesCompileDir;
|
||||
launcherPack = directories.launcherPackDir;
|
||||
if(!Files.isDirectory(launcherPack)) {
|
||||
Files.createDirectories(launcherPack);
|
||||
}
|
||||
|
||||
config.setLaunchServer(this);
|
||||
|
||||
|
@ -486,11 +491,12 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
public static class LaunchServerDirectories {
|
||||
public static final String UPDATES_NAME = "updates", PROFILES_NAME = "profiles",
|
||||
TRUSTSTORE_NAME = "truststore", LAUNCHERLIBRARIES_NAME = "launcher-libraries",
|
||||
LAUNCHERLIBRARIESCOMPILE_NAME = "launcher-libraries-compile", KEY_NAME = ".keys";
|
||||
LAUNCHERLIBRARIESCOMPILE_NAME = "launcher-libraries-compile", LAUNCHERPACK_NAME = "launcher-pack", KEY_NAME = ".keys";
|
||||
public Path updatesDir;
|
||||
public Path profilesDir;
|
||||
public Path launcherLibrariesDir;
|
||||
public Path launcherLibrariesCompileDir;
|
||||
public Path launcherPackDir;
|
||||
public Path keyDirectory;
|
||||
public Path dir;
|
||||
public Path trustStore;
|
||||
|
@ -503,6 +509,8 @@ public void collect() {
|
|||
if (launcherLibrariesDir == null) launcherLibrariesDir = getPath(LAUNCHERLIBRARIES_NAME);
|
||||
if (launcherLibrariesCompileDir == null)
|
||||
launcherLibrariesCompileDir = getPath(LAUNCHERLIBRARIESCOMPILE_NAME);
|
||||
if(launcherPackDir == null)
|
||||
launcherPackDir = getPath(LAUNCHERPACK_NAME);
|
||||
if (keyDirectory == null) keyDirectory = getPath(KEY_NAME);
|
||||
if (tmpDir == null)
|
||||
tmpDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve(String.format("launchserver-%s", SecurityHelper.randomStringToken()));
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public final class JARLauncherBinary extends LauncherBinary {
|
||||
|
@ -19,6 +21,8 @@ public final class JARLauncherBinary extends LauncherBinary {
|
|||
public final List<Path> coreLibs;
|
||||
public final List<Path> addonLibs;
|
||||
|
||||
public final Map<String, Path> files;
|
||||
|
||||
public JARLauncherBinary(LaunchServer server) throws IOException {
|
||||
super(server, resolve(server, ".jar"), "Launcher-%s-%d.jar");
|
||||
count = new AtomicLong(0);
|
||||
|
@ -27,6 +31,7 @@ public JARLauncherBinary(LaunchServer server) throws IOException {
|
|||
buildDir = server.dir.resolve("build");
|
||||
coreLibs = new ArrayList<>();
|
||||
addonLibs = new ArrayList<>();
|
||||
files = new HashMap<>();
|
||||
if (!Files.isDirectory(buildDir)) {
|
||||
Files.deleteIfExists(buildDir);
|
||||
Files.createDirectory(buildDir);
|
||||
|
|
|
@ -4,9 +4,12 @@
|
|||
import pro.gravit.utils.helper.IOHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
@ -48,6 +51,11 @@ public Path process(Path inputFile) throws IOException {
|
|||
}
|
||||
attach(output, inputFile, srv.launcherBinary.coreLibs);
|
||||
attach(output, inputFile, jars);
|
||||
for(var entry : srv.launcherBinary.files.entrySet()) {
|
||||
ZipEntry newEntry = IOHelper.newZipEntry(entry.getKey());
|
||||
output.putNextEntry(newEntry);
|
||||
IOHelper.transfer(entry.getValue(), output);
|
||||
}
|
||||
}
|
||||
return outputFile;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class PrepareBuildTask implements LauncherBuildTask {
|
||||
private final LaunchServer server;
|
||||
|
@ -33,8 +35,19 @@ public String getName() {
|
|||
public Path process(Path inputFile) throws IOException {
|
||||
server.launcherBinary.coreLibs.clear();
|
||||
server.launcherBinary.addonLibs.clear();
|
||||
IOHelper.walk(server.launcherLibraries, new ListFileVisitor(server.launcherBinary.coreLibs), true);
|
||||
IOHelper.walk(server.launcherLibrariesCompile, new ListFileVisitor(server.launcherBinary.addonLibs), true);
|
||||
server.launcherBinary.files.clear();
|
||||
IOHelper.walk(server.launcherLibraries, new ListFileVisitor(server.launcherBinary.coreLibs), false);
|
||||
IOHelper.walk(server.launcherLibrariesCompile, new ListFileVisitor(server.launcherBinary.addonLibs), false);
|
||||
try(Stream<Path> stream = Files.walk(server.launcherPack).filter((e) -> {
|
||||
try {
|
||||
return !Files.isDirectory(e) && !Files.isHidden(e);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
})) {
|
||||
var map = stream.collect(Collectors.toMap(k -> server.launcherPack.relativize(k).toString(), (v) -> v));
|
||||
server.launcherBinary.files.putAll(map);
|
||||
}
|
||||
UnpackHelper.unpack(IOHelper.getResourceURL("Launcher.jar"), result);
|
||||
tryUnpack();
|
||||
return result;
|
||||
|
|
Loading…
Reference in a new issue