From 96e85056dd914ccead7a7e2d84b4efc4640abb66 Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Tue, 7 Jul 2020 15:02:37 +0300 Subject: [PATCH] Update NXDT part Add NXDT CLI support Update MessagesConsumer --- .../{ICommunications.java => INSTask.java} | 2 +- .../COM/NET/NETCommunications.java | 4 +- .../java/nsusbloader/COM/USB/GoldLeaf_05.java | 5 +- .../java/nsusbloader/COM/USB/GoldLeaf_07.java | 5 +- .../java/nsusbloader/COM/USB/GoldLeaf_08.java | 5 +- .../java/nsusbloader/COM/USB/TinFoil.java | 5 +- .../nsusbloader/COM/USB/TransferModule.java | 7 +-- .../COM/USB/UsbCommunications.java | 4 +- .../Controllers/FrontController.java | 4 +- .../Controllers/NxdtController.java | 19 +++--- .../ModelControllers/MessagesConsumer.java | 11 +++- .../Utilities/nxdumptool/NxdtTask.java | 23 ++++++-- .../Utilities/nxdumptool/NxdtUsbAbi1.java | 6 +- .../nsusbloader/cli/CommandLineInterface.java | 30 ++++++++-- src/main/java/nsusbloader/cli/GoldLeaf.java | 26 +++++++-- .../cli/IncorrectSetupException.java | 18 ++++++ src/main/java/nsusbloader/cli/NXDT.java | 58 +++++++++++++++++++ src/main/java/nsusbloader/cli/TinfoilUsb.java | 22 ++++++- 18 files changed, 198 insertions(+), 56 deletions(-) rename src/main/java/nsusbloader/COM/{ICommunications.java => INSTask.java} (93%) create mode 100644 src/main/java/nsusbloader/cli/NXDT.java diff --git a/src/main/java/nsusbloader/COM/ICommunications.java b/src/main/java/nsusbloader/COM/INSTask.java similarity index 93% rename from src/main/java/nsusbloader/COM/ICommunications.java rename to src/main/java/nsusbloader/COM/INSTask.java index e0c6cb2..ac9a444 100644 --- a/src/main/java/nsusbloader/COM/ICommunications.java +++ b/src/main/java/nsusbloader/COM/INSTask.java @@ -18,7 +18,7 @@ */ package nsusbloader.COM; -public interface ICommunications extends Runnable { +public interface INSTask extends Runnable { void cancel(); boolean isCancelled(); } diff --git a/src/main/java/nsusbloader/COM/NET/NETCommunications.java b/src/main/java/nsusbloader/COM/NET/NETCommunications.java index e13a610..f349480 100644 --- a/src/main/java/nsusbloader/COM/NET/NETCommunications.java +++ b/src/main/java/nsusbloader/COM/NET/NETCommunications.java @@ -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; diff --git a/src/main/java/nsusbloader/COM/USB/GoldLeaf_05.java b/src/main/java/nsusbloader/COM/USB/GoldLeaf_05.java index 1c8e29e..1731b79 100644 --- a/src/main/java/nsusbloader/COM/USB/GoldLeaf_05.java +++ b/src/main/java/nsusbloader/COM/USB/GoldLeaf_05.java @@ -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 nspMap, ICommunications task, ILogPrinter logPrinter){ + GoldLeaf_05(DeviceHandle handler, LinkedHashMap nspMap, INSTask task, ILogPrinter logPrinter){ super(handler, nspMap, task, logPrinter); status = EFileStatus.FAILED; diff --git a/src/main/java/nsusbloader/COM/USB/GoldLeaf_07.java b/src/main/java/nsusbloader/COM/USB/GoldLeaf_07.java index e52ad9c..424a111 100644 --- a/src/main/java/nsusbloader/COM/USB/GoldLeaf_07.java +++ b/src/main/java/nsusbloader/COM/USB/GoldLeaf_07.java @@ -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 nspMap, ICommunications task, ILogPrinter logPrinter, boolean nspFilter){ + GoldLeaf_07(DeviceHandle handler, LinkedHashMap nspMap, INSTask task, ILogPrinter logPrinter, boolean nspFilter){ super(handler, nspMap, task, logPrinter); final byte CMD_GetDriveCount = 0x00; diff --git a/src/main/java/nsusbloader/COM/USB/GoldLeaf_08.java b/src/main/java/nsusbloader/COM/USB/GoldLeaf_08.java index be3cae1..caee81a 100644 --- a/src/main/java/nsusbloader/COM/USB/GoldLeaf_08.java +++ b/src/main/java/nsusbloader/COM/USB/GoldLeaf_08.java @@ -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 nspMap, ICommunications task, ILogPrinter logPrinter, boolean nspFilter){ + GoldLeaf_08(DeviceHandle handler, LinkedHashMap nspMap, INSTask task, ILogPrinter logPrinter, boolean nspFilter){ super(handler, nspMap, task, logPrinter); final byte CMD_GetDriveCount = 1; diff --git a/src/main/java/nsusbloader/COM/USB/TinFoil.java b/src/main/java/nsusbloader/COM/USB/TinFoil.java index ad47689..ec4d847 100644 --- a/src/main/java/nsusbloader/COM/USB/TinFoil.java +++ b/src/main/java/nsusbloader/COM/USB/TinFoil.java @@ -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 nspMap, ICommunications task, ILogPrinter logPrinter){ + TinFoil(DeviceHandle handler, LinkedHashMap nspMap, INSTask task, ILogPrinter logPrinter){ super(handler, nspMap, task, logPrinter); logPrinter.print("============= Tinfoil =============", EMsgType.INFO); diff --git a/src/main/java/nsusbloader/COM/USB/TransferModule.java b/src/main/java/nsusbloader/COM/USB/TransferModule.java index 0dae6d1..c1d09e3 100644 --- a/src/main/java/nsusbloader/COM/USB/TransferModule.java +++ b/src/main/java/nsusbloader/COM/USB/TransferModule.java @@ -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 nspMap; ILogPrinter logPrinter; DeviceHandle handlerNS; - ICommunications task; + INSTask task; - TransferModule(DeviceHandle handler, LinkedHashMap nspMap, ICommunications task, ILogPrinter printer){ + TransferModule(DeviceHandle handler, LinkedHashMap nspMap, INSTask task, ILogPrinter printer){ this.handlerNS = handler; this.nspMap = nspMap; this.task = task; diff --git a/src/main/java/nsusbloader/COM/USB/UsbCommunications.java b/src/main/java/nsusbloader/COM/USB/UsbCommunications.java index 91c6d34..3b5a249 100644 --- a/src/main/java/nsusbloader/COM/USB/UsbCommunications.java +++ b/src/main/java/nsusbloader/COM/USB/UsbCommunications.java @@ -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 nspMap; diff --git a/src/main/java/nsusbloader/Controllers/FrontController.java b/src/main/java/nsusbloader/Controllers/FrontController.java index f841813..1c70636 100644 --- a/src/main/java/nsusbloader/Controllers/FrontController.java +++ b/src/main/java/nsusbloader/Controllers/FrontController.java @@ -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 diff --git a/src/main/java/nsusbloader/Controllers/NxdtController.java b/src/main/java/nsusbloader/Controllers/NxdtController.java index a5367df..0b66515 100644 --- a/src/main/java/nsusbloader/Controllers/NxdtController.java +++ b/src/main/java/nsusbloader/Controllers/NxdtController.java @@ -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 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 * */ diff --git a/src/main/java/nsusbloader/ModelControllers/MessagesConsumer.java b/src/main/java/nsusbloader/ModelControllers/MessagesConsumer.java index f0b6d7c..80e272a 100644 --- a/src/main/java/nsusbloader/ModelControllers/MessagesConsumer.java +++ b/src/main/java/nsusbloader/ModelControllers/MessagesConsumer.java @@ -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(); diff --git a/src/main/java/nsusbloader/Utilities/nxdumptool/NxdtTask.java b/src/main/java/nsusbloader/Utilities/nxdumptool/NxdtTask.java index 4e4dc40..938eda9 100644 --- a/src/main/java/nsusbloader/Utilities/nxdumptool/NxdtTask.java +++ b/src/main/java/nsusbloader/Utilities/nxdumptool/NxdtTask.java @@ -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 { +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 { if (! usbConnect.isConnected()){ logPrinter.close(); - return false; + return; } DeviceHandle handler = usbConnect.getNsHandler(); @@ -55,7 +57,18 @@ public class NxdtTask extends Task { 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; } } \ No newline at end of file diff --git a/src/main/java/nsusbloader/Utilities/nxdumptool/NxdtUsbAbi1.java b/src/main/java/nsusbloader/Utilities/nxdumptool/NxdtUsbAbi1.java index 1a8d87d..a55b17f 100644 --- a/src/main/java/nsusbloader/Utilities/nxdumptool/NxdtUsbAbi1.java +++ b/src/main/java/nsusbloader/Utilities/nxdumptool/NxdtUsbAbi1.java @@ -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 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 task, + INSTask task, ILogPrinter logPrinter, String saveToPath ){ diff --git a/src/main/java/nsusbloader/cli/CommandLineInterface.java b/src/main/java/nsusbloader/cli/CommandLineInterface.java index 8edcc55..e5f931b 100644 --- a/src/main/java/nsusbloader/cli/CommandLineInterface.java +++ b/src/main/java/nsusbloader/cli/CommandLineInterface.java @@ -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); diff --git a/src/main/java/nsusbloader/cli/GoldLeaf.java b/src/main/java/nsusbloader/cli/GoldLeaf.java index f0d47a6..c8559e1 100644 --- a/src/main/java/nsusbloader/cli/GoldLeaf.java +++ b/src/main/java/nsusbloader/cli/GoldLeaf.java @@ -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 . +*/ 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= [filter] FILE1 ...\n" + "\tns-usbloader --goldleaf ver= [filter] FILE1 ..." + "\n\nOption:" - + "\n\tver=\tDefine GoldLeaf version (mandatory)\n\n" - + "\n\tfilter\t\nShow only *.nsp in GoldLeaf (optional)\n\n" + + "\n\tver=\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); diff --git a/src/main/java/nsusbloader/cli/IncorrectSetupException.java b/src/main/java/nsusbloader/cli/IncorrectSetupException.java index 6077b75..931a5fe 100644 --- a/src/main/java/nsusbloader/cli/IncorrectSetupException.java +++ b/src/main/java/nsusbloader/cli/IncorrectSetupException.java @@ -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 . +*/ package nsusbloader.cli; public class IncorrectSetupException extends Exception { diff --git a/src/main/java/nsusbloader/cli/NXDT.java b/src/main/java/nsusbloader/cli/NXDT.java new file mode 100644 index 0000000..90dc675 --- /dev/null +++ b/src/main/java/nsusbloader/cli/NXDT.java @@ -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 . +*/ +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(); + } +} diff --git a/src/main/java/nsusbloader/cli/TinfoilUsb.java b/src/main/java/nsusbloader/cli/TinfoilUsb.java index faf46f5..41c9658 100644 --- a/src/main/java/nsusbloader/cli/TinfoilUsb.java +++ b/src/main/java/nsusbloader/cli/TinfoilUsb.java @@ -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 . +*/ 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();