From 4a9b6078f99ffb2e7e3b56d8f847e4376c6002a0 Mon Sep 17 00:00:00 2001 From: Maschell Date: Tue, 4 Jun 2019 15:06:18 +0200 Subject: [PATCH] Refactor the wud/wumad handling --- .../FSTDataProviderContainer.java | 1 - ...MultipleFSTDataProviderFuseContainer.java} | 15 +++--- ...STDataProviderRecursiveFuseContainer.java} | 7 +-- .../implementation/WUDFuseContainer.java | 49 ------------------- .../implementation/WUMADFuseContainer.java | 49 ------------------- .../WUDFSTDataProviderLoader.java} | 21 ++++---- .../WumadFSTDataProviderLoader.java} | 21 ++++---- .../interfaces/FSTDataProviderLoader.java | 13 +++++ .../fuse_wiiu/utils/FuseContainerWrapper.java | 16 +++--- 9 files changed, 54 insertions(+), 138 deletions(-) rename src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/{PartitionFuseContainer.java => MultipleFSTDataProviderFuseContainer.java} (60%) rename src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/{RecursivePartitionFuseContainer.java => MultipleFSTDataProviderRecursiveFuseContainer.java} (89%) delete mode 100644 src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WUDFuseContainer.java delete mode 100644 src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WUMADFuseContainer.java rename src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/{WUDMountedFuseContainer.java => loader/WUDFSTDataProviderLoader.java} (65%) rename src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/{WUMADMountedFuseContainer.java => loader/WumadFSTDataProviderLoader.java} (68%) create mode 100644 src/main/java/de/mas/wiiu/jnus/fuse_wiiu/interfaces/FSTDataProviderLoader.java diff --git a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/FSTDataProviderContainer.java b/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/FSTDataProviderContainer.java index 9ea418a..32f726e 100644 --- a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/FSTDataProviderContainer.java +++ b/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/FSTDataProviderContainer.java @@ -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; diff --git a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/PartitionFuseContainer.java b/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/MultipleFSTDataProviderFuseContainer.java similarity index 60% rename from src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/PartitionFuseContainer.java rename to src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/MultipleFSTDataProviderFuseContainer.java index 6ee5464..69853d1 100644 --- a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/PartitionFuseContainer.java +++ b/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/MultipleFSTDataProviderFuseContainer.java @@ -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 extends GroupFuseContainer { +public class MultipleFSTDataProviderFuseContainer extends GroupFuseContainer { private final File file; + private final FSTDataProviderLoader loader; - public PartitionFuseContainer(Optional parent, File file) { + public MultipleFSTDataProviderFuseContainer(Optional parent, File file, FSTDataProviderLoader loader) { super(parent); this.file = file; + this.loader = loader; } @Override protected void doInit() { - Optional infoOpt = loadInfo(file); + Optional 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 loadInfo(File input); - - abstract protected List getDataProvider(T info); - void parseContents(List dps) { for (val dp : dps) { this.addFuseContainer(dp.getName(), new FSTDataProviderContainer(getParent(), dp)); diff --git a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/RecursivePartitionFuseContainer.java b/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/MultipleFSTDataProviderRecursiveFuseContainer.java similarity index 89% rename from src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/RecursivePartitionFuseContainer.java rename to src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/MultipleFSTDataProviderRecursiveFuseContainer.java index 806cea3..32dc964 100644 --- a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/RecursivePartitionFuseContainer.java +++ b/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/MultipleFSTDataProviderRecursiveFuseContainer.java @@ -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 extends PartitionFuseContainer { - public RecursivePartitionFuseContainer(Optional parent, File input) { - super(parent, input); +public class MultipleFSTDataProviderRecursiveFuseContainer extends MultipleFSTDataProviderFuseContainer { + public MultipleFSTDataProviderRecursiveFuseContainer(Optional parent, File input, FSTDataProviderLoader loader) { + super(parent, input, loader); } @Override diff --git a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WUDFuseContainer.java b/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WUDFuseContainer.java deleted file mode 100644 index 27a2805..0000000 --- a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WUDFuseContainer.java +++ /dev/null @@ -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 { - - public WUDFuseContainer(Optional parent, File input) { - super(parent, input); - } - - @Override - protected Optional loadInfo(File input) { - return WUDUtils.loadWUDInfo(input); - } - - @Override - protected List getDataProvider(WUDInfo info) { - List 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; - } -} diff --git a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WUMADFuseContainer.java b/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WUMADFuseContainer.java deleted file mode 100644 index 6ea001a..0000000 --- a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WUMADFuseContainer.java +++ /dev/null @@ -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 { - - public WUMADFuseContainer(Optional parent, File c) { - super(parent, c); - } - - @Override - protected Optional 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 getDataProvider(WumadInfo info) { - List 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; - } - -} diff --git a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WUDMountedFuseContainer.java b/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/loader/WUDFSTDataProviderLoader.java similarity index 65% rename from src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WUDMountedFuseContainer.java rename to src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/loader/WUDFSTDataProviderLoader.java index bf07303..532ab98 100644 --- a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WUDMountedFuseContainer.java +++ b/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/loader/WUDFSTDataProviderLoader.java @@ -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 { - - public WUDMountedFuseContainer(Optional parent, File input) { - super(parent, input); +public class WUDFSTDataProviderLoader implements FSTDataProviderLoader { + @Getter + private static WUDFSTDataProviderLoader instance = new WUDFSTDataProviderLoader(); + + private WUDFSTDataProviderLoader() { } - + @Override - protected List getDataProvider(WUDInfo info) { + public List getDataProvider(WUDInfo info) { List dps = new ArrayList<>(); try { dps = WUDLoader.getPartitonsAsFSTDataProvider(info, Settings.retailCommonKey); @@ -36,8 +38,7 @@ public class WUDMountedFuseContainer extends RecursivePartitionFuseContainer loadInfo(File input) { + public Optional loadInfo(File input) { return WUDUtils.loadWUDInfo(input); } - } diff --git a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WUMADMountedFuseContainer.java b/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/loader/WumadFSTDataProviderLoader.java similarity index 68% rename from src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WUMADMountedFuseContainer.java rename to src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/loader/WumadFSTDataProviderLoader.java index 63e76a6..f85a83d 100644 --- a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WUMADMountedFuseContainer.java +++ b/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/loader/WumadFSTDataProviderLoader.java @@ -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 { - - public WUMADMountedFuseContainer(Optional parent, File c) { - super(parent, c); +public class WumadFSTDataProviderLoader implements FSTDataProviderLoader { + @Getter + private static WumadFSTDataProviderLoader instance = new WumadFSTDataProviderLoader(); + + private WumadFSTDataProviderLoader() { } - + @Override - protected Optional loadInfo(File input) { + public Optional loadInfo(File input) { if (input != null && input.exists()) { try { return Optional.of(WumadLoader.load(input)); @@ -32,7 +34,7 @@ public class WUMADMountedFuseContainer extends RecursivePartitionFuseContainer getDataProvider(WumadInfo info) { + public List getDataProvider(WumadInfo info) { List dps = new ArrayList<>(); try { dps = WumadLoader.getPartitonsAsFSTDataProvider(info, Settings.retailCommonKey); @@ -45,5 +47,4 @@ public class WUMADMountedFuseContainer extends RecursivePartitionFuseContainer { + public Optional loadInfo(File input); + + public List getDataProvider(T info); +} diff --git a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/utils/FuseContainerWrapper.java b/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/utils/FuseContainerWrapper.java index 52d9172..858d3c0 100644 --- a/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/utils/FuseContainerWrapper.java +++ b/src/main/java/de/mas/wiiu/jnus/fuse_wiiu/utils/FuseContainerWrapper.java @@ -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)); }