From 6981345467dce125f9e484dafa7bfdcdbd211bf1 Mon Sep 17 00:00:00 2001 From: Maschell Date: Wed, 24 Apr 2019 13:53:07 +0200 Subject: [PATCH] Force the use "/" as the path separator internally --- src/de/mas/wiiu/jnus/NUSTitle.java | 2 +- .../mas/wiiu/jnus/entities/fst/FSTEntry.java | 2 +- .../implementations/woomy/WoomyParser.java | 4 ++-- .../wud/parser/WUDInfoParser.java | 6 +++--- src/de/mas/wiiu/jnus/utils/FSTUtils.java | 21 ++++++++++--------- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/de/mas/wiiu/jnus/NUSTitle.java b/src/de/mas/wiiu/jnus/NUSTitle.java index 6d67e26..04b841e 100644 --- a/src/de/mas/wiiu/jnus/NUSTitle.java +++ b/src/de/mas/wiiu/jnus/NUSTitle.java @@ -126,7 +126,7 @@ public class NUSTitle { .filter(e -> allowNotInPackage || !e.isNotInPackage()) // .flatMap(e -> { if (!e.isDir()) { - if (p.matcher(e.getFullPath().replace("/", File.separator)).matches()) { + if (p.matcher(e.getFullPath()).matches()) { return Stream.of(e); } else { return Stream.empty(); diff --git a/src/de/mas/wiiu/jnus/entities/fst/FSTEntry.java b/src/de/mas/wiiu/jnus/entities/fst/FSTEntry.java index baf2add..e1fb978 100644 --- a/src/de/mas/wiiu/jnus/entities/fst/FSTEntry.java +++ b/src/de/mas/wiiu/jnus/entities/fst/FSTEntry.java @@ -113,7 +113,7 @@ public class FSTEntry { private StringBuilder getPathInternal() { if (parent.isPresent()) { FSTEntry par = parent.get(); - return par.getPathInternal().append(par.getFilename()).append(File.separator); + return par.getPathInternal().append(par.getFilename()).append('/'); } return new StringBuilder(); } diff --git a/src/de/mas/wiiu/jnus/implementations/woomy/WoomyParser.java b/src/de/mas/wiiu/jnus/implementations/woomy/WoomyParser.java index a7524db..7813f04 100644 --- a/src/de/mas/wiiu/jnus/implementations/woomy/WoomyParser.java +++ b/src/de/mas/wiiu/jnus/implementations/woomy/WoomyParser.java @@ -61,7 +61,7 @@ public final class WoomyParser { ZipEntry metaFile = zipFile.getEntry(Settings.WOOMY_METADATA_FILENAME); if (metaFile == null) { log.info("No meta "); - throw new FileNotFoundException("No \""+ Settings.WOOMY_METADATA_FILENAME +"\" inside woomy was found."); + throw new FileNotFoundException("No \"" + Settings.WOOMY_METADATA_FILENAME + "\" inside woomy was found."); } WoomyMeta meta = WoomyMetaParser.parseMeta(zipFile.getInputStream(metaFile)); @@ -93,7 +93,7 @@ public final class WoomyParser { String entryName = entry.getName(); Matcher matcher = pattern.matcher(entryName); if (matcher.matches()) { - String[] tokens = entryName.replace(File.separator, "\\").split("[\\\\|/]"); // We only want the filename! + String[] tokens = entryName.replace(File.separator, "/").split("[\\\\|/]"); // We only want the filename! String filename = tokens[tokens.length - 1]; result.put(filename.toLowerCase(Locale.ENGLISH), entry); } diff --git a/src/de/mas/wiiu/jnus/implementations/wud/parser/WUDInfoParser.java b/src/de/mas/wiiu/jnus/implementations/wud/parser/WUDInfoParser.java index b2ea0f6..744ca00 100644 --- a/src/de/mas/wiiu/jnus/implementations/wud/parser/WUDInfoParser.java +++ b/src/de/mas/wiiu/jnus/implementations/wud/parser/WUDInfoParser.java @@ -134,11 +134,11 @@ public final class WUDInfoParser { for (val dirChilden : siFST.getRoot().getDirChildren()) { // The SI partition contains the tmd, cert and tik for every GM partition. - byte[] rawTIK = getFSTEntryAsByte(dirChilden.getFullPath() + File.separator + WUD_TICKET_FILENAME, siPartitionOffset, headerSize, siFST, + byte[] rawTIK = getFSTEntryAsByte(dirChilden.getFullPath() + '/' + WUD_TICKET_FILENAME, siPartitionOffset, headerSize, siFST, wudInfo.getWUDDiscReader(), wudInfo.getTitleKey()); - byte[] rawTMD = getFSTEntryAsByte(dirChilden.getFullPath() + File.separator + WUD_TMD_FILENAME, siPartitionOffset, headerSize, siFST, + byte[] rawTMD = getFSTEntryAsByte(dirChilden.getFullPath() + '/' + WUD_TMD_FILENAME, siPartitionOffset, headerSize, siFST, wudInfo.getWUDDiscReader(), wudInfo.getTitleKey()); - byte[] rawCert = getFSTEntryAsByte(dirChilden.getFullPath() + File.separator + WUD_CERT_FILENAME, siPartitionOffset, headerSize, siFST, + byte[] rawCert = getFSTEntryAsByte(dirChilden.getFullPath() + '/' + WUD_CERT_FILENAME, siPartitionOffset, headerSize, siFST, wudInfo.getWUDDiscReader(), wudInfo.getTitleKey()); String partitionName = "GM" + Utils.ByteArrayToString(Arrays.copyOfRange(rawTIK, 0x1DC, 0x1DC + 0x08)); diff --git a/src/de/mas/wiiu/jnus/utils/FSTUtils.java b/src/de/mas/wiiu/jnus/utils/FSTUtils.java index be1b770..cab7582 100644 --- a/src/de/mas/wiiu/jnus/utils/FSTUtils.java +++ b/src/de/mas/wiiu/jnus/utils/FSTUtils.java @@ -30,14 +30,14 @@ import lombok.val; public class FSTUtils { public static Optional getFSTEntryByFullPath(FSTEntry root, String givenFullPath) { - String fullPath = givenFullPath.replace("/", File.separator); - if (!fullPath.startsWith(File.separator)) { - fullPath = File.separator + fullPath; + String fullPath = givenFullPath.replace(File.separator, "/"); + if (!fullPath.startsWith("/")) { + fullPath = "/" + fullPath; } String dirPath = FilenameUtils.getFullPathNoEndSeparator(fullPath); Optional pathOpt = Optional.of(root); - if (!dirPath.equals(File.separator)) { + if (!dirPath.equals("/")) { pathOpt = getFileEntryDir(root, dirPath); } @@ -47,15 +47,16 @@ public class FSTUtils { } public static Optional getFileEntryDir(FSTEntry curEntry, String string) { - string = string.replace("/", File.separator); + string = string.replace(File.separator, "/"); - if (!string.endsWith(File.separator)) { - string += File.separator; + // We add the "/" at the end so we don't get false results when using the "startWith" function. + if (!string.endsWith("/")) { + string += "/"; } for (val curChild : curEntry.getDirChildren()) { String compareTo = curChild.getFullPath(); - if (!compareTo.endsWith(File.separator)) { - compareTo += File.separator; + if (!compareTo.endsWith("/")) { + compareTo += "/"; } if (string.startsWith(compareTo)) { if (string.equals(compareTo)) { @@ -107,7 +108,7 @@ public class FSTUtils { .filter(e -> allowNotInPackage || !e.isNotInPackage()) // .flatMap(e -> { if (!e.isDir()) { - if (p.matcher(e.getFullPath().replace("/", File.separator)).matches()) { + if (p.matcher(e.getFullPath()).matches()) { return Stream.of(e); } else { return Stream.empty();