Skip to content

Commit

Permalink
Merge pull request #7 from FlyingWolFox/dev
Browse files Browse the repository at this point in the history
Updated variable names and README
  • Loading branch information
FlyingWolFox authored Apr 12, 2020
2 parents dc9c0c3 + 2b8252b commit 4d4e329
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
16 changes: 8 additions & 8 deletions FileInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FileInfo implements Comparable<FileInfo> {
private File file; // file information
private String name; // filename
private Path path; // file path
private String md5; // md5 hash
private String hash;
private Directory dir; // directory that the file is in
private int num; // the file id in this directory
private boolean repeated; // flag to be used in internal repetion handling
Expand All @@ -40,16 +40,16 @@ public FileInfo(File file, Directory dir) {
this.dir = dir;
this.name = file.getName();
try {
calculateMD5();
calculateHash();
} catch (NoSuchAlgorithmException | IOException e) {
e.printStackTrace();
}
y++;
System.out.println(" MD5: " + md5);
System.out.println(" MD5: " + hash);
}

// calculates the md5 hash of this file
public void calculateMD5() throws NoSuchAlgorithmException, IOException {
public void calculateHash() throws NoSuchAlgorithmException, IOException {
InputStream fis = new FileInputStream(path.toString());

byte[] buffer = new byte[1024];
Expand All @@ -75,7 +75,7 @@ public void calculateMD5() throws NoSuchAlgorithmException, IOException {
sb.append(Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1));
}

md5 = sb.toString();
hash = sb.toString();
}

/**
Expand All @@ -95,8 +95,8 @@ public Path getPath() {
/**
* @return the md5 hash of this file
*/
public String getMD5() {
return this.md5;
public String getHash() {
return this.hash;
}

/**
Expand Down Expand Up @@ -148,7 +148,7 @@ public void setRepeated() {
* Used to compare files to find repetions
*/
public int compareTo(FileInfo file) {
return md5.compareTo(file.getMD5());
return hash.compareTo(file.getHash());
}

}
3 changes: 0 additions & 3 deletions Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public class Main {
private ArrayList<Directory> dirs; // where all directories are stored
private ArrayList<FileInfo> files; // where all files will be stored for comparasion
private ArrayList<Path> subfolders; // stores the subfolders of the Results folder
private ArrayList<Path> internalRepetions; // used in internal repetion handling, this
// still in the works
private HashMap<Integer, Character> letters; // used to translate the directory number in a letter to use in the
// filenames

Expand All @@ -33,7 +31,6 @@ public Main(String[] args) {
dirs = new ArrayList<Directory>();
files = new ArrayList<FileInfo>();
subfolders = new ArrayList<Path>();
internalRepetions = new ArrayList<Path>(); // not used yet
letters = new HashMap<Integer, Character>(26);
setLetters(); // fills the HashMap

Expand Down
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Theres a libray in the internet called FastMD5. It's a fast and super optimizade

3. **There's a way to rename them quickly?**

You can use my [renamer tool here](https://github.com/FlyingWolFox/Duplicate-Finder-Renamer/)) that is made to work with this tool, use another tool like Bulk Renaming Utility or a shell script/batch file
You can use my [renamer tool here](https://github.com/FlyingWolFox/Duplicate-Finder-Renamer/) that is made to work with this tool, use another tool like Bulk Renaming Utility or a shell script/batch file

4. **The tools rise an exception/error, what should I do?**

Expand Down Expand Up @@ -94,21 +94,16 @@ You can help createing an Issue or a Pull Request, I'll look into it, I promise!

3. **I want to put FastMD5 in the code, where I change?**

The method `calculateMD5()` in the ROM class is responsible to calculate the MD5 hash so any modifications in the hash calculation goes there. The method just change the `String md5` variable to contain the hash. However I don't know how to implement FastMD5, but I may try in the future.
The method `calculateHash()` in the FileInfo class is responsible to calculate the hash so any modifications in the hash calculation goes there. The method changes the `String hash` variable to contain the hash.

4. **Why not use other hashing algorithm or use multiple ones?**

I choosed MD5 because is relatively colision safe when looking for repeated files and it's fast. There was other alternatives, like SHA-1, that's fast too, but MD5 was good enough. Other hashes like SHA-2 or SHA-3 weren't considered because they're really slow. Other non-security algorithms weren't considered because I didn't know they existed until yesterday :D You can put any hash you want in the code and it'll work. I'm thinking of changing `calculateMD5()` to `calculateHash()` to make the use of other algorithms easier
I choosed MD5 because is relatively colision safe when looking for repeated files and it's fast. There was other alternatives, like SHA-1, that's fast too, but MD5 was good enough. Other hashes like SHA-2 or SHA-3 weren't considered because they're really slow. Other non-security algorithms weren't considered because I didn't know they existed until sometime ago :D You can put any hash you want in the code and it'll work.

5. **Everything is in the Main class in a weird way, how the code is designed?**

This is because this tool is more like a script, so things went to the Main classes. The code works basically in the constructors, that does almost everything. This is just to be pratic, feel free to change it (and even submmit a Pull Request!)

## Future plans

This tool isn't finished, not for me at least, so I'm planning to do:

- [ ] Implement a compressed archived comparer
- [ ] Better verbosity

Also I'm planning to make a GUI version of this tool (when I learn how to make GUIs) to be even better! It'll be in another repository tho. I'll update here when I finish it
I'm planning to make a GUI version of this tool (when I learn how to make GUIs) to be even better! It'll be in another repository tho. I'll update here when I finish it

0 comments on commit 4d4e329

Please sign in to comment.