Commits

John Marsden  committed fc3afe4

Cross platform hack for java.library.path and lwjgl path finding

  • Participants
  • Parent commits a04e8b0
  • Branches develop

Comments (0)

Files changed (1)

File src/main/java/cc/plural/ecs/provider/LWJGLApplication.java

 package cc.plural.ecs.provider;
 
 import cc.plural.ecs.runtime.ApplicationInterface;
+import java.io.File;
+import org.apache.log4j.Logger;
 import org.lwjgl.Sys;
 
 public class LWJGLApplication {
 
+    public static final Logger LOGGER = Logger.getLogger(LWJGLApplication.class.getCanonicalName());
     long lastFrame;
     int fps;
     long lastFPS;
         this.applicationConfiguration = applicationConfiguration;
         pauseFlag = false;
 
-//        String javaNativeProp = System.getProperty("java.library.path");
-//        String lwjglProp = System.getProperty("org.lwjgl.librarypath");
-//        if (javaNativeProp != null && lwjglProp == null) {
-//            String pathSeparator = System.getProperty("path.separator");
-//            String property = new File("natives").getAbsolutePath();
-//            System.setProperty("java.library.path", javaNativeProp + pathSeparator + property);
-//            System.out.println("Found library (" + System.getProperty("java.library.path") + ":" + System.getProperty("org.lwjgl.librarypath") + ")!");
-//        } else if (javaNativeProp == null && lwjglProp == null) {
-//            String property = new File("natives").getAbsolutePath();
-//            System.setProperty("java.library.path", property);
-//            System.setProperty("org.lwjgl.librarypath", property);
-//            System.out.println("Did not find library (" + System.getProperty("java.library.path") + ":" + System.getProperty("org.lwjgl.librarypath") + ")! setting it to: " + property);
-//        } else {
-//            System.out.println("Found library (" + System.getProperty("java.library.path") + ":" + System.getProperty("org.lwjgl.librarypath") + ")!");
-//        }
+
+
+        LOGGER.info("Identifying LWJGL");
+
+        // Check the natives folder
+        File check1 = new File("natives");
+        if (check1.exists()) {
+            setLWJGL(check1);
+        } else {
+            // Check the target/natives folder
+            File check2 = new File("target/natives");
+            if (check2.exists()) {
+                setLWJGL(check2);
+            } else {
+                // Check .lwjgl folder
+                String userHome = System.getProperty("user.home");
+                File userHomeFolder = new File(userHome);
+                File check3 = new File(userHomeFolder, ".lwjgl");
+                if (check3.exists()) {
+                    setLWJGL(check3);
+                } else {
+
+                    throw new RuntimeException("No LWJGL Found.");
+                }
+            }
+        }
+
+
+    }
+
+    public final void setLWJGL(File file) {
+        String javaNativeProp = System.getProperty("java.library.path");
+        String lwjglProp = System.getProperty("org.lwjgl.librarypath");
+        String pathSeparator = System.getProperty("path.separator");
+        String property = file.getAbsolutePath();
+        if (javaNativeProp == null && lwjglProp == null) {
+            System.setProperty("java.library.path", property);
+            System.setProperty("org.lwjgl.librarypath", property);
+            LOGGER.info(String.format("Setting Java Library and LWJGL Path: %s", property));
+        } else if (javaNativeProp != null && lwjglProp == null) {
+            System.setProperty("java.library.path", javaNativeProp + pathSeparator + property);
+            System.setProperty("org.lwjgl.librarypath", property);
+            LOGGER.info(String.format("Setting Java Library Path: %s and LWJGL Path: %s", javaNativeProp + pathSeparator + property, property));
+        } else if (javaNativeProp != null && lwjglProp != null) {
+            LOGGER.info("Java Library and Lwjgl Set Already");
+        } else {
+            LOGGER.info("Other Unknown");
+        }
     }
 
     public void start() {
             }
             renderer.display.sync(renderer.frameRate);
             renderer.display.update();
-            
+
 
             updateFPS();
         }