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,26 +20,36 @@ 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 {
@SuppressWarnings("deprecation") if (Main.isInDevelopmentMode()) {
String path = URLDecoder.decode(SpriteRegister.class.getProtectionDomain().getCodeSource().getLocation().getPath()); try {
path = path.substring(1); File dir = new File(SpriteRegister.class.getResource("/assets").toURI()).getParentFile();
File jarFile = new File(path); unpackDir(dir);
} catch (URISyntaxException e) {
if (jarFile.isFile()) { e.printStackTrace();
JarFile jar = new JarFile(jarFile); }
Enumeration<JarEntry> entries = jar.entries(); }
while (entries.hasMoreElements()) { else {
JarEntry je = entries.nextElement(); @SuppressWarnings("deprecation")
String name = je.getName(); String path = URLDecoder.decode(SpriteRegister.class.getProtectionDomain().getCodeSource().getLocation().getPath());
if (name.startsWith("assets/")) { File jarFile = new File(path);
File f = new File(name);
if (name.endsWith("/")) if (jarFile.isFile()) {
assert f.mkdirs(); JarFile jar = new JarFile(jarFile);
else if (!f.isFile()) Enumeration<JarEntry> entries = jar.entries();
Files.copy(jar.getInputStream(je), Paths.get(f.toURI())); 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();
} }
} }