Numerous bug fixes and updates
[debian/openrocket] / src / net / sf / openrocket / database / Databases.java
index 4efb545b4313737195e5f24fcab71e8c44fa81fe..3e4e6b6483952e3297472aa0405ad28c498f83da 100644 (file)
@@ -2,11 +2,13 @@ package net.sf.openrocket.database;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URL;
 import java.util.ArrayList;
 
 import net.sf.openrocket.file.MotorLoader;
 import net.sf.openrocket.material.Material;
 import net.sf.openrocket.rocketcomponent.Motor;
+import net.sf.openrocket.util.JarUtil;
 import net.sf.openrocket.util.MathUtil;
 
 
@@ -47,8 +49,18 @@ public class Databases {
                } catch (IOException e) {
                        System.out.println("Could not read thrust curves from JAR: "+e.getMessage());
                        
+                       // Try to find directory as a system resource
+                       File dir;
+                       URL url = ClassLoader.getSystemResource("datafiles/thrustcurves/");
+                       
+                       try {
+                               dir = JarUtil.urlToFile(url);
+                       } catch (Exception e1) {
+                               dir = new File("datafiles/thrustcurves/");
+                       }
+                               
                        try {
-                               MOTOR.loadDirectory(new File("datafiles/thrustcurves/"),".*\\.[eE][nN][gG]$");
+                               MOTOR.loadDirectory(dir, ".*\\.[eE][nN][gG]$");
                        } catch (IOException e1) {
                                System.out.println("Could not read thrust curves from directory either.");
                                throw new RuntimeException(e1);