Update NXDT part

Add NXDT CLI support
Update MessagesConsumer
master
Dmitry Isaenko 2020-07-07 15:02:37 +03:00
parent 6100a721af
commit 96e85056dd
18 changed files with 198 additions and 56 deletions

View File

@ -18,7 +18,7 @@
*/
package nsusbloader.COM;
public interface ICommunications extends Runnable {
public interface INSTask extends Runnable {
void cancel();
boolean isCancelled();
}

View File

@ -18,7 +18,7 @@
*/
package nsusbloader.COM.NET;
import nsusbloader.COM.ICommunications;
import nsusbloader.COM.INSTask;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EFileStatus;
import nsusbloader.ModelControllers.Log;
@ -32,7 +32,7 @@ import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.*;
public class NETCommunications implements ICommunications { // todo: rewrite
public class NETCommunications implements INSTask { // todo: rewrite
private ILogPrinter logPrinter;

View File

@ -18,8 +18,7 @@
*/
package nsusbloader.COM.USB;
import javafx.concurrent.Task;
import nsusbloader.COM.ICommunications;
import nsusbloader.COM.INSTask;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EFileStatus;
import nsusbloader.NSLDataTypes.EMsgType;
@ -54,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, ICommunications task, ILogPrinter logPrinter){
GoldLeaf_05(DeviceHandle handler, LinkedHashMap<String, File> nspMap, INSTask task, ILogPrinter logPrinter){
super(handler, nspMap, task, logPrinter);
status = EFileStatus.FAILED;

View File

@ -19,10 +19,9 @@
package nsusbloader.COM.USB;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.stage.FileChooser;
import nsusbloader.COM.Helpers.NSSplitReader;
import nsusbloader.COM.ICommunications;
import nsusbloader.COM.INSTask;
import nsusbloader.MediatorControl;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EMsgType;
@ -70,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, ICommunications task, ILogPrinter logPrinter, boolean nspFilter){
GoldLeaf_07(DeviceHandle handler, LinkedHashMap<String, File> nspMap, INSTask task, ILogPrinter logPrinter, boolean nspFilter){
super(handler, nspMap, task, logPrinter);
final byte CMD_GetDriveCount = 0x00;

View File

@ -19,9 +19,8 @@
package nsusbloader.COM.USB;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.stage.FileChooser;
import nsusbloader.COM.ICommunications;
import nsusbloader.COM.INSTask;
import nsusbloader.MediatorControl;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EMsgType;
@ -70,7 +69,7 @@ class GoldLeaf_08 extends TransferModule {
// For using in CMD_SelectFile with SPEC:/ prefix
private File selectedFile;
GoldLeaf_08(DeviceHandle handler, LinkedHashMap<String, File> nspMap, ICommunications task, ILogPrinter logPrinter, boolean nspFilter){
GoldLeaf_08(DeviceHandle handler, LinkedHashMap<String, File> nspMap, INSTask task, ILogPrinter logPrinter, boolean nspFilter){
super(handler, nspMap, task, logPrinter);
final byte CMD_GetDriveCount = 1;

View File

@ -18,8 +18,7 @@
*/
package nsusbloader.COM.USB;
import javafx.concurrent.Task;
import nsusbloader.COM.ICommunications;
import nsusbloader.COM.INSTask;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EFileStatus;
import nsusbloader.NSLDataTypes.EMsgType;
@ -49,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, ICommunications task, ILogPrinter logPrinter){
TinFoil(DeviceHandle handler, LinkedHashMap<String, File> nspMap, INSTask task, ILogPrinter logPrinter){
super(handler, nspMap, task, logPrinter);
logPrinter.print("============= Tinfoil =============", EMsgType.INFO);

View File

@ -18,8 +18,7 @@
*/
package nsusbloader.COM.USB;
import javafx.concurrent.Task;
import nsusbloader.COM.ICommunications;
import nsusbloader.COM.INSTask;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EFileStatus;
import nsusbloader.NSLDataTypes.EMsgType;
@ -34,9 +33,9 @@ public abstract class TransferModule {
LinkedHashMap<String, File> nspMap;
ILogPrinter logPrinter;
DeviceHandle handlerNS;
ICommunications task;
INSTask task;
TransferModule(DeviceHandle handler, LinkedHashMap<String, File> nspMap, ICommunications task, ILogPrinter printer){
TransferModule(DeviceHandle handler, LinkedHashMap<String, File> nspMap, INSTask task, ILogPrinter printer){
this.handlerNS = handler;
this.nspMap = nspMap;
this.task = task;

View File

@ -18,7 +18,7 @@
*/
package nsusbloader.COM.USB;
import nsusbloader.COM.ICommunications;
import nsusbloader.COM.INSTask;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.ModelControllers.Log;
import nsusbloader.NSLDataTypes.EFileStatus;
@ -31,7 +31,7 @@ import java.io.*;
import java.util.*;
// TODO: add filter option to show only NSP files
public class UsbCommunications implements ICommunications {
public class UsbCommunications implements INSTask {
private ILogPrinter logPrinter;
private LinkedHashMap<String, File> nspMap;

View File

@ -30,7 +30,7 @@ import javafx.scene.layout.Region;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import nsusbloader.AppPreferences;
import nsusbloader.COM.ICommunications;
import nsusbloader.COM.INSTask;
import nsusbloader.COM.NET.NETCommunications;
import nsusbloader.COM.USB.UsbCommunications;
import nsusbloader.MediatorControl;
@ -63,7 +63,7 @@ public class FrontController implements Initializable {
private String previouslyOpenedPath;
private Region btnUpStopImage;
private ResourceBundle resourceBundle;
private ICommunications usbNetCommunications;
private INSTask usbNetCommunications;
private Thread workThread;
@Override

View File

@ -18,7 +18,6 @@
*/
package nsusbloader.Controllers;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
@ -26,6 +25,7 @@ import javafx.scene.control.Label;
import javafx.scene.layout.Region;
import javafx.stage.DirectoryChooser;
import nsusbloader.AppPreferences;
import nsusbloader.COM.INSTask;
import nsusbloader.MediatorControl;
import nsusbloader.NSLDataTypes.EModule;
import nsusbloader.Utilities.nxdumptool.NxdtTask;
@ -45,7 +45,7 @@ public class NxdtController implements Initializable {
private Region btnDumpStopImage;
private Task<Boolean> NxdtTask;
private INSTask NxdtTask;
private Thread workThread;
@Override
@ -84,13 +84,6 @@ public class NxdtController implements Initializable {
MediatorControl.getInstance().getContoller().logArea.clear();
NxdtTask = new NxdtTask(saveToLocationLbl.getText());
NxdtTask.setOnSucceeded(event -> {
if (NxdtTask.getValue())
statusLbl.setText(rb.getString("done_txt"));
else
statusLbl.setText(rb.getString("failure_txt"));
});
workThread = new Thread(NxdtTask);
workThread.setDaemon(true);
workThread.start();
@ -102,7 +95,7 @@ public class NxdtController implements Initializable {
* */
private void stopBtnAction(){
if (workThread != null && workThread.isAlive()){
NxdtTask.cancel(false);
NxdtTask.cancel();
}
}
@ -130,6 +123,12 @@ public class NxdtController implements Initializable {
injectPldBtn.getStyleClass().remove("buttonStop");
injectPldBtn.getStyleClass().add("buttonUp");
}
public void setOneLineStatus(boolean status){
if (status)
statusLbl.setText(rb.getString("done_txt"));
else
statusLbl.setText(rb.getString("failure_txt"));
}
/**
* Save application settings on exit
* */

View File

@ -98,9 +98,14 @@ public class MessagesConsumer extends AnimationTimer {
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());
switch (appModuleType){
case RCM:
MediatorControl.getInstance().getContoller().getRcmCtrlr().setOneLineStatus(oneLinerStatus.get());
break;
case NXDT:
MediatorControl.getInstance().getContoller().getNXDTabController().setOneLineStatus(oneLinerStatus.get());
break;
}
this.stop();

View File

@ -18,7 +18,7 @@
*/
package nsusbloader.Utilities.nxdumptool;
import javafx.concurrent.Task;
import nsusbloader.COM.INSTask;
import nsusbloader.COM.USB.UsbConnect;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.ModelControllers.Log;
@ -26,18 +26,20 @@ import nsusbloader.NSLDataTypes.EModule;
import nsusbloader.NSLDataTypes.EMsgType;
import org.usb4java.DeviceHandle;
public class NxdtTask extends Task<Boolean> {
public class NxdtTask implements INSTask {
private ILogPrinter logPrinter;
private String saveToLocation;
private volatile boolean cancel;
public NxdtTask(String saveToLocation){
this.logPrinter = Log.getPrinter(EModule.NXDT);
this.saveToLocation = saveToLocation;
}
@Override
protected Boolean call() {
public void run() {
logPrinter.print("Save to location: "+ saveToLocation, EMsgType.INFO);
logPrinter.print("=============== nxdumptool ===============", EMsgType.INFO);
@ -45,7 +47,7 @@ public class NxdtTask extends Task<Boolean> {
if (! usbConnect.isConnected()){
logPrinter.close();
return false;
return;
}
DeviceHandle handler = usbConnect.getNsHandler();
@ -55,7 +57,18 @@ public class NxdtTask extends Task<Boolean> {
logPrinter.print(".:: Complete ::.", EMsgType.PASS);
usbConnect.close();
logPrinter.updateOneLinerStatus(true);
logPrinter.close();
return true;
return;
}
@Override
public void cancel() {
cancel = true;
}
@Override
public boolean isCancelled() {
return cancel;
}
}

View File

@ -18,7 +18,7 @@
*/
package nsusbloader.Utilities.nxdumptool;
import javafx.concurrent.Task;
import nsusbloader.COM.INSTask;
import nsusbloader.COM.USB.UsbErrorCodes;
import nsusbloader.ModelControllers.ILogPrinter;
import nsusbloader.NSLDataTypes.EMsgType;
@ -35,7 +35,7 @@ import java.util.Arrays;
class NxdtUsbAbi1 {
private ILogPrinter logPrinter;
private DeviceHandle handlerNS;
private Task<Boolean> task;
private INSTask task;
private String saveToPath;
private boolean isWindows;
@ -79,7 +79,7 @@ class NxdtUsbAbi1 {
0x00, 0x00, 0x00, 0x00 };
public NxdtUsbAbi1(DeviceHandle handler,
Task<Boolean> task,
INSTask task,
ILogPrinter logPrinter,
String saveToPath
){

View File

@ -57,19 +57,27 @@ public class CommandLineInterface {
return;
}
if (cli.hasOption("n") || cli.hasOption("tfn")){
final String[] tfnArguments = cli.getOptionValues("tfn");
new TinfoilNet(tfnArguments);
final String[] arguments = cli.getOptionValues("tfn");
new TinfoilNet(arguments);
return;
}
if (cli.hasOption("t") || cli.hasOption("tinfoil")){
final String[] tfArguments = cli.getOptionValues("tinfoil");
new TinfoilUsb(tfArguments);
final String[] arguments = cli.getOptionValues("tinfoil");
new TinfoilUsb(arguments);
return;
}
if (cli.hasOption("g") || cli.hasOption("goldleaf")){
final String[] glArguments = cli.getOptionValues("goldleaf");
new GoldLeaf(glArguments);
final String[] arguments = cli.getOptionValues("goldleaf");
new GoldLeaf(arguments);
return;
}
/*
if (cli.hasOption("x") || cli.hasOption("nxdt")){
final String[] arguments = cli.getOptionValues("nxdt");
new NXDT(arguments);
return;
}
*/
}
catch (ParseException pe){
System.out.println(pe.getLocalizedMessage() +
@ -139,6 +147,15 @@ public class CommandLineInterface {
.hasArgs()
.argName("...")
.build();
/* nxdumptool */
/*
final Option nxdtOption = Option.builder("x")
.longOpt("nxdt")
.desc("Handle nxdumptool connections.")
.hasArg()
.argName("DIRECTORY")
.build();
*/
final OptionGroup group = new OptionGroup();
group.addOption(rcmOption);
@ -148,6 +165,7 @@ public class CommandLineInterface {
group.addOption(helpOption);
group.addOption(tinfoilOption);
group.addOption(glOption);
//group.addOption(nxdtOption);
options.addOptionGroup(group);

View File

@ -1,6 +1,24 @@
/*
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.cli;
import nsusbloader.COM.ICommunications;
import nsusbloader.COM.INSTask;
import nsusbloader.COM.USB.UsbCommunications;
import nsusbloader.Controllers.SettingsController;
@ -51,8 +69,8 @@ public class GoldLeaf {
+ "\tns-usbloader -g ver=<arg1> [filter] FILE1 ...\n"
+ "\tns-usbloader --goldleaf ver=<arg1> [filter] FILE1 ..."
+ "\n\nOption:"
+ "\n\tver=<goldleaf_version>\tDefine GoldLeaf version (mandatory)\n\n"
+ "\n\tfilter\t\nShow only *.nsp in GoldLeaf (optional)\n\n"
+ "\n\tver=<goldleaf_version>\tDefine GoldLeaf version (mandatory)"
+ "\n\tfilter\t\t\tShow only *.nsp in GoldLeaf (optional)\n\n"
+ getGlSupportedVersions());
}
private String getGlSupportedVersions(){
@ -107,7 +125,7 @@ public class GoldLeaf {
}
public void runGoldLeafBackend() throws InterruptedException {
ICommunications task = new UsbCommunications(filesList,
INSTask task = new UsbCommunications(filesList,
"GoldLeaf"+goldLeafVersion,
filterForNsp);
Thread thread = new Thread(task);

View File

@ -1,3 +1,21 @@
/*
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.cli;
public class IncorrectSetupException extends Exception {

View File

@ -0,0 +1,58 @@
/*
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.cli;
import nsusbloader.Utilities.nxdumptool.NxdtTask;
import java.io.File;
public class NXDT {
private final String[] arguments;
private String saveTo;
public NXDT(String[] arguments) throws InterruptedException, IncorrectSetupException{
this.arguments = arguments;
parseArgument();
runBackend();
}
private void parseArgument() throws IncorrectSetupException{
final File file = new File(arguments[0]);
if (! file.exists()){
throw new IncorrectSetupException("Directory does not exist.\n" +
"Try 'ns-usbloader -h' for more information.");
}
if (file.isFile()){
throw new IncorrectSetupException("Argument is file while directory expected.\n" +
"Try 'ns-usbloader -h' for more information.");
}
saveTo = arguments[0];
}
private void runBackend() throws InterruptedException{
NxdtTask nxdtTask = new NxdtTask(saveTo);
Thread thread = new Thread(nxdtTask);
thread.start();
thread.join();
}
}

View File

@ -1,6 +1,24 @@
/*
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.cli;
import nsusbloader.COM.ICommunications;
import nsusbloader.COM.INSTask;
import nsusbloader.COM.USB.UsbCommunications;
import java.io.File;
@ -43,7 +61,7 @@ public class TinfoilUsb {
}
private void runTinfoilBackend() throws InterruptedException{
ICommunications task = new UsbCommunications(filesList, "TinFoil", false);
INSTask task = new UsbCommunications(filesList, "TinFoil", false);
Thread thread = new Thread(task);
thread.start();
thread.join();