1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-31 17:42:11 +02:00

shortenSaveAsWindows now uses java.nio

This commit is contained in:
soloturn
2022-01-03 14:02:19 +01:00
parent fca100cd25
commit ffa11e8aa7
3 changed files with 8 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ import java.net.HttpURLConnection;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@@ -237,7 +238,7 @@ class DownloadFileThread extends Thread {
} else if (saveAs.getAbsolutePath().length() > 259 && Utils.isWindows()) { } else if (saveAs.getAbsolutePath().length() > 259 && Utils.isWindows()) {
// This if is for when the file path has gone above 260 chars which windows does // This if is for when the file path has gone above 260 chars which windows does
// not allow // not allow
fos = new FileOutputStream( fos = Files.newOutputStream(
Utils.shortenSaveAsWindows(saveAs.getParentFile().getPath(), saveAs.getName())); Utils.shortenSaveAsWindows(saveAs.getParentFile().getPath(), saveAs.getName()));
} }
} }

View File

@@ -891,7 +891,7 @@ public class Utils {
return fileNameToSan.replaceAll("[\\\\/:*?\"<>|]", "_"); return fileNameToSan.replaceAll("[\\\\/:*?\"<>|]", "_");
} }
public static File shortenSaveAsWindows(String ripsDirPath, String fileName) throws FileNotFoundException { public static Path shortenSaveAsWindows(String ripsDirPath, String fileName) throws FileNotFoundException {
LOGGER.error("The filename " + fileName + " is to long to be saved on this file system."); LOGGER.error("The filename " + fileName + " is to long to be saved on this file system.");
LOGGER.info("Shortening filename"); LOGGER.info("Shortening filename");
String fullPath = ripsDirPath + File.separator + fileName; String fullPath = ripsDirPath + File.separator + fileName;
@@ -909,7 +909,7 @@ public class Utils {
fullPath = fullPath.substring(0, 259 - pathLength - fileExt.length() + 1) + "." + fileExt; fullPath = fullPath.substring(0, 259 - pathLength - fileExt.length() + 1) + "." + fileExt;
LOGGER.info(fullPath); LOGGER.info(fullPath);
LOGGER.info(fullPath.length()); LOGGER.info(fullPath.length());
return new File(fullPath); return Paths.get(fullPath);
} }
} }

View File

@@ -1,7 +1,8 @@
package com.rarchives.ripme.tst; package com.rarchives.ripme.tst;
import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import com.rarchives.ripme.utils.Utils; import com.rarchives.ripme.utils.Utils;
@@ -60,8 +61,8 @@ public class UtilsTest {
public void testShortenFileNameWindows() throws FileNotFoundException { public void testShortenFileNameWindows() throws FileNotFoundException {
String filename = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff.png"; String filename = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff.png";
// Test filename shortening for windows // Test filename shortening for windows
File f = Utils.shortenSaveAsWindows("D:/rips/test/reddit/deep", filename); Path f = Utils.shortenSaveAsWindows("D:/rips/test/reddit/deep", filename);
Assertions.assertEquals(new File( Assertions.assertEquals(Paths.get(
"D:/rips/test/reddit/deep/ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff.png"), "D:/rips/test/reddit/deep/ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff.png"),
f); f);
} }