Ignore cases in filenames, EXT4 is case sensitive...

This commit is contained in:
Maschell 2018-12-16 15:21:16 +01:00
parent f0306b8cce
commit 654e2f38f7
2 changed files with 45 additions and 20 deletions

View File

@ -26,6 +26,7 @@ import java.nio.file.Files;
import de.mas.wiiu.jnus.NUSTitle; import de.mas.wiiu.jnus.NUSTitle;
import de.mas.wiiu.jnus.Settings; import de.mas.wiiu.jnus.Settings;
import de.mas.wiiu.jnus.entities.content.Content; import de.mas.wiiu.jnus.entities.content.Content;
import de.mas.wiiu.jnus.utils.FileUtils;
import de.mas.wiiu.jnus.utils.StreamUtils; import de.mas.wiiu.jnus.utils.StreamUtils;
import lombok.Getter; import lombok.Getter;
import lombok.extern.java.Log; import lombok.extern.java.Log;
@ -45,9 +46,9 @@ public final class NUSDataProviderLocal extends NUSDataProvider {
@Override @Override
public InputStream getInputStreamFromContent(Content content, long offset) throws IOException { public InputStream getInputStreamFromContent(Content content, long offset) throws IOException {
File filepath = new File(getFilePathOnDisk(content)); File filepath = FileUtils.getFileIgnoringFilenameCases(getLocalPath(), content.getFilename());
if (!filepath.exists()) { if (filepath == null) {
String errormsg = "Couldn't open \"" + filepath + "\", file does not exist"; String errormsg = "Couldn't open \"" + getLocalPath() + File.separator + content.getFilename() + "\", file does not exist";
log.warning(errormsg); log.warning(errormsg);
throw new FileNotFoundException(errormsg); throw new FileNotFoundException(errormsg);
} }
@ -58,38 +59,47 @@ public final class NUSDataProviderLocal extends NUSDataProvider {
@Override @Override
public byte[] getContentH3Hash(Content content) throws IOException { public byte[] getContentH3Hash(Content content) throws IOException {
String h3Path = getLocalPath() + File.separator + String.format("%08X.h3", content.getID()); String h3Filename = String.format("%08X.%s", content.getID(), Settings.H3_EXTENTION);
File h3File = new File(h3Path); File filepath = FileUtils.getFileIgnoringFilenameCases(getLocalPath(), h3Filename);
if (!h3File.exists()) { if (filepath == null) {
String errormsg = "Couldn't open \"" + h3Path + "\", file does not exist"; String errormsg = "Couldn't open \"" + getLocalPath() + File.separator + h3Filename + "\", file does not exist";
log.warning(errormsg); log.warning(errormsg);
return new byte[0]; return new byte[0];
} }
return Files.readAllBytes(h3File.toPath()); return Files.readAllBytes(filepath.toPath());
} }
@Override @Override
public byte[] getRawTMD() throws IOException { public byte[] getRawTMD() throws IOException {
String inputPath = getLocalPath(); File file = FileUtils.getFileIgnoringFilenameCases(getLocalPath(), Settings.TMD_FILENAME);
String tmdPath = inputPath + File.separator + Settings.TMD_FILENAME; if (file == null || file.exists()) {
File tmdFile = new File(tmdPath); String errormsg = "Couldn't open \"" + getLocalPath() + File.separator + Settings.TMD_FILENAME + "\", file does not exist";
return Files.readAllBytes(tmdFile.toPath()); log.warning(errormsg);
throw new FileNotFoundException(errormsg);
}
return Files.readAllBytes(file.toPath());
} }
@Override @Override
public byte[] getRawTicket() throws IOException { public byte[] getRawTicket() throws IOException {
String inputPath = getLocalPath(); File file = FileUtils.getFileIgnoringFilenameCases(getLocalPath(), Settings.TICKET_FILENAME);
String ticketPath = inputPath + File.separator + Settings.TICKET_FILENAME; if (file == null || file.exists()) {
File ticketFile = new File(ticketPath); String errormsg = "Couldn't open \"" + getLocalPath() + File.separator + Settings.TICKET_FILENAME + "\", file does not exist";
return Files.readAllBytes(ticketFile.toPath()); log.warning(errormsg);
throw new FileNotFoundException(errormsg);
}
return Files.readAllBytes(file.toPath());
} }
@Override @Override
public byte[] getRawCert() throws IOException { public byte[] getRawCert() throws IOException {
String inputPath = getLocalPath(); File file = FileUtils.getFileIgnoringFilenameCases(getLocalPath(), Settings.CERT_FILENAME);
String certPath = inputPath + File.separator + Settings.CERT_FILENAME; if (file == null || file.exists()) {
File certFile = new File(certPath); String errormsg = "Couldn't open \"" + getLocalPath() + File.separator + Settings.CERT_FILENAME + "\", file does not exist";
return Files.readAllBytes(certFile.toPath()); log.warning(errormsg);
throw new FileNotFoundException(errormsg);
}
return Files.readAllBytes(file.toPath());
} }
@Override @Override

View File

@ -17,6 +17,7 @@
package de.mas.wiiu.jnus.utils; package de.mas.wiiu.jnus.utils;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -94,4 +95,18 @@ public final class FileUtils {
tempFile.renameTo(outputFile); 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;
}
} }