diff --git a/.idea/artifacts/Sherly_jar.xml b/.idea/artifacts/Sherly_jar.xml
new file mode 100644
index 0000000..139526d
--- /dev/null
+++ b/.idea/artifacts/Sherly_jar.xml
@@ -0,0 +1,8 @@
+
+
+ $PROJECT_DIR$/out/artifacts/Sherly_jar
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index aec1957..384e82a 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,10 +1,21 @@
+
+
+
+
+
-
+
+
+
+
+
+
+
@@ -42,9 +53,29 @@
{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
- "RunOnceActivity.ShowReadmeOnStart": "true"
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "last_opened_file_path": "/home/bly/IdeaProjects/Sherly",
+ "project.structure.last.edited": "Artifacts",
+ "project.structure.proportion": "0.15",
+ "project.structure.side.proportion": "0.2"
}
}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -96,7 +127,21 @@
1672749481858
-
+
+ 1672749693035
+
+
+
+ 1672749693035
+
+
+ 1672749718265
+
+
+
+ 1672749718265
+
+
@@ -127,6 +172,17 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..5ee19cb
--- /dev/null
+++ b/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: Main
+
diff --git a/src/ConsoleColors.java b/src/ConsoleColors.java
index 075d762..24b2f11 100644
--- a/src/ConsoleColors.java
+++ b/src/ConsoleColors.java
@@ -10,5 +10,6 @@ public class ConsoleColors {
public static final String CYAN_BOLD = "\033[1;36m"; // CYAN
+ public static final String RED_BOLD = "\033[1;31m"; // RED
}
diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..5ee19cb
--- /dev/null
+++ b/src/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: Main
+
diff --git a/src/Main.java b/src/Main.java
index 1cdfa3f..3b7d3cf 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -1,3 +1,4 @@
+import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -5,6 +6,7 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Scanner;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -17,7 +19,7 @@ public class Main {
public static void main(String[] args) throws InterruptedException {
boolean doTheColorThingy = false;
boolean showProgress = false;
-
+ boolean deleteDups = false;
boolean recordFolder = false;
List paths = new ArrayList<>();
@@ -32,6 +34,7 @@ public class Main {
if (i.equalsIgnoreCase("-c") || i.equalsIgnoreCase("-color")) { doTheColorThingy = true;}
if (i.equalsIgnoreCase("-p") || i.equalsIgnoreCase("-progress")) { showProgress = true;}
if (i.equalsIgnoreCase("-f") || i.equalsIgnoreCase("-folder")) { recordFolder = true;}
+ if (i.equalsIgnoreCase("-d") || i.equalsIgnoreCase("-delete")) { deleteDups = true;}
}
@@ -118,8 +121,52 @@ public class Main {
}
+ if (deleteDups) {
+ List allTheFilesWillBeDeleted = new ArrayList<>();
+ long bytes = 0;
+
+ for (String md5: fileMap.keySet()) {
+ Main.fileMap.get(md5).remove(0);
+ for (Path file: Main.fileMap.get(md5)) {
+ bytes += file.toFile().length();
+ }
+ allTheFilesWillBeDeleted.addAll(Main.fileMap.get(md5));
+
+ }
+
+
+
+ ask(doTheColorThingy, bytes, allTheFilesWillBeDeleted);
+
+ }
+
+ }
+ public static void ask(boolean color, long bytes, List deleteThem) {
+ if (color) {
+ System.out.println(ConsoleColors.RED_BOLD + (bytes / 8000000) + " unnecessary MB found, do you want to Delete them? Y / N" + ConsoleColors.RESET);
+ } else {
+ System.out.println((bytes / 8000000) + " unnecessary MB found, do you want to Delete them? Y / N");
+ }
+ Scanner input = new Scanner(System.in);
+ String answer = input.next();
+ if (answer.toLowerCase().contains("y")) {
+ delete(deleteThem);
+ input.close();
+
+ } else if (answer.toLowerCase().contains("n")) {
+ return;
+ } else {
+ ask(color, bytes, deleteThem);
+ }
+ input.close();
}
+ public static void delete(List deleteThem) {
+ for (Path file : deleteThem) {
+ file.toFile().delete();
+ }
+ }
+
}
diff --git a/src/ThreadedCompare.java b/src/ThreadedCompare.java
index ca2e0ab..795c37f 100644
--- a/src/ThreadedCompare.java
+++ b/src/ThreadedCompare.java
@@ -27,8 +27,14 @@ public class ThreadedCompare extends Thread {
//here it is trying to add the values in the HashMap so everything is nice and clear
Main.fileMap.putIfAbsent(getMD5Sum(file1.toFile()), bothList);
- Main.fileMap.get(getMD5Sum(file1.toFile())).removeAll(bothList);
- Main.fileMap.get(getMD5Sum(file1.toFile())).addAll(bothList);
+
+ if (!bothList.isEmpty()) {
+
+ Main.fileMap.get(getMD5Sum(file1.toFile())).remove(file1);
+ Main.fileMap.get(getMD5Sum(file1.toFile())).remove(file2);
+ Main.fileMap.get(getMD5Sum(file1.toFile())).addAll(bothList);
+ }
+
}
} catch (IOException e) {