added version check

preliminary applet support
This commit is contained in:
Brian Matzon 2006-07-02 21:47:09 +00:00
parent 800ba0a969
commit eba1a5c2cf
1 changed files with 43 additions and 1 deletions

View File

@ -31,8 +31,13 @@
*/
package org.lwjgl.devil;
import java.io.File;
import java.security.AccessController;
import java.security.PrivilegedAction;
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
import org.lwjgl.applet.LWJGLInstaller;
/**
* <p>
@ -44,9 +49,45 @@ import org.lwjgl.LWJGLUtil;
* $Id$
*/
class ILNative {
/** The native JNI library name */
private static String JNI_LIBRARY_NAME = "lwjgl-devil";
/** Version of IL */
public static final String VERSION = "1.0beta2";
/**
* utility loadlibrary to load the native library using elevated priviledges
* @param name Name of library to load, or full path if usingPath is true
* @param usingPath true if using the full path to the native
*/
private static void loadLibrary(final String name, final boolean usingPath) {
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
if(usingPath) {
System.load(name);
} else {
System.loadLibrary(name);
}
return null;
}
});
}
static {
System.loadLibrary("lwjgl-devil");
if (LWJGLInstaller.installed) {
loadLibrary(LWJGLInstaller.installDirectory + File.separator + System.mapLibraryName(JNI_LIBRARY_NAME), true);
} else {
loadLibrary(JNI_LIBRARY_NAME, false);
}
// check for mismatch
String nativeVersion = getNativeLibraryVersion();
if (!nativeVersion.equals(VERSION)) {
throw new LinkageError(
"Version mismatch: jar version is '" + VERSION +
"', native libary version is '" + nativeVersion + "'");
}
}
// IL
@ -55,6 +96,7 @@ class ILNative {
static native void resetNativeStubsIL(Class clazz);
static native void nCreateIL(String[] ilPaths) throws LWJGLException;
static native void nDestroyIL();
private static native String getNativeLibraryVersion();
static void createIL() throws LWJGLException {
String[] illPaths = LWJGLUtil.getLibraryPaths(new String[]{