* Native extraction will place natives in working directory unless its non-writable, in that case it will place them in <home dir>/.jme3/natives_<apphash>

* Hopefully fixed NPE in computing extraction hash

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8486 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..rd 14 years ago
parent dfafd24ab8
commit 164dec188a
  1. 44
      engine/src/desktop/com/jme3/system/Natives.java

@ -59,14 +59,20 @@ public class Natives {
} }
public static File getExtractionDir(){ public static File getExtractionDir(){
if (extractionDirOverride != null){ if (extractionDirOverride != null) {
return extractionDirOverride; return extractionDirOverride;
} }
if (extractionDir == null){ if (extractionDir == null) {
extractionDir = new File(JmeSystem.getStorageFolder(), File workingFolder = new File("").getAbsoluteFile();
"natives_" + Integer.toHexString(computeNativesHash()) ); if (!workingFolder.canWrite()) {
if (!extractionDir.exists()){ logger.log(Level.WARNING, "Working directory is not writable. Using home directory instead.");
extractionDir.mkdir(); extractionDir = new File(JmeSystem.getStorageFolder(),
"natives_" + Integer.toHexString(computeNativesHash()));
if (!extractionDir.exists()) {
extractionDir.mkdir();
}
} else {
extractionDir = workingFolder;
} }
} }
return extractionDir; return extractionDir;
@ -75,20 +81,20 @@ public class Natives {
private static int computeNativesHash(){ private static int computeNativesHash(){
try { try {
String classpath = System.getProperty("java.class.path"); String classpath = System.getProperty("java.class.path");
URL url = Natives.class.getResource(""); URL url = Thread.currentThread().getContextClassLoader().getResource("com/jme3/system/Natives.class");
if (url != null) {
StringBuilder sb = new StringBuilder(url.toString()); StringBuilder sb = new StringBuilder(url.toString());
if (sb.indexOf("jar:") == 0) { if (sb.indexOf("jar:") == 0) {
sb.delete(0, 4); sb.delete(0, 4);
sb.delete(sb.indexOf("!"), sb.length()); sb.delete(sb.indexOf("!"), sb.length());
sb.delete(sb.lastIndexOf("/") + 1, sb.length()); sb.delete(sb.lastIndexOf("/") + 1, sb.length());
} }
try { try {
url = new URL(sb.toString()); url = new URL(sb.toString());
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
throw new UnsupportedOperationException(ex); throw new UnsupportedOperationException(ex);
}
} }
URLConnection conn = url.openConnection(); URLConnection conn = url.openConnection();
int hash = classpath.hashCode() ^ (int)conn.getLastModified(); int hash = classpath.hashCode() ^ (int)conn.getLastModified();
return hash; return hash;

Loading…
Cancel
Save