2
0
Эх сурвалжийг харах

* 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

sha..rd 14 жил өмнө
parent
commit
164dec188a

+ 25 - 19
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){
-            extractionDir = new File(JmeSystem.getStorageFolder(), 
-                                     "natives_" + Integer.toHexString(computeNativesHash()) );
-            if (!extractionDir.exists()){
-                extractionDir.mkdir();
+        if (extractionDir == null) {
+            File workingFolder = new File("").getAbsoluteFile();
+            if (!workingFolder.canWrite()) {
+                logger.log(Level.WARNING, "Working directory is not writable. Using home directory instead.");
+                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("");
-            if (url != null) {
-                StringBuilder sb = new StringBuilder(url.toString());
-                if (sb.indexOf("jar:") == 0) {
-                    sb.delete(0, 4);
-                    sb.delete(sb.indexOf("!"), sb.length());
-                    sb.delete(sb.lastIndexOf("/") + 1, sb.length());
-                }
-                try {
-                    url = new URL(sb.toString());
-                } catch (MalformedURLException ex) {
-                    throw new UnsupportedOperationException(ex);
-                }
+            URL url = Thread.currentThread().getContextClassLoader().getResource("com/jme3/system/Natives.class");
+            
+            StringBuilder sb = new StringBuilder(url.toString());
+            if (sb.indexOf("jar:") == 0) {
+                sb.delete(0, 4);
+                sb.delete(sb.indexOf("!"), sb.length());
+                sb.delete(sb.lastIndexOf("/") + 1, sb.length());
+            }
+            try {
+                url = new URL(sb.toString());
+            } catch (MalformedURLException 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;