Ported the project to maven, updated README, fixed some minor issues in the code

This commit is contained in:
Julian Müller (ChaoticByte) 2023-05-05 20:56:59 +02:00
parent 619b16bd28
commit 5b77b2de6f
16 changed files with 182 additions and 516 deletions

4
.gitignore vendored
View file

@ -28,5 +28,5 @@ bin/
### Mac OS ###
.DS_Store
### Compile via Instructions ###
Bin/
### Maven ###
target/

View file

@ -1,8 +0,0 @@
<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>

6
.idea/misc.xml generated
View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated
View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Sherly.iml" filepath="$PROJECT_DIR$/Sherly.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated
View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

363
.idea/workspace.xml generated
View file

@ -1,363 +0,0 @@
<?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="Optimized imports">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Rebase.Settings">
<option name="NEW_BASE" value="master" />
</component>
<component name="Git.Settings">
<option name="PREVIOUS_COMMIT_AUTHORS">
<list>
<option value="Lia Brueggemann &lt;brueggemann.l@proton.me&gt;" />
</list>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="GithubPullRequestsUISettings">
<option name="selectedUrlAndAccountId">
<UrlAndAccount>
<option name="accountId" value="1ec83841-9eac-4bec-b8b8-e821355f624e" />
<option name="url" value="https://github.com/BlyDoesCoding/Sherly.git" />
</UrlAndAccount>
</option>
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2Jn9jTd9EocdVDpvvPMYxSrBjXm" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;master&quot;,
&quot;last_opened_file_path&quot;: &quot;/home/bly/IdeaProjects/Sherly&quot;,
&quot;project.structure.last.edited&quot;: &quot;Artifacts&quot;,
&quot;project.structure.proportion&quot;: &quot;0.15&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.2&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;
}
}</component>
<component name="RunAnythingCache">
<option name="myCommands">
<command value="github" />
</option>
</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="-f $USER_HOME$/.local/share/Steam -p -n" />
<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">
<changelist id="9b57ac51-c870-474b-9dfd-64a5fc490635" name="Changes" comment="" />
<created>1672703116568</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1672703116568</updated>
</task>
<task id="LOCAL-00001" summary="First Creation">
<created>1672703433480</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1672703433480</updated>
</task>
<task id="LOCAL-00002" summary="First Creation">
<created>1672703559416</created>
<option name="number" value="00002" />
<option name="presentableId" value="LOCAL-00002" />
<option name="project" value="LOCAL" />
<updated>1672703559416</updated>
</task>
<task id="LOCAL-00003" summary="Just a Test">
<created>1672703686539</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1672703686539</updated>
</task>
<task id="LOCAL-00004" summary="Just a Test">
<created>1672703881482</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1672703881482</updated>
</task>
<task id="LOCAL-00005" summary="Removing not needed lines">
<created>1672704560597</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1672704560597</updated>
</task>
<task id="LOCAL-00006" summary="Fixed Duplicates in HashMap">
<created>1672749481858</created>
<option name="number" value="00006" />
<option name="presentableId" value="LOCAL-00006" />
<option name="project" value="LOCAL" />
<updated>1672749481858</updated>
</task>
<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>
<task id="LOCAL-00009" summary="fixed A bug where it just randomly crashes and added the ability to delete duplicate files with -d paramater">
<created>1672798827144</created>
<option name="number" value="00009" />
<option name="presentableId" value="LOCAL-00009" />
<option name="project" value="LOCAL" />
<updated>1672798827144</updated>
</task>
<task id="LOCAL-00010" summary="Fixed another Random Crash that happened when a file size is near 0">
<created>1672874587158</created>
<option name="number" value="00010" />
<option name="presentableId" value="LOCAL-00010" />
<option name="project" value="LOCAL" />
<updated>1672874587158</updated>
</task>
<task id="LOCAL-00011" summary="Simplify code in ThreadedCompare.java and added option for debuging with -debug">
<created>1674655068301</created>
<option name="number" value="00011" />
<option name="presentableId" value="LOCAL-00011" />
<option name="project" value="LOCAL" />
<updated>1674655068301</updated>
</task>
<task id="LOCAL-00012" summary="Simplify code in ThreadedCompare.java and added option for debuging with -debug">
<created>1674655119812</created>
<option name="number" value="00012" />
<option name="presentableId" value="LOCAL-00012" />
<option name="project" value="LOCAL" />
<updated>1674655119812</updated>
</task>
<task id="LOCAL-00013" summary="Added Number of files in -d option">
<created>1674655881410</created>
<option name="number" value="00013" />
<option name="presentableId" value="LOCAL-00013" />
<option name="project" value="LOCAL" />
<updated>1674655881410</updated>
</task>
<task id="LOCAL-00014" summary="Added -h / -help option for better usability">
<created>1679341241426</created>
<option name="number" value="00014" />
<option name="presentableId" value="LOCAL-00014" />
<option name="project" value="LOCAL" />
<updated>1679341241426</updated>
</task>
<task id="LOCAL-00015" summary="Rework of README.md">
<created>1679341913990</created>
<option name="number" value="00015" />
<option name="presentableId" value="LOCAL-00015" />
<option name="project" value="LOCAL" />
<updated>1679341913990</updated>
</task>
<task id="LOCAL-00016" summary="Rework of README.md">
<created>1679341943299</created>
<option name="number" value="00016" />
<option name="presentableId" value="LOCAL-00016" />
<option name="project" value="LOCAL" />
<updated>1679341943299</updated>
</task>
<task id="LOCAL-00017" summary="Update deletion behavior and fixed file == NULL bug">
<created>1679344271798</created>
<option name="number" value="00017" />
<option name="presentableId" value="LOCAL-00017" />
<option name="project" value="LOCAL" />
<updated>1679344271798</updated>
</task>
<task id="LOCAL-00018" summary="Update README.md according to the new deletion behavior">
<created>1679344426853</created>
<option name="number" value="00018" />
<option name="presentableId" value="LOCAL-00018" />
<option name="project" value="LOCAL" />
<updated>1679344426853</updated>
</task>
<task id="LOCAL-00019" summary="Added -t to tell Sherly the number of Threads it should use">
<created>1679345325362</created>
<option name="number" value="00019" />
<option name="presentableId" value="LOCAL-00019" />
<option name="project" value="LOCAL" />
<updated>1679345325362</updated>
</task>
<task id="LOCAL-00020" summary="Upload Bin">
<created>1679346354129</created>
<option name="number" value="00020" />
<option name="presentableId" value="LOCAL-00020" />
<option name="project" value="LOCAL" />
<updated>1679346354129</updated>
</task>
<task id="LOCAL-00021" summary="Prepare for Aur Package">
<created>1679415958151</created>
<option name="number" value="00021" />
<option name="presentableId" value="LOCAL-00021" />
<option name="project" value="LOCAL" />
<updated>1679415958151</updated>
</task>
<task id="LOCAL-00022" summary="AUR Package instructions">
<created>1679508360229</created>
<option name="number" value="00022" />
<option name="presentableId" value="LOCAL-00022" />
<option name="project" value="LOCAL" />
<updated>1679508360229</updated>
</task>
<task id="LOCAL-00023" summary="Fix MD">
<created>1679508394699</created>
<option name="number" value="00023" />
<option name="presentableId" value="LOCAL-00023" />
<option name="project" value="LOCAL" />
<updated>1679508394699</updated>
</task>
<task id="LOCAL-00024" summary="Fix MD">
<created>1679508433400</created>
<option name="number" value="00024" />
<option name="presentableId" value="LOCAL-00024" />
<option name="project" value="LOCAL" />
<updated>1679508433400</updated>
</task>
<task id="LOCAL-00025" summary="Fix MD">
<created>1679508468115</created>
<option name="number" value="00025" />
<option name="presentableId" value="LOCAL-00025" />
<option name="project" value="LOCAL" />
<updated>1679508468115</updated>
</task>
<task id="LOCAL-00026" summary="replaced Algorythm and made it way faster">
<created>1679688274094</created>
<option name="number" value="00026" />
<option name="presentableId" value="LOCAL-00026" />
<option name="project" value="LOCAL" />
<updated>1679688274094</updated>
</task>
<task id="LOCAL-00027" summary="replaced Algorythm and made it way faster">
<created>1679696235787</created>
<option name="number" value="00027" />
<option name="presentableId" value="LOCAL-00027" />
<option name="project" value="LOCAL" />
<updated>1679696235787</updated>
</task>
<task id="LOCAL-00028" summary="Removed whitespaces and changed comments">
<created>1679698431426</created>
<option name="number" value="00028" />
<option name="presentableId" value="LOCAL-00028" />
<option name="project" value="LOCAL" />
<updated>1679698431426</updated>
</task>
<task id="LOCAL-00029" summary="Updaded readme and added compile instructions">
<created>1683227687665</created>
<option name="number" value="00029" />
<option name="presentableId" value="LOCAL-00029" />
<option name="project" value="LOCAL" />
<updated>1683227687665</updated>
</task>
<option name="localTasksCounter" value="30" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State>
<option name="FILTERS">
<map>
<entry key="branch">
<value>
<list>
<option value="master" />
</list>
</value>
</entry>
</map>
</option>
</State>
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="First Creation" />
<MESSAGE value="Just a Test" />
<MESSAGE value="Removing not needed lines" />
<MESSAGE value="Fixed Duplicates in HashMap" />
<MESSAGE value="test" />
<MESSAGE value="fixed A bug where it just randomly crashes and added the ability to delete duplicate files with -d paramater" />
<MESSAGE value="Fixed another Random Crash that happened when a file size is near 0" />
<MESSAGE value="Simplify code in ThreadedCompare.java and added option for debuging with -debug" />
<MESSAGE value="Added Number of files in -d option" />
<MESSAGE value="Added -h / -help option for better usability" />
<MESSAGE value="Rework of README.md" />
<MESSAGE value="Update deletion behavior and fixed file == NULL bug" />
<MESSAGE value="Update README.md according to the new deletion behavior" />
<MESSAGE value="Added -t to tell Sherly the number of Threads it should use" />
<MESSAGE value="Upload Bin" />
<MESSAGE value="Prepare for Aur Package" />
<MESSAGE value="AUR Package instructions" />
<MESSAGE value="Fix MD" />
<MESSAGE value="replaced Algorythm and made it way faster" />
<MESSAGE value="Removed whitespaces and changed comments" />
<MESSAGE value="Updaded readme and added compile instructions" />
<MESSAGE value="Optimized imports" />
<option name="LAST_COMMIT_MESSAGE" value="Optimized imports" />
</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>

