diff --git a/src/main/java/konogonka/Controllers/NCA/NCAController.java b/src/main/java/konogonka/Controllers/NCA/NCAController.java index 3dbf824..58fd610 100644 --- a/src/main/java/konogonka/Controllers/NCA/NCAController.java +++ b/src/main/java/konogonka/Controllers/NCA/NCAController.java @@ -1,5 +1,6 @@ package konogonka.Controllers.NCA; +import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.Label; import javafx.scene.control.TextField; @@ -8,7 +9,7 @@ import konogonka.Controllers.ITabController; import konogonka.Tools.ISuperProvider; import konogonka.Tools.NCA.NCAContentPFS0; import konogonka.Tools.NCA.NCAProvider; -import konogonka.Workers.AnalyzerNCA; +import konogonka.Workers.Analyzer; import java.io.File; import java.net.URL; @@ -93,11 +94,11 @@ public class NCAController implements ITabController { keysMap.put(pair[0], pair[1]); } - AnalyzerNCA analyzerNCA = new AnalyzerNCA(file, keysMap, offset); - analyzerNCA.setOnSucceeded(e->{ - populateFields(analyzerNCA.getValue()); + Task analyzer = Analyzer.analyzeNCA(file, keysMap, offset); + analyzer.setOnSucceeded(e->{ + populateFields((NCAProvider) analyzer.getValue()); }); - Thread workThread = new Thread(analyzerNCA); + Thread workThread = new Thread(analyzer); workThread.setDaemon(true); workThread.start(); } diff --git a/src/main/java/konogonka/Controllers/NPDM/NPDMController.java b/src/main/java/konogonka/Controllers/NPDM/NPDMController.java index 943d58e..2224100 100644 --- a/src/main/java/konogonka/Controllers/NPDM/NPDMController.java +++ b/src/main/java/konogonka/Controllers/NPDM/NPDMController.java @@ -1,5 +1,6 @@ package konogonka.Controllers.NPDM; +import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.Label; import javafx.scene.control.TextField; @@ -8,7 +9,7 @@ import konogonka.Tools.ISuperProvider; import konogonka.Tools.NPDM.ACI0Provider; import konogonka.Tools.NPDM.ACIDProvider; import konogonka.Tools.NPDM.NPDMProvider; -import konogonka.Workers.AnalyzerNPDM; +import konogonka.Workers.Analyzer; import java.io.File; import java.net.URL; @@ -81,26 +82,26 @@ public class NPDMController implements ITabController { public void analyze(File file) { analyze(file, 0); } @Override public void analyze(ISuperProvider parentProvider, int fileNo) throws Exception { - AnalyzerNPDM analyzerNPDM = new AnalyzerNPDM(parentProvider, fileNo); - analyzerNPDM.setOnSucceeded(e->{ - NPDMProvider npdm = analyzerNPDM.getValue(); + Task analyzer = Analyzer.analyzeNPDM(parentProvider, fileNo); + analyzer.setOnSucceeded(e->{ + NPDMProvider npdm = (NPDMProvider) analyzer.getValue(); setData(npdm, null); }); - Thread workThread = new Thread(analyzerNPDM); + Thread workThread = new Thread(analyzer); workThread.setDaemon(true); workThread.start(); } @Override public void analyze(File file, long offset) { - AnalyzerNPDM analyzerNPDM = new AnalyzerNPDM(file, offset); - analyzerNPDM.setOnSucceeded(e->{ - NPDMProvider npdm = analyzerNPDM.getValue(); + Task analyzer = Analyzer.analyzeNPDM(file, offset); + analyzer.setOnSucceeded(e->{ + NPDMProvider npdm = (NPDMProvider) analyzer.getValue(); if (offset == 0) setData(npdm, file); else setData(npdm, null); }); - Thread workThread = new Thread(analyzerNPDM); + Thread workThread = new Thread(analyzer); workThread.setDaemon(true); workThread.start(); } diff --git a/src/main/java/konogonka/Controllers/NSP/NSPController.java b/src/main/java/konogonka/Controllers/NSP/NSPController.java index d285878..88bc3f2 100644 --- a/src/main/java/konogonka/Controllers/NSP/NSPController.java +++ b/src/main/java/konogonka/Controllers/NSP/NSPController.java @@ -1,5 +1,6 @@ package konogonka.Controllers.NSP; +import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.Label; @@ -9,8 +10,8 @@ import konogonka.MediatorControl; import konogonka.Tools.ISuperProvider; import konogonka.Tools.PFS0.IPFS0Provider; import konogonka.Tools.PFS0.PFS0Provider; -import konogonka.Workers.AnalyzerNSP; -import konogonka.Workers.NspXciExtractor; +import konogonka.Workers.Analyzer; +import konogonka.Workers.Extractor; import java.io.File; import java.net.URL; @@ -64,8 +65,8 @@ public class NSPController implements ITabController { extractBtn.setDisable(true); - //NspXciExtractor extractor = new NspXciExtractor(rawFileDataStart, models, dir.getAbsolutePath()+File.separator, selectedFile); //TODO: REMOVE - NspXciExtractor extractor = new NspXciExtractor(provider, models, dir.getAbsolutePath()+File.separator); + //Extractor extractor = new Extractor(rawFileDataStart, models, dir.getAbsolutePath()+File.separator, selectedFile); //TODO: REMOVE + Extractor extractor = new Extractor(provider, models, dir.getAbsolutePath()+File.separator); extractor.setOnSucceeded(e->{ extractBtn.setDisable(false); }); @@ -94,17 +95,17 @@ public class NSPController implements ITabController { * */ @Override public void analyze(File selectedFile, long offset){ - // TODO: IMPLEMENT? + // TODO: IMPLEMENT?? return; } @Override public void analyze(File selectedFile){ - AnalyzerNSP analyzerNSP = new AnalyzerNSP(selectedFile); - analyzerNSP.setOnSucceeded(e->{ - PFS0Provider pfs0 = analyzerNSP.getValue(); + Task analyzer = Analyzer.analyzePFS0(selectedFile); + analyzer.setOnSucceeded(e->{ + PFS0Provider pfs0 = (PFS0Provider) analyzer.getValue(); this.setData(pfs0, selectedFile); }); - Thread workThread = new Thread(analyzerNSP); + Thread workThread = new Thread(analyzer); workThread.setDaemon(true); workThread.start(); } diff --git a/src/main/java/konogonka/Controllers/TIK/TIKController.java b/src/main/java/konogonka/Controllers/TIK/TIKController.java index f85f9f4..ee1f351 100644 --- a/src/main/java/konogonka/Controllers/TIK/TIKController.java +++ b/src/main/java/konogonka/Controllers/TIK/TIKController.java @@ -1,5 +1,6 @@ package konogonka.Controllers.TIK; +import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.Label; @@ -8,7 +9,7 @@ import konogonka.AppPreferences; import konogonka.Controllers.ITabController; import konogonka.Tools.ISuperProvider; import konogonka.Tools.TIK.TIKProvider; -import konogonka.Workers.AnalyzerTIK; +import konogonka.Workers.Analyzer; import java.io.File; import java.net.URL; @@ -68,15 +69,15 @@ public class TIKController implements ITabController { } @Override public void analyze(File file, long offset) { - AnalyzerTIK analyzerTIK = new AnalyzerTIK(file, offset); - analyzerTIK.setOnSucceeded(e->{ - TIKProvider tik = analyzerTIK.getValue(); + Task analyzer = Analyzer.analyzeTIK(file, offset); + analyzer.setOnSucceeded(e->{ + TIKProvider tik = (TIKProvider) analyzer.getValue(); if (offset == 0) setData(tik, file); else setData(tik, null); }); - Thread workThread = new Thread(analyzerTIK); + Thread workThread = new Thread(analyzer); workThread.setDaemon(true); workThread.start(); } diff --git a/src/main/java/konogonka/Controllers/XCI/HFSBlockController.java b/src/main/java/konogonka/Controllers/XCI/HFSBlockController.java index 587f18f..a62419f 100644 --- a/src/main/java/konogonka/Controllers/XCI/HFSBlockController.java +++ b/src/main/java/konogonka/Controllers/XCI/HFSBlockController.java @@ -9,7 +9,7 @@ import konogonka.Controllers.IRowModel; import konogonka.MediatorControl; import konogonka.Tools.ISuperProvider; import konogonka.Tools.XCI.HFS0Provider; -import konogonka.Workers.NspXciExtractor; +import konogonka.Workers.Extractor; import java.io.File; import java.net.URL; @@ -106,8 +106,8 @@ public class HFSBlockController implements Initializable { extractMainBtn.setDisable(true); System.out.println(dir.getAbsolutePath()+File.separator); - //NspXciExtractor extractor = new NspXciExtractor(bodySize, models, dir.getAbsolutePath()+File.separator, selectedFile); // TODO: REMOVE - NspXciExtractor extractor = new NspXciExtractor(provider, models, dir.getAbsolutePath()+File.separator); + //Extractor extractor = new Extractor(bodySize, models, dir.getAbsolutePath()+File.separator, selectedFile); // TODO: REMOVE + Extractor extractor = new Extractor(provider, models, dir.getAbsolutePath()+File.separator); extractor.setOnSucceeded(e->{ extractMainBtn.setDisable(false); }); diff --git a/src/main/java/konogonka/Controllers/XCI/XCIController.java b/src/main/java/konogonka/Controllers/XCI/XCIController.java index aefbb6d..b352df8 100644 --- a/src/main/java/konogonka/Controllers/XCI/XCIController.java +++ b/src/main/java/konogonka/Controllers/XCI/XCIController.java @@ -1,5 +1,6 @@ package konogonka.Controllers.XCI; +import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.Label; import javafx.scene.control.TextField; @@ -7,7 +8,7 @@ import konogonka.AppPreferences; import konogonka.Controllers.ITabController; import konogonka.Tools.ISuperProvider; import konogonka.Tools.XCI.XCIProvider; -import konogonka.Workers.AnalyzerXCI; +import konogonka.Workers.Analyzer; import java.io.File; import java.net.URL; @@ -98,11 +99,11 @@ public class XCIController implements ITabController { public void analyze(File selectedFile){ HFSBlockController.setSelectedFile(selectedFile); - AnalyzerXCI analyzerXCI = new AnalyzerXCI(selectedFile, AppPreferences.getInstance().getXciHeaderKey()); - analyzerXCI.setOnSucceeded(e->{ - populateFields(analyzerXCI.getValue()); + Task analyzer = Analyzer.analyzeXCI(selectedFile, AppPreferences.getInstance().getXciHeaderKey()); + analyzer.setOnSucceeded(e->{ + populateFields((XCIProvider) analyzer.getValue()); }); - Thread workThread = new Thread(analyzerXCI); + Thread workThread = new Thread(analyzer); workThread.setDaemon(true); workThread.start(); } diff --git a/src/main/java/konogonka/Workers/Analyzer.java b/src/main/java/konogonka/Workers/Analyzer.java new file mode 100644 index 0000000..b56a7bc --- /dev/null +++ b/src/main/java/konogonka/Workers/Analyzer.java @@ -0,0 +1,144 @@ +package konogonka.Workers; + +import javafx.concurrent.Task; +import konogonka.ModelControllers.EMsgType; +import konogonka.ModelControllers.LogPrinter; +import konogonka.Tools.ISuperProvider; +import konogonka.Tools.NCA.NCAProvider; +import konogonka.Tools.NPDM.NPDMProvider; +import konogonka.Tools.PFS0.PFS0Provider; +import konogonka.Tools.TIK.TIKProvider; +import konogonka.Tools.XCI.XCIProvider; + +import java.io.File; +import java.util.HashMap; + +// TODO: volatile needed? + +public class Analyzer { + + public static Task analyzeNCA(File file, HashMap keysMap, long offset){ + LogPrinter logPrinter = new LogPrinter(); + + return new Task(){ + @Override + protected NCAProvider call() { + logPrinter.print("\tStart chain: NCA", EMsgType.INFO); + try { + return new NCAProvider(file, keysMap, offset); + } + catch (Exception e){ + logPrinter.print(e.getMessage(), EMsgType.FAIL); + return null; + } + finally { + logPrinter.print("\tEnd chain: NCA", EMsgType.INFO); + logPrinter.close(); + } + } + }; + } + + public static Task analyzeTIK(File file, long offset){ + LogPrinter logPrinter = new LogPrinter(); + return new Task() { + @Override + protected TIKProvider call() { + logPrinter.print("\tStart chain: TIK", EMsgType.INFO); + try{ + return new TIKProvider(file, offset); + } + catch (Exception e){ + logPrinter.print("\tException: "+e.getMessage(), EMsgType.FAIL); + return null; + } + finally { + logPrinter.print("\tEnd chain: TIK", EMsgType.INFO); + logPrinter.close(); + } + } + }; + } + + public static Task analyzeNPDM(File file, long offset){ + LogPrinter logPrinter = new LogPrinter(); + return new Task(){ + @Override + protected NPDMProvider call() { + logPrinter.print("\tStart chain: NPDM", EMsgType.INFO); + try{ + return new NPDMProvider(file, offset); + } + catch (Exception e){ + logPrinter.print("\tException: "+e.getMessage(), EMsgType.FAIL); + return null; + } + finally { + logPrinter.print("\tEnd chain: NPDM", EMsgType.INFO); + logPrinter.close(); + } + } + }; + } + + public static Task analyzeNPDM(ISuperProvider parentProvider, int fileNo){ + LogPrinter logPrinter = new LogPrinter(); + return new Task(){ + @Override + protected NPDMProvider call() { + logPrinter.print("\tStart chain: NPDM [stream]", EMsgType.INFO); + try{ + return new NPDMProvider(parentProvider.getProviderSubFilePipedInpStream(fileNo)); + } + catch (Exception e){ + logPrinter.print("\tException: "+e.getMessage(), EMsgType.FAIL); + return null; + } + finally { + logPrinter.print("\tEnd chain: NPDM [stream]", EMsgType.INFO); + logPrinter.close(); + } + } + }; + } + + public static Task analyzePFS0(File file){ + LogPrinter logPrinter = new LogPrinter(); + return new Task(){ + @Override + protected PFS0Provider call() { + logPrinter.print("\tStart chain: NSP (PFS0)", EMsgType.INFO); + try{ + return new PFS0Provider(file); + } + catch (Exception e){ + logPrinter.print("\tException: "+e.getMessage(), EMsgType.FAIL); + return null; + } + finally { + logPrinter.print("\tEnd chain: NSP (PFS0)", EMsgType.INFO); + logPrinter.close(); + } + } + }; + } + + public static Task analyzeXCI(File file, String xciHdrKey){ + LogPrinter logPrinter = new LogPrinter(); + return new Task() { + @Override + protected XCIProvider call() { + logPrinter.print("\tStart chain: XCI", EMsgType.INFO); + try { + return new XCIProvider(file, xciHdrKey); + } catch (Exception e) { + logPrinter.print(e.getMessage(), EMsgType.FAIL); + return null; + } finally { + logPrinter.print("\tEnd chain: XCI", EMsgType.INFO); + logPrinter.close(); + } + } + }; + } +} diff --git a/src/main/java/konogonka/Workers/AnalyzerNCA.java b/src/main/java/konogonka/Workers/AnalyzerNCA.java deleted file mode 100644 index 3171f85..0000000 --- a/src/main/java/konogonka/Workers/AnalyzerNCA.java +++ /dev/null @@ -1,47 +0,0 @@ -package konogonka.Workers; - -import javafx.concurrent.Task; -import konogonka.ModelControllers.EMsgType; -import konogonka.ModelControllers.LogPrinter; -import konogonka.Tools.NCA.NCAProvider; - -import java.io.File; -import java.util.HashMap; - -public class AnalyzerNCA extends Task { - - private File file; - private long offset; - private LogPrinter logPrinter; - private HashMap keysMap; - - - public AnalyzerNCA(File file, HashMap keysMap){ - this(file, keysMap, 0); - } - - public AnalyzerNCA(File file, HashMap keysMap, long offset){ - this.file = file; - this.offset = offset; - this.logPrinter = new LogPrinter(); - this.keysMap = keysMap; - } - - @Override - protected NCAProvider call() { - logPrinter.print("\tStart chain: NCA", EMsgType.INFO); - - NCAProvider ncaProvider; - - try { - ncaProvider = new NCAProvider(file, keysMap, offset); - }catch (Exception e){ - logPrinter.print(e.getMessage(), EMsgType.FAIL); - ncaProvider = null; - }finally { - logPrinter.print("\tEnd chain: NCA", EMsgType.INFO); - logPrinter.close(); - } - return ncaProvider; - } -} diff --git a/src/main/java/konogonka/Workers/AnalyzerNPDM.java b/src/main/java/konogonka/Workers/AnalyzerNPDM.java deleted file mode 100644 index a45b1a4..0000000 --- a/src/main/java/konogonka/Workers/AnalyzerNPDM.java +++ /dev/null @@ -1,59 +0,0 @@ -package konogonka.Workers; - -import javafx.concurrent.Task; -import konogonka.ModelControllers.EMsgType; -import konogonka.ModelControllers.LogPrinter; -import konogonka.Tools.ISuperProvider; -import konogonka.Tools.NPDM.NPDMProvider; - -import java.io.File; - -public class AnalyzerNPDM extends Task { - - private File file; - private long offset; - private LogPrinter logPrinter; - - private ISuperProvider parentProvider; - private int fileNo; - - public AnalyzerNPDM(ISuperProvider parentProvider, int fileNo){ - this.parentProvider = parentProvider; - this.fileNo = fileNo; - this.logPrinter = new LogPrinter(); - } - - public AnalyzerNPDM(File file){ - this(file, 0); - } - - public AnalyzerNPDM(File file, long offset){ - this.file = file; - this.offset = offset; - this.logPrinter = new LogPrinter(); - } - - @Override - protected NPDMProvider call() { - logPrinter.print("\tStart chain: NPDM", EMsgType.INFO); - try{ - if (parentProvider != null) - return new NPDMProvider(parentProvider.getProviderSubFilePipedInpStream(fileNo)); - else - return new NPDMProvider(file, offset); - } - catch (Exception e){ - logPrinter.print("\tException: "+e.getMessage(), EMsgType.FAIL); - return null; - } - finally { - close(); - } - } - - private void close(){ - logPrinter.print("\tEnd chain: NPDM", EMsgType.INFO); - logPrinter.close(); - } -} - diff --git a/src/main/java/konogonka/Workers/AnalyzerNSP.java b/src/main/java/konogonka/Workers/AnalyzerNSP.java deleted file mode 100644 index d5190e7..0000000 --- a/src/main/java/konogonka/Workers/AnalyzerNSP.java +++ /dev/null @@ -1,40 +0,0 @@ -package konogonka.Workers; - -import javafx.concurrent.Task; -import konogonka.ModelControllers.EMsgType; -import konogonka.ModelControllers.LogPrinter; -import konogonka.Tools.PFS0.PFS0Provider; - - -import java.io.File; - -public class AnalyzerNSP extends Task { - - private File file; - private LogPrinter logPrinter; - - public AnalyzerNSP(File file){ - this.file = file; - this.logPrinter = new LogPrinter(); - } - - @Override - protected PFS0Provider call() { - logPrinter.print("\tStart chain: NSP", EMsgType.INFO); - try{ - return new PFS0Provider(file); - } - catch (Exception e){ - logPrinter.print("\tException: "+e.getMessage(), EMsgType.FAIL); - return null; - } - finally { - close(); - } - } - - private void close(){ - logPrinter.print("\tEnd chain: NSP", EMsgType.INFO); - logPrinter.close(); - } -} diff --git a/src/main/java/konogonka/Workers/AnalyzerTIK.java b/src/main/java/konogonka/Workers/AnalyzerTIK.java deleted file mode 100644 index 568421b..0000000 --- a/src/main/java/konogonka/Workers/AnalyzerTIK.java +++ /dev/null @@ -1,45 +0,0 @@ -package konogonka.Workers; - -import javafx.concurrent.Task; -import konogonka.ModelControllers.EMsgType; -import konogonka.ModelControllers.LogPrinter; -import konogonka.Tools.TIK.TIKProvider; - -import java.io.File; - -public class AnalyzerTIK extends Task { - - private File file; - private long offset; - private LogPrinter logPrinter; - - public AnalyzerTIK(File file){ - this(file, 0); - } - - public AnalyzerTIK(File file, long offset){ - this.file = file; - this.offset = offset; - this.logPrinter = new LogPrinter(); - } - - @Override - protected TIKProvider call() { - logPrinter.print("\tStart chain: TIK", EMsgType.INFO); - try{ - return new TIKProvider(file, offset); - } - catch (Exception e){ - logPrinter.print("\tException: "+e.getMessage(), EMsgType.FAIL); - return null; - } - finally { - close(); - } - } - - private void close(){ - logPrinter.print("\tEnd chain: TIK", EMsgType.INFO); - logPrinter.close(); - } -} diff --git a/src/main/java/konogonka/Workers/AnalyzerXCI.java b/src/main/java/konogonka/Workers/AnalyzerXCI.java deleted file mode 100644 index 778fdb9..0000000 --- a/src/main/java/konogonka/Workers/AnalyzerXCI.java +++ /dev/null @@ -1,39 +0,0 @@ -package konogonka.Workers; - -import javafx.concurrent.Task; -import konogonka.ModelControllers.EMsgType; -import konogonka.ModelControllers.LogPrinter; -import konogonka.Tools.XCI.XCIProvider; - -import java.io.File; - -public class AnalyzerXCI extends Task { - - private File file; - private LogPrinter logPrinter; - private String xciHdrKey; - - public AnalyzerXCI(File file, String xciHdrKey){ - this.file = file; - this.logPrinter = new LogPrinter(); - this.xciHdrKey = xciHdrKey; - } - - @Override - protected XCIProvider call() { - logPrinter.print("\tStart chain: XCI", EMsgType.INFO); - - XCIProvider xciProvider; - - try { - xciProvider = new XCIProvider(file, xciHdrKey); - }catch (Exception e){ - logPrinter.print(e.getMessage(), EMsgType.FAIL); - xciProvider = null; - }finally { - logPrinter.print("\tEnd chain: XCI", EMsgType.INFO); - logPrinter.close(); - } - return xciProvider; - } -} diff --git a/src/main/java/konogonka/Workers/NspXciExtractor.java b/src/main/java/konogonka/Workers/Extractor.java similarity index 94% rename from src/main/java/konogonka/Workers/NspXciExtractor.java rename to src/main/java/konogonka/Workers/Extractor.java index 19756f9..2f7b490 100644 --- a/src/main/java/konogonka/Workers/NspXciExtractor.java +++ b/src/main/java/konogonka/Workers/Extractor.java @@ -9,7 +9,7 @@ import konogonka.Tools.ISuperProvider; import java.io.*; import java.util.List; -public class NspXciExtractor extends Task { +public class Extractor extends Task { private ISuperProvider provider; private List models; @@ -17,7 +17,7 @@ public class NspXciExtractor extends Task { private String filesDestPath; - public NspXciExtractor(ISuperProvider provider, List models, String filesDestPath){ + public Extractor(ISuperProvider provider, List models, String filesDestPath){ this.provider = provider; this.models = models; this.filesDestPath = filesDestPath;