mirror of
https://github.com/Maschell/fuse-wiiu.git
synced 2024-11-22 06:39:14 +01:00
Move WUDInfo loading into an Util class
This commit is contained in:
parent
53443ef0dc
commit
0e00d6d28a
@ -2,18 +2,15 @@ package de.mas.wiiu.jnus.fuse_wiiu.implementation;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.apache.commons.io.FilenameUtils;
|
|
||||||
|
|
||||||
import de.mas.wiiu.jnus.WUDLoader;
|
import de.mas.wiiu.jnus.WUDLoader;
|
||||||
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.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;
|
import lombok.val;
|
||||||
@ -28,7 +25,7 @@ public class WUDFuseContainer extends GroupFuseContainer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doInit() {
|
protected void doInit() {
|
||||||
Optional<WUDInfo> WUDInfoOpt = loadWUDInfo(input);
|
Optional<WUDInfo> WUDInfoOpt = WUDUtils.loadWUDInfo(input);
|
||||||
if (WUDInfoOpt.isPresent()) {
|
if (WUDInfoOpt.isPresent()) {
|
||||||
parseContents(WUDInfoOpt.get());
|
parseContents(WUDInfoOpt.get());
|
||||||
} else {
|
} else {
|
||||||
@ -36,35 +33,6 @@ public class WUDFuseContainer extends GroupFuseContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<WUDInfo> loadWUDInfo(File file) {
|
|
||||||
String FSfilename = file.getName();
|
|
||||||
String basename = FilenameUtils.getBaseName(FSfilename);
|
|
||||||
File keyFile = new File(file.getParent() + File.separator + basename + ".key");
|
|
||||||
|
|
||||||
if (!keyFile.exists() && Settings.disckeyPath != null) {
|
|
||||||
System.out.println(".key not found at " + keyFile.getAbsolutePath());
|
|
||||||
keyFile = new File(Settings.disckeyPath.getAbsoluteFile() + File.separator + basename + ".key");
|
|
||||||
if (!keyFile.exists()) {
|
|
||||||
System.out.println(".key not found at " + keyFile.getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (keyFile.exists()) {
|
|
||||||
return Optional.of(WUDLoader.load(file.getAbsolutePath(), keyFile));
|
|
||||||
} else {
|
|
||||||
System.out.println("No .key was not found. Trying dev mode.");
|
|
||||||
return Optional.of(WUDLoader.loadDev(file.getAbsolutePath()));
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
StringWriter errors = new StringWriter();
|
|
||||||
e.printStackTrace(new PrintWriter(errors));
|
|
||||||
System.err.println(errors);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void parseContents(WUDInfo wudInfo) {
|
protected void parseContents(WUDInfo wudInfo) {
|
||||||
List<FSTDataProvider> dps = new ArrayList<>();
|
List<FSTDataProvider> dps = new ArrayList<>();
|
||||||
|
|
||||||
@ -75,9 +43,12 @@ public class WUDFuseContainer extends GroupFuseContainer {
|
|||||||
try {
|
try {
|
||||||
dps = WUDLoader.getPartitonsAsFSTDataProvider(wudInfo, Settings.devCommonKey);
|
dps = WUDLoader.getPartitonsAsFSTDataProvider(wudInfo, Settings.devCommonKey);
|
||||||
} catch (IOException | ParseException e1) {
|
} 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) {
|
} 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
44
src/main/java/de/mas/wiiu/jnus/fuse_wiiu/utils/WUDUtils.java
Normal file
44
src/main/java/de/mas/wiiu/jnus/fuse_wiiu/utils/WUDUtils.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package de.mas.wiiu.jnus.fuse_wiiu.utils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
|
||||||
|
import de.mas.wiiu.jnus.WUDLoader;
|
||||||
|
import de.mas.wiiu.jnus.fuse_wiiu.Settings;
|
||||||
|
import de.mas.wiiu.jnus.implementations.wud.parser.WUDInfo;
|
||||||
|
|
||||||
|
public class WUDUtils {
|
||||||
|
public static Optional<WUDInfo> loadWUDInfo(File file) {
|
||||||
|
String FSfilename = file.getName();
|
||||||
|
String basename = FilenameUtils.getBaseName(FSfilename);
|
||||||
|
File keyFile = new File(file.getParent() + File.separator + basename + ".key");
|
||||||
|
|
||||||
|
if (!keyFile.exists() && Settings.disckeyPath != null) {
|
||||||
|
System.out.println(".key not found at " + keyFile.getAbsolutePath());
|
||||||
|
keyFile = new File(Settings.disckeyPath.getAbsoluteFile() + File.separator + basename + ".key");
|
||||||
|
if (!keyFile.exists()) {
|
||||||
|
System.out.println(".key not found at " + keyFile.getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (keyFile.exists()) {
|
||||||
|
return Optional.of(WUDLoader.load(file.getAbsolutePath(), keyFile));
|
||||||
|
} else {
|
||||||
|
System.out.println("No .key was not found. Trying dev mode.");
|
||||||
|
return Optional.of(WUDLoader.loadDev(file.getAbsolutePath()));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
StringWriter errors = new StringWriter();
|
||||||
|
e.printStackTrace(new PrintWriter(errors));
|
||||||
|
System.err.println(errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user