/** Extracts the specified file into the temp directory if it does not already exist or the CRC does not match. If file * extraction fails and the file exists at java.library.path, that file is returned. * @param sourcePath The file to extract from the classpath or JAR. * @param dir The location where the extracted file will be written. */ public void extractFileTo (String sourcePath, File dir) throws IOException { extractFile(sourcePath, crc(readFile(sourcePath)), new File(dir, new File(sourcePath).getName())); }
/** Extracts the specified file into the temp directory if it does not already exist or the CRC does not match. If file * extraction fails and the file exists at java.library.path, that file is returned. * @param sourcePath The file to extract from the classpath or JAR. * @param dir The location where the extracted file will be written. */ public void extractFileTo (String sourcePath, File dir) throws IOException { extractFile(sourcePath, crc(readFile(sourcePath)), new File(dir, new File(sourcePath).getName())); }
/** Extracts the specified file to the specified directory if it does not already exist or the CRC does not match. If file * extraction fails and the file exists at java.library.path, that file is returned. * @param sourcePath The file to extract from the classpath or JAR. * @param dirName The name of the subdirectory where the file will be extracted. If null, the file's CRC will be used. * @return The extracted file. */ public File extractFile (String sourcePath, String dirName) throws IOException { try { String sourceCrc = crc(readFile(sourcePath)); if (dirName == null) dirName = sourceCrc; File extractedFile = getExtractedFile(dirName, new File(sourcePath).getName()); if (extractedFile == null) { extractedFile = getExtractedFile(UUID.randomUUID().toString(), new File(sourcePath).getName()); if (extractedFile == null) throw new GdxRuntimeException( "Unable to find writable path to extract file. Is the user home directory writable?"); } return extractFile(sourcePath, sourceCrc, extractedFile); } catch (RuntimeException ex) { // Fallback to file at java.library.path location, eg for applets. File file = new File(System.getProperty("java.library.path"), sourcePath); if (file.exists()) return file; throw 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); }
FileOutputStream output = null; try { input = readFile(sourcePath); extractedFile.getParentFile().mkdirs(); output = new FileOutputStream(extractedFile);
FileOutputStream output = null; try { input = readFile(sourcePath); extractedFile.getParentFile().mkdirs(); output = new FileOutputStream(extractedFile);
/** Extracts the specified file to the specified directory if it does not already exist or the CRC does not match. If file * extraction fails and the file exists at java.library.path, that file is returned. * @param sourcePath The file to extract from the classpath or JAR. * @param dirName The name of the subdirectory where the file will be extracted. If null, the file's CRC will be used. * @return The extracted file. */ public File extractFile (String sourcePath, String dirName) throws IOException { try { String sourceCrc = crc(readFile(sourcePath)); if (dirName == null) dirName = sourceCrc; File extractedFile = getExtractedFile(dirName, new File(sourcePath).getName()); if (extractedFile == null) { extractedFile = getExtractedFile(UUID.randomUUID().toString(), new File(sourcePath).getName()); if (extractedFile == null) throw new GdxRuntimeException( "Unable to find writable path to extract file. Is the user home directory writable?"); } return extractFile(sourcePath, sourceCrc, extractedFile); } catch (RuntimeException ex) { // Fallback to file at java.library.path location, eg for applets. File file = new File(System.getProperty("java.library.path"), sourcePath); if (file.exists()) return file; throw 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); }
/** Extracts the specified file into the temp directory if it does not already exist or the CRC does not match. If file * extraction fails and the file exists at java.library.path, that file is returned. * @param sourcePath The file to extract from the classpath or JAR. * @param dir The location where the extracted file will be written. */ public void extractFileTo (String sourcePath, File dir) throws IOException { extractFile(sourcePath, crc(readFile(sourcePath)), new File(dir, new File(sourcePath).getName())); }
/** 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 specified file to the specified directory if it does not already exist or the CRC does not match. If file * extraction fails and the file exists at java.library.path, that file is returned. * @param sourcePath The file to extract from the classpath or JAR. * @param dirName The name of the subdirectory where the file will be extracted. If null, the file's CRC will be used. * @return The extracted file. */ public File extractFile (String sourcePath, String dirName) throws IOException { try { String sourceCrc = crc(readFile(sourcePath)); if (dirName == null) dirName = sourceCrc; File extractedFile = getExtractedFile(dirName, new File(sourcePath).getName()); if (extractedFile == null) { extractedFile = getExtractedFile(UUID.randomUUID().toString(), new File(sourcePath).getName()); if (extractedFile == null) throw new GdxRuntimeException( "Unable to find writable path to extract file. Is the user home directory writable?"); } return extractFile(sourcePath, sourceCrc, extractedFile); } catch (RuntimeException ex) { // Fallback to file at java.library.path location, eg for applets. File file = new File(System.getProperty("java.library.path"), sourcePath); if (file.exists()) return file; throw ex; } }
FileOutputStream output = null; try { input = readFile(sourcePath); extractedFile.getParentFile().mkdirs(); output = new FileOutputStream(extractedFile);