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

View file

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

View file

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

View file

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

View file

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

View file

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

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.util.List;
public class NspXciExtractor extends Task<Void> {
public class Extractor extends Task<Void> {
private ISuperProvider provider;
private List<IRowModel> models;
@ -17,7 +17,7 @@ public class NspXciExtractor extends Task<Void> {
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.models = models;
this.filesDestPath = filesDestPath;