View file

@ -1,3 +0,0 @@
Manifest-Version: 1.0
Main-Class: Main

View file

@ -1,32 +1,14 @@
# xxSherly
A fork of [Sherly](https://github.com/BlyDoesCoding/Sherly), (not yet) using [xxHash](https://github.com/Cyan4973/xxHash).
## Introduction
# Sherly
Sherly is a Multithreaded Duplicate File Finder for your Terminal, written in java. You can Easily find duplicate Images, videos as well as any other type of Data. That can be helpful if you run on small storage or just want to keep regular housekeeping.
## Full Usages
## Installation
Install via AUR
```bash
yay -S sherly-git
```
Compile yourself
```bash
git clone https://github.com/BlyDoesCoding/Sherly
cd Sherly
mkdir -p Bin
javac -d Bin src/*.java -Xlint
cd Bin
jar cfe sherly.jar Main ConsoleColors.class Main.class ThreadedCompare.class
#the jar file will be in the Bin Folder
```
## Usage/Examples
```
```console
Usage: sherly -f inputfolder1 inputfolder2 inputfolder3 [options]...
-h / -help show this
@ -35,7 +17,23 @@ Usage: sherly -f inputfolder1 inputfolder2 inputfolder3 [options]...
-t / -threads override default Thread number (default is usually number of cores * 2)
-p / -progress enable progress indicator
-d / -delete delete all dups except one without asking first
-n / -noinput skip all user input
-debug debug stuff
```
## Build
```bash
mvn package
```
## Supported Platforms
| OS | Working | Version |
| :----: |:--------------:|:-------:|
| Linux | Yes | 1.0 |
| Windows 10/11/8/7 | Not yet tested | |
| BSD | Not yet tested | |
## Screenshots
![screenshot](https://github.com/BlyDoesCoding/Sherly/blob/master/Images/screenshot?raw=true)

View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

83
pom.xml Normal file
View file

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.blydoescoding.sherly</groupId>
<artifactId>xxSherly</artifactId>
<version>1.0</version>
<name>xxSherly</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>com.blydoescoding.sherly.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View file

@ -1,15 +0,0 @@
//Just regular Colors to make it a bit prettier
public class ConsoleColors {
// Reset
public static final String RESET = "\033[0m"; // Text Reset
public static final String GREEN_BOLD = "\033[1;32m"; // GREEN
public static final String BLUE_BOLD = "\033[1;34m"; // BLUE
public static final String CYAN_BOLD = "\033[1;36m"; // CYAN
public static final String RED_BOLD = "\033[1;31m"; // RED
}

View file

@ -1,3 +0,0 @@
Manifest-Version: 1.0
Main-Class: Main

View file

@ -1,3 +1,5 @@
package com.blydoescoding.sherly;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@ -10,11 +12,12 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Main {
public class App {
public static int completedThreads = 0;
public static int progress = 0;
public static HashMap<String, List<Path>> fileMap = new HashMap<>();
public static void main(String[] args) throws InterruptedException {
boolean doTheColorThingy = false;
boolean showProgress = false;
@ -23,13 +26,11 @@ public class Main {
boolean recordThreads = false;
int saidThreads = 0;
boolean showDebug = false;
boolean noInput = false;
boolean help = false;
List<String> paths = new ArrayList<>();
for(String i : args)
{
for(String i : args) {
if (recordFolder) {
if(Files.isDirectory(Paths.get(i))) {
paths.add(i);
@ -44,7 +45,6 @@ public class Main {
if (i.equalsIgnoreCase("-f") || i.equalsIgnoreCase("-folder")) { recordFolder = true;}
if (i.equalsIgnoreCase("-t") || i.equalsIgnoreCase("-threads")) { recordThreads = true;}
if (i.equalsIgnoreCase("-d") || i.equalsIgnoreCase("-delete")) { deleteDups = true;}
if (i.equalsIgnoreCase("-n") || i.equalsIgnoreCase("-noinput")) { noInput = true; }
if (i.equalsIgnoreCase("-h") || i.equalsIgnoreCase("-help")) { help = true;}
if (i.equalsIgnoreCase("-debug")) { showDebug = true;}
@ -59,7 +59,6 @@ public class Main {
System.out.println(" -t / -threads override default Thread number (default is usually number of cores * 2)");
System.out.println(" -p / -progress enable progress indicator");
System.out.println(" -d / -delete delete all dups except one without asking first");
System.out.println(" -n / -noinput skip all user input");
System.out.println(" -debug debug stuff");
return;
}
@ -116,15 +115,16 @@ public class Main {
}
}
//Start Multithreading
//sectionedList gives the thread their Assigned Part of Files
ThreadedCompare threadedCompare = new ThreadedCompare(sectionedList);
threadedCompare.start();
}
//this updates if necessary the Progress bar and checks for Finished threads
while (completedThreads < availableThreads) {
TimeUnit.MILLISECONDS.sleep(250);
@ -134,52 +134,51 @@ public class Main {
System.out.print("Progress: " + progress + " / " + filesToBeDone + " | " + (progress * 100 / filesToBeDone) + "%" + "\r");
}
}
ArrayList toRemove = new ArrayList<String>();
for (String md5: fileMap.keySet()) {
if (Main.fileMap.get(md5).size() == 1) {
toRemove.add(md5);
ArrayList<String> toRemove = new ArrayList<String>();
for (String checksum: fileMap.keySet()) {
if (App.fileMap.get(checksum).size() == 1) {
toRemove.add(checksum);
}
}
fileMap.keySet().removeAll(toRemove);
//now everything is finished and the Filemap (hashmap with all Dups) can be printed out in a nice view
//System.out.println(fileMap);
// now everything is finished and the Filemap (hashmap with all Dups) can be printed out in a nice view
for (String md5: fileMap.keySet()) {
for (String checksum: fileMap.keySet()) {
if (doTheColorThingy) {
System.out.println(ConsoleColors.BLUE_BOLD + md5 + ConsoleColors.CYAN_BOLD + " --> " + ConsoleColors.GREEN_BOLD + fileMap.get(md5) + ConsoleColors.RESET);
System.out.println(ConsoleColors.BLUE_BOLD + checksum + ConsoleColors.CYAN_BOLD + " --> " + ConsoleColors.GREEN_BOLD + fileMap.get(checksum) + ConsoleColors.RESET);
} else {
System.out.println(md5 +" --> " + fileMap.get(md5));
System.out.println(checksum +" --> " + fileMap.get(checksum));
}
}
List<Path> allTheFilesWillBeDeleted = new ArrayList<>();
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)) {
if (file != null) {
bytes += file.toFile().length();
}
long bytes = 0;
for (String md5: fileMap.keySet()) {
App.fileMap.get(md5).remove(0);
for (Path file: App.fileMap.get(md5)) {
if (file != null) {
bytes += file.toFile().length();
}
allTheFilesWillBeDeleted.addAll(Main.fileMap.get(md5));
}
allTheFilesWillBeDeleted.addAll(App.fileMap.get(md5));
}
if (deleteDups) {
delete(allTheFilesWillBeDeleted);
} else if (!noInput) {
ask(doTheColorThingy, bytes, allTheFilesWillBeDeleted);
}
if (deleteDups) {
delete(allTheFilesWillBeDeleted);
} else {
ask(doTheColorThingy, bytes, allTheFilesWillBeDeleted);
}
}
//print files and ask user
// print files and ask user
public static void ask(boolean color, long bytes, List<Path> deleteThem) {
if (color) {
System.out.println(ConsoleColors.RED_BOLD + (bytes / 8000000) + " unnecessary MB in " + deleteThem.size() + " Files found, do you want to Delete them? Y / N" + ConsoleColors.RESET);
@ -193,12 +192,12 @@ public class Main {
input.close();
} else if (answer.toLowerCase().contains("n")) {
input.close();
return;
} else {
ask(color, bytes, deleteThem);
}
input.close();
}
public static void delete(List<Path> deleteThem) {

View file

@ -0,0 +1,11 @@
package com.blydoescoding.sherly;
// Just regular Colors to make it a bit prettier
public class ConsoleColors {
public static final String RESET = "\033[0m"; // Text Reset
public static final String GREEN_BOLD = "\033[1;32m"; // GREEN
public static final String BLUE_BOLD = "\033[1;34m"; // BLUE
public static final String CYAN_BOLD = "\033[1;36m"; // CYAN
public static final String RED_BOLD = "\033[1;31m"; // RED
}

View file

@ -1,69 +1,69 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
package com.blydoescoding.sherly;
import java.io.*;
import java.nio.file.Path;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
public class ThreadedCompare extends Thread {
private final List<Path> pathsToCompareTo;
//private HashMap<String, List<Path>> threadFileMap = new HashMap<>();
public ThreadedCompare (List<Path> pathsToCompareTo) {
this.pathsToCompareTo = pathsToCompareTo;
}
@Override
public void run() {
for (Path file : pathsToCompareTo) {
List<Path> fileArray = new ArrayList<>();
assert fileArray != null;
fileArray.add(file);
String MD5;
String checksum;
try {
MD5 = getMD5Sum(file.toFile());
checksum = getChecksum(file.toFile());
} catch (IOException e) {
throw new RuntimeException(e);
}
if (Main.fileMap.containsKey(MD5)) {
fileArray.addAll(Main.fileMap.get(MD5));
Main.fileMap.put(MD5, fileArray);
if (App.fileMap.containsKey(checksum)) {
fileArray.addAll(App.fileMap.get(checksum));
App.fileMap.put(checksum, fileArray);
} else {
Main.fileMap.put(MD5, fileArray);
App.fileMap.put(checksum, fileArray);
}
Main.progress++;
App.progress++;
}
Main.completedThreads++;
App.completedThreads++;
}
//this is used to get the MD5 String of one of the files (one of them is just fine since they both have the same value)
private String getMD5Sum (File file) throws IOException {
private String getChecksum (File file) throws IOException {
MessageDigest messageDigest = null;
try {
messageDigest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
FileInputStream fis = new FileInputStream(file);
FileInputStream inputStream = new FileInputStream(file);
byte[] dataBytes = new byte[1024];
int unread = 0;
while ((unread = fis.read(dataBytes)) != -1) {
while ((unread = inputStream.read(dataBytes)) != -1) {
messageDigest.update(dataBytes, 0, unread);
}
byte[] mdbytes = messageDigest.digest();
StringBuilder sb = new StringBuilder();
for (byte mdbyte : mdbytes) {
sb.append(Integer.toString((mdbyte & 0xff) + 0x100, 16).substring(1));
inputStream.close();
// get digest & create hexadecimal represenation
byte[] digestBytes = messageDigest.digest();
StringBuilder stringBuilder = new StringBuilder();
for (byte digestByte : digestBytes) {
stringBuilder.append(Integer.toString((digestByte & 0xff) + 0x100, 16).substring(1));
}
return sb.toString();
return stringBuilder.toString();
}
}

View file

@ -1,2 +0,0 @@
#!/usr/bin/sh
java -jar /usr/share/java/sherly/sherly.jar $@