From 6fa111c872c7972ca8a2f1c95714a219ad246e96 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 26 Feb 2020 01:20:39 +0100 Subject: [PATCH] Fix sprite unpack, launching V1 --- .../api/editor/sprites/SpriteRegister.java | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/main/java/fr/ynerant/leveleditor/api/editor/sprites/SpriteRegister.java b/src/main/java/fr/ynerant/leveleditor/api/editor/sprites/SpriteRegister.java index 6539db0..d4c9215 100644 --- a/src/main/java/fr/ynerant/leveleditor/api/editor/sprites/SpriteRegister.java +++ b/src/main/java/fr/ynerant/leveleditor/api/editor/sprites/SpriteRegister.java @@ -20,26 +20,36 @@ public class SpriteRegister { private static final Map sprites = new HashMap<>(); public static void unpack() throws IOException { - @SuppressWarnings("deprecation") - String path = URLDecoder.decode(SpriteRegister.class.getProtectionDomain().getCodeSource().getLocation().getPath()); - path = path.substring(1); - 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("/")) - assert f.mkdirs(); - else if (!f.isFile()) - Files.copy(jar.getInputStream(je), Paths.get(f.toURI())); - } + if (Main.isInDevelopmentMode()) { + try { + File dir = new File(SpriteRegister.class.getResource("/assets").toURI()).getParentFile(); + unpackDir(dir); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + } + else { + @SuppressWarnings("deprecation") + String path = URLDecoder.decode(SpriteRegister.class.getProtectionDomain().getCodeSource().getLocation().getPath()); + 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.isDirectory()) + if (!f.mkdirs()) + throw new IOException("Unable to create make dir: " + f); + else if (!f.isFile()) + Files.copy(jar.getInputStream(je), Paths.get(f.toURI())); + } + } + jar.close(); } - jar.close(); } }