Refactoring

This commit is contained in:
Dmitry Isaenko 2019-08-24 08:34:29 +03:00
parent 5dcbaff8ac
commit 94cab77aa9
13 changed files with 187 additions and 268 deletions

View file

@ -1,5 +1,6 @@
package konogonka.Controllers.NCA; package konogonka.Controllers.NCA;
import javafx.concurrent.Task;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
@ -8,7 +9,7 @@ import konogonka.Controllers.ITabController;
import konogonka.Tools.ISuperProvider; import konogonka.Tools.ISuperProvider;
import konogonka.Tools.NCA.NCAContentPFS0; import konogonka.Tools.NCA.NCAContentPFS0;
import konogonka.Tools.NCA.NCAProvider; import konogonka.Tools.NCA.NCAProvider;
import konogonka.Workers.AnalyzerNCA; import konogonka.Workers.Analyzer;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
@ -93,11 +94,11 @@ public class NCAController implements ITabController {
keysMap.put(pair[0], pair[1]); keysMap.put(pair[0], pair[1]);
} }
AnalyzerNCA analyzerNCA = new AnalyzerNCA(file, keysMap, offset); Task analyzer = Analyzer.analyzeNCA(file, keysMap, offset);
analyzerNCA.setOnSucceeded(e->{ analyzer.setOnSucceeded(e->{
populateFields(analyzerNCA.getValue()); populateFields((NCAProvider) analyzer.getValue());
}); });
Thread workThread = new Thread(analyzerNCA); Thread workThread = new Thread(analyzer);
workThread.setDaemon(true); workThread.setDaemon(true);
workThread.start(); workThread.start();
} }

View file

