better jar handling; get native files from manifest instead of iterator over every file in the jar
This commit is contained in:
@@ -18,9 +18,7 @@
|
||||
package yugecin.opsudance.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import static yugecin.opsudance.core.Constants.PROJECT_NAME;
|
||||
|
||||
@@ -28,7 +26,7 @@ public class Environment {
|
||||
|
||||
public final boolean isJarRunning;
|
||||
public final File workingdir;
|
||||
public final JarFile jarfile;
|
||||
public final File jarfile;
|
||||
|
||||
public Environment() {
|
||||
Class thiz = Environment.class;
|
||||
@@ -38,7 +36,7 @@ public class Environment {
|
||||
this.workingdir = Paths.get(".").toAbsolutePath().normalize().toFile();
|
||||
this.jarfile = null;
|
||||
} else {
|
||||
String wdir = thisClassLocation.substring(6); // remove the jar://
|
||||
String wdir = thisClassLocation.substring(9); // remove jar:file:
|
||||
String separator = "!/";
|
||||
int separatorIdx = wdir.indexOf(separator);
|
||||
int lastSeparatorIdx = wdir.lastIndexOf(separator);
|
||||
@@ -47,15 +45,8 @@ public class Environment {
|
||||
PROJECT_NAME, thisClassLocation.substring(0, lastSeparatorIdx));
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
File jar = new File(wdir.substring(0, separatorIdx));
|
||||
this.workingdir = jar.getParentFile();
|
||||
try {
|
||||
this.jarfile = new JarFile(jar);
|
||||
} catch (IOException e) {
|
||||
String msg = String.format("Cannot read from jarfile (%s): %s", jar.getAbsolutePath(),
|
||||
e.getMessage());
|
||||
throw new RuntimeException(msg, e);
|
||||
}
|
||||
this.jarfile = new File(wdir.substring(0, separatorIdx));
|
||||
this.workingdir = jarfile.getParentFile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,14 @@ import yugecin.opsudance.options.Configuration;
|
||||
import yugecin.opsudance.options.OptionsService;
|
||||
import yugecin.opsudance.render.GameObjectRenderer;
|
||||
import yugecin.opsudance.skinning.SkinService;
|
||||
import yugecin.opsudance.utils.ManifestWrapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import static yugecin.opsudance.utils.SyntacticSugar.closeAndSwallow;
|
||||
|
||||
public class InstanceContainer {
|
||||
|
||||
@@ -60,9 +66,22 @@ public class InstanceContainer {
|
||||
public static void kickstart() {
|
||||
updater = new Updater();
|
||||
env = new Environment();
|
||||
config = new Configuration();
|
||||
|
||||
NativeLoader.loadNatives();
|
||||
JarFile jarfile = getJarfile();
|
||||
ManifestWrapper manifest = new ManifestWrapper(getJarManifest(jarfile));
|
||||
config = new Configuration(manifest);
|
||||
if (jarfile != null) {
|
||||
try {
|
||||
NativeLoader.loadNatives(jarfile, manifest);
|
||||
} catch (IOException e) {
|
||||
String msg = String.format("Could not unpack native(s): %s", e.getMessage());
|
||||
throw new RuntimeException(msg, e);
|
||||
} finally {
|
||||
closeAndSwallow(jarfile);
|
||||
}
|
||||
}
|
||||
NativeLoader.setNativePath();
|
||||
|
||||
ResourceLoader.addResourceLocation(new FileSystemLocation(new File("./res/")));
|
||||
|
||||
optionservice = new OptionsService();
|
||||
@@ -86,4 +105,31 @@ public class InstanceContainer {
|
||||
pauseState = new GamePauseMenu();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JarFile getJarfile() {
|
||||
if (env.jarfile == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return new JarFile(env.jarfile);
|
||||
} catch (IOException e) {
|
||||
String msg = String.format("Cannot read from jarfile (%s): %s", env.jarfile.getAbsolutePath(),
|
||||
e.getMessage());
|
||||
throw new RuntimeException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Manifest getJarManifest(@Nullable JarFile jarfile) {
|
||||
if (jarfile == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return jarfile.getManifest();
|
||||
} catch (IOException e) {
|
||||
String msg = String.format("Cannot read manifest from jarfile: %s", e.getMessage());
|
||||
throw new RuntimeException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user