Compare commits

..

2 commits

24 changed files with 331 additions and 155 deletions

View file

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

View file

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

View file

@ -22,7 +22,7 @@ import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.stage.FileChooser;
import nsusbloader.MediatorControl;
import nsusbloader.ModelControllers.LogPrinter;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EMsgType;
import nsusbloader.COM.Helpers.NSSplitReader;
import org.usb4java.DeviceHandle;
@ -69,7 +69,7 @@ class GoldLeaf extends TransferModule {
// For using in CMD_SelectFile with SPEC:/ prefix
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);
final byte CMD_GetDriveCount = 1;

View file

@ -19,7 +19,7 @@
package nsusbloader.COM.USB;
import javafx.concurrent.Task;
import nsusbloader.ModelControllers.LogPrinter;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EFileStatus;
import nsusbloader.NSLDataTypes.EMsgType;
import nsusbloader.COM.Helpers.NSSplitReader;
@ -53,7 +53,7 @@ public class GoldLeaf_05 extends TransferModule {
private RandomAccessFile raf; // 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);
status = EFileStatus.FAILED;

View file

@ -23,7 +23,7 @@ import javafx.concurrent.Task;
import javafx.stage.FileChooser;
import nsusbloader.COM.Helpers.NSSplitReader;
import nsusbloader.MediatorControl;
import nsusbloader.ModelControllers.LogPrinter;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EMsgType;
import org.usb4java.DeviceHandle;
import org.usb4java.LibUsb;
@ -69,7 +69,7 @@ class GoldLeaf_07 extends TransferModule {
// For using in CMD_SelectFile with SPEC:/ prefix
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);
final byte CMD_GetDriveCount = 0x00;

View file

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

View file

@ -19,7 +19,7 @@
package nsusbloader.COM.USB;
import javafx.concurrent.Task;
import nsusbloader.ModelControllers.LogPrinter;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EFileStatus;
import nsusbloader.NSLDataTypes.EMsgType;
import nsusbloader.COM.Helpers.NSSplitReader;
@ -48,7 +48,7 @@ class TinFoil extends TransferModule {
/* byte[] magic = new byte[4];
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);
logPrinter.print("============= Tinfoil =============", EMsgType.INFO);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -41,9 +41,9 @@ public class MediatorControl {
public synchronized void setBgThreadActive(boolean isActive, EModule appModuleType) {
isTransferActive.set(isActive);
mainCtrler.getFrontCtrlr().notifyTransmThreadStarted(isActive, appModuleType);
mainCtrler.getFrontCtrlr().notifyThreadStarted(isActive, appModuleType);
mainCtrler.getSmCtrlr().notifySmThreadStarted(isActive, appModuleType);
mainCtrler.getRcmCtrlr().notifySmThreadStarted(isActive, appModuleType);
mainCtrler.getRcmCtrlr().notifyThreadStarted(isActive, appModuleType);
mainCtrler.getNXDTabController().notifyThreadStarted(isActive, appModuleType);
}
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.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;
public class LogPrinter {
private MessagesConsumer msgConsumer;
private BlockingQueue<String> msgQueue;
private BlockingQueue<Double> progressQueue;
private HashMap<String, EFileStatus> statusMap; // BlockingQueue for literally one object. TODO: read more books ; replace to hashMap
public class LogPrinterGui implements ILogPrinter {
private final MessagesConsumer msgConsumer;
private final BlockingQueue<String> msgQueue;
private final BlockingQueue<Double> progressQueue;
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.progressQueue = new LinkedBlockingQueue<>();
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 is what will print to textArea of the application.
* */
@Override
public void print(String message, EMsgType type){
try {
switch (type){
@ -69,6 +73,7 @@ public class LogPrinter {
/**
* Update progress for progress bar
* */
@Override
public void updateProgress(Double value) {
try {
progressQueue.put(value);
@ -78,6 +83,7 @@ public class LogPrinter {
/**
* When we're done - update status
* */
@Override
public void update(HashMap<String, File> nspMap, EFileStatus status){
for (File file: nspMap.values())
statusMap.putIfAbsent(file.getName(), status);
@ -85,12 +91,19 @@ public class LogPrinter {
/**
* When we're done - update status
* */
@Override
public void update(File file, EFileStatus status){
statusMap.putIfAbsent(file.getName(), status);
}
@Override
public void updateOneLinerStatus(boolean status){
oneLinerStatus.set(status);
}
/**
* When we're done - close it
* */
@Override
public void close(){
msgConsumer.interrupt();
}

View file

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

View file

@ -25,14 +25,17 @@ import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import nsusbloader.Controllers.NSLMainController;
import nsusbloader.Utilities.Rcm;
import java.io.File;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.prefs.Preferences;
public class NSLMain extends Application {
public static final String appVersion = "v3.0";
public static final String appVersion = "v4.0";
public static boolean isCli;
@Override
public void start(Stage primaryStage) throws Exception{
@ -86,9 +89,11 @@ public class NSLMain extends Application {
}
private static boolean handleCli(String[] args){
if (args.length != 1)
if (args.length == 0)
return false;
NSLMain.isCli = true;
try {
switch (args[0]) {
case "-v":
@ -104,19 +109,44 @@ public class NSLMain extends Application {
else
System.out.println("Nothing to remove");
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":
default:
System.out.println("CLI Usage:\n"
+ "\t --rcm payload.bin\tSend payload\n"
+ "\t-c, --clean\tRemove/reset settings and exit\n"
+ "\t-v, --version \tShow application version\n"
+ "\t-h, --help\t\tShow this message");
return true;
default:
return false;
}
}
catch (Exception e){
e.printStackTrace();
return false;
return true;
}
}
}

View file

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

View file

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

View file

@ -24,10 +24,10 @@
*/
package nsusbloader.Utilities;
import javafx.concurrent.Task;
import nsusbloader.COM.USB.UsbConnect;
import nsusbloader.COM.USB.UsbErrorCodes;
import nsusbloader.ModelControllers.LogPrinter;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.ModelControllers.Log;
import nsusbloader.NSLDataTypes.EModule;
import nsusbloader.NSLDataTypes.EMsgType;
import org.usb4java.*;
@ -37,13 +37,15 @@ import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.Arrays;
public class RcmTask extends Task<Boolean> {
public class Rcm implements Runnable{
private boolean status = false;
private enum ECurrentOS {
win, lin, mac, unsupported
}
private LogPrinter logPrinter;
private ILogPrinter logPrinter;
private String filePath;
private DeviceHandle handler;
@ -65,13 +67,13 @@ public class RcmTask extends Task<Boolean> {
private static final byte[] sprayPttrn = { 0x00, 0x00, 0x01, 0x40};
public RcmTask(String filePath){
this.logPrinter = new LogPrinter(EModule.RCM);
public Rcm(String filePath){
this.logPrinter = Log.getPrinter(EModule.RCM);
this.filePath = filePath;
}
@Override
protected Boolean call() {
public void run() {
logPrinter.print("Selected: "+filePath, 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\n Nothing has been sent to NS. Execution stopped.", EMsgType.FAIL);
logPrinter.close();
return false;
return;
}
}
if (preparePayload()){
logPrinter.close();
return false;
return;
}
// === TEST THIS ===
// writeTestFile();
@ -111,7 +113,7 @@ public class RcmTask extends Task<Boolean> {
if (! usbConnect.isConnected()){
logPrinter.close();
return false;
return;
}
this.handler = usbConnect.getNsHandler();
@ -119,7 +121,7 @@ public class RcmTask extends Task<Boolean> {
if (readUsbDeviceID()){
usbConnect.close();
logPrinter.close();
return false;
return;
}
// Send payload
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);
usbConnect.close();
logPrinter.close();
return false;
return;
}
}
logPrinter.print("Information sent to NS.", EMsgType.PASS);
@ -137,7 +139,7 @@ public class RcmTask extends Task<Boolean> {
if (smashMacOS()){
usbConnect.close();
logPrinter.close();
return false;
return;
}
}
else {
@ -153,7 +155,7 @@ public class RcmTask extends Task<Boolean> {
"\n\n Execution stopped and failed. And it's strange.", EMsgType.FAIL);
usbConnect.close();
logPrinter.close();
return false;
return;
}
if (retval != 0){
@ -161,14 +163,13 @@ public class RcmTask extends Task<Boolean> {
"\n\n Execution stopped and failed.", EMsgType.FAIL);
usbConnect.close();
logPrinter.close();
return false;
return;
}
}
logPrinter.print(".:: Payload complete ::.", EMsgType.PASS);
usbConnect.close();
logPrinter.updateOneLinerStatus(true);
logPrinter.close();
return true;
}
/**
* 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;
import javafx.concurrent.Task;
import nsusbloader.ModelControllers.LogPrinter;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.ModelControllers.Log;
import nsusbloader.NSLDataTypes.EModule;
import nsusbloader.NSLDataTypes.EMsgType;
@ -39,14 +40,14 @@ public class SplitMergeTool {
class SplitTask extends Task<Boolean>{
private LogPrinter logPrinter;
private ILogPrinter logPrinter;
private String saveToPath;
private String filePath;
SplitTask(String filePath, String saveToPath){
this.filePath = filePath;
this.saveToPath = saveToPath;
logPrinter = new LogPrinter(EModule.SPLIT_MERGE_TOOL);
logPrinter = Log.getPrinter(EModule.SPLIT_MERGE_TOOL);
}
@Override
@ -182,14 +183,14 @@ class SplitTask extends Task<Boolean>{
class MergeTask extends Task<Boolean> {
private LogPrinter logPrinter;
private ILogPrinter logPrinter;
private String saveToPath;
private String filePath;
MergeTask(String filePath, String saveToPath) {
this.filePath = filePath;
this.saveToPath = saveToPath;
logPrinter = new LogPrinter(EModule.SPLIT_MERGE_TOOL);
logPrinter = Log.getPrinter(EModule.SPLIT_MERGE_TOOL);
}
@Override
protected Boolean call() {

View file

@ -8,11 +8,13 @@
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.SVGPath?>
<!--
Steps to roll NXDT functionality back:
* Uncheck 'Disable' on NXDT Tab
* Set 'Visible' on NXDT Tab selector (SVGPath container)
-->
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="nsusbloader.Controllers.NSLMainController">
<children>
<VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
@ -24,7 +26,7 @@ Steps to roll NXDT functionality back:
<fx:include fx:id="FrontTab" source="FrontTab.fxml" VBox.vgrow="ALWAYS" />
</content>
<graphic>
<SVGPath content="M21,19V17H8V19H21M21,13V11H8V13H21M8,7H21V5H8V7M4,5V7H6V5H4M3,5A1,1 0 0,1 4,4H6A1,1 0 0,1 7,5V7A1,1 0 0,1 6,8H4A1,1 0 0,1 3,7V5M4,11V13H6V11H4M3,11A1,1 0 0,1 4,10H6A1,1 0 0,1 7,11V13A1,1 0 0,1 6,14H4A1,1 0 0,1 3,13V11M4,17V19H6V17H4M3,17A1,1 0 0,1 4,16H6A1,1 0 0,1 7,17V19A1,1 0 0,1 6,20H4A1,1 0 0,1 3,19V17Z" />
<SVGPath content="M 19.953125 -0.00390625 C 19.945025 0.86963499 19.665113 1.3200779 19.117188 1.6679688 C 18.569261 2.0158596 17.688291 2.2107818 16.572266 2.2636719 C 14.340723 2.369428 11.22952 1.9408017 8.0175781 1.7636719 L 8.015625 1.7636719 C 5.8083004 1.6301338 3.850269 1.7145428 2.421875 2.328125 C 1.7074522 2.6350131 1.1147008 3.0945958 0.765625 3.7402344 C 0.41654922 4.3858729 0.3309909 5.1840438 0.50976562 6.0957031 L 0.515625 6.1269531 L 0.52539062 6.1582031 C 0.74516874 6.8214776 1.3043008 7.2559352 1.9550781 7.46875 C 2.6058554 7.6815648 3.3739015 7.7273729 4.2304688 7.703125 C 5.9436032 7.6546292 8.0253788 7.3082908 10.042969 7.1230469 C 12.060559 6.9378029 14.005763 6.9298258 15.349609 7.4511719 C 16.693456 7.972518 17.5 8.8951351 17.5 11 L 13.023438 11 L 10.837891 11 L 1 11 C 0.156581 11 -0.10111662 11.623241 -0.10351562 12.189453 C -0.10591562 12.759114 -0.10321863 13.218366 -0.10351562 13.919922 C -0.10353762 13.969822 -0.10345962 13.990156 -0.10351562 14.042969 C -0.10332363 14.492063 -0.10337263 14.807528 -0.10351562 15.150391 C -0.10359462 15.343113 -0.10438363 15.566512 -0.10351562 15.771484 C -0.10347763 15.861874 -0.10364063 15.971437 -0.10351562 16.064453 C -0.10316562 16.324274 -0.10337563 16.550139 -0.10351562 16.880859 C -0.10353662 16.930759 -0.10345962 16.951094 -0.10351562 17.003906 C -0.10317063 17.257044 -0.10337962 17.473987 -0.10351562 17.794922 C -0.10353762 17.844822 -0.10345962 17.863203 -0.10351562 17.916016 C -0.10380362 18.172294 -0.10461563 18.463892 -0.10351562 18.732422 C -0.10363862 18.825442 -0.10347763 18.935007 -0.10351562 19.025391 C -0.10359462 19.218111 -0.10438363 19.441511 -0.10351562 19.646484 C -0.10337262 19.98934 -0.10332563 20.306746 -0.10351562 20.755859 C -0.10353662 20.805759 -0.10345962 20.826093 -0.10351562 20.878906 C -0.10321564 21.580432 -0.10591562 22.037789 -0.10351562 22.607422 C -0.10111563 23.173608 0.156706 23.796875 1 23.796875 L 10.833984 23.796875 L 13.019531 23.796875 L 22.857422 23.796875 C 23.70084 23.796875 23.958538 23.17361 23.960938 22.607422 C 23.963338 22.037788 23.960642 21.580432 23.960938 20.878906 C 23.960959 20.829006 23.96088 20.808672 23.960938 20.755859 C 23.960749 20.306747 23.960795 19.989341 23.960938 19.646484 C 23.961015 19.453769 23.961803 19.230374 23.960938 19.025391 C 23.9609 18.935011 23.961059 18.825438 23.960938 18.732422 C 23.96059 18.472592 23.960799 18.246723 23.960938 17.916016 C 23.960959 17.866116 23.96088 17.847735 23.960938 17.794922 C 23.960642 17.093366 23.963337 16.63411 23.960938 16.064453 C 23.96106 15.971433 23.960898 15.861868 23.960938 15.771484 C 23.961015 15.578768 23.961803 15.355372 23.960938 15.150391 C 23.960797 14.807528 23.960748 14.492063 23.960938 14.042969 C 23.960959 13.993069 23.96088 13.972735 23.960938 13.919922 C 23.960642 13.218366 23.963337 12.759114 23.960938 12.189453 C 23.958538 11.623242 23.700715 11 22.857422 11 L 18.5 11 C 18.5 8.6048649 17.347496 7.152482 15.710938 6.5175781 C 14.074378 5.8826742 12.017906 5.9371971 9.9511719 6.1269531 C 7.8844382 6.3167092 5.7997949 6.6578708 4.2011719 6.703125 C 3.4018604 6.7257521 2.725744 6.6699978 2.265625 6.5195312 C 1.8171096 6.3728594 1.6083191 6.1804127 1.4941406 5.859375 C 1.3628245 5.141091 1.4300216 4.6115935 1.6445312 4.2148438 C 1.8648981 3.8072608 2.2462454 3.4910124 2.8164062 3.2460938 C 3.9567281 2.7562562 5.8156963 2.6320489 7.9570312 2.7617188 L 7.9589844 2.7617188 C 11.116926 2.9357557 14.220255 3.3773586 16.619141 3.2636719 C 17.818583 3.2068289 18.856796 3.0180713 19.654297 2.5117188 C 20.451798 2.0053661 20.942623 1.130365 20.953125 0.00390625 L 19.953125 -0.00390625 z M 4.4277344 13.271484 L 7 13.271484 L 7 16 L 9.71875 16 L 9.71875 18.5625 L 7 18.5625 L 7 21.291016 L 4.4277344 21.291016 L 4.4277344 18.5625 L 1.7089844 18.5625 L 1.7089844 16 L 4.4277344 16 L 4.4277344 13.271484 z M 20 14 A 1.9161212 1.9161212 0 0 1 21.916016 15.916016 A 1.9161212 1.9161212 0 0 1 20 17.832031 A 1.9161212 1.9161212 0 0 1 18.083984 15.916016 A 1.9161212 1.9161212 0 0 1 20 14 z M 16.421875 17.667969 A 1.9168563 1.9168563 0 0 1 18.337891 19.583984 A 1.9168563 1.9168563 0 0 1 16.421875 21.5 A 1.9168563 1.9168563 0 0 1 14.505859 19.583984 A 1.9168563 1.9168563 0 0 1 16.421875 17.667969 z " />
</graphic>
</Tab>
<Tab closable="false">