Refactor some old UI-related code. Rewrite LogPrinter to handle commandline. Add RCM-payload module into CLI interface: now it could be executed on system without graphical environment (x86/amd64 only).

E.g.: java -jar app.jar --rcm payload.bin
This commit is contained in:
Dmitry Isaenko 2020-07-03 04:01:20 +03:00
parent 255c926184
commit 6b65c74c9d
23 changed files with 328 additions and 154 deletions

View file

@ -8,7 +8,7 @@
<name>NS-USBloader</name> <name>NS-USBloader</name>
<artifactId>ns-usbloader</artifactId> <artifactId>ns-usbloader</artifactId>
<version>3.0-SNAPSHOT</version> <version>4.0-SNAPSHOT</version>
<url>https://github.com/developersu/ns-usbloader/</url> <url>https://github.com/developersu/ns-usbloader/</url>
<description> <description>

View file

@ -19,8 +19,9 @@
package nsusbloader.COM.NET; package nsusbloader.COM.NET;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EFileStatus; import nsusbloader.NSLDataTypes.EFileStatus;
import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.ModelControllers.Log;
import nsusbloader.NSLDataTypes.EModule; import nsusbloader.NSLDataTypes.EModule;
import nsusbloader.NSLDataTypes.EMsgType; import nsusbloader.NSLDataTypes.EMsgType;
import nsusbloader.COM.Helpers.NSSplitReader; import nsusbloader.COM.Helpers.NSSplitReader;
@ -33,7 +34,7 @@ import java.util.*;
public class NETCommunications extends Task<Void> { // todo: thows IOException? public class NETCommunications extends Task<Void> { // todo: thows IOException?
private LogPrinter logPrinter; private ILogPrinter logPrinter;
private String hostIP; private String hostIP;
private int hostPort; private int hostPort;
@ -61,7 +62,7 @@ public class NETCommunications extends Task<Void> { // todo: thows IOException?
else else
this.extras = ""; this.extras = "";
this.switchIP = switchIP; this.switchIP = switchIP;
this.logPrinter = new LogPrinter(EModule.USB_NET_TRANSFERS); this.logPrinter = Log.getPrinter(EModule.USB_NET_TRANSFERS);
this.nspMap = new HashMap<>(); this.nspMap = new HashMap<>();
this.nspFileSizes = new HashMap<>(); this.nspFileSizes = new HashMap<>();
// Filter and remove empty/incorrect split-files // Filter and remove empty/incorrect split-files

View file

@ -22,7 +22,7 @@ import javafx.application.Platform;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import nsusbloader.MediatorControl; import nsusbloader.MediatorControl;
import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EMsgType; import nsusbloader.NSLDataTypes.EMsgType;
import nsusbloader.COM.Helpers.NSSplitReader; import nsusbloader.COM.Helpers.NSSplitReader;
import org.usb4java.DeviceHandle; import org.usb4java.DeviceHandle;
@ -69,7 +69,7 @@ class GoldLeaf extends TransferModule {
// For using in CMD_SelectFile with SPEC:/ prefix // For using in CMD_SelectFile with SPEC:/ prefix
private File selectedFile; private File selectedFile;
GoldLeaf(DeviceHandle handler, LinkedHashMap<String, File> nspMap, Task<Void> task, LogPrinter logPrinter, boolean nspFilter){ GoldLeaf(DeviceHandle handler, LinkedHashMap<String, File> nspMap, Task<Void> task, ILogPrinter logPrinter, boolean nspFilter){
super(handler, nspMap, task, logPrinter); super(handler, nspMap, task, logPrinter);
final byte CMD_GetDriveCount = 1; final byte CMD_GetDriveCount = 1;

View file

@ -19,7 +19,7 @@
package nsusbloader.COM.USB; package nsusbloader.COM.USB;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EFileStatus; import nsusbloader.NSLDataTypes.EFileStatus;
import nsusbloader.NSLDataTypes.EMsgType; import nsusbloader.NSLDataTypes.EMsgType;
import nsusbloader.COM.Helpers.NSSplitReader; import nsusbloader.COM.Helpers.NSSplitReader;
@ -53,7 +53,7 @@ public class GoldLeaf_05 extends TransferModule {
private RandomAccessFile raf; // NSP File private RandomAccessFile raf; // NSP File
private NSSplitReader nsr; // It'a also NSP File private NSSplitReader nsr; // It'a also NSP File
GoldLeaf_05(DeviceHandle handler, LinkedHashMap<String, File> nspMap, Task<Void> task, LogPrinter logPrinter){ GoldLeaf_05(DeviceHandle handler, LinkedHashMap<String, File> nspMap, Task<Void> task, ILogPrinter logPrinter){
super(handler, nspMap, task, logPrinter); super(handler, nspMap, task, logPrinter);
status = EFileStatus.FAILED; status = EFileStatus.FAILED;

View file

@ -23,7 +23,7 @@ import javafx.concurrent.Task;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import nsusbloader.COM.Helpers.NSSplitReader; import nsusbloader.COM.Helpers.NSSplitReader;
import nsusbloader.MediatorControl; import nsusbloader.MediatorControl;
import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EMsgType; import nsusbloader.NSLDataTypes.EMsgType;
import org.usb4java.DeviceHandle; import org.usb4java.DeviceHandle;
import org.usb4java.LibUsb; import org.usb4java.LibUsb;
@ -69,7 +69,7 @@ class GoldLeaf_07 extends TransferModule {
// For using in CMD_SelectFile with SPEC:/ prefix // For using in CMD_SelectFile with SPEC:/ prefix
private File selectedFile; private File selectedFile;
GoldLeaf_07(DeviceHandle handler, LinkedHashMap<String, File> nspMap, Task<Void> task, LogPrinter logPrinter, boolean nspFilter){ GoldLeaf_07(DeviceHandle handler, LinkedHashMap<String, File> nspMap, Task<Void> task, ILogPrinter logPrinter, boolean nspFilter){
super(handler, nspMap, task, logPrinter); super(handler, nspMap, task, logPrinter);
final byte CMD_GetDriveCount = 0x00; final byte CMD_GetDriveCount = 0x00;

View file

@ -18,7 +18,7 @@
*/ */
package nsusbloader.COM.USB.PFS; package nsusbloader.COM.USB.PFS;
import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EMsgType; import nsusbloader.NSLDataTypes.EMsgType;
import java.io.*; import java.io.*;
@ -38,7 +38,7 @@ public class PFSProvider {
private long bodySize; private long bodySize;
private int ticketID = -1; private int ticketID = -1;
public PFSProvider(File nspFile, LogPrinter logPrinter) throws Exception{ public PFSProvider(File nspFile, ILogPrinter logPrinter) throws Exception{
if (nspFile.isDirectory()) { if (nspFile.isDirectory()) {
nspFileName = nspFile.getName(); nspFileName = nspFile.getName();
nspFile = new File(nspFile.getAbsolutePath() + File.separator + "00"); nspFile = new File(nspFile.getAbsolutePath() + File.separator + "00");

View file

@ -19,7 +19,7 @@
package nsusbloader.COM.USB; package nsusbloader.COM.USB;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EFileStatus; import nsusbloader.NSLDataTypes.EFileStatus;
import nsusbloader.NSLDataTypes.EMsgType; import nsusbloader.NSLDataTypes.EMsgType;
import nsusbloader.COM.Helpers.NSSplitReader; import nsusbloader.COM.Helpers.NSSplitReader;
@ -48,7 +48,7 @@ class TinFoil extends TransferModule {
/* byte[] magic = new byte[4]; /* byte[] magic = new byte[4];
ByteBuffer bb = StandardCharsets.UTF_8.encode("TUC0").rewind().get(magic); // Let's rephrase this 'string' */ ByteBuffer bb = StandardCharsets.UTF_8.encode("TUC0").rewind().get(magic); // Let's rephrase this 'string' */
TinFoil(DeviceHandle handler, LinkedHashMap<String, File> nspMap, Task<Void> task, LogPrinter logPrinter){ TinFoil(DeviceHandle handler, LinkedHashMap<String, File> nspMap, Task<Void> task, ILogPrinter logPrinter){
super(handler, nspMap, task, logPrinter); super(handler, nspMap, task, logPrinter);
logPrinter.print("============= Tinfoil =============", EMsgType.INFO); logPrinter.print("============= Tinfoil =============", EMsgType.INFO);

View file

@ -19,7 +19,7 @@
package nsusbloader.COM.USB; package nsusbloader.COM.USB;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EFileStatus; import nsusbloader.NSLDataTypes.EFileStatus;
import nsusbloader.NSLDataTypes.EMsgType; import nsusbloader.NSLDataTypes.EMsgType;
import org.usb4java.DeviceHandle; import org.usb4java.DeviceHandle;
@ -31,11 +31,11 @@ public abstract class TransferModule {
EFileStatus status = EFileStatus.UNKNOWN; EFileStatus status = EFileStatus.UNKNOWN;
LinkedHashMap<String, File> nspMap; LinkedHashMap<String, File> nspMap;
LogPrinter logPrinter; ILogPrinter logPrinter;
DeviceHandle handlerNS; DeviceHandle handlerNS;
Task<Void> task; Task<Void> task;
TransferModule(DeviceHandle handler, LinkedHashMap<String, File> nspMap, Task<Void> task, LogPrinter printer){ TransferModule(DeviceHandle handler, LinkedHashMap<String, File> nspMap, Task<Void> task, ILogPrinter printer){
this.handlerNS = handler; this.handlerNS = handler;
this.nspMap = nspMap; this.nspMap = nspMap;
this.task = task; this.task = task;

View file

@ -19,7 +19,8 @@
package nsusbloader.COM.USB; package nsusbloader.COM.USB;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.ModelControllers.Log;
import nsusbloader.NSLDataTypes.EFileStatus; import nsusbloader.NSLDataTypes.EFileStatus;
import nsusbloader.NSLDataTypes.EModule; import nsusbloader.NSLDataTypes.EModule;
import nsusbloader.NSLDataTypes.EMsgType; import nsusbloader.NSLDataTypes.EMsgType;
@ -32,7 +33,7 @@ import java.util.*;
// TODO: add filter option to show only NSP files // TODO: add filter option to show only NSP files
public class UsbCommunications extends Task<Void> { public class UsbCommunications extends Task<Void> {
private LogPrinter logPrinter; private ILogPrinter logPrinter;
private LinkedHashMap<String, File> nspMap; private LinkedHashMap<String, File> nspMap;
private String protocol; private String protocol;
private boolean nspFilterForGl; private boolean nspFilterForGl;
@ -43,7 +44,7 @@ public class UsbCommunications extends Task<Void> {
this.nspMap = new LinkedHashMap<>(); this.nspMap = new LinkedHashMap<>();
for (File f: nspList) for (File f: nspList)
nspMap.put(f.getName(), f); nspMap.put(f.getName(), f);
this.logPrinter = new LogPrinter(EModule.USB_NET_TRANSFERS); this.logPrinter = Log.getPrinter(EModule.USB_NET_TRANSFERS);
} }
@Override @Override

View file

@ -18,7 +18,7 @@
*/ */
package nsusbloader.COM.USB; package nsusbloader.COM.USB;
import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EMsgType; import nsusbloader.NSLDataTypes.EMsgType;
import org.usb4java.*; import org.usb4java.*;
@ -39,7 +39,7 @@ public class UsbConnect {
private DeviceHandle handlerNS; private DeviceHandle handlerNS;
private Device deviceNS; private Device deviceNS;
private LogPrinter logPrinter; private ILogPrinter logPrinter;
private boolean connected; // TODO: replace to 'connectionFailure' and invert requests everywhere private boolean connected; // TODO: replace to 'connectionFailure' and invert requests everywhere
@ -49,7 +49,7 @@ public class UsbConnect {
private int returningValue; private int returningValue;
private DeviceList deviceList; private DeviceList deviceList;
public static UsbConnect connectRcmMode(LogPrinter logPrinter){ public static UsbConnect connectRcmMode(ILogPrinter logPrinter){
UsbConnect usbConnect = new UsbConnect(logPrinter); UsbConnect usbConnect = new UsbConnect(logPrinter);
usbConnect.VENDOR_ID = RCM_VID; usbConnect.VENDOR_ID = RCM_VID;
usbConnect.PRODUCT_ID = RCM_PID; usbConnect.PRODUCT_ID = RCM_PID;
@ -71,7 +71,7 @@ public class UsbConnect {
return usbConnect; return usbConnect;
} }
public static UsbConnect connectHomebrewMode(LogPrinter logPrinter){ public static UsbConnect connectHomebrewMode(ILogPrinter logPrinter){
UsbConnect usbConnect = new UsbConnect(logPrinter); UsbConnect usbConnect = new UsbConnect(logPrinter);
usbConnect.VENDOR_ID = HOMEBREW_VID; usbConnect.VENDOR_ID = HOMEBREW_VID;
usbConnect.PRODUCT_ID = HOMEBREW_PID; usbConnect.PRODUCT_ID = HOMEBREW_PID;
@ -96,7 +96,7 @@ public class UsbConnect {
private UsbConnect(){} private UsbConnect(){}
private UsbConnect(LogPrinter logPrinter){ private UsbConnect(ILogPrinter logPrinter){
this.logPrinter = logPrinter; this.logPrinter = logPrinter;
this.connected = false; this.connected = false;
}; };

View file

@ -89,10 +89,7 @@ public class FrontController implements Initializable {
} }
} }
// Really bad disable-enable upload button function // Really bad disable-enable upload button function
if (tableFilesListController.isFilesForUploadListEmpty()) disableUploadStopBtn(tableFilesListController.isFilesForUploadListEmpty());
disableUploadStopBtn(true);
else
disableUploadStopBtn(false);
}); // Add listener to notify tableView controller }); // Add listener to notify tableView controller
tableFilesListController.setNewProtocol(choiceProtocol.getSelectionModel().getSelectedItem()); // Notify tableView controller tableFilesListController.setNewProtocol(choiceProtocol.getSelectionModel().getSelectedItem()); // Notify tableView controller
@ -132,10 +129,7 @@ public class FrontController implements Initializable {
this.switchThemeBtn.setOnAction(e->switchTheme()); this.switchThemeBtn.setOnAction(e->switchTheme());
if (getSelectedProtocol().equals("TinFoil")) uploadStopBtn.setDisable(getSelectedProtocol().equals("TinFoil"));
uploadStopBtn.setDisable(true);
else
uploadStopBtn.setDisable(false);
selectNspBtn.setOnAction(e-> selectFilesBtnAction()); selectNspBtn.setOnAction(e-> selectFilesBtnAction());
selectSplitNspBtn.setOnAction(e-> selectSplitBtnAction()); selectSplitNspBtn.setOnAction(e-> selectSplitBtnAction());
@ -157,15 +151,19 @@ public class FrontController implements Initializable {
* Changes UI theme on the go * Changes UI theme on the go
* */ * */
private void switchTheme(){ private void switchTheme(){
if (switchThemeBtn.getScene().getStylesheets().get(0).equals("/res/app_dark.css")) { final String darkTheme = "/res/app_dark.css";
switchThemeBtn.getScene().getStylesheets().remove("/res/app_dark.css"); final String lightTheme = "/res/app_light.css";
switchThemeBtn.getScene().getStylesheets().add("/res/app_light.css"); final ObservableList<String> styleSheets = switchThemeBtn.getScene().getStylesheets();
if (styleSheets.get(0).equals(darkTheme)) {
styleSheets.remove(darkTheme);
styleSheets.add(lightTheme);
} }
else { else {
switchThemeBtn.getScene().getStylesheets().remove("/res/app_light.css"); styleSheets.remove(lightTheme);
switchThemeBtn.getScene().getStylesheets().add("/res/app_dark.css"); styleSheets.add(darkTheme);
} }
AppPreferences.getInstance().setTheme(switchThemeBtn.getScene().getStylesheets().get(0)); AppPreferences.getInstance().setTheme(styleSheets.get(0));
} }
/** /**
* Get selected protocol (GL/TF) * Get selected protocol (GL/TF)
@ -186,8 +184,6 @@ public class FrontController implements Initializable {
return nsIpTextField.getText(); return nsIpTextField.getText();
} }
/*-****************************************************************************************************************-*/
/** /**
* Functionality for selecting NSP button. * Functionality for selecting NSP button.
* */ * */
@ -244,59 +240,60 @@ public class FrontController implements Initializable {
* It's button listener when no transmission executes * It's button listener when no transmission executes
* */ * */
private void uploadBtnAction(){ private void uploadBtnAction(){
if ((workThread == null || !workThread.isAlive())){ if (workThread != null && workThread.isAlive())
return;
// Collect files // Collect files
List<File> nspToUpload; List<File> nspToUpload;
if (tableFilesListController.getFilesForUpload() == null && getSelectedProtocol().equals("TinFoil")) {
MediatorControl.getInstance().getContoller().logArea.setText(resourceBundle.getString("tab3_Txt_NoFolderOrFileSelected")); TextArea logArea = MediatorControl.getInstance().getContoller().logArea;
if (getSelectedProtocol().equals("TinFoil") && tableFilesListController.getFilesForUpload() == null) {
logArea.setText(resourceBundle.getString("tab3_Txt_NoFolderOrFileSelected"));
return; return;
} }
else {
if ((nspToUpload = tableFilesListController.getFilesForUpload()) != null){ if ((nspToUpload = tableFilesListController.getFilesForUpload()) != null){
MediatorControl.getInstance().getContoller().logArea.setText(resourceBundle.getString("tab3_Txt_FilesToUploadTitle")+"\n"); logArea.setText(resourceBundle.getString("tab3_Txt_FilesToUploadTitle")+"\n");
for (File item: nspToUpload) nspToUpload.forEach(item -> logArea.appendText(" "+item.getAbsolutePath()+"\n"));
MediatorControl.getInstance().getContoller().logArea.appendText(" "+item.getAbsolutePath()+"\n");
} }
else { else {
MediatorControl.getInstance().getContoller().logArea.clear(); logArea.clear();
nspToUpload = new LinkedList<>(); nspToUpload = new LinkedList<>();
} }
}
SettingsController settings = MediatorControl.getInstance().getContoller().getSettingsCtrlr();
// If USB selected // If USB selected
if (getSelectedProtocol().equals("GoldLeaf") || if (getSelectedProtocol().equals("GoldLeaf") || ( getSelectedProtocol().equals("TinFoil") && getSelectedNetUsb().equals("USB") ) ){
( getSelectedProtocol().equals("TinFoil") && getSelectedNetUsb().equals("USB") ) usbNetCommunications = new UsbCommunications(nspToUpload, getSelectedProtocol() + settings.getGlOldVer(), settings.getNSPFileFilterForGL());
){
usbNetCommunications = new UsbCommunications(nspToUpload, getSelectedProtocol()+MediatorControl.getInstance().getContoller().getSettingsCtrlr().getGlOldVer(), MediatorControl.getInstance().getContoller().getSettingsCtrlr().getNSPFileFilterForGL());
workThread = new Thread(usbNetCommunications);
workThread.setDaemon(true);
workThread.start();
} }
else { // NET INSTALL OVER TINFOIL else { // NET INSTALL OVER TINFOIL
if (MediatorControl.getInstance().getContoller().getSettingsCtrlr().isNsIpValidate() && ! getNsIp().matches("^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$")) final String ipValidationPattern = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
if (!ServiceWindow.getConfirmationWindow(resourceBundle.getString("windowTitleBadIp"),resourceBundle.getString("windowBodyBadIp")))
if (settings.isNsIpValidate() && ! getNsIp().matches(ipValidationPattern)) {
if (!ServiceWindow.getConfirmationWindow(resourceBundle.getString("windowTitleBadIp"), resourceBundle.getString("windowBodyBadIp")))
return; return;
}
String nsIP = getNsIp(); String nsIP = getNsIp();
if (! MediatorControl.getInstance().getContoller().getSettingsCtrlr().getExpertModeSelected()) if (! settings.getExpertModeSelected())
usbNetCommunications = new NETCommunications(nspToUpload, nsIP, false, "", "", ""); usbNetCommunications = new NETCommunications(nspToUpload, nsIP, false, "", "", "");
else { else {
usbNetCommunications = new NETCommunications( usbNetCommunications = new NETCommunications(
nspToUpload, nspToUpload,
nsIP, nsIP,
MediatorControl.getInstance().getContoller().getSettingsCtrlr().getNotServeSelected(), settings.getNotServeSelected(),
MediatorControl.getInstance().getContoller().getSettingsCtrlr().getAutoIpSelected()?"":MediatorControl.getInstance().getContoller().getSettingsCtrlr().getHostIp(), settings.getAutoIpSelected()?"":settings.getHostIp(),
MediatorControl.getInstance().getContoller().getSettingsCtrlr().getRandPortSelected()?"":MediatorControl.getInstance().getContoller().getSettingsCtrlr().getHostPort(), settings.getRandPortSelected()?"":settings.getHostPort(),
MediatorControl.getInstance().getContoller().getSettingsCtrlr().getNotServeSelected()?MediatorControl.getInstance().getContoller().getSettingsCtrlr().getHostExtra():"" settings.getNotServeSelected()?settings.getHostExtra():""
); );
} }
}
workThread = new Thread(usbNetCommunications); workThread = new Thread(usbNetCommunications);
workThread.setDaemon(true); workThread.setDaemon(true);
workThread.start(); workThread.start();
} }
}
}
/** /**
* It's button listener when transmission in progress * It's button listener when transmission in progress
* */ * */
@ -320,10 +317,11 @@ public class FrontController implements Initializable {
@FXML @FXML
private void handleDrop(DragEvent event){ private void handleDrop(DragEvent event){
List<File> filesDropped = event.getDragboard().getFiles(); List<File> filesDropped = event.getDragboard().getFiles();
SettingsController settingsController = MediatorControl.getInstance().getContoller().getSettingsCtrlr();
if (getSelectedProtocol().equals("TinFoil") && MediatorControl.getInstance().getContoller().getSettingsCtrlr().getTfXciNszXczSupport()) if (getSelectedProtocol().equals("TinFoil") && settingsController.getTfXciNszXczSupport())
filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches("(.*\\.nsp$)|(.*\\.xci$)|(.*\\.nsz$)|(.*\\.xcz$)")); filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches("(.*\\.nsp$)|(.*\\.xci$)|(.*\\.nsz$)|(.*\\.xcz$)"));
else if (getSelectedProtocol().equals("GoldLeaf") && (! MediatorControl.getInstance().getContoller().getSettingsCtrlr().getNSPFileFilterForGL())) else if (getSelectedProtocol().equals("GoldLeaf") && (! settingsController.getNSPFileFilterForGL()))
filesDropped.removeIf(file -> (file.isDirectory() && ! file.getName().toLowerCase().matches(".*\\.nsp$"))); filesDropped.removeIf(file -> (file.isDirectory() && ! file.getName().toLowerCase().matches(".*\\.nsp$")));
else else
filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches(".*\\.nsp$")); filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches(".*\\.nsp$"));
@ -339,7 +337,7 @@ public class FrontController implements Initializable {
* Called from mediator * Called from mediator
* TODO: remove shitcoding practices * TODO: remove shitcoding practices
* */ * */
public void notifyTransmThreadStarted(boolean isActive, EModule type){ public void notifyThreadStarted(boolean isActive, EModule type){
if (! type.equals(EModule.USB_NET_TRANSFERS)){ if (! type.equals(EModule.USB_NET_TRANSFERS)){
usbNetPane.setDisable(isActive); usbNetPane.setDisable(isActive);
return; return;

View file

@ -18,7 +18,6 @@
*/ */
package nsusbloader.Controllers; package nsusbloader.Controllers;
import javafx.concurrent.Task;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
@ -36,7 +35,7 @@ import nsusbloader.AppPreferences;
import nsusbloader.MediatorControl; import nsusbloader.MediatorControl;
import nsusbloader.NSLDataTypes.EModule; import nsusbloader.NSLDataTypes.EModule;
import nsusbloader.ServiceWindow; import nsusbloader.ServiceWindow;
import nsusbloader.Utilities.RcmTask; import nsusbloader.Utilities.Rcm;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
@ -199,37 +198,32 @@ public class RcmController implements Initializable {
return; return;
} }
Task<Boolean> RcmTask; Rcm rcmTask;
RadioButton selectedRadio = (RadioButton)rcmToggleGrp.getSelectedToggle(); RadioButton selectedRadio = (RadioButton)rcmToggleGrp.getSelectedToggle();
switch (selectedRadio.getId()){ switch (selectedRadio.getId()){
case "pldrRadio1": case "pldrRadio1":
RcmTask = new RcmTask(payloadFPathLbl1.getText()); rcmTask = new Rcm(payloadFPathLbl1.getText());
break; break;
case "pldrRadio2": case "pldrRadio2":
RcmTask = new RcmTask(payloadFPathLbl2.getText()); rcmTask = new Rcm(payloadFPathLbl2.getText());
break; break;
case "pldrRadio3": case "pldrRadio3":
RcmTask = new RcmTask(payloadFPathLbl3.getText()); rcmTask = new Rcm(payloadFPathLbl3.getText());
break; break;
case "pldrRadio4": case "pldrRadio4":
RcmTask = new RcmTask(payloadFPathLbl4.getText()); rcmTask = new Rcm(payloadFPathLbl4.getText());
break; break;
case "pldrRadio5": case "pldrRadio5":
RcmTask = new RcmTask(payloadFPathLbl5.getText()); rcmTask = new Rcm(payloadFPathLbl5.getText());
break; break;
default: default:
return; return;
} }
RcmTask.setOnSucceeded(event -> { Thread rcmThread = new Thread(rcmTask);
if (RcmTask.getValue())
statusLbl.setText(rb.getString("done_txt")); rcmThread.setDaemon(true);
else rcmThread.start();
statusLbl.setText(rb.getString("failure_txt"));
});
Thread RcmThread = new Thread(RcmTask);
RcmThread.setDaemon(true);
RcmThread.start();
} }
@FXML @FXML
@ -328,7 +322,14 @@ public class RcmController implements Initializable {
} }
} }
public void notifySmThreadStarted(boolean isStart, EModule type){ public void setOneLineStatus(boolean statusSuccess){
if (statusSuccess)
statusLbl.setText(rb.getString("done_txt"));
else
statusLbl.setText(rb.getString("failure_txt"));
}
public void notifyThreadStarted(boolean isStart, EModule type){
rcmToolPane.setDisable(isStart); rcmToolPane.setDisable(isStart);
if (type.equals(EModule.RCM) && isStart){ if (type.equals(EModule.RCM) && isStart){
MediatorControl.getInstance().getContoller().logArea.clear(); MediatorControl.getInstance().getContoller().logArea.clear();

View file

@ -41,9 +41,9 @@ public class MediatorControl {
public synchronized void setBgThreadActive(boolean isActive, EModule appModuleType) { public synchronized void setBgThreadActive(boolean isActive, EModule appModuleType) {
isTransferActive.set(isActive); isTransferActive.set(isActive);
mainCtrler.getFrontCtrlr().notifyTransmThreadStarted(isActive, appModuleType); mainCtrler.getFrontCtrlr().notifyThreadStarted(isActive, appModuleType);
mainCtrler.getSmCtrlr().notifySmThreadStarted(isActive, appModuleType); mainCtrler.getSmCtrlr().notifySmThreadStarted(isActive, appModuleType);
mainCtrler.getRcmCtrlr().notifySmThreadStarted(isActive, appModuleType); mainCtrler.getRcmCtrlr().notifyThreadStarted(isActive, appModuleType);
mainCtrler.getNXDTabController().notifyThreadStarted(isActive, appModuleType); mainCtrler.getNXDTabController().notifyThreadStarted(isActive, appModuleType);
} }
public synchronized boolean getTransferActive() { return this.isTransferActive.get(); } public synchronized boolean getTransferActive() { return this.isTransferActive.get(); }

View file

@ -0,0 +1,35 @@
/*
Copyright 2019-2020 Dmitry Isaenko
This file is part of NS-USBloader.
NS-USBloader is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
NS-USBloader is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
*/
package nsusbloader.ModelControllers;
import nsusbloader.NSLDataTypes.EFileStatus;
import nsusbloader.NSLDataTypes.EMsgType;
import java.io.File;
import java.util.HashMap;
public interface ILogPrinter {
void print(String message, EMsgType type);
void updateProgress(Double value);
void update(HashMap<String, File> nspMap, EFileStatus status);
void update(File file, EFileStatus status);
void updateOneLinerStatus(boolean status);
void close();
}

View file

@ -0,0 +1,34 @@
/*
Copyright 2019-2020 Dmitry Isaenko
This file is part of NS-USBloader.
NS-USBloader is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
NS-USBloader is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
*/
package nsusbloader.ModelControllers;
import nsusbloader.NSLDataTypes.EModule;
import nsusbloader.NSLMain;
public class Log {
private Log(){}
public static ILogPrinter getPrinter(EModule whoIsAsking){
if (NSLMain.isCli)
return new LogPrinterCli();
else
return new LogPrinterGui(whoIsAsking);
}
}

View file

@ -0,0 +1,42 @@
package nsusbloader.ModelControllers;
import nsusbloader.NSLDataTypes.EFileStatus;
import nsusbloader.NSLDataTypes.EMsgType;
import java.io.File;
import java.util.HashMap;
public class LogPrinterCli implements ILogPrinter{
@Override
public void print(String message, EMsgType type) {
switch (type){
case PASS:
System.out.println("P: "+message);
break;
case FAIL:
System.out.println("F: "+message);
break;
case INFO:
System.out.println("I: "+message);
break;
case WARNING:
System.out.println("W: "+message);
break;
default:
System.out.println(message);
}
}
@Override
public void updateProgress(Double value) { }
@Override
public void update(HashMap<String, File> nspMap, EFileStatus status) { }
@Override
public void update(File file, EFileStatus status) { }
@Override
public void updateOneLinerStatus(boolean status){ }
@Override
public void close() {
System.out.println("\n-\n");
}
}

View file

@ -26,23 +26,27 @@ import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;
public class LogPrinter { public class LogPrinterGui implements ILogPrinter {
private MessagesConsumer msgConsumer; private final MessagesConsumer msgConsumer;
private BlockingQueue<String> msgQueue; private final BlockingQueue<String> msgQueue;
private BlockingQueue<Double> progressQueue; private final BlockingQueue<Double> progressQueue;
private HashMap<String, EFileStatus> statusMap; // BlockingQueue for literally one object. TODO: read more books ; replace to hashMap private final HashMap<String, EFileStatus> statusMap; // BlockingQueue for literally one object. TODO: read more books ; replace to hashMap
private AtomicBoolean oneLinerStatus;
public LogPrinter(EModule whoIsAsking){ public LogPrinterGui(EModule whoIsAsking){
this.msgQueue = new LinkedBlockingQueue<>(); this.msgQueue = new LinkedBlockingQueue<>();
this.progressQueue = new LinkedBlockingQueue<>(); this.progressQueue = new LinkedBlockingQueue<>();
this.statusMap = new HashMap<>(); this.statusMap = new HashMap<>();
this.msgConsumer = new MessagesConsumer(whoIsAsking, this.msgQueue, this.progressQueue, this.statusMap); this.oneLinerStatus = new AtomicBoolean();
this.msgConsumer = new MessagesConsumer(whoIsAsking, this.msgQueue, this.progressQueue, this.statusMap, this.oneLinerStatus);
this.msgConsumer.start(); this.msgConsumer.start();
} }
/** /**
* This is what will print to textArea of the application. * This is what will print to textArea of the application.
* */ * */
@Override
public void print(String message, EMsgType type){ public void print(String message, EMsgType type){
try { try {
switch (type){ switch (type){
@ -69,6 +73,7 @@ public class LogPrinter {
/** /**
* Update progress for progress bar * Update progress for progress bar
* */ * */
@Override
public void updateProgress(Double value) { public void updateProgress(Double value) {
try { try {
progressQueue.put(value); progressQueue.put(value);
@ -78,6 +83,7 @@ public class LogPrinter {
/** /**
* When we're done - update status * When we're done - update status
* */ * */
@Override
public void update(HashMap<String, File> nspMap, EFileStatus status){ public void update(HashMap<String, File> nspMap, EFileStatus status){
for (File file: nspMap.values()) for (File file: nspMap.values())
statusMap.putIfAbsent(file.getName(), status); statusMap.putIfAbsent(file.getName(), status);
@ -85,12 +91,19 @@ public class LogPrinter {
/** /**
* When we're done - update status * When we're done - update status
* */ * */
@Override
public void update(File file, EFileStatus status){ public void update(File file, EFileStatus status){
statusMap.putIfAbsent(file.getName(), status); statusMap.putIfAbsent(file.getName(), status);
} }
@Override
public void updateOneLinerStatus(boolean status){
oneLinerStatus.set(status);
}
/** /**
* When we're done - close it * When we're done - close it
* */ * */
@Override
public void close(){ public void close(){
msgConsumer.interrupt(); msgConsumer.interrupt();
} }

View file

@ -26,10 +26,12 @@ import nsusbloader.Controllers.NSTableViewController;
import nsusbloader.MediatorControl; import nsusbloader.MediatorControl;
import nsusbloader.NSLDataTypes.EFileStatus; import nsusbloader.NSLDataTypes.EFileStatus;
import nsusbloader.NSLDataTypes.EModule; import nsusbloader.NSLDataTypes.EModule;
import nsusbloader.NSLDataTypes.EMsgType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;
public class MessagesConsumer extends AnimationTimer { public class MessagesConsumer extends AnimationTimer {
private final BlockingQueue<String> msgQueue; private final BlockingQueue<String> msgQueue;
@ -41,9 +43,15 @@ public class MessagesConsumer extends AnimationTimer {
private final NSTableViewController tableViewController; private final NSTableViewController tableViewController;
private final EModule appModuleType; private final EModule appModuleType;
private AtomicBoolean oneLinerStatus;
private boolean isInterrupted; private boolean isInterrupted;
MessagesConsumer(EModule appModuleType, BlockingQueue<String> msgQueue, BlockingQueue<Double> progressQueue, HashMap<String, EFileStatus> statusMap){ MessagesConsumer(EModule appModuleType,
BlockingQueue<String> msgQueue,
BlockingQueue<Double> progressQueue,
HashMap<String, EFileStatus> statusMap,
AtomicBoolean oneLinerStatus) {
this.appModuleType = appModuleType; this.appModuleType = appModuleType;
this.isInterrupted = false; this.isInterrupted = false;
@ -56,6 +64,8 @@ public class MessagesConsumer extends AnimationTimer {
this.statusMap = statusMap; this.statusMap = statusMap;
this.tableViewController = MediatorControl.getInstance().getContoller().FrontTabController.tableFilesListController; this.tableViewController = MediatorControl.getInstance().getContoller().FrontTabController.tableFilesListController;
this.oneLinerStatus = oneLinerStatus;
progressBar.setProgress(0.0); progressBar.setProgress(0.0);
progressBar.setProgress(ProgressIndicator.INDETERMINATE_PROGRESS); progressBar.setProgress(ProgressIndicator.INDETERMINATE_PROGRESS);
@ -84,9 +94,15 @@ public class MessagesConsumer extends AnimationTimer {
MediatorControl.getInstance().setBgThreadActive(false, appModuleType); MediatorControl.getInstance().setBgThreadActive(false, appModuleType);
progressBar.setProgress(0.0); progressBar.setProgress(0.0);
if (statusMap.size() > 0) if (statusMap.size() > 0){
for (String key : statusMap.keySet()) for (String key : statusMap.keySet())
tableViewController.setFileStatus(key, statusMap.get(key)); tableViewController.setFileStatus(key, statusMap.get(key));
}
//TODO: rewrite
if (appModuleType.equals(EModule.RCM)){
MediatorControl.getInstance().getContoller().getRcmCtrlr().setOneLineStatus(oneLinerStatus.get());
}
this.stop(); this.stop();
} }
} }

View file

@ -25,14 +25,17 @@ import javafx.scene.Scene;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.stage.Stage; import javafx.stage.Stage;
import nsusbloader.Controllers.NSLMainController; import nsusbloader.Controllers.NSLMainController;
import nsusbloader.Utilities.Rcm;
import java.io.File;
import java.util.Locale; import java.util.Locale;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.prefs.Preferences; import java.util.prefs.Preferences;
public class NSLMain extends Application { public class NSLMain extends Application {
public static final String appVersion = "v3.0"; public static final String appVersion = "v4.0";
public static boolean isCli;
@Override @Override
public void start(Stage primaryStage) throws Exception{ public void start(Stage primaryStage) throws Exception{
@ -86,9 +89,11 @@ public class NSLMain extends Application {
} }
private static boolean handleCli(String[] args){ private static boolean handleCli(String[] args){
if (args.length != 1) if (args.length == 0)
return false; return false;
NSLMain.isCli = true;
try { try {
switch (args[0]) { switch (args[0]) {
case "-v": case "-v":
@ -104,19 +109,44 @@ public class NSLMain extends Application {
else else
System.out.println("Nothing to remove"); System.out.println("Nothing to remove");
return true; return true;
case "--rcm": // TODO: rewrite
if (args.length < 2){
System.out.println("No payload file specified. Expected:\n"
+ "... file.jar --rcm payload.bin\n" + "or\n"
+ "... file.jar --rcm /home/user/payload.bin\n");
return true;
}
boolean isWindows = false;
if (System.getProperty("os.name").toLowerCase().replace(" ", "").contains("windows"))
isWindows = true;
if (isWindows) {
if (! args[1].matches("^.:\\\\.*$"))
args[1] = System.getProperty("user.dir") + File.separator + args[1];
}
else {
if (! args[1].startsWith("/"))
args[1] = System.getProperty("user.dir") + File.separator + args[1];
}
Rcm rcm = new Rcm(args[1]);
Thread rcmThread = new Thread(rcm);
rcmThread.start();
return true;
case "--help": case "--help":
default:
System.out.println("CLI Usage:\n" System.out.println("CLI Usage:\n"
+ "\t --rcm payload.bin\tSend payload\n"
+ "\t-c, --clean\tRemove/reset settings and exit\n" + "\t-c, --clean\tRemove/reset settings and exit\n"
+ "\t-v, --version \tShow application version\n" + "\t-v, --version \tShow application version\n"
+ "\t-h, --help\t\tShow this message"); + "\t-h, --help\t\tShow this message");
return true; return true;
default:
return false;
} }
} }
catch (Exception e){ catch (Exception e){
e.printStackTrace(); e.printStackTrace();
return false; return true;
} }
} }
} }

View file

@ -20,18 +20,19 @@ package nsusbloader.Utilities;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import nsusbloader.COM.USB.UsbConnect; import nsusbloader.COM.USB.UsbConnect;
import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.ModelControllers.Log;
import nsusbloader.NSLDataTypes.EModule; import nsusbloader.NSLDataTypes.EModule;
import nsusbloader.NSLDataTypes.EMsgType; import nsusbloader.NSLDataTypes.EMsgType;
import org.usb4java.DeviceHandle; import org.usb4java.DeviceHandle;
public class NxdtTask extends Task<Boolean> { public class NxdtTask extends Task<Boolean> {
private LogPrinter logPrinter; private ILogPrinter logPrinter;
private String saveToLocation; private String saveToLocation;
public NxdtTask(String saveToLocation){ public NxdtTask(String saveToLocation){
this.logPrinter = new LogPrinter(EModule.NXDT); this.logPrinter = Log.getPrinter(EModule.NXDT);
this.saveToLocation = saveToLocation; this.saveToLocation = saveToLocation;
} }

View file

@ -20,7 +20,7 @@ package nsusbloader.Utilities;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import nsusbloader.COM.USB.UsbErrorCodes; import nsusbloader.COM.USB.UsbErrorCodes;
import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EMsgType; import nsusbloader.NSLDataTypes.EMsgType;
import org.usb4java.DeviceHandle; import org.usb4java.DeviceHandle;
import org.usb4java.LibUsb; import org.usb4java.LibUsb;
@ -33,7 +33,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
class NxdtUsbAbi1 { class NxdtUsbAbi1 {
private LogPrinter logPrinter; private ILogPrinter logPrinter;
private DeviceHandle handlerNS; private DeviceHandle handlerNS;
private Task<Boolean> task; private Task<Boolean> task;
private String saveToPath; private String saveToPath;
@ -80,7 +80,7 @@ class NxdtUsbAbi1 {
public NxdtUsbAbi1(DeviceHandle handler, public NxdtUsbAbi1(DeviceHandle handler,
Task<Boolean> task, Task<Boolean> task,
LogPrinter logPrinter, ILogPrinter logPrinter,
String saveToPath String saveToPath
){ ){
this.handlerNS = handler; this.handlerNS = handler;

View file

@ -24,10 +24,10 @@
*/ */
package nsusbloader.Utilities; package nsusbloader.Utilities;
import javafx.concurrent.Task;
import nsusbloader.COM.USB.UsbConnect; import nsusbloader.COM.USB.UsbConnect;
import nsusbloader.COM.USB.UsbErrorCodes; import nsusbloader.COM.USB.UsbErrorCodes;
import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.ModelControllers.Log;
import nsusbloader.NSLDataTypes.EModule; import nsusbloader.NSLDataTypes.EModule;
import nsusbloader.NSLDataTypes.EMsgType; import nsusbloader.NSLDataTypes.EMsgType;
import org.usb4java.*; import org.usb4java.*;
@ -37,13 +37,15 @@ import java.nio.ByteBuffer;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import java.util.Arrays; import java.util.Arrays;
public class RcmTask extends Task<Boolean> { public class Rcm implements Runnable{
private boolean status = false;
private enum ECurrentOS { private enum ECurrentOS {
win, lin, mac, unsupported win, lin, mac, unsupported
} }
private LogPrinter logPrinter; private ILogPrinter logPrinter;
private String filePath; private String filePath;
private DeviceHandle handler; private DeviceHandle handler;
@ -65,13 +67,13 @@ public class RcmTask extends Task<Boolean> {
private static final byte[] sprayPttrn = { 0x00, 0x00, 0x01, 0x40}; private static final byte[] sprayPttrn = { 0x00, 0x00, 0x01, 0x40};
public RcmTask(String filePath){ public Rcm(String filePath){
this.logPrinter = new LogPrinter(EModule.RCM); this.logPrinter = Log.getPrinter(EModule.RCM);
this.filePath = filePath; this.filePath = filePath;
} }
@Override @Override
protected Boolean call() { public void run() {
logPrinter.print("Selected: "+filePath, EMsgType.INFO); logPrinter.print("Selected: "+filePath, EMsgType.INFO);
logPrinter.print("=============== RCM ===============", EMsgType.INFO); logPrinter.print("=============== RCM ===============", EMsgType.INFO);
@ -94,13 +96,13 @@ public class RcmTask extends Task<Boolean> {
"\n But you could file a bug with request."+ "\n But you could file a bug with request."+
"\n\n Nothing has been sent to NS. Execution stopped.", EMsgType.FAIL); "\n\n Nothing has been sent to NS. Execution stopped.", EMsgType.FAIL);
logPrinter.close(); logPrinter.close();
return false; return;
} }
} }
if (preparePayload()){ if (preparePayload()){
logPrinter.close(); logPrinter.close();
return false; return;
} }
// === TEST THIS === // === TEST THIS ===
// writeTestFile(); // writeTestFile();
@ -111,7 +113,7 @@ public class RcmTask extends Task<Boolean> {
if (! usbConnect.isConnected()){ if (! usbConnect.isConnected()){
logPrinter.close(); logPrinter.close();
return false; return;
} }
this.handler = usbConnect.getNsHandler(); this.handler = usbConnect.getNsHandler();
@ -119,7 +121,7 @@ public class RcmTask extends Task<Boolean> {
if (readUsbDeviceID()){ if (readUsbDeviceID()){
usbConnect.close(); usbConnect.close();
logPrinter.close(); logPrinter.close();
return false; return;
} }
// Send payload // Send payload
for (int i=0; i < fullPayload.length / 4096 ; i++){ for (int i=0; i < fullPayload.length / 4096 ; i++){
@ -128,7 +130,7 @@ public class RcmTask extends Task<Boolean> {
"\n\n Execution stopped.", EMsgType.FAIL); "\n\n Execution stopped.", EMsgType.FAIL);
usbConnect.close(); usbConnect.close();
logPrinter.close(); logPrinter.close();
return false; return;
} }
} }
logPrinter.print("Information sent to NS.", EMsgType.PASS); logPrinter.print("Information sent to NS.", EMsgType.PASS);
@ -137,7 +139,7 @@ public class RcmTask extends Task<Boolean> {
if (smashMacOS()){ if (smashMacOS()){
usbConnect.close(); usbConnect.close();
logPrinter.close(); logPrinter.close();
return false; return;
} }
} }
else { else {
@ -153,7 +155,7 @@ public class RcmTask extends Task<Boolean> {
"\n\n Execution stopped and failed. And it's strange.", EMsgType.FAIL); "\n\n Execution stopped and failed. And it's strange.", EMsgType.FAIL);
usbConnect.close(); usbConnect.close();
logPrinter.close(); logPrinter.close();
return false; return;
} }
if (retval != 0){ if (retval != 0){
@ -161,14 +163,13 @@ public class RcmTask extends Task<Boolean> {
"\n\n Execution stopped and failed.", EMsgType.FAIL); "\n\n Execution stopped and failed.", EMsgType.FAIL);
usbConnect.close(); usbConnect.close();
logPrinter.close(); logPrinter.close();
return false; return;
} }
} }
logPrinter.print(".:: Payload complete ::.", EMsgType.PASS); logPrinter.print(".:: Payload complete ::.", EMsgType.PASS);
usbConnect.close(); usbConnect.close();
logPrinter.updateOneLinerStatus(true);
logPrinter.close(); logPrinter.close();
return true;
} }
/** /**
* Prepare the 'big' or full-size byte-buffer that is actually is a payload that we're about to use. * Prepare the 'big' or full-size byte-buffer that is actually is a payload that we're about to use.

View file

@ -19,7 +19,8 @@
package nsusbloader.Utilities; package nsusbloader.Utilities;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.ModelControllers.Log;
import nsusbloader.NSLDataTypes.EModule; import nsusbloader.NSLDataTypes.EModule;
import nsusbloader.NSLDataTypes.EMsgType; import nsusbloader.NSLDataTypes.EMsgType;
@ -39,14 +40,14 @@ public class SplitMergeTool {
class SplitTask extends Task<Boolean>{ class SplitTask extends Task<Boolean>{
private LogPrinter logPrinter; private ILogPrinter logPrinter;
private String saveToPath; private String saveToPath;
private String filePath; private String filePath;
SplitTask(String filePath, String saveToPath){ SplitTask(String filePath, String saveToPath){
this.filePath = filePath; this.filePath = filePath;
this.saveToPath = saveToPath; this.saveToPath = saveToPath;
logPrinter = new LogPrinter(EModule.SPLIT_MERGE_TOOL); logPrinter = Log.getPrinter(EModule.SPLIT_MERGE_TOOL);
} }
@Override @Override
@ -182,14 +183,14 @@ class SplitTask extends Task<Boolean>{
class MergeTask extends Task<Boolean> { class MergeTask extends Task<Boolean> {
private LogPrinter logPrinter; private ILogPrinter logPrinter;
private String saveToPath; private String saveToPath;
private String filePath; private String filePath;
MergeTask(String filePath, String saveToPath) { MergeTask(String filePath, String saveToPath) {
this.filePath = filePath; this.filePath = filePath;
this.saveToPath = saveToPath; this.saveToPath = saveToPath;
logPrinter = new LogPrinter(EModule.SPLIT_MERGE_TOOL); logPrinter = Log.getPrinter(EModule.SPLIT_MERGE_TOOL);
} }
@Override @Override
protected Boolean call() { protected Boolean call() {