Возможность сборки Avanguard для каждого проекта отдельно

This commit is contained in:
Gravit 2018-10-13 11:59:50 +07:00
parent 4a2b535403
commit b4cd10ef85
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
8 changed files with 33 additions and 0 deletions

View file

@ -5,6 +5,7 @@
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.nio.file.*; import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.HashMap; import java.util.HashMap;
@ -33,6 +34,9 @@
import proguard.ProGuard; import proguard.ProGuard;
public final class JARLauncherBinary extends LauncherBinary { public final class JARLauncherBinary extends LauncherBinary {
public static final String[] guardFileList = {"Avanguard64.dll", "Avanguard32.dll", "wrapper64.exe", "wrapper32.exe"};
private final class RuntimeDirVisitor extends SimpleFileVisitor<Path> { private final class RuntimeDirVisitor extends SimpleFileVisitor<Path> {
private final ZipOutputStream output; private final ZipOutputStream output;
private final Map<String, byte[]> runtime; private final Map<String, byte[]> runtime;
@ -69,6 +73,7 @@ private static ZipEntry newEntry(String fileName) {
@LauncherAPI @LauncherAPI
public final Path runtimeDir; public final Path runtimeDir;
public final Path guardDir;
@LauncherAPI @LauncherAPI
public final Path initScriptFile; public final Path initScriptFile;
@ -81,6 +86,7 @@ public JARLauncherBinary(LaunchServer server) throws IOException {
super(server, server.dir.resolve(server.config.binaryName + ".jar"), super(server, server.dir.resolve(server.config.binaryName + ".jar"),
server.dir.resolve(server.config.binaryName + (server.config.sign.enabled ? "-sign.jar" : "-obf.jar"))); server.dir.resolve(server.config.binaryName + (server.config.sign.enabled ? "-sign.jar" : "-obf.jar")));
runtimeDir = server.dir.resolve(Launcher.RUNTIME_DIR); runtimeDir = server.dir.resolve(Launcher.RUNTIME_DIR);
guardDir = server.dir.resolve("guard");
initScriptFile = runtimeDir.resolve(Launcher.INIT_SCRIPT_FILE); initScriptFile = runtimeDir.resolve(Launcher.INIT_SCRIPT_FILE);
obfJar = server.config.sign.enabled ? server.dir.resolve(server.config.binaryName + "-obf.jar") obfJar = server.config.sign.enabled ? server.dir.resolve(server.config.binaryName + "-obf.jar")
: syncBinaryFile; : syncBinaryFile;
@ -90,6 +96,7 @@ public JARLauncherBinary(LaunchServer server) throws IOException {
@Override @Override
public void build() throws IOException { public void build() throws IOException {
tryUnpackRuntime(); tryUnpackRuntime();
tryUnpackGuard();
// Build launcher binary // Build launcher binary
LogHelper.info("Building launcher binary file"); LogHelper.info("Building launcher binary file");
@ -232,6 +239,13 @@ private void stdBuild() throws IOException {
output.putNextEntry(e); output.putNextEntry(e);
jaConfigurator.compile(); jaConfigurator.compile();
output.write(jaConfigurator.getBytecode()); output.write(jaConfigurator.getBytecode());
for(String file : guardFileList)
{
Path path = guardDir.resolve(file);
ZipEntry en = newZipEntry(file);
output.putNextEntry(en);
IOHelper.transfer(path,output);
}
server.buildHookManager.postHook(context); server.buildHookManager.postHook(context);
} catch (CannotCompileException | NotFoundException e) { } catch (CannotCompileException | NotFoundException e) {
LogHelper.error(e); LogHelper.error(e);
@ -257,4 +271,23 @@ public void tryUnpackRuntime() throws IOException {
} }
} }
} }
@LauncherAPI
public void tryUnpackGuard() throws IOException {
// Verify is runtime dir unpacked
if (IOHelper.isDir(guardDir))
return; // Already unpacked
// Unpack launcher runtime files
Files.createDirectory(guardDir);
LogHelper.info("Unpacking launcher native guard files");
try (ZipInputStream input = IOHelper.newZipInput(IOHelper.getResourceURL("guard.zip"))) {
for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) {
if (entry.isDirectory())
continue; // Skip dirs
// Unpack runtime file
IOHelper.transfer(input, guardDir.resolve(IOHelper.toPath(entry.getName())));
}
}
}
} }

Binary file not shown.