Refactor the WUD loading.

This commit is contained in:
Maschell 2019-06-04 12:14:08 +02:00
parent 03f29b8f01
commit 0132848dae
4 changed files with 132 additions and 78 deletions

View File

@ -0,0 +1,38 @@
package de.mas.wiiu.jnus.fuse_wiiu.implementation;
import java.io.File;
import java.util.List;
import java.util.Optional;
import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory;
import de.mas.wiiu.jnus.interfaces.FSTDataProvider;
import lombok.val;
public abstract class PartitionFuseContainer<T> extends GroupFuseContainer {
private final File file;
public PartitionFuseContainer(Optional<FuseDirectory> parent, File file) {
super(parent);
this.file = file;
}
@Override
protected void doInit() {
Optional<T> infoOpt = loadInfo(file);
if (infoOpt.isPresent()) {
parseContents(getDataProvider(infoOpt.get()));
} else {
System.err.println("Failed to parse " + file.getAbsolutePath());
}
}
protected abstract Optional<T> loadInfo(File input);
abstract protected List<FSTDataProvider> getDataProvider(T info);
void parseContents(List<FSTDataProvider> dps) {
for (val dp : dps) {
this.addFuseContainer(dp.getName(), new FSTDataProviderContainer(getParent(), dp));
}
}
}

View File

