mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
Фиксы FileNotFoundException и распаковки guard/runtime
This commit is contained in:
parent
ef840af7a0
commit
c3a040ec25
4 changed files with 22 additions and 17 deletions
|
@ -5,7 +5,6 @@
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.HashMap;
|
||||
|
@ -20,7 +19,6 @@
|
|||
import javassist.NotFoundException;
|
||||
import ru.gravit.launcher.AutogenConfig;
|
||||
import ru.gravit.launcher.Launcher;
|
||||
import ru.gravit.launcher.LauncherAPI;
|
||||
import ru.gravit.launcher.LauncherConfig;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
@ -69,27 +67,27 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
|
||||
private final class GuardDirVisitor extends SimpleFileVisitor<Path> {
|
||||
private final ZipOutputStream output;
|
||||
private final Map<String, byte[]> runtime;
|
||||
private final Map<String, byte[]> guard;
|
||||
|
||||
private GuardDirVisitor(ZipOutputStream output, Map<String, byte[]> runtime) {
|
||||
private GuardDirVisitor(ZipOutputStream output, Map<String, byte[]> guard) {
|
||||
this.output = output;
|
||||
this.runtime = runtime;
|
||||
this.guard = guard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
||||
String dirName = IOHelper.toString(guardDir.relativize(dir));
|
||||
output.putNextEntry(newEntry(dirName + '/'));
|
||||
output.putNextEntry(newGuardEntry(dirName + '/'));
|
||||
return super.preVisitDirectory(dir, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
String fileName = IOHelper.toString(guardDir.relativize(file));
|
||||
runtime.put(fileName, SecurityHelper.digest(DigestAlgorithm.MD5, file));
|
||||
guard.put(fileName, SecurityHelper.digest(DigestAlgorithm.MD5, file));
|
||||
|
||||
// Create zip entry and transfer contents
|
||||
output.putNextEntry(newEntry(fileName));
|
||||
output.putNextEntry(newGuardEntry(fileName));
|
||||
IOHelper.transfer(file, output);
|
||||
|
||||
// Return result
|
||||
|
@ -100,6 +98,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
private static ZipEntry newEntry(String fileName) {
|
||||
return newZipEntry(Launcher.RUNTIME_DIR + IOHelper.CROSS_SEPARATOR + fileName);
|
||||
}
|
||||
private static ZipEntry newGuardEntry(String fileName) {
|
||||
return newZipEntry(Launcher.GUARD_DIR + IOHelper.CROSS_SEPARATOR + fileName);
|
||||
}
|
||||
|
||||
|
||||
public final Path runtimeDir;
|
||||
|
@ -246,13 +247,13 @@ private void stdBuild() throws IOException {
|
|||
output.putNextEntry(newZipEntry(ent.getKey().replace('.', '/').concat(".class")));
|
||||
output.write(server.buildHookManager.classTransform(ent.getValue(), ent.getKey()));
|
||||
}
|
||||
// map for runtime
|
||||
// map for guard
|
||||
Map<String, byte[]> runtime = new HashMap<>(256);
|
||||
if (server.buildHookManager.buildRuntime()) {
|
||||
// Verify has init script file
|
||||
if (!IOHelper.isFile(initScriptFile))
|
||||
throw new IOException(String.format("Missing init script file ('%s')", Launcher.INIT_SCRIPT_FILE));
|
||||
// Write launcher runtime dir
|
||||
// Write launcher guard dir
|
||||
IOHelper.walk(runtimeDir, new RuntimeDirVisitor(output, runtime), false);
|
||||
IOHelper.walk(guardDir, new GuardDirVisitor(output, runtime), false);
|
||||
}
|
||||
|
@ -281,11 +282,11 @@ private void stdBuild() throws IOException {
|
|||
|
||||
|
||||
public void tryUnpackRuntime() throws IOException {
|
||||
// Verify is runtime dir unpacked
|
||||
// Verify is guard dir unpacked
|
||||
if (IOHelper.isDir(runtimeDir))
|
||||
return; // Already unpacked
|
||||
|
||||
// Unpack launcher runtime files
|
||||
// Unpack launcher guard files
|
||||
Files.createDirectory(runtimeDir);
|
||||
LogHelper.info("Unpacking launcher runtime files");
|
||||
try (ZipInputStream input = IOHelper.newZipInput(IOHelper.getResourceURL("runtime.zip"))) {
|
||||
|
@ -293,18 +294,18 @@ public void tryUnpackRuntime() throws IOException {
|
|||
if (entry.isDirectory())
|
||||
continue; // Skip dirs
|
||||
|
||||
// Unpack runtime file
|
||||
// Unpack guard file
|
||||
IOHelper.transfer(input, runtimeDir.resolve(IOHelper.toPath(entry.getName())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void tryUnpackGuard() throws IOException {
|
||||
// Verify is runtime dir unpacked
|
||||
// Verify is guard dir unpacked
|
||||
if (IOHelper.isDir(guardDir))
|
||||
return; // Already unpacked
|
||||
|
||||
// Unpack launcher runtime files
|
||||
// Unpack launcher guard files
|
||||
Files.createDirectory(guardDir);
|
||||
LogHelper.info("Unpacking launcher native guard files");
|
||||
try (ZipInputStream input = IOHelper.newZipInput(IOHelper.getResourceURL("guard.zip"))) {
|
||||
|
@ -312,7 +313,7 @@ public void tryUnpackGuard() throws IOException {
|
|||
if (entry.isDirectory())
|
||||
continue; // Skip dirs
|
||||
|
||||
// Unpack runtime file
|
||||
// Unpack guard file
|
||||
IOHelper.transfer(input, guardDir.resolve(IOHelper.toPath(entry.getName())));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep
|
|||
String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString();
|
||||
args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled())));
|
||||
Collections.addAll(args, "-javaagent:".concat(pathLauncher));
|
||||
Collections.addAll(args, "-cp");
|
||||
Collections.addAll(args, pathLauncher);
|
||||
Collections.addAll(args, LauncherEngine.class.getName());
|
||||
EnvHelper.addEnv(processBuilder);
|
||||
LogHelper.debug("Commandline: " + args);
|
||||
|
|
|
@ -151,7 +151,7 @@ public static void main(String... args) throws Throwable {
|
|||
JVMHelper.checkStackTrace(LauncherEngine.class);
|
||||
JVMHelper.verifySystemProperties(Launcher.class, true);
|
||||
EnvHelper.checkDangerousParams();
|
||||
if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set");
|
||||
//if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set");
|
||||
LogHelper.printVersion("Launcher");
|
||||
// Start Launcher
|
||||
Instant start = Instant.now();
|
||||
|
|
|
@ -52,6 +52,8 @@ static int readBuildNumber() {
|
|||
@LauncherAPI
|
||||
public static final String RUNTIME_DIR = "runtime";
|
||||
@LauncherAPI
|
||||
public static final String GUARD_DIR = "guard";
|
||||
@LauncherAPI
|
||||
public static final String CONFIG_FILE = "config.bin";
|
||||
@LauncherAPI
|
||||
public static ClientProfile profile;
|
||||
|
|
Loading…
Reference in a new issue