Improved logging

This commit is contained in:
Maschell 2018-12-06 17:40:11 +01:00
parent ed488d3904
commit b6c6ae7320
8 changed files with 40 additions and 24 deletions

View File

@ -88,7 +88,7 @@ public final class DecryptionService {
return;
}
log.fine("Decrypting " + entry.getFilename());
log.info("Decrypting " + entry.getFilename());
String targetFilePath = new StringBuilder().append(outputPath).append("/").append(entry.getFilename()).toString();
String fullPath = new StringBuilder().append(outputPath).toString();

View File

@ -44,7 +44,7 @@ public final class NUSTitleLoaderWUD extends NUSTitleLoader {
public static List<NUSTitle> loadNUSTitle(String WUDPath, File key) throws Exception {
byte[] data = Files.readAllBytes(key.toPath());
if (data == null) {
System.out.println("Failed to read the key file.");
log.warning("Failed to read the key file.");
return new ArrayList<>();
}
return loadNUSTitle(WUDPath, data);
@ -62,7 +62,7 @@ public final class NUSTitleLoaderWUD extends NUSTitleLoader {
byte[] usedTitleKey = titleKey;
File wudFile = new File(WUDPath);
if (!wudFile.exists()) {
log.info(WUDPath + " does not exist.");
log.warning(WUDPath + " does not exist.");
System.exit(1);
}
@ -70,7 +70,7 @@ public final class NUSTitleLoaderWUD extends NUSTitleLoader {
if (usedTitleKey == null && !forceNoKey) {
File keyFile = new File(wudFile.getParentFile().getPath() + File.separator + Settings.WUD_KEY_FILENAME);
if (!keyFile.exists()) {
log.info(keyFile.getAbsolutePath() + " does not exist and no title key was provided.");
log.warning(keyFile.getAbsolutePath() + " does not exist and no title key was provided.");
return new ArrayList<>();
}
usedTitleKey = Files.readAllBytes(keyFile.toPath());
@ -78,7 +78,7 @@ public final class NUSTitleLoaderWUD extends NUSTitleLoader {
WUDInfo wudInfo = WUDInfoParser.createAndLoad(image.getWUDDiscReader(), usedTitleKey);
if (wudInfo == null) {
System.out.println("WTF. ERROR.");
log.warning("Failed to parse any WUDInfo");
return new ArrayList<>();
}

View File

@ -20,7 +20,9 @@ import java.io.IOException;
import java.io.PipedInputStream;
import de.mas.wiiu.jnus.utils.Utils;
import lombok.extern.java.Log;
@Log
public class PipedInputStreamWithException extends PipedInputStream implements InputStreamWithException {
private Exception e = null;
private boolean exceptionSet = false;
@ -63,7 +65,7 @@ public class PipedInputStreamWithException extends PipedInputStream implements I
Utils.sleep(10);
}
if (tries > 100) {
// TODO: warning?
log.warning("Tried too often.");
break;
}
}

View File

@ -147,7 +147,7 @@ public final class WUDService {
}
} while (written < image.getWUDFileSize());
System.out.println();
System.out.println("Sectors compressed.");
log.info("Sectors compressed.");
log.info("Writing sector table");
fileOutput.seek(sectorTableStart);
ByteBuffer buffer = ByteBuffer.allocate(sectorTablePlaceHolder.length);
@ -164,7 +164,7 @@ public final class WUDService {
public static boolean compareWUDImage(WUDImage firstImage, WUDImage secondImage) throws IOException {
if (firstImage.getWUDFileSize() != secondImage.getWUDFileSize()) {
log.info("Filesize is different");
log.warning("Filesize is different");
return false;
}
InputStream in1 = firstImage.getWUDDiscReader().readEncryptedToInputStream(0, WUDImage.WUD_FILESIZE);
@ -182,13 +182,13 @@ public final class WUDService {
int read1 = StreamUtils.getChunkFromStream(in1, blockBuffer1, overflow1, bufferSize);
int read2 = StreamUtils.getChunkFromStream(in2, blockBuffer2, overflow2, bufferSize);
if (read1 != read2) {
log.info("Verification error");
log.warning("Verification error");
result = false;
break;
}
if (!Arrays.equals(blockBuffer1, blockBuffer2)) {
log.info("Verification error");
log.warning("Verification error");
result = false;
break;
}
@ -203,7 +203,7 @@ public final class WUDService {
}
} while (totalread < WUDImage.WUD_FILESIZE);
System.out.println();
System.out.println("Verfication done!");
log.info("Verfication done!");
in1.close();
in2.close();
@ -275,7 +275,7 @@ public final class WUDService {
}
} while (totalread < WUDImage.WUD_FILESIZE);
System.out.println();
System.out.println("Decompressing done!");
log.info("Decompressing done!");
in.close();
out.close();
@ -331,7 +331,7 @@ public final class WUDService {
double readMB = totalread / 1024.0 / 1024.0;
double percent = ((double) totalread / WUDImage.WUD_FILESIZE) * 100;
System.out.println(String.format("\rHashing: %.2fMB done (%.2f%%)", readMB, percent));
log.info(String.format("\rHashing: %.2fMB done (%.2f%%)", readMB, percent));
HashResult result = new HashResult(sha1.digest(), md5.digest(), Utils.StringToByteArray(Long.toHexString(checksumEngine.getValue())));

View File

@ -16,6 +16,7 @@
****************************************************************************/
package de.mas.wiiu.jnus.entities.fst;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
@ -151,14 +152,18 @@ public class FSTEntry {
}
public void printRecursive(int space) {
printRecursive(System.out,space);
}
public void printRecursive(PrintStream out, int space) {
for (int i = 0; i < space; i++) {
System.out.print(" ");
out.print(" ");
}
System.out.print(getFilename());
out.print(getFilename());
if (isNotInPackage()) {
System.out.print(" (not in package)");
out.print(" (not in package)");
}
System.out.println();
out.println();
for (FSTEntry child : getDirChildren(true)) {
child.printRecursive(space + 5);
}

View File

@ -204,7 +204,7 @@ public final class HashUtil {
byte[] hash2 = HashUtil.hashSHA1(file2);
boolean result = Arrays.equals(hash1, hash2);
if (!result) {
log.info("Hash doesn't match for " + file1.getAbsolutePath() + "(" + Utils.ByteArrayToString(hash1) + ") and " + file2.getAbsolutePath() + "("
log.warning("Hash doesn't match for " + file1.getAbsolutePath() + "(" + Utils.ByteArrayToString(hash1) + ") and " + file2.getAbsolutePath() + "("
+ Utils.ByteArrayToString(hash2) + ")!");
}
return result;
@ -246,7 +246,7 @@ public final class HashUtil {
if (!Arrays.equals(expected_h1_hash, real_h1_hash)) {
throw new CheckSumWrongException("h1 checksumfail", real_h1_hash, expected_h1_hash);
} else {
log.finer("h1 checksum right!");
log.finest("h1 checksum right!");
}
}
@ -257,12 +257,12 @@ public final class HashUtil {
if (!Arrays.equals(expected_h2_hash, real_h2_hash)) {
throw new CheckSumWrongException("h2 checksumfail", real_h2_hash, expected_h2_hash);
} else {
log.fine("h2 checksum right!");
log.finest("h2 checksum right!");
}
}
if (h3Hashes == null) {
log.info("didn't check the h3, its missing.");
log.warning("didn't check the h3, its missing.");
return;
}
if ((block % 4096) == 0) {
@ -272,7 +272,7 @@ public final class HashUtil {
if (!Arrays.equals(expected_h3_hash, real_h3_hash)) {
throw new CheckSumWrongException("h3 checksumfail", real_h3_hash, expected_h3_hash);
} else {
log.fine("h3 checksum right!");
log.finest("h3 checksum right!");
}
}
}

View File

@ -23,6 +23,9 @@ import java.io.InputStream;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -176,6 +179,10 @@ public final class Utils {
return 0L;
}
}
public static void setGlobalLogLevel(Level level) {
Arrays.stream(LogManager.getLogManager().getLogger("").getHandlers()).forEach(h -> h.setLevel(level));
}
public static boolean checkFileExists(String path) {
return new File(path).exists();

View File

@ -30,7 +30,9 @@ import de.mas.wiiu.jnus.utils.CheckSumWrongException;
import de.mas.wiiu.jnus.utils.HashUtil;
import de.mas.wiiu.jnus.utils.StreamUtils;
import de.mas.wiiu.jnus.utils.Utils;
import lombok.extern.java.Log;
@Log
public class NUSDecryption extends AESDecryption {
public NUSDecryption(byte[] AESKey, byte[] IV) {
super(AESKey, IV);
@ -130,7 +132,7 @@ public class NUSDecryption extends AESDecryption {
throw new CheckSumWrongException("hash checksum failed", calculated_hash1, expected_hash);
} else {
// log.warning("Hash DOES match saves output stream.");
log.finest("Hash DOES match saves output stream.");
}
}
@ -184,7 +186,7 @@ public class NUSDecryption extends AESDecryption {
soffset = 0;
}
} while (wrote < filesize && (inBlockBuffer == BLOCKSIZE));
// System.out.println("Decryption okay");
log.finest("Decryption okay");
outputStream.close();
inputStream.close();
}