From 654e2f38f7b9001c2d65069ab170d8f7b5762aa7 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 16 Dec 2018 15:21:16 +0100 Subject: [PATCH] Ignore cases in filenames, EXT4 is case sensitive... --- .../implementations/NUSDataProviderLocal.java | 50 +++++++++++-------- src/de/mas/wiiu/jnus/utils/FileUtils.java | 15 ++++++ 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/de/mas/wiiu/jnus/implementations/NUSDataProviderLocal.java b/src/de/mas/wiiu/jnus/implementations/NUSDataProviderLocal.java index ba99ab7..1836068 100644 --- a/src/de/mas/wiiu/jnus/implementations/NUSDataProviderLocal.java +++ b/src/de/mas/wiiu/jnus/implementations/NUSDataProviderLocal.java @@ -26,6 +26,7 @@ import java.nio.file.Files; import de.mas.wiiu.jnus.NUSTitle; import de.mas.wiiu.jnus.Settings; import de.mas.wiiu.jnus.entities.content.Content; +import de.mas.wiiu.jnus.utils.FileUtils; import de.mas.wiiu.jnus.utils.StreamUtils; import lombok.Getter; import lombok.extern.java.Log; @@ -45,9 +46,9 @@ public final class NUSDataProviderLocal extends NUSDataProvider { @Override public InputStream getInputStreamFromContent(Content content, long offset) throws IOException { - File filepath = new File(getFilePathOnDisk(content)); - if (!filepath.exists()) { - String errormsg = "Couldn't open \"" + filepath + "\", file does not exist"; + File filepath = FileUtils.getFileIgnoringFilenameCases(getLocalPath(), content.getFilename()); + if (filepath == null) { + String errormsg = "Couldn't open \"" + getLocalPath() + File.separator + content.getFilename() + "\", file does not exist"; log.warning(errormsg); throw new FileNotFoundException(errormsg); } @@ -58,38 +59,47 @@ public final class NUSDataProviderLocal extends NUSDataProvider { @Override public byte[] getContentH3Hash(Content content) throws IOException { - String h3Path = getLocalPath() + File.separator + String.format("%08X.h3", content.getID()); - File h3File = new File(h3Path); - if (!h3File.exists()) { - String errormsg = "Couldn't open \"" + h3Path + "\", file does not exist"; + String h3Filename = String.format("%08X.%s", content.getID(), Settings.H3_EXTENTION); + File filepath = FileUtils.getFileIgnoringFilenameCases(getLocalPath(), h3Filename); + if (filepath == null) { + String errormsg = "Couldn't open \"" + getLocalPath() + File.separator + h3Filename + "\", file does not exist"; log.warning(errormsg); return new byte[0]; } - return Files.readAllBytes(h3File.toPath()); + return Files.readAllBytes(filepath.toPath()); } @Override public byte[] getRawTMD() throws IOException { - String inputPath = getLocalPath(); - String tmdPath = inputPath + File.separator + Settings.TMD_FILENAME; - File tmdFile = new File(tmdPath); - return Files.readAllBytes(tmdFile.toPath()); + File file = FileUtils.getFileIgnoringFilenameCases(getLocalPath(), Settings.TMD_FILENAME); + if (file == null || file.exists()) { + String errormsg = "Couldn't open \"" + getLocalPath() + File.separator + Settings.TMD_FILENAME + "\", file does not exist"; + log.warning(errormsg); + throw new FileNotFoundException(errormsg); + } + return Files.readAllBytes(file.toPath()); } @Override public byte[] getRawTicket() throws IOException { - String inputPath = getLocalPath(); - String ticketPath = inputPath + File.separator + Settings.TICKET_FILENAME; - File ticketFile = new File(ticketPath); - return Files.readAllBytes(ticketFile.toPath()); + File file = FileUtils.getFileIgnoringFilenameCases(getLocalPath(), Settings.TICKET_FILENAME); + if (file == null || file.exists()) { + String errormsg = "Couldn't open \"" + getLocalPath() + File.separator + Settings.TICKET_FILENAME + "\", file does not exist"; + log.warning(errormsg); + throw new FileNotFoundException(errormsg); + } + return Files.readAllBytes(file.toPath()); } @Override public byte[] getRawCert() throws IOException { - String inputPath = getLocalPath(); - String certPath = inputPath + File.separator + Settings.CERT_FILENAME; - File certFile = new File(certPath); - return Files.readAllBytes(certFile.toPath()); + File file = FileUtils.getFileIgnoringFilenameCases(getLocalPath(), Settings.CERT_FILENAME); + if (file == null || file.exists()) { + String errormsg = "Couldn't open \"" + getLocalPath() + File.separator + Settings.CERT_FILENAME + "\", file does not exist"; + log.warning(errormsg); + throw new FileNotFoundException(errormsg); + } + return Files.readAllBytes(file.toPath()); } @Override diff --git a/src/de/mas/wiiu/jnus/utils/FileUtils.java b/src/de/mas/wiiu/jnus/utils/FileUtils.java index 1485f49..d9f9249 100644 --- a/src/de/mas/wiiu/jnus/utils/FileUtils.java +++ b/src/de/mas/wiiu/jnus/utils/FileUtils.java @@ -17,6 +17,7 @@ package de.mas.wiiu.jnus.utils; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -94,4 +95,18 @@ public final class FileUtils { tempFile.renameTo(outputFile); } + public static File getFileIgnoringFilenameCases(String folder, String filename) { + File filepath = new File(folder + File.separator + filename); + if (!filepath.exists()) { + // Try to find it ignoring cases. + File[] filesIngoringCases = new File(folder).listFiles(f -> f.getName().equalsIgnoreCase(filename)); + if (filesIngoringCases.length == 1 && !filesIngoringCases[0].isDirectory()) { + return filesIngoringCases[0].getAbsoluteFile(); + } else { + return null; + } + } + return filepath; + } + }