Extract UI assets from JAR on first launch
This commit is contained in:
@@ -14,6 +14,8 @@ import me.sashegdev.zernmc.launcher.minecraft.InstanceManager;
|
|||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -77,11 +79,46 @@ public class JFXLauncher extends Application {
|
|||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void extractAssets() {
|
||||||
|
try {
|
||||||
|
Path assetsDir = Paths.get("assets");
|
||||||
|
if (Files.exists(assetsDir)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("[JFX] Извлечение assets из JAR...");
|
||||||
|
Path jarPath = Paths.get(JFXLauncher.class.getProtectionDomain().getCodeSource().getLocation().toURI());
|
||||||
|
if (Files.exists(jarPath) && jarPath.toString().endsWith(".jar")) {
|
||||||
|
try (JarFile jar = new JarFile(jarPath.toFile())) {
|
||||||
|
var entries = jar.entries();
|
||||||
|
while (entries.hasMoreElements()) {
|
||||||
|
JarEntry entry = entries.nextElement();
|
||||||
|
if (entry.getName().startsWith("assets/")) {
|
||||||
|
Path outPath = assetsDir.resolve(entry.getName().substring(7));
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
Files.createDirectories(outPath);
|
||||||
|
} else {
|
||||||
|
Files.createDirectories(outPath.getParent());
|
||||||
|
try (InputStream is = jar.getInputStream(entry)) {
|
||||||
|
Files.copy(is, outPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("[JFX] Assets извлечены");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("[JFX] Ошибка извлечения assets: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) {
|
public void start(Stage stage) {
|
||||||
this.mainStage = stage;
|
this.mainStage = stage;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
extractAssets();
|
||||||
log("Запуск JFX UI...");
|
log("Запуск JFX UI...");
|
||||||
startServer();
|
startServer();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user