Added a fuzzyExist func to check if a file exist when we don't know it's extension (For use with rippers that use getFileExtFromMIME)

This commit is contained in:
cyian-1756 2018-07-22 19:31:11 -04:00
parent 368646145d
commit 1d60bf6956
2 changed files with 23 additions and 1 deletions

View File

@ -79,7 +79,7 @@ class DownloadFileThread extends Thread {
observer.downloadErrored(url, "Download interrupted");
return;
}
if (saveAs.exists() && !observer.tryResumeDownload()) {
if (saveAs.exists() && !observer.tryResumeDownload() || Utils.fuzzyExists(new File(saveAs.getParent()), saveAs.getName())) {
if (Utils.getConfigBoolean("file.overwrite", false)) {
logger.info("[!] Deleting existing file" + prettySaveAs);
saveAs.delete();

View File

@ -741,4 +741,26 @@ public class Utils {
return null;
}
// Checks if a file exists ignoring it's extension.
// Code from: https://stackoverflow.com/a/17698068
public static boolean fuzzyExists(File folder, String fileName) {
if (!folder.exists()) {
return false;
}
File[] listOfFiles = folder.listFiles();
if (listOfFiles == null) {
return false;
}
for (File file : listOfFiles) {
if (file.isFile()) {
String[] filename = file.getName().split("\\.(?=[^\\.]+$)"); //split filename from it's extension
if(filename[0].equalsIgnoreCase(fileName)) {
return true;
}
}
}
return false;
}
}