From ae8dc339f59e972a932b9097d47271e245e4ca9a Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Tue, 06 Aug 2019 19:35:43 -0400
Subject: [PATCH] Proto textures parsing.

---
 GroupEditor.java |   17 +++++++-
 Grafreed.java    |   73 ++++++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+), 2 deletions(-)

diff --git a/Grafreed.java b/Grafreed.java
index a463511..ed3e880 100644
--- a/Grafreed.java
+++ b/Grafreed.java
@@ -49,6 +49,79 @@
             
         }
     }
+
+    public static String RemovePrefix(String s, String prefix)
+    {
+        if (s != null && prefix != null && s.startsWith(prefix))
+        {
+            return s.substring(prefix.length());
+        }
+
+        return s;
+    }
+    
+    static void ParseFileSystem(java.io.File dir, iResourceCallBack callback, String prefix)
+    {
+        callback.CallBack(RemovePrefix(dir.toString(),prefix).split("/"));
+        File[] listFiles = dir.listFiles();
+        if (listFiles != null)
+        {
+            for (java.io.File file : listFiles)
+            {
+                ParseFileSystem(file, callback, prefix);
+            }
+        }
+    }
+        
+    static interface iResourceCallBack
+    {
+        void CallBack(String[] path);
+    }
+    
+    static void ParseResources(String path, iResourceCallBack callback)
+    {
+        java.io.File jarFile = new java.io.File(Grafreed.class.getProtectionDomain().getCodeSource().getLocation().getPath());
+
+        if (jarFile.isFile())
+        {
+            // Run with JAR file
+            try
+            {
+                java.util.jar.JarFile jar = new java.util.jar.JarFile(jarFile);
+                java.util.Enumeration<java.util.jar.JarEntry> entries = jar.entries(); //gives ALL entries in jar
+                while (entries.hasMoreElements())
+                {
+                    String name = entries.nextElement().getName();
+                    
+                    if (name.startsWith(path + "/"))
+                        callback.CallBack(RemovePrefix(name, path).split("/"));
+                }
+                jar.close();
+            } catch (Exception ex)
+            {
+                ex.printStackTrace();
+            }
+        } else
+        {
+            // Run with IDE
+            final java.net.URL url = Object3D.class.getResource("/" + path);
+            if (url != null)
+            {
+                try
+                {
+                    java.io.File apps = new java.io.File(url.toURI());
+                    ParseFileSystem(apps, callback, RemovePrefix(url.toString(), "file:"));
+//                    for (java.io.File app : apps.listFiles())
+//                    {
+//                        //System.out.println(RemovePrefix(app.toString(), RemovePrefix(url.toString(), "file:") + "/"));
+//                    }
+                } catch (Exception ex)
+                {
+                    ex.printStackTrace();
+                }
+            }
+        }
+    }
     
     public void init()
     {
diff --git a/GroupEditor.java b/GroupEditor.java
index 5698ae1..ed46f77 100644
--- a/GroupEditor.java
+++ b/GroupEditor.java
@@ -16,6 +16,7 @@
 //import buoy.widget.BFileChooser;
 
 class GroupEditor extends ObjEditor implements //iParse, //iCallBack,
+    Grafreed.iResourceCallBack,
         ObjectUI,
         Runnable,
         ActionListener,
@@ -311,12 +312,24 @@
         }
     }
         
-    public void ChangeSkybox(String name)
+    public void CallBack(String[] path)
+    {
+        for (int i = 0; i < path.length; i++)
+        {
+            System.out.print(path[i] + "/");
+        }
+        
+        System.out.println();
+    }
+    
+    public void ChangeSkybox(String skybox)
     {
         //cameraView.envyoff = false;
-        group.skyboxname = name;
+        group.skyboxname = skybox;
         group.skyboxext = "jpg";
         cameraView.repaint();
+
+        Grafreed.ParseResources("textures", this);
     }
     
     //ObjEditor objEditor;

--
Gitblit v1.6.2