From 513a31fcee6624614edc7043e9c25159bcb623d2 Mon Sep 17 00:00:00 2001 From: Maschell Date: Tue, 13 Dec 2016 20:18:51 +0100 Subject: [PATCH] Added some more checks and changed the output. --- src/de/mas/jnus/lib/NUSTitleLoaderWUD.java | 7 +++ src/de/mas/jnus/lib/WUDService.java | 49 ++++++++++++------- .../mas/jnus/lib/entities/fst/FSTService.java | 2 +- .../lib/implementations/NUSDataProvider.java | 6 ++- .../wud/parser/WUDInfoParser.java | 2 - 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/de/mas/jnus/lib/NUSTitleLoaderWUD.java b/src/de/mas/jnus/lib/NUSTitleLoaderWUD.java index 15f80e2..ae2bbb4 100644 --- a/src/de/mas/jnus/lib/NUSTitleLoaderWUD.java +++ b/src/de/mas/jnus/lib/NUSTitleLoaderWUD.java @@ -30,9 +30,16 @@ public class NUSTitleLoaderWUD extends NUSTitleLoader { WUDImage image = new WUDImage(wudFile); if(titleKey == null){ File keyFile = new File(wudFile.getParentFile().getPath() + File.separator + Settings.WUD_KEY_FILENAME); + if(!keyFile.exists()){ + System.out.println(keyFile.getAbsolutePath() + " does not exist and no title key was provided."); + return null; + } titleKey = Files.readAllBytes(keyFile.toPath()); } WUDInfo wudInfo = WUDInfoParser.createAndLoad(image.getWUDDiscReader(), titleKey); + if(wudInfo == null){ + return null; + } config.setWUDInfo(wudInfo); diff --git a/src/de/mas/jnus/lib/WUDService.java b/src/de/mas/jnus/lib/WUDService.java index 2869532..c1061d5 100644 --- a/src/de/mas/jnus/lib/WUDService.java +++ b/src/de/mas/jnus/lib/WUDService.java @@ -24,24 +24,31 @@ import lombok.extern.java.Log; @Log public class WUDService { - public static boolean compressWUDToWUX(WUDImage image,String outputFolder) throws IOException{ - return compressWUDToWUX(image, outputFolder, "game.wux"); + public static File compressWUDToWUX(WUDImage image,String outputFolder) throws IOException{ + return compressWUDToWUX(image, outputFolder, "game.wux",false); } - public static boolean compressWUDToWUX(WUDImage image,String outputFolder,String filename) throws IOException{ + + public static File compressWUDToWUX(WUDImage image,String outputFolder,boolean overwrite) throws IOException{ + return compressWUDToWUX(image, outputFolder, "game.wux",overwrite); + } + + public static File compressWUDToWUX(WUDImage image,String outputFolder,String filename,boolean overwrite) throws IOException{ if(image.isCompressed()){ - log.info("Given Image is already compressed"); - return false; + log.info("Given image is already compressed"); + return null; } if(image.getWUDFileSize() != WUDImage.WUD_FILESIZE) { log.info("Given WUD has not the expected filesize"); - return false; + return null; } Utils.createDir(outputFolder); String filePath; + if(outputFolder == null) outputFolder = ""; + if(!outputFolder.isEmpty()){ filePath = outputFolder+ File.separator + filename; }else{ @@ -49,11 +56,12 @@ public class WUDService { } File outputFile = new File(filePath); - if(outputFile.exists()){ + if(outputFile.exists() && !overwrite){ log.info("Couldn't compress wud, target file already exists (" + outputFile.getAbsolutePath() + ")"); - //return false; + return null; } + log.info("Writing compressed file to: " + outputFile.getAbsolutePath() ); RandomAccessFile fileOutput = new RandomAccessFile(outputFile, "rw"); WUDImageCompressedInfo info = WUDImageCompressedInfo.getDefaultCompressedInfo(); @@ -102,15 +110,16 @@ public class WUDService { written += read; curSector++; - if(curSector % 1000 == 0){ + if(curSector % 10 == 0){ double readMB = written / 1024.0 / 1024.0; double writtenMB = ((long)realSector * (long)bufferSize) / 1024.0 / 1024.0; double percent = ((double)written / image.getWUDFileSize())*100; double ratio = 1 / (writtenMB / readMB); - System.out.println(String.format(Locale.ROOT,"Compressing (%05.2f%%) | Ratio: 1:%.2f | Read: %08.2fMB | Written: %08.2fMB",percent,ratio,readMB,writtenMB)); + System.out.print(String.format(Locale.ROOT,"\rCompressing into .wux | Progress %.2f%% | Ratio: 1:%.2f | Read: %.2fMB | Written: %.2fMB\t",percent,ratio,readMB,writtenMB)); } }while(written < image.getWUDFileSize()); - + System.out.println(); + System.out.println("Sectors compressed."); log.info("Writing sector table"); fileOutput.seek(sectorTableStart); ByteBuffer buffer = ByteBuffer.allocate(sectorTablePlaceHolder.length); @@ -119,15 +128,15 @@ public class WUDService { buffer.putInt(e.getValue()); } - fileOutput.write(buffer.array()); - + fileOutput.write(buffer.array()); fileOutput.close(); - return true; + + return outputFile; } public static boolean compareWUDImage(WUDImage firstImage,WUDImage secondImage) throws IOException{ if(firstImage.getWUDFileSize() != secondImage.getWUDFileSize()){ - log.info("Filesize if different"); + log.info("Filesize is different"); return false; } InputStream in1 = firstImage.getWUDDiscReader().readEncryptedToInputStream(0, WUDImage.WUD_FILESIZE); @@ -159,14 +168,16 @@ public class WUDService { totalread += read1; curSector++; - if(curSector % 100 == 0){ - System.out.println(String.format("Checked: %016X bytes (%.2f%%)", (long)curSector*(long)bufferSize,(((long)curSector*(long)bufferSize*1.0)/(WUDImage.WUD_FILESIZE))*100)); + if(curSector % 1 == 0){ + double readMB = totalread / 1024.0 / 1024.0; + double percent = ((double)totalread / WUDImage.WUD_FILESIZE)*100; + System.out.print(String.format("\rVerification: %.2fMB done (%.2f%%)", readMB,percent)); } }while(totalread < WUDImage.WUD_FILESIZE); - + System.out.println(); + System.out.print("Verfication done!"); in1.close(); in2.close(); - log.info("Verfication done!"); return result; } diff --git a/src/de/mas/jnus/lib/entities/fst/FSTService.java b/src/de/mas/jnus/lib/entities/fst/FSTService.java index 5de1613..384c958 100644 --- a/src/de/mas/jnus/lib/entities/fst/FSTService.java +++ b/src/de/mas/jnus/lib/entities/fst/FSTService.java @@ -57,7 +57,7 @@ public class FSTService { FSTEntry parent = fstEntryToOffsetMap.get(parentOffset); if(parent != null){ - log.info("no parent found for a FSTEntry"); + log.fine("no parent found for a FSTEntry"); parent.addChildren(entry); } diff --git a/src/de/mas/jnus/lib/implementations/NUSDataProvider.java b/src/de/mas/jnus/lib/implementations/NUSDataProvider.java index 00ba2af..26e24ce 100644 --- a/src/de/mas/jnus/lib/implementations/NUSDataProvider.java +++ b/src/de/mas/jnus/lib/implementations/NUSDataProvider.java @@ -3,6 +3,7 @@ package de.mas.jnus.lib.implementations; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.util.concurrent.SynchronousQueue; import com.sun.istack.internal.NotNull; @@ -60,11 +61,12 @@ public abstract class NUSDataProvider { } String h3Filename = String.format("%08X%s", content.getID(),Settings.H3_EXTENTION); File output = new File(outputFolder + File.separator + h3Filename); - if(output.exists() && output.length() == hash.length){ + if(output.exists() && output.length() == hash.length){ + System.out.println(h3Filename + " already exists"); return; } - log.info("Saving " + h3Filename +" "); + System.out.println("Saving " + h3Filename +" "); FileUtils.saveByteArrayToFile(output, hash); } diff --git a/src/de/mas/jnus/lib/implementations/wud/parser/WUDInfoParser.java b/src/de/mas/jnus/lib/implementations/wud/parser/WUDInfoParser.java index 5702b06..8568392 100644 --- a/src/de/mas/jnus/lib/implementations/wud/parser/WUDInfoParser.java +++ b/src/de/mas/jnus/lib/implementations/wud/parser/WUDInfoParser.java @@ -111,8 +111,6 @@ public class WUDInfoParser { gamePartition.setPartitionOffset(partitionOffset); gamePartition.setPartitionName(partitionName); - System.out.println(String.format("partitionName: %s", partitionName)); - System.out.println(String.format("Gameoffset: %016X", partitionOffset)); wudInfo.setGamePartitionName(partitionName); partition = gamePartition; }