@ -0,0 +1,72 @@
package de.mas.wiiu.jnus.fuse_wiiu.implementation;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
import java.util.Optional;
import de.mas.wiiu.jnus.NUSTitleLoaderFST;
import de.mas.wiiu.jnus.entities.fst.FSTEntry;
import de.mas.wiiu.jnus.fuse_wiiu.Settings;
import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory;
import de.mas.wiiu.jnus.implementations.FSTDataProviderNUSTitle;
import de.mas.wiiu.jnus.interfaces.FSTDataProvider;
import de.mas.wiiu.jnus.interfaces.HasNUSTitle;
import de.mas.wiiu.jnus.utils.FSTUtils;
public abstract class RecursivePartitionFuseContainer<T> extends PartitionFuseContainer<T> {
public RecursivePartitionFuseContainer(Optional<FuseDirectory> parent, File input) {
super(parent, input);
}
@Override
void parseContents(List<FSTDataProvider> dps) {
try {
for (FSTDataProvider dp : dps) {
for (FSTEntry tmd : FSTUtils.getFSTEntriesByRegEx(dp.getRoot(), ".*tmd")) {
Optional<FSTEntry> parentOpt = tmd.getParent();
if (parentOpt.isPresent()) {
FSTEntry parent = parentOpt.get();
if (parent.getFileChildren().stream().filter(f -> f.getFilename().endsWith(".app")).findAny().isPresent()) {
FSTDataProvider fdp = null;
try {
fdp = new FSTDataProviderNUSTitle(NUSTitleLoaderFST.loadNUSTitle(dp, parent, Settings.retailCommonKey));
} catch (IOException | ParseException e) {
try {
fdp = new FSTDataProviderNUSTitle(NUSTitleLoaderFST.loadNUSTitle(dp, parent, Settings.devCommonKey));
} catch (Exception e1) {
System.out.println("Ignoring " + parent.getFilename() + " :" + e1.getClass().getName() + " " + e1.getMessage());
continue;
}
} catch (Exception e) {
System.out.println("Ignoring " + parent.getFilename() + " :" + e.getClass().getName() + " " + e.getMessage());
continue;
}
FSTDataProvider fdpCpy = fdp;
this.addFuseContainer("[DECRYPTED] [" + dp.getName() + "] " + parent.getFilename(),
new FSTDataProviderContainer(getParent(), fdpCpy));
}
}
}
if (dp instanceof HasNUSTitle) {
try {
this.addFuseContainer("[ENCRYPTED] " + dp.getName(), new NUSTitleEncryptedFuseContainer(getParent(), ((HasNUSTitle) dp).getNUSTitle()));
} catch (Exception e) {
e.printStackTrace();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -13,49 +13,37 @@ import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory;
import de.mas.wiiu.jnus.fuse_wiiu.utils.WUDUtils; import de.mas.wiiu.jnus.fuse_wiiu.utils.WUDUtils;
import de.mas.wiiu.jnus.implementations.wud.parser.WUDInfo; import de.mas.wiiu.jnus.implementations.wud.parser.WUDInfo;
import de.mas.wiiu.jnus.interfaces.FSTDataProvider; import de.mas.wiiu.jnus.interfaces.FSTDataProvider;
import lombok.val;
public class WUDFuseContainer extends GroupFuseContainer { public class WUDFuseContainer extends PartitionFuseContainer<WUDInfo> {
private final File input;
public WUDFuseContainer(Optional<FuseDirectory> parent, File input) { public WUDFuseContainer(Optional<FuseDirectory> parent, File input) {
super(parent); super(parent, input);
this.input = input;
} }
@Override @Override
protected void doInit() { protected Optional<WUDInfo> loadInfo(File input) {
Optional<WUDInfo> WUDInfoOpt = WUDUtils.loadWUDInfo(input); return WUDUtils.loadWUDInfo(input);
if (WUDInfoOpt.isPresent()) {
parseContents(WUDInfoOpt.get());
} else {
System.out.println("Failed to parse WUD/WUX " + input.getAbsolutePath());
}
} }
protected void parseContents(WUDInfo wudInfo) { @Override
protected List<FSTDataProvider> getDataProvider(WUDInfo info) {
List<FSTDataProvider> dps = new ArrayList<>(); List<FSTDataProvider> dps = new ArrayList<>();
try { try {
dps = WUDLoader.getPartitonsAsFSTDataProvider(wudInfo, Settings.retailCommonKey); dps = WUDLoader.getPartitonsAsFSTDataProvider(info, Settings.retailCommonKey);
} catch (ParseException e) { } catch (ParseException e) {
try { try {
dps = WUDLoader.getPartitonsAsFSTDataProvider(wudInfo, Settings.devCommonKey); dps = WUDLoader.getPartitonsAsFSTDataProvider(info, Settings.devCommonKey);
} catch (IOException | ParseException e1) { } catch (IOException | ParseException e1) {
e.printStackTrace(); e.printStackTrace();
e1.printStackTrace(); e1.printStackTrace();
System.out.println("Ignoring " + input.getAbsolutePath() + " :" + e1.getClass().getName() + " " + e1.getMessage()); // System.out.println("Ignoring " + input.getAbsolutePath() + " :" + e1.getClass().getName() + " " + e1.getMessage());
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
System.out.println("Ignoring " + input.getAbsolutePath() + " :" + e.getClass().getName() + " " + e.getMessage()); // System.out.println("Ignoring " + input.getAbsolutePath() + " :" + e.getClass().getName() + " " + e.getMessage());
} }
return dps;
for (val dp : dps) {
this.addFuseContainer(dp.getName(), new FSTDataProviderContainer(getParent(), dp));
}
} }
} }

View File

@ -7,81 +7,37 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import de.mas.wiiu.jnus.NUSTitleLoaderFST;
import de.mas.wiiu.jnus.WUDLoader; import de.mas.wiiu.jnus.WUDLoader;
import de.mas.wiiu.jnus.entities.fst.FSTEntry;
import de.mas.wiiu.jnus.fuse_wiiu.Settings; import de.mas.wiiu.jnus.fuse_wiiu.Settings;
import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory; import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory;
import de.mas.wiiu.jnus.implementations.FSTDataProviderNUSTitle; import de.mas.wiiu.jnus.fuse_wiiu.utils.WUDUtils;
import de.mas.wiiu.jnus.implementations.wud.parser.WUDInfo; import de.mas.wiiu.jnus.implementations.wud.parser.WUDInfo;
import de.mas.wiiu.jnus.interfaces.FSTDataProvider; import de.mas.wiiu.jnus.interfaces.FSTDataProvider;
import de.mas.wiiu.jnus.interfaces.HasNUSTitle;
import de.mas.wiiu.jnus.utils.FSTUtils;
public class WUDMountedFuseContainer extends WUDFuseContainer { public class WUDMountedFuseContainer extends RecursivePartitionFuseContainer<WUDInfo> {
public WUDMountedFuseContainer(Optional<FuseDirectory> parent, File input) { public WUDMountedFuseContainer(Optional<FuseDirectory> parent, File input) {
super(parent, input); super(parent, input);
} }
@Override @Override
protected void parseContents(WUDInfo wudinfo) { protected List<FSTDataProvider> getDataProvider(WUDInfo info) {
List<FSTDataProvider> dps = new ArrayList<>(); List<FSTDataProvider> dps = new ArrayList<>();
try { try {
dps = WUDLoader.getPartitonsAsFSTDataProvider(wudinfo, Settings.retailCommonKey); dps = WUDLoader.getPartitonsAsFSTDataProvider(info, Settings.retailCommonKey);
} catch (Exception e) { } catch (Exception e) {
try { try {
dps = WUDLoader.getPartitonsAsFSTDataProvider(wudinfo, Settings.devCommonKey); dps = WUDLoader.getPartitonsAsFSTDataProvider(info, Settings.devCommonKey);
} catch (IOException | ParseException e1) { } catch (IOException | ParseException e1) {
return; return dps;
} }
} }
return dps;
}
try { @Override
for (FSTDataProvider dp : dps) { protected Optional<WUDInfo> loadInfo(File input) {
for (FSTEntry tmd : FSTUtils.getFSTEntriesByRegEx(dp.getRoot(), ".*tmd")) { return WUDUtils.loadWUDInfo(input);
Optional<FSTEntry> parentOpt = tmd.getParent();
if (parentOpt.isPresent()) {
FSTEntry parent = parentOpt.get();
if (parent.getFileChildren().stream().filter(f -> f.getFilename().endsWith(".app")).findAny().isPresent()) {
FSTDataProvider fdp = null;
try {
fdp = new FSTDataProviderNUSTitle(NUSTitleLoaderFST.loadNUSTitle(dp, parent, Settings.retailCommonKey));
} catch (IOException | ParseException e) {
try {
fdp = new FSTDataProviderNUSTitle(NUSTitleLoaderFST.loadNUSTitle(dp, parent, Settings.devCommonKey));
} catch (Exception e1) {
System.out.println("Ignoring " + parent.getFilename() + " :" + e1.getClass().getName() + " " + e1.getMessage());
continue;
}
} catch (Exception e) {
System.out.println("Ignoring " + parent.getFilename() + " :" + e.getClass().getName() + " " + e.getMessage());
continue;
}
FSTDataProvider fdpCpy = fdp;
this.addFuseContainer("[DECRYPTED] [" + dp.getName() + "] " + parent.getFilename(),
new FSTDataProviderContainer(getParent(), fdpCpy));
}
}
}
if (dp instanceof HasNUSTitle) {
try {
this.addFuseContainer("[ENCRYPTED] " + dp.getName(), new NUSTitleEncryptedFuseContainer(getParent(), ((HasNUSTitle) dp).getNUSTitle()));
} catch (Exception e) {
e.printStackTrace();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
} }
} }