diff --git a/src/main/java/galaxyoyo/unknown/api/editor/sprites/SpriteRegister.java b/src/main/java/galaxyoyo/unknown/api/editor/sprites/SpriteRegister.java index f8c0e52..206e5f9 100644 --- a/src/main/java/galaxyoyo/unknown/api/editor/sprites/SpriteRegister.java +++ b/src/main/java/galaxyoyo/unknown/api/editor/sprites/SpriteRegister.java @@ -1,5 +1,7 @@ package galaxyoyo.unknown.api.editor.sprites; +import galaxyoyo.unknown.client.main.Main; + import java.awt.image.BufferedImage; import java.io.BufferedInputStream; import java.io.BufferedReader; @@ -8,12 +10,16 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.net.URISyntaxException; +import java.net.URLDecoder; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; import javax.imageio.ImageIO; @@ -26,16 +32,39 @@ public class SpriteRegister private static Map>> nameToCoords; private static Map sprites = new HashMap(); - public static void unpack() + public static void unpack() throws IOException, URISyntaxException { - try + if (Main.isInDevelopmentMode()) { File dir = new File(SpriteRegister.class.getResource("/assets").toURI()); unpackDir(dir); } - catch (URISyntaxException | IOException e) + else { - e.printStackTrace(); + @SuppressWarnings("deprecation") + String path = URLDecoder.decode(SpriteRegister.class.getProtectionDomain().getCodeSource().getLocation().getPath()); + path = path.substring(1, path.length()); + File jarFile = new File(path); + + if(jarFile.isFile()) + { + JarFile jar = new JarFile(jarFile); + Enumeration entries = jar.entries(); + while (entries.hasMoreElements()) + { + JarEntry je = entries.nextElement(); + String name = je.getName(); + if (name.startsWith("assets/")) + { + File f = new File(name); + if (name.endsWith("/")) + f.mkdirs(); + else if (!f.isFile()) + Files.copy(jar.getInputStream(je), Paths.get(f.toURI())); + } + } + jar.close(); + } } } diff --git a/src/main/java/galaxyoyo/unknown/client/main/Main.java b/src/main/java/galaxyoyo/unknown/client/main/Main.java index 73ab639..bbde9ff 100644 --- a/src/main/java/galaxyoyo/unknown/client/main/Main.java +++ b/src/main/java/galaxyoyo/unknown/client/main/Main.java @@ -14,6 +14,7 @@ import java.awt.Graphics2D; import java.awt.GraphicsEnvironment; import java.awt.HeadlessException; import java.awt.image.BufferedImage; +import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; @@ -66,7 +67,15 @@ public class Main Locale.setDefault(Locale.FRANCE); - DEV = Main.class.getClassLoader().getResource("/META-INF/MANIFEST.MF") == null; + try + { + new File(Main.class.getResource("/assets").toURI()); + DEV = true; + } + catch (Throwable t) + { + DEV = false; + } Logger LOGGER = (Logger) LogManager.getRootLogger(); ConsoleAppender console = ConsoleAppender.newBuilder().setLayout(PatternLayout.newBuilder().withPattern("[%d{dd/MM/yyyy}] [%d{HH:mm:ss}] [%t] [%c] [%p] %m%n").build()).setName("Console").build(); @@ -110,7 +119,14 @@ public class Main } } - SpriteRegister.unpack(); + try + { + SpriteRegister.unpack(); + } + catch (IOException | URISyntaxException e) + { + e.printStackTrace(); + } SpriteRegister.refreshAllSprites();