From f0306b8cce68ceff97ca1b84bf7688aaaec631ff Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 16 Dec 2018 15:03:46 +0100 Subject: [PATCH] Add warnings when files couldn't be found. --- src/de/mas/wiiu/jnus/DecryptionService.java | 6 ++++++ .../wiiu/jnus/implementations/NUSDataProviderLocal.java | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/de/mas/wiiu/jnus/DecryptionService.java b/src/de/mas/wiiu/jnus/DecryptionService.java index 013e62d..07e0fe7 100644 --- a/src/de/mas/wiiu/jnus/DecryptionService.java +++ b/src/de/mas/wiiu/jnus/DecryptionService.java @@ -166,6 +166,11 @@ public final class DecryptionService { NUSDataProvider dataProvider = getNUSTitle().getDataProvider(); InputStream in = dataProvider.getInputStreamFromContent(c, fileOffsetBlock); + if (in == null) { + String errormsg = "Failed to open the content " + c.getFilename() + " as input stream."; + log.warning(errormsg); + throw new FileNotFoundException(errormsg); + } try { decryptFSTEntryFromStreams(in, outputStream, fileSize, fileOffset, c); @@ -209,6 +214,7 @@ public final class DecryptionService { if (content.isHashed()) { NUSDataProvider dataProvider = getNUSTitle().getDataProvider(); byte[] h3 = dataProvider.getContentH3Hash(content); + nusdecryption.decryptFileStreamHashed(inputStream, outputStream, size, offset, (short) contentIndex, h3); } else { nusdecryption.decryptFileStream(inputStream, outputStream, size, (short) contentIndex, content.getSHA2Hash(), encryptedFileSize); diff --git a/src/de/mas/wiiu/jnus/implementations/NUSDataProviderLocal.java b/src/de/mas/wiiu/jnus/implementations/NUSDataProviderLocal.java index 97bb740..ba99ab7 100644 --- a/src/de/mas/wiiu/jnus/implementations/NUSDataProviderLocal.java +++ b/src/de/mas/wiiu/jnus/implementations/NUSDataProviderLocal.java @@ -18,6 +18,7 @@ package de.mas.wiiu.jnus.implementations; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; @@ -27,7 +28,9 @@ import de.mas.wiiu.jnus.Settings; import de.mas.wiiu.jnus.entities.content.Content; import de.mas.wiiu.jnus.utils.StreamUtils; import lombok.Getter; +import lombok.extern.java.Log; +@Log public final class NUSDataProviderLocal extends NUSDataProvider { @Getter private final String localPath; @@ -44,7 +47,9 @@ public final class NUSDataProviderLocal extends NUSDataProvider { public InputStream getInputStreamFromContent(Content content, long offset) throws IOException { File filepath = new File(getFilePathOnDisk(content)); if (!filepath.exists()) { - return null; + String errormsg = "Couldn't open \"" + filepath + "\", file does not exist"; + log.warning(errormsg); + throw new FileNotFoundException(errormsg); } InputStream in = new FileInputStream(filepath); StreamUtils.skipExactly(in, offset); @@ -56,6 +61,8 @@ public final class NUSDataProviderLocal extends NUSDataProvider { 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"; + log.warning(errormsg); return new byte[0]; } return Files.readAllBytes(h3File.toPath());