* NativeLibraryLoader.registerNativeLibrary("mystuff", Platform.Windows32, "native/windows/mystuff.dll");
* NativeLibraryLoader.registerNativeLibrary("mystuff", Platform.Windows64, "native/windows/mystuff64.dll");
* NativeLibraryLoader.registerNativeLibrary("mystuff", Platform.Linux32, "native/linux/libmystuff.so");
* NativeLibraryLoader.registerNativeLibrary("mystuff", Platform.Linux64, "native/linux/libmystuff64.so");
* NativeLibraryLoader.registerNativeLibrary("mystuff", Platform.MacOSX32, "native/macosx/libmystuff.jnilib");
* NativeLibraryLoader.registerNativeLibrary("mystuff", Platform.MacOSX64, "native/macosx/libmystuff.jnilib");
*
*
* NativeLibraryLoader.loadNativeLibrary("mystuff", true);
*
* It will load the right library automatically based on the platform.
*
* @author Kirill Vainer
*/
public final class NativeLibraryLoader {
private static final Logger logger = Logger.getLogger(NativeLibraryLoader.class.getName());
private static final byte[] buf = new byte[1024 * 100];
private static File extractionFolderOverride = null;
private static File extractionFolder = null;
private static final HashMapnull
to restore default
* functionality.
*
* @param path Path where to extract native libraries.
*/
public static void setCustomExtractionFolder(String path) {
extractionFolderOverride = new File(path).getAbsoluteFile();
}
/**
* Returns the folder where native libraries will be extracted.
* This is automatically determined at run-time based on the
* following criteria:natives_<hash>
where <hash>
* is computed automatically as the XOR of the classpath hash code
* and the last modified date of this class.
*
* @return Path where natives will be extracted to.
*/
public static File getExtractionFolder() {
if (extractionFolderOverride != null) {
return extractionFolderOverride;
}
if (extractionFolder == null) {
File workingFolder = new File("").getAbsoluteFile();
if (!workingFolder.canWrite()) {
setExtractionFolderToUserCache();
} else {
try {
File file = new File(workingFolder + File.separator + ".jmetestwrite");
file.createNewFile();
file.delete();
extractionFolder = workingFolder;
} catch (Exception e) {
setExtractionFolderToUserCache();
}
}
}
return extractionFolder;
}
/**
* Determine jME3's cache folder for the user account based on the OS.
*
* If the OS cache folder is missing, the assumption is that this
* particular version of the OS does not have a dedicated cache folder,
* hence, we use the user's home folder instead as the root.
*
* The folder returned is as follows:
* E.g.
*