mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-22 07:59:19 +01:00
Added some more checks and changed the output.
This commit is contained in:
parent
b7ec1a4d31
commit
513a31fcee
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user