diff --git a/src/java/org/lwjgl/devil/ILNative.java b/src/java/org/lwjgl/devil/ILNative.java index 353a0619..b4526500 100644 --- a/src/java/org/lwjgl/devil/ILNative.java +++ b/src/java/org/lwjgl/devil/ILNative.java @@ -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; /** *

@@ -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[]{