/** 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 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 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; } }