Added some more checks and changed the output.

This commit is contained in:
Maschell 2016-12-13 20:18:51 +01:00
parent b7ec1a4d31
commit 513a31fcee
5 changed files with 42 additions and 24 deletions

View File

@ -30,9 +30,16 @@ public class NUSTitleLoaderWUD extends NUSTitleLoader {
WUDImage image = new WUDImage(wudFile); WUDImage image = new WUDImage(wudFile);
if(titleKey == null){ if(titleKey == null){
File keyFile = new File(wudFile.getParentFile().getPath() + File.separator + Settings.WUD_KEY_FILENAME); 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()); titleKey = Files.readAllBytes(keyFile.toPath());
} }
WUDInfo wudInfo = WUDInfoParser.createAndLoad(image.getWUDDiscReader(), titleKey); WUDInfo wudInfo = WUDInfoParser.createAndLoad(image.getWUDDiscReader(), titleKey);
if(wudInfo == null){
return null;
}
config.setWUDInfo(wudInfo); config.setWUDInfo(wudInfo);

View File

@ -24,24 +24,31 @@ import lombok.extern.java.Log;
@Log @Log
public class WUDService { public class WUDService {
public static boolean compressWUDToWUX(WUDImage image,String outputFolder) throws IOException{ public static File compressWUDToWUX(WUDImage image,String outputFolder) throws IOException{
return compressWUDToWUX(image, outputFolder, "game.wux"); 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()){ if(image.isCompressed()){
log.info("Given Image is already compressed"); log.info("Given image is already compressed");
return false; return null;
} }
if(image.getWUDFileSize() != WUDImage.WUD_FILESIZE) if(image.getWUDFileSize() != WUDImage.WUD_FILESIZE)
{ {
log.info("Given WUD has not the expected filesize"); log.info("Given WUD has not the expected filesize");
return false; return null;
} }
Utils.createDir(outputFolder); Utils.createDir(outputFolder);
String filePath; String filePath;
if(outputFolder == null) outputFolder = "";
if(!outputFolder.isEmpty()){ if(!outputFolder.isEmpty()){
filePath = outputFolder+ File.separator + filename; filePath = outputFolder+ File.separator + filename;
}else{ }else{
@ -49,11 +56,12 @@ public class WUDService {
} }
File outputFile = new File(filePath); File outputFile = new File(filePath);
if(outputFile.exists()){ if(outputFile.exists() && !overwrite){
log.info("Couldn't compress wud, target file already exists (" + outputFile.getAbsolutePath() + ")"); 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"); RandomAccessFile fileOutput = new RandomAccessFile(outputFile, "rw");
WUDImageCompressedInfo info = WUDImageCompressedInfo.getDefaultCompressedInfo(); WUDImageCompressedInfo info = WUDImageCompressedInfo.getDefaultCompressedInfo();
@ -102,15 +110,16 @@ public class WUDService {
written += read; written += read;
curSector++; curSector++;
if(curSector % 1000 == 0){ if(curSector % 10 == 0){
double readMB = written / 1024.0 / 1024.0; double readMB = written / 1024.0 / 1024.0;
double writtenMB = ((long)realSector * (long)bufferSize) / 1024.0 / 1024.0; double writtenMB = ((long)realSector * (long)bufferSize) / 1024.0 / 1024.0;
double percent = ((double)written / image.getWUDFileSize())*100; double percent = ((double)written / image.getWUDFileSize())*100;
double ratio = 1 / (writtenMB / readMB); 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()); }while(written < image.getWUDFileSize());
System.out.println();
System.out.println("Sectors compressed.");
log.info("Writing sector table"); log.info("Writing sector table");
fileOutput.seek(sectorTableStart); fileOutput.seek(sectorTableStart);
ByteBuffer buffer = ByteBuffer.allocate(sectorTablePlaceHolder.length); ByteBuffer buffer = ByteBuffer.allocate(sectorTablePlaceHolder.length);
@ -120,14 +129,14 @@ public class WUDService {
} }
fileOutput.write(buffer.array()); fileOutput.write(buffer.array());
fileOutput.close(); fileOutput.close();
return true;
return outputFile;
} }
public static boolean compareWUDImage(WUDImage firstImage,WUDImage secondImage) throws IOException{ public static boolean compareWUDImage(WUDImage firstImage,WUDImage secondImage) throws IOException{
if(firstImage.getWUDFileSize() != secondImage.getWUDFileSize()){ if(firstImage.getWUDFileSize() != secondImage.getWUDFileSize()){
log.info("Filesize if different"); log.info("Filesize is different");
return false; return false;
} }
InputStream in1 = firstImage.getWUDDiscReader().readEncryptedToInputStream(0, WUDImage.WUD_FILESIZE); InputStream in1 = firstImage.getWUDDiscReader().readEncryptedToInputStream(0, WUDImage.WUD_FILESIZE);
@ -159,14 +168,16 @@ public class WUDService {
totalread += read1; totalread += read1;
curSector++; curSector++;
if(curSector % 100 == 0){ if(curSector % 1 == 0){
System.out.println(String.format("Checked: %016X bytes (%.2f%%)", (long)curSector*(long)bufferSize,(((long)curSector*(long)bufferSize*1.0)/(WUDImage.WUD_FILESIZE))*100)); 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); }while(totalread < WUDImage.WUD_FILESIZE);
System.out.println();
System.out.print("Verfication done!");
in1.close(); in1.close();
in2.close(); in2.close();
log.info("Verfication done!");
return result; return result;
} }

View File

@ -57,7 +57,7 @@ public class FSTService {
FSTEntry parent = fstEntryToOffsetMap.get(parentOffset); FSTEntry parent = fstEntryToOffsetMap.get(parentOffset);
if(parent != null){ if(parent != null){
log.info("no parent found for a FSTEntry"); log.fine("no parent found for a FSTEntry");
parent.addChildren(entry); parent.addChildren(entry);
} }

View File

@ -3,6 +3,7 @@ package de.mas.jnus.lib.implementations;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.concurrent.SynchronousQueue;
import com.sun.istack.internal.NotNull; import com.sun.istack.internal.NotNull;
@ -61,10 +62,11 @@ public abstract class NUSDataProvider {
String h3Filename = String.format("%08X%s", content.getID(),Settings.H3_EXTENTION); String h3Filename = String.format("%08X%s", content.getID(),Settings.H3_EXTENTION);
File output = new File(outputFolder + File.separator + h3Filename); 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; return;
} }
log.info("Saving " + h3Filename +" "); System.out.println("Saving " + h3Filename +" ");
FileUtils.saveByteArrayToFile(output, hash); FileUtils.saveByteArrayToFile(output, hash);
} }

View File

@ -111,8 +111,6 @@ public class WUDInfoParser {
gamePartition.setPartitionOffset(partitionOffset); gamePartition.setPartitionOffset(partitionOffset);
gamePartition.setPartitionName(partitionName); gamePartition.setPartitionName(partitionName);
System.out.println(String.format("partitionName: %s", partitionName));
System.out.println(String.format("Gameoffset: %016X", partitionOffset));
wudInfo.setGamePartitionName(partitionName); wudInfo.setGamePartitionName(partitionName);
partition = gamePartition; partition = gamePartition;
} }