From 4760b5e358168036595cb64447c1644e23635a51 Mon Sep 17 00:00:00 2001 From: Michael-Jouanneau Date: Sat, 26 Nov 2016 20:02:23 +0100 Subject: [PATCH] Changed Things --- src/Launcher/Tabs.java | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/Launcher/Tabs.java b/src/Launcher/Tabs.java index 936e7ef..0c67337 100644 --- a/src/Launcher/Tabs.java +++ b/src/Launcher/Tabs.java @@ -5,8 +5,16 @@ import javafx.fxml.FXMLLoader; import javafx.scene.Node; import javafx.scene.layout.Pane; import javafx.util.Pair; + +import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; import java.net.URL; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; @SuppressWarnings({"unused", "WeakerAccess"}) public class Tabs { @@ -71,4 +79,29 @@ public class Tabs { unloadTab(fileName); return load(fileName); } + public static List listShit(Class from, String path) throws IOException{ + final File jarFile = new File(from.getProtectionDomain().getCodeSource().getLocation().getPath()); + List l = new ArrayList<>(); + if(jarFile.isFile()) { // Run with JAR file + final JarFile jar = new JarFile(jarFile); + final Enumeration entries = jar.entries(); //gives ALL entries in jar + while(entries.hasMoreElements()) { + final String name = entries.nextElement().getName(); + if (name.startsWith(path + "/")) //filter according to the path + l.add(name); + } + jar.close(); + } else { // Run with IDE + final URL url = from.getResource("/" + path); + if (url != null) + try { + final File apps = new File(url.toURI()); + for (File app : apps.listFiles()) + l.add(app.getName()); + } catch (URISyntaxException ex) { + // never happens + } + } + return l; + } }