Skip to content

Commit

Permalink
Color codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vortex2Oblivion committed Nov 29, 2024
1 parent 96fd121 commit 3b2e110
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit 3b2e110

Please sign in to comment.