Add warnings when files couldn't be found.

This commit is contained in:
Maschell 2018-12-16 15:03:46 +01:00
parent fa3b0df7d2
commit f0306b8cce
2 changed files with 14 additions and 1 deletions

View File

@ -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);

View File

@ -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());