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:
parent
368646145d
commit
1d60bf6956
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user