/** Extracts the source file and calls System.load. Attemps to extract and load from multiple locations. Throws runtime * exception if all fail. */ private void loadFile (String sourcePath) { String sourceCrc = crc(readFile(sourcePath)); String fileName = new File(sourcePath).getName(); // Temp directory with username in path. File file = new File(System.getProperty("java.io.tmpdir") + "/libgdx" + System.getProperty("user.name") + "/" + sourceCrc, fileName); Throwable ex = loadFile(sourcePath, sourceCrc, file); if (ex == null) return; // System provided temp directory. try { file = File.createTempFile(sourceCrc, null); if (file.delete() && loadFile(sourcePath, sourceCrc, file) == null) return; } catch (Throwable ignored) { } // User home. file = new File(System.getProperty("user.home") + "/.libgdx/" + sourceCrc, fileName); if (loadFile(sourcePath, sourceCrc, file) == null) return; // Relative directory. file = new File(".temp/" + sourceCrc, fileName); if (loadFile(sourcePath, sourceCrc, file) == null) return; // Fallback to java.library.path location, eg for applets. file = new File(System.getProperty("java.library.path"), sourcePath); if (file.exists()) { System.load(file.getAbsolutePath()); return; } throw new GdxRuntimeException(ex); }
/** Extracts the source file and calls System.load. Attemps to extract and load from multiple locations. Throws runtime * exception if all fail. */ private void loadFile (String sourcePath) { String sourceCrc = crc(readFile(sourcePath)); String fileName = new File(sourcePath).getName(); // Temp directory with username in path. File file = new File(System.getProperty("java.io.tmpdir") + "/libgdx" + System.getProperty("user.name") + "/" + sourceCrc, fileName); Throwable ex = loadFile(sourcePath, sourceCrc, file); if (ex == null) return; // System provided temp directory. try { file = File.createTempFile(sourceCrc, null); if (file.delete() && loadFile(sourcePath, sourceCrc, file) == null) return; } catch (Throwable ignored) { } // User home. file = new File(System.getProperty("user.home") + "/.libgdx/" + sourceCrc, fileName); if (loadFile(sourcePath, sourceCrc, file) == null) return; // Relative directory. file = new File(".temp/" + sourceCrc, fileName); if (loadFile(sourcePath, sourceCrc, file) == null) return; // Fallback to java.library.path location, eg for applets. file = new File(System.getProperty("java.library.path"), sourcePath); if (file.exists()) { System.load(file.getAbsolutePath()); return; } throw new GdxRuntimeException(ex); }
/** Loads a shared library for the platform the application is running on. * @param libraryName The platform independent library name. If not contain a prefix (eg lib) or suffix (eg .dll). */ public void load (String libraryName) { // in case of iOS, things have been linked statically to the executable, bail out. if (isIos) return; synchronized (SharedLibraryLoader.class) { if (isLoaded(libraryName)) return; String platformName = mapLibraryName(libraryName); try { if (isAndroid) System.loadLibrary(platformName); else loadFile(platformName); setLoaded(libraryName); } catch (Throwable ex) { throw new GdxRuntimeException("Couldn't load shared library '" + platformName + "' for target: " + System.getProperty("os.name") + (is64Bit ? ", 64-bit" : ", 32-bit"), ex); } } }
/** Loads a shared library for the platform the application is running on. * @param libraryName The platform independent library name. If not contain a prefix (eg lib) or suffix (eg .dll). */ public void load (String libraryName) { // in case of iOS, things have been linked statically to the executable, bail out. if (isIos) return; synchronized (SharedLibraryLoader.class) { if (isLoaded(libraryName)) return; String platformName = mapLibraryName(libraryName); try { if (isAndroid) System.loadLibrary(platformName); else loadFile(platformName); setLoaded(libraryName); } catch (Throwable ex) { throw new GdxRuntimeException("Couldn't load shared library '" + platformName + "' for target: " + System.getProperty("os.name") + (is64Bit ? ", 64-bit" : ", 32-bit"), ex); } } }
/** Extracts the source file and calls System.load. Attemps to extract and load from multiple locations. Throws runtime * exception if all fail. */ private void loadFile (String sourcePath) { String sourceCrc = crc(readFile(sourcePath)); String fileName = new File(sourcePath).getName(); // Temp directory with username in path. File file = new File(System.getProperty("java.io.tmpdir") + "/libgdx" + System.getProperty("user.name") + "/" + sourceCrc, fileName); Throwable ex = loadFile(sourcePath, sourceCrc, file); if (ex == null) return; // System provided temp directory. try { file = File.createTempFile(sourceCrc, null); if (file.delete() && loadFile(sourcePath, sourceCrc, file) == null) return; } catch (Throwable ignored) { } // User home. file = new File(System.getProperty("user.home") + "/.libgdx/" + sourceCrc, fileName); if (loadFile(sourcePath, sourceCrc, file) == null) return; // Relative directory. file = new File(".temp/" + sourceCrc, fileName); if (loadFile(sourcePath, sourceCrc, file) == null) return; // Fallback to java.library.path location, eg for applets. file = new File(System.getProperty("java.library.path"), sourcePath); if (file.exists()) { System.load(file.getAbsolutePath()); return; } throw new GdxRuntimeException(ex); }
/** Loads a shared library for the platform the application is running on. * @param libraryName The platform independent library name. If not contain a prefix (eg lib) or suffix (eg .dll). */ public void load (String libraryName) { // in case of iOS, things have been linked statically to the executable, bail out. if (isIos) return; synchronized (SharedLibraryLoader.class) { if (isLoaded(libraryName)) return; String platformName = mapLibraryName(libraryName); try { if (isAndroid) System.loadLibrary(platformName); else loadFile(platformName); setLoaded(libraryName); } catch (Throwable ex) { throw new GdxRuntimeException("Couldn't load shared library '" + platformName + "' for target: " + System.getProperty("os.name") + (is64Bit ? ", 64-bit" : ", 32-bit"), ex); } } }