diff --git a/.classpath b/.classpath index 499a103..269d628 100644 --- a/.classpath +++ b/.classpath @@ -21,6 +21,5 @@ - diff --git a/lib/jme-physics.jar b/lib/jme-physics.jar deleted file mode 100644 index f5e7885..0000000 Binary files a/lib/jme-physics.jar and /dev/null differ diff --git a/src/sg/env/Envoriment.java b/src/sg/env/Envoriment.java new file mode 100644 index 0000000..72c6c47 --- /dev/null +++ b/src/sg/env/Envoriment.java @@ -0,0 +1,5 @@ +package sg.env; + +public class Envoriment { + +} diff --git a/src/sg/util/FileFinder.java b/src/sg/util/FileFinder.java new file mode 100644 index 0000000..18424f8 --- /dev/null +++ b/src/sg/util/FileFinder.java @@ -0,0 +1,148 @@ +package sg.util; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.regex.Matcher; + +/** + * File path utilities + * + * @author Ziver + */ +public class FileFinder { + + /** + * Returns a String with a relative path from the given path + * + * @param file The file to get a relative path from + * @param path The path + * @return A String with a relative path + */ + public static String relativePath(File file, String path){ + String absolute = file.getAbsolutePath(); + String tmpPath = path.replaceAll( + "[/\\\\]", + Matcher.quoteReplacement(File.separator)); + + String relative = absolute.substring( + absolute.indexOf(tmpPath)+path.length(), + absolute.length()); + return relative; + } + + /** + * Returns the File object for the given file + * + * @param path The path to the file (no / if not absolute path) + * @return A File object for the file + * @throws URISyntaxException + */ + public static File find(String path){ + try { + File file = new File(path); + if(file!=null && file.exists()){ + return file; + } + return new File(findURL(path).toURI()); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + + /** + * Reads and returns the content of a file as a String. + * Or use FileUtils.readFileToString(file); + * + * @param file The file to read + * @return The file content + * @throws IOException + */ + public static String getFileContent(File file) throws IOException{ + BufferedReader in = new BufferedReader(new FileReader(file)); + StringBuffer ret = new StringBuffer(); + int tmp; + + while((tmp=in.read()) != -1){ + ret.append((char)tmp); + } + + in.close(); + return ret.toString(); + } + + /** + * Returns the URL to the given file + * + * @param path The path to the file (no / if not absolute path) + * @return A URL object for the file + * @throws URISyntaxException + */ + public static URL findURL(String path){ + return FileFinder.class.getClassLoader().getResource(path); + } + + /** + * Returns a ArrayList with all the files in a folder and sub folders + * + * @param dir The directory to search in + * @return The ArrayList with the files + */ + public static ArrayList search(File dir){ + return search(dir, new ArrayList()); + } + + /** + * Returns a ArrayList with all the files in a folder and sub folders + * + * @param dir The directory to search in + * @param fileList The ArrayList to add the files to + * @return The ArrayList with the files + */ + public static ArrayList search(File dir, ArrayList fileList){ + String[] temp = dir.list(); + File file; + + if(temp != null){ + for(int i=0; i