From 6fb73418734b47f26a6b212eb31bae62394a866b Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Tue, 12 Nov 2019 16:37:14 -0500 Subject: [PATCH] Fixed path name issues on windows --- src/main/java/com/rarchives/ripme/utils/Utils.java | 6 ++---- src/test/java/com/rarchives/ripme/tst/UtilsTest.java | 8 +++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index 98ed8895..a009c7a1 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -870,8 +870,6 @@ public class Utils { // How long the path without the file name is int pathLength = ripsDirPath.length(); int fileNameLength = fileName.length(); - LOGGER.info(pathLength); - LOGGER.info(fileNameLength); if (pathLength == 260) { // We've reached the max length, there's nothing more we can do throw new FileNotFoundException("File path is too long for this OS"); @@ -881,8 +879,8 @@ public class Utils { // file extension String fileExt = saveAsSplit[saveAsSplit.length - 1]; // The max limit for paths on Windows is 260 chars - LOGGER.info(fullPath.substring(0, 260 - pathLength - fileExt.length() + 1) + "." + fileExt); - fullPath = fullPath.substring(0, 260 - pathLength - fileExt.length() + 1) + "." + fileExt; + LOGGER.info(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.length()); return new File(fullPath); diff --git a/src/test/java/com/rarchives/ripme/tst/UtilsTest.java b/src/test/java/com/rarchives/ripme/tst/UtilsTest.java index 59bb5d3b..d87eca55 100644 --- a/src/test/java/com/rarchives/ripme/tst/UtilsTest.java +++ b/src/test/java/com/rarchives/ripme/tst/UtilsTest.java @@ -7,10 +7,12 @@ import java.util.Arrays; import com.rarchives.ripme.utils.Utils; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class UtilsTest { - public void testGetEXTFromMagic() { + public void testGetEXTFromMagic() + { Assertions.assertEquals("jpeg", Utils.getEXTFromMagic(new byte[] { -1, -40, -1, -37, 0, 0, 0, 0 })); Assertions.assertEquals("png", Utils.getEXTFromMagic(new byte[] { -119, 80, 78, 71, 13, 0, 0, 0 })); } @@ -44,13 +46,13 @@ public class UtilsTest { public void testBetween() { Assertions.assertEquals(Arrays.asList(" is a "), Utils.between("This is a test", "This", "test")); } - + @Test public void testShortenFileNameWindows() throws FileNotFoundException { String filename = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff.png"; // Test filename shortening for windows File f = Utils.shortenSaveAsWindows("D:/rips/test/reddit/deep", filename); Assertions.assertEquals(new File( - "D:/rips/test/reddit/deep/fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff.png"), + "D:/rips/test/reddit/deep/ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff.png"), f); }