mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-30 01:00:11 +02:00
Changed up name sanitization a bit
This commit is contained in:
@@ -20,7 +20,7 @@ import org.jsoup.HttpStatusException;
|
|||||||
|
|
||||||
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
|
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
|
||||||
import com.rarchives.ripme.utils.Utils;
|
import com.rarchives.ripme.utils.Utils;
|
||||||
import com.rarchives.ripme.ripper.AbstractRipper;
|
import static java.lang.Math.toIntExact;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thread for downloading files.
|
* Thread for downloading files.
|
||||||
@@ -62,11 +62,6 @@ class DownloadFileThread extends Thread {
|
|||||||
this.cookies = cookies;
|
this.cookies = cookies;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File sanitizeSaveAs(File fileToSan) {
|
|
||||||
String fileName = fileToSan.getName().replaceAll("[\\\\/:*?\"<>|]", "_");
|
|
||||||
return new File(saveAs.getParentFile().getAbsolutePath() + File.separator + fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to download the file. Retries as needed.
|
* Attempts to download the file. Retries as needed.
|
||||||
@@ -74,7 +69,7 @@ class DownloadFileThread extends Thread {
|
|||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
// First thing we make sure the file name doesn't have any illegal chars in it
|
// First thing we make sure the file name doesn't have any illegal chars in it
|
||||||
saveAs = sanitizeSaveAs(saveAs);
|
saveAs = new File(saveAs.getParentFile().getAbsolutePath() + File.separator + Utils.sanitizeSaveAs(saveAs.getName()));
|
||||||
long fileSize = 0;
|
long fileSize = 0;
|
||||||
int bytesTotal = 0;
|
int bytesTotal = 0;
|
||||||
int bytesDownloaded = 0;
|
int bytesDownloaded = 0;
|
||||||
@@ -222,14 +217,16 @@ class DownloadFileThread extends Thread {
|
|||||||
String[] saveAsSplit = saveAs.getName().split("\\.");
|
String[] saveAsSplit = saveAs.getName().split("\\.");
|
||||||
// Get the file extension so when we shorten the file name we don't cut off the file extension
|
// Get the file extension so when we shorten the file name we don't cut off the file extension
|
||||||
String fileExt = saveAsSplit[saveAsSplit.length - 1];
|
String fileExt = saveAsSplit[saveAsSplit.length - 1];
|
||||||
// The max limit for filenames on Linux with Ext3/4 is 255 bytes, on windows it's 256 chars so rather than
|
// The max limit for filenames on Linux with Ext3/4 is 255 bytes
|
||||||
// bother with code with both platforms we just cut the file name down to 254 chars
|
|
||||||
logger.info(saveAs.getName().substring(0, 254 - fileExt.length()) + fileExt);
|
logger.info(saveAs.getName().substring(0, 254 - fileExt.length()) + fileExt);
|
||||||
String filename = saveAs.getName().substring(0, 254 - fileExt.length()) + "." + fileExt;
|
String filename = saveAs.getName().substring(0, 254 - fileExt.length()) + "." + fileExt;
|
||||||
// We can't just use the new file name as the saveAs because the file name doesn't include the
|
// We can't just use the new file name as the saveAs because the file name doesn't include the
|
||||||
// users save path, so we get the user save path from the old saveAs
|
// users save path, so we get the user save path from the old saveAs
|
||||||
saveAs = new File(saveAs.getParentFile().getAbsolutePath() + "/" + filename);
|
saveAs = new File(saveAs.getParentFile().getAbsolutePath() + File.separator + filename);
|
||||||
fos = new FileOutputStream(saveAs);
|
fos = new FileOutputStream(saveAs);
|
||||||
|
} else if (saveAs.getAbsolutePath().length() > 259 && Utils.isWindows()) {
|
||||||
|
// This if is for when the file path has gone above 260 chars which windows does not allow
|
||||||
|
fos = new FileOutputStream(Utils.shortenSaveAsWindows(saveAs.getParentFile().getPath(), saveAs.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user