diff --git a/Main.java b/Main.java index 7b7ed39..f5eab47 100644 --- a/Main.java +++ b/Main.java @@ -6,44 +6,50 @@ import java.util.Scanner; public class Main { - public static void main(String[] args) { - for (File folder : new File(System.getenv("HAXEPATH") + "/lib/").listFiles()) { - if (folder.isDirectory()) { + for (File folder : new File(System.getenv("HAXEPATH") + "/lib/").listFiles()) { // Read all folders in the + // haxelib folder. + if (folder.isDirectory()) { // Make sure that the found folder is actually a folder. try { - String libPath = "C:/HaxeToolkit/haxe/lib/" + folder.getName(); - Scanner s = new Scanner(new File(libPath + "/.current")); - String currentVersion = s.nextLine(); - String formattedFolder = folder.getName().replace(',', '.'); - System.out.println("Checking " + formattedFolder); - for (File libVersion : new File(libPath).listFiles()) { - if (libVersion.isDirectory()) { - if (!libVersion.getName().contains(currentVersion.replace('.', ','))) { + String folderName = folder.getName(); + String libPath = "C:/HaxeToolkit/haxe/lib/" + folderName; + File currentVersionFile = new File(libPath + "/.current"); + if (new File(libPath + "/.dev").exists()) { + System.out.println("\u001B[33mWARNING: Development library deteched. Skipping.\u001B[0m"); + } else { + Scanner currentVersionRaw = new Scanner(currentVersionFile); + String currentVersion = currentVersionRaw.nextLine().replace('.', ','); + currentVersionRaw.close(); // Close scanner since we don't need it anymore. + String formattedFolder = folderName.replace(',', '.'); + System.out.println("Checking " + formattedFolder); + for (File libVersion : new File(libPath).listFiles()) { // Read all the versions of the current + // library. + if (libVersion.isDirectory() + && !libVersion.getName().contains(currentVersion)) { String strippedVersion = libVersion.getName().replace(libPath, ""); String formattedVersion = strippedVersion.replace(',', '.'); - System.out - .println("\nFound unused version: " + formattedVersion); - System.out.println("Would you like to remove it? y/n"); + System.out.println("\nFound unused version: " + formattedVersion); + System.out.println("Would you like to remove it? \u001B[32my\u001B[0m/\u001B[31mn\u001B[0m"); // y\n with color codes if (System.console().readLine().toLowerCase().equals("y")) { runCommand("haxelib", "remove", formattedFolder, formattedVersion); } else { System.out.println("Skipping."); } - } } } - s.close(); - } catch (FileNotFoundException e) { - System.out.println("An error occurred."); + } catch (FileNotFoundException e) { // If an error happens + System.out + .println("\u001B[31mERROR: Could not find library "+ folder.getName().replace(',', '.') +" or an unknown error occured. Skipping"); e.printStackTrace(); + System.out.println("\u001B[0m"); } } } } /** - * Runs a system command + * Runs a system command * I got this off a random website lol * * @see https://javapointers.com/java/java-core/how-to-run-a-command-using-java-in-linux-or-windows/