Refactor the wud/wumad handling

This commit is contained in:
Maschell 2019-06-04 15:06:18 +02:00
parent 0c8cdbb376
commit 4a9b6078f9
9 changed files with 54 additions and 138 deletions

View File

@ -1,6 +1,5 @@
package de.mas.wiiu.jnus.fuse_wiiu.implementation;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.Supplier;

View File

@ -4,32 +4,31 @@ import java.io.File;
import java.util.List;
import java.util.Optional;
import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FSTDataProviderLoader;
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 {
public class MultipleFSTDataProviderFuseContainer<T> extends GroupFuseContainer {
private final File file;
private final FSTDataProviderLoader<T> loader;
public PartitionFuseContainer(Optional<FuseDirectory> parent, File file) {
public MultipleFSTDataProviderFuseContainer(Optional<FuseDirectory> parent, File file, FSTDataProviderLoader<T> loader) {
super(parent);
this.file = file;
this.loader = loader;
}
@Override
protected void doInit() {
Optional<T> infoOpt = loadInfo(file);
Optional<T> infoOpt = loader.loadInfo(file);
if (infoOpt.isPresent()) {
parseContents(getDataProvider(infoOpt.get()));
parseContents(loader.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

@ -9,15 +9,16 @@ 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.FSTDataProviderLoader;
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);
public class MultipleFSTDataProviderRecursiveFuseContainer<T> extends MultipleFSTDataProviderFuseContainer<T> {
public MultipleFSTDataProviderRecursiveFuseContainer(Optional<FuseDirectory> parent, File input, FSTDataProviderLoader<T> loader) {
super(parent, input, loader);
}
@Override

View File

@ -1,49 +0,0 @@
package de.mas.wiiu.jnus.fuse_wiiu.implementation;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import de.mas.wiiu.jnus.WUDLoader;
import de.mas.wiiu.jnus.fuse_wiiu.Settings;
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;
public class WUDFuseContainer extends PartitionFuseContainer<WUDInfo> {
public WUDFuseContainer(Optional<FuseDirectory> parent, File input) {
super(parent, input);
}
@Override
protected Optional<WUDInfo> loadInfo(File input) {
return WUDUtils.loadWUDInfo(input);
}
@Override
protected List<FSTDataProvider> getDataProvider(WUDInfo info) {
List<FSTDataProvider> dps = new ArrayList<>();
try {
dps = WUDLoader.getPartitonsAsFSTDataProvider(info, Settings.retailCommonKey);
} catch (ParseException e) {
try {
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());
}
} catch (Exception e) {
e.printStackTrace();
// System.out.println("Ignoring " + input.getAbsolutePath() + " :" + e.getClass().getName() + " " + e.getMessage());
}
return dps;
}
}

View File

@ -1,49 +0,0 @@
package de.mas.wiiu.jnus.fuse_wiiu.implementation;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import de.mas.wiiu.jnus.WumadLoader;
import de.mas.wiiu.jnus.fuse_wiiu.Settings;
import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory;
import de.mas.wiiu.jnus.implementations.wud.wumad.WumadInfo;
import de.mas.wiiu.jnus.interfaces.FSTDataProvider;
public class WUMADFuseContainer extends PartitionFuseContainer<WumadInfo> {
public WUMADFuseContainer(Optional<FuseDirectory> parent, File c) {
super(parent, c);
}
@Override
protected Optional<WumadInfo> loadInfo(File input) {
if (input != null && input.exists()) {
try {
return Optional.of(WumadLoader.load(input));
} catch (Exception e) {
e.printStackTrace();
}
}
return Optional.empty();
}
@Override
protected List<FSTDataProvider> getDataProvider(WumadInfo info) {
List<FSTDataProvider> dps = new ArrayList<>();
try {
dps = WumadLoader.getPartitonsAsFSTDataProvider(info, Settings.retailCommonKey);
} catch (Exception e) {
try {
dps = WumadLoader.getPartitonsAsFSTDataProvider(info, Settings.devCommonKey);
} catch (IOException | ParseException e1) {
return dps;
}
}
return dps;
}
}

View File

@ -1,4 +1,4 @@
package de.mas.wiiu.jnus.fuse_wiiu.implementation;
package de.mas.wiiu.jnus.fuse_wiiu.implementation.loader;
import java.io.File;
import java.io.IOException;
@ -9,19 +9,21 @@ import java.util.Optional;
import de.mas.wiiu.jnus.WUDLoader;
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.FSTDataProviderLoader;
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.Getter;
public class WUDMountedFuseContainer extends RecursivePartitionFuseContainer<WUDInfo> {
public class WUDFSTDataProviderLoader implements FSTDataProviderLoader<WUDInfo> {
@Getter
private static WUDFSTDataProviderLoader instance = new WUDFSTDataProviderLoader();
public WUDMountedFuseContainer(Optional<FuseDirectory> parent, File input) {
super(parent, input);
private WUDFSTDataProviderLoader() {
}
@Override
protected List<FSTDataProvider> getDataProvider(WUDInfo info) {
public List<FSTDataProvider> getDataProvider(WUDInfo info) {
List<FSTDataProvider> dps = new ArrayList<>();
try {
dps = WUDLoader.getPartitonsAsFSTDataProvider(info, Settings.retailCommonKey);
@ -36,8 +38,7 @@ public class WUDMountedFuseContainer extends RecursivePartitionFuseContainer<WUD
}
@Override
protected Optional<WUDInfo> loadInfo(File input) {
public Optional<WUDInfo> loadInfo(File input) {
return WUDUtils.loadWUDInfo(input);
}
}

View File

@ -1,4 +1,4 @@
package de.mas.wiiu.jnus.fuse_wiiu.implementation;
package de.mas.wiiu.jnus.fuse_wiiu.implementation.loader;
import java.io.File;
import java.io.IOException;
@ -9,18 +9,20 @@ import java.util.Optional;
import de.mas.wiiu.jnus.WumadLoader;
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.FSTDataProviderLoader;
import de.mas.wiiu.jnus.implementations.wud.wumad.WumadInfo;
import de.mas.wiiu.jnus.interfaces.FSTDataProvider;
import lombok.Getter;
public class WUMADMountedFuseContainer extends RecursivePartitionFuseContainer<WumadInfo> {
public class WumadFSTDataProviderLoader implements FSTDataProviderLoader<WumadInfo> {
@Getter
private static WumadFSTDataProviderLoader instance = new WumadFSTDataProviderLoader();
public WUMADMountedFuseContainer(Optional<FuseDirectory> parent, File c) {
super(parent, c);
private WumadFSTDataProviderLoader() {
}
@Override
protected Optional<WumadInfo> loadInfo(File input) {
public Optional<WumadInfo> loadInfo(File input) {
if (input != null && input.exists()) {
try {
return Optional.of(WumadLoader.load(input));
@ -32,7 +34,7 @@ public class WUMADMountedFuseContainer extends RecursivePartitionFuseContainer<W
}
@Override
protected List<FSTDataProvider> getDataProvider(WumadInfo info) {
public List<FSTDataProvider> getDataProvider(WumadInfo info) {
List<FSTDataProvider> dps = new ArrayList<>();
try {
dps = WumadLoader.getPartitonsAsFSTDataProvider(info, Settings.retailCommonKey);
@ -45,5 +47,4 @@ public class WUMADMountedFuseContainer extends RecursivePartitionFuseContainer<W
}
return dps;
}
}

View File

@ -0,0 +1,13 @@
package de.mas.wiiu.jnus.fuse_wiiu.interfaces;
import java.io.File;
import java.util.List;
import java.util.Optional;
import de.mas.wiiu.jnus.interfaces.FSTDataProvider;
public interface FSTDataProviderLoader<T> {
public Optional<T> loadInfo(File input);
public List<FSTDataProvider> getDataProvider(T info);
}

View File

@ -8,12 +8,12 @@ import java.util.Optional;
import de.mas.wiiu.jnus.fuse_wiiu.implementation.FSFuseContainer;
import de.mas.wiiu.jnus.fuse_wiiu.implementation.LocalBackupNUSTitleContainer;
import de.mas.wiiu.jnus.fuse_wiiu.implementation.LocalNUSTitleContainer;
import de.mas.wiiu.jnus.fuse_wiiu.implementation.WUDFuseContainer;
import de.mas.wiiu.jnus.fuse_wiiu.implementation.WUDMountedFuseContainer;
import de.mas.wiiu.jnus.fuse_wiiu.implementation.MultipleFSTDataProviderFuseContainer;
import de.mas.wiiu.jnus.fuse_wiiu.implementation.MultipleFSTDataProviderRecursiveFuseContainer;
import de.mas.wiiu.jnus.fuse_wiiu.implementation.WUDToWUDContainer;
import de.mas.wiiu.jnus.fuse_wiiu.implementation.WUMADFuseContainer;
import de.mas.wiiu.jnus.fuse_wiiu.implementation.WUMADMountedFuseContainer;
import de.mas.wiiu.jnus.fuse_wiiu.implementation.WoomyNUSTitleContainer;
import de.mas.wiiu.jnus.fuse_wiiu.implementation.loader.WUDFSTDataProviderLoader;
import de.mas.wiiu.jnus.fuse_wiiu.implementation.loader.WumadFSTDataProviderLoader;
import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseContainer;
import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory;
import de.mas.wiiu.jnus.implementations.wud.reader.WUDDiscReaderSplitted;
@ -50,8 +50,8 @@ public class FuseContainerWrapper {
}
if (c.exists() && c.getName().endsWith(".wumad")) {
result.put(prefix + c.getName(), new WUMADFuseContainer(parent, c));
result.put(prefix + "[EXTRA] " + c.getName(), new WUMADMountedFuseContainer(parent, c));
result.put(prefix + c.getName(), new MultipleFSTDataProviderFuseContainer<>(parent, c, WumadFSTDataProviderLoader.getInstance()));
result.put(prefix + "[EXTRA] " + c.getName(), new MultipleFSTDataProviderRecursiveFuseContainer<>(parent, c, WumadFSTDataProviderLoader.getInstance()));
return result;
}
@ -75,8 +75,8 @@ public class FuseContainerWrapper {
return false;
}
result.put(prefix + c.getName(), new WUDFuseContainer(parent, c));
result.put(prefix + "[EXTRA] " + c.getName(), new WUDMountedFuseContainer(parent, c));
result.put(prefix + c.getName(), new MultipleFSTDataProviderFuseContainer<>(parent, c, WUDFSTDataProviderLoader.getInstance()));
result.put(prefix + "[EXTRA] " + c.getName(), new MultipleFSTDataProviderRecursiveFuseContainer<>(parent, c, WUDFSTDataProviderLoader.getInstance()));
if (c.getName().endsWith("part1.wud") || c.getName().endsWith(".wux")) {
result.put(prefix + "[WUD] " + c.getName(), new WUDToWUDContainer(parent, c));
}