Fix sprite unpack, launching V1

This commit is contained in:
Yohann D'ANELLO 2020-02-26 01:20:39 +01:00
parent 07d8c480de
commit 6fa111c872
1 changed files with 29 additions and 19 deletions

View File

@ -20,9 +20,17 @@ public class SpriteRegister {
private static final Map<String, Category> sprites = new HashMap<>(); private static final Map<String, Category> sprites = new HashMap<>();
public static void unpack() throws IOException { public static void unpack() throws IOException {
if (Main.isInDevelopmentMode()) {
try {
File dir = new File(SpriteRegister.class.getResource("/assets").toURI()).getParentFile();
unpackDir(dir);
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
else {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
String path = URLDecoder.decode(SpriteRegister.class.getProtectionDomain().getCodeSource().getLocation().getPath()); String path = URLDecoder.decode(SpriteRegister.class.getProtectionDomain().getCodeSource().getLocation().getPath());
path = path.substring(1);
File jarFile = new File(path); File jarFile = new File(path);
if (jarFile.isFile()) { if (jarFile.isFile()) {
@ -33,8 +41,9 @@ public class SpriteRegister {
String name = je.getName(); String name = je.getName();
if (name.startsWith("assets/")) { if (name.startsWith("assets/")) {
File f = new File(name); File f = new File(name);
if (name.endsWith("/")) if (name.endsWith("/") && !f.isDirectory())
assert f.mkdirs(); if (!f.mkdirs())
throw new IOException("Unable to create make dir: " + f);
else if (!f.isFile()) else if (!f.isFile())
Files.copy(jar.getInputStream(je), Paths.get(f.toURI())); Files.copy(jar.getInputStream(je), Paths.get(f.toURI()));
} }
@ -42,6 +51,7 @@ public class SpriteRegister {
jar.close(); jar.close();
} }
} }
}
private static void unpackDir(File dir) throws IOException { private static void unpackDir(File dir) throws IOException {
for (File f : Objects.requireNonNull(dir.listFiles())) { for (File f : Objects.requireNonNull(dir.listFiles())) {