diff --git a/src/main/java/nsusbloader/AppPreferences.java b/src/main/java/nsusbloader/AppPreferences.java index 66f24f2..62baa86 100644 --- a/src/main/java/nsusbloader/AppPreferences.java +++ b/src/main/java/nsusbloader/AppPreferences.java @@ -16,7 +16,15 @@ public class AppPreferences { theme = "/res/app_dark.css"; return theme; } + public String getProtocol(){ + String protocol = preferences.get("PROTOCOL", "TinFoil"); // Don't let user to change settings manually + if (!protocol.matches("(^TinFoil$)|(^GoldLeaf$)")) + protocol = "TinFoil"; + return protocol; + } public void setTheme(String theme){ preferences.put("THEME", theme); } + public void setProtocol(String protocol){ preferences.put("PROTOCOL", protocol); } + public String getRecent(){ return preferences.get("RECENT", System.getProperty("user.home")); } public void setRecent(String path){ preferences.put("RECENT", path); } diff --git a/src/main/java/nsusbloader/Controllers/NSLMainController.java b/src/main/java/nsusbloader/Controllers/NSLMainController.java index 1ae0ef0..3befcbd 100644 --- a/src/main/java/nsusbloader/Controllers/NSLMainController.java +++ b/src/main/java/nsusbloader/Controllers/NSLMainController.java @@ -42,6 +42,7 @@ public class NSLMainController implements Initializable { @FXML public NSTableViewController tableFilesListController; // Accessible from Mediator + private UsbCommunications usbCommunications; private Thread usbThread; private String previouslyOpenedPath; @@ -74,7 +75,7 @@ public class NSLMainController implements Initializable { ObservableList choiceProtocolList = FXCollections.observableArrayList("TinFoil", "GoldLeaf"); choiceProtocol.setItems(choiceProtocolList); - choiceProtocol.getSelectionModel().select(0); // TODO: shared settings + choiceProtocol.getSelectionModel().select(AppPreferences.getInstance().getProtocol()); // TODO: shared settings choiceProtocol.setOnAction(e->tableFilesListController.setNewProtocol(choiceProtocol.getSelectionModel().getSelectedItem())); // Add listener to notify tableView controller tableFilesListController.setNewProtocol(choiceProtocol.getSelectionModel().getSelectedItem()); // Notify tableView controller @@ -99,6 +100,7 @@ public class NSLMainController implements Initializable { switchThemeBtn.getScene().getStylesheets().remove("/res/app_light.css"); switchThemeBtn.getScene().getStylesheets().add("/res/app_dark.css"); } + AppPreferences.getInstance().setTheme(switchThemeBtn.getScene().getStylesheets().get(0)); } /** * Functionality for selecting NSP button. @@ -142,8 +144,9 @@ public class NSLMainController implements Initializable { for (File item: nspToUpload) logArea.appendText(" "+item.getAbsolutePath()+"\n"); } - UsbCommunications usbCommunications = new UsbCommunications(nspToUpload, choiceProtocol.getSelectionModel().getSelectedItem()); + usbCommunications = new UsbCommunications(nspToUpload, choiceProtocol.getSelectionModel().getSelectedItem()); usbThread = new Thread(usbCommunications); + usbThread.setDaemon(true); usbThread.start(); } } @@ -152,7 +155,7 @@ public class NSLMainController implements Initializable { * */ private void stopBtnAction(){ if (usbThread != null && usbThread.isAlive()){ - usbThread.interrupt(); + usbCommunications.cancel(false); } } /** @@ -189,7 +192,7 @@ public class NSLMainController implements Initializable { * Save preferences before exit * */ public void exit(){ - AppPreferences.getInstance().setTheme(switchThemeBtn.getScene().getStylesheets().get(0)); + AppPreferences.getInstance().setProtocol(choiceProtocol.getSelectionModel().getSelectedItem()); AppPreferences.getInstance().setRecent(previouslyOpenedPath); } } diff --git a/src/main/java/nsusbloader/Controllers/NSLRowModel.java b/src/main/java/nsusbloader/Controllers/NSLRowModel.java index 1765eea..afd3f17 100644 --- a/src/main/java/nsusbloader/Controllers/NSLRowModel.java +++ b/src/main/java/nsusbloader/Controllers/NSLRowModel.java @@ -45,6 +45,9 @@ public class NSLRowModel { case FAILED: this.status = "Failed"; break; + case UNKNOWN: + this.status = "..."; + break; case INCORRECT_FILE_FAILED: this.status = "Failed: Incorrect file"; markForUpload = false; diff --git a/src/main/java/nsusbloader/Controllers/NSTableViewController.java b/src/main/java/nsusbloader/Controllers/NSTableViewController.java index 0252da9..9e1670c 100644 --- a/src/main/java/nsusbloader/Controllers/NSTableViewController.java +++ b/src/main/java/nsusbloader/Controllers/NSTableViewController.java @@ -125,7 +125,7 @@ public class NSTableViewController implements Initializable { } } /** - * Return files ready for upload. Requested from NSLMainController only + * Return files ready for upload. Requested from NSLMainController only -> uploadBtnAction() //TODO: set undefined * @return null if no files marked for upload * List if there are files * */ @@ -135,11 +135,15 @@ public class NSTableViewController implements Initializable { return null; else { for (NSLRowModel model: rowsObsLst){ - if (model.isMarkForUpload()) + if (model.isMarkForUpload()){ files.add(model.getNspFile()); + model.setStatus(EFileStatus.UNKNOWN); + } } - if (!files.isEmpty()) + if (!files.isEmpty()) { + table.refresh(); return files; + } else return null; } diff --git a/src/main/java/nsusbloader/NSLDataTypes/EFileStatus.java b/src/main/java/nsusbloader/NSLDataTypes/EFileStatus.java index 674521a..9d75dfd 100644 --- a/src/main/java/nsusbloader/NSLDataTypes/EFileStatus.java +++ b/src/main/java/nsusbloader/NSLDataTypes/EFileStatus.java @@ -1,5 +1,5 @@ package nsusbloader.NSLDataTypes; public enum EFileStatus { - UPLOADED, INCORRECT_FILE_FAILED, FAILED + UPLOADED, INCORRECT_FILE_FAILED, FAILED, UNKNOWN } diff --git a/src/main/java/nsusbloader/UsbCommunications.java b/src/main/java/nsusbloader/UsbCommunications.java index d0df921..2f0b827 100644 --- a/src/main/java/nsusbloader/UsbCommunications.java +++ b/src/main/java/nsusbloader/UsbCommunications.java @@ -18,6 +18,8 @@ import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; +import static nsusbloader.RainbowHexDump.hexDumpUTF8; + public class UsbCommunications extends Task { private final int DEFAULT_INTERFACE = 0; @@ -349,7 +351,7 @@ public class UsbCommunications extends Task { byte[] receivedArray; while (true){ - if (Thread.currentThread().isInterrupted()) // Check if user interrupted process. + if (isCancelled()) // Check if user interrupted process. return false; receivedArray = readFromUsb(); if (receivedArray == null) @@ -428,7 +430,7 @@ public class UsbCommunications extends Task { int readPice = 8388608; // = 8Mb while (currentOffset < receivedRangeSize){ - if (Thread.currentThread().isInterrupted()) // Check if user interrupted process. + if (isCancelled()) // Check if user interrupted process. return true; if ((currentOffset + readPice) >= receivedRangeSize ) readPice = Math.toIntExact(receivedRangeSize - currentOffset); @@ -561,6 +563,7 @@ public class UsbCommunications extends Task { readByte = readFromUsb(); if (readByte == null) return false; + if (Arrays.equals(readByte, CMD_ConnectionResponse)) { if (!handleConnectionResponse(pfsElement)) return false; @@ -699,7 +702,7 @@ public class UsbCommunications extends Task { while (readFrom < realNcaSize){ - if (Thread.currentThread().isInterrupted()) // Check if user interrupted process. + if (isCancelled()) // Check if user interrupted process. return false; if (realNcaSize - readFrom < readPice) @@ -707,7 +710,7 @@ public class UsbCommunications extends Task { readBuf = new byte[readPice]; if (bufferedInStream.read(readBuf) != readPice) return false; - + //System.out.println("S: "+readFrom+" T: "+realNcaSize+" P: "+readPice); // DEBUG if (!writeToUsb(readBuf)) return false; //-----------------------------------------/