fixed A bug where it just randomly crashes and added the ability to delete duplicate files with -d paramater
This commit is contained in:
parent
a07a5032c2
commit
f32e5225cb
7 changed files with 131 additions and 7 deletions
8
.idea/artifacts/Sherly_jar.xml
generated
Normal file
8
.idea/artifacts/Sherly_jar.xml
generated
Normal file
|
@ -0,0 +1,8 @@
|
|||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="Sherly:jar">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/Sherly_jar</output-path>
|
||||
<root id="archive" name="Sherly.jar">
|
||||
<element id="module-output" name="Sherly" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
64
.idea/workspace.xml
generated
64
.idea/workspace.xml
generated
|
@ -1,10 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ArtifactsWorkspaceSettings">
|
||||
<artifacts-to-build>
|
||||
<artifact name="Sherly:jar" />
|
||||
</artifacts-to-build>
|
||||
</component>
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="9b57ac51-c870-474b-9dfd-64a5fc490635" name="Changes" comment="Fixed Duplicates in HashMap">
|
||||
<list default="true" id="9b57ac51-c870-474b-9dfd-64a5fc490635" name="Changes" comment="test">
|
||||
<change afterPath="$PROJECT_DIR$/.idea/artifacts/Sherly_jar.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/META-INF/MANIFEST.MF" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/META-INF/MANIFEST.MF" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/ConsoleColors.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ConsoleColors.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/ThreadedCompare.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ThreadedCompare.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
|
@ -42,9 +53,29 @@
|
|||
<component name="PropertiesComponent">{
|
||||
"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"
|
||||
}
|
||||
}</component>
|
||||
<component name="RunManager">
|
||||
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="Main" />
|
||||
<module name="Sherly" />
|
||||
<option name="PROGRAM_PARAMETERS" value="-c -f $USER_HOME$/Pictures/ -p -d" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Application.Main" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
|
@ -96,7 +127,21 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1672749481858</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="7" />
|
||||
<task id="LOCAL-00007" summary="Fixed Duplicates in HashMap">
|
||||
<created>1672749693035</created>
|
||||
<option name="number" value="00007" />
|
||||
<option name="presentableId" value="LOCAL-00007" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1672749693035</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00008" summary="test">
|
||||
<created>1672749718265</created>
|
||||
<option name="number" value="00008" />
|
||||
<option name="presentableId" value="LOCAL-00008" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1672749718265</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="9" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -127,6 +172,17 @@
|
|||
<MESSAGE value="Just a Test" />
|
||||
<MESSAGE value="Removing not needed lines" />
|
||||
<MESSAGE value="Fixed Duplicates in HashMap" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Fixed Duplicates in HashMap" />
|
||||
<MESSAGE value="test" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="test" />
|
||||
</component>
|
||||
<component name="XDebuggerManager">
|
||||
<breakpoint-manager>
|
||||
<breakpoints>
|
||||
<breakpoint enabled="true" type="java-exception">
|
||||
<properties class="java.lang.ArrayIndexOutOfBoundsException" package="java.lang" />
|
||||
<option name="timeStamp" value="1" />
|
||||
</breakpoint>
|
||||
</breakpoints>
|
||||
</breakpoint-manager>
|
||||
</component>
|
||||
</project>
|
3
META-INF/MANIFEST.MF
Normal file
3
META-INF/MANIFEST.MF
Normal file
|
@ -0,0 +1,3 @@
|
|||
Manifest-Version: 1.0
|
||||
Main-Class: Main
|
||||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
3
src/META-INF/MANIFEST.MF
Normal file
3
src/META-INF/MANIFEST.MF
Normal file
|
@ -0,0 +1,3 @@
|
|||
Manifest-Version: 1.0
|
||||
Main-Class: Main
|
||||
|
|
@ -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<String> 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<Path> 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<Path> 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<Path> deleteThem) {
|
||||
for (Path file : deleteThem) {
|
||||
file.toFile().delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Reference in a new issue