remove native filenames from manifest, add it in code instead

what was I thinking
This commit is contained in:
yugecin 2018-10-02 20:33:06 +02:00
parent dd2ac9c1f2
commit ccf17a849e
No known key found for this signature in database
GPG Key ID: 2C5AC035A7068E44
4 changed files with 12 additions and 29 deletions

View File

@ -119,9 +119,6 @@ then run (code is compiled automatically when you run)
<attribute name="Manifest-Version" value="1.0" /> <attribute name="Manifest-Version" value="1.0" />
<attribute name="Built-By" value="${user.name}" /> <attribute name="Built-By" value="${user.name}" />
<attribute name="Main-Class" value="${main}" /> <attribute name="Main-Class" value="${main}" />
<attribute name="WinNatives" value="OpenAL32.dll,OpenAL64.dll,lwjgl.dll,lwjgl64.dll" />
<attribute name="NixNatives" value="liblwjgl.so,liblwjgl64.so,libopenal.so,libopenal64.so" />
<attribute name="MacNatives" value="liblwjgl.dylib,openal.dylib" />
</manifest> </manifest>
<fileset dir="${dir.out}/classes" /> <fileset dir="${dir.out}/classes" />
<zipfileset src="${dir.out}/lib.jar"> <zipfileset src="${dir.out}/lib.jar">

View File

@ -149,9 +149,6 @@
<manifestEntries> <manifestEntries>
<Main-Class>${mainClassName}</Main-Class> <Main-Class>${mainClassName}</Main-Class>
<Use-XDG>${XDG}</Use-XDG> <Use-XDG>${XDG}</Use-XDG>
<WinNatives>OpenAL32.dll,OpenAL64.dll,lwjgl.dll,lwjgl64.dll</WinNatives>
<NixNatives>liblwjgl.so,liblwjgl64.so,libopenal.so,libopenal64.so</NixNatives>
<MacNatives>liblwjgl.dylib,openal.dylib</MacNatives>
</manifestEntries> </manifestEntries>
</transformer> </transformer>
</transformers> </transformers>

View File

@ -19,7 +19,6 @@
package itdelatrisu.opsu; package itdelatrisu.opsu;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.utils.ManifestWrapper;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -50,42 +49,32 @@ public class NativeLoader {
* Unpacks natives for the current operating system to the natives directory. * Unpacks natives for the current operating system to the natives directory.
* @throws IOException if an I/O exception occurs * @throws IOException if an I/O exception occurs
*/ */
public static void loadNatives(JarFile jarfile, ManifestWrapper manifest) throws IOException { public static void loadNatives(JarFile jarfile) throws IOException {
if (!config.NATIVE_DIR.exists() && !config.NATIVE_DIR.mkdir()) { if (!config.NATIVE_DIR.exists() && !config.NATIVE_DIR.mkdir()) {
String msg = String.format("Could not create folder '%s'", String msg = String.format("Could not create folder '%s'",
config.NATIVE_DIR.getAbsolutePath()); config.NATIVE_DIR.getAbsolutePath());
throw new RuntimeException(msg); throw new RuntimeException(msg);
} }
String osName = System.getProperty("os.name"); final String osName = System.getProperty("os.name");
String nativekey = null; final String[] files;
if (osName.startsWith("Win")) { if (osName.startsWith("Win")) {
nativekey = "WinNatives"; files = new String[] { "OpenAL32.dll", "OpenAL64.dll", "lwjgl.dll", "lwjgl64.dll" };
} else if (osName.startsWith("Linux")) { } else if (osName.startsWith("Linux")) {
nativekey = "NixNatives"; files = new String[] { "liblwjgl.so", "liblwjgl64.so", "libopenal.so", "libopenal64.so" };
} else if (osName.startsWith("Mac") || osName.startsWith("Darwin")) { } else if (osName.startsWith("Mac") || osName.startsWith("Darwin")) {
nativekey = "MacNatives"; files = new String[] { "liblwjgl.dylib", "openal.dylib" };
} } else {
if (nativekey == null) {
Log.warn("Cannot determine natives for os " + osName); Log.warn("Cannot determine natives for os " + osName);
return; return;
} }
String natives = manifest.valueOrDefault(null, nativekey, null); for (String file : files) {
if (natives == null) { File unpackedFile = new File(config.NATIVE_DIR, file);
String msg = String.format("No entry for '%s' in manifest, jar is badly packed or damaged",
nativekey);
throw new RuntimeException(msg);
}
String[] nativefiles = natives.split(",");
for (String nativefile : nativefiles) {
File unpackedFile = new File(config.NATIVE_DIR, nativefile);
if (unpackedFile.exists()) { if (unpackedFile.exists()) {
continue; continue;
} }
Utils.unpackFromJar(jarfile, unpackedFile, nativefile); Utils.unpackFromJar(jarfile, unpackedFile, file);
} }
} }

View File

@ -92,7 +92,7 @@ public class InstanceContainer {
config = new Configuration(manifest); config = new Configuration(manifest);
if (jarfile != null) { if (jarfile != null) {
try { try {
NativeLoader.loadNatives(jarfile, manifest); NativeLoader.loadNatives(jarfile);
} catch (IOException e) { } catch (IOException e) {
String msg = String.format("Could not unpack native(s): %s", e.getMessage()); String msg = String.format("Could not unpack native(s): %s", e.getMessage());
throw new RuntimeException(msg, e); throw new RuntimeException(msg, e);