mirror of
https://github.com/Maschell/fuse-wiiu.git
synced 2024-11-22 06:39:14 +01:00
Refactor the WUD loading.
This commit is contained in:
parent
03f29b8f01
commit
0132848dae
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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.implementations.wud.parser.WUDInfo;
|
||||
import de.mas.wiiu.jnus.interfaces.FSTDataProvider;
|
||||
import lombok.val;
|
||||
|
||||
public class WUDFuseContainer extends GroupFuseContainer {
|
||||
private final File input;
|
||||
public class WUDFuseContainer extends PartitionFuseContainer<WUDInfo> {
|
||||
|
||||
public WUDFuseContainer(Optional<FuseDirectory> parent, File input) {
|
||||
super(parent);
|
||||
this.input = input;
|
||||
super(parent, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInit() {
|
||||
Optional<WUDInfo> WUDInfoOpt = WUDUtils.loadWUDInfo(input);
|
||||
if (WUDInfoOpt.isPresent()) {
|
||||
parseContents(WUDInfoOpt.get());
|
||||
} else {
|
||||
System.out.println("Failed to parse WUD/WUX " + input.getAbsolutePath());
|
||||
}
|
||||
protected Optional<WUDInfo> loadInfo(File input) {
|
||||
return WUDUtils.loadWUDInfo(input);
|
||||
}
|
||||
|
||||
protected void parseContents(WUDInfo wudInfo) {
|
||||
@Override
|
||||
protected List<FSTDataProvider> getDataProvider(WUDInfo info) {
|
||||
List<FSTDataProvider> dps = new ArrayList<>();
|
||||
|
||||
try {
|
||||
dps = WUDLoader.getPartitonsAsFSTDataProvider(wudInfo, Settings.retailCommonKey);
|
||||
dps = WUDLoader.getPartitonsAsFSTDataProvider(info, Settings.retailCommonKey);
|
||||
|
||||
} catch (ParseException e) {
|
||||
try {
|
||||
dps = WUDLoader.getPartitonsAsFSTDataProvider(wudInfo, Settings.devCommonKey);
|
||||
dps = WUDLoader.getPartitonsAsFSTDataProvider(info, Settings.devCommonKey);
|
||||
} catch (IOException | ParseException e1) {
|
||||
e.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) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Ignoring " + input.getAbsolutePath() + " :" + e.getClass().getName() + " " + e.getMessage());
|
||||
// System.out.println("Ignoring " + input.getAbsolutePath() + " :" + e.getClass().getName() + " " + e.getMessage());
|
||||
}
|
||||
|
||||
for (val dp : dps) {
|
||||
this.addFuseContainer(dp.getName(), new FSTDataProviderContainer(getParent(), dp));
|
||||
}
|
||||
|
||||
return dps;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,81 +7,37 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import de.mas.wiiu.jnus.NUSTitleLoaderFST;
|
||||
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.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.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) {
|
||||
super(parent, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parseContents(WUDInfo wudinfo) {
|
||||
protected List<FSTDataProvider> getDataProvider(WUDInfo info) {
|
||||
List<FSTDataProvider> dps = new ArrayList<>();
|
||||
try {
|
||||
dps = WUDLoader.getPartitonsAsFSTDataProvider(wudinfo, Settings.retailCommonKey);
|
||||
dps = WUDLoader.getPartitonsAsFSTDataProvider(info, Settings.retailCommonKey);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
dps = WUDLoader.getPartitonsAsFSTDataProvider(wudinfo, Settings.devCommonKey);
|
||||
dps = WUDLoader.getPartitonsAsFSTDataProvider(info, Settings.devCommonKey);
|
||||
} catch (IOException | ParseException e1) {
|
||||
return;
|
||||
return dps;
|
||||
}
|
||||
}
|
||||
return 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();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<WUDInfo> loadInfo(File input) {
|
||||
return WUDUtils.loadWUDInfo(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user