2015-08-26 00:00:34 +02:00
|
|
|
/*
|
|
|
|
* opsu! - an open-source osu! client
|
|
|
|
* Copyright (C) 2014, 2015 Jeffrey Han
|
|
|
|
*
|
|
|
|
* opsu! is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* opsu! is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with opsu!. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package itdelatrisu.opsu;
|
|
|
|
|
2017-05-21 11:12:55 +02:00
|
|
|
import org.newdawn.slick.util.Log;
|
2017-05-25 01:03:15 +02:00
|
|
|
import yugecin.opsudance.utils.ManifestWrapper;
|
2017-05-21 11:12:55 +02:00
|
|
|
|
2015-08-26 00:00:34 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2017-05-21 11:12:55 +02:00
|
|
|
import java.lang.reflect.Field;
|
2017-05-25 01:03:15 +02:00
|
|
|
import java.util.jar.JarFile;
|
2017-05-21 11:12:55 +02:00
|
|
|
|
|
|
|
import static yugecin.opsudance.core.InstanceContainer.*;
|
2015-08-26 00:00:34 +02:00
|
|
|
|
|
|
|
public class NativeLoader {
|
2015-08-30 21:31:01 +02:00
|
|
|
|
2017-05-25 01:03:15 +02:00
|
|
|
public static void setNativePath() {
|
2017-05-21 11:12:55 +02:00
|
|
|
String nativepath = config.NATIVE_DIR.getAbsolutePath();
|
|
|
|
System.setProperty("org.lwjgl.librarypath", nativepath);
|
|
|
|
System.setProperty("java.library.path", nativepath);
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Workaround for "java.library.path" property being read-only.
|
|
|
|
// http://stackoverflow.com/a/24988095
|
|
|
|
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
|
|
|
|
fieldSysPath.setAccessible(true);
|
|
|
|
fieldSysPath.set(null, null);
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.warn("Failed to set 'sys_paths' field.", e);
|
|
|
|
}
|
2015-08-30 21:31:01 +02:00
|
|
|
}
|
2015-08-26 00:00:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unpacks natives for the current operating system to the natives directory.
|
2015-09-10 05:51:16 +02:00
|
|
|
* @throws IOException if an I/O exception occurs
|
2015-08-26 00:00:34 +02:00
|
|
|
*/
|
2017-05-25 01:03:15 +02:00
|
|
|
public static void loadNatives(JarFile jarfile, ManifestWrapper manifest) throws IOException {
|
2017-05-21 11:12:55 +02:00
|
|
|
if (!config.NATIVE_DIR.exists() && !config.NATIVE_DIR.mkdir()) {
|
|
|
|
String msg = String.format("Could not create folder '%s'",
|
|
|
|
config.NATIVE_DIR.getAbsolutePath());
|
|
|
|
throw new RuntimeException(msg);
|
|
|
|
}
|
|
|
|
|
2015-08-26 00:00:34 +02:00
|
|
|
String osName = System.getProperty("os.name");
|
2017-05-25 01:03:15 +02:00
|
|
|
String nativekey = null;
|
2015-08-26 00:00:34 +02:00
|
|
|
if (osName.startsWith("Win")) {
|
2017-05-25 01:03:15 +02:00
|
|
|
nativekey = "WinNatives";
|
2015-08-26 00:00:34 +02:00
|
|
|
} else if (osName.startsWith("Linux")) {
|
2017-05-25 01:03:15 +02:00
|
|
|
nativekey = "NixNatives";
|
2015-08-31 00:56:05 +02:00
|
|
|
} else if (osName.startsWith("Mac") || osName.startsWith("Darwin")) {
|
2017-05-25 01:03:15 +02:00
|
|
|
nativekey = "MacNatives";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nativekey == null) {
|
|
|
|
Log.warn("Cannot determine natives for os " + osName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String natives = manifest.valueOrDefault(null, nativekey, null);
|
|
|
|
if (natives == null) {
|
|
|
|
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()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Utils.unpackFromJar(jarfile, unpackedFile, nativefile);
|
2015-08-26 00:00:34 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-21 11:12:55 +02:00
|
|
|
|
2015-08-26 00:00:34 +02:00
|
|
|
}
|