@ -1,5 +1,6 @@
package konogonka.Controllers.NPDM; package konogonka.Controllers.NPDM;
import javafx.concurrent.Task;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
@ -8,7 +9,7 @@ import konogonka.Tools.ISuperProvider;
import konogonka.Tools.NPDM.ACI0Provider; import konogonka.Tools.NPDM.ACI0Provider;
import konogonka.Tools.NPDM.ACIDProvider; import konogonka.Tools.NPDM.ACIDProvider;
import konogonka.Tools.NPDM.NPDMProvider; import konogonka.Tools.NPDM.NPDMProvider;
import konogonka.Workers.AnalyzerNPDM; import konogonka.Workers.Analyzer;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
@ -81,26 +82,26 @@ public class NPDMController implements ITabController {
public void analyze(File file) { analyze(file, 0); } public void analyze(File file) { analyze(file, 0); }
@Override @Override
public void analyze(ISuperProvider parentProvider, int fileNo) throws Exception { public void analyze(ISuperProvider parentProvider, int fileNo) throws Exception {
AnalyzerNPDM analyzerNPDM = new AnalyzerNPDM(parentProvider, fileNo); Task analyzer = Analyzer.analyzeNPDM(parentProvider, fileNo);
analyzerNPDM.setOnSucceeded(e->{ analyzer.setOnSucceeded(e->{
NPDMProvider npdm = analyzerNPDM.getValue(); NPDMProvider npdm = (NPDMProvider) analyzer.getValue();
setData(npdm, null); setData(npdm, null);
}); });
Thread workThread = new Thread(analyzerNPDM); Thread workThread = new Thread(analyzer);
workThread.setDaemon(true); workThread.setDaemon(true);
workThread.start(); workThread.start();
} }
@Override @Override
public void analyze(File file, long offset) { public void analyze(File file, long offset) {
AnalyzerNPDM analyzerNPDM = new AnalyzerNPDM(file, offset); Task analyzer = Analyzer.analyzeNPDM(file, offset);
analyzerNPDM.setOnSucceeded(e->{ analyzer.setOnSucceeded(e->{
NPDMProvider npdm = analyzerNPDM.getValue(); NPDMProvider npdm = (NPDMProvider) analyzer.getValue();
if (offset == 0) if (offset == 0)
setData(npdm, file); setData(npdm, file);
else else
setData(npdm, null); setData(npdm, null);
}); });
Thread workThread = new Thread(analyzerNPDM); Thread workThread = new Thread(analyzer);
workThread.setDaemon(true); workThread.setDaemon(true);
workThread.start(); workThread.start();
} }

View file

@ -1,5 +1,6 @@
package konogonka.Controllers.NSP; package konogonka.Controllers.NSP;
import javafx.concurrent.Task;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
@ -9,8 +10,8 @@ import konogonka.MediatorControl;
import konogonka.Tools.ISuperProvider; import konogonka.Tools.ISuperProvider;
import konogonka.Tools.PFS0.IPFS0Provider; import konogonka.Tools.PFS0.IPFS0Provider;
import konogonka.Tools.PFS0.PFS0Provider; import konogonka.Tools.PFS0.PFS0Provider;
import konogonka.Workers.AnalyzerNSP; import konogonka.Workers.Analyzer;
import konogonka.Workers.NspXciExtractor; import konogonka.Workers.Extractor;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
@ -64,8 +65,8 @@ public class NSPController implements ITabController {
extractBtn.setDisable(true); extractBtn.setDisable(true);
//NspXciExtractor extractor = new NspXciExtractor(rawFileDataStart, models, dir.getAbsolutePath()+File.separator, selectedFile); //TODO: REMOVE //Extractor extractor = new Extractor(rawFileDataStart, models, dir.getAbsolutePath()+File.separator, selectedFile); //TODO: REMOVE
NspXciExtractor extractor = new NspXciExtractor(provider, models, dir.getAbsolutePath()+File.separator); Extractor extractor = new Extractor(provider, models, dir.getAbsolutePath()+File.separator);
extractor.setOnSucceeded(e->{ extractor.setOnSucceeded(e->{
extractBtn.setDisable(false); extractBtn.setDisable(false);
}); });
@ -94,17 +95,17 @@ public class NSPController implements ITabController {
* */ * */
@Override @Override
public void analyze(File selectedFile, long offset){ public void analyze(File selectedFile, long offset){
// TODO: IMPLEMENT? // TODO: IMPLEMENT??
return; return;
} }
@Override @Override
public void analyze(File selectedFile){ public void analyze(File selectedFile){
AnalyzerNSP analyzerNSP = new AnalyzerNSP(selectedFile); Task analyzer = Analyzer.analyzePFS0(selectedFile);
analyzerNSP.setOnSucceeded(e->{ analyzer.setOnSucceeded(e->{
PFS0Provider pfs0 = analyzerNSP.getValue(); PFS0Provider pfs0 = (PFS0Provider) analyzer.getValue();
this.setData(pfs0, selectedFile); this.setData(pfs0, selectedFile);
}); });
Thread workThread = new Thread(analyzerNSP); Thread workThread = new Thread(analyzer);
workThread.setDaemon(true); workThread.setDaemon(true);
workThread.start(); workThread.start();
} }

View file

@ -1,5 +1,6 @@
package konogonka.Controllers.TIK; package konogonka.Controllers.TIK;
import javafx.concurrent.Task;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
@ -8,7 +9,7 @@ import konogonka.AppPreferences;
import konogonka.Controllers.ITabController; import konogonka.Controllers.ITabController;
import konogonka.Tools.ISuperProvider; import konogonka.Tools.ISuperProvider;
import konogonka.Tools.TIK.TIKProvider; import konogonka.Tools.TIK.TIKProvider;
import konogonka.Workers.AnalyzerTIK; import konogonka.Workers.Analyzer;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
@ -68,15 +69,15 @@ public class TIKController implements ITabController {
} }
@Override @Override
public void analyze(File file, long offset) { public void analyze(File file, long offset) {
AnalyzerTIK analyzerTIK = new AnalyzerTIK(file, offset); Task analyzer = Analyzer.analyzeTIK(file, offset);
analyzerTIK.setOnSucceeded(e->{ analyzer.setOnSucceeded(e->{
TIKProvider tik = analyzerTIK.getValue(); TIKProvider tik = (TIKProvider) analyzer.getValue();
if (offset == 0) if (offset == 0)
setData(tik, file); setData(tik, file);
else else
setData(tik, null); setData(tik, null);
}); });
Thread workThread = new Thread(analyzerTIK); Thread workThread = new Thread(analyzer);
workThread.setDaemon(true); workThread.setDaemon(true);
workThread.start(); workThread.start();
} }

View file

@ -9,7 +9,7 @@ import konogonka.Controllers.IRowModel;
import konogonka.MediatorControl; import konogonka.MediatorControl;
import konogonka.Tools.ISuperProvider; import konogonka.Tools.ISuperProvider;
import konogonka.Tools.XCI.HFS0Provider; import konogonka.Tools.XCI.HFS0Provider;
import konogonka.Workers.NspXciExtractor; import konogonka.Workers.Extractor;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
@ -106,8 +106,8 @@ public class HFSBlockController implements Initializable {
extractMainBtn.setDisable(true); extractMainBtn.setDisable(true);
System.out.println(dir.getAbsolutePath()+File.separator); System.out.println(dir.getAbsolutePath()+File.separator);
//NspXciExtractor extractor = new NspXciExtractor(bodySize, models, dir.getAbsolutePath()+File.separator, selectedFile); // TODO: REMOVE //Extractor extractor = new Extractor(bodySize, models, dir.getAbsolutePath()+File.separator, selectedFile); // TODO: REMOVE
NspXciExtractor extractor = new NspXciExtractor(provider, models, dir.getAbsolutePath()+File.separator); Extractor extractor = new Extractor(provider, models, dir.getAbsolutePath()+File.separator);
extractor.setOnSucceeded(e->{ extractor.setOnSucceeded(e->{
extractMainBtn.setDisable(false); extractMainBtn.setDisable(false);
}); });

View file

@ -1,5 +1,6 @@
package konogonka.Controllers.XCI; package konogonka.Controllers.XCI;
import javafx.concurrent.Task;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
@ -7,7 +8,7 @@ import konogonka.AppPreferences;
import konogonka.Controllers.ITabController; import konogonka.Controllers.ITabController;
import konogonka.Tools.ISuperProvider; import konogonka.Tools.ISuperProvider;
import konogonka.Tools.XCI.XCIProvider; import konogonka.Tools.XCI.XCIProvider;
import konogonka.Workers.AnalyzerXCI; import konogonka.Workers.Analyzer;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
@ -98,11 +99,11 @@ public class XCIController implements ITabController {
public void analyze(File selectedFile){ public void analyze(File selectedFile){
HFSBlockController.setSelectedFile(selectedFile); HFSBlockController.setSelectedFile(selectedFile);
AnalyzerXCI analyzerXCI = new AnalyzerXCI(selectedFile, AppPreferences.getInstance().getXciHeaderKey()); Task analyzer = Analyzer.analyzeXCI(selectedFile, AppPreferences.getInstance().getXciHeaderKey());
analyzerXCI.setOnSucceeded(e->{ analyzer.setOnSucceeded(e->{
populateFields(analyzerXCI.getValue()); populateFields((XCIProvider) analyzer.getValue());
}); });
Thread workThread = new Thread(analyzerXCI); Thread workThread = new Thread(analyzer);
workThread.setDaemon(true); workThread.setDaemon(true);
workThread.start(); workThread.start();
} }

View file

@ -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<NCAProvider> analyzeNCA(File file, HashMap<String, String> keysMap, long offset){
LogPrinter logPrinter = new LogPrinter();
return new Task<NCAProvider>(){
@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<TIKProvider> analyzeTIK(File file, long offset){
LogPrinter logPrinter = new LogPrinter();
return new Task<TIKProvider>() {
@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<NPDMProvider> analyzeNPDM(File file, long offset){
LogPrinter logPrinter = new LogPrinter();
return new Task<NPDMProvider>(){
@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<NPDMProvider> analyzeNPDM(ISuperProvider parentProvider, int fileNo){
LogPrinter logPrinter = new LogPrinter();
return new Task<NPDMProvider>(){
@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<PFS0Provider> analyzePFS0(File file){
LogPrinter logPrinter = new LogPrinter();
return new Task<PFS0Provider>(){
@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<XCIProvider> analyzeXCI(File file, String xciHdrKey){
LogPrinter logPrinter = new LogPrinter();
return new Task<XCIProvider>() {
@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();
}
}
};
}
}

View file

@ -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<NCAProvider> {
private File file;
private long offset;
private LogPrinter logPrinter;
private HashMap<String, String> keysMap;
public AnalyzerNCA(File file, HashMap<String, String> keysMap){
this(file, keysMap, 0);
}
public AnalyzerNCA(File file, HashMap<String, String> 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;
}
}

View file

@ -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<NPDMProvider> {
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();
}
}

View file

@ -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<PFS0Provider> {
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();
}
}

View file

@ -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<TIKProvider> {
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();
}
}

View file

@ -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<XCIProvider> {
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;
}
}

View file

@ -9,7 +9,7 @@ import konogonka.Tools.ISuperProvider;
import java.io.*; import java.io.*;
import java.util.List; import java.util.List;
public class NspXciExtractor extends Task<Void> { public class Extractor extends Task<Void> {
private ISuperProvider provider; private ISuperProvider provider;
private List<IRowModel> models; private List<IRowModel> models;
@ -17,7 +17,7 @@ public class NspXciExtractor extends Task<Void> {
private String filesDestPath; private String filesDestPath;
public NspXciExtractor(ISuperProvider provider, List<IRowModel> models, String filesDestPath){ public Extractor(ISuperProvider provider, List<IRowModel> models, String filesDestPath){
this.provider = provider; this.provider = provider;
this.models = models; this.models = models;
this.filesDestPath = filesDestPath; this.filesDestPath = filesDestPath;